@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 +135 -112
- package/dist/{EOAauthentication.d.ts → auth/EOAauthentication.d.ts} +14 -4
- package/dist/{authentication.d.ts → auth/authentication.d.ts} +51 -24
- package/dist/auth/ephemeralAuthentication.d.ts +44 -0
- package/dist/{passkeyAuthentication.d.ts → auth/passkeyAuthentication.d.ts} +3 -4
- package/dist/client/networkSigner.d.ts +96 -0
- package/dist/client/types.d.ts +60 -0
- package/dist/client/walletProviderServiceClient.d.ts +43 -0
- package/dist/client/walletProviderServiceClientInterface.d.ts +59 -0
- package/dist/index.cjs.js +6 -1
- package/dist/index.d.ts +30 -8
- package/dist/index.esm.js +6 -1
- package/dist/setupMessage.d.ts +77 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/encoder.d.ts +2 -0
- package/dist/utils/validator.d.ts +6 -0
- package/dist/viemSigner.d.ts +4 -4
- package/package.json +10 -6
- package/dist/encoding.d.ts +0 -3
- package/dist/ephemeralAuthentication.d.ts +0 -21
- package/dist/networkSigner.d.ts +0 -182
- package/dist/validator.d.ts +0 -3
- package/dist/walletProviderServiceClient.d.ts +0 -32
- package/dist/walletProviderServiceClientInterface.d.ts +0 -43
package/README.md
CHANGED
|
@@ -1,104 +1,103 @@
|
|
|
1
1
|
# walletprovider-sdk
|
|
2
2
|
|
|
3
|
-
The
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
npm
|
|
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
|
-
|
|
25
|
+
# Quick start
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Check the [demo](./demo/README.md) for a quick start guide.
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
# Documentation
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
For description of classes, interfaces, types, please refer to [documentation](./docs/walletprovider-sdk.md).
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
# Features
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
## The backend
|
|
35
|
+
- Authentication
|
|
36
|
+
- Keygen
|
|
37
|
+
- Signing
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
## Overview
|
|
42
40
|
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
-
|
|
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 **
|
|
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
|
|
85
|
-
const
|
|
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
|
-
|
|
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.
|
|
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
|
|
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 `
|
|
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
|
|
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
|
|
178
|
+
// Create Passkey authenticator, signature will include epk
|
|
156
179
|
const passkeyAuth = new PasskeyAuth(
|
|
157
180
|
rpConfig,
|
|
158
|
-
|
|
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.
|
|
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
|
|
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 `
|
|
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/
|
|
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
|
-
|
|
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(
|
|
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.
|
|
208
|
+
Use the [NetworkSigner.signMessage](./docs/walletprovider-sdk.networksigner.signMessage.md) method in order to generate a signature.
|
|
190
209
|
|
|
191
210
|
```ts
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
##
|
|
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
|
-
##
|
|
259
|
+
## Generate the documentation
|
|
237
260
|
|
|
238
261
|
```bash
|
|
239
|
-
npm run
|
|
262
|
+
npm run docs
|
|
240
263
|
```
|
|
241
264
|
|
|
242
|
-
##
|
|
265
|
+
## Lint the code
|
|
243
266
|
|
|
244
267
|
```bash
|
|
245
|
-
|
|
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 '
|
|
4
|
+
import { MetadataSetupOpts, KeygenSetupOpts } from '../setupMessage';
|
|
5
5
|
import { type UserAuthentication } from './authentication';
|
|
6
6
|
import { type TypedDataDomain } from 'viem';
|
|
7
|
-
import {
|
|
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:
|
|
65
|
+
ephClaim: EphKeyClaim;
|
|
57
66
|
}): Promise<UserAuthentication>;
|
|
67
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from '../setupMessage';
|
|
2
2
|
import { IBrowserWallet } from './EOAauthentication';
|
|
3
3
|
import { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
|
|
4
|
-
import {
|
|
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 |
|
|
19
|
+
setup: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts;
|
|
20
20
|
challenge: string;
|
|
21
21
|
}): Promise<UserAuthentication>;
|
|
22
22
|
}
|
|
23
23
|
export interface DkgAuthModule extends AuthModule {
|
|
24
|
-
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
135
|
+
constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser);
|
|
109
136
|
authenticate({ setup, challenge, }: {
|
|
110
|
-
setup:
|
|
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 {
|
|
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,
|
|
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:
|
|
27
|
+
ephClaim: EphKeyClaim;
|
|
29
28
|
}): Promise<UserAuthentication>;
|