@silencelaboratories/walletprovider-sdk 0.3.0 → 0.4.1

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
@@ -1,104 +1,103 @@
1
1
  # walletprovider-sdk
2
2
 
3
- The frontend library for Silent Network.
4
-
5
- # Demo
6
-
7
- Under the [demo](./demo) directory we provide the sample webpage that shows example usage of the library.
8
- In order to run it execute the following:
9
-
10
- 1. Build the library
11
-
12
- ```
13
- npm install
14
- npm run build
15
- ```
16
-
17
- 2. Run the demo
18
-
19
- ```
20
- cd demo
21
- npm install
22
- npm run dev
3
+ The client library for Silent Network Wallet Provider Service.
4
+
5
+ - [Installing](#installing)
6
+ - [Quick start](#quick-start)
7
+ - [Documentation](#documentation)
8
+ - [Features](#features)
9
+ - [Overview](#overview)
10
+ - [Authentication](#authentication)
11
+ - [Keygen](#keygen)
12
+ - [Signing](#signing)
13
+ - [Development](#development)
14
+ - [Build the library](#build-the-library)
15
+ - [End to end tests](#end-to-end-tests)
16
+ - [Generate the documentation](#generate-the-documentation)
17
+ - [Lint the code](#lint-the-code)
18
+
19
+ # Installing
20
+
21
+ ```sh
22
+ npm i @silencelaboratories/walletprovider-sdk
23
23
  ```
24
24
 
25
- The demo fetches configuration from the `.env` file. We provided example `.env` [here](./demo/.env).
25
+ # Quick start
26
26
 
27
- The demo communicates with [backend service](#the-backend). Run it before using the demo page.
27
+ Check the [demo](./demo/README.md) for a quick start guide.
28
28
 
29
- # Using the library
29
+ # Documentation
30
30
 
31
- The library is published on [npmjs](https://www.npmjs.com/package/@silencelaboratories/walletprovider-sdk) registry.
31
+ For description of classes, interfaces, types, please refer to [documentation](./docs/walletprovider-sdk.md).
32
32
 
33
- Install it in your project as usual:
33
+ # Features
34
34
 
35
- ```
36
- npm i @silencelaboratories/walletprovider-sdk
37
- ```
38
-
39
- ## The backend
35
+ - Authentication
36
+ - Keygen
37
+ - Signing
40
38
 
41
- The library communicates with backend service. The example implementation of such service is accessible [here](https://shipyard.rs/silencelaboratories/crates/wallet-provider-service). Please refer to backend documentation in order to run the service.
39
+ ## Overview
42
40
 
43
- Frontend uses [WalletProviderServiceClient](./docs/walletprovider-sdk.walletproviderserviceclient.md) object in order to connect to the backend and send requests.
41
+ The library provides API to authenticate, generate keys, and sign messages against the Silent Network. Before sending request for a distributed key or signature, users need to be authenticated to the Silent Network.
44
42
 
45
- # Documentation
46
-
47
- For description of classes, interfaces, types, please refer to [documentation](./docs/walletprovider-sdk.md).
43
+ Once authenticated, users register an ephemeral signing key pair and associate it with their identity. The ephemeral signing keys can later be used to authorize signing requests for duration of the session without the need for repeated user interaction, providing a seamless and secure authentication mechanism.
48
44
 
49
45
  ## Authentication
50
46
 
47
+ Users authenticate to Silent Network using 2 methods [Wallet-based](./docs/walletprovider-sdk.eoaauth.md) or [Passkey](./docs/walletprovider-sdk.passkeyauth.md).
51
48
 
52
- Users authenticate using **EOA wallet** or **Passkey** 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.
49
+ - [Wallet-based](./docs/walletprovider-sdk.eoaauth.md) authenticate users using their digital wallet, it runs at the same time users start doing **keygen**.
55
50
 
56
- Key generation:
57
- - [EOAAuth](./docs/walletprovider-sdk.eoaauth.md) to authenticate the user **during keygen**. The `EOAAuth` object is created with the user's wallet address.
51
+ - [Passkey](./docs/walletprovider-sdk.passkeyauth.md) has 2 steps: **register** and **login**. The user registers a passkey with the network, then logs in with the passkey while starting the **keygen** process.
58
52
 
59
- - [PasskeyAuth](./docs/walletprovider-sdk.passkeyauth.md) to authenticate the user **during keygen**. The `PasskeyAuth` object is created with the [PasskeyUser](./docs/walletprovider-sdk.passkeyuser.md), [RelyingPartyConfig](./docs/walletprovider-sdk.relyingpartyconfig.md).
60
53
 
61
- - The ephemeral public key and lifetime of the key in seconds will be associated with both `EOAAuth` and `PasskeyAuth` objects.
54
+ The [ephemeral public claim](./docs/walletprovider-sdk.eoaauth.ephclaim.md) will be associated with both [EOAAuth](./docs/walletprovider-sdk.eoaauth.md) and [PasskeyAuth](./docs/walletprovider-sdk.passkeyauth.md) objects.
62
55
 
63
- Signature generation:
64
- - [EphAuth](./docs/walletprovider-sdk.ephauth.md) to authenticate the user **during signing**. The `EphAuth` object is created with the ephemeral keypair.
56
+ - Users will use [EphAuth](./docs/walletprovider-sdk.ephauth.md) to do non-interactive authenticate **during signing**.
57
+ - The library supports 2 signing algorithms for ephemeral signing keys: `secp256k1, ed25519`
65
58
 
66
59
  ## Keygen
67
60
 
68
-
69
- The full working example is in the [demo](https://github.com/silence-laboratories/walletprovider-sdk/blob/a75d7a009fb4d3629d353d53f8c27c34190c9035/demo/src/routes/%2Bpage.svelte#L89).
61
+ The full working example is in the [demo](https://github.com/silence-laboratories/walletprovider-sdk/blob/main/demo/src/routes/%2Bpage.svelte#L172).
70
62
  The core object to use is the [NetworkSigner](./docs/walletprovider-sdk.networksigner.md). It allows to generate keys and do signatures.
71
63
 
72
- In order to create your keys, 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**.
64
+ In order to create your keys, you need two other components. The [WalletProviderServiceClient](./docs/walletprovider-sdk.walletproviderserviceclient.md) that connects to the Backend part of the SDK, and the **authenticator module**.
73
65
 
74
66
  ### Authenticate with EOA wallet
75
67
  We provide EOA authentication via [EOAAuth](./docs/walletprovider-sdk.eoaauth.md) module. Let's create the `NetworkSigner` with associated `EOAAuth` object.
76
68
 
77
69
  ```ts
