@silencelaboratories/walletprovider-sdk 0.2.0 → 1.3.0
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 +109 -96
- package/dist/EOAauthentication.d.ts +15 -6
- package/dist/authentication.d.ts +68 -40
- package/dist/encoding.d.ts +1 -0
- package/dist/ephemeralAuthentication.d.ts +34 -6
- package/dist/index.cjs.js +6 -1
- package/dist/index.d.ts +23 -3
- package/dist/index.esm.js +6 -1
- package/dist/networkSigner.d.ts +49 -50
- package/dist/passkeyAuthentication.d.ts +5 -9
- package/dist/setupMessage.d.ts +70 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/validator.d.ts +6 -0
- package/dist/viemSigner.d.ts +4 -3
- package/dist/walletProviderServiceClient.d.ts +24 -8
- package/dist/walletProviderServiceClientInterface.d.ts +30 -6
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -1,105 +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 =
|
|
80
|
-
ephSK = sk;
|
|
72
|
+
const sk = generateEphPrivateKey(algSign);
|
|
81
73
|
// Derive public part epk from esk
|
|
82
|
-
ephPK =
|
|
74
|
+
const ephPK = getEphPublicKey(sk, algSign);
|
|
83
75
|
// Arbitrary ID to identify the ephemeral key
|
|
84
76
|
const ephId = uuidv4();
|
|
85
|
-
// Create
|
|
86
|
-
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
|
+
);
|
|
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
|
-
|
|
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 [
|
|
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.
|
|
119
|
+
let resp: KeygenResponse = await sdk.generateKey(JSON.stringify(permissions));
|
|
122
120
|
```
|
|
123
121
|
|
|
124
|
-
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.
|
|
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 `
|
|
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
|
|
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 =
|
|
136
|
-
ephSK = sk;
|
|
156
|
+
const sk = generateEphPrivateKey(algSign);
|
|
137
157
|
// Derive public part epk from esk
|
|
138
|
-
ephPK =
|
|
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,50 +172,40 @@ 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
|
|
178
|
+
// Create Passkey authenticator, signature will include epk
|
|
158
179
|
const passkeyAuth = new PasskeyAuth(
|
|
159
180
|
rpConfig,
|
|
160
|
-
|
|
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 [
|
|
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
|
|
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 `
|
|
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/
|
|
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
|
-
|
|
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(
|
|
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.
|
|
208
|
+
Use the [NetworkSigner.signMessage](./docs/walletprovider-sdk.networksigner.signMessage.md) method in order to generate a signature.
|
|
192
209
|
|
|
193
210
|
```ts
|
|
194
211
|
let signMessage = JSON.stringify({
|
|
@@ -212,21 +229,17 @@ let signMessage = JSON.stringify({
|
|
|
212
229
|
requestType: 'accountAbstractionTx',
|
|
213
230
|
});
|
|
214
231
|
|
|
215
|
-
let resp = await sdk.
|
|
232
|
+
let resp = await sdk.signMessage(selectedKeyId, signMessage);
|
|
216
233
|
```
|
|
217
234
|
|
|
218
235
|
The [SignResponse](./docs/walletprovider-sdk.signresponse.md) contains the signature `sign` and the recovery ID `recid`.
|
|
219
236
|
|
|
237
|
+
# Development
|
|
220
238
|
|
|
221
|
-
##
|
|
222
|
-
|
|
223
|
-
```bash
|
|
224
|
-
npm install
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## Build
|
|
239
|
+
## Build the library
|
|
228
240
|
|
|
229
241
|
```bash
|
|
242
|
+
npm i
|
|
230
243
|
npm run build
|
|
231
244
|
```
|
|
232
245
|
|
|
@@ -235,14 +248,14 @@ The output will be in the `dist` folder.
|
|
|
235
248
|
## End to end tests
|
|
236
249
|
Please refer to [README.md](./e2e-tests/README.md) for instructions how to execute them.
|
|
237
250
|
|
|
238
|
-
##
|
|
251
|
+
## Generate the documentation
|
|
239
252
|
|
|
240
253
|
```bash
|
|
241
|
-
npm run
|
|
254
|
+
npm run docs
|
|
242
255
|
```
|
|
243
256
|
|
|
244
|
-
##
|
|
257
|
+
## Lint the code
|
|
245
258
|
|
|
246
259
|
```bash
|
|
247
|
-
|
|
260
|
+
./local_ci.sh
|
|
248
261
|
```
|
|
@@ -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 './
|
|
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,
|
|
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
|
-
|
|
57
|
-
lifetime: number;
|
|
65
|
+
ephClaim: EphKeyClaim;
|
|
58
66
|
}): Promise<UserAuthentication>;
|
|
67
|
+
export {};
|
package/dist/authentication.d.ts
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
import { KeygenSetupOpts, SignSetupOpts } from './
|
|
1
|
+
import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from './setupMessage';
|
|
2
2
|
import { IBrowserWallet } from './EOAauthentication';
|
|
3
3
|
import { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
|
|
4
|
+
import { EphKeyClaim, SignAlgorithm } from './ephemeralAuthentication';
|
|
4
5
|
/** Type of the request authentication
|
|
5
6
|
* @alpha
|
|
6
7
|
*/
|
|
7
8
|
export type UserCredentials = {
|
|
8
9
|
id: string;
|
|
9
|
-
method:
|
|
10
|
+
method: 'eoa' | 'ephemeral' | 'passkey';
|
|
10
11
|
credentials: string;
|
|
11
|
-
ephId?: string;
|
|
12
12
|
};
|
|
13
13
|
export type UserAuthentication = {
|
|
14
14
|
credentials: UserCredentials;
|
|
15
15
|
signature: string;
|
|
16
|
-
passkeyCredentialId?: string;
|
|
17
16
|
};
|
|
18
17
|
export interface AuthModule {
|
|
19
18
|
authenticate({ setup, challenge, }: {
|
|
20
|
-
setup: KeygenSetupOpts | SignSetupOpts;
|
|
19
|
+
setup: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts;
|
|
21
20
|
challenge: string;
|
|
22
21
|
}): Promise<UserAuthentication>;
|
|
23
22
|
}
|
|
23
|
+
export interface DkgAuthModule extends AuthModule {
|
|
24
|
+
get ephClaim(): EphKeyClaim;
|
|
25
|
+
}
|
|
24
26
|
/** The `EOAAuth` implementing Externally Owned Account authentication.
|
|
25
27
|
* @alpha
|
|
26
28
|
*/
|
|
27
|
-
export declare class EOAAuth implements
|
|
28
|
-
/** Ephemeral id identify ephemeral key */
|
|
29
|
-
ephId: string;
|
|
29
|
+
export declare class EOAAuth implements DkgAuthModule {
|
|
30
30
|
/** An interface to the wallet, like MetaMask, that is used to sign the requests */
|
|
31
|
-
browserWallet
|
|
32
|
-
/** Public key of the ephemeral key */
|
|
33
|
-
ephPK: Uint8Array;
|
|
34
|
-
/** Lifetime of the ephemeral key */
|
|
35
|
-
lifetime: number;
|
|
31
|
+
private browserWallet;
|
|
36
32
|
/** the ETH address that is used to do EOA authentication */
|
|
37
|
-
eoa
|
|
38
|
-
|
|
33
|
+
private eoa;
|
|
34
|
+
/** Ephemeral key claim */
|
|
35
|
+
ephClaim: EphKeyClaim;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param eoa - Ethereum address
|
|
39
|
+
* @param browserWallet - Interface to the wallet provider, like MetaMask, that is used to sign the requests
|
|
40
|
+
* @param ephClaim - EphKeyClaim instance
|
|
41
|
+
*/
|
|
42
|
+
constructor(eoa: string, browserWallet: IBrowserWallet, ephClaim: EphKeyClaim);
|
|
43
|
+
private validateInputs;
|
|
39
44
|
/**
|
|
40
45
|
* Prepares a message to present on the Browser Wallet window and requests to sign it.
|
|
41
46
|
* @param setup - Keygen setup options
|
|
@@ -43,8 +48,8 @@ export declare class EOAAuth implements AuthModule {
|
|
|
43
48
|
*
|
|
44
49
|
* @public
|
|
45
50
|
*/
|
|
46
|
-
authenticate({ setup, challenge }: {
|
|
47
|
-
setup: KeygenSetupOpts;
|
|
51
|
+
authenticate({ setup, challenge, }: {
|
|
52
|
+
setup: KeygenSetupOpts | MetadataSetupOpts;
|
|
48
53
|
challenge: string;
|
|
49
54
|
}): Promise<UserAuthentication>;
|
|
50
55
|
}
|
|
@@ -55,13 +60,17 @@ export declare class EOAAuth implements AuthModule {
|
|
|
55
60
|
* asking the user to sign the request each time.
|
|
56
61
|
* */
|
|
57
62
|
export declare class EphAuth implements AuthModule {
|
|
58
|
-
/** Ephemeral id identify ephemeral key */
|
|
59
|
-
ephId: string;
|
|
60
63
|
/** Secret key of the ephemeral keypair */
|
|
61
|
-
ephSK
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
private ephSK;
|
|
65
|
+
/** Ephemeral key claim */
|
|
66
|
+
private ephClaim;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param ephId - Ephemeral key ID
|
|
70
|
+
* @param ephSK - Ephemeral secret key
|
|
71
|
+
* @param signAlg - Signature algorithm
|
|
72
|
+
*/
|
|
73
|
+
constructor(ephId: string, ephSK: Uint8Array, signAlg: SignAlgorithm);
|
|
65
74
|
/**
|
|
66
75
|
* Prepares a message to present on the Browser Wallet window and requests to sign it.
|
|
67
76
|
* @param setup - Signgen setup options
|
|
@@ -69,30 +78,49 @@ export declare class EphAuth implements AuthModule {
|
|
|
69
78
|
*
|
|
70
79
|
* @public
|
|
71
80
|
*/
|
|
72
|
-
authenticate({ setup, challenge }: {
|
|
73
|
-
setup: SignSetupOpts;
|
|
81
|
+
authenticate({ setup, challenge, }: {
|
|
82
|
+
setup: SignSetupOpts | MetadataSetupOpts;
|
|
74
83
|
challenge: string;
|
|
75
84
|
}): Promise<UserAuthentication>;
|
|
76
85
|
}
|
|
77
86
|
/** The `AuthModule` implementing Passkey authentication.
|
|
78
87
|
* @alpha
|
|
79
88
|
*/
|
|
80
|
-
export declare class PasskeyAuth implements
|
|
89
|
+
export declare class PasskeyAuth implements DkgAuthModule {
|
|
81
90
|
/** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
|
|
82
|
-
rpConfig
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
constructor(rpConfig: RelyingPartyConfig,
|
|
94
|
-
authenticate({ setup, challenge }: {
|
|
95
|
-
setup: KeygenSetupOpts;
|
|
91
|
+
private rpConfig;
|
|
92
|
+
/** ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field */
|
|
93
|
+
private allowCredentialId;
|
|
94
|
+
/** Ephemeral key claim */
|
|
95
|
+
ephClaim: EphKeyClaim;
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
|
|
99
|
+
* @param allowCredentialId - ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field
|
|
100
|
+
* @param ephClaim - EphKeyClaim instance
|
|
101
|
+
*/
|
|
102
|
+
constructor(rpConfig: RelyingPartyConfig, allowCredentialId: string, ephClaim: EphKeyClaim);
|
|
103
|
+
authenticate({ setup, challenge, }: {
|
|
104
|
+
setup: KeygenSetupOpts | MetadataSetupOpts;
|
|
105
|
+
challenge: string;
|
|
106
|
+
}): Promise<UserAuthentication>;
|
|
107
|
+
}
|
|
108
|
+
/** The `AuthModule` implementing Passkey register.
|
|
109
|
+
* @alpha
|
|
110
|
+
*/
|
|
111
|
+
export declare class PasskeyRegister implements AuthModule {
|
|
112
|
+
/** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
|
|
113
|
+
private rpConfig;
|
|
114
|
+
/** Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user */
|
|
115
|
+
private user;
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
|
|
119
|
+
* @param user - Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user
|
|
120
|
+
*/
|
|
121
|
+
constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser);
|
|
122
|
+
authenticate({ setup, challenge, }: {
|
|
123
|
+
setup: MetadataSetupOpts;
|
|
96
124
|
challenge: string;
|
|
97
125
|
}): Promise<UserAuthentication>;
|
|
98
126
|
}
|
package/dist/encoding.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const decodeBase64: (b64: string) => Uint8Array;
|
|
2
2
|
export declare const encodeBase64: (b: Uint8Array) => string;
|
|
3
3
|
export declare const arrayBufferToBase64Url: (a: ArrayBuffer) => string;
|
|
4
|
+
export declare const calculateFinalChallenge: (setupOpts: string) => string;
|
|
@@ -1,16 +1,44 @@
|
|
|
1
1
|
import { UserAuthentication } from './authentication';
|
|
2
|
-
import { SignSetupOpts } from './
|
|
3
|
-
|
|
2
|
+
import { 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;
|
|
4
13
|
ephPK: string;
|
|
14
|
+
signAlg: SignAlgorithm;
|
|
5
15
|
expiry: number;
|
|
6
|
-
|
|
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
|
+
}
|
|
7
27
|
/** Locally sign the signature requests to network without asking the user, the ephSK is registered during keygen.
|
|
8
28
|
* The signature is the authorization for signgen operation
|
|
9
29
|
*/
|
|
10
|
-
export declare function authenticateUsingEphKey({ setup,
|
|
30
|
+
export declare function authenticateUsingEphKey({ setup, challenge, ephSK, ephClaim, }: {
|
|
11
31
|
setup: SignSetupOpts;
|
|
12
|
-
ephId: string;
|
|
13
32
|
challenge: string;
|
|
14
33
|
ephSK: Uint8Array;
|
|
15
|
-
|
|
34
|
+
ephClaim: EphKeyClaim;
|
|
16
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;
|