@silencelaboratories/walletprovider-sdk 1.3.0 → 1.5.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.
@@ -0,0 +1,7 @@
1
+ export declare const arrayBufferToBase64Url: (a: ArrayBuffer) => string;
2
+ /**
3
+ *
4
+ * @param serialized MUST be in canonicalized JSON format
5
+ * @returns
6
+ */
7
+ export declare const calculateFinalChallenge: (serialized: string) => string;
@@ -0,0 +1,9 @@
1
+ import { AuthMethod, AuthPayload } from './../auth/authentication';
2
+ import { EphKeySignAlgorithm } from '../auth/ephemeralAuthentication';
3
+ import { MPCSignAlgorithm } from '../client/networkSigner';
4
+ export declare const throwIfInvalidString: (key: string, value: string) => void;
5
+ export declare const throwIfInvalidEphPK: (ephKey: Uint8Array, signAlg: EphKeySignAlgorithm) => void;
6
+ export declare const throwIfInvalidEphSK: (ephKey: Uint8Array, signAlg: EphKeySignAlgorithm) => void;
7
+ export declare const throwIfInvalidMPCSignAlg: (signAlg: MPCSignAlgorithm) => void;
8
+ export declare const throwIf: (condition: boolean, message: string) => void;
9
+ export declare const throwIfInvalidAuthPayloadType: (payload: AuthPayload, expected_types: any[], authMethod: AuthMethod) => void;
@@ -1,15 +1,24 @@
1
1
  import { LocalAccount } from 'viem/accounts';
2
- import { NetworkSigner } from './networkSigner';
2
+ import { MPCSignAlgorithm, NetworkSigner } from './client/networkSigner';
3
3
  import { Address } from 'viem';
4
+ /**
5
+ * Options for creating a distributed signing request for signing transactions using Silent Network.
6
+ * @public
7
+ */
8
+ export interface DSGOpts {
9
+ threshold: number;
10
+ keyId: string;
11
+ signAlg: MPCSignAlgorithm;
12
+ }
4
13
  /**
5
14
  * Create a new viem custom account for signing transactions using
6
15
  * the MPC network.
7
- * @param clusterConfig The network cluster configuration.
16
+ * @param networkSigner API to communicate with the Silent MPC Network.
8
17
  * @param keyId The selected Key ID.
9
18
  * @param publicKey Associated public key of the selected Key ID.
10
- * @param threshold The threshold.
19
+ * @param signAlg The signature algorithm for signing (default: secp256k1).
11
20
  */
12
- export declare function createViemAccount(networkSigner: NetworkSigner, keyId: string, publicKey: string): LocalAccount;
21
+ export declare function createViemAccount(networkSigner: NetworkSigner, publicKey: string, dsgOpts: DSGOpts): LocalAccount;
13
22
  /** Computes ETH address from ECDSA `publicKey` returned by Silent Network
14
23
  * @public
15
24
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silencelaboratories/walletprovider-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "author": "Silence Laboratories",
5
5
  "description": "Frontend SDK for Wallet Providers",
6
6
  "main": "./dist/index.cjs.js",
@@ -16,12 +16,13 @@
16
16
  "files": [
17
17
  "dist"
18
18
  ],
19
+ "type": "module",
19
20
  "scripts": {
20
21
  "format": "prettier --write --cache .",
21
22
  "formatcheck": "prettier --check --cache .",
22
23
  "lint": "eslint --cache ./src/**/*.ts",
23
24
  "typecheck": "tsc -p . --noEmit",
24
- "test": "vitest",
25
+ "test": "vitest run",
25
26
  "build": "node build.js && npm run build:declaration",
26
27
  "build:declaration": "tsc -p . --emitDeclarationOnly",
27
28
  "clean": "rimraf dist",
@@ -29,6 +30,7 @@
29
30
  "docs": "npm run build:declaration && api-extractor run --local --verbose && api-documenter markdown -i ./temp -o ./docs"