70
+ const algSign = 'secp256k1'; // Signing algorithms of ephemeral key
78
71
  // Generate ephemeral secret key esk
79
- const sk = generateEphPrivateKey();
72
+ const sk = generateEphPrivateKey(algSign);
80
73
  // Derive public part epk from esk
81
- const ephPK = getEphPublicKey(sk);
74
+ const ephPK = getEphPublicKey(sk, algSign);
82
75
  // Arbitrary ID to identify the ephemeral key
83
76
  const ephId = uuidv4();
84
- // Create a client that connects to the backend service
85
- const wpClient = await createWalletProviderService(clusterConfig);
77
+ // Create ephemeral key claim instance based on the ephemeral key
78
+ const ephClaim = new EphKeyClaim(
79
+ ephId,
80
+ ephPK,
81
+ algSign,
82
+ // Lifetime of one hour
83
+ 60 * 60,
84
+ );
86
85
 
87
86
  // Create EOA authenticator, signature will include epk
88
87
  const eoaAuth = new EOAAuth(
89
- ephId,
90
88
  accountsFromBrowserWallet[0],
91
89
  new BrowserWallet(),
92
- ephPK,
93
- // Lifetime of one hour
94
- 60 * 60,
90
+ ephClaim
95
91
  );
96
92
 
93
+ // Create a client that connects to the backend service
94
+ const wpClient = await createWalletProviderService(clusterConfig);
95
+
97
96
  // Create a new signer instance
98
97
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, eoaAuth);
99
98
  ```
100
99
 
101
- Now you can generate a key, using the [generateKey](./docs/walletprovider-sdk.networksigner.authenticateandcreatekey.md) method. The method accepts optional permissions. No permissions means _allow all operations_.
100
+ Now you can generate a key, using the [generateKey](./docs/walletprovider-sdk.networksigner.generatekey.md) method. The method accepts optional permissions. No permissions means _allow all operations_.
102
101
 
103
102
  ```ts
