@actioncodes/protocol 2.0.25 → 2.0.27
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction, VersionedTransaction, TransactionInstruction, Connection } from "@solana/web3.js";
|
|
1
|
+
import { Transaction, VersionedTransaction, TransactionInstruction, Connection, type TransactionResponse, type VersionedTransactionResponse, type ParsedTransactionWithMeta } from "@solana/web3.js";
|
|
2
2
|
import { BaseChainAdapter } from "./BaseChainAdapter";
|
|
3
3
|
import { type ProtocolMetaFields } from "../utils/protocolMeta";
|
|
4
4
|
import type { ActionCode, DelegatedActionCode } from "../types";
|
|
@@ -17,12 +17,28 @@ export declare class SolanaAdapter extends BaseChainAdapter {
|
|
|
17
17
|
verifyRevokeWithDelegation(delegatedActionCode: DelegatedActionCode, revokeSignature: string): boolean;
|
|
18
18
|
/** Create a Solana memo instruction carrying protocol meta (for SDK/clients) */
|
|
19
19
|
static createProtocolMetaIx(meta: ProtocolMetaFields): TransactionInstruction;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Extract protocol metadata string (memo) from a base64-encoded transaction, or null
|
|
22
|
+
* @overload
|
|
23
|
+
*/
|
|
21
24
|
getProtocolMeta(txString: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Extract protocol metadata string (memo) from a transaction response from solana.getTransaction(), or null
|
|
27
|
+
* @overload
|
|
28
|
+
*/
|
|
29
|
+
getProtocolMeta(txResponse: TransactionResponse | VersionedTransactionResponse | ParsedTransactionWithMeta): string | null;
|
|
22
30
|
/** Deserialize a base64-encoded transaction string to SolanaTransaction */
|
|
23
31
|
private deserializeTransaction;
|
|
24
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Get parsed ProtocolMeta object from base64-encoded transaction, or null if none or invalid
|
|
34
|
+
* @overload
|
|
35
|
+
*/
|
|
25
36
|
parseMeta(txString: string): ProtocolMetaFields | null;
|
|
37
|
+
/**
|
|
38
|
+
* Get parsed ProtocolMeta object from transaction response from solana.getTransaction(), or null if none or invalid
|
|
39
|
+
* @overload
|
|
40
|
+
*/
|
|
41
|
+
parseMeta(txResponse: TransactionResponse | VersionedTransactionResponse | ParsedTransactionWithMeta): ProtocolMetaFields | null;
|
|
26
42
|
/** List memo instructions from the transaction (legacy & versioned) */
|
|
27
43
|
private getMemoInstructions;
|
|
28
44
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/SolanaAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EAEtB,UAAU,
|
|
1
|
+
{"version":3,"file":"SolanaAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/SolanaAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EAEtB,UAAU,EAGV,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,EACjC,KAAK,yBAAyB,EAG/B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAQhE,0CAA0C;AAC1C,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,oBAAoB,CAAC;AAEnE,eAAO,MAAM,kBAAkB,EAAG,QAAiB,CAAC;AAEpD,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,0CAA0C;IAC1C,OAAO,CAAC,eAAe;IAOvB,mEAAmE;IACnE,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IA6BjD,wCAAwC;IACxC,oBAAoB,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,OAAO;IAkFvE,0EAA0E;IAC1E,sBAAsB,CACpB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO;IA8BV,0BAA0B,CACxB,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,MAAM,GACtB,OAAO;IAiFV,gFAAgF;IAChF,MAAM,CAAC,oBAAoB,CACzB,IAAI,EAAE,kBAAkB,GACvB,sBAAsB;IAKzB;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAChD;;;OAGG;IACH,eAAe,CACb,UAAU,EACN,mBAAmB,GACnB,4BAA4B,GAC5B,yBAAyB,GAC5B,MAAM,GAAG,IAAI;IAwJhB,2EAA2E;IAC3E,OAAO,CAAC,sBAAsB;IAqB9B;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI;IACtD;;;OAGG;IACH,SAAS,CACP,UAAU,EACN,mBAAmB,GACnB,4BAA4B,GAC5B,yBAAyB,GAC5B,kBAAkB,GAAG,IAAI;IAgB5B,uEAAuE;IACvE,OAAO,CAAC,mBAAmB;IAyE3B;;;OAGG;IACH,4BAA4B,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAiC5E;;;;OAIG;IACH,oCAAoC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAoI5D,gCAAgC,CAC9B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,IAAI;IA2BP;;;;;;;;;OASG;WACU,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,kBAAkB,EACxB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,MAAM,CAAC;CA8JnB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var I0=Object.create;var{getPrototypeOf:b0,defineProperty:o,getOwnPropertyNames:e8,getOwnPropertyDescriptor:m0}=Object,o8=Object.prototype.hasOwnProperty;var Q8=(Q,$,q)=>{q=Q!=null?I0(b0(Q)):{};let Z=$||!Q||!Q.__esModule?o(q,"default",{value:Q,enumerable:!0}):q;for(let Y of e8(Q))if(!o8.call(Z,Y))o(Z,Y,{get:()=>Q[Y],enumerable:!0});return Z},t8=new WeakMap,B0=(Q)=>{var $=t8.get(Q),q;if($)return $;if($=o({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")e8(Q).map((Z)=>!o8.call($,Z)&&o($,Z,{get:()=>Q[Z],enumerable:!(q=m0(Q,Z))||q.enumerable}));return t8.set(Q,$),$};var y0=(Q,$)=>{for(var q in $)o(Q,q,{get:$[q],enumerable:!0,configurable:!0,set:(Z)=>$[q]=()=>Z})};var r0={};y0(r0,{validateProtocolMetaFormat:()=>i0,truncateBits:()=>O8,sha256:()=>F0,serializeDelegationProof:()=>x8,serializeCanonicalRevoke:()=>l,serializeCanonical:()=>H,parseProtocolMeta:()=>U8,hmacSha256:()=>v8,hkdfSha256:()=>d0,getCanonicalMessageParts:()=>w8,digestToDigits:()=>F8,codeHash:()=>u,buildProtocolMeta:()=>T8,base32EncodeCrockford:()=>l0,WalletStrategy:()=>t,TransactionNotSignedByIssuerError:()=>u8,TransactionNotSignedByIntendedOwnerError:()=>A8,SolanaAdapter:()=>e,SUPPORTED_CHAINS:()=>M8,SCHEME:()=>k8,ProtocolErrorCode:()=>w0,ProtocolError:()=>X,PROTOCOL_NORMALIZATION:()=>J8,PROTOCOL_META_MAX_BYTES:()=>a,MissingMetaError:()=>C8,MetaMismatchError:()=>p8,InvalidSignatureError:()=>h8,InvalidPubkeyFormatError:()=>g8,InvalidCodeFormatError:()=>c8,InvalidAdapterError:()=>d8,ExpiredCodeError:()=>f8,DelegationStrategy:()=>I8,CODE_MIN_LENGTH:()=>L8,CODE_MAX_LENGTH:()=>V8,CODE_DEFAULT_LENGTH:()=>n0,CODE_CHARSET_DIGITS:()=>s0,CANONICAL_REVOKE_MESSAGE_PREFIX:()=>L0,CANONICAL_MESSAGE_VERSION:()=>l8,CANONICAL_MESSAGE_PREFIX:()=>x0,BaseChainAdapter:()=>j8,ActionCodesProtocol:()=>k0,ADAPTER_CHAIN_NAME:()=>n});module.exports=B0(r0);class j8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function E0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function G8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let q=$&&`"${$}" `;throw Error(`${q}expected integer >= 0, got ${Q}`)}}function f(Q,$,q=""){let Z=E0(Q),Y=Q?.length,J=$!==void 0;if(!Z||J&&Y!==$){let U=q&&`"${q}" `,z=J?` of length ${$}`:"",G=Z?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+z+", got "+G)}return Q}function $8(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");G8(Q.outputLen),G8(Q.blockLen)}function s(Q,$=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if($&&Q.finished)throw Error("Hash#digest() has already been called")}function Q0(Q,$){f(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function T(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function N8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function I(Q,$){return Q<<32-$|Q>>>$}function $0(Q,$={}){let q=(Y,J)=>Q(J).update(Y).digest(),Z=Q(void 0);return q.outputLen=Z.outputLen,q.blockLen=Z.blockLen,q.create=(Y)=>Q(Y),Object.assign(q,$),Object.freeze(q)}var q0=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function Z0(Q,$,q){return Q&$^~Q&q}function Y0(Q,$,q){return Q&$^Q&q^$&q}class R8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,q,Z){this.blockLen=Q,this.outputLen=$,this.padOffset=q,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=N8(this.buffer)}update(Q){s(this),f(Q);let{view:$,buffer:q,blockLen:Z}=this,Y=Q.length;for(let J=0;J<Y;){let U=Math.min(Z-this.pos,Y-J);if(U===Z){let z=N8(Q);for(;Z<=Y-J;J+=Z)this.process(z,J);continue}if(q.set(Q.subarray(J,J+U),this.pos),this.pos+=U,J+=U,this.pos===Z)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){s(this),Q0(Q,this),this.finished=!0;let{buffer:$,view:q,blockLen:Z,isLE:Y}=this,{pos:J}=this;if($[J++]=128,T(this.buffer.subarray(J)),this.padOffset>Z-J)this.process(q,0),J=0;for(let K=J;K<Z;K++)$[K]=0;q.setBigUint64(Z-8,BigInt(this.length*8),Y),this.process(q,0);let U=N8(Q),z=this.outputLen;if(z%4)throw Error("_sha2: outputLen must be aligned to 32bit");let G=z/4,N=this.get();if(G>N.length)throw Error("_sha2: outputLen bigger than state");for(let K=0;K<G;K++)U.setUint32(4*K,N[K],Y)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let q=Q.slice(0,$);return this.destroy(),q}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:q,length:Z,finished:Y,destroyed:J,pos:U}=this;if(Q.destroyed=J,Q.finished=Y,Q.length=Z,Q.pos=U,Z%$)Q.buffer.set(q);return Q}clone(){return this._cloneInto()}}var y=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),x=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),L=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var W8=BigInt(4294967295),J0=BigInt(32);function H0(Q,$=!1){if($)return{h:Number(Q&W8),l:Number(Q>>J0&W8)};return{h:Number(Q>>J0&W8)|0,l:Number(Q&W8)|0}}function X0(Q,$=!1){let q=Q.length,Z=new Uint32Array(q),Y=new Uint32Array(q);for(let J=0;J<q;J++){let{h:U,l:z}=H0(Q[J],$);[Z[J],Y[J]]=[U,z]}return[Z,Y]}var E8=(Q,$,q)=>Q>>>q,H8=(Q,$,q)=>Q<<32-q|$>>>q,c=(Q,$,q)=>Q>>>q|$<<32-q,d=(Q,$,q)=>Q<<32-q|$>>>q,q8=(Q,$,q)=>Q<<64-q|$>>>q-32,Z8=(Q,$,q)=>Q>>>q-32|$<<64-q;function b(Q,$,q,Z){let Y=($>>>0)+(Z>>>0);return{h:Q+q+(Y/4294967296|0)|0,l:Y|0}}var U0=(Q,$,q)=>(Q>>>0)+($>>>0)+(q>>>0),z0=(Q,$,q,Z)=>$+q+Z+(Q/4294967296|0)|0,K0=(Q,$,q,Z)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0),j0=(Q,$,q,Z,Y)=>$+q+Z+Y+(Q/4294967296|0)|0,G0=(Q,$,q,Z,Y)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0)+(Y>>>0),N0=(Q,$,q,Z,Y,J)=>$+q+Z+Y+J+(Q/4294967296|0)|0;var _0=Uint32Array.from([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]),C=new Uint32Array(64);class P8 extends R8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:q,D:Z,E:Y,F:J,G:U,H:z}=this;return[Q,$,q,Z,Y,J,U,z]}set(Q,$,q,Z,Y,J,U,z){this.A=Q|0,this.B=$|0,this.C=q|0,this.D=Z|0,this.E=Y|0,this.F=J|0,this.G=U|0,this.H=z|0}process(Q,$){for(let K=0;K<16;K++,$+=4)C[K]=Q.getUint32($,!1);for(let K=16;K<64;K++){let j=C[K-15],R=C[K-2],W=I(j,7)^I(j,18)^j>>>3,F=I(R,17)^I(R,19)^R>>>10;C[K]=F+C[K-7]+W+C[K-16]|0}let{A:q,B:Z,C:Y,D:J,E:U,F:z,G,H:N}=this;for(let K=0;K<64;K++){let j=I(U,6)^I(U,11)^I(U,25),R=N+j+Z0(U,z,G)+_0[K]+C[K]|0,F=(I(q,2)^I(q,13)^I(q,22))+Y0(q,Z,Y)|0;N=G,G=z,z=U,U=J+R|0,J=Y,Y=Z,Z=q,q=R+F|0}q=q+this.A|0,Z=Z+this.B|0,Y=Y+this.C|0,J=J+this.D|0,U=U+this.E|0,z=z+this.F|0,G=G+this.G|0,N=N+this.H|0,this.set(q,Z,Y,J,U,z,G,N)}roundClean(){T(C)}destroy(){this.set(0,0,0,0,0,0,0,0),T(this.buffer)}}class R0 extends P8{A=y[0]|0;B=y[1]|0;C=y[2]|0;D=y[3]|0;E=y[4]|0;F=y[5]|0;G=y[6]|0;H=y[7]|0;constructor(){super(32)}}class S0 extends P8{A=E[0]|0;B=E[1]|0;C=E[2]|0;D=E[3]|0;E=E[4]|0;F=E[5]|0;G=E[6]|0;H=E[7]|0;constructor(){super(28)}}var W0=(()=>X0(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((Q)=>BigInt(Q))))(),f0=(()=>W0[0])(),C0=(()=>W0[1])(),p=new Uint32Array(80),A=new Uint32Array(80);class Y8 extends R8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:q,Bl:Z,Ch:Y,Cl:J,Dh:U,Dl:z,Eh:G,El:N,Fh:K,Fl:j,Gh:R,Gl:W,Hh:F,Hl:w}=this;return[Q,$,q,Z,Y,J,U,z,G,N,K,j,R,W,F,w]}set(Q,$,q,Z,Y,J,U,z,G,N,K,j,R,W,F,w){this.Ah=Q|0,this.Al=$|0,this.Bh=q|0,this.Bl=Z|0,this.Ch=Y|0,this.Cl=J|0,this.Dh=U|0,this.Dl=z|0,this.Eh=G|0,this.El=N|0,this.Fh=K|0,this.Fl=j|0,this.Gh=R|0,this.Gl=W|0,this.Hh=F|0,this.Hl=w|0}process(Q,$){for(let O=0;O<16;O++,$+=4)p[O]=Q.getUint32($),A[O]=Q.getUint32($+=4);for(let O=16;O<80;O++){let _=p[O-15]|0,S=A[O-15]|0,b8=c(_,S,1)^c(_,S,8)^E8(_,S,7),m8=d(_,S,1)^d(_,S,8)^H8(_,S,7),m=p[O-2]|0,B=A[O-2]|0,z8=c(m,B,19)^q8(m,B,61)^E8(m,B,6),B8=d(m,B,19)^Z8(m,B,61)^H8(m,B,6),K8=K0(m8,B8,A[O-7],A[O-16]),y8=j0(K8,b8,z8,p[O-7],p[O-16]);p[O]=y8|0,A[O]=K8|0}let{Ah:q,Al:Z,Bh:Y,Bl:J,Ch:U,Cl:z,Dh:G,Dl:N,Eh:K,El:j,Fh:R,Fl:W,Gh:F,Gl:w,Hh:k,Hl:D}=this;for(let O=0;O<80;O++){let _=c(K,j,14)^c(K,j,18)^q8(K,j,41),S=d(K,j,14)^d(K,j,18)^Z8(K,j,41),b8=K&R^~K&F,m8=j&W^~j&w,m=G0(D,S,m8,C0[O],A[O]),B=N0(m,k,_,b8,f0[O],p[O]),z8=m|0,B8=c(q,Z,28)^q8(q,Z,34)^q8(q,Z,39),K8=d(q,Z,28)^Z8(q,Z,34)^Z8(q,Z,39),y8=q&Y^q&U^Y&U,T0=Z&J^Z&z^J&z;k=F|0,D=w|0,F=R|0,w=W|0,R=K|0,W=j|0,{h:K,l:j}=b(G|0,N|0,B|0,z8|0),G=U|0,N=z|0,U=Y|0,z=J|0,Y=q|0,J=Z|0;let a8=U0(z8,K8,T0);q=z0(a8,B,B8,y8),Z=a8|0}({h:q,l:Z}=b(this.Ah|0,this.Al|0,q|0,Z|0)),{h:Y,l:J}=b(this.Bh|0,this.Bl|0,Y|0,J|0),{h:U,l:z}=b(this.Ch|0,this.Cl|0,U|0,z|0),{h:G,l:N}=b(this.Dh|0,this.Dl|0,G|0,N|0),{h:K,l:j}=b(this.Eh|0,this.El|0,K|0,j|0),{h:R,l:W}=b(this.Fh|0,this.Fl|0,R|0,W|0),{h:F,l:w}=b(this.Gh|0,this.Gl|0,F|0,w|0),{h:k,l:D}=b(this.Hh|0,this.Hl|0,k|0,D|0),this.set(q,Z,Y,J,U,z,G,N,K,j,R,W,F,w,k,D)}roundClean(){T(p,A)}destroy(){T(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class p0 extends Y8{Ah=L[0]|0;Al=L[1]|0;Bh=L[2]|0;Bl=L[3]|0;Ch=L[4]|0;Cl=L[5]|0;Dh=L[6]|0;Dl=L[7]|0;Eh=L[8]|0;El=L[9]|0;Fh=L[10]|0;Fl=L[11]|0;Gh=L[12]|0;Gl=L[13]|0;Hh=L[14]|0;Hl=L[15]|0;constructor(){super(64)}}class A0 extends Y8{Ah=x[0]|0;Al=x[1]|0;Bh=x[2]|0;Bl=x[3]|0;Ch=x[4]|0;Cl=x[5]|0;Dh=x[6]|0;Dl=x[7]|0;Eh=x[8]|0;El=x[9]|0;Fh=x[10]|0;Fl=x[11]|0;Gh=x[12]|0;Gl=x[13]|0;Hh=x[14]|0;Hl=x[15]|0;constructor(){super(48)}}var V=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),M=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class u0 extends Y8{Ah=V[0]|0;Al=V[1]|0;Bh=V[2]|0;Bl=V[3]|0;Ch=V[4]|0;Cl=V[5]|0;Dh=V[6]|0;Dl=V[7]|0;Eh=V[8]|0;El=V[9]|0;Fh=V[10]|0;Fl=V[11]|0;Gh=V[12]|0;Gl=V[13]|0;Hh=V[14]|0;Hl=V[15]|0;constructor(){super(28)}}class g0 extends Y8{Ah=M[0]|0;Al=M[1]|0;Bh=M[2]|0;Bl=M[3]|0;Ch=M[4]|0;Cl=M[5]|0;Dh=M[6]|0;Dl=M[7]|0;Eh=M[8]|0;El=M[9]|0;Fh=M[10]|0;Fl=M[11]|0;Gh=M[12]|0;Gl=M[13]|0;Hh=M[14]|0;Hl=M[15]|0;constructor(){super(32)}}var D8=$0(()=>new R0,q0(1));class _8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if($8(Q),f($,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let q=this.blockLen,Z=new Uint8Array(q);Z.set($.length>q?Q.create().update($).digest():$);for(let Y=0;Y<Z.length;Y++)Z[Y]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let Y=0;Y<Z.length;Y++)Z[Y]^=106;this.oHash.update(Z),T(Z)}update(Q){return s(this),this.iHash.update(Q),this}digestInto(Q){s(this),f(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:$,iHash:q,finished:Z,destroyed:Y,blockLen:J,outputLen:U}=this;return Q=Q,Q.finished=Z,Q.destroyed=Y,Q.blockLen=J,Q.outputLen=U,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=q._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var i=(Q,$,q)=>new _8(Q,$).update(q).digest();i.create=(Q,$)=>new _8(Q,$);function h0(Q,$,q){if($8(Q),q===void 0)q=new Uint8Array(Q.outputLen);return i(Q,q,$)}var S8=Uint8Array.of(0),D0=Uint8Array.of();function c0(Q,$,q,Z=32){$8(Q),G8(Z,"length");let Y=Q.outputLen;if(Z>255*Y)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/Y);if(q===void 0)q=D0;else f(q,void 0,"info");let U=new Uint8Array(J*Y),z=i.create(Q,$),G=z._cloneInto(),N=new Uint8Array(z.outputLen);for(let K=0;K<J;K++)S8[0]=K+1,G.update(K===0?D0:N).update(q).update(S8).digestInto(N),U.set(N,Y*K),z._cloneInto(G);return z.destroy(),G.destroy(),T(N,S8),U.slice(0,Z)}var v0=(Q,$,q,Z,Y)=>c0(Q,h0(Q,$,q),Z,Y);function r(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function F0(Q){return D8(r(Q))}function v8(Q,$){return i(D8,r(Q),r($))}function d0(Q,$,{salt:q,info:Z}={}){let Y=q?r(q):new Uint8Array(32),J=r(Q),U=Z?r(Z):new Uint8Array(0);return v0(D8,J,Y,U,$)}var O0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function l0(Q){let $=0,q=0,Z="";for(let Y=0;Y<Q.length;Y++){q=q<<8|Q[Y],$+=8;while($>=5)Z+=O0[q>>>$-5&31],$-=5}if($>0)Z+=O0[q<<5-$&31];return Z}function O8(Q,$){let q=Math.ceil($/8),Z=new Uint8Array(q),Y=Math.min(q,Q.length);Z.set(Q.subarray(0,Y));let J=q*8-$;if(J>0){let U=255<<J;Z[q-1]=Z[q-1]&U}return Z}function F8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let q="",Z=Q[Q.length-1]&15;for(let Y=0;q.length<$;Y++){let J=(Z+Y*4)%Math.max(1,Q.length-4),G=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");q+=G}return q.slice(0,$)}function u(Q){let $=F0(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}var w0;((D)=>{D.EXPIRED_CODE="EXPIRED_CODE";D.INVALID_CODE="INVALID_CODE";D.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";D.INVALID_SIGNATURE="INVALID_SIGNATURE";D.MISSING_META="MISSING_META";D.INVALID_META_FORMAT="INVALID_META_FORMAT";D.META_MISMATCH="META_MISMATCH";D.META_TOO_LARGE="META_TOO_LARGE";D.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";D.TRANSACTION_NOT_SIGNED_BY_ISSUER="TRANSACTION_NOT_SIGNED_BY_ISSUER";D.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";D.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";D.INVALID_INPUT="INVALID_INPUT";D.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";D.CRYPTO_ERROR="CRYPTO_ERROR";D.INVALID_DIGEST="INVALID_DIGEST";D.INVALID_ADAPTER="INVALID_ADAPTER"})(w0||={});class X extends Error{code;details;constructor(Q,$,q){super($);this.code=Q;this.details=q;this.name="ProtocolError"}static expiredCode(Q,$,q){return new f8(Q,$,q)}static invalidCode(){return new X("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,$){return new c8(Q,$)}static invalidSignature(Q){return new h8(Q)}static missingMeta(){return new C8}static invalidMetaFormat(Q){return new X("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,q){return new p8(Q,$,q)}static metaTooLarge(Q,$){return new X("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new A8(Q,$)}static transactionNotSignedByIssuer(Q,$){return new u8(Q,$)}static invalidTransactionFormat(Q){return new X("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new g8(Q,$)}static invalidInput(Q,$,q){return new X("INVALID_INPUT",`Invalid ${Q}: ${q}`,{field:Q,value:$,reason:q})}static missingRequiredField(Q){return new X("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new X("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new X("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new d8(Q)}static create(Q,$,q){return new X(Q,$,q)}}class f8 extends X{constructor(Q,$,q){super("EXPIRED_CODE",`Action code '${Q}' has expired`,{code:Q,expiresAt:$,currentTime:q});this.name="ExpiredCodeError"}}class C8 extends X{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class p8 extends X{constructor(Q,$,q){super("META_MISMATCH",`Meta ${q} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:q});this.name="MetaMismatchError"}}class A8 extends X{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${$.join(", ")}]`,{intended:Q,actualSigners:$});this.name="TransactionNotSignedByIntendedOwnerError"}}class u8 extends X{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_ISSUER",`Transaction not signed by issuer '${Q}'. Actual signers: [${$.join(", ")}]`,{issuer:Q,actualSigners:$});this.name="TransactionNotSignedByIssuerError"}}class g8 extends X{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class h8 extends X{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class c8 extends X{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class d8 extends X{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}var l8=1,x0="actioncodes",L0="actioncodes-revoke";function H(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey))throw X.invalidInput("pubkey",Q.pubkey,"contains invalid characters for public key or JSON");let $=JSON.stringify({id:x0,ver:l8,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode($)}function l(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(typeof Q.codeHash!=="string")throw X.invalidInput("codeHash",Q.codeHash,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(Q.codeHash.length===0)throw X.invalidInput("codeHash",Q.codeHash,"cannot be empty");if(Q.codeHash.length>100)throw X.invalidInput("codeHash",Q.codeHash,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey)||/["\\\x00-\x1f\x7f-\x9f]/.test(Q.codeHash))throw X.invalidInput("input","contains invalid characters for identifiers or JSON","contains invalid characters");let $=JSON.stringify({id:L0,ver:l8,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function w8(Q){return H({pubkey:Q,windowStart:Date.now()})}function x8(Q){let $=["walletPubkey","delegatedPubkey","chain"];for(let Z of $){let Y=Q[Z];if(typeof Y!=="string")throw X.invalidInput(Z,Y,"must be a string");if(Y.length===0)throw X.invalidInput(Z,Y,"cannot be empty");if(Y.length>100)throw X.invalidInput(Z,Y,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Y))throw X.invalidInput(Z,Y,"contains invalid characters for identifiers or JSON")}let q=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(q)}var J8="NFC",a=512,L8=6,V8=24,n0=8,s0="0123456789",M8={solana:"solana"};var k8="actioncodes:";function T8(Q){let $=V0(Q);if($.int!=null)X8($.int);let q=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.iss!=null&&$.iss!==$.int)q.push(`iss=${encodeURIComponent($.iss)}`);if($.p!=null&&Object.keys($.p).length>0){let Y=JSON.stringify($.p);X8(Y),q.push(`p=${encodeURIComponent(Y)}`)}let Z=k8+q.join("&");return M0(Z),Z}function U8(Q){if(!Q.startsWith(k8))throw Error("protocol meta must start with actioncodes:");let q=Q.slice(k8.length).split("&").filter(Boolean),Z=new Map;for(let W of q){let[F,w]=W.split("=",2);if(!F)continue;let k=w!=null?decodeURIComponent(w):"";Z.set(F,k)}let Y=Z.get("ver"),J=Z.get("id"),U=Z.get("int"),z=Z.get("iss"),G=Z.get("p");if(Y==null||J==null||U==null)throw Error("protocol meta missing required fields ver or id or int");let N=Number(Y);if(!Number.isInteger(N)||N<=0)throw Error("protocol meta ver must be positive integer");let K;if(G!=null&&G!=="")try{if(K=JSON.parse(G),typeof K!=="object"||K===null||Array.isArray(K))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let j=V0({ver:N,id:J,int:U,iss:z,p:K});if(j.int!=null)X8(j.int);if(j.iss!=null)X8(j.iss);if(j.p!=null)X8(JSON.stringify(j.p));if([...Z.keys()].filter((W)=>W!=="ver"&&W!=="id"&&W!=="int"&&W!=="iss"&&W!=="p").length>0)throw Error("protocol meta contains unsupported keys");return M0(T8(j)),j}function i0(Q){try{return U8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function V0(Q){let $=Q.id.normalize(J8).trim(),q={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)q.int=Q.int.normalize(J8).trim();if(Q.iss!=null)q.iss=Q.iss.normalize(J8).trim();if(Q.p!=null)q.p=Q.p;return q}function M0(Q){if(new TextEncoder().encode(Q).length>a)throw Error(`protocol meta exceeds ${a} bytes`)}function X8(Q){if(new TextEncoder().encode(Q).length>a)throw Error(`protocol meta params exceed ${a} bytes`)}var n8=Q8(require("bs58"));class t{config;constructor(Q){this.config=Q}generateCode(Q,$,q){let Z=Q,Y=JSON.parse(new TextDecoder().decode(Z)),J=Y.pubkey,U=Y.windowStart,z;try{z=n8.default.decode(q)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let G=v8(z,Z),N=Math.max(L8,Math.min(V8,this.config.codeLength)),K=8*Math.ceil(N/2),j=O8(G,K),R=F8(j,N);return{chain:$,code:R,pubkey:J,timestamp:U,expiresAt:U+this.config.ttlMs,signature:q}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);let q=H({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw X.missingRequiredField("signature");let Z;try{Z=n8.default.decode(Q.signature)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let Y=v8(Z,q),J=Math.max(L8,Math.min(V8,this.config.codeLength)),U=O8(Y,8*Math.ceil(J/2));if(F8(U,J)!==Q.code)throw X.invalidCode()}}var s8=require("@solana/web3.js"),i8=Q8(require("tweetnacl")),r8=Q8(require("bs58"));class I8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new t(Q)}generateDelegatedCode(Q,$,q,Z){return this.validateDelegationProof(Q),{...this.walletStrategy.generateCode($,q,Z),delegationProof:Q}}validateDelegatedCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);if(this.validateDelegationProof(Q.delegationProof),Q.pubkey!==Q.delegationProof.delegatedPubkey)throw X.invalidInput("delegatedPubkey",Q.delegationProof.delegatedPubkey,"Action code pubkey does not match delegated signer");if(Q.expiresAt>Q.delegationProof.expiresAt)throw X.invalidInput("expiresAt",Q.expiresAt,"Action code cannot expire after delegation proof expiration");if(!Q.delegationProof.signature)throw X.missingRequiredField("delegationProof.signature");let q=H({pubkey:Q.delegationProof.delegatedPubkey,windowStart:Q.timestamp}),Z;try{Z=r8.default.decode(Q.signature??"")}catch{throw X.invalidSignature("Invalid Base58 delegated signature format")}let Y=r8.default.decode(Q.delegationProof.delegatedPubkey);if(!i8.default.sign.detached.verify(q,Z,Y))throw X.invalidSignature("Delegated signature verification failed")}validateDelegationProof(Q){if(!Q.walletPubkey||typeof Q.walletPubkey!=="string")throw X.invalidInput("walletPubkey",Q.walletPubkey,"Wallet pubkey is required and must be a string");try{new s8.PublicKey(Q.walletPubkey)}catch{throw X.invalidInput("walletPubkey",Q.walletPubkey,"Invalid wallet pubkey format")}if(!Q.delegatedPubkey||typeof Q.delegatedPubkey!=="string")throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Delegated pubkey is required and must be a string");try{new s8.PublicKey(Q.delegatedPubkey)}catch{throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Invalid delegated pubkey format")}if(!Q.chain||typeof Q.chain!=="string")throw X.invalidInput("chain",Q.chain,"Chain is required and must be a string");if(Q.chain.length===0||Q.chain.length>50)throw X.invalidInput("chain",Q.chain,"Chain must be between 1 and 50 characters");if(!/^[a-z0-9-]+$/.test(Q.chain))throw X.invalidInput("chain",Q.chain,"Chain contains invalid characters (only lowercase letters, numbers, and hyphens allowed)");if(typeof Q.expiresAt!=="number"||!Number.isInteger(Q.expiresAt))throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be a valid integer timestamp");if(Q.expiresAt<=0)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be positive");let $=Date.now(),q=31536000000;if(Q.expiresAt>$+q)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time is too far in the future");if(Q.expiresAt<$)throw X.expiredCode("Delegation proof has expired",Q.expiresAt,$);if(!Q.signature||typeof Q.signature!=="string")throw X.invalidInput("signature",Q.signature,"Delegation signature is required and must be a string");if(Q.signature.length===0||Q.signature.length>200)throw X.invalidInput("signature",Q.signature,"Delegation signature must be between 1 and 200 characters")}}var P=Q8(require("tweetnacl")),g=Q8(require("bs58")),v=require("@solana/web3.js"),h=require("@solana/spl-memo");var n="solana";class e extends j8{normalizePubkey(Q){if(typeof Q==="string")return new v.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;try{let $=H({pubkey:Q.pubkey,windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Z=g.default.decode(Q.signature),Y=q.toBytes();if(Z.length!==64||Y.length!==32)return!1;return P.default.sign.detached.verify($,Z,Y)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;let $=Q.delegationProof;if(!$.walletPubkey||!$.delegatedPubkey||!$.chain||!$.expiresAt||!$.signature)return!1;if($.chain!==n)return!1;if(Q.pubkey!==$.delegatedPubkey)return!1;if($.expiresAt<Date.now())return!1;try{let q=x8($),Z=this.normalizePubkey($.walletPubkey),Y=g.default.decode($.signature),J=Z.toBytes(),U=H({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),z=this.normalizePubkey($.delegatedPubkey),G=g.default.decode(Q.signature),N=z.toBytes();if(Y.length!==64||J.length!==32)return!1;if(G.length!==64||N.length!==32)return!1;let K=P.default.sign.detached.verify(q,Y,J),j=P.default.sign.detached.verify(U,G,N);return K&&j}catch{return!1}}verifyRevokeWithWallet(Q,$){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!$)return!1;try{let q=l({pubkey:Q.pubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),Y=g.default.decode($),J=Z.toBytes();if(Y.length!==64||J.length!==32)return!1;return P.default.sign.detached.verify(q,Y,J)}catch{return!1}}verifyRevokeWithDelegation(Q,$){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature||!Q.delegationProof)return!1;let q=Q.delegationProof;if(!q.walletPubkey||!q.delegatedPubkey||!q.chain||!q.expiresAt||!q.signature)return!1;if(q.chain!==n)return!1;if(Q.pubkey!==q.delegatedPubkey)return!1;if(q.expiresAt<Date.now())return!1;try{let Z=x8(q),Y=this.normalizePubkey(q.walletPubkey),J=g.default.decode(q.signature),U=Y.toBytes(),z=l({pubkey:q.delegatedPubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),G=this.normalizePubkey(q.delegatedPubkey),N=g.default.decode($),K=G.toBytes();if(J.length!==64||U.length!==32)return!1;if(N.length!==64||K.length!==32)return!1;let j=P.default.sign.detached.verify(Z,J,U),R=P.default.sign.detached.verify(z,N,K);return j&&R}catch{return!1}}static createProtocolMetaIx(Q){let $=T8(Q);return h.createMemoInstruction($)}getProtocolMeta(Q){try{let $=this.deserializeTransaction(Q);for(let q of this.getMemoInstructions($)){let Z=q.data;try{let Y=new TextDecoder().decode(Z);if(U8(Y))return Y}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let $=v.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if($.message instanceof v.MessageV0)return $;else return v.Transaction.from(Buffer.from(Q,"base64"))}catch{try{return v.Transaction.from(Buffer.from(Q,"base64"))}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return U8($)}getMemoInstructions(Q){if(Q instanceof v.Transaction)return Q.instructions.filter(($)=>$.programId.equals(h.MEMO_PROGRAM_ID));else{let q=Q.message;if(q instanceof v.MessageV0){let Z=[];for(let Y of q.compiledInstructions){let J=q.staticAccountKeys[Y.programIdIndex];if(J&&J.equals(h.MEMO_PROGRAM_ID)){let U=Y.accountKeyIndexes.map((z)=>({pubkey:q.staticAccountKeys[z],isSigner:!1,isWritable:!1}));Z.push(new v.TransactionInstruction({keys:U,programId:J,data:Y.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,$){let q=Date.now();if(q>Q.expiresAt)throw X.expiredCode(Q.code,Q.expiresAt,q);let Z=this.parseMeta($);if(!Z)throw X.missingMeta();if(Z.ver!==2)throw X.metaMismatch("2",String(Z.ver),"ver");let Y=u(Q.code);if(Z.id!==Y)throw X.metaMismatch(Y,Z.id,"id");if(Z.int!==Q.pubkey)throw X.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw X.missingMeta();let{int:q,iss:Z}=$;if(!q)throw X.invalidMetaFormat("Missing 'int' (intendedFor) field");let Y,J;try{Y=new v.PublicKey(q)}catch{throw X.invalidPubkeyFormat(q,"Invalid public key format")}try{if(Z)J=new v.PublicKey(Z)}catch{throw X.invalidPubkeyFormat(Z||"","Invalid public key format")}let U=this.deserializeTransaction(Q),z=[];if(U instanceof v.Transaction){let G=!1,N=!1;if(U.signatures.forEach((K)=>{if(!K.signature)return;if(z.push(K.publicKey.toString()),K.publicKey.equals(Y))G=!0;if(Z&&K.publicKey.equals(J))N=!0}),!G)throw X.transactionNotSignedByIntendedOwner(q,z);if(Z&&!N)throw X.transactionNotSignedByIssuer(Z,z);return}if(U instanceof v.VersionedTransaction){let G=U.message;if(G instanceof v.MessageV0){let N=!1,K=!1,j=G.header.numRequiredSignatures;for(let R=0;R<j;R++){let W=G.staticAccountKeys[R];if(W){if(z.push(W.toString()),W.equals(Y))N=!0;if(Z&&W.equals(J))K=!0}}if(!N)throw X.transactionNotSignedByIntendedOwner(q,z);if(Z&&!K)throw X.transactionNotSignedByIssuer(Z,z);return}}throw X.invalidTransactionFormat("Unsupported transaction format")}verifyMessageSignedByIntentOwner(Q,$,q){try{let Z=new TextEncoder().encode(Q),Y=g.default.decode($),U=this.normalizePubkey(q).toBytes();if(!P.default.sign.detached.verify(Z,Y,U))throw X.invalidSignature("Signature verification failed")}catch(Z){if(Z instanceof Error&&Z.message.includes("Signature verification failed"))throw Z;throw X.invalidSignature("Invalid signature format")}}static async attachProtocolMeta(Q,$,q){if(new e().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let J=e.createProtocolMetaIx($);try{let U=v.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if(U.message instanceof v.MessageV0){let z=U.message,G=z.addressTableLookups&&z.addressTableLookups.length>0,N=z.staticAccountKeys.length,K=z.compiledInstructions.some((j)=>j.accountKeyIndexes.some((R)=>R>=N));if(G&&K){if(!q)throw X.invalidTransactionFormat("Connection required: Transaction uses address lookup tables and instructions reference accounts from those tables. A Solana connection is needed to resolve lookup tables and correctly recalculate account indices.");let j=[];for(let k of z.addressTableLookups)try{let D=await q.getAddressLookupTable(k.accountKey);if(D.value)j.push(D.value)}catch(D){throw X.invalidTransactionFormat(`Failed to resolve address lookup table ${k.accountKey.toString()}: ${D}`)}let R=v.TransactionMessage.decompile(z,{addressLookupTableAccounts:j});R.instructions.push(J);let W=R.compileToV0Message(j),F=new v.VersionedTransaction(W),w=W.header.numRequiredSignatures;return F.signatures=Array.from({length:w},()=>new Uint8Array(64)),Buffer.from(F.serialize()).toString("base64")}else{let j=[...z.staticAccountKeys];if(!j.some((D)=>D.equals(h.MEMO_PROGRAM_ID)))j.push(h.MEMO_PROGRAM_ID);let W={programIdIndex:j.findIndex((D)=>D.equals(h.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:J.data},F=new v.MessageV0({header:z.header,staticAccountKeys:j,recentBlockhash:z.recentBlockhash,compiledInstructions:[...z.compiledInstructions,W],addressTableLookups:z.addressTableLookups}),w=new v.VersionedTransaction(F),k=F.header.numRequiredSignatures;return w.signatures=Array.from({length:k},()=>new Uint8Array(64)),Buffer.from(w.serialize()).toString("base64")}}else{let z=v.Transaction.from(Buffer.from(Q,"base64"));return z.add(J),Buffer.from(z.serialize({requireAllSignatures:!1})).toString("base64")}}catch(U){if(U instanceof X)throw U;try{let z=v.Transaction.from(Buffer.from(Q,"base64"));return z.add(J),Buffer.from(z.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw X.invalidTransactionFormat(`Invalid base64 transaction format: ${U}`)}}}}class k0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new e,this._walletStrategy=new t(Q),this._delegationStrategy=new I8(Q)}getConfig(){return this.config}registerAdapter(Q,$){this.adapters[Q]=$}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}async generate(Q,$,q,Z){if(!q||!M8[q])throw X.invalidAdapter(q);if(!Z||typeof Z!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=w8($),J=await Z(Y,q);if(!J)throw X.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(Y,q,J)}else{let Y=$,J=w8(Y.delegatedPubkey),U=await Z(J,q);if(!U)throw X.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(Y,J,q,U)}}async revoke(Q,$,q,Z){if(!q||!M8[q])throw X.invalidAdapter(q);if(!Z||typeof Z!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=l({codeHash:u($.code),pubkey:$.pubkey,windowStart:$.timestamp}),J=await Z(Y,q);if(!J)throw X.invalidSignature("Missing signature over canonical message");return{...$,revokeSignature:J}}else{let Y=$,J=l({codeHash:u($.code),pubkey:Y.delegationProof.delegatedPubkey,windowStart:$.timestamp}),U=await Z(J,q);if(!U)throw X.invalidSignature("Missing delegated signature");return{...$,revokeSignature:U}}}validate(Q,$){if(Q==="wallet"){this.walletStrategy.validateCode($);let q=this.getAdapter($.chain);if(!q)throw X.invalidAdapter($.chain);if(!q.verifyWithWallet($))throw X.invalidSignature("Wallet signature verification failed")}else{this.delegationStrategy.validateDelegatedCode($);let q=this.getAdapter($.chain);if(!q)throw X.invalidAdapter($.chain);if(!q.verifyWithDelegation($))throw X.invalidSignature("Delegation signature verification failed")}}}
|
|
1
|
+
var I0=Object.create;var{getPrototypeOf:b0,defineProperty:Q8,getOwnPropertyNames:e8,getOwnPropertyDescriptor:B0}=Object,o8=Object.prototype.hasOwnProperty;var $8=(Q,$,q)=>{q=Q!=null?I0(b0(Q)):{};let Z=$||!Q||!Q.__esModule?Q8(q,"default",{value:Q,enumerable:!0}):q;for(let Y of e8(Q))if(!o8.call(Z,Y))Q8(Z,Y,{get:()=>Q[Y],enumerable:!0});return Z},t8=new WeakMap,m0=(Q)=>{var $=t8.get(Q),q;if($)return $;if($=Q8({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")e8(Q).map((Z)=>!o8.call($,Z)&&Q8($,Z,{get:()=>Q[Z],enumerable:!(q=B0(Q,Z))||q.enumerable}));return t8.set(Q,$),$};var y0=(Q,$)=>{for(var q in $)Q8(Q,q,{get:$[q],enumerable:!0,configurable:!0,set:(Z)=>$[q]=()=>Z})};var r0={};y0(r0,{validateProtocolMetaFormat:()=>i0,truncateBits:()=>F8,sha256:()=>O0,serializeDelegationProof:()=>L8,serializeCanonicalRevoke:()=>n,serializeCanonical:()=>P,parseProtocolMeta:()=>_,hmacSha256:()=>R8,hkdfSha256:()=>d0,getCanonicalMessageParts:()=>w8,digestToDigits:()=>O8,codeHash:()=>c,buildProtocolMeta:()=>k8,base32EncodeCrockford:()=>l0,WalletStrategy:()=>e,TransactionNotSignedByIssuerError:()=>u8,TransactionNotSignedByIntendedOwnerError:()=>p8,SolanaAdapter:()=>o,SUPPORTED_CHAINS:()=>T8,SCHEME:()=>M8,ProtocolErrorCode:()=>w0,ProtocolError:()=>X,PROTOCOL_NORMALIZATION:()=>X8,PROTOCOL_META_MAX_BYTES:()=>t,MissingMetaError:()=>C8,MetaMismatchError:()=>A8,InvalidSignatureError:()=>h8,InvalidPubkeyFormatError:()=>g8,InvalidCodeFormatError:()=>c8,InvalidAdapterError:()=>d8,ExpiredCodeError:()=>f8,DelegationStrategy:()=>I8,CODE_MIN_LENGTH:()=>x8,CODE_MAX_LENGTH:()=>V8,CODE_DEFAULT_LENGTH:()=>n0,CODE_CHARSET_DIGITS:()=>s0,CANONICAL_REVOKE_MESSAGE_PREFIX:()=>x0,CANONICAL_MESSAGE_VERSION:()=>l8,CANONICAL_MESSAGE_PREFIX:()=>L0,BaseChainAdapter:()=>K8,ActionCodesProtocol:()=>M0,ADAPTER_CHAIN_NAME:()=>s});module.exports=m0(r0);class K8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function E0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function G8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let q=$&&`"${$}" `;throw Error(`${q}expected integer >= 0, got ${Q}`)}}function p(Q,$,q=""){let Z=E0(Q),Y=Q?.length,J=$!==void 0;if(!Z||J&&Y!==$){let U=q&&`"${q}" `,z=J?` of length ${$}`:"",K=Z?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+z+", got "+K)}return Q}function q8(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");G8(Q.outputLen),G8(Q.blockLen)}function i(Q,$=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if($&&Q.finished)throw Error("Hash#digest() has already been called")}function Q0(Q,$){p(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function I(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function N8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function b(Q,$){return Q<<32-$|Q>>>$}function $0(Q,$={}){let q=(Y,J)=>Q(J).update(Y).digest(),Z=Q(void 0);return q.outputLen=Z.outputLen,q.blockLen=Z.blockLen,q.create=(Y)=>Q(Y),Object.assign(q,$),Object.freeze(q)}var q0=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function Z0(Q,$,q){return Q&$^~Q&q}function Y0(Q,$,q){return Q&$^Q&q^$&q}class W8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,q,Z){this.blockLen=Q,this.outputLen=$,this.padOffset=q,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=N8(this.buffer)}update(Q){i(this),p(Q);let{view:$,buffer:q,blockLen:Z}=this,Y=Q.length;for(let J=0;J<Y;){let U=Math.min(Z-this.pos,Y-J);if(U===Z){let z=N8(Q);for(;Z<=Y-J;J+=Z)this.process(z,J);continue}if(q.set(Q.subarray(J,J+U),this.pos),this.pos+=U,J+=U,this.pos===Z)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){i(this),Q0(Q,this),this.finished=!0;let{buffer:$,view:q,blockLen:Z,isLE:Y}=this,{pos:J}=this;if($[J++]=128,I(this.buffer.subarray(J)),this.padOffset>Z-J)this.process(q,0),J=0;for(let j=J;j<Z;j++)$[j]=0;q.setBigUint64(Z-8,BigInt(this.length*8),Y),this.process(q,0);let U=N8(Q),z=this.outputLen;if(z%4)throw Error("_sha2: outputLen must be aligned to 32bit");let K=z/4,N=this.get();if(K>N.length)throw Error("_sha2: outputLen bigger than state");for(let j=0;j<K;j++)U.setUint32(4*j,N[j],Y)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let q=Q.slice(0,$);return this.destroy(),q}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:q,length:Z,finished:Y,destroyed:J,pos:U}=this;if(Q.destroyed=J,Q.finished=Y,Q.length=Z,Q.pos=U,Z%$)Q.buffer.set(q);return Q}clone(){return this._cloneInto()}}var E=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),H=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),L=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),x=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var v8=BigInt(4294967295),J0=BigInt(32);function H0(Q,$=!1){if($)return{h:Number(Q&v8),l:Number(Q>>J0&v8)};return{h:Number(Q>>J0&v8)|0,l:Number(Q&v8)|0}}function X0(Q,$=!1){let q=Q.length,Z=new Uint32Array(q),Y=new Uint32Array(q);for(let J=0;J<q;J++){let{h:U,l:z}=H0(Q[J],$);[Z[J],Y[J]]=[U,z]}return[Z,Y]}var E8=(Q,$,q)=>Q>>>q,H8=(Q,$,q)=>Q<<32-q|$>>>q,d=(Q,$,q)=>Q>>>q|$<<32-q,l=(Q,$,q)=>Q<<32-q|$>>>q,Z8=(Q,$,q)=>Q<<64-q|$>>>q-32,Y8=(Q,$,q)=>Q>>>q-32|$<<64-q;function B(Q,$,q,Z){let Y=($>>>0)+(Z>>>0);return{h:Q+q+(Y/4294967296|0)|0,l:Y|0}}var U0=(Q,$,q)=>(Q>>>0)+($>>>0)+(q>>>0),z0=(Q,$,q,Z)=>$+q+Z+(Q/4294967296|0)|0,j0=(Q,$,q,Z)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0),K0=(Q,$,q,Z,Y)=>$+q+Z+Y+(Q/4294967296|0)|0,G0=(Q,$,q,Z,Y)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0)+(Y>>>0),N0=(Q,$,q,Z,Y,J)=>$+q+Z+Y+J+(Q/4294967296|0)|0;var _0=Uint32Array.from([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]),u=new Uint32Array(64);class P8 extends W8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:q,D:Z,E:Y,F:J,G:U,H:z}=this;return[Q,$,q,Z,Y,J,U,z]}set(Q,$,q,Z,Y,J,U,z){this.A=Q|0,this.B=$|0,this.C=q|0,this.D=Z|0,this.E=Y|0,this.F=J|0,this.G=U|0,this.H=z|0}process(Q,$){for(let j=0;j<16;j++,$+=4)u[j]=Q.getUint32($,!1);for(let j=16;j<64;j++){let G=u[j-15],W=u[j-2],v=b(G,7)^b(G,18)^G>>>3,R=b(W,17)^b(W,19)^W>>>10;u[j]=R+u[j-7]+v+u[j-16]|0}let{A:q,B:Z,C:Y,D:J,E:U,F:z,G:K,H:N}=this;for(let j=0;j<64;j++){let G=b(U,6)^b(U,11)^b(U,25),W=N+G+Z0(U,z,K)+_0[j]+u[j]|0,R=(b(q,2)^b(q,13)^b(q,22))+Y0(q,Z,Y)|0;N=K,K=z,z=U,U=J+W|0,J=Y,Y=Z,Z=q,q=W+R|0}q=q+this.A|0,Z=Z+this.B|0,Y=Y+this.C|0,J=J+this.D|0,U=U+this.E|0,z=z+this.F|0,K=K+this.G|0,N=N+this.H|0,this.set(q,Z,Y,J,U,z,K,N)}roundClean(){I(u)}destroy(){this.set(0,0,0,0,0,0,0,0),I(this.buffer)}}class W0 extends P8{A=E[0]|0;B=E[1]|0;C=E[2]|0;D=E[3]|0;E=E[4]|0;F=E[5]|0;G=E[6]|0;H=E[7]|0;constructor(){super(32)}}class S0 extends P8{A=H[0]|0;B=H[1]|0;C=H[2]|0;D=H[3]|0;E=H[4]|0;F=H[5]|0;G=H[6]|0;H=H[7]|0;constructor(){super(28)}}var v0=(()=>X0(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((Q)=>BigInt(Q))))(),f0=(()=>v0[0])(),C0=(()=>v0[1])(),g=new Uint32Array(80),h=new Uint32Array(80);class J8 extends W8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:q,Bl:Z,Ch:Y,Cl:J,Dh:U,Dl:z,Eh:K,El:N,Fh:j,Fl:G,Gh:W,Gl:v,Hh:R,Hl:w}=this;return[Q,$,q,Z,Y,J,U,z,K,N,j,G,W,v,R,w]}set(Q,$,q,Z,Y,J,U,z,K,N,j,G,W,v,R,w){this.Ah=Q|0,this.Al=$|0,this.Bh=q|0,this.Bl=Z|0,this.Ch=Y|0,this.Cl=J|0,this.Dh=U|0,this.Dl=z|0,this.Eh=K|0,this.El=N|0,this.Fh=j|0,this.Fl=G|0,this.Gh=W|0,this.Gl=v|0,this.Hh=R|0,this.Hl=w|0}process(Q,$){for(let O=0;O<16;O++,$+=4)g[O]=Q.getUint32($),h[O]=Q.getUint32($+=4);for(let O=16;O<80;O++){let C=g[O-15]|0,A=h[O-15]|0,b8=d(C,A,1)^d(C,A,8)^E8(C,A,7),B8=l(C,A,1)^l(C,A,8)^H8(C,A,7),m=g[O-2]|0,y=h[O-2]|0,z8=d(m,y,19)^Z8(m,y,61)^E8(m,y,6),m8=l(m,y,19)^Y8(m,y,61)^H8(m,y,6),j8=j0(B8,m8,h[O-7],h[O-16]),y8=K0(j8,b8,z8,g[O-7],g[O-16]);g[O]=y8|0,h[O]=j8|0}let{Ah:q,Al:Z,Bh:Y,Bl:J,Ch:U,Cl:z,Dh:K,Dl:N,Eh:j,El:G,Fh:W,Fl:v,Gh:R,Gl:w,Hh:M,Hl:D}=this;for(let O=0;O<80;O++){let C=d(j,G,14)^d(j,G,18)^Z8(j,G,41),A=l(j,G,14)^l(j,G,18)^Y8(j,G,41),b8=j&W^~j&R,B8=G&v^~G&w,m=G0(D,A,B8,C0[O],h[O]),y=N0(m,M,C,b8,f0[O],g[O]),z8=m|0,m8=d(q,Z,28)^Z8(q,Z,34)^Z8(q,Z,39),j8=l(q,Z,28)^Y8(q,Z,34)^Y8(q,Z,39),y8=q&Y^q&U^Y&U,k0=Z&J^Z&z^J&z;M=R|0,D=w|0,R=W|0,w=v|0,W=j|0,v=G|0,{h:j,l:G}=B(K|0,N|0,y|0,z8|0),K=U|0,N=z|0,U=Y|0,z=J|0,Y=q|0,J=Z|0;let a8=U0(z8,j8,k0);q=z0(a8,y,m8,y8),Z=a8|0}({h:q,l:Z}=B(this.Ah|0,this.Al|0,q|0,Z|0)),{h:Y,l:J}=B(this.Bh|0,this.Bl|0,Y|0,J|0),{h:U,l:z}=B(this.Ch|0,this.Cl|0,U|0,z|0),{h:K,l:N}=B(this.Dh|0,this.Dl|0,K|0,N|0),{h:j,l:G}=B(this.Eh|0,this.El|0,j|0,G|0),{h:W,l:v}=B(this.Fh|0,this.Fl|0,W|0,v|0),{h:R,l:w}=B(this.Gh|0,this.Gl|0,R|0,w|0),{h:M,l:D}=B(this.Hh|0,this.Hl|0,M|0,D|0),this.set(q,Z,Y,J,U,z,K,N,j,G,W,v,R,w,M,D)}roundClean(){I(g,h)}destroy(){I(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class A0 extends J8{Ah=x[0]|0;Al=x[1]|0;Bh=x[2]|0;Bl=x[3]|0;Ch=x[4]|0;Cl=x[5]|0;Dh=x[6]|0;Dl=x[7]|0;Eh=x[8]|0;El=x[9]|0;Fh=x[10]|0;Fl=x[11]|0;Gh=x[12]|0;Gl=x[13]|0;Hh=x[14]|0;Hl=x[15]|0;constructor(){super(64)}}class p0 extends J8{Ah=L[0]|0;Al=L[1]|0;Bh=L[2]|0;Bl=L[3]|0;Ch=L[4]|0;Cl=L[5]|0;Dh=L[6]|0;Dl=L[7]|0;Eh=L[8]|0;El=L[9]|0;Fh=L[10]|0;Fl=L[11]|0;Gh=L[12]|0;Gl=L[13]|0;Hh=L[14]|0;Hl=L[15]|0;constructor(){super(48)}}var V=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),T=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class u0 extends J8{Ah=V[0]|0;Al=V[1]|0;Bh=V[2]|0;Bl=V[3]|0;Ch=V[4]|0;Cl=V[5]|0;Dh=V[6]|0;Dl=V[7]|0;Eh=V[8]|0;El=V[9]|0;Fh=V[10]|0;Fl=V[11]|0;Gh=V[12]|0;Gl=V[13]|0;Hh=V[14]|0;Hl=V[15]|0;constructor(){super(28)}}class g0 extends J8{Ah=T[0]|0;Al=T[1]|0;Bh=T[2]|0;Bl=T[3]|0;Ch=T[4]|0;Cl=T[5]|0;Dh=T[6]|0;Dl=T[7]|0;Eh=T[8]|0;El=T[9]|0;Fh=T[10]|0;Fl=T[11]|0;Gh=T[12]|0;Gl=T[13]|0;Hh=T[14]|0;Hl=T[15]|0;constructor(){super(32)}}var D8=$0(()=>new W0,q0(1));class _8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if(q8(Q),p($,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let q=this.blockLen,Z=new Uint8Array(q);Z.set($.length>q?Q.create().update($).digest():$);for(let Y=0;Y<Z.length;Y++)Z[Y]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let Y=0;Y<Z.length;Y++)Z[Y]^=106;this.oHash.update(Z),I(Z)}update(Q){return i(this),this.iHash.update(Q),this}digestInto(Q){i(this),p(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:$,iHash:q,finished:Z,destroyed:Y,blockLen:J,outputLen:U}=this;return Q=Q,Q.finished=Z,Q.destroyed=Y,Q.blockLen=J,Q.outputLen=U,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=q._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var r=(Q,$,q)=>new _8(Q,$).update(q).digest();r.create=(Q,$)=>new _8(Q,$);function h0(Q,$,q){if(q8(Q),q===void 0)q=new Uint8Array(Q.outputLen);return r(Q,q,$)}var S8=Uint8Array.of(0),D0=Uint8Array.of();function c0(Q,$,q,Z=32){q8(Q),G8(Z,"length");let Y=Q.outputLen;if(Z>255*Y)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/Y);if(q===void 0)q=D0;else p(q,void 0,"info");let U=new Uint8Array(J*Y),z=r.create(Q,$),K=z._cloneInto(),N=new Uint8Array(z.outputLen);for(let j=0;j<J;j++)S8[0]=j+1,K.update(j===0?D0:N).update(q).update(S8).digestInto(N),U.set(N,Y*j),z._cloneInto(K);return z.destroy(),K.destroy(),I(N,S8),U.slice(0,Z)}var R0=(Q,$,q,Z,Y)=>c0(Q,h0(Q,$,q),Z,Y);function a(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function O0(Q){return D8(a(Q))}function R8(Q,$){return r(D8,a(Q),a($))}function d0(Q,$,{salt:q,info:Z}={}){let Y=q?a(q):new Uint8Array(32),J=a(Q),U=Z?a(Z):new Uint8Array(0);return R0(D8,J,Y,U,$)}var F0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function l0(Q){let $=0,q=0,Z="";for(let Y=0;Y<Q.length;Y++){q=q<<8|Q[Y],$+=8;while($>=5)Z+=F0[q>>>$-5&31],$-=5}if($>0)Z+=F0[q<<5-$&31];return Z}function F8(Q,$){let q=Math.ceil($/8),Z=new Uint8Array(q),Y=Math.min(q,Q.length);Z.set(Q.subarray(0,Y));let J=q*8-$;if(J>0){let U=255<<J;Z[q-1]=Z[q-1]&U}return Z}function O8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let q="",Z=Q[Q.length-1]&15;for(let Y=0;q.length<$;Y++){let J=(Z+Y*4)%Math.max(1,Q.length-4),K=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");q+=K}return q.slice(0,$)}function c(Q){let $=O0(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}var w0;((D)=>{D.EXPIRED_CODE="EXPIRED_CODE";D.INVALID_CODE="INVALID_CODE";D.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";D.INVALID_SIGNATURE="INVALID_SIGNATURE";D.MISSING_META="MISSING_META";D.INVALID_META_FORMAT="INVALID_META_FORMAT";D.META_MISMATCH="META_MISMATCH";D.META_TOO_LARGE="META_TOO_LARGE";D.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";D.TRANSACTION_NOT_SIGNED_BY_ISSUER="TRANSACTION_NOT_SIGNED_BY_ISSUER";D.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";D.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";D.INVALID_INPUT="INVALID_INPUT";D.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";D.CRYPTO_ERROR="CRYPTO_ERROR";D.INVALID_DIGEST="INVALID_DIGEST";D.INVALID_ADAPTER="INVALID_ADAPTER"})(w0||={});class X extends Error{code;details;constructor(Q,$,q){super($);this.code=Q;this.details=q;this.name="ProtocolError"}static expiredCode(Q,$,q){return new f8(Q,$,q)}static invalidCode(){return new X("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,$){return new c8(Q,$)}static invalidSignature(Q){return new h8(Q)}static missingMeta(){return new C8}static invalidMetaFormat(Q){return new X("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,q){return new A8(Q,$,q)}static metaTooLarge(Q,$){return new X("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new p8(Q,$)}static transactionNotSignedByIssuer(Q,$){return new u8(Q,$)}static invalidTransactionFormat(Q){return new X("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new g8(Q,$)}static invalidInput(Q,$,q){return new X("INVALID_INPUT",`Invalid ${Q}: ${q}`,{field:Q,value:$,reason:q})}static missingRequiredField(Q){return new X("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new X("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new X("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new d8(Q)}static create(Q,$,q){return new X(Q,$,q)}}class f8 extends X{constructor(Q,$,q){super("EXPIRED_CODE",`Action code '${Q}' has expired`,{code:Q,expiresAt:$,currentTime:q});this.name="ExpiredCodeError"}}class C8 extends X{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class A8 extends X{constructor(Q,$,q){super("META_MISMATCH",`Meta ${q} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:q});this.name="MetaMismatchError"}}class p8 extends X{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${$.join(", ")}]`,{intended:Q,actualSigners:$});this.name="TransactionNotSignedByIntendedOwnerError"}}class u8 extends X{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_ISSUER",`Transaction not signed by issuer '${Q}'. Actual signers: [${$.join(", ")}]`,{issuer:Q,actualSigners:$});this.name="TransactionNotSignedByIssuerError"}}class g8 extends X{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class h8 extends X{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class c8 extends X{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class d8 extends X{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}var l8=1,L0="actioncodes",x0="actioncodes-revoke";function P(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey))throw X.invalidInput("pubkey",Q.pubkey,"contains invalid characters for public key or JSON");let $=JSON.stringify({id:L0,ver:l8,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode($)}function n(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(typeof Q.codeHash!=="string")throw X.invalidInput("codeHash",Q.codeHash,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(Q.codeHash.length===0)throw X.invalidInput("codeHash",Q.codeHash,"cannot be empty");if(Q.codeHash.length>100)throw X.invalidInput("codeHash",Q.codeHash,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey)||/["\\\x00-\x1f\x7f-\x9f]/.test(Q.codeHash))throw X.invalidInput("input","contains invalid characters for identifiers or JSON","contains invalid characters");let $=JSON.stringify({id:x0,ver:l8,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function w8(Q){return P({pubkey:Q,windowStart:Date.now()})}function L8(Q){let $=["walletPubkey","delegatedPubkey","chain"];for(let Z of $){let Y=Q[Z];if(typeof Y!=="string")throw X.invalidInput(Z,Y,"must be a string");if(Y.length===0)throw X.invalidInput(Z,Y,"cannot be empty");if(Y.length>100)throw X.invalidInput(Z,Y,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Y))throw X.invalidInput(Z,Y,"contains invalid characters for identifiers or JSON")}let q=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(q)}var X8="NFC",t=512,x8=6,V8=24,n0=8,s0="0123456789",T8={solana:"solana"};var M8="actioncodes:";function k8(Q){let $=V0(Q);if($.int!=null)U8($.int);let q=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.iss!=null&&$.iss!==$.int)q.push(`iss=${encodeURIComponent($.iss)}`);if($.p!=null&&Object.keys($.p).length>0){let Y=JSON.stringify($.p);U8(Y),q.push(`p=${encodeURIComponent(Y)}`)}let Z=M8+q.join("&");return T0(Z),Z}function _(Q){if(!Q.startsWith(M8))throw Error("protocol meta must start with actioncodes:");let q=Q.slice(M8.length).split("&").filter(Boolean),Z=new Map;for(let v of q){let[R,w]=v.split("=",2);if(!R)continue;let M=w!=null?decodeURIComponent(w):"";Z.set(R,M)}let Y=Z.get("ver"),J=Z.get("id"),U=Z.get("int"),z=Z.get("iss"),K=Z.get("p");if(Y==null||J==null||U==null)throw Error("protocol meta missing required fields ver or id or int");let N=Number(Y);if(!Number.isInteger(N)||N<=0)throw Error("protocol meta ver must be positive integer");let j;if(K!=null&&K!=="")try{if(j=JSON.parse(K),typeof j!=="object"||j===null||Array.isArray(j))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let G=V0({ver:N,id:J,int:U,iss:z,p:j});if(G.int!=null)U8(G.int);if(G.iss!=null)U8(G.iss);if(G.p!=null)U8(JSON.stringify(G.p));if([...Z.keys()].filter((v)=>v!=="ver"&&v!=="id"&&v!=="int"&&v!=="iss"&&v!=="p").length>0)throw Error("protocol meta contains unsupported keys");return T0(k8(G)),G}function i0(Q){try{return _(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function V0(Q){let $=Q.id.normalize(X8).trim(),q={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)q.int=Q.int.normalize(X8).trim();if(Q.iss!=null)q.iss=Q.iss.normalize(X8).trim();if(Q.p!=null)q.p=Q.p;return q}function T0(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta exceeds ${t} bytes`)}function U8(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta params exceed ${t} bytes`)}var n8=$8(require("bs58"));class e{config;constructor(Q){this.config=Q}generateCode(Q,$,q){let Z=Q,Y=JSON.parse(new TextDecoder().decode(Z)),J=Y.pubkey,U=Y.windowStart,z;try{z=n8.default.decode(q)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let K=R8(z,Z),N=Math.max(x8,Math.min(V8,this.config.codeLength)),j=8*Math.ceil(N/2),G=F8(K,j),W=O8(G,N);return{chain:$,code:W,pubkey:J,timestamp:U,expiresAt:U+this.config.ttlMs,signature:q}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);let q=P({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw X.missingRequiredField("signature");let Z;try{Z=n8.default.decode(Q.signature)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let Y=R8(Z,q),J=Math.max(x8,Math.min(V8,this.config.codeLength)),U=F8(Y,8*Math.ceil(J/2));if(O8(U,J)!==Q.code)throw X.invalidCode()}}var s8=require("@solana/web3.js"),i8=$8(require("tweetnacl")),r8=$8(require("bs58"));class I8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new e(Q)}generateDelegatedCode(Q,$,q,Z){return this.validateDelegationProof(Q),{...this.walletStrategy.generateCode($,q,Z),delegationProof:Q}}validateDelegatedCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);if(this.validateDelegationProof(Q.delegationProof),Q.pubkey!==Q.delegationProof.delegatedPubkey)throw X.invalidInput("delegatedPubkey",Q.delegationProof.delegatedPubkey,"Action code pubkey does not match delegated signer");if(Q.expiresAt>Q.delegationProof.expiresAt)throw X.invalidInput("expiresAt",Q.expiresAt,"Action code cannot expire after delegation proof expiration");if(!Q.delegationProof.signature)throw X.missingRequiredField("delegationProof.signature");let q=P({pubkey:Q.delegationProof.delegatedPubkey,windowStart:Q.timestamp}),Z;try{Z=r8.default.decode(Q.signature??"")}catch{throw X.invalidSignature("Invalid Base58 delegated signature format")}let Y=r8.default.decode(Q.delegationProof.delegatedPubkey);if(!i8.default.sign.detached.verify(q,Z,Y))throw X.invalidSignature("Delegated signature verification failed")}validateDelegationProof(Q){if(!Q.walletPubkey||typeof Q.walletPubkey!=="string")throw X.invalidInput("walletPubkey",Q.walletPubkey,"Wallet pubkey is required and must be a string");try{new s8.PublicKey(Q.walletPubkey)}catch{throw X.invalidInput("walletPubkey",Q.walletPubkey,"Invalid wallet pubkey format")}if(!Q.delegatedPubkey||typeof Q.delegatedPubkey!=="string")throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Delegated pubkey is required and must be a string");try{new s8.PublicKey(Q.delegatedPubkey)}catch{throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Invalid delegated pubkey format")}if(!Q.chain||typeof Q.chain!=="string")throw X.invalidInput("chain",Q.chain,"Chain is required and must be a string");if(Q.chain.length===0||Q.chain.length>50)throw X.invalidInput("chain",Q.chain,"Chain must be between 1 and 50 characters");if(!/^[a-z0-9-]+$/.test(Q.chain))throw X.invalidInput("chain",Q.chain,"Chain contains invalid characters (only lowercase letters, numbers, and hyphens allowed)");if(typeof Q.expiresAt!=="number"||!Number.isInteger(Q.expiresAt))throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be a valid integer timestamp");if(Q.expiresAt<=0)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be positive");let $=Date.now(),q=31536000000;if(Q.expiresAt>$+q)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time is too far in the future");if(Q.expiresAt<$)throw X.expiredCode("Delegation proof has expired",Q.expiresAt,$);if(!Q.signature||typeof Q.signature!=="string")throw X.invalidInput("signature",Q.signature,"Delegation signature is required and must be a string");if(Q.signature.length===0||Q.signature.length>200)throw X.invalidInput("signature",Q.signature,"Delegation signature must be between 1 and 200 characters")}}var S=$8(require("tweetnacl")),f=$8(require("bs58")),F=require("@solana/web3.js"),k=require("@solana/spl-memo");var s="solana";class o extends K8{normalizePubkey(Q){if(typeof Q==="string")return new F.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!==s)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;try{let $=P({pubkey:Q.pubkey,windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Z=f.default.decode(Q.signature),Y=q.toBytes();if(Z.length!==64||Y.length!==32)return!1;return S.default.sign.detached.verify($,Z,Y)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==s)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;let $=Q.delegationProof;if(!$.walletPubkey||!$.delegatedPubkey||!$.chain||!$.expiresAt||!$.signature)return!1;if($.chain!==s)return!1;if(Q.pubkey!==$.delegatedPubkey)return!1;if($.expiresAt<Date.now())return!1;try{let q=L8($),Z=this.normalizePubkey($.walletPubkey),Y=f.default.decode($.signature),J=Z.toBytes(),U=P({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),z=this.normalizePubkey($.delegatedPubkey),K=f.default.decode(Q.signature),N=z.toBytes();if(Y.length!==64||J.length!==32)return!1;if(K.length!==64||N.length!==32)return!1;let j=S.default.sign.detached.verify(q,Y,J),G=S.default.sign.detached.verify(U,K,N);return j&&G}catch{return!1}}verifyRevokeWithWallet(Q,$){if(Q.chain!==s)return!1;if(!Q.pubkey||!Q.timestamp||!$)return!1;try{let q=n({pubkey:Q.pubkey,codeHash:c(Q.code),windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),Y=f.default.decode($),J=Z.toBytes();if(Y.length!==64||J.length!==32)return!1;return S.default.sign.detached.verify(q,Y,J)}catch{return!1}}verifyRevokeWithDelegation(Q,$){if(Q.chain!==s)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature||!Q.delegationProof)return!1;let q=Q.delegationProof;if(!q.walletPubkey||!q.delegatedPubkey||!q.chain||!q.expiresAt||!q.signature)return!1;if(q.chain!==s)return!1;if(Q.pubkey!==q.delegatedPubkey)return!1;if(q.expiresAt<Date.now())return!1;try{let Z=L8(q),Y=this.normalizePubkey(q.walletPubkey),J=f.default.decode(q.signature),U=Y.toBytes(),z=n({pubkey:q.delegatedPubkey,codeHash:c(Q.code),windowStart:Q.timestamp}),K=this.normalizePubkey(q.delegatedPubkey),N=f.default.decode($),j=K.toBytes();if(J.length!==64||U.length!==32)return!1;if(N.length!==64||j.length!==32)return!1;let G=S.default.sign.detached.verify(Z,J,U),W=S.default.sign.detached.verify(z,N,j);return G&&W}catch{return!1}}static createProtocolMetaIx(Q){let $=k8(Q);return k.createMemoInstruction($)}getProtocolMeta(Q){try{if(typeof Q==="string"){let $=this.deserializeTransaction(Q);for(let q of this.getMemoInstructions($)){let Z=q.data;try{let Y=new TextDecoder().decode(Z);if(_(Y))return Y}catch{}}return null}if("transaction"in Q&&"message"in Q.transaction){let $=Q.transaction.message;if("instructions"in $&&Array.isArray($.instructions)&&$.instructions.length>0&&(("program"in $.instructions[0])||("programId"in $.instructions[0]))){for(let q of $.instructions)if("program"in q&&q.program==="spl-memo"||"programId"in q&&q.programId instanceof F.PublicKey&&q.programId.equals(k.MEMO_PROGRAM_ID)){let Z=null;if("parsed"in q&&typeof q.parsed==="string")Z=q.parsed;else if("data"in q&&typeof q.data==="string")try{let Y=f.default.decode(q.data);Z=new TextDecoder().decode(Y)}catch{continue}if(Z)try{if(_(Z))return Z}catch{}}return null}try{if($ instanceof F.MessageV0){let q=$,Z=q.staticAccountKeys;for(let Y of q.compiledInstructions){let J=Z[Y.programIdIndex];if(J&&J.equals(k.MEMO_PROGRAM_ID))try{let U=Buffer.from(Y.data),z=new TextDecoder().decode(U);if(_(z))return z}catch{}}return null}if($ instanceof F.Message||"version"in $&&$.version==="legacy"){let q=$,Z=q.accountKeys;for(let Y of q.compiledInstructions){let J=Z[Y.programIdIndex];if(J&&J.equals(k.MEMO_PROGRAM_ID))try{let U=Buffer.from(Y.data),z=new TextDecoder().decode(U);if(_(z))return z}catch{}}return null}try{let q=F.TransactionMessage.decompile($);for(let Z of q.instructions)if(Z.programId.equals(k.MEMO_PROGRAM_ID))try{let Y=new TextDecoder().decode(Z.data);if(_(Y))return Y}catch{}}catch{}}catch{}return null}return null}catch{return null}}deserializeTransaction(Q){try{return F.VersionedTransaction.deserialize(Buffer.from(Q,"base64"))}catch{try{return F.Transaction.from(Buffer.from(Q,"base64"))}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=typeof Q==="string"?this.getProtocolMeta(Q):this.getProtocolMeta(Q);if(!$)return null;return _($)}getMemoInstructions(Q){if(Q instanceof F.Transaction)return Q.instructions.filter(($)=>$.programId.equals(k.MEMO_PROGRAM_ID));else{let q=Q.message,Z=[],Y;try{Y=q.getAccountKeys()}catch{Y=null}let J=q.staticAccountKeys;for(let U of q.compiledInstructions){let z=J[U.programIdIndex];if(z&&z.equals(k.MEMO_PROGRAM_ID)){let K=U.accountKeyIndexes.map((N)=>{if(Y){let j=Y.get(N);return j?{pubkey:j,isSigner:!1,isWritable:!1}:null}else{if(N<J.length)return{pubkey:J[N],isSigner:!1,isWritable:!1};return null}}).filter((N)=>N!==null);Z.push(new F.TransactionInstruction({keys:K,programId:z,data:U.data}))}}return Z}}verifyTransactionMatchesCode(Q,$){let q=Date.now();if(q>Q.expiresAt)throw X.expiredCode(Q.code,Q.expiresAt,q);let Z=this.parseMeta($);if(!Z)throw X.missingMeta();if(Z.ver!==2)throw X.metaMismatch("2",String(Z.ver),"ver");let Y=c(Q.code);if(Z.id!==Y)throw X.metaMismatch(Y,Z.id,"id");if(Z.int!==Q.pubkey)throw X.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw X.missingMeta();let{int:q,iss:Z}=$;if(!q)throw X.invalidMetaFormat("Missing 'int' (intendedFor) field");let Y,J;try{Y=new F.PublicKey(q)}catch{throw X.invalidPubkeyFormat(q,"Invalid public key format")}try{if(Z)J=new F.PublicKey(Z)}catch{throw X.invalidPubkeyFormat(Z||"","Invalid public key format")}let U=this.deserializeTransaction(Q),z=[];if(U instanceof F.Transaction){let K=!1,N=!1;if(U.signatures.forEach((j)=>{if(!j.signature)return;if(z.push(j.publicKey.toString()),j.publicKey.equals(Y))K=!0;if(Z&&j.publicKey.equals(J))N=!0}),!K)throw X.transactionNotSignedByIntendedOwner(q,z);if(Z&&!N)throw X.transactionNotSignedByIssuer(Z,z);return}if(U instanceof F.VersionedTransaction){let K=U.message,N=!1,j=!1,G=K.header.numRequiredSignatures,W;try{W=K.getAccountKeys()}catch{W=null}for(let v=0;v<G;v++){let R=W?W.get(v):K.staticAccountKeys[v];if(R){if(z.push(R.toString()),R.equals(Y))N=!0;if(Z&&R.equals(J))j=!0}}if(!N)throw X.transactionNotSignedByIntendedOwner(q,z);if(Z&&!j)throw X.transactionNotSignedByIssuer(Z,z);return}throw X.invalidTransactionFormat("Unsupported transaction format")}verifyMessageSignedByIntentOwner(Q,$,q){try{let Z=new TextEncoder().encode(Q),Y=f.default.decode($),U=this.normalizePubkey(q).toBytes();if(!S.default.sign.detached.verify(Z,Y,U))throw X.invalidSignature("Signature verification failed")}catch(Z){if(Z instanceof Error&&Z.message.includes("Signature verification failed"))throw Z;throw X.invalidSignature("Invalid signature format")}}static async attachProtocolMeta(Q,$,q){if(new o().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let J=o.createProtocolMetaIx($);try{let U=F.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if(U.message instanceof F.MessageV0){let z=U.message,K=z.addressTableLookups&&z.addressTableLookups.length>0,N=z.staticAccountKeys.length,j=z.compiledInstructions.some((G)=>G.accountKeyIndexes.some((W)=>W>=N));if(K&&j){if(!q)throw X.invalidTransactionFormat("Connection required: Transaction uses address lookup tables and instructions reference accounts from those tables. A Solana connection is needed to resolve lookup tables and correctly recalculate account indices.");let G=[];for(let M of z.addressTableLookups)try{let D=await q.getAddressLookupTable(M.accountKey);if(D.value)G.push(D.value)}catch(D){throw X.invalidTransactionFormat(`Failed to resolve address lookup table ${M.accountKey.toString()}: ${D}`)}let W=F.TransactionMessage.decompile(z,{addressLookupTableAccounts:G});W.instructions.push(J);let v=W.compileToV0Message(G),R=new F.VersionedTransaction(v),w=v.header.numRequiredSignatures;return R.signatures=Array.from({length:w},()=>new Uint8Array(64)),Buffer.from(R.serialize()).toString("base64")}else{let G=[...z.staticAccountKeys];if(!G.some((D)=>D.equals(k.MEMO_PROGRAM_ID)))G.push(k.MEMO_PROGRAM_ID);let v={programIdIndex:G.findIndex((D)=>D.equals(k.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:J.data},R=new F.MessageV0({header:z.header,staticAccountKeys:G,recentBlockhash:z.recentBlockhash,compiledInstructions:[...z.compiledInstructions,v],addressTableLookups:z.addressTableLookups}),w=new F.VersionedTransaction(R),M=R.header.numRequiredSignatures;return w.signatures=Array.from({length:M},()=>new Uint8Array(64)),Buffer.from(w.serialize()).toString("base64")}}else{let z=F.Transaction.from(Buffer.from(Q,"base64"));return z.add(J),Buffer.from(z.serialize({requireAllSignatures:!1})).toString("base64")}}catch(U){if(U instanceof X)throw U;try{let z=F.Transaction.from(Buffer.from(Q,"base64"));return z.add(J),Buffer.from(z.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw X.invalidTransactionFormat(`Invalid base64 transaction format: ${U}`)}}}}class M0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new o,this._walletStrategy=new e(Q),this._delegationStrategy=new I8(Q)}getConfig(){return this.config}registerAdapter(Q,$){this.adapters[Q]=$}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}async generate(Q,$,q,Z){if(!q||!T8[q])throw X.invalidAdapter(q);if(!Z||typeof Z!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=w8($),J=await Z(Y,q);if(!J)throw X.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(Y,q,J)}else{let Y=$,J=w8(Y.delegatedPubkey),U=await Z(J,q);if(!U)throw X.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(Y,J,q,U)}}async revoke(Q,$,q,Z){if(!q||!T8[q])throw X.invalidAdapter(q);if(!Z||typeof Z!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=n({codeHash:c($.code),pubkey:$.pubkey,windowStart:$.timestamp}),J=await Z(Y,q);if(!J)throw X.invalidSignature("Missing signature over canonical message");return{...$,revokeSignature:J}}else{let Y=$,J=n({codeHash:c($.code),pubkey:Y.delegationProof.delegatedPubkey,windowStart:$.timestamp}),U=await Z(J,q);if(!U)throw X.invalidSignature("Missing delegated signature");return{...$,revokeSignature:U}}}validate(Q,$){if(Q==="wallet"){this.walletStrategy.validateCode($);let q=this.getAdapter($.chain);if(!q)throw X.invalidAdapter($.chain);if(!q.verifyWithWallet($))throw X.invalidSignature("Wallet signature verification failed")}else{this.delegationStrategy.validateDelegatedCode($);let q=this.getAdapter($.chain);if(!q)throw X.invalidAdapter($.chain);if(!q.verifyWithDelegation($))throw X.invalidSignature("Delegation signature verification failed")}}}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=86F860824C6AF6E264756E2164756E21
|