@silencelaboratories/walletprovider-sdk 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,19 +46,46 @@ Frontend uses [WalletProviderServiceClient](./docs/walletprovider-sdk.walletprov
46
46
 
47
47
  For description of classes, interfaces, types, please refer to [documentation](./docs/walletprovider-sdk.md).
48
48
 
49
+ ## Authentication
50
+
51
+
52
+ Users authenticate using an EOA wallet during **key generation** and register an ephemeral signing key pair and associates it with their identity.
53
+
54
+ Frontend can later use the ephemeral signing key pair to authorize **signing requests** for duration of the session without the need for repeated user interaction, providing a seamless and secure authentication mechanism.
55
+
56
+ We use [EOAAuth](./docs/walletprovider-sdk.eoaauth.md) to authenticate the user **during keygen**. The `EOAAuth` object is created with the user's wallet address, ephemeral public key, and lifetime of the key in seconds.
57
+
58
+ We then use [EphAuth](./docs/walletprovider-sdk.ephauth.md) to authenticate the user **during signing**. The `EphAuth` object is created with the user's wallet address and ephemeral keypair.
59
+
49
60
  ## Keygen
50
61
 
51
- The full working example is in the [demo](./demo/src/routes/%2Bpage.svelte#L87).
62
+
63
+ The full working example is in the [demo](https://github.com/silence-laboratories/walletprovider-sdk/blob/a75d7a009fb4d3629d353d53f8c27c34190c9035/demo/src/routes/%2Bpage.svelte#L89).
52
64
  The core object to use is the [NetworkSigner](./docs/walletprovider-sdk.networksigner.md).
53
65
 
54
66
  It allows to generate keys and do signatures. In order to create, you need two other components. The [WalletProviderServiceClient](./docs/walletprovider-sdk.walletproviderserviceclient.md) that connects to the Backend part of the SDK, and the authentication module. Currently we provide EOA authentication via [EOAAuth](./docs/walletprovider-sdk.eoaauth.md).
55
67
 
68
+
56
69
  Let's create the `NetworkSigner`
57
70
 
58
71
  ```ts
72
+ // Generate ephemeral secret key esk
73
+ const sk = ed.utils.randomPrivateKey();
74
+ ephSK = sk;
75
+ // Derive public part epk from esk
76
+ ephPK = await ed.getPublicKeyAsync(sk);
77
+
78
+ // Create a client that connects to the backend service
59
79
  const wpClient = await createWalletProviderService(clusterConfig);
60
- // Authenticate using EOA
61
- const eoaAuth = new EOAAuth(accountsFromBrowserWallet[0], new BrowserWallet());
80
+
81
+ // Create EOA authenticator, signature will include epk
82
+ const eoaAuth = new EOAAuth(
83
+ accountsFromBrowserWallet[0],
84
+ new BrowserWallet(),
85
+ ephPK,
86
+ // Lifetime of one hour
87
+ 60 * 60,
88
+ );
62
89
 
63
90
  // Create a new signer instance
64
91
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, eoaAuth);
@@ -90,9 +117,19 @@ Calling this method will cause to the Browser Wallet window to pop up, requestin
90
117
 
91
118
  The [KeygenResponse](./docs/walletprovider-sdk.keygenresponse.md) contains `keyId` and `publicKey`. The `publicKey` is the public part of the key generated by Silent Network. Use the `keyId` in subsequent calls to sign.
92
119
 
120
+ The `esk` key can be later used by the frontend in subsequent signgen requests for authenticating.
121
+
93
122
  ## Signing
94
123
 
95
- The full signing example is [here](./demo/src/routes/%2Bpage.svelte#L158).
124
+ The full signing example is [here](https://github.com/silence-laboratories/walletprovider-sdk/blob/a75d7a009fb4d3629d353d53f8c27c34190c9035/demo/src/routes/%2Bpage.svelte#L170).
125
+
126
+ Let's create NetworkSigner for signing. Note the `EphAuth` is used to avoid user interaction when generating the signatures.
127
+ ```ts
128
+ const authModule = new EphAuth(accountsFromBrowserWallet[0], ephSK!);
129
+ // Create a new signer instance
130
+ const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, authModule);
131
+ ```
132
+
96
133
 
97
134
  Use the [NetworkSigner.authenticateAndSign](./docs/walletprovider-sdk.networksigner.authenticateandsign.md) method in order to generate a signature.
98
135
 
@@ -1,9 +1,14 @@
1
1
  /** Externally Owned Account (EOA) atuhentication. Uses secret key stored on a wallet to sign requests.
2
2
  * The requests are presented to the user in a readable form by using TypedData (EIP712).
3
3
  */
4
- import { KeygenSetupOpts, type SignSetupOpts } from './networkSigner.ts';
4
+ import { KeygenSetupOpts, SignSetupOpts } from './networkSigner.ts';
5
5
  import { type UserAuthentication } from './authentication.ts';
6
- import type { TypedDataDomain } from 'viem';
6
+ import { type TypedDataDomain } from 'viem';
7
+ export type EphClaim = {
8
+ eoa: string;
9
+ ephPK: string;
10
+ expiry: number;
11
+ };
7
12
  export type FieldDefinition = {
8
13
  name: string;
9
14
  type: string;
@@ -47,10 +52,22 @@ export interface IBrowserWallet {
47
52
  /** Present the request to the User using wallet UI, and ask for sign.
48
53
  * The signature is the authorization for the operation
49
54
  */
50
- export declare function authenticateUsingEOA({ setup, user_id, challenge, browserWallet, }: {
51
- setup: KeygenSetupOpts | SignSetupOpts;
55
+ export declare function authenticateUsingEOA({ setup, user_id, challenge, browserWallet, ephPK, lifetime, }: {
56
+ setup: KeygenSetupOpts;
52
57
  user_id: string;
53
58
  challenge: string;
54
59
  browserWallet: IBrowserWallet;
60
+ ephPK: Uint8Array;
61
+ lifetime: number;
62
+ }): Promise<UserAuthentication>;
63
+ /** Present the request to the User using wallet UI, and ask for sign.
64
+ * The signature is the authorization for the operation
65
+ */
66
+ export declare function authenticateUsingEphKey({ setup, user_id, challenge, ephSK, ephPK, }: {
67
+ setup: SignSetupOpts;
68
+ user_id: string;
69
+ challenge: string;
70
+ ephSK: Uint8Array;
71
+ ephPK: Uint8Array;
55
72
  }): Promise<UserAuthentication>;
56
73
  //# sourceMappingURL=EOAauthentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EOAauthentication.d.ts","sourceRoot":"","sources":["../src/EOAauthentication.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAmB,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC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}
@@ -32,7 +32,11 @@ export declare class EOAAuth implements AuthModule {
32
32
  userId: string;
33
33
  /** An interface to the wallet, like MetaMask, that is used to sign the requests */
34
34
  browserWallet: IBrowserWallet;
35
- constructor(userId: string, browserWallet: IBrowserWallet);
35
+ /** Public key of the ephemeral key */
36
+ ephPK: Uint8Array;
37
+ /** Lifetime of the ephemeral key */
38
+ lifetime: number;
39
+ constructor(userId: string, browserWallet: IBrowserWallet, ephPK: Uint8Array, lifetime?: number);
36
40
  /**
37
41
  * Prepares a message to present on the Browser Wallet window and requests to sign it.
38
42
  * @param setup - either Keygen or Sign setup options
@@ -45,4 +49,22 @@ export declare class EOAAuth implements AuthModule {
45
49
  challenge: string;
46
50
  }): Promise<UserAuthentication>;
47
51
  }
52
+ /** An Ephmeral key used to locally sign the signature requests to network.
53
+ * This eph key is registered during keygen. The key is used to sign the requests without
54
+ * asking the user to sign the request each time.
55
+ * The auth module is only used for signing requests to the network.
56
+ * */
57
+ export declare class EphAuth implements AuthModule {
58
+ /** User ID, typically the ETH address that is used to do authentication */
59
+ userId: string;
60
+ /** Secret key of the ephemeral keypair */
61
+ ephSK: Uint8Array;
62
+ /** Public key of the ephemeral keypair */
63
+ ephPK: Uint8Array;
64
+ constructor(userId: string, ephSK: Uint8Array);
65
+ authenticate({ setup, challenge, }: {
66
+ setup: KeygenSetupOpts | SignSetupOpts;
67
+ challenge: string;
68
+ }): Promise<UserAuthentication>;
69
+ }
48
70
  //# sourceMappingURL=authentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAE3E;;GAEG;AACH,oBAAY,UAAU;IACpB,oDAAoD;IACpD,GAAG,IAAA;IACH,wBAAwB;IACxB,IAAI,IAAA;CACL;AAED,MAA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 @@
1
1
  export { NetworkSigner, SignResponse, KeygenResponse } from './networkSigner.ts';
2
- export { AuthMethod, EOAAuth } from './authentication.ts';
2
+ export { AuthMethod, EOAAuth, EphAuth } from './authentication.ts';
3
3
  export type { IBrowserWallet, TypedData } from './EOAauthentication.ts';
4
4
  export type { ClientConfig, IWalletProviderServiceClient } from './walletProviderServiceClientInterface.ts';
5
5
  export { WalletProviderServiceClient } from './walletProviderServiceClient.ts';
6
+ export { computeAddress } from './viemSigner.ts';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE1D,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExE,YAAY,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AAC5G,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExE,YAAY,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AAC5G,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}