104
103
  const permissions = {
@@ -120,22 +119,52 @@ const permissions = {
120
119
  let resp: KeygenResponse = await sdk.generateKey(JSON.stringify(permissions));
121
120
  ```
122
121
 
123
- Calling this method will cause to the Browser Wallet window to pop up, requesting the User to sign the request.
122
+ Calling this method will cause to the Digital Wallet window to pop up, requesting the User to sign the request.
124
123
 
125
124
  The returned [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.
126
125
 
127
- The `esk` key can be later used by the frontend in subsequent signgen requests for authenticating.
126
+ The ephemeral `sk` key can be later used in subsequent signgen requests for authenticating.
128
127
 
129
128
  ### Authenticate with Passkey
130
- We provide Passkey authentication via [PasskeyAuth](./docs/walletprovider-sdk.passkeyauth.md) module. Let's create the `NetworkSigner` with associated `PasskeyAuth` object.
129
+ First, we need to register user passkey to the network. We provide Passkey register via [PasskeyRegister](./docs/walletprovider-sdk.passkeyregister.md) module.
130
+ ```ts
131
+ const wpClient = await createWalletProviderService(clusterConfig);
132
+ const rpConfig: RelyingPartyConfig = {
133
+ rpId: 'localhost',
134
+ rpName: 'http://localhost:5173',
135
+ };
136
+ const userId = uuidv4();
137
+ const passkeyUser = {
138
+ id: userId,
139
+ displayName: 'Alice',
140
+ name: 'alice@gmail.com ' + userId, // For development purposes
141
+ };
142
+
143
+ const passkeyAuth = new PasskeyRegister(rpConfig, passkeyUser);
144
+ // Create a new signer instance
145
+ const sdk = new NetworkSigner(wpClient, +threshold, +partiesNumber, passkeyAuth);
146
+
147
+ // Register a new passkey
148
+ let resp: RegisterPasskeyResponse = await sdk.registerPasskey();
149
+ ```
150
+
151
+ We provide Passkey login authentication via [PasskeyAuth](./docs/walletprovider-sdk.passkeyauth.md) module. Let's create the `NetworkSigner` with associated `PasskeyAuth` object.
131
152
 
132
153
  ```ts
154
+ const algSign = 'secp256k1'; // Signing algorithms of ephemeral key
133
155
  // Generate ephemeral secret key esk
134
- const sk = generateEphPrivateKey();
156
+ const sk = generateEphPrivateKey(algSign);
135
157
  // Derive public part epk from esk
136
- const ephPK = getEphPublicKey(sk);
158
+ const ephPK = getEphPublicKey(sk, algSign);
137
159
  // Arbitrary ID to identify the ephemeral key
138
160
  const ephId = uuidv4();
161
+ // Create ephemeral key claim instance based on the ephemeral key
162
+ const ephClaim = new EphKeyClaim(
163
+ ephId,
164
+ ephPK,
165
+ // Lifetime of one hour
166
+ 60 * 60,
167
+ );
139
168
  // Create a client that connects to the backend service
140
169
  const wpClient = await createWalletProviderService(clusterConfig);
141
170
  // Here we configure the relying party for local development
@@ -143,88 +172,82 @@ const rpConfig: RelyingPartyConfig = {
143
172
  rpId: 'localhost',
144
173
  rpName: 'http://localhost:5173',
145
174
  };
146
- // Information about the owner of the passkey
147
- const passkeyUser: PasskeyUser = {
148
- id: userId,
149
- displayName: 'Alice',
150
- name: 'alice@gmail.com ' + userId, // For development purposes
151
- };
152
175
 
153
176
  // Get passkey credential id from your storage
154
177
  const credentialId = getPasskeyCredentialId();
155
- // Create EOA authenticator, signature will include epk
178
+ // Create Passkey authenticator, signature will include epk
156
179
  const passkeyAuth = new PasskeyAuth(
157
180
  rpConfig,
158
- passkeyUser,
159
- ephId,
160
- ephPK,
161
- // Lifetime of one hour
162
- 60 * 60,
163
- // If credentialId is null, we will do passkey register, otherwise, we will do passkey auth/login
181
+ // We will do passkey auth/login with the provided credentialId
164
182
  credentialId,
183
+ ephClaim,
165
184
  );
166
185
 
167
186
  // Create a new signer instance
168
187
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, passkeyAuth);
169
188
  ```
170
189
 
171
- Now you can generate a key like in the EOA example by calling the [generateKey](./docs/walletprovider-sdk.networksigner.authenticateandcreatekey.md) method.
190
+ Now you can generate a key like in the EOA example by calling the [generateKey](./docs/walletprovider-sdk.networksigner.generatekey.md) method.
172
191
 
173
- Calling this method will prompt the browser to request Passkey User Verification. Once user verification is done, the [KeygenResponse](./docs/walletprovider-sdk.keygenresponse.md) is returned.
192
+ Calling this method will prompt the device to request [Passkey User Verification](https://web.dev/articles/webauthn-user-verification). Once user verification is done, the [KeygenResponse](./docs/walletprovider-sdk.keygenresponse.md) is returned.
174
193
 
175
- The `esk` key can be later used by the frontend in subsequent signgen requests for authenticating.
194
+ The `sk` key can be later used in subsequent signgen requests.
176
195
 
177
196
  ## Signing
178
197
 
179
- The full signing example is [here](https://github.com/silence-laboratories/walletprovider-sdk/blob/a75d7a009fb4d3629d353d53f8c27c34190c9035/demo/src/routes/%2Bpage.svelte#L170).
198
+ The full signing example is [here](https://github.com/silence-laboratories/walletprovider-sdk/blob/main/demo/src/routes/%2Bpage.svelte#L228).
180
199
 
181
- Let's create NetworkSigner for signing. Note the `EphAuth` is used to avoid user interaction when generating the signatures.
200
+ The workflow is similar to the keygen process. The core objects to use are the [NetworkSigner](./docs/walletprovider-sdk.networksigner.md), WalletProviderServiceClient, and the [ephemeral authenticator module](./docs/walletprovider-sdk.ephauth.md).
182
201
  ```ts
183
- const authModule = new EphAuth(ephId, ephSK);
202
+ const authModule = new EphAuth(selectedEphId, ephSK, selectedEphSignAlg);
184
203
  // Create a new signer instance
185
204
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, authModule);
186
205
  ```
187
206
 
188
207
 
189
- Use the [NetworkSigner.signMessage](./docs/walletprovider-sdk.networksigner.authenticateandsign.md) method in order to generate a signature.
208
+ Use the [NetworkSigner.signMessage](./docs/walletprovider-sdk.networksigner.signMessage.md) method in order to generate a signature.
190
209
 
191
210
  ```ts
