@silencelaboratories/walletprovider-sdk 1.7.0 → 4.0.1-hackathon
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 +80 -38
- package/dist/EOAauthentication.d.ts +67 -0
- package/dist/auth/EOAauthentication.d.ts +1 -1
- package/dist/auth/authentication.d.ts +15 -26
- package/dist/authentication.d.ts +146 -0
- package/dist/builder/signRequest.d.ts +2 -2
- package/dist/builder/userAuth.d.ts +14 -9
- package/dist/client/api.d.ts +18 -0
- package/dist/client/intentServiceClient.d.ts +4 -0
- package/dist/client/keyRefresher.d.ts +34 -0
- package/dist/client/networkRequest.d.ts +38 -0
- package/dist/client/networkResponse.d.ts +19 -11
- package/dist/client/networkSigner.d.ts +20 -4
- package/dist/client/types.d.ts +60 -0
- package/dist/client/walletProviderServiceClient.d.ts +16 -2
- package/dist/client/walletProviderServiceClientInterface.d.ts +21 -7
- package/dist/encoding.d.ts +4 -0
- package/dist/ephemeralAuthentication.d.ts +44 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.esm.js +1 -1
- package/dist/networkSigner.d.ts +129 -0
- package/dist/passkeyAuthentication.d.ts +28 -0
- package/dist/policy.d.ts +220 -0
- package/dist/setupMessage.d.ts +5 -10
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/validator.d.ts +6 -0
- package/dist/walletProviderServiceClient.d.ts +43 -0
- package/dist/walletProviderServiceClientInterface.d.ts +59 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -137,36 +137,77 @@ We provide EOA authentication via [EOAAuth](./docs/classes/EOAAuth.html) module.
|
|
|
137
137
|
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
Now you can generate a key, using the [generateKey](./docs/classes/NetworkSigner.html#generatekey) method. The method accepts optional
|
|
140
|
+
Now you can generate a key, using the [generateKey](./docs/classes/NetworkSigner.html#generatekey) method. The method accepts optional Policy. No Policy means _allow all operations_.
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
const POLICY_ERC20_TRANSFER = new Policy({
|
|
144
|
+
version: '1.0',
|
|
145
|
+
description: 'Simple ERC20 transfer policy',
|
|
146
|
+
rules: [
|
|
147
|
+
new Rule({
|
|
148
|
+
description: 'ERC20 transferFrom: sender/recipient match and value < 10000',
|
|
149
|
+
chain_type: ChainType.Ethereum,
|
|
150
|
+
conditions: [
|
|
151
|
+
{
|
|
152
|
+
logic: Logic.And,
|
|
153
|
+
abi: {
|
|
154
|
+
name: 'transfer',
|
|
155
|
+
type: 'function',
|
|
156
|
+
inputs: [
|
|
157
|
+
{
|
|
158
|
+
name: 'to',
|
|
159
|
+
type: 'address',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'amount',
|
|
163
|
+
type: 'uint256',
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
outputs: [
|
|
167
|
+
{
|
|
168
|
+
name: '',
|
|
169
|
+
type: 'bool',
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
group: [
|
|
174
|
+
{
|
|
175
|
+
transaction_type: TransactionType.Erc20,
|
|
176
|
+
transaction_attr: TransactionAttribute.Receiver,
|
|
177
|
+
operator: Operator.Eq,
|
|
178
|
+
value: '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
transaction_type: TransactionType.Erc20,
|
|
182
|
+
transaction_attr: "to",
|
|
183
|
+
operator: Operator.Eq,
|
|
184
|
+
value: '0x1758f42af7026fbbb559dc60ece0de3ef81f665e',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
transaction_type: TransactionType.Erc20,
|
|
188
|
+
transaction_attr: "amount",
|
|
189
|
+
operator: Operator.Lt,
|
|
190
|
+
value: 10000,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
}),
|
|
155
196
|
],
|
|
156
|
-
};
|
|
197
|
+
});
|
|
157
198
|
|
|
158
199
|
let signAlgs = ['secp256k1', 'ed25519'];
|
|
159
200
|
|
|
160
201
|
// Generate new eph key, will be later used in sign requests
|
|
161
|
-
const selectedEphSignAlg = 'secp256k1'; // Signing algorithm of
|
|
202
|
+
const selectedEphSignAlg = 'secp256k1'; // Signing algorithm of Ephemeral Key
|
|
162
203
|
const sk = generateEphPrivateKey(selectedEphSignAlg);
|
|
163
204
|
const ephPK = getEphPublicKey(sk, selectedEphSignAlg);
|
|
164
205
|
const ephId = uuidv4();
|
|
165
206
|
|
|
166
207
|
const ephClaim = new EphKeyClaim(ephId, ephPK, selectedEphSignAlg, expireAt(60 * 60));
|
|
167
208
|
|
|
168
|
-
// Generate keys for secp256k1, ed25519, and include
|
|
169
|
-
let resp: KeygenResponse[] = await sdk.generateKey(+threshold, +partiesNumber, signAlgs, ephClaim,
|
|
209
|
+
// Generate keys for secp256k1, ed25519, and include Ephemeral Key, Policy in the request
|
|
210
|
+
let resp: KeygenResponse[] = await sdk.generateKey(+threshold, +partiesNumber, signAlgs, ephClaim, POLICY_ERC20_TRANSFER);
|
|
170
211
|
```
|
|
171
212
|
|
|
172
213
|
Calling this method will cause to the Digital Wallet window to pop up, requesting the User to sign the request.
|
|
@@ -222,7 +263,7 @@ const ephPK = getEphPublicKey(sk, selectedEphSignAlg);
|
|
|
222
263
|
const ephId = uuidv4();
|
|
223
264
|
|
|
224
265
|
const ephClaim = new EphKeyClaim(ephId, ephPK, selectedEphSignAlg, expireAt(60 * 60));
|
|
225
|
-
let resp: KeygenResponse[] = await sdk.generateKey(+threshold, +partiesNumber, signAlgs, ephClaim
|
|
266
|
+
let resp: KeygenResponse[] = await sdk.generateKey(+threshold, +partiesNumber, signAlgs, ephClaim);
|
|
226
267
|
```
|
|
227
268
|
|
|
228
269
|
Now you can generate a key like in the EOA example by calling the [generateKey](./docs/classes/NetworkSigner.html#generatekey) method.
|
|
@@ -244,27 +285,28 @@ const sdk = new NetworkSigner(wpClient, authModule);
|
|
|
244
285
|
Use the [SignRequestBuilder](./docs/classes/SignRequestBuilder.html) builder to generate the sign message payload. Then call the [signMessage](./docs/classes/NetworkSigner.html#signmessage) method to run the signing process.
|
|
245
286
|
|
|
246
287
|
```ts
|
|
288
|
+
const data = encodeFunctionData({
|
|
289
|
+
abi: ERC_20_ABI,
|
|
290
|
+
functionName: 'transfer',
|
|
291
|
+
args: ['0x1758f42af7026fbbb559dc60ece0de3ef81f665e', 1000n],
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const eip1559Tx: UnsignedTransactionRequest = {
|
|
295
|
+
from: ethAddress,
|
|
296
|
+
to: '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238', // USDC Contract
|
|
297
|
+
value: '0x0',
|
|
298
|
+
data,
|
|
299
|
+
chainId: 80002,
|
|
300
|
+
nonce: 0,
|
|
301
|
+
gas: '0x18473',
|
|
302
|
+
maxFeePerGas: '0x18473',
|
|
303
|
+
maxPriorityFeePerGas: '0x1000',
|
|
304
|
+
};
|
|
247
305
|
const signMessage = new SignRequestBuilder()
|
|
248
306
|
.setRequest(
|
|
249
307
|
uuidv4(),
|
|
250
|
-
JSON.stringify(
|
|
251
|
-
|
|
252
|
-
sender: '0x8d4cb2540d993fe34c646299f1ab4af3012ff34c',
|
|
253
|
-
nonce: '0x7',
|
|
254
|
-
initCode: '0x',
|
|
255
|
-
callData: '0000...',
|
|
256
|
-
callGasLimit: '0x18473',
|
|
257
|
-
verificationGasLimit: '0x18473',
|
|
258
|
-
preVerificationGas: '66768',
|
|
259
|
-
maxFeePerGas: '',
|
|
260
|
-
maxPriorityFeePerGas: '',
|
|
261
|
-
paymasterAndData: '0x',
|
|
262
|
-
},
|
|
263
|
-
entryPointVersion: 'v0.6.0',
|
|
264
|
-
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
265
|
-
chainId: 80002,
|
|
266
|
-
}),
|
|
267
|
-
'accountAbstractionTx',
|
|
308
|
+
JSON.stringify(eip1559Tx),
|
|
309
|
+
'EIP1559',
|
|
268
310
|
)
|
|
269
311
|
.setRequest(
|
|
270
312
|
uuidv4(),
|
|
@@ -273,7 +315,7 @@ const signMessage = new SignRequestBuilder()
|
|
|
273
315
|
)
|
|
274
316
|
.build();
|
|
275
317
|
|
|
276
|
-
let resp = await sdk.signMessage(
|
|
318
|
+
let resp = await sdk.signMessage(threshold, selectedKeyId, 'secp256k1', signMessage);
|
|
277
319
|
```
|
|
278
320
|
|
|
279
321
|
The [SignResponse](./docs/interfaces/SignResponse.html) contains the signature `sign`, the recovery ID `recid` and the transaction ID `transactionId`.
|
|
@@ -285,7 +327,7 @@ The full key refresh example is [here](https://github.com/silence-laboratories/w
|
|
|
285
327
|
The workflow is similar to the keygen process.
|
|
286
328
|
|
|
287
329
|
```ts
|
|
288
|
-
const algSign = 'secp256k1'; // Signing algorithms of
|
|
330
|
+
const algSign = 'secp256k1'; // Signing algorithms of Ephemeral Key
|
|
289
331
|
|
|
290
332
|
// Create EOA authenticator
|
|
291
333
|
const eoaAuth = new EOAAuth(
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Externally Owned Account (EOA) atuhentication. Uses secret key stored on a wallet to sign requests.
|
|
2
|
+
* The requests are presented to the user in a readable form by using TypedData (EIP712).
|
|
3
|
+
*/
|
|
4
|
+
import { MetadataSetupOpts, KeygenSetupOpts } from './setupMessage';
|
|
5
|
+
import { type UserAuthentication } from './authentication';
|
|
6
|
+
import { type TypedDataDomain } from 'viem';
|
|
7
|
+
import { EphKeyClaim } from './ephemeralAuthentication';
|
|
8
|
+
export type FieldDefinition = {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
};
|
|
12
|
+
/** EIP-712 Typed data struct definition.
|
|
13
|
+
* @alpha
|
|
14
|
+
* */
|
|
15
|
+
export type TypedData<T> = {
|
|
16
|
+
/** contains the schema definition of the types that are in `msg` */
|
|
17
|
+
types: Record<string, Array<FieldDefinition>>;
|
|
18
|
+
/** is the signature domain separator */
|
|
19
|
+
domain: TypedDataDomain;
|
|
20
|
+
/** points to the type from `types`. It's the root object of `message` */
|
|
21
|
+
primaryType: string;
|
|
22
|
+
/** the request that User is asked to sign */
|
|
23
|
+
message: T;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Interface to implement communication between this library, and a Browser Wallet. In order to
|
|
27
|
+
* request the signature from the User.
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
export interface IBrowserWallet {
|
|
31
|
+
/** Sign data using the secret key stored on Browser Wallet
|
|
32
|
+
* It creates a popup window, presenting the human readable form of `request`
|
|
33
|
+
* @param from - the address used to sign the request
|
|
34
|
+
* @param request - the request to sign by the User in the form of EIP712 typed data.
|
|
35
|
+
* @throws Throws an error if User rejected signature
|
|
36
|
+
* @example The example implementation:
|
|
37
|
+
* ```ts
|
|
38
|
+
* async signTypedData<T>(from: string, request: TypedData<T>): Promise<unknown> {
|
|
39
|
+
* return await browserWallet.request({
|
|
40
|
+
* method: 'eth_signTypedData_v4',
|
|
41
|
+
* params: [from, JSON.stringify(request)],
|
|
42
|
+
* });
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
signTypedData<T>(from: string, request: TypedData<T>): Promise<unknown>;
|
|
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>>;
|
|
57
|
+
/** Present the request to the User using wallet UI, and ask for sign.
|
|
58
|
+
* The signature is the authorization for keygen operation
|
|
59
|
+
*/
|
|
60
|
+
export declare function authenticateUsingEOA({ setup, eoa, challenge, browserWallet, ephClaim, }: {
|
|
61
|
+
setup: KeygenSetupOpts | MetadataSetupOpts;
|
|
62
|
+
eoa: string;
|
|
63
|
+
challenge: string;
|
|
64
|
+
browserWallet: IBrowserWallet;
|
|
65
|
+
ephClaim: EphKeyClaim;
|
|
66
|
+
}): Promise<UserAuthentication>;
|
|
67
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
4
|
+
import { UserAuthentication } from './authentication';
|
|
5
5
|
import { type TypedDataDomain } from 'viem';
|
|
6
6
|
export type FieldDefinition = {
|
|
7
7
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddEphKeyRequest, KeyRefreshRequest, RegisterPasskeyRequest } from './../client/networkRequest';
|
|
1
|
+
import { AddEphKeyRequest, DeletePolicyRequest, KeyRefreshRequest, RegisterPasskeyRequest, UpdatePolicyRequest } from './../client/networkRequest';
|
|
2
2
|
import { KeygenSetupOpts, SignSetupOpts, FinishPresignOpts } from '../setupMessage';
|
|
3
3
|
import { EoaAuthPayload, IBrowserWallet } from './EOAauthentication';
|
|
4
4
|
import { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
|
|
@@ -11,24 +11,25 @@ export type AuthMethod = 'eoa' | 'ephemeral' | 'passkey';
|
|
|
11
11
|
export type UserCredentials = {
|
|
12
12
|
id: string;
|
|
13
13
|
method: AuthMethod;
|
|
14
|
-
credentials: string;
|
|
15
14
|
};
|
|
16
15
|
/** User signature container.
|
|
17
16
|
* It contains the signature of the request and the user credentials (authentication method, id and additional credential information).
|
|
18
17
|
* @public
|
|
19
18
|
*/
|
|
20
|
-
export
|
|
19
|
+
export declare class UserAuthentication {
|
|
21
20
|
credentials: UserCredentials;
|
|
22
21
|
signature: string;
|
|
23
|
-
|
|
22
|
+
constructor(credentials: UserCredentials, signature: string);
|
|
23
|
+
}
|
|
24
|
+
export interface AuthModuleParams<T extends AuthPayload = AuthPayload> {
|
|
25
|
+
payload: T;
|
|
26
|
+
challenge: string;
|
|
27
|
+
}
|
|
24
28
|
export interface AuthModule {
|
|
25
|
-
authenticate(
|
|
26
|
-
payload: AuthPayload;
|
|
27
|
-
challenge: string;
|
|
28
|
-
}): Promise<UserAuthentication>;
|
|
29
|
+
authenticate(params: AuthModuleParams): Promise<UserAuthentication>;
|
|
29
30
|
}
|
|
30
31
|
export type AuthPayload = EoaAuthPayload | PasskeyLoginPayload | EphemeralAuthPayload | RegisterPasskeyRequest;
|
|
31
|
-
type PasskeyLoginPayload = KeygenSetupOpts | AddEphKeyRequest | RevokeEphKeyRequest | SignSetupOpts | FinishPresignOpts | KeyRefreshRequest;
|
|
32
|
+
type PasskeyLoginPayload = KeygenSetupOpts | AddEphKeyRequest | RevokeEphKeyRequest | UpdatePolicyRequest | DeletePolicyRequest | SignSetupOpts | FinishPresignOpts | KeyRefreshRequest;
|
|
32
33
|
/** The `EOAAuth` implementing Externally Owned Account authentication.
|
|
33
34
|
* @public
|
|
34
35
|
*/
|
|
@@ -50,10 +51,7 @@ export declare class EOAAuth {
|
|
|
50
51
|
* @param challenge - the challenge received from the backend in v1 or generated by client in v2
|
|
51
52
|
* @public
|
|
52
53
|
*/
|
|
53
|
-
authenticate({ payload, challenge
|
|
54
|
-
payload: EoaAuthPayload;
|
|
55
|
-
challenge: string;
|
|
56
|
-
}): Promise<UserAuthentication>;
|
|
54
|
+
authenticate({ payload, challenge }: AuthModuleParams<EoaAuthPayload>): Promise<UserAuthentication>;
|
|
57
55
|
}
|
|
58
56
|
/** The `EphAuth` module is only used for signing requests to the network.
|
|
59
57
|
* @public
|
|
@@ -80,15 +78,12 @@ export declare class EphAuth implements AuthModule {
|
|
|
80
78
|
*
|
|
81
79
|
* @public
|
|
82
80
|
*/
|
|
83
|
-
authenticate({ payload, challenge
|
|
84
|
-
payload: EphemeralAuthPayload;
|
|
85
|
-
challenge: string;
|
|
86
|
-
}): Promise<UserAuthentication>;
|
|
81
|
+
authenticate({ payload, challenge }: AuthModuleParams<EphemeralAuthPayload>): Promise<UserAuthentication>;
|
|
87
82
|
}
|
|
88
83
|
/** The `AuthModule` implementing Passkey authentication.
|
|
89
84
|
* @public
|
|
90
85
|
*/
|
|
91
|
-
export declare class PasskeyAuth {
|
|
86
|
+
export declare class PasskeyAuth implements AuthModule {
|
|
92
87
|
/** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
|
|
93
88
|
private rpConfig;
|
|
94
89
|
/** ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field */
|
|
@@ -106,10 +101,7 @@ export declare class PasskeyAuth {
|
|
|
106
101
|
* @public
|
|
107
102
|
*/
|
|
108
103
|
authenticate({ payload, // TODO: Passkey login doesnt require payload, we should clean up this
|
|
109
|
-
challenge, }:
|
|
110
|
-
payload: PasskeyLoginPayload;
|
|
111
|
-
challenge: string;
|
|
112
|
-
}): Promise<UserAuthentication>;
|
|
104
|
+
challenge, }: AuthModuleParams<PasskeyLoginPayload>): Promise<UserAuthentication>;
|
|
113
105
|
}
|
|
114
106
|
/** The `AuthModule` implementing Passkey register.
|
|
115
107
|
* @public
|
|
@@ -131,9 +123,6 @@ export declare class PasskeyRegister implements AuthModule {
|
|
|
131
123
|
* @param challenge - the challenge received from the backend in v1 or generated by client in v2
|
|
132
124
|
* @public
|
|
133
125
|
*/
|
|
134
|
-
authenticate({ payload, challenge
|
|
135
|
-
payload: RegisterPasskeyRequest;
|
|
136
|
-
challenge: string;
|
|
137
|
-
}): Promise<UserAuthentication>;
|
|
126
|
+
authenticate({ payload, challenge }: AuthModuleParams<RegisterPasskeyRequest>): Promise<UserAuthentication>;
|
|
138
127
|
}
|
|
139
128
|
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
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, signAlg, }: {
|
|
19
|
+
setup: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts;
|
|
20
|
+
challenge: string;
|
|
21
|
+
signAlg: string;
|
|
22
|
+
}): Promise<UserAuthentication>;
|
|
23
|
+
}
|
|
24
|
+
export interface DkgAuthModule extends AuthModule {
|
|
25
|
+
getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
|
|
26
|
+
}
|
|
27
|
+
/** The `EOAAuth` implementing Externally Owned Account authentication.
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
export declare class EOAAuth implements DkgAuthModule {
|
|
31
|
+
/** An interface to the wallet, like MetaMask, that is used to sign the requests */
|
|
32
|
+
private browserWallet;
|
|
33
|
+
/** the ETH address that is used to do EOA authentication */
|
|
34
|
+
private eoa;
|
|
35
|
+
/** Ephemeral key claim populated for non batched requests*/
|
|
36
|
+
ephClaim?: EphKeyClaim;
|
|
37
|
+
/** Ephemeral key claims map contains pairs of
|
|
38
|
+
* SignatureAlgorithms and their appropriate EphKeyClaims in case of batched requests */
|
|
39
|
+
ephClaims?: Map<string, EphKeyClaim>;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param eoa - Ethereum address
|
|
43
|
+
* @param browserWallet - Interface to the wallet provider, like MetaMask, that is used to sign the requests
|
|
44
|
+
* @param ephClaimOptions - Either EphKeyClaim or Map of SignatureAlgorithms and their appropriate EphKeyClaims
|
|
45
|
+
*/
|
|
46
|
+
constructor(eoa: string, browserWallet: IBrowserWallet, ephClaimOptions: {
|
|
47
|
+
ephClaim?: EphKeyClaim;
|
|
48
|
+
ephClaims?: Map<string, EphKeyClaim>;
|
|
49
|
+
});
|
|
50
|
+
private validateInputs;
|
|
51
|
+
getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
|
|
52
|
+
/**
|
|
53
|
+
* Prepares a message to present on the Browser Wallet window and requests to sign it.
|
|
54
|
+
* @param setup - Keygen setup options
|
|
55
|
+
* @param challenge - the challenge received from the backend
|
|
56
|
+
* @param signAlg - signature algorithm of the EphKeyClaim used for authentication
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
authenticate({ setup, challenge, signAlg, }: {
|
|
60
|
+
setup: KeygenSetupOpts | MetadataSetupOpts;
|
|
61
|
+
challenge: string;
|
|
62
|
+
signAlg: string;
|
|
63
|
+
}): Promise<UserAuthentication>;
|
|
64
|
+
}
|
|
65
|
+
/** The `EphAuth` module is only used for signing requests to the network.
|
|
66
|
+
* @alpha
|
|
67
|
+
* An Ephmeral key used to locally sign the signature requests to network.
|
|
68
|
+
* This eph key is registered during keygen. The key is used to sign the requests without
|
|
69
|
+
* asking the user to sign the request each time.
|
|
70
|
+
* */
|
|
71
|
+
export declare class EphAuth implements AuthModule {
|
|
72
|
+
/** Secret key of the ephemeral keypair */
|
|
73
|
+
private ephSK;
|
|
74
|
+
/** Ephemeral key claim */
|
|
75
|
+
private ephClaim;
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param ephId - Ephemeral key ID
|
|
79
|
+
* @param ephSK - Ephemeral secret key
|
|
80
|
+
* @param signAlg - Signature algorithm
|
|
81
|
+
*/
|
|
82
|
+
constructor(ephId: string, ephSK: Uint8Array, signAlg: SignAlgorithm);
|
|
83
|
+
/**
|
|
84
|
+
* Prepares a message to present on the Browser Wallet window and requests to sign it.
|
|
85
|
+
* @param setup - Signgen setup options
|
|
86
|
+
* @param challenge - the challenge received from the backend
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
authenticate({ setup, challenge, }: {
|
|
91
|
+
setup: SignSetupOpts | MetadataSetupOpts;
|
|
92
|
+
challenge: string;
|
|
93
|
+
signAlg: string;
|
|
94
|
+
}): Promise<UserAuthentication>;
|
|
95
|
+
}
|
|
96
|
+
/** The `AuthModule` implementing Passkey authentication.
|
|
97
|
+
* @alpha
|
|
98
|
+
*/
|
|
99
|
+
export declare class PasskeyAuth implements DkgAuthModule {
|
|
100
|
+
/** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
|
|
101
|
+
private rpConfig;
|
|
102
|
+
/** ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field */
|
|
103
|
+
private allowCredentialId;
|
|
104
|
+
/** Ephemeral key claim populated for non batched requests*/
|
|
105
|
+
ephClaim?: EphKeyClaim;
|
|
106
|
+
/** Ephemeral key claims map contains pairs of
|
|
107
|
+
* SignatureAlgorithms and their appropriate EphKeyClaims in case of batched requests */
|
|
108
|
+
ephClaims?: Map<string, EphKeyClaim>;
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
|
|
112
|
+
* @param allowCredentialId - ID of the acceptable credential by user. App proves that user has passkey credential by passing the value of this field
|
|
113
|
+
* @param ephClaimOptions - Either EphKeyClaim or Map of SignatureAlgorithms and their appropriate EphKeyClaims
|
|
114
|
+
*/
|
|
115
|
+
constructor(rpConfig: RelyingPartyConfig, allowCredentialId: string, ephClaimOptions: {
|
|
116
|
+
ephClaim?: EphKeyClaim;
|
|
117
|
+
ephClaims?: Map<string, EphKeyClaim>;
|
|
118
|
+
});
|
|
119
|
+
private validateInputs;
|
|
120
|
+
getEphClaims(): EphKeyClaim | Map<string, EphKeyClaim>;
|
|
121
|
+
authenticate({ setup, challenge, signAlg, }: {
|
|
122
|
+
setup: KeygenSetupOpts | MetadataSetupOpts;
|
|
123
|
+
challenge: string;
|
|
124
|
+
signAlg: string;
|
|
125
|
+
}): Promise<UserAuthentication>;
|
|
126
|
+
}
|
|
127
|
+
/** The `AuthModule` implementing Passkey register.
|
|
128
|
+
* @alpha
|
|
129
|
+
*/
|
|
130
|
+
export declare class PasskeyRegister implements AuthModule {
|
|
131
|
+
/** Replying party object. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp */
|
|
132
|
+
private rpConfig;
|
|
133
|
+
/** Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user */
|
|
134
|
+
private user;
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @param rpConfig - Passkey relying party configuration. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
|
|
138
|
+
* @param user - Passkey user information, only requires while registering. Read more: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user
|
|
139
|
+
*/
|
|
140
|
+
constructor(rpConfig: RelyingPartyConfig, user: PasskeyUser);
|
|
141
|
+
authenticate({ setup, challenge, }: {
|
|
142
|
+
setup: MetadataSetupOpts;
|
|
143
|
+
challenge: string;
|
|
144
|
+
signAlg: string;
|
|
145
|
+
}): Promise<UserAuthentication>;
|
|
146
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type of signing transaction.
|
|
3
|
-
* For `
|
|
3
|
+
* For `rawBytes` | `solanaTransaction` it is REQUIRED to encode the message in hex.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export type SignRequestType = '
|
|
6
|
+
export type SignRequestType = 'EIP1559' | 'EIP712' | 'EIP191' | 'rawBytes' | 'solanaTransaction';
|
|
7
7
|
/**
|
|
8
8
|
* Builder class for constructing request payload for DSG.
|
|
9
9
|
* The returned value from `build()` is the value of `message` field of SignSetupOpts.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { AuthModule, UserAuthentication } from '../auth/authentication';
|
|
1
|
+
import { AuthModule, AuthModuleParams, UserAuthentication } from '../auth/authentication';
|
|
2
2
|
import { ApiVersion, RequestPayloadV1, RequestPayloadV2, Slug } from '../client/walletProviderServiceClientInterface';
|
|
3
3
|
import { FinishPresignOpts, KeygenSetupOpts, SignSetupOpts } from '../setupMessage';
|
|
4
|
-
import { AddEphKeyRequest, KeyRefreshRequest, RegisterPasskeyRequest, RevokeEphKeyRequest } from '../client/networkRequest';
|
|
4
|
+
import { AddEphKeyRequest, DeletePolicyRequest, KeyRefreshRequest, RegisterPasskeyRequest, RevokeEphKeyRequest, UpdatePolicyRequest } from '../client/networkRequest';
|
|
5
|
+
export type UserSignaturesOptionalParams = {
|
|
6
|
+
challenge?: string | undefined;
|
|
7
|
+
};
|
|
5
8
|
/**
|
|
6
9
|
* Builder class for constructing user signatures in all kind of client requests to the network.
|
|
7
10
|
* It uses the API of `AuthModule` concrete types together with the `challenge` to generate the user signatures.
|
|
@@ -18,11 +21,13 @@ export declare class UserSignatures {
|
|
|
18
21
|
setKeygenUserSigs(payload: KeygenSetupOpts[], challenges?: {
|
|
19
22
|
[key: string]: string;
|
|
20
23
|
}): Promise<void>;
|
|
21
|
-
setSigngenUserSigs(
|
|
22
|
-
setAddEphKeyUserSigs(
|
|
23
|
-
setRevokeEphKeyUserSigs(
|
|
24
|
-
setRegisterPasskeyUserSigs(
|
|
25
|
-
setKeyRefreshUserSigs(
|
|
26
|
-
setFinishPresignUserSigs(
|
|
27
|
-
|
|
24
|
+
setSigngenUserSigs(authParams: AuthModuleParams<SignSetupOpts>): Promise<void>;
|
|
25
|
+
setAddEphKeyUserSigs(authParams: AuthModuleParams<AddEphKeyRequest>): Promise<void>;
|
|
26
|
+
setRevokeEphKeyUserSigs(authParams: AuthModuleParams<RevokeEphKeyRequest>): Promise<void>;
|
|
27
|
+
setRegisterPasskeyUserSigs(authParams: AuthModuleParams<RegisterPasskeyRequest>): Promise<void>;
|
|
28
|
+
setKeyRefreshUserSigs(authParams: AuthModuleParams<KeyRefreshRequest>): Promise<void>;
|
|
29
|
+
setFinishPresignUserSigs(authParams: AuthModuleParams<FinishPresignOpts>): Promise<void>;
|
|
30
|
+
setUpdatePolicyUserSigs(authParams: AuthModuleParams<UpdatePolicyRequest>): Promise<void>;
|
|
31
|
+
setDeletePolicyUserSigs(authParams: AuthModuleParams<DeletePolicyRequest>): Promise<void>;
|
|
32
|
+
build(slug: Slug, payload: RequestPayloadV1 | RequestPayloadV2, options?: UserSignaturesOptionalParams): Promise<Record<string, UserAuthentication>>;
|
|
28
33
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface RequestOptions extends RequestInit {
|
|
2
|
+
headers?: Record<string, string>;
|
|
3
|
+
}
|
|
4
|
+
export declare class HttpClient {
|
|
5
|
+
private readonly baseURL;
|
|
6
|
+
private defaultHeaders;
|
|
7
|
+
constructor(baseURL?: string);
|
|
8
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
9
|
+
private buildUrl;
|
|
10
|
+
private handleResponse;
|
|
11
|
+
private request;
|
|
12
|
+
get<T>(endpoint: string, options?: RequestOptions): Promise<T>;
|
|
13
|
+
post<T, D = unknown>(endpoint: string, data: D, options?: RequestOptions): Promise<T>;
|
|
14
|
+
put<T, D = unknown>(endpoint: string, data: D, options?: RequestOptions): Promise<T>;
|
|
15
|
+
patch<T, D = unknown>(endpoint: string, data: D, options?: RequestOptions): Promise<T>;
|
|
16
|
+
delete<T>(endpoint: string, options?: RequestOptions): Promise<T>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AuthModule } from '../auth/authentication';
|
|
2
|
+
import { type IWalletProviderServiceClient } from './walletProviderServiceClientInterface';
|
|
3
|
+
import { KeyRefreshResponse } from './networkResponse';
|
|
4
|
+
import { MPCSignAlgorithm } from './networkSigner';
|
|
5
|
+
/** The NetworkKeyRefresher contains API to run key refresh towards Silent Network.
|
|
6
|
+
* the Auth module, that is used to prompt the User before executing the request.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class NetworkKeyRefresher {
|
|
10
|
+
/** Authentication module, used to get confirmation from the User before request execution */
|
|
11
|
+
authModule: AuthModule;
|
|
12
|
+
/** Number of nodes that needs to participate in DSG. New `t` of (t;n) setup for this key. */
|
|
13
|
+
newThreshold: number;
|
|
14
|
+
/** Number of nodes that participate in key refresh operation. New `n` of (t;n) setup for this key. */
|
|
15
|
+
newTotalNodes: number;
|
|
16
|
+
/** Wallet Provider backend client */
|
|
17
|
+
wpClient: IWalletProviderServiceClient;
|
|
18
|
+
/**
|
|
19
|
+
* Facade class used to execute key refresh on Silent Network.
|
|
20
|
+
* @param wpClient - Wallet Provider backend client
|
|
21
|
+
* @param newThreshold - Number of nodes that needs to participate in DSG. New `t` of (t;n) setup for this key.
|
|
22
|
+
* @param newTotalNodes - Number of nodes that participate in key refresh operation. New `n` of (t;n) setup for this key.
|
|
23
|
+
* @param authModule - Authentication module, used to get confirmation from the User before request execution
|
|
24
|
+
*/
|
|
25
|
+
constructor(wpClient: IWalletProviderServiceClient, newThreshold: number, newTotalNodes: number, authModule: AuthModule);
|
|
26
|
+
/** Generate a distributed key that's generated by Silent Network.
|
|
27
|
+
* Uses `authModule` to authenticate the User with the Silent Network.
|
|
28
|
+
* @param keyId - the key id returned from `keygen`
|
|
29
|
+
* @param signAlg - signature algorithm of the refresh key.
|
|
30
|
+
* @returns {@link KeyRefreshResponse} containing `keyId`, `pubKey`,
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
refreshKey(keyId: string, signAlg: MPCSignAlgorithm): Promise<KeyRefreshResponse>;
|
|
34
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EoaAuthPayload } from '../auth/EOAauthentication';
|
|
2
2
|
import { EphKeyClaim } from '../auth/ephemeralAuthentication';
|
|
3
|
+
import { Policy } from '../policy';
|
|
3
4
|
export declare class RevokeEphKeyRequest implements EoaAuthPayload {
|
|
4
5
|
readonly key_id: string;
|
|
5
6
|
readonly eph_claim: string;
|
|
@@ -57,3 +58,40 @@ export declare class KeyRefreshRequest implements EoaAuthPayload {
|
|
|
57
58
|
}[];
|
|
58
59
|
};
|
|
59
60
|
}
|
|
61
|
+
export declare class UpdatePolicyRequest implements EoaAuthPayload {
|
|
62
|
+
/** Policy associated key ID */
|
|
63
|
+
readonly key_id: string;
|
|
64
|
+
/** New policy */
|
|
65
|
+
readonly policy: string;
|
|
66
|
+
constructor({ keyId, policy }: {
|
|
67
|
+
keyId: string;
|
|
68
|
+
policy: Policy;
|
|
69
|
+
});
|
|
70
|
+
get eoaRequestSchema(): {
|
|
71
|
+
Request: {
|
|
72
|
+
name: string;
|
|
73
|
+
type: string;
|
|
74
|
+
}[];
|
|
75
|
+
UpdatePolicyRequest: {
|
|
76
|
+
name: string;
|
|
77
|
+
type: string;
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export declare class DeletePolicyRequest implements EoaAuthPayload {
|
|
82
|
+
/** Policy associated key ID */
|
|
83
|
+
readonly key_id: string;
|
|
84
|
+
constructor({ keyId }: {
|
|
85
|
+
keyId: string;
|
|
86
|
+
});
|
|
87
|
+
get eoaRequestSchema(): {
|
|
88
|
+
Request: {
|
|
89
|
+
name: string;
|
|
90
|
+
type: string;
|
|
91
|
+
}[];
|
|
92
|
+
DeletePolicyRequest: {
|
|
93
|
+
name: string;
|
|
94
|
+
type: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
}
|