@silencelaboratories/walletprovider-sdk 0.2.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,105 +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 = ed.utils.randomPrivateKey();
80
- ephSK = sk;
72
+ const sk = generateEphPrivateKey(algSign);
81
73
  // Derive public part epk from esk
82
- ephPK = await ed.getPublicKeyAsync(sk);
74
+ const ephPK = getEphPublicKey(sk, algSign);
83
75
  // Arbitrary ID to identify the ephemeral key
84
76
  const ephId = uuidv4();
85
- // Create a client that connects to the backend service
86
- 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
+ );
87
85
 
88
86
  // Create EOA authenticator, signature will include epk
89
87
  const eoaAuth = new EOAAuth(
90
- ephId,
91
88
  accountsFromBrowserWallet[0],
92
89
  new BrowserWallet(),
93
- ephPK,
94
- // Lifetime of one hour
95
- 60 * 60,
90
+ ephClaim
96
91
  );
97
92
 
93
+ // Create a client that connects to the backend service
94
+ const wpClient = await createWalletProviderService(clusterConfig);
95
+
98
96
  // Create a new signer instance
99
97
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, eoaAuth);
100
98
  ```
101
99
 
102
- Now you can generate a key, using the [authenticateAndCreateKey](./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_.
103
101
 
104
102
  ```ts
105
103
  const permissions = {
@@ -118,26 +116,55 @@ const permissions = {
118
116
  };
119
117
 
120
118
  // Generate a new key
121
- let resp: KeygenResponse = await sdk.authenticateAndCreateKey(JSON.stringify(permissions));
119
+ let resp: KeygenResponse = await sdk.generateKey(JSON.stringify(permissions));
122
120
  ```
123
121
 
124
- 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.
125
123
 
126
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.
127
125
 
128
- 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.
129
127
 
130
128
  ### Authenticate with Passkey
131
- 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.
132
152
 
133
153
  ```ts
154
+ const algSign = 'secp256k1'; // Signing algorithms of ephemeral key
134
155
  // Generate ephemeral secret key esk
135
- const sk = ed.utils.randomPrivateKey();
136
- ephSK = sk;
156
+ const sk = generateEphPrivateKey(algSign);
137
157
  // Derive public part epk from esk
138
- ephPK = await ed.getPublicKeyAsync(sk);
158
+ const ephPK = getEphPublicKey(sk, algSign);
139
159
  // Arbitrary ID to identify the ephemeral key
140
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
+ );
141
168
  // Create a client that connects to the backend service
142
169
  const wpClient = await createWalletProviderService(clusterConfig);
143
170
  // Here we configure the relying party for local development
@@ -145,88 +172,82 @@ const rpConfig: RelyingPartyConfig = {
145
172
  rpId: 'localhost',
146
173
  rpName: 'http://localhost:5173',
147
174
  };
148
- // Information about the owner of the passkey
149
- const passkeyUser: PasskeyUser = {
150
- id: userId,
151
- displayName: 'Alice',
152
- name: 'alice@gmail.com ' + userId, // For development purposes
153
- };
154
175
 
155
176
  // Get passkey credential id from your storage
156
177
  const credentialId = getPasskeyCredentialId();
157
- // Create EOA authenticator, signature will include epk
178
+ // Create Passkey authenticator, signature will include epk
158
179
  const passkeyAuth = new PasskeyAuth(
159
180
  rpConfig,
160
- passkeyUser,
161
- ephId,
162
- ephPK,
163
- // Lifetime of one hour
164
- 60 * 60,
165
- // 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
166
182
  credentialId,
183
+ ephClaim,
167
184
  );
168
185
 
169
186
  // Create a new signer instance
170
187
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, passkeyAuth);
171
188
  ```
172
189
 
173
- Now you can generate a key like in the EOA example by calling the [authenticateAndCreateKey](./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.
174
191
 
175
- 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.
176
193
 
177
- 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.
178
195
 
179
196
  ## Signing
180
197
 
181
- 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).
182
199
 
183
- 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).
184
201
  ```ts
185
- const authModule = new EphAuth(ephId, ephSK);
202
+ const authModule = new EphAuth(selectedEphId, ephSK, selectedEphSignAlg);
186
203
  // Create a new signer instance
187
204
  const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, authModule);
188
205
  ```
189
206
 
190
207
 
191
- Use the [NetworkSigner.authenticateAndSign](./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.
192
209
 
193
210
  ```ts