192
- let signMessage = JSON.stringify({
193
- message: JSON.stringify({
194
- userOperation: {
195
- sender: '0x8d4cb2540d993fe34c646299f1ab4af3012ff34c',
196
- nonce: '0x7',
197
- initCode: '0x',
198
- callData: '0000189...',
199
- callGasLimit: '0x18473',
200
- verificationGasLimit: '0x18473',
201
- preVerificationGas: '66768',
202
- maxFeePerGas: '',
203
- maxPriorityFeePerGas: '',
204
- paymasterAndData: '0x',
205
- },
206
- entryPointVersion: 'v0.6.0',
207
- entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
208
- chainId: 80002,
209
- }),
210
- requestType: 'accountAbstractionTx',
211
- });
211
+ const signMessage = new SignRequestBuilder()
212
+ .setRequest(
213
+ uuidv4(),
214
+ JSON.stringify({
215
+ userOperation: {
216
+ sender: '0x8d4cb2540d993fe34c646299f1ab4af3012ff34c',
217
+ nonce: '0x7',
218
+ initCode: '0x',
219
+ callData: '0000...',
220
+ callGasLimit: '0x18473',
221
+ verificationGasLimit: '0x18473',
222
+ preVerificationGas: '66768',
223
+ maxFeePerGas: '',
224
+ maxPriorityFeePerGas: '',
225
+ paymasterAndData: '0x',
226
+ },
227
+ entryPointVersion: 'v0.6.0',
228
+ entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
229
+ chainId: 80002,
230
+ }),
231
+ 'accountAbstractionTx',
232
+ )
233
+ .setRequest(
234
+ uuidv4(),
235
+ '4549502d313931206d657373616765',
236
+ 'rawBytes',
237
+ )
238
+ .build();
212
239
 
213
240
  let resp = await sdk.signMessage(selectedKeyId, signMessage);
214
241
  ```
215
242
 
216
243
  The [SignResponse](./docs/walletprovider-sdk.signresponse.md) contains the signature `sign` and the recovery ID `recid`.
217
244
 
245
+ # Development
218
246
 
219
- ## Install dependencies
220
-
221
- ```bash
222
- npm install
223
- ```
224
-
225
- ## Build
247
+ ## Build the library
226
248
 
227
249
  ```bash
