@actioncodes/protocol 2.0.19 → 2.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/SolanaAdapter.d.ts +1 -0
- package/dist/adapters/SolanaAdapter.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +5 -5
- package/dist/index.js +2 -2
- package/dist/index.js.map +5 -5
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ export declare class SolanaAdapter extends BaseChainAdapter {
|
|
|
36
36
|
* Throws ProtocolError if validation fails.
|
|
37
37
|
*/
|
|
38
38
|
verifyTransactionSignedByIntentOwner(txString: string): void;
|
|
39
|
+
verifyMessageSignedByIntentOwner(message: string, signature: string, pubkey: string): void;
|
|
39
40
|
/**
|
|
40
41
|
* Attach protocol meta into a base64-encoded transaction and return the modified transaction as base64.
|
|
41
42
|
* Throws ProtocolError if the transaction already contains protocol meta.
|
|
@@ -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,EAEvB,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;
|
|
1
|
+
{"version":3,"file":"SolanaAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/SolanaAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EAEvB,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,yFAAyF;IACzF,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAoBhD,2EAA2E;IAC3E,OAAO,CAAC,sBAAsB;IA2B9B,iGAAiG;IACjG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAMtD,uEAAuE;IACvE,OAAO,CAAC,mBAAmB;IAmC3B;;;OAGG;IACH,4BAA4B,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAiC5E;;;;OAIG;IACH,oCAAoC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAqE5D,gCAAgC,CAC9B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,IAAI;IA0BP;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,kBAAkB,GACvB,MAAM;CAoFV"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export declare const CODE_MIN_LENGTH = 6;
|
|
|
4
4
|
export declare const CODE_MAX_LENGTH = 24;
|
|
5
5
|
export declare const CODE_DEFAULT_LENGTH = 8;
|
|
6
6
|
export declare const CODE_CHARSET_DIGITS = "0123456789";
|
|
7
|
-
export declare const SUPPORTED_CHAINS:
|
|
7
|
+
export declare const SUPPORTED_CHAINS: {
|
|
8
|
+
readonly solana: "solana";
|
|
9
|
+
};
|
|
8
10
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAGrC,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAGrC,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB;;CAEnB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var T0=Object.create;var{getPrototypeOf:I0,defineProperty:o,getOwnPropertyNames:t8,getOwnPropertyDescriptor:m0}=Object,e8=Object.prototype.hasOwnProperty;var Q8=(Q,$,Z)=>{Z=Q!=null?T0(I0(Q)):{};let q=$||!Q||!Q.__esModule?o(Z,"default",{value:Q,enumerable:!0}):Z;for(let Y of t8(Q))if(!e8.call(q,Y))o(q,Y,{get:()=>Q[Y],enumerable:!0});return q},a8=new WeakMap,b0=(Q)=>{var $=a8.get(Q),Z;if($)return $;if($=o({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")t8(Q).map((q)=>!e8.call($,q)&&o($,q,{get:()=>Q[q],enumerable:!(Z=m0(Q,q))||Z.enumerable}));return a8.set(Q,$),$};var B0=(Q,$)=>{for(var Z in $)o(Q,Z,{get:$[Z],enumerable:!0,configurable:!0,set:(q)=>$[Z]=()=>q})};var i0={};B0(i0,{validateProtocolMetaFormat:()=>n0,truncateBits:()=>D8,sha256:()=>O0,serializeDelegationProof:()=>F8,serializeCanonicalRevoke:()=>h,serializeCanonical:()=>E,parseProtocolMeta:()=>J8,hmacSha256:()=>W8,hkdfSha256:()=>c0,getCanonicalMessageParts:()=>O8,digestToDigits:()=>v8,codeHash:()=>p,buildProtocolMeta:()=>T8,base32EncodeCrockford:()=>d0,WalletStrategy:()=>a,TransactionNotSignedByIntendedOwnerError:()=>u8,SolanaAdapter:()=>t,SUPPORTED_CHAINS:()=>M8,SCHEME:()=>V8,ProtocolErrorCode:()=>F0,ProtocolError:()=>X,PROTOCOL_NORMALIZATION:()=>w8,PROTOCOL_META_MAX_BYTES:()=>r,MissingMetaError:()=>C8,MetaMismatchError:()=>p8,InvalidSignatureError:()=>g8,InvalidPubkeyFormatError:()=>A8,InvalidCodeFormatError:()=>h8,InvalidAdapterError:()=>c8,ExpiredCodeError:()=>f8,DelegationStrategy:()=>I8,CODE_MIN_LENGTH:()=>x8,CODE_MAX_LENGTH:()=>L8,CODE_DEFAULT_LENGTH:()=>l0,CODE_CHARSET_DIGITS:()=>s0,CANONICAL_REVOKE_MESSAGE_PREFIX:()=>x0,CANONICAL_MESSAGE_VERSION:()=>d8,CANONICAL_MESSAGE_PREFIX:()=>w0,BaseChainAdapter:()=>z8,ActionCodesProtocol:()=>V0,ADAPTER_CHAIN_NAME:()=>l});module.exports=b0(i0);class z8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function y0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function K8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let Z=$&&`"${$}" `;throw Error(`${Z}expected integer >= 0, got ${Q}`)}}function S(Q,$,Z=""){let q=y0(Q),Y=Q?.length,J=$!==void 0;if(!q||J&&Y!==$){let U=Z&&`"${Z}" `,K=J?` of length ${$}`:"",G=q?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+K+", got "+G)}return Q}function $8(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");K8(Q.outputLen),K8(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 o8(Q,$){S(Q,void 0,"digestInto() output");let Z=$.outputLen;if(Q.length<Z)throw Error('"digestInto() output" expected to be of length >='+Z)}function k(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function j8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function T(Q,$){return Q<<32-$|Q>>>$}function Q0(Q,$={}){let Z=(Y,J)=>Q(J).update(Y).digest(),q=Q(void 0);return Z.outputLen=q.outputLen,Z.blockLen=q.blockLen,Z.create=(Y)=>Q(Y),Object.assign(Z,$),Object.freeze(Z)}var $0=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function Z0(Q,$,Z){return Q&$^~Q&Z}function q0(Q,$,Z){return Q&$^Q&Z^$&Z}class G8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,Z,q){this.blockLen=Q,this.outputLen=$,this.padOffset=Z,this.isLE=q,this.buffer=new Uint8Array(Q),this.view=j8(this.buffer)}update(Q){s(this),S(Q);let{view:$,buffer:Z,blockLen:q}=this,Y=Q.length;for(let J=0;J<Y;){let U=Math.min(q-this.pos,Y-J);if(U===q){let K=j8(Q);for(;q<=Y-J;J+=q)this.process(K,J);continue}if(Z.set(Q.subarray(J,J+U),this.pos),this.pos+=U,J+=U,this.pos===q)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){s(this),o8(Q,this),this.finished=!0;let{buffer:$,view:Z,blockLen:q,isLE:Y}=this,{pos:J}=this;if($[J++]=128,k(this.buffer.subarray(J)),this.padOffset>q-J)this.process(Z,0),J=0;for(let z=J;z<q;z++)$[z]=0;Z.setBigUint64(q-8,BigInt(this.length*8),Y),this.process(Z,0);let U=j8(Q),K=this.outputLen;if(K%4)throw Error("_sha2: outputLen must be aligned to 32bit");let G=K/4,j=this.get();if(G>j.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<G;z++)U.setUint32(4*z,j[z],Y)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let Z=Q.slice(0,$);return this.destroy(),Z}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:Z,length:q,finished:Y,destroyed:J,pos:U}=this;if(Q.destroyed=J,Q.finished=Y,Q.length=q,Q.pos=U,q%$)Q.buffer.set(Z);return Q}clone(){return this._cloneInto()}}var B=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),y=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),w=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 N8=BigInt(4294967295),Y0=BigInt(32);function E0(Q,$=!1){if($)return{h:Number(Q&N8),l:Number(Q>>Y0&N8)};return{h:Number(Q>>Y0&N8)|0,l:Number(Q&N8)|0}}function J0(Q,$=!1){let Z=Q.length,q=new Uint32Array(Z),Y=new Uint32Array(Z);for(let J=0;J<Z;J++){let{h:U,l:K}=E0(Q[J],$);[q[J],Y[J]]=[U,K]}return[q,Y]}var E8=(Q,$,Z)=>Q>>>Z,P8=(Q,$,Z)=>Q<<32-Z|$>>>Z,A=(Q,$,Z)=>Q>>>Z|$<<32-Z,g=(Q,$,Z)=>Q<<32-Z|$>>>Z,Z8=(Q,$,Z)=>Q<<64-Z|$>>>Z-32,q8=(Q,$,Z)=>Q>>>Z-32|$<<64-Z;function I(Q,$,Z,q){let Y=($>>>0)+(q>>>0);return{h:Q+Z+(Y/4294967296|0)|0,l:Y|0}}var X0=(Q,$,Z)=>(Q>>>0)+($>>>0)+(Z>>>0),U0=(Q,$,Z,q)=>$+Z+q+(Q/4294967296|0)|0,z0=(Q,$,Z,q)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0),K0=(Q,$,Z,q,Y)=>$+Z+q+Y+(Q/4294967296|0)|0,j0=(Q,$,Z,q,Y)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0)+(Y>>>0),G0=(Q,$,Z,q,Y,J)=>$+Z+q+Y+J+(Q/4294967296|0)|0;var H0=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]),_=new Uint32Array(64);class H8 extends G8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:Z,D:q,E:Y,F:J,G:U,H:K}=this;return[Q,$,Z,q,Y,J,U,K]}set(Q,$,Z,q,Y,J,U,K){this.A=Q|0,this.B=$|0,this.C=Z|0,this.D=q|0,this.E=Y|0,this.F=J|0,this.G=U|0,this.H=K|0}process(Q,$){for(let z=0;z<16;z++,$+=4)_[z]=Q.getUint32($,!1);for(let z=16;z<64;z++){let N=_[z-15],R=_[z-2],O=T(N,7)^T(N,18)^N>>>3,F=T(R,17)^T(R,19)^R>>>10;_[z]=F+_[z-7]+O+_[z-16]|0}let{A:Z,B:q,C:Y,D:J,E:U,F:K,G,H:j}=this;for(let z=0;z<64;z++){let N=T(U,6)^T(U,11)^T(U,25),R=j+N+Z0(U,K,G)+H0[z]+_[z]|0,F=(T(Z,2)^T(Z,13)^T(Z,22))+q0(Z,q,Y)|0;j=G,G=K,K=U,U=J+R|0,J=Y,Y=q,q=Z,Z=R+F|0}Z=Z+this.A|0,q=q+this.B|0,Y=Y+this.C|0,J=J+this.D|0,U=U+this.E|0,K=K+this.F|0,G=G+this.G|0,j=j+this.H|0,this.set(Z,q,Y,J,U,K,G,j)}roundClean(){k(_)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}class N0 extends H8{A=B[0]|0;B=B[1]|0;C=B[2]|0;D=B[3]|0;E=B[4]|0;F=B[5]|0;G=B[6]|0;H=B[7]|0;constructor(){super(32)}}class S0 extends H8{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(28)}}var R0=(()=>J0(["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))))(),_0=(()=>R0[0])(),f0=(()=>R0[1])(),f=new Uint32Array(80),C=new Uint32Array(80);class Y8 extends G8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:Z,Bl:q,Ch:Y,Cl:J,Dh:U,Dl:K,Eh:G,El:j,Fh:z,Fl:N,Gh:R,Gl:O,Hh:F,Hl:V}=this;return[Q,$,Z,q,Y,J,U,K,G,j,z,N,R,O,F,V]}set(Q,$,Z,q,Y,J,U,K,G,j,z,N,R,O,F,V){this.Ah=Q|0,this.Al=$|0,this.Bh=Z|0,this.Bl=q|0,this.Ch=Y|0,this.Cl=J|0,this.Dh=U|0,this.Dl=K|0,this.Eh=G|0,this.El=j|0,this.Fh=z|0,this.Fl=N|0,this.Gh=R|0,this.Gl=O|0,this.Hh=F|0,this.Hl=V|0}process(Q,$){for(let W=0;W<16;W++,$+=4)f[W]=Q.getUint32($),C[W]=Q.getUint32($+=4);for(let W=16;W<80;W++){let P=f[W-15]|0,H=C[W-15]|0,m8=A(P,H,1)^A(P,H,8)^E8(P,H,7),b8=g(P,H,1)^g(P,H,8)^P8(P,H,7),m=f[W-2]|0,b=C[W-2]|0,X8=A(m,b,19)^Z8(m,b,61)^E8(m,b,6),B8=g(m,b,19)^q8(m,b,61)^P8(m,b,6),U8=z0(b8,B8,C[W-7],C[W-16]),y8=K0(U8,m8,X8,f[W-7],f[W-16]);f[W]=y8|0,C[W]=U8|0}let{Ah:Z,Al:q,Bh:Y,Bl:J,Ch:U,Cl:K,Dh:G,Dl:j,Eh:z,El:N,Fh:R,Fl:O,Gh:F,Gl:V,Hh:v,Hl:e}=this;for(let W=0;W<80;W++){let P=A(z,N,14)^A(z,N,18)^Z8(z,N,41),H=g(z,N,14)^g(z,N,18)^q8(z,N,41),m8=z&R^~z&F,b8=N&O^~N&V,m=j0(e,H,b8,f0[W],C[W]),b=G0(m,v,P,m8,_0[W],f[W]),X8=m|0,B8=A(Z,q,28)^Z8(Z,q,34)^Z8(Z,q,39),U8=g(Z,q,28)^q8(Z,q,34)^q8(Z,q,39),y8=Z&Y^Z&U^Y&U,k0=q&J^q&K^J&K;v=F|0,e=V|0,F=R|0,V=O|0,R=z|0,O=N|0,{h:z,l:N}=I(G|0,j|0,b|0,X8|0),G=U|0,j=K|0,U=Y|0,K=J|0,Y=Z|0,J=q|0;let r8=X0(X8,U8,k0);Z=U0(r8,b,B8,y8),q=r8|0}({h:Z,l:q}=I(this.Ah|0,this.Al|0,Z|0,q|0)),{h:Y,l:J}=I(this.Bh|0,this.Bl|0,Y|0,J|0),{h:U,l:K}=I(this.Ch|0,this.Cl|0,U|0,K|0),{h:G,l:j}=I(this.Dh|0,this.Dl|0,G|0,j|0),{h:z,l:N}=I(this.Eh|0,this.El|0,z|0,N|0),{h:R,l:O}=I(this.Fh|0,this.Fl|0,R|0,O|0),{h:F,l:V}=I(this.Gh|0,this.Gl|0,F|0,V|0),{h:v,l:e}=I(this.Hh|0,this.Hl|0,v|0,e|0),this.set(Z,q,Y,J,U,K,G,j,z,N,R,O,F,V,v,e)}roundClean(){k(f,C)}destroy(){k(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class C0 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(64)}}class p0 extends Y8{Ah=w[0]|0;Al=w[1]|0;Bh=w[2]|0;Bl=w[3]|0;Ch=w[4]|0;Cl=w[5]|0;Dh=w[6]|0;Dl=w[7]|0;Eh=w[8]|0;El=w[9]|0;Fh=w[10]|0;Fl=w[11]|0;Gh=w[12]|0;Gl=w[13]|0;Hh=w[14]|0;Hl=w[15]|0;constructor(){super(48)}}var L=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=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(28)}}class A0 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 R8=Q0(()=>new N0,$0(1));class S8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if($8(Q),S($,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 Z=this.blockLen,q=new Uint8Array(Z);q.set($.length>Z?Q.create().update($).digest():$);for(let Y=0;Y<q.length;Y++)q[Y]^=54;this.iHash.update(q),this.oHash=Q.create();for(let Y=0;Y<q.length;Y++)q[Y]^=106;this.oHash.update(q),k(q)}update(Q){return s(this),this.iHash.update(Q),this}digestInto(Q){s(this),S(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:Z,finished:q,destroyed:Y,blockLen:J,outputLen:U}=this;return Q=Q,Q.finished=q,Q.destroyed=Y,Q.blockLen=J,Q.outputLen=U,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=Z._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var n=(Q,$,Z)=>new S8(Q,$).update(Z).digest();n.create=(Q,$)=>new S8(Q,$);function g0(Q,$,Z){if($8(Q),Z===void 0)Z=new Uint8Array(Q.outputLen);return n(Q,Z,$)}var _8=Uint8Array.of(0),W0=Uint8Array.of();function h0(Q,$,Z,q=32){$8(Q),K8(q,"length");let Y=Q.outputLen;if(q>255*Y)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(q/Y);if(Z===void 0)Z=W0;else S(Z,void 0,"info");let U=new Uint8Array(J*Y),K=n.create(Q,$),G=K._cloneInto(),j=new Uint8Array(K.outputLen);for(let z=0;z<J;z++)_8[0]=z+1,G.update(z===0?W0:j).update(Z).update(_8).digestInto(j),U.set(j,Y*z),K._cloneInto(G);return K.destroy(),G.destroy(),k(j,_8),U.slice(0,q)}var D0=(Q,$,Z,q,Y)=>h0(Q,g0(Q,$,Z),q,Y);function i(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function O0(Q){return R8(i(Q))}function W8(Q,$){return n(R8,i(Q),i($))}function c0(Q,$,{salt:Z,info:q}={}){let Y=Z?i(Z):new Uint8Array(32),J=i(Q),U=q?i(q):new Uint8Array(0);return D0(R8,J,Y,U,$)}var v0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function d0(Q){let $=0,Z=0,q="";for(let Y=0;Y<Q.length;Y++){Z=Z<<8|Q[Y],$+=8;while($>=5)q+=v0[Z>>>$-5&31],$-=5}if($>0)q+=v0[Z<<5-$&31];return q}function D8(Q,$){let Z=Math.ceil($/8),q=new Uint8Array(Z),Y=Math.min(Z,Q.length);q.set(Q.subarray(0,Y));let J=Z*8-$;if(J>0){let U=255<<J;q[Z-1]=q[Z-1]&U}return q}function v8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let Z="",q=Q[Q.length-1]&15;for(let Y=0;Z.length<$;Y++){let J=(q+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");Z+=G}return Z.slice(0,$)}function p(Q){let $=O0(Q);return Array.from($).map((Z)=>Z.toString(16).padStart(2,"0")).join("")}var F0;((v)=>{v.EXPIRED_CODE="EXPIRED_CODE";v.INVALID_CODE="INVALID_CODE";v.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";v.INVALID_SIGNATURE="INVALID_SIGNATURE";v.MISSING_META="MISSING_META";v.INVALID_META_FORMAT="INVALID_META_FORMAT";v.META_MISMATCH="META_MISMATCH";v.META_TOO_LARGE="META_TOO_LARGE";v.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";v.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";v.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";v.INVALID_INPUT="INVALID_INPUT";v.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";v.CRYPTO_ERROR="CRYPTO_ERROR";v.INVALID_DIGEST="INVALID_DIGEST";v.INVALID_ADAPTER="INVALID_ADAPTER"})(F0||={});class X extends Error{code;details;constructor(Q,$,Z){super($);this.code=Q;this.details=Z;this.name="ProtocolError"}static expiredCode(Q,$,Z){return new f8(Q,$,Z)}static invalidCode(){return new X("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,$){return new h8(Q,$)}static invalidSignature(Q){return new g8(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,$,Z){return new p8(Q,$,Z)}static metaTooLarge(Q,$){return new X("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(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 A8(Q,$)}static invalidInput(Q,$,Z){return new X("INVALID_INPUT",`Invalid ${Q}: ${Z}`,{field:Q,value:$,reason:Z})}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 c8(Q)}static create(Q,$,Z){return new X(Q,$,Z)}}class f8 extends X{constructor(Q,$,Z){super("EXPIRED_CODE",`Action code '${Q}' has expired`,{code:Q,expiresAt:$,currentTime:Z});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,$,Z){super("META_MISMATCH",`Meta ${Z} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:Z});this.name="MetaMismatchError"}}class u8 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 A8 extends X{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class g8 extends X{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class h8 extends X{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class c8 extends X{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}var d8=1,w0="actioncodes",x0="actioncodes-revoke";function E(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:w0,ver:d8,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode($)}function h(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:d8,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function O8(Q){return E({pubkey:Q,windowStart:Date.now()})}function F8(Q){let $=["walletPubkey","delegatedPubkey","chain"];for(let q of $){let Y=Q[q];if(typeof Y!=="string")throw X.invalidInput(q,Y,"must be a string");if(Y.length===0)throw X.invalidInput(q,Y,"cannot be empty");if(Y.length>100)throw X.invalidInput(q,Y,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Y))throw X.invalidInput(q,Y,"contains invalid characters for identifiers or JSON")}let Z=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(Z)}var w8="NFC",r=256,x8=6,L8=24,l0=8,s0="0123456789",M8=["solana"];var V8="actioncodes:";function T8(Q){let $=L0(Q);if($.int!=null)k8($.int);let Z=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let Y=JSON.stringify($.p);k8(Y),Z.push(`p=${encodeURIComponent(Y)}`)}let q=V8+Z.join("&");return M0(q),q}function J8(Q){if(!Q.startsWith(V8))throw Error("protocol meta must start with actioncodes:");let Z=Q.slice(V8.length).split("&").filter(Boolean),q=new Map;for(let R of Z){let[O,F]=R.split("=",2);if(!O)continue;let V=F!=null?decodeURIComponent(F):"";q.set(O,V)}let Y=q.get("ver"),J=q.get("id"),U=q.get("int"),K=q.get("p");if(Y==null||J==null||U==null)throw Error("protocol meta missing required fields ver or id or int");let G=Number(Y);if(!Number.isInteger(G)||G<=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 z=L0({ver:G,id:J,int:U,p:j});if(z.int!=null)k8(z.int);if(z.p!=null)k8(JSON.stringify(z.p));if([...q.keys()].filter((R)=>R!=="ver"&&R!=="id"&&R!=="int"&&R!=="p").length>0)throw Error("protocol meta contains unsupported keys");return M0(T8(z)),z}function n0(Q){try{return J8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function L0(Q){let $=Q.id.normalize(w8).trim(),Z={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)Z.int=Q.int.normalize(w8).trim();if(Q.p!=null)Z.p=Q.p;return Z}function M0(Q){if(new TextEncoder().encode(Q).length>r)throw Error(`protocol meta exceeds ${r} bytes`)}function k8(Q){if(new TextEncoder().encode(Q).length>r)throw Error(`protocol meta params exceed ${r} bytes`)}var l8=Q8(require("bs58"));class a{config;constructor(Q){this.config=Q}generateCode(Q,$,Z){let q=Q,Y=JSON.parse(new TextDecoder().decode(q)),J=Y.pubkey,U=Y.windowStart,K;try{K=l8.default.decode(Z)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let G=W8(K,q),j=Math.max(x8,Math.min(L8,this.config.codeLength)),z=8*Math.ceil(j/2),N=D8(G,z),R=v8(N,j);return{chain:$,code:R,pubkey:J,timestamp:U,expiresAt:U+this.config.ttlMs,signature:Z}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);let Z=E({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw X.missingRequiredField("signature");let q;try{q=l8.default.decode(Q.signature)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let Y=W8(q,Z),J=Math.max(x8,Math.min(L8,this.config.codeLength)),U=D8(Y,8*Math.ceil(J/2));if(v8(U,J)!==Q.code)throw X.invalidCode()}}var s8=require("@solana/web3.js"),n8=Q8(require("tweetnacl")),i8=Q8(require("bs58"));class I8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new a(Q)}generateDelegatedCode(Q,$,Z,q){return this.validateDelegationProof(Q),{...this.walletStrategy.generateCode($,Z,q),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 Z=E({pubkey:Q.delegationProof.delegatedPubkey,windowStart:Q.timestamp}),q;try{q=i8.default.decode(Q.signature??"")}catch{throw X.invalidSignature("Invalid Base58 delegated signature format")}let Y=i8.default.decode(Q.delegationProof.delegatedPubkey);if(!n8.default.sign.detached.verify(Z,q,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(),Z=31536000000;if(Q.expiresAt>$+Z)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 c=Q8(require("tweetnacl")),d=Q8(require("bs58")),D=require("@solana/web3.js"),u=require("@solana/spl-memo");var l="solana";class t extends z8{normalizePubkey(Q){if(typeof Q==="string")return new D.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;try{let $=E({pubkey:Q.pubkey,windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),q=d.default.decode(Q.signature),Y=Z.toBytes();if(q.length!==64||Y.length!==32)return!1;return c.default.sign.detached.verify($,q,Y)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;let $=Q.delegationProof;if(!$.walletPubkey||!$.delegatedPubkey||!$.chain||!$.expiresAt||!$.signature)return!1;if($.chain!==l)return!1;if(Q.pubkey!==$.delegatedPubkey)return!1;if($.expiresAt<Date.now())return!1;try{let Z=F8($),q=this.normalizePubkey($.walletPubkey),Y=d.default.decode($.signature),J=q.toBytes(),U=E({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),K=this.normalizePubkey($.delegatedPubkey),G=d.default.decode(Q.signature),j=K.toBytes();if(Y.length!==64||J.length!==32)return!1;if(G.length!==64||j.length!==32)return!1;let z=c.default.sign.detached.verify(Z,Y,J),N=c.default.sign.detached.verify(U,G,j);return z&&N}catch{return!1}}verifyRevokeWithWallet(Q,$){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!$)return!1;try{let Z=h({pubkey:Q.pubkey,codeHash:p(Q.code),windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Y=d.default.decode($),J=q.toBytes();if(Y.length!==64||J.length!==32)return!1;return c.default.sign.detached.verify(Z,Y,J)}catch{return!1}}verifyRevokeWithDelegation(Q,$){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature||!Q.delegationProof)return!1;let Z=Q.delegationProof;if(!Z.walletPubkey||!Z.delegatedPubkey||!Z.chain||!Z.expiresAt||!Z.signature)return!1;if(Z.chain!==l)return!1;if(Q.pubkey!==Z.delegatedPubkey)return!1;if(Z.expiresAt<Date.now())return!1;try{let q=F8(Z),Y=this.normalizePubkey(Z.walletPubkey),J=d.default.decode(Z.signature),U=Y.toBytes(),K=h({pubkey:Z.delegatedPubkey,codeHash:p(Q.code),windowStart:Q.timestamp}),G=this.normalizePubkey(Z.delegatedPubkey),j=d.default.decode($),z=G.toBytes();if(J.length!==64||U.length!==32)return!1;if(j.length!==64||z.length!==32)return!1;let N=c.default.sign.detached.verify(q,J,U),R=c.default.sign.detached.verify(K,j,z);return N&&R}catch{return!1}}static createProtocolMetaIx(Q){let $=T8(Q);return u.createMemoInstruction($)}getProtocolMeta(Q){try{let $=this.deserializeTransaction(Q);for(let Z of this.getMemoInstructions($)){let q=Z.data;try{let Y=new TextDecoder().decode(q);if(J8(Y))return Y}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let $=D.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if($.message instanceof D.MessageV0)return $;else return D.Transaction.from(Buffer.from(Q,"base64"))}catch{try{return D.Transaction.from(Buffer.from(Q,"base64"))}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return J8($)}getMemoInstructions(Q){if(Q instanceof D.Transaction)return Q.instructions.filter(($)=>$.programId.equals(u.MEMO_PROGRAM_ID));else{let Z=Q.message;if(Z instanceof D.MessageV0){let q=[];for(let Y of Z.compiledInstructions){let J=Z.staticAccountKeys[Y.programIdIndex];if(J&&J.equals(u.MEMO_PROGRAM_ID)){let U=Y.accountKeyIndexes.map((K)=>({pubkey:Z.staticAccountKeys[K],isSigner:!1,isWritable:!1}));q.push(new D.TransactionInstruction({keys:U,programId:J,data:Y.data}))}}return q}return[]}}verifyTransactionMatchesCode(Q,$){let Z=Date.now();if(Z>Q.expiresAt)throw X.expiredCode(Q.code,Q.expiresAt,Z);let q=this.parseMeta($);if(!q)throw X.missingMeta();if(q.ver!==2)throw X.metaMismatch("2",String(q.ver),"ver");let Y=p(Q.code);if(q.id!==Y)throw X.metaMismatch(Y,q.id,"id");if(q.int!==Q.pubkey)throw X.metaMismatch(Q.pubkey,q.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw X.missingMeta();let Z=$.int;if(!Z)throw X.invalidMetaFormat("Missing 'int' (intendedFor) field");let q;try{q=new D.PublicKey(Z)}catch{throw X.invalidPubkeyFormat(Z,"Invalid public key format")}let Y=this.deserializeTransaction(Q),J=[];if(Y instanceof D.Transaction){if(!Y.signatures.some((K)=>{if(!K.signature)return!1;return J.push(K.publicKey.toString()),K.publicKey.equals(q)}))throw X.transactionNotSignedByIntendedOwner(Z,J);return}if(Y instanceof D.VersionedTransaction){let U=Y.message;if(U instanceof D.MessageV0){let K=U.header.numRequiredSignatures;for(let G=0;G<K;G++){let j=U.staticAccountKeys[G];if(j){if(J.push(j.toString()),j.equals(q))return}}throw X.transactionNotSignedByIntendedOwner(Z,J)}}throw X.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,$){if(new t().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let Y=t.createProtocolMetaIx($);try{let J=D.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof D.MessageV0){let U=J.message,K=[...U.staticAccountKeys];if(!K.some((R)=>R.equals(u.MEMO_PROGRAM_ID)))K.push(u.MEMO_PROGRAM_ID);let j={programIdIndex:K.findIndex((R)=>R.equals(u.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:Y.data},z=new D.MessageV0({header:U.header,staticAccountKeys:K,recentBlockhash:U.recentBlockhash,compiledInstructions:[...U.compiledInstructions,j],addressTableLookups:U.addressTableLookups}),N=new D.VersionedTransaction(z);return N.signatures=J.signatures,Buffer.from(N.serialize()).toString("base64")}else{let U=D.Transaction.from(Buffer.from(Q,"base64"));return U.add(Y),Buffer.from(U.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=D.Transaction.from(Buffer.from(Q,"base64"));return J.add(Y),Buffer.from(J.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}}class V0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new t,this._walletStrategy=new a(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,$,Z,q){if(!Z||!M8.includes(Z))throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=O8($),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(Y,Z,J)}else{let Y=$,J=O8(Y.delegatedPubkey),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(Y,J,Z,U)}}async revoke(Q,$,Z,q){if(!Z||!M8.includes(Z))throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=h({codeHash:p($.code),pubkey:$.pubkey,windowStart:$.timestamp}),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return{...$,revokeSignature:J}}else{let Y=$,J=h({codeHash:p($.code),pubkey:Y.delegationProof.delegatedPubkey,windowStart:$.timestamp}),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return{...$,revokeSignature:U}}}validate(Q,$){if(Q==="wallet"){this.walletStrategy.validateCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithWallet($))throw X.invalidSignature("Wallet signature verification failed")}else{this.delegationStrategy.validateDelegatedCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithDelegation($))throw X.invalidSignature("Delegation signature verification failed")}}}
|
|
1
|
+
var T0=Object.create;var{getPrototypeOf:I0,defineProperty:o,getOwnPropertyNames:t8,getOwnPropertyDescriptor:m0}=Object,e8=Object.prototype.hasOwnProperty;var Q8=(Q,$,Z)=>{Z=Q!=null?T0(I0(Q)):{};let q=$||!Q||!Q.__esModule?o(Z,"default",{value:Q,enumerable:!0}):Z;for(let Y of t8(Q))if(!e8.call(q,Y))o(q,Y,{get:()=>Q[Y],enumerable:!0});return q},a8=new WeakMap,b0=(Q)=>{var $=a8.get(Q),Z;if($)return $;if($=o({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")t8(Q).map((q)=>!e8.call($,q)&&o($,q,{get:()=>Q[q],enumerable:!(Z=m0(Q,q))||Z.enumerable}));return a8.set(Q,$),$};var B0=(Q,$)=>{for(var Z in $)o(Q,Z,{get:$[Z],enumerable:!0,configurable:!0,set:(q)=>$[Z]=()=>q})};var i0={};B0(i0,{validateProtocolMetaFormat:()=>n0,truncateBits:()=>D8,sha256:()=>O0,serializeDelegationProof:()=>F8,serializeCanonicalRevoke:()=>d,serializeCanonical:()=>E,parseProtocolMeta:()=>J8,hmacSha256:()=>W8,hkdfSha256:()=>c0,getCanonicalMessageParts:()=>O8,digestToDigits:()=>v8,codeHash:()=>u,buildProtocolMeta:()=>T8,base32EncodeCrockford:()=>d0,WalletStrategy:()=>a,TransactionNotSignedByIntendedOwnerError:()=>u8,SolanaAdapter:()=>t,SUPPORTED_CHAINS:()=>M8,SCHEME:()=>V8,ProtocolErrorCode:()=>F0,ProtocolError:()=>X,PROTOCOL_NORMALIZATION:()=>w8,PROTOCOL_META_MAX_BYTES:()=>r,MissingMetaError:()=>C8,MetaMismatchError:()=>p8,InvalidSignatureError:()=>g8,InvalidPubkeyFormatError:()=>A8,InvalidCodeFormatError:()=>h8,InvalidAdapterError:()=>c8,ExpiredCodeError:()=>f8,DelegationStrategy:()=>I8,CODE_MIN_LENGTH:()=>x8,CODE_MAX_LENGTH:()=>L8,CODE_DEFAULT_LENGTH:()=>l0,CODE_CHARSET_DIGITS:()=>s0,CANONICAL_REVOKE_MESSAGE_PREFIX:()=>x0,CANONICAL_MESSAGE_VERSION:()=>d8,CANONICAL_MESSAGE_PREFIX:()=>w0,BaseChainAdapter:()=>z8,ActionCodesProtocol:()=>V0,ADAPTER_CHAIN_NAME:()=>l});module.exports=b0(i0);class z8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function y0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function K8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let Z=$&&`"${$}" `;throw Error(`${Z}expected integer >= 0, got ${Q}`)}}function _(Q,$,Z=""){let q=y0(Q),Y=Q?.length,J=$!==void 0;if(!q||J&&Y!==$){let U=Z&&`"${Z}" `,K=J?` of length ${$}`:"",G=q?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+K+", got "+G)}return Q}function $8(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");K8(Q.outputLen),K8(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 o8(Q,$){_(Q,void 0,"digestInto() output");let Z=$.outputLen;if(Q.length<Z)throw Error('"digestInto() output" expected to be of length >='+Z)}function k(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function j8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function T(Q,$){return Q<<32-$|Q>>>$}function Q0(Q,$={}){let Z=(Y,J)=>Q(J).update(Y).digest(),q=Q(void 0);return Z.outputLen=q.outputLen,Z.blockLen=q.blockLen,Z.create=(Y)=>Q(Y),Object.assign(Z,$),Object.freeze(Z)}var $0=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function Z0(Q,$,Z){return Q&$^~Q&Z}function q0(Q,$,Z){return Q&$^Q&Z^$&Z}class G8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,Z,q){this.blockLen=Q,this.outputLen=$,this.padOffset=Z,this.isLE=q,this.buffer=new Uint8Array(Q),this.view=j8(this.buffer)}update(Q){s(this),_(Q);let{view:$,buffer:Z,blockLen:q}=this,Y=Q.length;for(let J=0;J<Y;){let U=Math.min(q-this.pos,Y-J);if(U===q){let K=j8(Q);for(;q<=Y-J;J+=q)this.process(K,J);continue}if(Z.set(Q.subarray(J,J+U),this.pos),this.pos+=U,J+=U,this.pos===q)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){s(this),o8(Q,this),this.finished=!0;let{buffer:$,view:Z,blockLen:q,isLE:Y}=this,{pos:J}=this;if($[J++]=128,k(this.buffer.subarray(J)),this.padOffset>q-J)this.process(Z,0),J=0;for(let z=J;z<q;z++)$[z]=0;Z.setBigUint64(q-8,BigInt(this.length*8),Y),this.process(Z,0);let U=j8(Q),K=this.outputLen;if(K%4)throw Error("_sha2: outputLen must be aligned to 32bit");let G=K/4,j=this.get();if(G>j.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<G;z++)U.setUint32(4*z,j[z],Y)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let Z=Q.slice(0,$);return this.destroy(),Z}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:Z,length:q,finished:Y,destroyed:J,pos:U}=this;if(Q.destroyed=J,Q.finished=Y,Q.length=q,Q.pos=U,q%$)Q.buffer.set(Z);return Q}clone(){return this._cloneInto()}}var B=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),y=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),w=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 N8=BigInt(4294967295),Y0=BigInt(32);function E0(Q,$=!1){if($)return{h:Number(Q&N8),l:Number(Q>>Y0&N8)};return{h:Number(Q>>Y0&N8)|0,l:Number(Q&N8)|0}}function J0(Q,$=!1){let Z=Q.length,q=new Uint32Array(Z),Y=new Uint32Array(Z);for(let J=0;J<Z;J++){let{h:U,l:K}=E0(Q[J],$);[q[J],Y[J]]=[U,K]}return[q,Y]}var E8=(Q,$,Z)=>Q>>>Z,H8=(Q,$,Z)=>Q<<32-Z|$>>>Z,h=(Q,$,Z)=>Q>>>Z|$<<32-Z,c=(Q,$,Z)=>Q<<32-Z|$>>>Z,Z8=(Q,$,Z)=>Q<<64-Z|$>>>Z-32,q8=(Q,$,Z)=>Q>>>Z-32|$<<64-Z;function I(Q,$,Z,q){let Y=($>>>0)+(q>>>0);return{h:Q+Z+(Y/4294967296|0)|0,l:Y|0}}var X0=(Q,$,Z)=>(Q>>>0)+($>>>0)+(Z>>>0),U0=(Q,$,Z,q)=>$+Z+q+(Q/4294967296|0)|0,z0=(Q,$,Z,q)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0),K0=(Q,$,Z,q,Y)=>$+Z+q+Y+(Q/4294967296|0)|0,j0=(Q,$,Z,q,Y)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0)+(Y>>>0),G0=(Q,$,Z,q,Y,J)=>$+Z+q+Y+J+(Q/4294967296|0)|0;var P0=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]),f=new Uint32Array(64);class P8 extends G8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:Z,D:q,E:Y,F:J,G:U,H:K}=this;return[Q,$,Z,q,Y,J,U,K]}set(Q,$,Z,q,Y,J,U,K){this.A=Q|0,this.B=$|0,this.C=Z|0,this.D=q|0,this.E=Y|0,this.F=J|0,this.G=U|0,this.H=K|0}process(Q,$){for(let z=0;z<16;z++,$+=4)f[z]=Q.getUint32($,!1);for(let z=16;z<64;z++){let N=f[z-15],R=f[z-2],O=T(N,7)^T(N,18)^N>>>3,F=T(R,17)^T(R,19)^R>>>10;f[z]=F+f[z-7]+O+f[z-16]|0}let{A:Z,B:q,C:Y,D:J,E:U,F:K,G,H:j}=this;for(let z=0;z<64;z++){let N=T(U,6)^T(U,11)^T(U,25),R=j+N+Z0(U,K,G)+P0[z]+f[z]|0,F=(T(Z,2)^T(Z,13)^T(Z,22))+q0(Z,q,Y)|0;j=G,G=K,K=U,U=J+R|0,J=Y,Y=q,q=Z,Z=R+F|0}Z=Z+this.A|0,q=q+this.B|0,Y=Y+this.C|0,J=J+this.D|0,U=U+this.E|0,K=K+this.F|0,G=G+this.G|0,j=j+this.H|0,this.set(Z,q,Y,J,U,K,G,j)}roundClean(){k(f)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}class N0 extends P8{A=B[0]|0;B=B[1]|0;C=B[2]|0;D=B[3]|0;E=B[4]|0;F=B[5]|0;G=B[6]|0;H=B[7]|0;constructor(){super(32)}}class S0 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(28)}}var R0=(()=>J0(["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))))(),_0=(()=>R0[0])(),f0=(()=>R0[1])(),C=new Uint32Array(80),p=new Uint32Array(80);class Y8 extends G8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:Z,Bl:q,Ch:Y,Cl:J,Dh:U,Dl:K,Eh:G,El:j,Fh:z,Fl:N,Gh:R,Gl:O,Hh:F,Hl:V}=this;return[Q,$,Z,q,Y,J,U,K,G,j,z,N,R,O,F,V]}set(Q,$,Z,q,Y,J,U,K,G,j,z,N,R,O,F,V){this.Ah=Q|0,this.Al=$|0,this.Bh=Z|0,this.Bl=q|0,this.Ch=Y|0,this.Cl=J|0,this.Dh=U|0,this.Dl=K|0,this.Eh=G|0,this.El=j|0,this.Fh=z|0,this.Fl=N|0,this.Gh=R|0,this.Gl=O|0,this.Hh=F|0,this.Hl=V|0}process(Q,$){for(let W=0;W<16;W++,$+=4)C[W]=Q.getUint32($),p[W]=Q.getUint32($+=4);for(let W=16;W<80;W++){let P=C[W-15]|0,S=p[W-15]|0,m8=h(P,S,1)^h(P,S,8)^E8(P,S,7),b8=c(P,S,1)^c(P,S,8)^H8(P,S,7),m=C[W-2]|0,b=p[W-2]|0,X8=h(m,b,19)^Z8(m,b,61)^E8(m,b,6),B8=c(m,b,19)^q8(m,b,61)^H8(m,b,6),U8=z0(b8,B8,p[W-7],p[W-16]),y8=K0(U8,m8,X8,C[W-7],C[W-16]);C[W]=y8|0,p[W]=U8|0}let{Ah:Z,Al:q,Bh:Y,Bl:J,Ch:U,Cl:K,Dh:G,Dl:j,Eh:z,El:N,Fh:R,Fl:O,Gh:F,Gl:V,Hh:v,Hl:e}=this;for(let W=0;W<80;W++){let P=h(z,N,14)^h(z,N,18)^Z8(z,N,41),S=c(z,N,14)^c(z,N,18)^q8(z,N,41),m8=z&R^~z&F,b8=N&O^~N&V,m=j0(e,S,b8,f0[W],p[W]),b=G0(m,v,P,m8,_0[W],C[W]),X8=m|0,B8=h(Z,q,28)^Z8(Z,q,34)^Z8(Z,q,39),U8=c(Z,q,28)^q8(Z,q,34)^q8(Z,q,39),y8=Z&Y^Z&U^Y&U,k0=q&J^q&K^J&K;v=F|0,e=V|0,F=R|0,V=O|0,R=z|0,O=N|0,{h:z,l:N}=I(G|0,j|0,b|0,X8|0),G=U|0,j=K|0,U=Y|0,K=J|0,Y=Z|0,J=q|0;let r8=X0(X8,U8,k0);Z=U0(r8,b,B8,y8),q=r8|0}({h:Z,l:q}=I(this.Ah|0,this.Al|0,Z|0,q|0)),{h:Y,l:J}=I(this.Bh|0,this.Bl|0,Y|0,J|0),{h:U,l:K}=I(this.Ch|0,this.Cl|0,U|0,K|0),{h:G,l:j}=I(this.Dh|0,this.Dl|0,G|0,j|0),{h:z,l:N}=I(this.Eh|0,this.El|0,z|0,N|0),{h:R,l:O}=I(this.Fh|0,this.Fl|0,R|0,O|0),{h:F,l:V}=I(this.Gh|0,this.Gl|0,F|0,V|0),{h:v,l:e}=I(this.Hh|0,this.Hl|0,v|0,e|0),this.set(Z,q,Y,J,U,K,G,j,z,N,R,O,F,V,v,e)}roundClean(){k(C,p)}destroy(){k(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class C0 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(64)}}class p0 extends Y8{Ah=w[0]|0;Al=w[1]|0;Bh=w[2]|0;Bl=w[3]|0;Ch=w[4]|0;Cl=w[5]|0;Dh=w[6]|0;Dl=w[7]|0;Eh=w[8]|0;El=w[9]|0;Fh=w[10]|0;Fl=w[11]|0;Gh=w[12]|0;Gl=w[13]|0;Hh=w[14]|0;Hl=w[15]|0;constructor(){super(48)}}var L=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=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(28)}}class A0 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 R8=Q0(()=>new N0,$0(1));class S8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if($8(Q),_($,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 Z=this.blockLen,q=new Uint8Array(Z);q.set($.length>Z?Q.create().update($).digest():$);for(let Y=0;Y<q.length;Y++)q[Y]^=54;this.iHash.update(q),this.oHash=Q.create();for(let Y=0;Y<q.length;Y++)q[Y]^=106;this.oHash.update(q),k(q)}update(Q){return s(this),this.iHash.update(Q),this}digestInto(Q){s(this),_(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:Z,finished:q,destroyed:Y,blockLen:J,outputLen:U}=this;return Q=Q,Q.finished=q,Q.destroyed=Y,Q.blockLen=J,Q.outputLen=U,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=Z._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var n=(Q,$,Z)=>new S8(Q,$).update(Z).digest();n.create=(Q,$)=>new S8(Q,$);function g0(Q,$,Z){if($8(Q),Z===void 0)Z=new Uint8Array(Q.outputLen);return n(Q,Z,$)}var _8=Uint8Array.of(0),W0=Uint8Array.of();function h0(Q,$,Z,q=32){$8(Q),K8(q,"length");let Y=Q.outputLen;if(q>255*Y)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(q/Y);if(Z===void 0)Z=W0;else _(Z,void 0,"info");let U=new Uint8Array(J*Y),K=n.create(Q,$),G=K._cloneInto(),j=new Uint8Array(K.outputLen);for(let z=0;z<J;z++)_8[0]=z+1,G.update(z===0?W0:j).update(Z).update(_8).digestInto(j),U.set(j,Y*z),K._cloneInto(G);return K.destroy(),G.destroy(),k(j,_8),U.slice(0,q)}var D0=(Q,$,Z,q,Y)=>h0(Q,g0(Q,$,Z),q,Y);function i(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function O0(Q){return R8(i(Q))}function W8(Q,$){return n(R8,i(Q),i($))}function c0(Q,$,{salt:Z,info:q}={}){let Y=Z?i(Z):new Uint8Array(32),J=i(Q),U=q?i(q):new Uint8Array(0);return D0(R8,J,Y,U,$)}var v0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function d0(Q){let $=0,Z=0,q="";for(let Y=0;Y<Q.length;Y++){Z=Z<<8|Q[Y],$+=8;while($>=5)q+=v0[Z>>>$-5&31],$-=5}if($>0)q+=v0[Z<<5-$&31];return q}function D8(Q,$){let Z=Math.ceil($/8),q=new Uint8Array(Z),Y=Math.min(Z,Q.length);q.set(Q.subarray(0,Y));let J=Z*8-$;if(J>0){let U=255<<J;q[Z-1]=q[Z-1]&U}return q}function v8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let Z="",q=Q[Q.length-1]&15;for(let Y=0;Z.length<$;Y++){let J=(q+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");Z+=G}return Z.slice(0,$)}function u(Q){let $=O0(Q);return Array.from($).map((Z)=>Z.toString(16).padStart(2,"0")).join("")}var F0;((v)=>{v.EXPIRED_CODE="EXPIRED_CODE";v.INVALID_CODE="INVALID_CODE";v.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";v.INVALID_SIGNATURE="INVALID_SIGNATURE";v.MISSING_META="MISSING_META";v.INVALID_META_FORMAT="INVALID_META_FORMAT";v.META_MISMATCH="META_MISMATCH";v.META_TOO_LARGE="META_TOO_LARGE";v.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";v.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";v.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";v.INVALID_INPUT="INVALID_INPUT";v.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";v.CRYPTO_ERROR="CRYPTO_ERROR";v.INVALID_DIGEST="INVALID_DIGEST";v.INVALID_ADAPTER="INVALID_ADAPTER"})(F0||={});class X extends Error{code;details;constructor(Q,$,Z){super($);this.code=Q;this.details=Z;this.name="ProtocolError"}static expiredCode(Q,$,Z){return new f8(Q,$,Z)}static invalidCode(){return new X("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,$){return new h8(Q,$)}static invalidSignature(Q){return new g8(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,$,Z){return new p8(Q,$,Z)}static metaTooLarge(Q,$){return new X("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(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 A8(Q,$)}static invalidInput(Q,$,Z){return new X("INVALID_INPUT",`Invalid ${Q}: ${Z}`,{field:Q,value:$,reason:Z})}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 c8(Q)}static create(Q,$,Z){return new X(Q,$,Z)}}class f8 extends X{constructor(Q,$,Z){super("EXPIRED_CODE",`Action code '${Q}' has expired`,{code:Q,expiresAt:$,currentTime:Z});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,$,Z){super("META_MISMATCH",`Meta ${Z} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:Z});this.name="MetaMismatchError"}}class u8 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 A8 extends X{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class g8 extends X{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class h8 extends X{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class c8 extends X{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}var d8=1,w0="actioncodes",x0="actioncodes-revoke";function E(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:w0,ver:d8,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode($)}function d(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:d8,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function O8(Q){return E({pubkey:Q,windowStart:Date.now()})}function F8(Q){let $=["walletPubkey","delegatedPubkey","chain"];for(let q of $){let Y=Q[q];if(typeof Y!=="string")throw X.invalidInput(q,Y,"must be a string");if(Y.length===0)throw X.invalidInput(q,Y,"cannot be empty");if(Y.length>100)throw X.invalidInput(q,Y,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Y))throw X.invalidInput(q,Y,"contains invalid characters for identifiers or JSON")}let Z=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(Z)}var w8="NFC",r=256,x8=6,L8=24,l0=8,s0="0123456789",M8={solana:"solana"};var V8="actioncodes:";function T8(Q){let $=L0(Q);if($.int!=null)k8($.int);let Z=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let Y=JSON.stringify($.p);k8(Y),Z.push(`p=${encodeURIComponent(Y)}`)}let q=V8+Z.join("&");return M0(q),q}function J8(Q){if(!Q.startsWith(V8))throw Error("protocol meta must start with actioncodes:");let Z=Q.slice(V8.length).split("&").filter(Boolean),q=new Map;for(let R of Z){let[O,F]=R.split("=",2);if(!O)continue;let V=F!=null?decodeURIComponent(F):"";q.set(O,V)}let Y=q.get("ver"),J=q.get("id"),U=q.get("int"),K=q.get("p");if(Y==null||J==null||U==null)throw Error("protocol meta missing required fields ver or id or int");let G=Number(Y);if(!Number.isInteger(G)||G<=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 z=L0({ver:G,id:J,int:U,p:j});if(z.int!=null)k8(z.int);if(z.p!=null)k8(JSON.stringify(z.p));if([...q.keys()].filter((R)=>R!=="ver"&&R!=="id"&&R!=="int"&&R!=="p").length>0)throw Error("protocol meta contains unsupported keys");return M0(T8(z)),z}function n0(Q){try{return J8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function L0(Q){let $=Q.id.normalize(w8).trim(),Z={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)Z.int=Q.int.normalize(w8).trim();if(Q.p!=null)Z.p=Q.p;return Z}function M0(Q){if(new TextEncoder().encode(Q).length>r)throw Error(`protocol meta exceeds ${r} bytes`)}function k8(Q){if(new TextEncoder().encode(Q).length>r)throw Error(`protocol meta params exceed ${r} bytes`)}var l8=Q8(require("bs58"));class a{config;constructor(Q){this.config=Q}generateCode(Q,$,Z){let q=Q,Y=JSON.parse(new TextDecoder().decode(q)),J=Y.pubkey,U=Y.windowStart,K;try{K=l8.default.decode(Z)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let G=W8(K,q),j=Math.max(x8,Math.min(L8,this.config.codeLength)),z=8*Math.ceil(j/2),N=D8(G,z),R=v8(N,j);return{chain:$,code:R,pubkey:J,timestamp:U,expiresAt:U+this.config.ttlMs,signature:Z}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);let Z=E({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw X.missingRequiredField("signature");let q;try{q=l8.default.decode(Q.signature)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let Y=W8(q,Z),J=Math.max(x8,Math.min(L8,this.config.codeLength)),U=D8(Y,8*Math.ceil(J/2));if(v8(U,J)!==Q.code)throw X.invalidCode()}}var s8=require("@solana/web3.js"),n8=Q8(require("tweetnacl")),i8=Q8(require("bs58"));class I8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new a(Q)}generateDelegatedCode(Q,$,Z,q){return this.validateDelegationProof(Q),{...this.walletStrategy.generateCode($,Z,q),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 Z=E({pubkey:Q.delegationProof.delegatedPubkey,windowStart:Q.timestamp}),q;try{q=i8.default.decode(Q.signature??"")}catch{throw X.invalidSignature("Invalid Base58 delegated signature format")}let Y=i8.default.decode(Q.delegationProof.delegatedPubkey);if(!n8.default.sign.detached.verify(Z,q,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(),Z=31536000000;if(Q.expiresAt>$+Z)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 H=Q8(require("tweetnacl")),A=Q8(require("bs58")),D=require("@solana/web3.js"),g=require("@solana/spl-memo");var l="solana";class t extends z8{normalizePubkey(Q){if(typeof Q==="string")return new D.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;try{let $=E({pubkey:Q.pubkey,windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),q=A.default.decode(Q.signature),Y=Z.toBytes();if(q.length!==64||Y.length!==32)return!1;return H.default.sign.detached.verify($,q,Y)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;let $=Q.delegationProof;if(!$.walletPubkey||!$.delegatedPubkey||!$.chain||!$.expiresAt||!$.signature)return!1;if($.chain!==l)return!1;if(Q.pubkey!==$.delegatedPubkey)return!1;if($.expiresAt<Date.now())return!1;try{let Z=F8($),q=this.normalizePubkey($.walletPubkey),Y=A.default.decode($.signature),J=q.toBytes(),U=E({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),K=this.normalizePubkey($.delegatedPubkey),G=A.default.decode(Q.signature),j=K.toBytes();if(Y.length!==64||J.length!==32)return!1;if(G.length!==64||j.length!==32)return!1;let z=H.default.sign.detached.verify(Z,Y,J),N=H.default.sign.detached.verify(U,G,j);return z&&N}catch{return!1}}verifyRevokeWithWallet(Q,$){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!$)return!1;try{let Z=d({pubkey:Q.pubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Y=A.default.decode($),J=q.toBytes();if(Y.length!==64||J.length!==32)return!1;return H.default.sign.detached.verify(Z,Y,J)}catch{return!1}}verifyRevokeWithDelegation(Q,$){if(Q.chain!==l)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature||!Q.delegationProof)return!1;let Z=Q.delegationProof;if(!Z.walletPubkey||!Z.delegatedPubkey||!Z.chain||!Z.expiresAt||!Z.signature)return!1;if(Z.chain!==l)return!1;if(Q.pubkey!==Z.delegatedPubkey)return!1;if(Z.expiresAt<Date.now())return!1;try{let q=F8(Z),Y=this.normalizePubkey(Z.walletPubkey),J=A.default.decode(Z.signature),U=Y.toBytes(),K=d({pubkey:Z.delegatedPubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),G=this.normalizePubkey(Z.delegatedPubkey),j=A.default.decode($),z=G.toBytes();if(J.length!==64||U.length!==32)return!1;if(j.length!==64||z.length!==32)return!1;let N=H.default.sign.detached.verify(q,J,U),R=H.default.sign.detached.verify(K,j,z);return N&&R}catch{return!1}}static createProtocolMetaIx(Q){let $=T8(Q);return g.createMemoInstruction($)}getProtocolMeta(Q){try{let $=this.deserializeTransaction(Q);for(let Z of this.getMemoInstructions($)){let q=Z.data;try{let Y=new TextDecoder().decode(q);if(J8(Y))return Y}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let $=D.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if($.message instanceof D.MessageV0)return $;else return D.Transaction.from(Buffer.from(Q,"base64"))}catch{try{return D.Transaction.from(Buffer.from(Q,"base64"))}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return J8($)}getMemoInstructions(Q){if(Q instanceof D.Transaction)return Q.instructions.filter(($)=>$.programId.equals(g.MEMO_PROGRAM_ID));else{let Z=Q.message;if(Z instanceof D.MessageV0){let q=[];for(let Y of Z.compiledInstructions){let J=Z.staticAccountKeys[Y.programIdIndex];if(J&&J.equals(g.MEMO_PROGRAM_ID)){let U=Y.accountKeyIndexes.map((K)=>({pubkey:Z.staticAccountKeys[K],isSigner:!1,isWritable:!1}));q.push(new D.TransactionInstruction({keys:U,programId:J,data:Y.data}))}}return q}return[]}}verifyTransactionMatchesCode(Q,$){let Z=Date.now();if(Z>Q.expiresAt)throw X.expiredCode(Q.code,Q.expiresAt,Z);let q=this.parseMeta($);if(!q)throw X.missingMeta();if(q.ver!==2)throw X.metaMismatch("2",String(q.ver),"ver");let Y=u(Q.code);if(q.id!==Y)throw X.metaMismatch(Y,q.id,"id");if(q.int!==Q.pubkey)throw X.metaMismatch(Q.pubkey,q.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw X.missingMeta();let Z=$.int;if(!Z)throw X.invalidMetaFormat("Missing 'int' (intendedFor) field");let q;try{q=new D.PublicKey(Z)}catch{throw X.invalidPubkeyFormat(Z,"Invalid public key format")}let Y=this.deserializeTransaction(Q),J=[];if(Y instanceof D.Transaction){if(!Y.signatures.some((K)=>{if(!K.signature)return!1;return J.push(K.publicKey.toString()),K.publicKey.equals(q)}))throw X.transactionNotSignedByIntendedOwner(Z,J);return}if(Y instanceof D.VersionedTransaction){let U=Y.message;if(U instanceof D.MessageV0){let K=U.header.numRequiredSignatures;for(let G=0;G<K;G++){let j=U.staticAccountKeys[G];if(j){if(J.push(j.toString()),j.equals(q))return}}throw X.transactionNotSignedByIntendedOwner(Z,J)}}throw X.invalidTransactionFormat("Unsupported transaction format")}verifyMessageSignedByIntentOwner(Q,$,Z){try{let q=new TextEncoder().encode(Q),Y=A.default.decode($),U=this.normalizePubkey(Z).toBytes();if(!H.default.sign.detached.verify(q,Y,U))throw X.invalidSignature("Signature verification failed")}catch(q){if(q instanceof Error&&q.message.includes("Signature verification failed"))throw q;throw X.invalidSignature("Invalid signature format")}}static attachProtocolMeta(Q,$){if(new t().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let Y=t.createProtocolMetaIx($);try{let J=D.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof D.MessageV0){let U=J.message,K=[...U.staticAccountKeys];if(!K.some((R)=>R.equals(g.MEMO_PROGRAM_ID)))K.push(g.MEMO_PROGRAM_ID);let j={programIdIndex:K.findIndex((R)=>R.equals(g.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:Y.data},z=new D.MessageV0({header:U.header,staticAccountKeys:K,recentBlockhash:U.recentBlockhash,compiledInstructions:[...U.compiledInstructions,j],addressTableLookups:U.addressTableLookups}),N=new D.VersionedTransaction(z);return N.signatures=J.signatures,Buffer.from(N.serialize()).toString("base64")}else{let U=D.Transaction.from(Buffer.from(Q,"base64"));return U.add(Y),Buffer.from(U.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=D.Transaction.from(Buffer.from(Q,"base64"));return J.add(Y),Buffer.from(J.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}}class V0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new t,this._walletStrategy=new a(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,$,Z,q){if(!Z||!M8[Z])throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=O8($),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(Y,Z,J)}else{let Y=$,J=O8(Y.delegatedPubkey),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(Y,J,Z,U)}}async revoke(Q,$,Z,q){if(!Z||!M8[Z])throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=d({codeHash:u($.code),pubkey:$.pubkey,windowStart:$.timestamp}),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return{...$,revokeSignature:J}}else{let Y=$,J=d({codeHash:u($.code),pubkey:Y.delegationProof.delegatedPubkey,windowStart:$.timestamp}),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return{...$,revokeSignature:U}}}validate(Q,$){if(Q==="wallet"){this.walletStrategy.validateCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithWallet($))throw X.invalidSignature("Wallet signature verification failed")}else{this.delegationStrategy.validateDelegatedCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithDelegation($))throw X.invalidSignature("Delegation signature verification failed")}}}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=56A6C6A4FE4F63A164756E2164756E21
|