194
- let signMessage = JSON.stringify({
195
- message: JSON.stringify({
196
- userOperation: {
197
- sender: '0x8d4cb2540d993fe34c646299f1ab4af3012ff34c',
198
- nonce: '0x7',
199
- initCode: '0x',
200
- callData: '0000189...',
201
- callGasLimit: '0x18473',
202
- verificationGasLimit: '0x18473',
203
- preVerificationGas: '66768',
204
- maxFeePerGas: '',
205
- maxPriorityFeePerGas: '',
206
- paymasterAndData: '0x',
207
- },
208
- entryPointVersion: 'v0.6.0',
209
- entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
210
- chainId: 80002,
211
- }),
212
- requestType: 'accountAbstractionTx',
213
- });
214
-
215
- let resp = await sdk.authenticateAndSign(selectedKeyId, signMessage);
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();
239
+
240
+ let resp = await sdk.signMessage(selectedKeyId, signMessage);
216
241
  ```
217
242
 
218
243
  The [SignResponse](./docs/walletprovider-sdk.signresponse.md) contains the signature `sign` and the recovery ID `recid`.
219
244
 
245
+ # Development
220
246
 
221
- ## Install dependencies
222
-
223
- ```bash
224
- npm install
225
- ```
226
-
227
- ## Build
247
+ ## Build the library
228
248
 
229
249
  ```bash
250
+ npm i
230
251
  npm run build
231
252
  ```
232
253
 
@@ -235,14 +256,14 @@ The output will be in the `dist` folder.
235
256
  ## End to end tests
236
257
  Please refer to [README.md](./e2e-tests/README.md) for instructions how to execute them.
237
258
 
238
- ## Format the code
259
+ ## Generate the documentation
239
260
 
240
261
  ```bash
241
- npm run format
262
+ npm run docs
242
263
  ```
243
264
 
244
- ## Generate the documentation
265
+ ## Lint the code
245
266
 
246
267
  ```bash
