Skip to content

Commit

Permalink
Bump SignInWithEth/Sol canisters (#6406)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Sep 17, 2024
1 parent 7c5f8d3 commit fc7dfa2
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 99 deletions.
8 changes: 4 additions & 4 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@
},
"sign_in_with_ethereum": {
"type": "custom",
"candid": "https://github.com/kristoferlund/ic-siwe/releases/download/v0.0.6/ic_siwe_provider.did",
"wasm": "https://github.com/kristoferlund/ic-siwe/releases/download/v0.0.6/ic_siwe_provider.wasm.gz"
"candid": "https://github.com/kristoferlund/ic-siwe/releases/download/v0.1.1/ic_siwe_provider.did",
"wasm": "https://github.com/kristoferlund/ic-siwe/releases/download/v0.1.1/ic_siwe_provider.wasm.gz"
},
"sign_in_with_solana": {
"type": "custom",
"candid": "https://github.com/kristoferlund/ic-siws/releases/download/v0.0.1/ic_siws_provider.did",
"wasm": "https://github.com/kristoferlund/ic-siws/releases/download/v0.0.1/ic_siws_provider.wasm.gz"
"candid": "https://github.com/kristoferlund/ic-siws/releases/download/v0.0.2/ic_siws_provider.did",
"wasm": "https://github.com/kristoferlund/ic-siws/releases/download/v0.0.2/ic_siws_provider.wasm.gz"
},
"website": {
"build": "",
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/SigninWithEth.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
message: prepareResponse.siweMessage,
});
client
.signInWithWallet("eth", account, signResponse, assumeIdentity)
.signInWithWallet("eth", account, signResponse, prepareResponse.nonce, assumeIdentity)
.then((resp) => {
if (resp.kind === "success") {
dispatch("connected", resp);
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/SigninWithSol.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
const signResponse = await signMessage(data);
const signature = base58.encode(signResponse);
await client
.signInWithWallet("sol", account, signature, assumeIdentity)
.signInWithWallet("sol", account, signature, "", assumeIdentity)
.then((resp) => {
if (resp.kind === "success") {
dispatch("connected", resp);
Expand Down
3 changes: 0 additions & 3 deletions frontend/openchat-agent/codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ didc bind ../../backend/canisters/local_user_index/api/can.did -t js > ./src/ser
didc bind ../../backend/canisters/market_maker/api/can.did -t ts > ./src/services/marketMaker/candid/types.d.ts
didc bind ../../backend/canisters/market_maker/api/can.did -t js > ./src/services/marketMaker/candid/idl.js

didc bind ../../backend/canisters/notifications_index/api/can.did -t ts > ./src/services/notifications/candid/types.d.ts
didc bind ../../backend/canisters/notifications_index/api/can.did -t js > ./src/services/notifications/candid/idl.js

didc bind ../../backend/canisters/proposals_bot/api/can.did -t ts > ./src/services/proposalsBot/candid/types.d.ts
didc bind ../../backend/canisters/proposals_bot/api/can.did -t js > ./src/services/proposalsBot/candid/idl.js

Expand Down
5 changes: 3 additions & 2 deletions frontend/openchat-agent/src/services/openchatAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3557,11 +3557,12 @@ export class OpenChatAgent extends EventTarget {
token: "eth" | "sol",
address: string,
signature: string,
sessionKey: Uint8Array
sessionKey: Uint8Array,
nonce: string,
): Promise<PrepareDelegationResponse> {
switch (token) {
case "eth":
return this._signInWithEthereumClient.login(signature, address, sessionKey);
return this._signInWithEthereumClient.login(signature, address, sessionKey, nonce);
case "sol":
return this._signInWithSolanaClient.login(signature, address, sessionKey);
}
Expand Down
106 changes: 68 additions & 38 deletions frontend/openchat-agent/src/services/signInWithEthereum/candid/can.did
Original file line number Diff line number Diff line change
@@ -1,53 +1,83 @@
type Address = text;
type CanisterPublicKey = PublicKey;
type Delegation = record {
pubkey : PublicKey;
targets : opt vec principal;
expiration : Timestamp;
};
type GetAddressResponse = variant { Ok : Address; Err : text };
type GetDelegationResponse = variant { Ok : SignedDelegation; Err : text };
type GetPrincipalResponse = variant { Ok : Principal; Err : text };
type LoginDetails = record {
user_canister_pubkey : CanisterPublicKey;
expiration : Timestamp;
};
type LoginResponse = variant { Ok : LoginDetails; Err : text };
type PrepareLoginResponse = variant { Ok : SiweMessage; Err : text };
type Principal = vec nat8;
type PublicKey = vec nat8;
type Principal = blob;
type PublicKey = blob;
type SessionKey = PublicKey;
type SiweMessage = text;
type SiweSignature = text;
type Timestamp = nat64;
type Nonce = text;

type RuntimeFeature = variant {
IncludeUriInSeed;
DisableEthToPrincipalMapping;
DisablePrincipalToEthMapping;
DisablePrincipalToEthMapping
};
type SessionKey = PublicKey;

type SettingsInput = record {
uri : text;
runtime_features : opt vec RuntimeFeature;
domain : text;
statement : opt text;
scheme : opt text;
uri : text;
salt : text;
session_expires_in : opt nat64;
targets : opt vec text;
chain_id : opt nat;
scheme : opt text;
statement : opt text;
sign_in_expires_in : opt nat64;
session_expires_in : opt nat64;
targets : opt vec text;
runtime_features: opt vec RuntimeFeature;
};

type GetAddressResponse = variant {
Ok : Address;
Err : text;
};

type GetDelegationResponse = variant {
Ok : SignedDelegation;
Err : text;
};

type SignedDelegation = record {
signature : vec nat8;
delegation : Delegation;
signature : blob;
};
type SiweMessage = text;
type SiweSignature = text;
type Timestamp = nat64;
service : {
get_address : (Principal) -> (GetAddressResponse) query;
get_caller_address : () -> (GetAddressResponse) query;
get_principal : (Address) -> (GetPrincipalResponse) query;
siwe_get_delegation : (Address, SessionKey, Timestamp) -> (
GetDelegationResponse,
) query;
siwe_login : (SiweSignature, Address, SessionKey) -> (LoginResponse);
siwe_prepare_login : (Address) -> (PrepareLoginResponse);
}

type Delegation = record {
pubkey : PublicKey;
expiration : Timestamp;
targets : opt vec principal;
};

type GetPrincipalResponse = variant {
Ok : Principal;
Err : text;
};

type LoginResponse = variant {
Ok : LoginDetails;
Err : text;
};

type LoginDetails = record {
expiration : Timestamp;
user_canister_pubkey : CanisterPublicKey;
};

type PrepareLoginOkResponse = record {
siwe_message: SiweMessage;
nonce : text;
};

type PrepareLoginResponse = variant {
Ok : PrepareLoginOkResponse;
Err : text;
};

service : (settings_input : SettingsInput) -> {
"get_address" : (Principal) -> (GetAddressResponse) query;
"get_caller_address" : () -> (GetAddressResponse) query;
"get_principal" : (Address) -> (GetPrincipalResponse) query;
"siwe_prepare_login" : (Address) -> (PrepareLoginResponse);
"siwe_login" : (SiweSignature, Address, SessionKey, Nonce) -> (LoginResponse);
"siwe_get_delegation" : (Address, SessionKey, Timestamp) -> (GetDelegationResponse) query;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
export const idlFactory = ({ IDL }) => {
const RuntimeFeature = IDL.Variant({
'IncludeUriInSeed' : IDL.Null,
'DisableEthToPrincipalMapping' : IDL.Null,
'DisablePrincipalToEthMapping' : IDL.Null,
});
const SettingsInput = IDL.Record({
'uri' : IDL.Text,
'runtime_features' : IDL.Opt(IDL.Vec(RuntimeFeature)),
'domain' : IDL.Text,
'statement' : IDL.Opt(IDL.Text),
'scheme' : IDL.Opt(IDL.Text),
'salt' : IDL.Text,
'session_expires_in' : IDL.Opt(IDL.Nat64),
'targets' : IDL.Opt(IDL.Vec(IDL.Text)),
'chain_id' : IDL.Opt(IDL.Nat),
'sign_in_expires_in' : IDL.Opt(IDL.Nat64),
});
const Principal = IDL.Vec(IDL.Nat8);
const Address = IDL.Text;
const GetAddressResponse = IDL.Variant({ 'Ok' : Address, 'Err' : IDL.Text });
Expand All @@ -23,15 +40,20 @@ export const idlFactory = ({ IDL }) => {
'Err' : IDL.Text,
});
const SiweSignature = IDL.Text;
const Nonce = IDL.Text;
const CanisterPublicKey = PublicKey;
const LoginDetails = IDL.Record({
'user_canister_pubkey' : CanisterPublicKey,
'expiration' : Timestamp,
});
const LoginResponse = IDL.Variant({ 'Ok' : LoginDetails, 'Err' : IDL.Text });
const SiweMessage = IDL.Text;
const PrepareLoginOkResponse = IDL.Record({
'nonce' : IDL.Text,
'siwe_message' : SiweMessage,
});
const PrepareLoginResponse = IDL.Variant({
'Ok' : SiweMessage,
'Ok' : PrepareLoginOkResponse,
'Err' : IDL.Text,
});
return IDL.Service({
Expand All @@ -44,11 +66,30 @@ export const idlFactory = ({ IDL }) => {
['query'],
),
'siwe_login' : IDL.Func(
[SiweSignature, Address, SessionKey],
[SiweSignature, Address, SessionKey, Nonce],
[LoginResponse],
[],
),
'siwe_prepare_login' : IDL.Func([Address], [PrepareLoginResponse], []),
});
};
export const init = ({ IDL }) => { return []; };
export const init = ({ IDL }) => {
const RuntimeFeature = IDL.Variant({
'IncludeUriInSeed' : IDL.Null,
'DisableEthToPrincipalMapping' : IDL.Null,
'DisablePrincipalToEthMapping' : IDL.Null,
});
const SettingsInput = IDL.Record({
'uri' : IDL.Text,
'runtime_features' : IDL.Opt(IDL.Vec(RuntimeFeature)),
'domain' : IDL.Text,
'statement' : IDL.Opt(IDL.Text),
'scheme' : IDL.Opt(IDL.Text),
'salt' : IDL.Text,
'session_expires_in' : IDL.Opt(IDL.Nat64),
'targets' : IDL.Opt(IDL.Vec(IDL.Text)),
'chain_id' : IDL.Opt(IDL.Nat),
'sign_in_expires_in' : IDL.Opt(IDL.Nat64),
});
return [SettingsInput];
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export interface LoginDetails {
}
export type LoginResponse = { 'Ok' : LoginDetails } |
{ 'Err' : string };
export type PrepareLoginResponse = { 'Ok' : SiweMessage } |
export type Nonce = string;
export interface PrepareLoginOkResponse {
'nonce' : string,
'siwe_message' : SiweMessage,
}
export type PrepareLoginResponse = { 'Ok' : PrepareLoginOkResponse } |
{ 'Err' : string };
export type Principal = Uint8Array | number[];
export type PublicKey = Uint8Array | number[];
Expand Down Expand Up @@ -57,7 +62,7 @@ export interface _SERVICE {
GetDelegationResponse
>,
'siwe_login' : ActorMethod<
[SiweSignature, Address, SessionKey],
[SiweSignature, Address, SessionKey, Nonce],
LoginResponse
>,
'siwe_prepare_login' : ActorMethod<[Address], PrepareLoginResponse>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function prepareLoginResponse(candid: ApiPrepareLoginResponse): SiwePrepa
if ("Ok" in candid) {
return {
kind: "success",
siweMessage: candid.Ok,
siweMessage: candid.Ok.siwe_message,
nonce: candid.Ok.nonce,
};
}
if ("Err" in candid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export class SignInWithEthereumClient extends CandidService {
signature: string,
address: string,
sessionKey: Uint8Array,
nonce: string,
): Promise<PrepareDelegationResponse> {
return this.handleResponse(
this.service.siwe_login(signature, address, sessionKey),
this.service.siwe_login(signature, address, sessionKey, nonce),
loginResponse,
[signature, address, sessionKey],
[signature, address, sessionKey, nonce],
);
}

Expand Down
Loading

0 comments on commit fc7dfa2

Please sign in to comment.