30
31
  },
31
32
  "devDependencies": {
33
+ "@commitlint/config-conventional": "^12.1.1",
32
34
  "@eslint/js": "9.14.0",
33
35
  "@microsoft/api-documenter": "^7.25.2",
34
36
  "@microsoft/api-extractor": "^7.46.2",
@@ -43,11 +45,12 @@
43
45
  "rimraf": "^6.0.1",
44
46
  "typescript": "5.6.3",
45
47
  "typescript-eslint": "8.13.0",
46
- "vitest": "^2.1.5"
48
+ "vitest": "^2.1.8"
47
49
  },
48
50
  "dependencies": {
49
51
  "@noble/curves": "^1.6.0",
50
52
  "js-base64": "^3.7.7",
53
+ "json-canonicalize": "^1.0.6",
51
54
  "viem": "2.21.54"
52
55
  }
53
56
  }
@@ -1,4 +0,0 @@
1
- export declare const decodeBase64: (b64: string) => Uint8Array;
2
- export declare const encodeBase64: (b: Uint8Array) => string;
3
- export declare const arrayBufferToBase64Url: (a: ArrayBuffer) => string;
4
- export declare const calculateFinalChallenge: (setupOpts: string) => string;
@@ -1,44 +0,0 @@
1
- import { UserAuthentication } from './authentication';
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;
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;
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,117 +0,0 @@
1
- import { AuthModule } from './authentication';
2
- import { type IWalletProviderServiceClient } from './walletProviderServiceClientInterface';
3
- /**
4
- * Response from the network for keygen requests
5
- * @alpha
6
- */
7
- export interface KeygenResponse {
8
- /**
9
- * Unique ID of produced key used in subsequent API calls.
10
- */
11
- keyId: string;
12
- /**
13
- * Public key encoded with SEC1 format.
14
- *
15
- * If point is uncompressed it's in a form of 0x04 || X || Y
16
- *
17
- * If point is compressed it's in a form Y || X,
18
- *
19
- * where Y is set to 0x02 if Y-coord is even, or 0x03 if Y-coord is odd
20
- */
21
- publicKey: string;
22
- }
23
- /**
24
- * Response from the network for sign request
25
- * @alpha
26
- */
27
- export interface SignResponse {
28
- /**
29
- * Hexstring of length 128 bytes, in a form: r || s
30
- */
31
- sign: string;
32
- /**
33
- * Recovery id, either 0, or 1
34
- */
35
- recid: number;
36
- }
37
- /**
38
- * Response from the network for adding ephemeral key request
39
- * @alpha
40
- */
41
- export interface OperationStatusResponse {
42
- /**
43
- * Status of the request.
44
- */
45
- status: string;
46
- }
47
- /**
48
- * Response from the network for registering passkey request
49
- * @alpha
50
- */
51
- export interface RegisterPasskeyResponse {
52
- /**
53
- * The registered passkey credential id. This helps both the user and the network to identify the passkey.
54
- * @alpha
55
- */
56
- passkeyCredentialId: string;
57
- }
58
- /** The networkSigner contains an API to communicate with the Silent MPC Network. Call to sign and keygen require
59
- * the Auth module, that is used to prompt the User before executing the request.
60
- * @alpha
61
- */
62
- export declare class NetworkSigner {
63
- /** Authentication module, used to get confirmation from the User before request execution */
64
- authModule: AuthModule;
65
- /** Number of nodes that needs to participate in protocol in order to generate valid signature. Also known as `t`. */
66
- threshold: number;
67
- /** Number of nodes that participate in keygen operation. Also known as `n`. */
68
- totalNodes: number;
69
- /** Wallet Provider backend client */
70
- wpClient: IWalletProviderServiceClient;
71
- /**
72
- * Facade class used to execute operations on Silent Network.
73
- * @param wpClient - Wallet Provider backend client
74
- * @param threshold - Number of nodes that needs to participate in protocol in order to generate valid signature. Also known as `t`.
75
- * @param totalNodes - Number of nodes that participate in keygen operation. Also known as `n`.
76
- * @param authModule - Authentication module, used to get confirmation from the User before request execution
77
- */
78
- constructor(wpClient: IWalletProviderServiceClient, threshold: number, totalNodes: number, authModule: AuthModule);
79
- /** Generate a distributed key that's generated by Silent Network.
80
- * Uses `authModule` to authenticate the User with the Silent Network.
81
- * @param permissions - optional permissions that will be stored in the key metadata.
82
- * The permissions are validated during sign requests.
83
- * @returns {@link KeygenResponse} containing `keyId` and the `pubKey` public part of the key
84
- * @public
85
- */
86
- generateKey(permissions?: string): Promise<KeygenResponse>;
87
- /** Generate a signature by the distributed key of Silent Network.
88
- * Uses `authModule` to authenticate the sign request by the User.
89
- * The network chooses `t` nodes to execute the protocol.
90
- * @param keyId - the key id returned from `keygen`
91
- * @param message - the message to sign by the MPC network
92
- * @returns {@link SignResponse}
93
- * @public
94
- */
95
- signMessage(keyId: string, message: string): Promise<SignResponse>;
96
- /** Add new ephemeral key to an exist distributed key on the network.
97
- * Uses `authModule` to authenticate the request by the User.
98
- * @param keyId - the key id returned from `keygen`
99
- * @returns {@link OperationStatusResponse}
100
- * @public
101
- */
102
- addEphemeralKey(keyId: string): Promise<OperationStatusResponse>;
103
- /** Revoke ephemeral key of an exist distributed key on the network.
104
- * Uses `authModule` to authenticate the request by the User.
105
- * @param keyId - the key id returned from `keygen`
106
- * @returns {@link OperationStatusResponse}
107
- * @public
108
- */
109
- revokeEphemeralKey(keyId: string): Promise<OperationStatusResponse>;
110
- /** Register new user's passkey on the network. This will try to register to all the available nodes on the network.
111
- * Uses `authModule` to authenticate the request by the User.
112
- * @returns {@link RegisterPasskeyResponse}
113
- * @public
114
- */
115
- registerPasskey(): Promise<RegisterPasskeyResponse>;
116
- private setEphClaimOf;
117
- }
@@ -1,6 +0,0 @@
1
- import { SignAlgorithm } from './ephemeralAuthentication';
2
- export declare const throwIfInvalidString: (key: string, value: string) => void;
3
- export declare const throwIfInvalidEphPK: (ephKey: Uint8Array, signAlg: SignAlgorithm) => void;
4
- export declare const throwIfInvalidEphSK: (ephKey: Uint8Array, signAlg: SignAlgorithm) => void;
5
- export declare const throwIfInvalidSignAlg: (signAlg: SignAlgorithm) => void;
6
- export declare const throwIf: (condition: boolean, message: string) => void;
@@ -1,43 +0,0 @@
1
- import { AuthModule, DkgAuthModule } from './authentication';
2
- import { type KeygenResponse, type SignResponse, type OperationStatusResponse, type RegisterPasskeyResponse } from './networkSigner';
3
- import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from './setupMessage';
4
- import { ApiVersion, type ClientConfig, IWalletProviderServiceClient, QueryPath } from './walletProviderServiceClientInterface';
5
- /**
6
- * The Websocket client to the Wallet Provider backend service.
7
- * All requests are relayed by this entity to the MPC network.
8
- * @alpha
9
- */
10
- export declare class WalletProviderServiceClient implements IWalletProviderServiceClient {
11
- walletProviderId: string;
12
- walletProviderUrl: string;
13
- apiVersion: ApiVersion;
14
- /**
15
- * Create new client that connects to the backend service
16
- * @param config - config containing information about backend service
17
- */
18
- constructor(config: ClientConfig);
19
- getVersion(): ApiVersion;
20
- getWalletId(): string;
21
- startKeygen({ setup, authModule, }: {
22
- setup: KeygenSetupOpts;
23
- authModule: DkgAuthModule;
24
- }): Promise<KeygenResponse>;
25
- startSigngen({ setup, authModule }: {
26
- setup: SignSetupOpts;
27
- authModule: AuthModule;
28
- }): Promise<SignResponse>;
29
- addEphemeralKey({ setup, authModule, }: {
30
- setup: MetadataSetupOpts;
31
- authModule: DkgAuthModule;
32
- }): Promise<OperationStatusResponse>;
33
- revokeEphemeralKey({ setup, authModule, }: {
34
- setup: MetadataSetupOpts;
35
- authModule: AuthModule;
36
- }): Promise<OperationStatusResponse>;
37
- registerPasskey({ setup, authModule, }: {
38
- setup: MetadataSetupOpts;
39
- authModule: AuthModule;
40
- }): Promise<RegisterPasskeyResponse>;
41
- connect(path: QueryPath, setupOpts: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts, authModule: AuthModule): Promise<string>;
42
- connectV2(path: QueryPath, setupOpts: KeygenSetupOpts | SignSetupOpts | MetadataSetupOpts, authModule: AuthModule): Promise<string>;
43
- }
@@ -1,59 +0,0 @@
1
- import { AuthModule, UserAuthentication } from './authentication';
2
- import { KeygenResponse, SignResponse, OperationStatusResponse, RegisterPasskeyResponse } from './networkSigner';
3
- import { MetadataSetupOpts, KeygenSetupOpts, SignSetupOpts } from './setupMessage';
4
- /**
5
- * The config used to create Wallet Provider Service backend client.
6
- * Please refer to {@link https://shipyard.rs/silencelaboratories/crates/wallet-provider-service | example backend service}
7
- * implementation for requirements that the backend service must fulfill.
8
- * @alpha
9
- */
10
- export type ClientConfig = {
11
- /**
12
- * The version of the API used to connect to the service
13
- */
14
- apiVersion: ApiVersion;
15
- /**
16
- * The id of the Wallet Provider Service
17
- * @alpha
18
- */
19
- walletProviderId: string;
20
- /**
21
- * The URL used to connect to the service
22
- * @alpha
23
- */
24
- walletProviderUrl: string;
25
- };
26
- /**
27
- * The API version of the Wallet Provider Service
28
- * @public
29
- */
30
- export type ApiVersion = 'v1' | 'v2';
31
- export type Signer = (challenge: string) => Promise<UserAuthentication>;
32
- /** Interface for client of Wallet Provider Service
33
- * @alpha
34
- */
35
- export interface IWalletProviderServiceClient {
36
- getWalletId(): string;
37
- getVersion(): ApiVersion;
38
- startKeygen({ setup, authModule }: {
39
- setup: KeygenSetupOpts;
40
- authModule: AuthModule;
41
- }): Promise<KeygenResponse>;
42
- startSigngen({ setup, authModule }: {
43
- setup: SignSetupOpts;
44
- authModule: AuthModule;
45
- }): Promise<SignResponse>;
46
- addEphemeralKey({ setup, authModule, }: {
47
- setup: MetadataSetupOpts;
48
- authModule: AuthModule;
49
- }): Promise<OperationStatusResponse>;
50
- revokeEphemeralKey({ setup, authModule, }: {
51
- setup: MetadataSetupOpts;
52
- authModule: AuthModule;
53
- }): Promise<OperationStatusResponse>;
54
- registerPasskey({ setup, authModule, }: {
55
- setup: MetadataSetupOpts;
56
- authModule: AuthModule;
57
- }): Promise<RegisterPasskeyResponse>;
58
- }
59
- export type QueryPath = 'signgen' | 'keygen' | 'addEphemeralKey' | 'revokeEphemeralKey' | 'registerPasskey';