247
- npm run docs
268
+ ./local_ci.sh
248
269
  ```
@@ -1,9 +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 { EphKeyClaim } from './ephemeralAuthentication';
7
8
  export type FieldDefinition = {
8
9
  name: string;
9
10
  type: string;
@@ -44,15 +45,23 @@ export interface IBrowserWallet {
44
45
  */
45
46
  signTypedData<T>(from: string, request: TypedData<T>): Promise<unknown>;
46
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>>;
47
57
  /** Present the request to the User using wallet UI, and ask for sign.
48
58
  * The signature is the authorization for keygen operation
49
59
  */
50
- export declare function authenticateUsingEOA({ setup, ephId, eoa, challenge, browserWallet, ephPK, lifetime, }: {
51
- setup: KeygenSetupOpts;
52
- ephId: string;
60
+ export declare function authenticateUsingEOA({ setup, eoa, challenge, browserWallet, ephClaim, }: {
61
+ setup: KeygenSetupOpts | MetadataSetupOpts;
53
62
  eoa: string;
54
63
  challenge: string;
55
64
  browserWallet: IBrowserWallet;
56
- ephPK: Uint8Array;
57
- lifetime: number;
65
+ ephClaim: EphKeyClaim;
58
66
  }): Promise<UserAuthentication>;
67
+ export {};
@@ -0,0 +1,140 @@
1
+ import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from '../setupMessage';
2
+ import { IBrowserWallet } from './EOAauthentication';
3
+ import { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
4
+ import { EphKeyClaim, SignAlgorithm } from './ephemeralAuthentication';
5
+ /** Type of the request authentication
6
+ * @alpha
7
+ */
8
+ export type UserCredentials = {
9
+ id: string;
10
+ method: 'eoa' | 'ephemeral' | 'passkey';
11
+ credentials: string;
12
+ };
13
+ export type UserAuthentication = {
14
+ credentials: UserCredentials;
15
+ signature: string;
16
+ };
17
+ export interface AuthModule {
18
+ authenticate({ setup, challenge, }: {
19
+ setup: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts;
20
+ challenge: string;
21
+ }): Promise<UserAuthentication>;
22
+ }
23
+ export interface DkgAuthModule extends AuthModule {
24
+ getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
25
+ }
26
+ /** The `EOAAuth` implementing Externally Owned Account authentication.
27
+ * @alpha
28
+ */
29
+ export declare class EOAAuth implements DkgAuthModule {
30
+ /** An interface to the wallet, like MetaMask, that is used to sign the requests */
31
+ private browserWallet;
32
+ /** the ETH address that is used to do EOA authentication */
33
+ private eoa;
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>;
39
+ /**
40
+ *
41
+ * @param eoa - Ethereum address
42
+ * @param browserWallet - Interface to the wallet provider, like MetaMask, that is used to sign the requests
43
+ * @param ephClaimOptions - Either EphKeyClaim or Map of SignatureAlgorithms and their appropriate EphKeyClaims
44
+ */
45
+ constructor(eoa: string, browserWallet: IBrowserWallet, ephClaimOptions: {
46
+ ephClaim?: EphKeyClaim;
47
+ ephClaims?: Map<string, EphKeyClaim>;
48
+ });
49
+ private validateInputs;
50
+ getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
51
+ /**
52
+ * Prepares a message to present on the Browser Wallet window and requests to sign it.
53
+ * @param setup - Keygen setup options
54
+ * @param challenge - the challenge received from the backend
55
+ * @public
56
+ */
57
+ authenticate({ setup, challenge, }: {
58
+ setup: KeygenSetupOpts | MetadataSetupOpts;
59
+ challenge: string;
60
+ }): Promise<UserAuthentication>;
61
+ }
62
+ /** The `EphAuth` module is only used for signing requests to the network.
63
+ * @alpha
64
+ * An Ephmeral key used to locally sign the signature requests to network.
65
+ * This eph key is registered during keygen. The key is used to sign the requests without
66
+ * asking the user to sign the request each time.
67
+ * */
68
+ export declare class EphAuth implements AuthModule {
69
+ /** Secret key of the ephemeral keypair */
70
+ private ephSK;
71
+ /** Ephemeral key claim */
72
+ private ephClaim;
73
+ /**
74
+ *
75
+ * @param ephId - Ephemeral key ID
76
+ * @param ephSK - Ephemeral secret key
77
+ * @param signAlg - Signature algorithm
78
+ */
79
+ constructor(ephId: string, ephSK: Uint8Array, signAlg: SignAlgorithm);
80
+ /**
81
+ * Prepares a message to present on the Browser Wallet window and requests to sign it.
82
+ * @param setup - Signgen setup options
83
+ * @param challenge - the challenge received from the backend
84
+ *
85
+ * @public
86
+ */
87
+ authenticate({ setup, challenge, }: {
88
+ setup: SignSetupOpts | MetadataSetupOpts;
89
+ challenge: string;
90
+ }): Promise<UserAuthentication>;
91
+ }
92
+ /** The `AuthModule` implementing Passkey authentication.
93
+ * @alpha
94
+ */
95
+ export declare class PasskeyAuth implements DkgAuthModule {
96
+ /** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
97
+ private rpConfig;
98
+ /** ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field */
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;
128
+ /** Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user */
129
+ private user;
130
+ /**
131
+ *
132
+ * @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
133
+ * @param user - Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user
134
+ */
135
+ constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser);
136
+ authenticate({ setup, challenge, }: {
137
+ setup: MetadataSetupOpts;
138
+ challenge: string;
139
+ }): Promise<UserAuthentication>;
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,4 +1,5 @@
1
1
  import { UserAuthentication } from './authentication';
2
+ import { EphKeyClaim } from './ephemeralAuthentication';
2
3
  /** Information about the user currently registering. Read more: https://w3c.github.io/webauthn/#dom-publickeycredentialcreationoptions-user
3
4
  * @alpha
4
5
  * */
@@ -14,19 +15,14 @@ export type RelyingPartyConfig = {
14
15
  rpName: string;
15
16
  rpId: string;
16
17
  };
17
- export declare function passkeyRegister({ user, ephId, challenge, rpConfig, ephPK, lifetime, }: {
18
+ export declare function passkeyRegister({ user, challenge, rpConfig, }: {
18
19
  user: PasskeyUser;
19
- ephId: string;
20
20
  challenge: string;
21
21
  rpConfig: RelyingPartyConfig;
22
- ephPK: Uint8Array;
23
- lifetime: number;
24
22
  }): Promise<UserAuthentication>;
25
- export declare function passkeyLogin({ ephId, challenge, credentialId, rpConfig, ephPK, lifetime, }: {
26
- ephId: string;
23
+ export declare function passkeyLogin({ challenge, allowCredentialId, rpConfig, ephClaim, }: {
27
24
  challenge: string;
28
- credentialId: string;
25
+ allowCredentialId: string | null;
29
26
  rpConfig: RelyingPartyConfig;
30
- ephPK: Uint8Array;
31
- lifetime: number;
27
+ ephClaim: EphKeyClaim;
32
28
  }): Promise<UserAuthentication>;