@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.
@@ -0,0 +1,96 @@
1
+ import { AuthModule } from '../auth/authentication';
2
+ import { type IWalletProviderServiceClient } from './walletProviderServiceClientInterface';
3
+ import { KeygenResponse, OperationStatusResponse, RegisterPasskeyResponse, SignResponse } from './types';
4
+ /**
5
+ * Type of sign request.
6
+ * @alpha
7
+ */
8
+ export type SignRequestType = 'accountAbstractionTx' | 'EIP712' | 'EIP191' | 'rawBytes' | 'eddsa';
9
+ /**
10
+ * Builder class for constructing SignRequest instances.
11
+ */
12
+ export declare class SignRequestBuilder {
13
+ private signRequest;
14
+ /**
15
+ * Sets the transaction ID, message, and request type for the sign request.
16
+ * Ensures that each transaction ID is only set once.
17
+ * @param transactionId - The transaction ID.
18
+ * @param message - The message to be signed.
19
+ * @param requestType - The type of the sign request.
20
+ * @returns The builder instance.
21
+ */
22
+ setRequest(transactionId: string, message: string, requestType: SignRequestType): SignRequestBuilder;
23
+ /**
24
+ * Builds and returns the SignRequest instance as a Map.
25
+ * @returns The constructed SignRequest instance as a Map.
26
+ */
27
+ build(): string;
28
+ }
29
+ /** The networkSigner contains an API to communicate with the Silent MPC Network. Call to sign and keygen require
30
+ * the Auth module, that is used to prompt the User before executing the request.
31
+ * @alpha
32
+ */
33
+ export declare class NetworkSigner {
34
+ /** Authentication module, used to get confirmation from the User before request execution */
35
+ authModule: AuthModule;
36
+ /** Number of nodes that needs to participate in protocol in order to generate valid signature. Also known as `t`. */
37
+ threshold: number;
38
+ /** Number of nodes that participate in keygen operation. Also known as `n`. */
39
+ totalNodes: number;
40
+ /** Wallet Provider backend client */
41
+ wpClient: IWalletProviderServiceClient;
42
+ /**
43
+ * Facade class used to execute operations on Silent Network.
44
+ * @param wpClient - Wallet Provider backend client
45
+ * @param threshold - Number of nodes that needs to participate in protocol in order to generate valid signature. Also known as `t`.
46
+ * @param totalNodes - Number of nodes that participate in keygen operation. Also known as `n`.
47
+ * @param authModule - Authentication module, used to get confirmation from the User before request execution
48
+ */
49
+ constructor(wpClient: IWalletProviderServiceClient, threshold: number, totalNodes: number, authModule: AuthModule);
50
+ /** Generate a distributed key that's generated by Silent Network.
51
+ * Uses `authModule` to authenticate the User with the Silent Network.
52
+ * @param signAlgs - signature algorithms for which MPC keys will be generated.
53
+ * @param permissions - optional permissions that will be stored in the key metadata.
54
+ * The permissions are validated during sign requests.
55
+ * @returns {@link KeygenResponse} containing `keyId` and the `pubKey` public part of the key
56
+ * @public
57
+ */
58
+ generateKey(signAlgs: string[], permissions?: string): Promise<KeygenResponse[]>;
59
+ /** Generate a signature by the distributed key of Silent Network.
60
+ * Uses `authModule` to authenticate the sign request by the User.
61
+ * The network chooses `t` nodes to execute the protocol.
62
+ * @param keyId - the key id returned from `keygen`
63
+ * @param signAlg - the signature algorithm to use for MPC signing, different form signAlg inside EphKeyClaim
64
+ * @param signRequest - the sign request containing the transaction id, request type and message to sign
65
+ * @returns {@link SignResponse}
66
+ * @public
67
+ */
68
+ signMessage(keyId: string, signAlg: string, signRequest: string): Promise<SignResponse[]>;
69
+ /** Add new ephemeral key to an exist distributed key on the network.
70
+ * Uses `authModule` to authenticate the request by the User.
71
+ * @param keyId - the key id returned from `keygen`
72
+ * @returns {@link OperationStatusResponse}
73
+ * @public
74
+ */
75
+ addEphemeralKey(keyId: string): Promise<OperationStatusResponse>;
76
+ /** Revoke ephemeral key of an exist distributed key on the network.
77
+ * Uses `authModule` to authenticate the request by the User.
78
+ * @param keyId - the key id returned from `keygen`
79
+ * @returns {@link OperationStatusResponse}
80
+ * @public
81
+ */
82
+ revokeEphemeralKey(keyId: string): Promise<OperationStatusResponse>;
83
+ /** Register new user's passkey on the network. This will try to register to all the available nodes on the network.
84
+ * Uses `authModule` to authenticate the request by the User.
85
+ * @returns {@link RegisterPasskeyResponse}
86
+ * @public
87
+ */
88
+ registerPasskey(): Promise<RegisterPasskeyResponse>;
89
+ private setEphClaimOf;
90
+ }
91
+ /**
92
+ *
93
+ * @param signgenResponse - response from the network for sign request
94
+ * @returns - flattened signature in a form: 0x{signature}{recover_id}
95
+ */
96
+ export declare const flattenSignature: (signgenResponse: SignResponse) => `0x${string}`;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Response from the network for keygen requests
3
+ * @alpha
4
+ */
5
+ export interface KeygenResponse {
6
+ /**
7
+ * Unique ID of produced key used in subsequent API calls.
8
+ */
9
+ keyId: string;
10
+ /**
11
+ * Public key encoded with SEC1 format.
12
+ *
13
+ * If point is uncompressed it's in a form of 0x04 || X || Y
14
+ *
15
+ * If point is compressed it's in a form Y || X,
16
+ *
17
+ * where Y is set to 0x02 if Y-coord is even, or 0x03 if Y-coord is odd
18
+ */
19
+ publicKey: string;
20
+ /**
21
+ * Signature algorithm that uses this key for signing
22
+ */
23
+ signAlg: string;
24
+ }
25
+ /**
26
+ * Response from the network for sign request
27
+ * @alpha
28
+ */
29
+ export interface SignResponse {
30
+ transactionId: string;
31
+ /**
32
+ * Hexstring of length 128 bytes, in a form: r || s
33
+ */
34
+ sign: string;
35
+ /**
36
+ * Recovery id, either 0, or 1
37
+ */
38
+ recid: number;
39
+ }
40
+ /**
41
+ * Response from the network for adding ephemeral key request
42
+ * @alpha
43
+ */
44
+ export interface OperationStatusResponse {
45
+ /**
46
+ * Status of the request.
47
+ */
48
+ status: string;
49
+ }
50
+ /**
51
+ * Response from the network for registering passkey request
52
+ * @alpha
53
+ */
54
+ export interface RegisterPasskeyResponse {
55
+ /**
56
+ * The registered passkey credential id. This helps both the user and the network to identify the passkey.
57
+ * @alpha
58
+ */
59
+ passkeyCredentialId: string;
60
+ }
@@ -0,0 +1,43 @@
1
+ import { AuthModule, DkgAuthModule } from '../auth/authentication';
2
+ import { type KeygenResponse, type SignResponse, type OperationStatusResponse, type RegisterPasskeyResponse } from './types';
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({ setups, authModule, }: {
22
+ setups: 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
+ }
@@ -0,0 +1,59 @@
1
+ import { AuthModule, UserAuthentication } from '../auth/authentication';
2
+ import { KeygenResponse, SignResponse, OperationStatusResponse, RegisterPasskeyResponse } from './types';
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({ setups, authModule }: {
39
+ setups: 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';
package/dist/index.cjs.js CHANGED
@@ -1 +1,6 @@
1
- "use strict";var S=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var Y=(n,e,t)=>e in n?S(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var X=(n,e)=>{for(var t in e)S(n,t,{get:e[t],enumerable:!0})},Z=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of G(e))!z.call(n,i)&&i!==t&&S(n,i,{get:()=>e[i],enumerable:!(r=Q(e,i))||r.enumerable});return n};var j=n=>Z(S({},"__esModule",{value:!0}),n);var s=(n,e,t)=>Y(n,typeof e!="symbol"?e+"":e,t);var se={};X(se,{EOAAuth:()=>I,EphAuth:()=>E,NetworkSigner:()=>C,PasskeyAuth:()=>K,WalletProviderServiceClient:()=>A,computeAddress:()=>V,generateEphPrivateKey:()=>q,getEphPublicKey:()=>B});module.exports=j(se);var U=require("js-base64");var R=n=>btoa(String.fromCodePoint.apply(null,Array.from(n))),c=n=>U.Base64.fromUint8Array(new Uint8Array(n),!0);var h=(n,e)=>{u(typeof e!="string",`${n} must be string`),u((e==null?void 0:e.trim().length)===0,`${n} cannot be empty`)},w=n=>{u(!(n instanceof Uint8Array),"key must be an Uint8Array"),u(n.length!==32,"ed25519: key length must be 32 bytes")},u=(n,e)=>{if(n)throw new Error(e)};var A=class{constructor(e){s(this,"walletProviderId");s(this,"walletProviderUrl");s(this,"passkeyCredentialId");this.walletProviderId=e.walletProviderId,this.walletProviderUrl=e.walletProviderUrl}getWalletId(){return this.walletProviderId}async startKeygen({setup:e,authModule:t}){return this.connect(e,t).then(r=>{var p,l;let i=r.split(":");u(i.length!==2,"Invalid keygen response from network");let a=(p=i[0])==null?void 0:p.split("=")[1];return{publicKey:(l=i[1])==null?void 0:l.split("=")[1],keyId:a,passkeyCredentialId:this.passkeyCredentialId}})}async startSigngen({setup:e,authModule:t}){return this.connect(e,t).then(r=>{var p,l;let i=r.split(":");u(i.length!==2,"Invalid signgen response from network");let a=(p=i[0])==null?void 0:p.split("=")[1],o=(l=i[1])==null?void 0:l.split("=")[1];if(a===void 0||o===void 0)throw new Error("Invalid signgen response from network");return{sign:a,recid:parseInt(o)}})}async addEphemeralKey({setup:e,authModule:t}){return this.connect(e,t).then(r=>({status:r}))}connect(e,t){return new Promise((r,i)=>{let a=0,o=e.queryPath;o==="signgen"&&(e.message=R(new TextEncoder().encode(e.message)));let p=new WebSocket(`${this.walletProviderUrl}/${o}`);p.addEventListener("open",l=>{switch(console.debug(`Connection opened in state ${a} with event ${JSON.stringify(l,void 0," ")}`),a){case 0:a=1,p.send(JSON.stringify(e));break;case 1:case 2:a=3,i("Incorrect protocol state");break;case 3:break}}),p.addEventListener("message",async l=>{switch(console.debug(`Connection message in state ${a} with event ${JSON.stringify(l,void 0," ")}`),a){case 0:a=3,i("Incorrect protocol state");break;case 1:{a=2;try{let d=await t.authenticate({setup:e,challenge:l.data});d.credentials.method==="passkey"&&(this.passkeyCredentialId=d.credentials.id),p.send(JSON.stringify(d))}catch(d){i(d)}break}case 2:a=3,p.close(),r(l.data);break;case 3:break}}),p.addEventListener("error",l=>{console.debug(`Connection error in state ${a} with event ${JSON.stringify(l,void 0," ")}`),a!=3&&(a=3,i("Incorrect protocol state"))}),p.addEventListener("close",l=>{console.debug(`Connection closed in state ${a} with event ${JSON.stringify(l,void 0," ")}`),a!=3&&(a=3,i("Incorrect protocol state"))})})}};var ee=1,T=2,te=3,M=[{name:"tag",type:"uint16"},{name:"value",type:"string"}],g=class{constructor({t:e,n:t,key_label:r,permissions:i}){s(this,"t");s(this,"n");s(this,"key_label");s(this,"metadata");this.t=e,this.n=t,r&&(this.key_label=r),this.metadata=[],i&&this.metadata.push({tag:ee,value:i})}set ephClaim(e){this.metadata.push({tag:T,value:e.toJSON()})}get queryPath(){return"keygen"}get requestSchema(){return{Request:[{name:"setup",type:"KeygenSetupOpts"},{name:"challenge",type:"string"}],KeygenSetupOpts:[{name:"t",type:"uint32"},{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:M}}},b=class{constructor({t:e,key_id:t,message:r}){s(this,"t");s(this,"key_id");s(this,"message");this.t=e,this.key_id=t,this.message=r}get queryPath(){return"signgen"}},f=class{constructor({n:e,key_id:t}){s(this,"n");s(this,"key_id");s(this,"metadata");this.n=e,this.key_id=t,this.metadata=[],this.metadata.push({tag:te,value:t})}set ephClaim(e){this.metadata.push({tag:T,value:e.toJSON()})}get queryPath(){return"addEphemeralKey"}get requestSchema(){return{Request:[{name:"setup",type:"AddEphemeralKeyOpts"},{name:"challenge",type:"string"}],AddEphemeralKeyOpts:[{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:M}}},C=class{constructor(e,t,r,i){s(this,"authModule");s(this,"threshold");s(this,"totalNodes");s(this,"wp_client");u(t<2,`Threshold = ${t} must be at least 2`),u(r<t,`Total nodes = ${r} must be greater or equal to threshold = ${t}`),this.threshold=t,this.totalNodes=r,this.authModule=i,this.wp_client=e}async generateKey(e){let t=new g({t:this.threshold,n:this.totalNodes,permissions:e,key_label:void 0});return this.setEphClaimOf(t),await this.wp_client.startKeygen({setup:t,authModule:this.authModule})}async signMessage(e,t){h("keyId",e),h("message",t);let r=new b({t:this.threshold,key_id:e,message:t});return await this.wp_client.startSigngen({setup:r,authModule:this.authModule})}async addEphemeralKey(e){h("keyId",e);let t=new f({n:this.totalNodes,key_id:e});return this.setEphClaimOf(t),await this.wp_client.addEphemeralKey({setup:t,authModule:this.authModule})}setEphClaimOf(e){e.ephClaim=this.authModule.ephClaim}};var ne={name:"SilentShard authentication",version:"0.1.0"},re=[{name:"name",type:"string"},{name:"version",type:"string"}];function ie(n,e,t){let r;return n instanceof g?r=new g({t:n.t,n:n.n,key_label:n.key_label,permissions:void 0}):r=new f({n:n.n,key_id:n.key_id}),r.ephClaim=t,{types:{EIP712Domain:re,...n.requestSchema},domain:ne,primaryType:"Request",message:{setup:r,challenge:e}}}async function N({setup:n,eoa:e,challenge:t,browserWallet:r,ephClaim:i}){let a=ie(n,t,i),o=await r.signTypedData(e,a);return{credentials:{credentials:i.toJSON(),method:"eoa",id:e},signature:o}}var W=require("@noble/curves/ed25519");var O=require("js-base64"),k=require("viem");async function D({user:n,challenge:e,rpConfig:t,ephClaim:r}){let i=(0,k.hexToBytes)(`0x${e}`,{size:32}),a={publicKey:{authenticatorSelection:{residentKey:"preferred",userVerification:"required"},challenge:i,excludeCredentials:[],pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],rp:{name:t.rpName,id:t.rpId},user:{...n,id:O.Base64.toUint8Array(n.id)}}},o=await navigator.credentials.create(a);if(o===null)throw new Error("No credential returned");let p=c(o.response.attestationObject),d={rawCredential:JSON.stringify({authenticatorAttachment:o.authenticatorAttachment,id:o.id,rawId:c(o.rawId),response:{attestationObject:p,clientDataJSON:c(o.response.clientDataJSON)},type:o.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:r.toJSON(),method:"passkey",id:o.id},signature:JSON.stringify(d)}}async function J({challenge:n,allowCredentialId:e,rpConfig:t,ephClaim:r}){let i=(0,k.hexToBytes)(`0x${n}`,{size:32}),a=e?[{type:"public-key",id:O.Base64.toUint8Array(e)}]:[],o={publicKey:{userVerification:"required",challenge:i,allowCredentials:a}},p=await navigator.credentials.get(o);if(p===null)throw new Error("Failed to get navigator credentials");let l=p.response,d=l.userHandle;if(d===null)throw new Error("User handle cannot be null");let H=c(l.signature),L={rawCredential:JSON.stringify({authenticatorAttachment:p.authenticatorAttachment,id:p.id,rawId:c(p.rawId),response:{authenticatorData:c(l.authenticatorData),clientDataJSON:c(l.clientDataJSON),signature:H,userHandle:c(d)},type:p.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:r.toJSON(),method:"passkey",id:p.id},signature:JSON.stringify(L)}}var x=require("viem"),P=require("@noble/curves/ed25519");var m=class{constructor(e,t,r=3600){s(this,"ephId");s(this,"ephPK");s(this,"expiry");this.validateInputs(e,t,r),this.ephId=e,this.ephPK=(0,x.toHex)(t),this.expiry=Math.floor(Date.now()/1e3)+r}validateInputs(e,t,r){h("ephId",e),w(t),u(Number.isInteger(r)===!1,"lifetime must be an integer");let i=r>0&&r<=365*24*60*60;u(!i,"lifetime must be greater than 0 and less than or equal to 365 days")}toJSON(){return JSON.stringify({ephId:this.ephId,ephPK:this.ephPK,expiry:this.expiry})}};async function _({setup:n,challenge:e,ephSK:t,ephClaim:r}){let i={setup:n,challenge:e},a=new TextEncoder,o=(0,x.toHex)(P.ed25519.sign(a.encode(JSON.stringify(i)),t));return{credentials:{credentials:r.toJSON(),method:"ephemeral",id:r.ephId},signature:o}}function q(){return P.ed25519.utils.randomPrivateKey()}function B(n){return P.ed25519.getPublicKey(n)}var $=require("viem");var I=class{constructor(e,t,r,i,a){s(this,"browserWallet");s(this,"eoa");s(this,"ephClaim");this.validateInputs(t,r),this.ephClaim=new m(e,i,a),this.browserWallet=r,this.eoa=t}validateInputs(e,t){u(!(0,$.isAddress)(e),"invalid Ethereum address format"),u(!((t==null?void 0:t.signTypedData)instanceof Function),"invalid browserWallet")}async authenticate({setup:e,challenge:t}){return await N({setup:e,eoa:this.eoa,challenge:t,browserWallet:this.browserWallet,ephClaim:this.ephClaim})}},E=class{constructor(e,t){s(this,"ephSK");s(this,"ephClaim");w(t),this.ephSK=t;let r=W.ed25519.getPublicKey(this.ephSK);this.ephClaim=new m(e,r)}async authenticate({setup:e,challenge:t}){return await _({setup:e,challenge:t,ephSK:this.ephSK,ephClaim:this.ephClaim})}},K=class{constructor(e,t,r,i,a,o){s(this,"rpConfig");s(this,"allowCredentialId");s(this,"user");s(this,"ephClaim");this.ephClaim=new m(i,a,o),this.rpConfig=e,this.user=t,this.allowCredentialId=r}async authenticate({setup:e,challenge:t}){let r=e.queryPath==="addEphemeralKey";if(this.allowCredentialId||r)return await J({allowCredentialId:this.allowCredentialId,challenge:t,rpConfig:this.rpConfig,ephClaim:this.ephClaim});if(this.user)return await D({user:this.user,challenge:t,rpConfig:this.rpConfig,ephClaim:this.ephClaim});throw new Error("Invalid arguments for passkey authentication")}};var v=require("viem/accounts"),F=require("@noble/curves/secp256k1");var y=require("viem");function V(n){if(n.startsWith("0x")&&(n=n.slice(2)),n.startsWith("04"))return(0,v.publicKeyToAddress)(`0x${n} `);if(n.startsWith("02")||n.startsWith("03")){let e=F.secp256k1.ProjectivePoint.fromHex(n).toHex(!1);return(0,v.publicKeyToAddress)(`0x${e}`)}else throw new Error("Invalid public key")}0&&(module.exports={EOAAuth,EphAuth,NetworkSigner,PasskeyAuth,WalletProviderServiceClient,computeAddress,generateEphPrivateKey,getEphPublicKey});
1
+ "use strict";var B=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Ee=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Pe=(n,e)=>{for(var t in e)B(n,t,{get:e[t],enumerable:!0})},Oe=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ae(e))!Ce.call(n,i)&&i!==t&&B(n,i,{get:()=>e[i],enumerable:!(s=be(e,i))||s.enumerable});return n};var ke=n=>Oe(B({},"__esModule",{value:!0}),n);var p=(n,e,t)=>Ee(n,typeof e!="symbol"?e+"":e,t);var Ve={};Pe(Ve,{EOAAuth:()=>O,EphAuth:()=>M,EphKeyClaim:()=>b,NetworkSigner:()=>U,PasskeyAuth:()=>k,PasskeyRegister:()=>R,SignRequestBuilder:()=>v,WalletProviderServiceClient:()=>N,computeAddress:()=>z,default:()=>Je,flattenSignature:()=>F,generateEphPrivateKey:()=>W,getEphPublicKey:()=>K});module.exports=ke(Ve);var ve=1,re=2,j=3,oe=[{name:"tag",type:"uint16"},{name:"value",type:"string"}],m=class{constructor({t:e,n:t,key_label:s,permissions:i,signAlg:o}){p(this,"t");p(this,"n");p(this,"key_label");p(this,"metadata");p(this,"signAlg");this.t=e,this.n=t,s&&(this.key_label=s),this.signAlg=o,this.metadata=[],i&&this.metadata.push({tag:ve,value:i})}set ephClaim(e){this.metadata.push({tag:re,value:e.toJSON()})}get requestSchema(){return{Request:[{name:"setup",type:"KeygenSetupOpts"},{name:"challenge",type:"string"}],KeygenSetupOpts:[{name:"t",type:"uint32"},{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:oe}}},C=class{constructor({t:e,key_id:t,signAlg:s,message:i}){p(this,"t");p(this,"key_id");p(this,"message");p(this,"signAlg");this.t=e,this.key_id=t,this.message=i,this.signAlg=s}},y=class{constructor(){p(this,"metadata");this.metadata=[]}set ephClaim(e){this.metadata.push({tag:re,value:e.toJSON()})}set keyId(e){this.metadata.push({tag:j,value:e})}extractMetadataByTag(e){let t=this.metadata.find(s=>s.tag===e);if(t)return t.value;throw new Error(`Tag ${e} not found in metadata`)}get requestSchema(){return{Request:[{name:"setup",type:"MetadataSetupOpts"},{name:"challenge",type:"string"}],MetadataSetupOpts:[{name:"metadata",type:"TaggedValue[]"}],TaggedValue:oe}}};var Ie={name:"SilentShard authentication",version:"0.1.0"},Ke=[{name:"name",type:"string"},{name:"version",type:"string"}];function Me(n,e,t){let s;return n instanceof m?s=new m({t:n.t,n:n.n,key_label:n.key_label,permissions:void 0,signAlg:n.signAlg}):(s=new y,s.keyId=n.extractMetadataByTag(j)),s.ephClaim=t,{types:{EIP712Domain:Ke,...n.requestSchema},domain:Ie,primaryType:"Request",message:{setup:s,challenge:e}}}async function ae({setup:n,eoa:e,challenge:t,browserWallet:s,ephClaim:i}){let o=Me(n,t,i),r=await s.signTypedData(e,o);return{credentials:{credentials:i.toJSON(),method:"eoa",id:e},signature:r}}var he=require("js-base64");function Re(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function Q(n,...e){if(!Re(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function Y(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function ce(n,e){Q(n);let t=e.outputLen;if(n.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var J=n=>new DataView(n.buffer,n.byteOffset,n.byteLength),w=(n,e)=>n<<32-e|n>>>e;function Ue(n){if(typeof n!="string")throw new Error("utf8ToBytes expected string, got "+typeof n);return new Uint8Array(new TextEncoder().encode(n))}function X(n){return typeof n=="string"&&(n=Ue(n)),Q(n),n}var D=class{clone(){return this._cloneInto()}};function pe(n){let e=s=>n().update(X(s)).digest(),t=n();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>n(),e}function Ne(n,e,t,s){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,t,s);let i=BigInt(32),o=BigInt(4294967295),r=Number(t>>i&o),a=Number(t&o),c=s?4:0,h=s?0:4;n.setUint32(e+c,r,s),n.setUint32(e+h,a,s)}var ue=(n,e,t)=>n&e^~n&t,le=(n,e,t)=>n&e^n&t^e&t,V=class extends D{constructor(e,t,s,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=s,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=J(this.buffer)}update(e){Y(this);let{view:t,buffer:s,blockLen:i}=this;e=X(e);let o=e.length;for(let r=0;r<o;){let a=Math.min(i-this.pos,o-r);if(a===i){let c=J(e);for(;i<=o-r;r+=i)this.process(c,r);continue}s.set(e.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Y(this),ce(e,this),this.finished=!0;let{buffer:t,view:s,blockLen:i,isLE:o}=this,{pos:r}=this;t[r++]=128,this.buffer.subarray(r).fill(0),this.padOffset>i-r&&(this.process(s,0),r=0);for(let u=r;u<i;u++)t[u]=0;Ne(s,i-8,BigInt(this.length*8),o),this.process(s,0);let a=J(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,g=this.get();if(h>g.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,g[u],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let s=e.slice(0,t);return this.destroy(),s}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:s,length:i,finished:o,destroyed:r,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=r,i%t&&e.buffer.set(s),e}};var Te=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),E=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),P=new Uint32Array(64),Z=class extends V{constructor(){super(64,32,8,!1),this.A=E[0]|0,this.B=E[1]|0,this.C=E[2]|0,this.D=E[3]|0,this.E=E[4]|0,this.F=E[5]|0,this.G=E[6]|0,this.H=E[7]|0}get(){let{A:e,B:t,C:s,D:i,E:o,F:r,G:a,H:c}=this;return[e,t,s,i,o,r,a,c]}set(e,t,s,i,o,r,a,c){this.A=e|0,this.B=t|0,this.C=s|0,this.D=i|0,this.E=o|0,this.F=r|0,this.G=a|0,this.H=c|0}process(e,t){for(let u=0;u<16;u++,t+=4)P[u]=e.getUint32(t,!1);for(let u=16;u<64;u++){let d=P[u-15],f=P[u-2],S=w(d,7)^w(d,18)^d>>>3,I=w(f,17)^w(f,19)^f>>>10;P[u]=I+P[u-7]+S+P[u-16]|0}let{A:s,B:i,C:o,D:r,E:a,F:c,G:h,H:g}=this;for(let u=0;u<64;u++){let d=w(a,6)^w(a,11)^w(a,25),f=g+d+ue(a,c,h)+Te[u]+P[u]|0,I=(w(s,2)^w(s,13)^w(s,22))+le(s,i,o)|0;g=h,h=c,c=a,a=r+f|0,r=o,o=i,i=s,s=f+I|0}s=s+this.A|0,i=i+this.B|0,o=o+this.C|0,r=r+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,g=g+this.H|0,this.set(s,i,o,r,a,c,h,g)}roundClean(){P.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ee=pe(()=>new Z);var q=require("viem"),A=n=>he.Base64.fromUint8Array(new Uint8Array(n),!0),$=n=>{let e=(0,q.stringToBytes)(n),t=ee(ee(e));return(0,q.toHex)(t,{size:32}).slice(2)};var te=require("js-base64"),ne=require("viem");async function ge({user:n,challenge:e,rpConfig:t}){let s=(0,ne.hexToBytes)(`0x${e}`,{size:32}),i={publicKey:{authenticatorSelection:{residentKey:"preferred",userVerification:"required"},challenge:s,excludeCredentials:[],pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],rp:{name:t.rpName,id:t.rpId},user:{...n,id:te.Base64.toUint8Array(n.id)}}},o=await navigator.credentials.create(i);if(o===null)throw new Error("No credential returned");let r=A(o.response.attestationObject),c={rawCredential:JSON.stringify({authenticatorAttachment:o.authenticatorAttachment,id:o.id,rawId:A(o.rawId),response:{attestationObject:r,clientDataJSON:A(o.response.clientDataJSON)},type:o.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:"",method:"passkey",id:o.id},signature:JSON.stringify(c)}}async function de({challenge:n,allowCredentialId:e,rpConfig:t,ephClaim:s}){let i=(0,ne.hexToBytes)(`0x${n}`,{size:32}),o=e?[{type:"public-key",id:te.Base64.toUint8Array(e)}]:[],r={publicKey:{userVerification:"required",challenge:i,allowCredentials:o}},a=await navigator.credentials.get(r);if(a===null)throw new Error("Failed to get navigator credentials");let c=a.response,h=c.userHandle;if(h===null)throw new Error("User handle cannot be null");let g=A(c.signature),d={rawCredential:JSON.stringify({authenticatorAttachment:a.authenticatorAttachment,id:a.id,rawId:A(a.rawId),response:{authenticatorData:A(c.authenticatorData),clientDataJSON:A(c.clientDataJSON),signature:g,userHandle:A(h)},type:a.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:s.toJSON(),method:"passkey",id:a.id},signature:JSON.stringify(d)}}var L=require("viem");var _=require("@noble/curves/ed25519"),se=require("@noble/curves/secp256k1");var x=(n,e)=>{l(typeof e!="string",`${n} must be string`),l((e==null?void 0:e.trim().length)===0,`${n} cannot be empty`)},fe=(n,e)=>{l(!(n instanceof Uint8Array),"key must be an Uint8Array"),e==="secp256k1"&&l(n.length!==65,"secp256k1: key length must be 65 bytes, got "+n.length),e==="ed25519"&&l(n.length!==32,"ed25519: key length must be 32 bytes, got "+n.length)},me=(n,e)=>{l(!(n instanceof Uint8Array),"key must be an Uint8Array"),e==="secp256k1"&&l(n.length!==32,"secp256k1: key length must be 32 bytes, got "+n.length),e==="ed25519"&&l(n.length!==32,"ed25519: key length must be 32 bytes, got "+n.length)};var l=(n,e)=>{if(n)throw new Error(e)};var ye=require("viem/accounts");var b=class{constructor(e,t,s,i=3600){p(this,"ephId");p(this,"ephPK");p(this,"signAlg");p(this,"expiry");this.validateInputs(e,t,s,i),this.ephId=e,this.ephPK=(0,L.toHex)(t),this.signAlg=s,this.expiry=Math.floor(Date.now()/1e3)+i}validateInputs(e,t,s,i){x("ephId",e),fe(t,s),l(Number.isInteger(i)===!1,"lifetime must be an integer");let o=i>0&&i<=365*24*60*60;l(!o,"lifetime must be greater than 0 and less than or equal to 365 days")}toJSON(){return JSON.stringify({ephId:this.ephId,ephPK:this.ephPK,expiry:this.expiry,signAlg:this.signAlg})}};async function Se({setup:n,challenge:e,ephSK:t,ephClaim:s}){let i={setup:n,challenge:e},o=new TextEncoder().encode(JSON.stringify(i)),r=await Be(o,t,s.signAlg),a;n instanceof C&&(a=n.message);let c={base64Message:a,signature:r};return{credentials:{credentials:s.toJSON(),method:"ephemeral",id:s.ephId},signature:JSON.stringify(c)}}async function Be(n,e,t){switch(t){case"ed25519":return(0,L.toHex)(_.ed25519.sign(n,e));case"secp256k1":return await(0,ye.signMessage)({message:{raw:n},privateKey:(0,L.toHex)(e)});default:throw new Error("Invalid signature algorithm")}}function W(n){switch(n){case"ed25519":return _.ed25519.utils.randomPrivateKey();case"secp256k1":return se.secp256k1.utils.randomPrivateKey();default:throw new Error("Invalid signature algorithm")}}function K(n,e){switch(e){case"ed25519":return _.ed25519.getPublicKey(n);case"secp256k1":return se.secp256k1.getPublicKey(n,!1);default:throw new Error("Invalid signature algorithm")}}var we=require("viem");var O=class{constructor(e,t,s){p(this,"browserWallet");p(this,"eoa");p(this,"ephClaim");p(this,"ephClaims");this.validateInputs(e,t,s.ephClaim,s.ephClaims),s.ephClaims&&(this.ephClaims=s.ephClaims),s.ephClaim&&(this.ephClaim=s.ephClaim),this.browserWallet=t,this.eoa=e}validateInputs(e,t,s,i){l(!(0,we.isAddress)(e),"invalid Ethereum address format"),l(!((t==null?void 0:t.signTypedData)instanceof Function),"invalid browserWallet"),l(!!s==!!i,"one and only one of the eph claim fields must be populated")}getEphClaims(){return this.ephClaim?this.ephClaim:this.ephClaims}async authenticate({setup:e,challenge:t}){l(!(e instanceof m||e instanceof y),`invalid setup for EOA authenticate. Requires KeygenSetupOpts or MetadataSetupOpts but found ${JSON.stringify(e)}`);let s;if(this.ephClaim)s=this.ephClaim;else if(this.ephClaims&&e instanceof m){if(s=this.ephClaims.get(e.signAlg),!s)throw new Error(`No EphKeyClaim for ${e.signAlg}`)}else throw new Error("No EphKeyClaim associated with current authentication");return await ae({setup:e,eoa:this.eoa,challenge:t,browserWallet:this.browserWallet,ephClaim:s})}},M=class{constructor(e,t,s){p(this,"ephSK");p(this,"ephClaim");me(t,s),this.ephSK=t;let i=K(this.ephSK,s);this.ephClaim=new b(e,i,s)}async authenticate({setup:e,challenge:t}){return l(!(e instanceof C||e instanceof y),`invalid setup for Eph authenticate. Requires SignSetupOpts or MetadataSetupOpts but found ${JSON.stringify(e)}`),await Se({setup:e,challenge:t,ephSK:this.ephSK,ephClaim:this.ephClaim})}},k=class{constructor(e,t,s){p(this,"rpConfig");p(this,"allowCredentialId");p(this,"ephClaim");p(this,"ephClaims");this.validateInputs(s.ephClaim,s.ephClaims),s.ephClaims&&(this.ephClaims=s.ephClaims),s.ephClaim&&(this.ephClaim=s.ephClaim),this.rpConfig=e,this.allowCredentialId=t}validateInputs(e,t){l(!!e==!!t,"one and only one of the eph claim fields must be populated")}getEphClaims(){return this.ephClaim?this.ephClaim:this.ephClaims}async authenticate({setup:e,challenge:t}){l(!(e instanceof m||e instanceof y),`invalid setup for Passkey authenticate. Requires KeygenSetupOpts or MetadataSetupOpts but found ${JSON.stringify(e)}`);let s;if(this.ephClaim)s=this.ephClaim;else if(this.ephClaims&&e instanceof m){if(s=this.ephClaims.get(e.signAlg),!s)throw new Error(`No EphKeyClaim for ${e.signAlg}`)}else throw new Error("No EphKeyClaim associated with current authentication");return await de({allowCredentialId:this.allowCredentialId,challenge:t,rpConfig:this.rpConfig,ephClaim:s})}},R=class{constructor(e,t){p(this,"rpConfig");p(this,"user");this.rpConfig=e,this.user=t}async authenticate({setup:e,challenge:t}){return l(!(e instanceof y),`invalid setup for Passkey register. Requires MetadataSetupOpts but found ${JSON.stringify(e)}`),await ge({user:this.user,challenge:t,rpConfig:this.rpConfig})}};var v=class{constructor(){p(this,"signRequest",new Map)}setRequest(e,t,s){if(x("transactionId",e),x("message",t),x("requestType",s),this.signRequest.has(e))throw new Error(`Transaction ID ${e} is already set.`);return this.signRequest.set(e,{message:t,requestType:s}),this}build(){let e={};if(this.signRequest.forEach((t,s)=>{t.requestType==="eddsa"?e[s]=t.message:e[s]=JSON.stringify(t)}),Object.keys(e).length===0)throw new Error("No sign request is set.");return JSON.stringify(e)}},U=class{constructor(e,t,s,i){p(this,"authModule");p(this,"threshold");p(this,"totalNodes");p(this,"wpClient");l(t<2,`Threshold = ${t} must be at least 2`),l(s<t,`Total nodes = ${s} must be greater or equal to threshold = ${t}`),this.threshold=t,this.totalNodes=s,this.authModule=i,this.wpClient=e}async generateKey(e,t){let s=[];return e.forEach(o=>{let r=new m({t:this.threshold,n:this.totalNodes,permissions:t,key_label:void 0,signAlg:o});this.setEphClaimOf(r),s.push(r)}),await this.wpClient.startKeygen({setups:s,authModule:this.authModule})}async signMessage(e,t,s){x("keyId",e),x("signAlg",t),x("signRequest",s);let i=new C({t:this.threshold,key_id:e,signAlg:t,message:s});return await this.wpClient.startSigngen({setup:i,authModule:this.authModule})}async addEphemeralKey(e){x("keyId",e);let t=new y;return t.keyId=e,this.setEphClaimOf(t),await this.wpClient.addEphemeralKey({setup:t,authModule:this.authModule})}async revokeEphemeralKey(e){x("keyId",e);let t=new y;return t.keyId=e,this.setEphClaimOf(t),await this.wpClient.revokeEphemeralKey({setup:t,authModule:this.authModule})}async registerPasskey(){let e=new y;return await this.wpClient.registerPasskey({setup:e,authModule:this.authModule})}setEphClaimOf(e){if(!(this.authModule instanceof O||this.authModule instanceof k))return;let t=this.authModule.getEphClaims();if(t instanceof b)e.ephClaim=t;else if(e instanceof m)if(t.has(e.signAlg))e.ephClaim=t.get(e.signAlg);else throw new Error("no eph claim for "+e.signAlg)}},F=n=>{let{sign:e,recid:t}=n,s=(27+t).toString(16);return`0x${e}${s}`};var ie=require("js-base64");var N=class{constructor(e){p(this,"walletProviderId");p(this,"walletProviderUrl");p(this,"apiVersion","v1");this.walletProviderId=e.walletProviderId,this.walletProviderUrl=`${e.walletProviderUrl}/${e.apiVersion}`,this.apiVersion=e.apiVersion}getVersion(){return this.apiVersion}getWalletId(){return this.walletProviderId}async startKeygen({setups:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("keygen",e,t).then(i=>{let o=i.split(";");l(o.length!==e.length,"Invalid keygen response from network, not all keys were generated");let r=[];return o.forEach(a=>{var d,f,S;let c=a.split(":");l(c.length!==3,"Invalid keygen response from network");let h=(d=c[0])==null?void 0:d.split("=")[1],g=(f=c[1])==null?void 0:f.split("=")[1],u=(S=c[2])==null?void 0:S.split("=")[1];r.push({publicKey:g,keyId:h,signAlg:u})}),r})}async startSigngen({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("signgen",e,t).then(i=>i.split(";").map(r=>{var a,c,h,g,u;if(e.signAlg=="secp256k1"){let d=r.split(":");l(d.length!==3,"Invalid signgen response from network");let f=(a=d[0])==null?void 0:a.split("=")[1],S=(c=d[1])==null?void 0:c.split("=")[1],I=(h=d[2])==null?void 0:h.split("=")[1];if(f===void 0||S===void 0||I===void 0)throw new Error("Invalid signgen response from network");return{transactionId:I,sign:f,recid:parseInt(S)}}else{let d=r.split(":");l(d.length!==2,"Invalid signgen response from network");let f=(g=d[0])==null?void 0:g.split("=")[1],S=(u=d[1])==null?void 0:u.split("=")[1];if(f===void 0||S===void 0)throw new Error("Invalid signgen response from network");return{transactionId:S,sign:f,recid:0}}}))}async addEphemeralKey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("addEphemeralKey",e,t).then(i=>({status:i}))}async revokeEphemeralKey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("revokeEphemeralKey",e,t).then(i=>({status:i}))}async registerPasskey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("registerPasskey",e,t).then(i=>({passkeyCredentialId:i}))}connect(e,t,s){return new Promise((i,o)=>{let r=0;e==="signgen"&&(t.message=ie.Base64.encode(t.message));let a=new WebSocket(`${this.walletProviderUrl}/${e}`);a.addEventListener("open",c=>{switch(console.debug(`Connection opened in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r){case 0:r=1,a.send(JSON.stringify(t));break;case 1:case 2:r=3,o("Incorrect protocol state");break;case 3:break}}),a.addEventListener("message",async c=>{switch(console.debug(`Connection message in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r){case 0:r=3,o("Incorrect protocol state");break;case 1:{r=2;try{let h=c.data,g=new H(s);if(e==="keygen"){let u=JSON.parse(c.data);l(u===void 0,"Received data is not in a expected key:value format"),await g.setKeygenUserSigsV1(t,u)}else e==="signgen"?await g.setSigngenUserSigs(t,h):await g.setMetadataUserSigs(t,h);a.send(JSON.stringify(g.build()))}catch(h){o(h)}break}case 2:{r=3,a.close(),i(c.data);break}case 3:break}}),a.addEventListener("error",c=>{console.debug(`Connection error in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r!=3&&(r=3,o("Incorrect protocol state"))}),a.addEventListener("close",c=>{console.debug(`Connection closed in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r!=3&&(r=3,o("Incorrect protocol state"))})})}connectV2(e,t,s){return new Promise((i,o)=>{let r=0;e==="signgen"&&(t.message=ie.Base64.encode(t.message));let a=new WebSocket(`${this.walletProviderUrl}/${e}`);a.addEventListener("open",async c=>{switch(console.debug(`Connection opened in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r){case 0:r=2;try{let h=JSON.stringify(t),g=new H(s);e==="keygen"?await g.setKeygenUserSigsV2(t):e==="signgen"?await g.setSigngenUserSigs(t):await g.setMetadataUserSigs(t),a.send(JSON.stringify({setupOpts:h,userSigs:g.build()}))}catch(h){o(h)}break;case 2:r=3,o("Incorrect protocol state");break;case 3:break}}),a.addEventListener("message",async c=>{switch(console.debug(`Connection message in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r){case 0:r=3,o("Incorrect protocol state");break;case 2:{r=3,a.close(),i(c.data);break}case 3:break}}),a.addEventListener("error",c=>{console.debug(`Connection error in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r!=3&&(r=3,o("Incorrect protocol state"))}),a.addEventListener("close",c=>{console.debug(`Connection closed in state ${r} with event ${JSON.stringify(c,void 0," ")}`),r!=3&&(r=3,o("Incorrect protocol state"))})})}},H=class{constructor(e){p(this,"userAuthentications");p(this,"authModule");this.authModule=e,this.userAuthentications=new Map}async setKeygenUserSigsV1(e,t){for(let s of e){let i=s.signAlg,o=t[i];if(o){let r=await this.authModule.authenticate({setup:s,challenge:o});this.userAuthentications.set(i,r)}else throw new Error(`no final challenge found in response for ${i}`)}}async setKeygenUserSigsV2(e){for(let t of e){let s=t.signAlg,i=await this.authModule.authenticate({setup:t,challenge:$(JSON.stringify(t))});this.userAuthentications.set(s,i)}}async setSigngenUserSigs(e,t){let s=await this.authModule.authenticate({setup:e,challenge:t!=null?t:$(JSON.stringify(e))});this.userAuthentications.set(e.signAlg,s)}async setMetadataUserSigs(e,t){let s=await this.authModule.authenticate({setup:e,challenge:t!=null?t:$(JSON.stringify(e))});this.userAuthentications.set("main",s)}build(){return Object.fromEntries(this.userAuthentications)}};var G=require("viem/accounts"),xe=require("@noble/curves/secp256k1");var T=require("viem"),De=require("js-base64");function z(n){if(n.startsWith("0x")&&(n=n.slice(2)),n.startsWith("04"))return(0,G.publicKeyToAddress)(`0x${n} `);if(n.startsWith("02")||n.startsWith("03")){let e=xe.secp256k1.ProjectivePoint.fromHex(n).toHex(!1);return(0,G.publicKeyToAddress)(`0x${e}`)}else throw new Error("Invalid public key")}var Je={NetworkSigner:U,SignRequestBuilder:v,WalletProviderServiceClient:N,EOAAuth:O,EphAuth:M,PasskeyAuth:k,PasskeyRegister:R,generateEphPrivateKey:W,getEphPublicKey:K,EphKeyClaim:b,computeAddress:z,flattenSignature:F};0&&(module.exports={EOAAuth,EphAuth,EphKeyClaim,NetworkSigner,PasskeyAuth,PasskeyRegister,SignRequestBuilder,WalletProviderServiceClient,computeAddress,flattenSignature,generateEphPrivateKey,getEphPublicKey});
2
+ /*! Bundled license information:
3
+
4
+ @noble/hashes/esm/utils.js:
5
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6
+ */
package/dist/index.d.ts CHANGED
@@ -1,9 +1,31 @@
1
- export type { SignResponse, KeygenResponse, AddEphemeralKeyResponse } from './networkSigner';
2
- export type { IBrowserWallet, TypedData } from './EOAauthentication';
3
- export type { ClientConfig, IWalletProviderServiceClient } from './walletProviderServiceClientInterface';
4
- export type { PasskeyUser, RelyingPartyConfig } from './passkeyAuthentication';
5
- export { WalletProviderServiceClient } from './walletProviderServiceClient';
6
- export { NetworkSigner } from './networkSigner';
7
- export { EOAAuth, EphAuth, PasskeyAuth } from './authentication';
1
+ export type { SignResponse, KeygenResponse, OperationStatusResponse, RegisterPasskeyResponse } from './client/types';
2
+ export type { SignRequestType } from './client/networkSigner';
3
+ export type { ApiVersion, ClientConfig, IWalletProviderServiceClient, } from './client/walletProviderServiceClientInterface';
4
+ export type { IBrowserWallet, TypedData } from './auth/EOAauthentication';
5
+ export type { PasskeyUser, RelyingPartyConfig } from './auth/passkeyAuthentication';
6
+ export type { SignAlgorithm } from './auth/ephemeralAuthentication';
7
+ export { NetworkSigner, SignRequestBuilder, flattenSignature } from './client/networkSigner';
8
+ export { WalletProviderServiceClient } from './client/walletProviderServiceClient';
9
+ export { EOAAuth, EphAuth, PasskeyAuth, PasskeyRegister } from './auth/authentication';
10
+ export { generateEphPrivateKey, getEphPublicKey, EphKeyClaim } from './auth/ephemeralAuthentication';
8
11
  export { computeAddress } from './viemSigner';
9
- export { generateEphPrivateKey, getEphPublicKey } from './ephemeralAuthentication';
12
+ import { NetworkSigner, SignRequestBuilder } from './client/networkSigner';
13
+ import { WalletProviderServiceClient } from './client/walletProviderServiceClient';
14
+ import { EOAAuth, EphAuth, PasskeyAuth, PasskeyRegister } from './auth/authentication';
15
+ import { generateEphPrivateKey, getEphPublicKey, EphKeyClaim } from './auth/ephemeralAuthentication';
16
+ import { computeAddress } from './viemSigner';
17
+ declare const _default: {
18
+ NetworkSigner: typeof NetworkSigner;
19
+ SignRequestBuilder: typeof SignRequestBuilder;
20
+ WalletProviderServiceClient: typeof WalletProviderServiceClient;
21
+ EOAAuth: typeof EOAAuth;
22
+ EphAuth: typeof EphAuth;
23
+ PasskeyAuth: typeof PasskeyAuth;
24
+ PasskeyRegister: typeof PasskeyRegister;
25
+ generateEphPrivateKey: typeof generateEphPrivateKey;
26
+ getEphPublicKey: typeof getEphPublicKey;
27
+ EphKeyClaim: typeof EphKeyClaim;
28
+ computeAddress: typeof computeAddress;
29
+ flattenSignature: (signgenResponse: import(".").SignResponse) => `0x${string}`;
30
+ };
31
+ export default _default;
package/dist/index.esm.js CHANGED
@@ -1 +1,6 @@
1
- var $=Object.defineProperty,F=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var w=(n,e,t)=>e in n?$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,y=(n,e)=>{for(var t in e||(e={}))H.call(e,t)&&w(n,t,e[t]);if(O)for(var t of O(e))L.call(e,t)&&w(n,t,e[t]);return n},A=(n,e)=>F(n,V(e));var s=(n,e,t)=>w(n,typeof e!="symbol"?e+"":e,t);import{Base64 as Q}from"js-base64";var k=n=>btoa(String.fromCodePoint.apply(null,Array.from(n))),c=n=>Q.fromUint8Array(new Uint8Array(n),!0);var h=(n,e)=>{u(typeof e!="string","".concat(n," must be string")),u((e==null?void 0:e.trim().length)===0,"".concat(n," cannot be empty"))},S=n=>{u(!(n instanceof Uint8Array),"key must be an Uint8Array"),u(n.length!==32,"ed25519: key length must be 32 bytes")},u=(n,e)=>{if(n)throw new Error(e)};var C=class{constructor(e){s(this,"walletProviderId");s(this,"walletProviderUrl");s(this,"passkeyCredentialId");this.walletProviderId=e.walletProviderId,this.walletProviderUrl=e.walletProviderUrl}getWalletId(){return this.walletProviderId}async startKeygen({setup:e,authModule:t}){return this.connect(e,t).then(r=>{var p,l;let i=r.split(":");u(i.length!==2,"Invalid keygen response from network");let a=(p=i[0])==null?void 0:p.split("=")[1];return{publicKey:(l=i[1])==null?void 0:l.split("=")[1],keyId:a,passkeyCredentialId:this.passkeyCredentialId}})}async startSigngen({setup:e,authModule:t}){return this.connect(e,t).then(r=>{var p,l;let i=r.split(":");u(i.length!==2,"Invalid signgen response from network");let a=(p=i[0])==null?void 0:p.split("=")[1],o=(l=i[1])==null?void 0:l.split("=")[1];if(a===void 0||o===void 0)throw new Error("Invalid signgen response from network");return{sign:a,recid:parseInt(o)}})}async addEphemeralKey({setup:e,authModule:t}){return this.connect(e,t).then(r=>({status:r}))}connect(e,t){return new Promise((r,i)=>{let a=0,o=e.queryPath;o==="signgen"&&(e.message=k(new TextEncoder().encode(e.message)));let p=new WebSocket("".concat(this.walletProviderUrl,"/").concat(o));p.addEventListener("open",l=>{switch(console.debug("Connection opened in state ".concat(a," with event ").concat(JSON.stringify(l,void 0," "))),a){case 0:a=1,p.send(JSON.stringify(e));break;case 1:case 2:a=3,i("Incorrect protocol state");break;case 3:break}}),p.addEventListener("message",async l=>{switch(console.debug("Connection message in state ".concat(a," with event ").concat(JSON.stringify(l,void 0," "))),a){case 0:a=3,i("Incorrect protocol state");break;case 1:{a=2;try{let d=await t.authenticate({setup:e,challenge:l.data});d.credentials.method==="passkey"&&(this.passkeyCredentialId=d.credentials.id),p.send(JSON.stringify(d))}catch(d){i(d)}break}case 2:a=3,p.close(),r(l.data);break;case 3:break}}),p.addEventListener("error",l=>{console.debug("Connection error in state ".concat(a," with event ").concat(JSON.stringify(l,void 0," "))),a!=3&&(a=3,i("Incorrect protocol state"))}),p.addEventListener("close",l=>{console.debug("Connection closed in state ".concat(a," with event ").concat(JSON.stringify(l,void 0," "))),a!=3&&(a=3,i("Incorrect protocol state"))})})}};var G=1,x=2,z=3,U=[{name:"tag",type:"uint16"},{name:"value",type:"string"}],g=class{constructor({t:e,n:t,key_label:r,permissions:i}){s(this,"t");s(this,"n");s(this,"key_label");s(this,"metadata");this.t=e,this.n=t,r&&(this.key_label=r),this.metadata=[],i&&this.metadata.push({tag:G,value:i})}set ephClaim(e){this.metadata.push({tag:x,value:e.toJSON()})}get queryPath(){return"keygen"}get requestSchema(){return{Request:[{name:"setup",type:"KeygenSetupOpts"},{name:"challenge",type:"string"}],KeygenSetupOpts:[{name:"t",type:"uint32"},{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:U}}},P=class{constructor({t:e,key_id:t,message:r}){s(this,"t");s(this,"key_id");s(this,"message");this.t=e,this.key_id=t,this.message=r}get queryPath(){return"signgen"}},f=class{constructor({n:e,key_id:t}){s(this,"n");s(this,"key_id");s(this,"metadata");this.n=e,this.key_id=t,this.metadata=[],this.metadata.push({tag:z,value:t})}set ephClaim(e){this.metadata.push({tag:x,value:e.toJSON()})}get queryPath(){return"addEphemeralKey"}get requestSchema(){return{Request:[{name:"setup",type:"AddEphemeralKeyOpts"},{name:"challenge",type:"string"}],AddEphemeralKeyOpts:[{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:U}}},I=class{constructor(e,t,r,i){s(this,"authModule");s(this,"threshold");s(this,"totalNodes");s(this,"wp_client");u(t<2,"Threshold = ".concat(t," must be at least 2")),u(r<t,"Total nodes = ".concat(r," must be greater or equal to threshold = ").concat(t)),this.threshold=t,this.totalNodes=r,this.authModule=i,this.wp_client=e}async generateKey(e){let t=new g({t:this.threshold,n:this.totalNodes,permissions:e,key_label:void 0});return this.setEphClaimOf(t),await this.wp_client.startKeygen({setup:t,authModule:this.authModule})}async signMessage(e,t){h("keyId",e),h("message",t);let r=new P({t:this.threshold,key_id:e,message:t});return await this.wp_client.startSigngen({setup:r,authModule:this.authModule})}async addEphemeralKey(e){h("keyId",e);let t=new f({n:this.totalNodes,key_id:e});return this.setEphClaimOf(t),await this.wp_client.addEphemeralKey({setup:t,authModule:this.authModule})}setEphClaimOf(e){e.ephClaim=this.authModule.ephClaim}};var Y={name:"SilentShard authentication",version:"0.1.0"},X=[{name:"name",type:"string"},{name:"version",type:"string"}];function Z(n,e,t){let r;return n instanceof g?r=new g({t:n.t,n:n.n,key_label:n.key_label,permissions:void 0}):r=new f({n:n.n,key_id:n.key_id}),r.ephClaim=t,{types:y({EIP712Domain:X},n.requestSchema),domain:Y,primaryType:"Request",message:{setup:r,challenge:e}}}async function R({setup:n,eoa:e,challenge:t,browserWallet:r,ephClaim:i}){let a=Z(n,t,i),o=await r.signTypedData(e,a);return{credentials:{credentials:i.toJSON(),method:"eoa",id:e},signature:o}}import{ed25519 as te}from"@noble/curves/ed25519";import{Base64 as T}from"js-base64";import{hexToBytes as M}from"viem";async function N({user:n,challenge:e,rpConfig:t,ephClaim:r}){let i=M("0x".concat(e),{size:32}),a={publicKey:{authenticatorSelection:{residentKey:"preferred",userVerification:"required"},challenge:i,excludeCredentials:[],pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],rp:{name:t.rpName,id:t.rpId},user:A(y({},n),{id:T.toUint8Array(n.id)})}},o=await navigator.credentials.create(a);if(o===null)throw new Error("No credential returned");let p=c(o.response.attestationObject),d={rawCredential:JSON.stringify({authenticatorAttachment:o.authenticatorAttachment,id:o.id,rawId:c(o.rawId),response:{attestationObject:p,clientDataJSON:c(o.response.clientDataJSON)},type:o.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:r.toJSON(),method:"passkey",id:o.id},signature:JSON.stringify(d)}}async function D({challenge:n,allowCredentialId:e,rpConfig:t,ephClaim:r}){let i=M("0x".concat(n),{size:32}),a=e?[{type:"public-key",id:T.toUint8Array(e)}]:[],o={publicKey:{userVerification:"required",challenge:i,allowCredentials:a}},p=await navigator.credentials.get(o);if(p===null)throw new Error("Failed to get navigator credentials");let l=p.response,d=l.userHandle;if(d===null)throw new Error("User handle cannot be null");let B=c(l.signature),W={rawCredential:JSON.stringify({authenticatorAttachment:p.authenticatorAttachment,id:p.id,rawId:c(p.rawId),response:{authenticatorData:c(l.authenticatorData),clientDataJSON:c(l.clientDataJSON),signature:B,userHandle:c(d)},type:p.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:r.toJSON(),method:"passkey",id:p.id},signature:JSON.stringify(W)}}import{toHex as J}from"viem";import{ed25519 as E}from"@noble/curves/ed25519";var m=class{constructor(e,t,r=3600){s(this,"ephId");s(this,"ephPK");s(this,"expiry");this.validateInputs(e,t,r),this.ephId=e,this.ephPK=J(t),this.expiry=Math.floor(Date.now()/1e3)+r}validateInputs(e,t,r){h("ephId",e),S(t),u(Number.isInteger(r)===!1,"lifetime must be an integer");let i=r>0&&r<=365*24*60*60;u(!i,"lifetime must be greater than 0 and less than or equal to 365 days")}toJSON(){return JSON.stringify({ephId:this.ephId,ephPK:this.ephPK,expiry:this.expiry})}};async function _({setup:n,challenge:e,ephSK:t,ephClaim:r}){let i={setup:n,challenge:e},a=new TextEncoder,o=J(E.sign(a.encode(JSON.stringify(i)),t));return{credentials:{credentials:r.toJSON(),method:"ephemeral",id:r.ephId},signature:o}}function j(){return E.utils.randomPrivateKey()}function ee(n){return E.getPublicKey(n)}import{isAddress as ne}from"viem";var K=class{constructor(e,t,r,i,a){s(this,"browserWallet");s(this,"eoa");s(this,"ephClaim");this.validateInputs(t,r),this.ephClaim=new m(e,i,a),this.browserWallet=r,this.eoa=t}validateInputs(e,t){u(!ne(e),"invalid Ethereum address format"),u(!((t==null?void 0:t.signTypedData)instanceof Function),"invalid browserWallet")}async authenticate({setup:e,challenge:t}){return await R({setup:e,eoa:this.eoa,challenge:t,browserWallet:this.browserWallet,ephClaim:this.ephClaim})}},v=class{constructor(e,t){s(this,"ephSK");s(this,"ephClaim");S(t),this.ephSK=t;let r=te.getPublicKey(this.ephSK);this.ephClaim=new m(e,r)}async authenticate({setup:e,challenge:t}){return await _({setup:e,challenge:t,ephSK:this.ephSK,ephClaim:this.ephClaim})}},b=class{constructor(e,t,r,i,a,o){s(this,"rpConfig");s(this,"allowCredentialId");s(this,"user");s(this,"ephClaim");this.ephClaim=new m(i,a,o),this.rpConfig=e,this.user=t,this.allowCredentialId=r}async authenticate({setup:e,challenge:t}){let r=e.queryPath==="addEphemeralKey";if(this.allowCredentialId||r)return await D({allowCredentialId:this.allowCredentialId,challenge:t,rpConfig:this.rpConfig,ephClaim:this.ephClaim});if(this.user)return await N({user:this.user,challenge:t,rpConfig:this.rpConfig,ephClaim:this.ephClaim});throw new Error("Invalid arguments for passkey authentication")}};import{publicKeyToAddress as q,toAccount as Ve}from"viem/accounts";import{secp256k1 as re}from"@noble/curves/secp256k1";import{hashMessage as ze,hashTypedData as Ye,keccak256 as Xe,serializeSignature as Ze,serializeTransaction as je,toHex as tt}from"viem";function ie(n){if(n.startsWith("0x")&&(n=n.slice(2)),n.startsWith("04"))return q("0x".concat(n," "));if(n.startsWith("02")||n.startsWith("03")){let e=re.ProjectivePoint.fromHex(n).toHex(!1);return q("0x".concat(e))}else throw new Error("Invalid public key")}export{K as EOAAuth,v as EphAuth,I as NetworkSigner,b as PasskeyAuth,C as WalletProviderServiceClient,ie as computeAddress,j as generateEphPrivateKey,ee as getEphPublicKey};
1
+ var Se=Object.defineProperty,we=Object.defineProperties;var xe=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var $=(n,e,t)=>e in n?Se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,K=(n,e)=>{for(var t in e||(e={}))be.call(e,t)&&$(n,t,e[t]);if(ee)for(var t of ee(e))Ae.call(e,t)&&$(n,t,e[t]);return n},L=(n,e)=>we(n,xe(e));var p=(n,e,t)=>$(n,typeof e!="symbol"?e+"":e,t);var Ce=1,te=2,_=3,ne=[{name:"tag",type:"uint16"},{name:"value",type:"string"}],m=class{constructor({t:e,n:t,key_label:s,permissions:r,signAlg:o}){p(this,"t");p(this,"n");p(this,"key_label");p(this,"metadata");p(this,"signAlg");this.t=e,this.n=t,s&&(this.key_label=s),this.signAlg=o,this.metadata=[],r&&this.metadata.push({tag:Ce,value:r})}set ephClaim(e){this.metadata.push({tag:te,value:e.toJSON()})}get requestSchema(){return{Request:[{name:"setup",type:"KeygenSetupOpts"},{name:"challenge",type:"string"}],KeygenSetupOpts:[{name:"t",type:"uint32"},{name:"n",type:"uint32"},{name:"metadata",type:"TaggedValue[]"}],TaggedValue:ne}}},C=class{constructor({t:e,key_id:t,signAlg:s,message:r}){p(this,"t");p(this,"key_id");p(this,"message");p(this,"signAlg");this.t=e,this.key_id=t,this.message=r,this.signAlg=s}},y=class{constructor(){p(this,"metadata");this.metadata=[]}set ephClaim(e){this.metadata.push({tag:te,value:e.toJSON()})}set keyId(e){this.metadata.push({tag:_,value:e})}extractMetadataByTag(e){let t=this.metadata.find(s=>s.tag===e);if(t)return t.value;throw new Error("Tag ".concat(e," not found in metadata"))}get requestSchema(){return{Request:[{name:"setup",type:"MetadataSetupOpts"},{name:"challenge",type:"string"}],MetadataSetupOpts:[{name:"metadata",type:"TaggedValue[]"}],TaggedValue:ne}}};var Ee={name:"SilentShard authentication",version:"0.1.0"},Pe=[{name:"name",type:"string"},{name:"version",type:"string"}];function Oe(n,e,t){let s;return n instanceof m?s=new m({t:n.t,n:n.n,key_label:n.key_label,permissions:void 0,signAlg:n.signAlg}):(s=new y,s.keyId=n.extractMetadataByTag(_)),s.ephClaim=t,{types:K({EIP712Domain:Pe},n.requestSchema),domain:Ee,primaryType:"Request",message:{setup:s,challenge:e}}}async function se({setup:n,eoa:e,challenge:t,browserWallet:s,ephClaim:r}){let o=Oe(n,t,r),i=await s.signTypedData(e,o);return{credentials:{credentials:r.toJSON(),method:"eoa",id:e},signature:i}}import{Base64 as Me}from"js-base64";function ke(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function W(n,...e){if(!ke(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}function F(n,e=!0){if(n.destroyed)throw new Error("Hash instance has been destroyed");if(e&&n.finished)throw new Error("Hash#digest() has already been called")}function ie(n,e){W(n);let t=e.outputLen;if(n.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}var D=n=>new DataView(n.buffer,n.byteOffset,n.byteLength),w=(n,e)=>n<<32-e|n>>>e;function ve(n){if(typeof n!="string")throw new Error("utf8ToBytes expected string, got "+typeof n);return new Uint8Array(new TextEncoder().encode(n))}function H(n){return typeof n=="string"&&(n=ve(n)),W(n),n}var B=class{clone(){return this._cloneInto()}};function re(n){let e=s=>n().update(H(s)).digest(),t=n();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>n(),e}function Ie(n,e,t,s){if(typeof n.setBigUint64=="function")return n.setBigUint64(e,t,s);let r=BigInt(32),o=BigInt(4294967295),i=Number(t>>r&o),a=Number(t&o),c=s?4:0,h=s?0:4;n.setUint32(e+c,i,s),n.setUint32(e+h,a,s)}var oe=(n,e,t)=>n&e^~n&t,ae=(n,e,t)=>n&e^n&t^e&t,J=class extends B{constructor(e,t,s,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=s,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=D(this.buffer)}update(e){F(this);let{view:t,buffer:s,blockLen:r}=this;e=H(e);let o=e.length;for(let i=0;i<o;){let a=Math.min(r-this.pos,o-i);if(a===r){let c=D(e);for(;r<=o-i;i+=r)this.process(c,i);continue}s.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){F(this),ie(e,this),this.finished=!0;let{buffer:t,view:s,blockLen:r,isLE:o}=this,{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(s,0),i=0);for(let u=i;u<r;u++)t[u]=0;Ie(s,r-8,BigInt(this.length*8),o),this.process(s,0);let a=D(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,g=this.get();if(h>g.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,g[u],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let s=e.slice(0,t);return this.destroy(),s}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:s,length:r,finished:o,destroyed:i,pos:a}=this;return e.length=r,e.pos=a,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(s),e}};var Ke=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),E=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),P=new Uint32Array(64),G=class extends J{constructor(){super(64,32,8,!1),this.A=E[0]|0,this.B=E[1]|0,this.C=E[2]|0,this.D=E[3]|0,this.E=E[4]|0,this.F=E[5]|0,this.G=E[6]|0,this.H=E[7]|0}get(){let{A:e,B:t,C:s,D:r,E:o,F:i,G:a,H:c}=this;return[e,t,s,r,o,i,a,c]}set(e,t,s,r,o,i,a,c){this.A=e|0,this.B=t|0,this.C=s|0,this.D=r|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,t){for(let u=0;u<16;u++,t+=4)P[u]=e.getUint32(t,!1);for(let u=16;u<64;u++){let d=P[u-15],f=P[u-2],S=w(d,7)^w(d,18)^d>>>3,v=w(f,17)^w(f,19)^f>>>10;P[u]=v+P[u-7]+S+P[u-16]|0}let{A:s,B:r,C:o,D:i,E:a,F:c,G:h,H:g}=this;for(let u=0;u<64;u++){let d=w(a,6)^w(a,11)^w(a,25),f=g+d+oe(a,c,h)+Ke[u]+P[u]|0,v=(w(s,2)^w(s,13)^w(s,22))+ae(s,r,o)|0;g=h,h=c,c=a,a=i+f|0,i=o,o=r,r=s,s=f+v|0}s=s+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,g=g+this.H|0,this.set(s,r,o,i,a,c,h,g)}roundClean(){P.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var z=re(()=>new G);import{stringToBytes as Re,toHex as Ue}from"viem";var b=n=>Me.fromUint8Array(new Uint8Array(n),!0),V=n=>{let e=Re(n),t=z(z(e));return Ue(t,{size:32}).slice(2)};import{Base64 as ce}from"js-base64";import{hexToBytes as pe}from"viem";async function ue({user:n,challenge:e,rpConfig:t}){let s=pe("0x".concat(e),{size:32}),r={publicKey:{authenticatorSelection:{residentKey:"preferred",userVerification:"required"},challenge:s,excludeCredentials:[],pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],rp:{name:t.rpName,id:t.rpId},user:L(K({},n),{id:ce.toUint8Array(n.id)})}},o=await navigator.credentials.create(r);if(o===null)throw new Error("No credential returned");let i=b(o.response.attestationObject),c={rawCredential:JSON.stringify({authenticatorAttachment:o.authenticatorAttachment,id:o.id,rawId:b(o.rawId),response:{attestationObject:i,clientDataJSON:b(o.response.clientDataJSON)},type:o.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:"",method:"passkey",id:o.id},signature:JSON.stringify(c)}}async function le({challenge:n,allowCredentialId:e,rpConfig:t,ephClaim:s}){let r=pe("0x".concat(n),{size:32}),o=e?[{type:"public-key",id:ce.toUint8Array(e)}]:[],i={publicKey:{userVerification:"required",challenge:r,allowCredentials:o}},a=await navigator.credentials.get(i);if(a===null)throw new Error("Failed to get navigator credentials");let c=a.response,h=c.userHandle;if(h===null)throw new Error("User handle cannot be null");let g=b(c.signature),d={rawCredential:JSON.stringify({authenticatorAttachment:a.authenticatorAttachment,id:a.id,rawId:b(a.rawId),response:{authenticatorData:b(c.authenticatorData),clientDataJSON:b(c.clientDataJSON),signature:g,userHandle:b(h)},type:a.type}),origin:t.rpName,rpId:t.rpId};return{credentials:{credentials:s.toJSON(),method:"passkey",id:a.id},signature:JSON.stringify(d)}}import{toHex as j}from"viem";import{ed25519 as Q}from"@noble/curves/ed25519";import{secp256k1 as de}from"@noble/curves/secp256k1";var x=(n,e)=>{l(typeof e!="string","".concat(n," must be string")),l((e==null?void 0:e.trim().length)===0,"".concat(n," cannot be empty"))},he=(n,e)=>{l(!(n instanceof Uint8Array),"key must be an Uint8Array"),e==="secp256k1"&&l(n.length!==65,"secp256k1: key length must be 65 bytes, got "+n.length),e==="ed25519"&&l(n.length!==32,"ed25519: key length must be 32 bytes, got "+n.length)},ge=(n,e)=>{l(!(n instanceof Uint8Array),"key must be an Uint8Array"),e==="secp256k1"&&l(n.length!==32,"secp256k1: key length must be 32 bytes, got "+n.length),e==="ed25519"&&l(n.length!==32,"ed25519: key length must be 32 bytes, got "+n.length)};var l=(n,e)=>{if(n)throw new Error(e)};import{signMessage as Ne}from"viem/accounts";var A=class{constructor(e,t,s,r=3600){p(this,"ephId");p(this,"ephPK");p(this,"signAlg");p(this,"expiry");this.validateInputs(e,t,s,r),this.ephId=e,this.ephPK=j(t),this.signAlg=s,this.expiry=Math.floor(Date.now()/1e3)+r}validateInputs(e,t,s,r){x("ephId",e),he(t,s),l(Number.isInteger(r)===!1,"lifetime must be an integer");let o=r>0&&r<=365*24*60*60;l(!o,"lifetime must be greater than 0 and less than or equal to 365 days")}toJSON(){return JSON.stringify({ephId:this.ephId,ephPK:this.ephPK,expiry:this.expiry,signAlg:this.signAlg})}};async function fe({setup:n,challenge:e,ephSK:t,ephClaim:s}){let r={setup:n,challenge:e},o=new TextEncoder().encode(JSON.stringify(r)),i=await Te(o,t,s.signAlg),a;n instanceof C&&(a=n.message);let c={base64Message:a,signature:i};return{credentials:{credentials:s.toJSON(),method:"ephemeral",id:s.ephId},signature:JSON.stringify(c)}}async function Te(n,e,t){switch(t){case"ed25519":return j(Q.sign(n,e));case"secp256k1":return await Ne({message:{raw:n},privateKey:j(e)});default:throw new Error("Invalid signature algorithm")}}function Y(n){switch(n){case"ed25519":return Q.utils.randomPrivateKey();case"secp256k1":return de.utils.randomPrivateKey();default:throw new Error("Invalid signature algorithm")}}function M(n,e){switch(e){case"ed25519":return Q.getPublicKey(n);case"secp256k1":return de.getPublicKey(n,!1);default:throw new Error("Invalid signature algorithm")}}import{isAddress as Be}from"viem";var O=class{constructor(e,t,s){p(this,"browserWallet");p(this,"eoa");p(this,"ephClaim");p(this,"ephClaims");this.validateInputs(e,t,s.ephClaim,s.ephClaims),s.ephClaims&&(this.ephClaims=s.ephClaims),s.ephClaim&&(this.ephClaim=s.ephClaim),this.browserWallet=t,this.eoa=e}validateInputs(e,t,s,r){l(!Be(e),"invalid Ethereum address format"),l(!((t==null?void 0:t.signTypedData)instanceof Function),"invalid browserWallet"),l(!!s==!!r,"one and only one of the eph claim fields must be populated")}getEphClaims(){return this.ephClaim?this.ephClaim:this.ephClaims}async authenticate({setup:e,challenge:t}){l(!(e instanceof m||e instanceof y),"invalid setup for EOA authenticate. Requires KeygenSetupOpts or MetadataSetupOpts but found ".concat(JSON.stringify(e)));let s;if(this.ephClaim)s=this.ephClaim;else if(this.ephClaims&&e instanceof m){if(s=this.ephClaims.get(e.signAlg),!s)throw new Error("No EphKeyClaim for ".concat(e.signAlg))}else throw new Error("No EphKeyClaim associated with current authentication");return await se({setup:e,eoa:this.eoa,challenge:t,browserWallet:this.browserWallet,ephClaim:s})}},R=class{constructor(e,t,s){p(this,"ephSK");p(this,"ephClaim");ge(t,s),this.ephSK=t;let r=M(this.ephSK,s);this.ephClaim=new A(e,r,s)}async authenticate({setup:e,challenge:t}){return l(!(e instanceof C||e instanceof y),"invalid setup for Eph authenticate. Requires SignSetupOpts or MetadataSetupOpts but found ".concat(JSON.stringify(e))),await fe({setup:e,challenge:t,ephSK:this.ephSK,ephClaim:this.ephClaim})}},k=class{constructor(e,t,s){p(this,"rpConfig");p(this,"allowCredentialId");p(this,"ephClaim");p(this,"ephClaims");this.validateInputs(s.ephClaim,s.ephClaims),s.ephClaims&&(this.ephClaims=s.ephClaims),s.ephClaim&&(this.ephClaim=s.ephClaim),this.rpConfig=e,this.allowCredentialId=t}validateInputs(e,t){l(!!e==!!t,"one and only one of the eph claim fields must be populated")}getEphClaims(){return this.ephClaim?this.ephClaim:this.ephClaims}async authenticate({setup:e,challenge:t}){l(!(e instanceof m||e instanceof y),"invalid setup for Passkey authenticate. Requires KeygenSetupOpts or MetadataSetupOpts but found ".concat(JSON.stringify(e)));let s;if(this.ephClaim)s=this.ephClaim;else if(this.ephClaims&&e instanceof m){if(s=this.ephClaims.get(e.signAlg),!s)throw new Error("No EphKeyClaim for ".concat(e.signAlg))}else throw new Error("No EphKeyClaim associated with current authentication");return await le({allowCredentialId:this.allowCredentialId,challenge:t,rpConfig:this.rpConfig,ephClaim:s})}},U=class{constructor(e,t){p(this,"rpConfig");p(this,"user");this.rpConfig=e,this.user=t}async authenticate({setup:e,challenge:t}){return l(!(e instanceof y),"invalid setup for Passkey register. Requires MetadataSetupOpts but found ".concat(JSON.stringify(e))),await ue({user:this.user,challenge:t,rpConfig:this.rpConfig})}};var I=class{constructor(){p(this,"signRequest",new Map)}setRequest(e,t,s){if(x("transactionId",e),x("message",t),x("requestType",s),this.signRequest.has(e))throw new Error("Transaction ID ".concat(e," is already set."));return this.signRequest.set(e,{message:t,requestType:s}),this}build(){let e={};if(this.signRequest.forEach((t,s)=>{t.requestType==="eddsa"?e[s]=t.message:e[s]=JSON.stringify(t)}),Object.keys(e).length===0)throw new Error("No sign request is set.");return JSON.stringify(e)}},N=class{constructor(e,t,s,r){p(this,"authModule");p(this,"threshold");p(this,"totalNodes");p(this,"wpClient");l(t<2,"Threshold = ".concat(t," must be at least 2")),l(s<t,"Total nodes = ".concat(s," must be greater or equal to threshold = ").concat(t)),this.threshold=t,this.totalNodes=s,this.authModule=r,this.wpClient=e}async generateKey(e,t){let s=[];return e.forEach(o=>{let i=new m({t:this.threshold,n:this.totalNodes,permissions:t,key_label:void 0,signAlg:o});this.setEphClaimOf(i),s.push(i)}),await this.wpClient.startKeygen({setups:s,authModule:this.authModule})}async signMessage(e,t,s){x("keyId",e),x("signAlg",t),x("signRequest",s);let r=new C({t:this.threshold,key_id:e,signAlg:t,message:s});return await this.wpClient.startSigngen({setup:r,authModule:this.authModule})}async addEphemeralKey(e){x("keyId",e);let t=new y;return t.keyId=e,this.setEphClaimOf(t),await this.wpClient.addEphemeralKey({setup:t,authModule:this.authModule})}async revokeEphemeralKey(e){x("keyId",e);let t=new y;return t.keyId=e,this.setEphClaimOf(t),await this.wpClient.revokeEphemeralKey({setup:t,authModule:this.authModule})}async registerPasskey(){let e=new y;return await this.wpClient.registerPasskey({setup:e,authModule:this.authModule})}setEphClaimOf(e){if(!(this.authModule instanceof O||this.authModule instanceof k))return;let t=this.authModule.getEphClaims();if(t instanceof A)e.ephClaim=t;else if(e instanceof m)if(t.has(e.signAlg))e.ephClaim=t.get(e.signAlg);else throw new Error("no eph claim for "+e.signAlg)}},X=n=>{let{sign:e,recid:t}=n,s=(27+t).toString(16);return"0x".concat(e).concat(s)};import{Base64 as me}from"js-base64";var T=class{constructor(e){p(this,"walletProviderId");p(this,"walletProviderUrl");p(this,"apiVersion","v1");this.walletProviderId=e.walletProviderId,this.walletProviderUrl="".concat(e.walletProviderUrl,"/").concat(e.apiVersion),this.apiVersion=e.apiVersion}getVersion(){return this.apiVersion}getWalletId(){return this.walletProviderId}async startKeygen({setups:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("keygen",e,t).then(r=>{let o=r.split(";");l(o.length!==e.length,"Invalid keygen response from network, not all keys were generated");let i=[];return o.forEach(a=>{var d,f,S;let c=a.split(":");l(c.length!==3,"Invalid keygen response from network");let h=(d=c[0])==null?void 0:d.split("=")[1],g=(f=c[1])==null?void 0:f.split("=")[1],u=(S=c[2])==null?void 0:S.split("=")[1];i.push({publicKey:g,keyId:h,signAlg:u})}),i})}async startSigngen({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("signgen",e,t).then(r=>r.split(";").map(i=>{var a,c,h,g,u;if(e.signAlg=="secp256k1"){let d=i.split(":");l(d.length!==3,"Invalid signgen response from network");let f=(a=d[0])==null?void 0:a.split("=")[1],S=(c=d[1])==null?void 0:c.split("=")[1],v=(h=d[2])==null?void 0:h.split("=")[1];if(f===void 0||S===void 0||v===void 0)throw new Error("Invalid signgen response from network");return{transactionId:v,sign:f,recid:parseInt(S)}}else{let d=i.split(":");l(d.length!==2,"Invalid signgen response from network");let f=(g=d[0])==null?void 0:g.split("=")[1],S=(u=d[1])==null?void 0:u.split("=")[1];if(f===void 0||S===void 0)throw new Error("Invalid signgen response from network");return{transactionId:S,sign:f,recid:0}}}))}async addEphemeralKey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("addEphemeralKey",e,t).then(r=>({status:r}))}async revokeEphemeralKey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("revokeEphemeralKey",e,t).then(r=>({status:r}))}async registerPasskey({setup:e,authModule:t}){return(this.apiVersion==="v1"?this.connect.bind(this):this.connectV2.bind(this))("registerPasskey",e,t).then(r=>({passkeyCredentialId:r}))}connect(e,t,s){return new Promise((r,o)=>{let i=0;e==="signgen"&&(t.message=me.encode(t.message));let a=new WebSocket("".concat(this.walletProviderUrl,"/").concat(e));a.addEventListener("open",c=>{switch(console.debug("Connection opened in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i){case 0:i=1,a.send(JSON.stringify(t));break;case 1:case 2:i=3,o("Incorrect protocol state");break;case 3:break}}),a.addEventListener("message",async c=>{switch(console.debug("Connection message in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i){case 0:i=3,o("Incorrect protocol state");break;case 1:{i=2;try{let h=c.data,g=new q(s);if(e==="keygen"){let u=JSON.parse(c.data);l(u===void 0,"Received data is not in a expected key:value format"),await g.setKeygenUserSigsV1(t,u)}else e==="signgen"?await g.setSigngenUserSigs(t,h):await g.setMetadataUserSigs(t,h);a.send(JSON.stringify(g.build()))}catch(h){o(h)}break}case 2:{i=3,a.close(),r(c.data);break}case 3:break}}),a.addEventListener("error",c=>{console.debug("Connection error in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i!=3&&(i=3,o("Incorrect protocol state"))}),a.addEventListener("close",c=>{console.debug("Connection closed in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i!=3&&(i=3,o("Incorrect protocol state"))})})}connectV2(e,t,s){return new Promise((r,o)=>{let i=0;e==="signgen"&&(t.message=me.encode(t.message));let a=new WebSocket("".concat(this.walletProviderUrl,"/").concat(e));a.addEventListener("open",async c=>{switch(console.debug("Connection opened in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i){case 0:i=2;try{let h=JSON.stringify(t),g=new q(s);e==="keygen"?await g.setKeygenUserSigsV2(t):e==="signgen"?await g.setSigngenUserSigs(t):await g.setMetadataUserSigs(t),a.send(JSON.stringify({setupOpts:h,userSigs:g.build()}))}catch(h){o(h)}break;case 2:i=3,o("Incorrect protocol state");break;case 3:break}}),a.addEventListener("message",async c=>{switch(console.debug("Connection message in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i){case 0:i=3,o("Incorrect protocol state");break;case 2:{i=3,a.close(),r(c.data);break}case 3:break}}),a.addEventListener("error",c=>{console.debug("Connection error in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i!=3&&(i=3,o("Incorrect protocol state"))}),a.addEventListener("close",c=>{console.debug("Connection closed in state ".concat(i," with event ").concat(JSON.stringify(c,void 0," "))),i!=3&&(i=3,o("Incorrect protocol state"))})})}},q=class{constructor(e){p(this,"userAuthentications");p(this,"authModule");this.authModule=e,this.userAuthentications=new Map}async setKeygenUserSigsV1(e,t){for(let s of e){let r=s.signAlg,o=t[r];if(o){let i=await this.authModule.authenticate({setup:s,challenge:o});this.userAuthentications.set(r,i)}else throw new Error("no final challenge found in response for ".concat(r))}}async setKeygenUserSigsV2(e){for(let t of e){let s=t.signAlg,r=await this.authModule.authenticate({setup:t,challenge:V(JSON.stringify(t))});this.userAuthentications.set(s,r)}}async setSigngenUserSigs(e,t){let s=await this.authModule.authenticate({setup:e,challenge:t!=null?t:V(JSON.stringify(e))});this.userAuthentications.set(e.signAlg,s)}async setMetadataUserSigs(e,t){let s=await this.authModule.authenticate({setup:e,challenge:t!=null?t:V(JSON.stringify(e))});this.userAuthentications.set("main",s)}build(){return Object.fromEntries(this.userAuthentications)}};import{publicKeyToAddress as ye,toAccount as Ft}from"viem/accounts";import{secp256k1 as De}from"@noble/curves/secp256k1";import{hashMessage as Yt,hashTypedData as Xt,keccak256 as Zt,serializeSignature as en,serializeTransaction as tn,toHex as sn}from"viem";import{Base64 as on}from"js-base64";function Z(n){if(n.startsWith("0x")&&(n=n.slice(2)),n.startsWith("04"))return ye("0x".concat(n," "));if(n.startsWith("02")||n.startsWith("03")){let e=De.ProjectivePoint.fromHex(n).toHex(!1);return ye("0x".concat(e))}else throw new Error("Invalid public key")}var dn={NetworkSigner:N,SignRequestBuilder:I,WalletProviderServiceClient:T,EOAAuth:O,EphAuth:R,PasskeyAuth:k,PasskeyRegister:U,generateEphPrivateKey:Y,getEphPublicKey:M,EphKeyClaim:A,computeAddress:Z,flattenSignature:X};export{O as EOAAuth,R as EphAuth,A as EphKeyClaim,N as NetworkSigner,k as PasskeyAuth,U as PasskeyRegister,I as SignRequestBuilder,T as WalletProviderServiceClient,Z as computeAddress,dn as default,X as flattenSignature,Y as generateEphPrivateKey,M as getEphPublicKey};
2
+ /*! Bundled license information:
3
+
4
+ @noble/hashes/esm/utils.js:
5
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6
+ */
@@ -0,0 +1,77 @@
1
+ import { EphKeyClaim } from './auth/ephemeralAuthentication';
2
+ export declare const TAG_EPH_KEY = 2;
3
+ export declare const TAG_KEY_ID = 3;
4
+ export declare class KeygenSetupOpts {
5
+ /** Threshold, number of parties that needs to participate in a protocol in order to produce valid signature */
6
+ t: number;
7
+ /** Total number of nodes that participate in Key generation, must be greater or equal than `t` */
8
+ n: number;
9
+ /** Optional key label */
10
+ key_label?: string;
11
+ /** Metadata for a key. Currently they store the permissions, can be set in a constructor of this class.
12
+ If permissions are not set, all operations are allowed.
13
+ */
14
+ private metadata;
15
+ /** Signature algorithm chosen for key generation */
16
+ signAlg: string;
17
+ constructor({ t, n, key_label, permissions, signAlg, }: {
18
+ t: number;
19
+ n: number;
20
+ key_label: string | undefined;
21
+ permissions: string | undefined;
22
+ signAlg: string;
23
+ });
24
+ set ephClaim(ephClaim: EphKeyClaim);
25
+ get requestSchema(): {
26
+ Request: {
27
+ name: string;
28
+ type: string;
29
+ }[];
30
+ KeygenSetupOpts: {
31
+ name: string;
32
+ type: string;
33
+ }[];
34
+ TaggedValue: {
35
+ name: string;
36
+ type: string;
37
+ }[];
38
+ };
39
+ }
40
+ export declare class SignSetupOpts {
41
+ /** Number of nodes that will participate in the signature execution */
42
+ t: number;
43
+ /** Select the key using it's ID */
44
+ key_id: string;
45
+ /** The message to sign */
46
+ message: string;
47
+ /** Select which signature algorithm to use */
48
+ signAlg: string;
49
+ constructor({ t, key_id, signAlg, message }: {
50
+ t: number;
51
+ key_id: string;
52
+ message: string;
53
+ signAlg: string;
54
+ });
55
+ }
56
+ export declare class MetadataSetupOpts {
57
+ /** Metadata for a keyshare if in used by adding eph key. Otherwise, it provides metadata for the authentication setup.*/
58
+ private metadata;
59
+ constructor();
60
+ set ephClaim(ephClaim: EphKeyClaim);
61
+ set keyId(keyId: string);
62
+ extractMetadataByTag(tag: number): string;
63
+ get requestSchema(): {
64
+ Request: {
65
+ name: string;
66
+ type: string;
67
+ }[];
68
+ MetadataSetupOpts: {
69
+ name: string;
70
+ type: string;
71
+ }[];
72
+ TaggedValue: {
73
+ name: string;
74
+ type: string;
75
+ }[];
76
+ };
77
+ }