250
+ npm i
228
251
  npm run build
229
252
  ```
230
253
 
@@ -233,14 +256,14 @@ The output will be in the `dist` folder.
233
256
  ## End to end tests
234
257
  Please refer to [README.md](./e2e-tests/README.md) for instructions how to execute them.
235
258
 
236
- ## Format the code
259
+ ## Generate the documentation
237
260
 
238
261
  ```bash
239
- npm run format
262
+ npm run docs
240
263
  ```
241
264
 
242
- ## Generate the documentation
265
+ ## Lint the code
243
266
 
244
267
  ```bash
245
- npm run docs
268
+ ./local_ci.sh
246
269
  ```
@@ -1,10 +1,10 @@
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 } from './networkSigner';
4
+ import { MetadataSetupOpts, KeygenSetupOpts } from '../setupMessage';
5
5
  import { type UserAuthentication } from './authentication';
6
6
  import { type TypedDataDomain } from 'viem';
7
- import { EphClaim } from './ephemeralAuthentication';
7
+ import { EphKeyClaim } from './ephemeralAuthentication';
8
8
  export type FieldDefinition = {
9
9
  name: string;
10
10
  type: string;
@@ -45,13 +45,23 @@ export interface IBrowserWallet {
45
45
  */
46
46
  signTypedData<T>(from: string, request: TypedData<T>): Promise<unknown>;
47
47
  }
48
+ type RequestToSign<T> = {
49
+ setup: T;
50
+ challenge: string;
51
+ };
52
+ export declare const EIP712SilentShardAuthenticationDomain: {
53
+ name: string;
54
+ version: string;
55
+ };
56
+ export declare function createTypedRequest(setup: KeygenSetupOpts | MetadataSetupOpts, aggregated_challenge: string, ephClaim: EphKeyClaim): TypedData<RequestToSign<KeygenSetupOpts | MetadataSetupOpts>>;
48
57
  /** Present the request to the User using wallet UI, and ask for sign.
49
58
  * The signature is the authorization for keygen operation
50
59
  */
51
60
  export declare function authenticateUsingEOA({ setup, eoa, challenge, browserWallet, ephClaim, }: {
52
- setup: KeygenSetupOpts;
61
+ setup: KeygenSetupOpts | MetadataSetupOpts;
53
62
  eoa: string;
54
63
  challenge: string;
55
64
  browserWallet: IBrowserWallet;
56
- ephClaim: EphClaim;
65
+ ephClaim: EphKeyClaim;
57
66
  }): Promise<UserAuthentication>;
67
+ export {};
@@ -1,7 +1,7 @@
1
- import { AddEphemeralKeyOpts, KeygenSetupOpts, SignSetupOpts } from './networkSigner';
1
+ import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from '../setupMessage';
2
2
  import { IBrowserWallet } from './EOAauthentication';
3
3
  import { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
4
- import { EphClaim } from './ephemeralAuthentication';
4
+ import { EphKeyClaim, SignAlgorithm } from './ephemeralAuthentication';
5
5
  /** Type of the request authentication
6
6
  * @alpha
7
7
  */
@@ -16,12 +16,12 @@ export type UserAuthentication = {
16
16
  };
17
17
  export interface AuthModule {
18
18
  authenticate({ setup, challenge, }: {
19
- setup: KeygenSetupOpts | SignSetupOpts | AddEphemeralKeyOpts;
19
+ setup: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts;
20
20
  challenge: string;
21
21
  }): Promise<UserAuthentication>;
22
22
  }
23
23
  export interface DkgAuthModule extends AuthModule {
24
- get ephClaim(): EphClaim;
24
+ getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
25
25
  }
26
26
  /** The `EOAAuth` implementing Externally Owned Account authentication.
27
27
  * @alpha
@@ -31,27 +31,31 @@ export declare class EOAAuth implements DkgAuthModule {
31
31
  private browserWallet;
32
32
  /** the ETH address that is used to do EOA authentication */
33
33
  private eoa;
34
- /** Ephemeral key claim */
35
- ephClaim: EphClaim;
34
+ /** Ephemeral key claim populated for non batched requests*/
35
+ ephClaim?: EphKeyClaim;
36
+ /** Ephemeral key claims map contains pairs of
37
+ * SignatureAlgorithms and their appropriate EphKeyClaims in case of batched requests */
38
+ ephClaims?: Map<string, EphKeyClaim>;
36
39
  /**
37
40
  *
38
- * @param ephId - Ephemeral key ID
39
41
  * @param eoa - Ethereum address
40
42
  * @param browserWallet - Interface to the wallet provider, like MetaMask, that is used to sign the requests
41
- * @param ephPK - Ephemeral public key
42
- * @param lifetime - Lifetime of the ephemeral key. Default is 1 hour
43
+ * @param ephClaimOptions - Either EphKeyClaim or Map of SignatureAlgorithms and their appropriate EphKeyClaims
43
44
  */
44
- constructor(ephId: string, eoa: string, browserWallet: IBrowserWallet, ephPK: Uint8Array, lifetime: number);
45
+ constructor(eoa: string, browserWallet: IBrowserWallet, ephClaimOptions: {
46
+ ephClaim?: EphKeyClaim;
47
+ ephClaims?: Map<string, EphKeyClaim>;
48
+ });
45
49
  private validateInputs;
50
+ getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
46
51
  /**
47
52
  * Prepares a message to present on the Browser Wallet window and requests to sign it.
48
53
  * @param setup - Keygen setup options
49
54
  * @param challenge - the challenge received from the backend
50
- *
51
55
  * @public
52
56
  */
53
- authenticate({ setup, challenge }: {
54
- setup: KeygenSetupOpts;
57
+ authenticate({ setup, challenge, }: {
58
+ setup: KeygenSetupOpts | MetadataSetupOpts;
55
59
  challenge: string;
56
60
  }): Promise<UserAuthentication>;
57
61
  }
@@ -70,8 +74,9 @@ export declare class EphAuth implements AuthModule {
70
74
  *
71
75
  * @param ephId - Ephemeral key ID
72
76
  * @param ephSK - Ephemeral secret key
77
+ * @param signAlg - Signature algorithm
73
78
  */
74
- constructor(ephId: string, ephSK: Uint8Array);
79
+ constructor(ephId: string, ephSK: Uint8Array, signAlg: SignAlgorithm);
75
80
  /**
76
81
  * Prepares a message to present on the Browser Wallet window and requests to sign it.
77
82
  * @param setup - Signgen setup options
@@ -79,8 +84,8 @@ export declare class EphAuth implements AuthModule {
79
84
  *
80
85
  * @public
81
86
  */
82
- authenticate({ setup, challenge }: {
83
- setup: SignSetupOpts;
87
+ authenticate({ setup, challenge, }: {
88
+ setup: SignSetupOpts | MetadataSetupOpts;
84
89
  challenge: string;
85
90
  }): Promise<UserAuthentication>;
86
91
  }
@@ -92,22 +97,44 @@ export declare class PasskeyAuth implements DkgAuthModule {
92
97
  private rpConfig;
93
98
  /** ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field */
94
99
  private allowCredentialId;
100
+ /** Ephemeral key claim populated for non batched requests*/
101
+ ephClaim?: EphKeyClaim;
102
+ /** Ephemeral key claims map contains pairs of
103
+ * SignatureAlgorithms and their appropriate EphKeyClaims in case of batched requests */
104
+ ephClaims?: Map<string, EphKeyClaim>;
105
+ /**
106
+ *
107
+ * @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
108
+ * @param allowCredentialId - ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field
109
+ * @param ephClaimOptions - Either EphKeyClaim or Map of SignatureAlgorithms and their appropriate EphKeyClaims
110
+ */
111
+ constructor(rpConfig: RelyingPartyConfig, allowCredentialId: string, ephClaimOptions: {
112
+ ephClaim?: EphKeyClaim;
113
+ ephClaims?: Map<string, EphKeyClaim>;
114
+ });
115
+ private validateInputs;
116
+ getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
117
+ authenticate({ setup, challenge, }: {
118
+ setup: KeygenSetupOpts | MetadataSetupOpts;
119
+ challenge: string;
120
+ }): Promise<UserAuthentication>;
121
+ }
122
+ /** The `AuthModule` implementing Passkey register.
123
+ * @alpha
124
+ */
125
+ export declare class PasskeyRegister implements AuthModule {
126
+ /** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
127
+ private rpConfig;
95
128
  /** Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user */
96
129
  private user;
97
- /** Ephemeral key claim */
98
- ephClaim: EphClaim;
99
130
  /**
100
131
  *
101
132
  * @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
102
133
  * @param user - Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user
103
- * @param allowCredentialId - ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field
104
- * @param ephId - Ephemeral key ID
105
- * @param ephPK - Ephemeral public key
106
- * @param lifetime - Lifetime of the ephemeral key. Default is 1 hour
107
134
  */
108
- constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser | null, allowCredentialId: string | null, ephId: string, ephPK: Uint8Array, lifetime: number);
135
+ constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser);
109
136
  authenticate({ setup, challenge, }: {
110
- setup: KeygenSetupOpts | AddEphemeralKeyOpts;
137
+ setup: MetadataSetupOpts;
111
138
  challenge: string;
112
139
  }): Promise<UserAuthentication>;
113
140
  }
@@ -0,0 +1,44 @@
1
+ import { UserAuthentication } from './authentication';
2
+ import { MetadataSetupOpts, SignSetupOpts } from '../setupMessage';
3
+ /**
4
+ * Supported signature algorithms for ephemeral key
5
+ * @alpha
6
+ */
7
+ export type SignAlgorithm = 'ed25519' | 'secp256k1';
8
+ /** The `EphKeyClaim` object represents the public claim of the ephemeral key.
9
+ * @alpha
10
+ */
11
+ export declare class EphKeyClaim {
12
+ ephId: string;
13
+ ephPK: string;
14
+ signAlg: SignAlgorithm;
15
+ expiry: number;
16
+ /**
17
+ *
18
+ * @param ephId - Ephemeral key ID
19
+ * @param ephPK - Ephemeral public key
20
+ * @param signAlg - Signature algorithm.
21
+ * @param lifetime - Lifetime of the ephemeral key. Default is 1 hour
22
+ */
23
+ constructor(ephId: string, ephPK: Uint8Array, signAlg: SignAlgorithm, lifetime?: number);
24
+ private validateInputs;
25
+ toJSON(): string;
26
+ }
27
+ /** Locally sign the signature requests to network without asking the user, the ephSK is registered during keygen.
28
+ * The signature is the authorization for signgen operation
29
+ */
30
+ export declare function authenticateUsingEphKey({ setup, challenge, ephSK, ephClaim, }: {
31
+ setup: SignSetupOpts | MetadataSetupOpts;
32
+ challenge: string;
33
+ ephSK: Uint8Array;
34
+ ephClaim: EphKeyClaim;
35
+ }): Promise<UserAuthentication>;
36
+ export declare function genHexSignature(msg: Uint8Array, ephSK: Uint8Array, signAlg: SignAlgorithm): Promise<string>;
37
+ /** Generate Ephemeral `privateKey`
38
+ * @public
39
+ */
40
+ export declare function generateEphPrivateKey(algSign: SignAlgorithm): Uint8Array;
41
+ /** Derive Ephemeral `publicKey` from `privateKey` returned from `generateEphPrivateKey`
42
+ * @public
43
+ */
44
+ export declare function getEphPublicKey(ephSK: Uint8Array, algSign: SignAlgorithm): Uint8Array;
@@ -1,5 +1,5 @@
1
1
  import { UserAuthentication } from './authentication';
2
- import { EphClaim } from './ephemeralAuthentication';
2
+ import { EphKeyClaim } from './ephemeralAuthentication';
3
3
  /** Information about the user currently registering. Read more: https://w3c.github.io/webauthn/#dom-publickeycredentialcreationoptions-user
4
4
  * @alpha
5
5
  * */
@@ -15,15 +15,14 @@ export type RelyingPartyConfig = {
15
15
  rpName: string;
16
16
  rpId: string;
17
17
  };
18
- export declare function passkeyRegister({ user, challenge, rpConfig, ephClaim, }: {
18
+ export declare function passkeyRegister({ user, challenge, rpConfig, }: {
19
19
  user: PasskeyUser;
20
20
  challenge: string;
21
21
  rpConfig: RelyingPartyConfig;
22
- ephClaim: EphClaim;
23
22
  }): Promise<UserAuthentication>;
24
23
  export declare function passkeyLogin({ challenge, allowCredentialId, rpConfig, ephClaim, }: {
25
24
  challenge: string;
26
25
  allowCredentialId: string | null;
27
26
  rpConfig: RelyingPartyConfig;
28
- ephClaim: EphClaim;
27
+ ephClaim: EphKeyClaim;
29
28
  }): Promise<UserAuthentication>;