@actioncodes/protocol 2.0.21 → 2.0.23

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.
Files changed (89) hide show
  1. package/README.md +239 -146
  2. package/dist/adapters/SolanaAdapter.d.ts.map +1 -1
  3. package/dist/constants.d.ts +1 -1
  4. package/dist/errors.d.ts +5 -0
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/index.cjs +2 -2
  7. package/dist/index.cjs.map +6 -6
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +6 -6
  10. package/dist/utils/protocolMeta.d.ts +1 -0
  11. package/dist/utils/protocolMeta.d.ts.map +1 -1
  12. package/docs/ActionCodesProtocol/README.md +2 -2
  13. package/docs/ActionCodesProtocol/classes/ActionCodesProtocol.md +183 -33
  14. package/docs/README.md +425 -8
  15. package/docs/adapters/BaseChainAdapter/README.md +3 -4
  16. package/docs/adapters/BaseChainAdapter/classes/BaseChainAdapter.md +87 -20
  17. package/docs/adapters/BaseChainAdapter/interfaces/ChainAdapter.md +68 -12
  18. package/docs/adapters/BaseChainAdapter/type-aliases/SignFn.md +25 -0
  19. package/docs/adapters/SolanaAdapter/README.md +6 -3
  20. package/docs/adapters/SolanaAdapter/classes/SolanaAdapter.md +140 -43
  21. package/docs/adapters/SolanaAdapter/type-aliases/SolanaTransaction.md +3 -3
  22. package/docs/adapters/SolanaAdapter/variables/ADAPTER_CHAIN_NAME.md +11 -0
  23. package/docs/constants/README.md +2 -2
  24. package/docs/constants/variables/CODE_CHARSET_DIGITS.md +2 -2
  25. package/docs/constants/variables/CODE_DEFAULT_LENGTH.md +2 -2
  26. package/docs/constants/variables/CODE_MAX_LENGTH.md +2 -2
  27. package/docs/constants/variables/CODE_MIN_LENGTH.md +2 -2
  28. package/docs/constants/variables/PROTOCOL_META_MAX_BYTES.md +3 -3
  29. package/docs/constants/variables/PROTOCOL_NORMALIZATION.md +2 -2
  30. package/docs/constants/variables/SUPPORTED_CHAINS.md +9 -3
  31. package/docs/errors/README.md +4 -2
  32. package/docs/errors/classes/ExpiredCodeError.md +85 -21
  33. package/docs/errors/classes/InvalidAdapterError.md +751 -0
  34. package/docs/errors/classes/InvalidCodeFormatError.md +85 -21
  35. package/docs/errors/classes/InvalidPubkeyFormatError.md +85 -21
  36. package/docs/errors/classes/InvalidSignatureError.md +85 -21
  37. package/docs/errors/classes/MetaMismatchError.md +85 -21
  38. package/docs/errors/classes/MissingMetaError.md +85 -21
  39. package/docs/errors/classes/ProtocolError.md +75 -21
  40. package/docs/errors/classes/TransactionNotSignedByIntendedOwnerError.md +85 -21
  41. package/docs/errors/classes/TransactionNotSignedByIssuerError.md +755 -0
  42. package/docs/errors/enumerations/ProtocolErrorCode.md +39 -15
  43. package/docs/index/README.md +170 -14
  44. package/docs/modules.md +3 -3
  45. package/docs/strategy/DelegationStrategy/README.md +11 -0
  46. package/docs/strategy/DelegationStrategy/classes/DelegationStrategy.md +79 -0
  47. package/docs/strategy/WalletStrategy/README.md +2 -2
  48. package/docs/strategy/WalletStrategy/classes/WalletStrategy.md +22 -18
  49. package/docs/types/README.md +11 -3
  50. package/docs/types/interfaces/ActionCode.md +23 -26
  51. package/docs/types/interfaces/ActionCodeRevoke.md +93 -0
  52. package/docs/types/interfaces/CanonicalMessageParts.md +5 -13
  53. package/docs/types/interfaces/CanonicalRevokeMessageParts.md +33 -0
  54. package/docs/types/interfaces/CodeGenerationConfig.md +6 -6
  55. package/docs/types/interfaces/DelegatedActionCode.md +97 -0
  56. package/docs/types/interfaces/DelegatedActionCodeRevoke.md +105 -0
  57. package/docs/types/interfaces/DelegationProof.md +49 -0
  58. package/docs/types/type-aliases/Chain.md +11 -0
  59. package/docs/utils/canonical/README.md +6 -2
  60. package/docs/utils/canonical/functions/getCanonicalMessageParts.md +21 -0
  61. package/docs/utils/canonical/functions/serializeCanonical.md +3 -3
  62. package/docs/utils/canonical/functions/serializeCanonicalRevoke.md +21 -0
  63. package/docs/utils/canonical/functions/serializeDelegationProof.md +21 -0
  64. package/docs/utils/canonical/variables/CANONICAL_MESSAGE_PREFIX.md +3 -3
  65. package/docs/utils/canonical/variables/CANONICAL_MESSAGE_VERSION.md +3 -3
  66. package/docs/utils/canonical/variables/CANONICAL_REVOKE_MESSAGE_PREFIX.md +11 -0
  67. package/docs/utils/crypto/README.md +2 -3
  68. package/docs/utils/crypto/functions/base32EncodeCrockford.md +2 -2
  69. package/docs/utils/crypto/functions/codeHash.md +2 -2
  70. package/docs/utils/crypto/functions/digestToDigits.md +2 -2
  71. package/docs/utils/crypto/functions/hkdfSha256.md +2 -2
  72. package/docs/utils/crypto/functions/hmacSha256.md +2 -2
  73. package/docs/utils/crypto/functions/sha256.md +2 -2
  74. package/docs/utils/crypto/functions/truncateBits.md +2 -2
  75. package/docs/utils/protocolMeta/README.md +2 -2
  76. package/docs/utils/protocolMeta/functions/buildProtocolMeta.md +3 -3
  77. package/docs/utils/protocolMeta/functions/parseProtocolMeta.md +3 -3
  78. package/docs/utils/protocolMeta/functions/validateProtocolMetaFormat.md +3 -3
  79. package/docs/utils/protocolMeta/interfaces/ProtocolMetaFields.md +11 -3
  80. package/docs/utils/protocolMeta/variables/SCHEME.md +3 -3
  81. package/package.json +7 -7
  82. package/docs/adapters/BaseChainAdapter/interfaces/BaseContext.md +0 -17
  83. package/docs/adapters/BaseChainAdapter/type-aliases/ChainContext.md +0 -23
  84. package/docs/adapters/NodeCryptoAdapter/README.md +0 -15
  85. package/docs/adapters/NodeCryptoAdapter/classes/NodeCryptoAdapter.md +0 -254
  86. package/docs/adapters/NodeCryptoAdapter/type-aliases/NodeCryptoContext.md +0 -27
  87. package/docs/adapters/SolanaAdapter/type-aliases/SolanaContext.md +0 -27
  88. package/docs/types/interfaces/CodeGenerationResult.md +0 -25
  89. package/docs/utils/crypto/functions/generateRandomSecret.md +0 -15
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:()=>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")}}}
1
+ var I0=Object.create;var{getPrototypeOf:m0,defineProperty:o,getOwnPropertyNames:e8,getOwnPropertyDescriptor:b0}=Object,o8=Object.prototype.hasOwnProperty;var Q8=(Q,$,q)=>{q=Q!=null?I0(m0(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=b0(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:()=>E,parseProtocolMeta:()=>U8,hmacSha256:()=>v8,hkdfSha256:()=>d0,getCanonicalMessageParts:()=>w8,digestToDigits:()=>F8,codeHash:()=>A,buildProtocolMeta:()=>T8,base32EncodeCrockford:()=>l0,WalletStrategy:()=>t,TransactionNotSignedByIssuerError:()=>u8,TransactionNotSignedByIntendedOwnerError:()=>A8,SolanaAdapter:()=>e,SUPPORTED_CHAINS:()=>V8,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:()=>M8,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 S(Q,$,q=""){let Z=E0(Q),Y=Q?.length,J=$!==void 0;if(!Z||J&&Y!==$){let U=q&&`"${q}" `,K=J?` of length ${$}`:"",j=Z?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+K+", got "+j)}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,$){S(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function k(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function N8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function T(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),S(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 K=N8(Q);for(;Z<=Y-J;J+=Z)this.process(K,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,k(this.buffer.subarray(J)),this.padOffset>Z-J)this.process(q,0),J=0;for(let z=J;z<Z;z++)$[z]=0;q.setBigUint64(Z-8,BigInt(this.length*8),Y),this.process(q,0);let U=N8(Q),K=this.outputLen;if(K%4)throw Error("_sha2: outputLen must be aligned to 32bit");let j=K/4,G=this.get();if(j>G.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<j;z++)U.setUint32(4*z,G[z],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 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 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:K}=H0(Q[J],$);[Z[J],Y[J]]=[U,K]}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 I(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]),f=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:K}=this;return[Q,$,q,Z,Y,J,U,K]}set(Q,$,q,Z,Y,J,U,K){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=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],W=T(N,7)^T(N,18)^N>>>3,F=T(R,17)^T(R,19)^R>>>10;f[z]=F+f[z-7]+W+f[z-16]|0}let{A:q,B:Z,C:Y,D:J,E:U,F:K,G:j,H:G}=this;for(let z=0;z<64;z++){let N=T(U,6)^T(U,11)^T(U,25),R=G+N+Z0(U,K,j)+_0[z]+f[z]|0,F=(T(q,2)^T(q,13)^T(q,22))+Y0(q,Z,Y)|0;G=j,j=K,K=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,K=K+this.F|0,j=j+this.G|0,G=G+this.H|0,this.set(q,Z,Y,J,U,K,j,G)}roundClean(){k(f)}destroy(){this.set(0,0,0,0,0,0,0,0),k(this.buffer)}}class R0 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 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])(),C=new Uint32Array(80),p=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:K,Eh:j,El:G,Fh:z,Fl:N,Gh:R,Gl:W,Hh:F,Hl:V}=this;return[Q,$,q,Z,Y,J,U,K,j,G,z,N,R,W,F,V]}set(Q,$,q,Z,Y,J,U,K,j,G,z,N,R,W,F,V){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=K|0,this.Eh=j|0,this.El=G|0,this.Fh=z|0,this.Fl=N|0,this.Gh=R|0,this.Gl=W|0,this.Hh=F|0,this.Hl=V|0}process(Q,$){for(let D=0;D<16;D++,$+=4)C[D]=Q.getUint32($),p[D]=Q.getUint32($+=4);for(let D=16;D<80;D++){let P=C[D-15]|0,_=p[D-15]|0,m8=c(P,_,1)^c(P,_,8)^E8(P,_,7),b8=d(P,_,1)^d(P,_,8)^H8(P,_,7),m=C[D-2]|0,b=p[D-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(b8,B8,p[D-7],p[D-16]),y8=j0(K8,m8,z8,C[D-7],C[D-16]);C[D]=y8|0,p[D]=K8|0}let{Ah:q,Al:Z,Bh:Y,Bl:J,Ch:U,Cl:K,Dh:j,Dl:G,Eh:z,El:N,Fh:R,Fl:W,Gh:F,Gl:V,Hh:h,Hl:O}=this;for(let D=0;D<80;D++){let P=c(z,N,14)^c(z,N,18)^q8(z,N,41),_=d(z,N,14)^d(z,N,18)^Z8(z,N,41),m8=z&R^~z&F,b8=N&W^~N&V,m=G0(O,_,b8,C0[D],p[D]),b=N0(m,h,P,m8,f0[D],C[D]),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&K^J&K;h=F|0,O=V|0,F=R|0,V=W|0,R=z|0,W=N|0,{h:z,l:N}=I(j|0,G|0,b|0,z8|0),j=U|0,G=K|0,U=Y|0,K=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}=I(this.Ah|0,this.Al|0,q|0,Z|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:j,l:G}=I(this.Dh|0,this.Dl|0,j|0,G|0),{h:z,l:N}=I(this.Eh|0,this.El|0,z|0,N|0),{h:R,l:W}=I(this.Fh|0,this.Fl|0,R|0,W|0),{h:F,l:V}=I(this.Gh|0,this.Gl|0,F|0,V|0),{h,l:O}=I(this.Hh|0,this.Hl|0,h|0,O|0),this.set(q,Z,Y,J,U,K,j,G,z,N,R,W,F,V,h,O)}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 p0 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 A0 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 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),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 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),k(Z)}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: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 S(q,void 0,"info");let U=new Uint8Array(J*Y),K=i.create(Q,$),j=K._cloneInto(),G=new Uint8Array(K.outputLen);for(let z=0;z<J;z++)S8[0]=z+1,j.update(z===0?D0:G).update(q).update(S8).digestInto(G),U.set(G,Y*z),K._cloneInto(j);return K.destroy(),j.destroy(),k(G,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),j=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");q+=j}return q.slice(0,$)}function A(Q){let $=F0(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}var w0;((O)=>{O.EXPIRED_CODE="EXPIRED_CODE";O.INVALID_CODE="INVALID_CODE";O.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";O.INVALID_SIGNATURE="INVALID_SIGNATURE";O.MISSING_META="MISSING_META";O.INVALID_META_FORMAT="INVALID_META_FORMAT";O.META_MISMATCH="META_MISMATCH";O.META_TOO_LARGE="META_TOO_LARGE";O.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";O.TRANSACTION_NOT_SIGNED_BY_ISSUER="TRANSACTION_NOT_SIGNED_BY_ISSUER";O.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";O.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";O.INVALID_INPUT="INVALID_INPUT";O.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";O.CRYPTO_ERROR="CRYPTO_ERROR";O.INVALID_DIGEST="INVALID_DIGEST";O.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 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: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 E({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,M8=24,n0=8,s0="0123456789",V8={solana:"solana"};var k8="actioncodes:";function T8(Q){let $=M0(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 V0(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,V]=W.split("=",2);if(!F)continue;let h=V!=null?decodeURIComponent(V):"";Z.set(F,h)}let Y=Z.get("ver"),J=Z.get("id"),U=Z.get("int"),K=Z.get("iss"),j=Z.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 z;if(j!=null&&j!=="")try{if(z=JSON.parse(j),typeof z!=="object"||z===null||Array.isArray(z))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let N=M0({ver:G,id:J,int:U,iss:K,p:z});if(N.int!=null)X8(N.int);if(N.iss!=null)X8(N.iss);if(N.p!=null)X8(JSON.stringify(N.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 V0(T8(N)),N}function i0(Q){try{return U8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function M0(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 V0(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,K;try{K=n8.default.decode(q)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let j=v8(K,Z),G=Math.max(L8,Math.min(M8,this.config.codeLength)),z=8*Math.ceil(G/2),N=O8(j,z),R=F8(N,G);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=E({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(M8,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=E({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 H=Q8(require("tweetnacl")),u=Q8(require("bs58")),v=require("@solana/web3.js"),g=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 $=E({pubkey:Q.pubkey,windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Z=u.default.decode(Q.signature),Y=q.toBytes();if(Z.length!==64||Y.length!==32)return!1;return H.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=u.default.decode($.signature),J=Z.toBytes(),U=E({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),K=this.normalizePubkey($.delegatedPubkey),j=u.default.decode(Q.signature),G=K.toBytes();if(Y.length!==64||J.length!==32)return!1;if(j.length!==64||G.length!==32)return!1;let z=H.default.sign.detached.verify(q,Y,J),N=H.default.sign.detached.verify(U,j,G);return z&&N}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:A(Q.code),windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),Y=u.default.decode($),J=Z.toBytes();if(Y.length!==64||J.length!==32)return!1;return H.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=u.default.decode(q.signature),U=Y.toBytes(),K=l({pubkey:q.delegatedPubkey,codeHash:A(Q.code),windowStart:Q.timestamp}),j=this.normalizePubkey(q.delegatedPubkey),G=u.default.decode($),z=j.toBytes();if(J.length!==64||U.length!==32)return!1;if(G.length!==64||z.length!==32)return!1;let N=H.default.sign.detached.verify(Z,J,U),R=H.default.sign.detached.verify(K,G,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 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(g.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(g.MEMO_PROGRAM_ID)){let U=Y.accountKeyIndexes.map((K)=>({pubkey:q.staticAccountKeys[K],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=A(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),K=[];if(U instanceof v.Transaction){let j=!1,G=!1;if(U.signatures.forEach((z)=>{if(!z.signature)return;if(K.push(z.publicKey.toString()),z.publicKey.equals(Y))j=!0;if(Z&&z.publicKey.equals(J))G=!0}),!j)throw X.transactionNotSignedByIntendedOwner(q,K);if(Z&&!G)throw X.transactionNotSignedByIssuer(Z,K);return}if(U instanceof v.VersionedTransaction){let j=U.message;if(j instanceof v.MessageV0){let G=!1,z=!1,N=j.header.numRequiredSignatures;for(let R=0;R<N;R++){let W=j.staticAccountKeys[R];if(W){if(K.push(W.toString()),W.equals(Y))G=!0;if(Z&&W.equals(J))z=!0}}if(!G)throw X.transactionNotSignedByIntendedOwner(q,K);if(Z&&!z)throw X.transactionNotSignedByIssuer(Z,K);return}}throw X.invalidTransactionFormat("Unsupported transaction format")}verifyMessageSignedByIntentOwner(Q,$,q){try{let Z=new TextEncoder().encode(Q),Y=u.default.decode($),U=this.normalizePubkey(q).toBytes();if(!H.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 attachProtocolMeta(Q,$){if(new e().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let Y=e.createProtocolMetaIx($);try{let J=v.VersionedTransaction.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof v.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 G={programIdIndex:K.findIndex((R)=>R.equals(g.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:Y.data},z=new v.MessageV0({header:U.header,staticAccountKeys:K,recentBlockhash:U.recentBlockhash,compiledInstructions:[...U.compiledInstructions,G],addressTableLookups:U.addressTableLookups}),N=new v.VersionedTransaction(z);return N.signatures=J.signatures,Buffer.from(N.serialize()).toString("base64")}else{let U=v.Transaction.from(Buffer.from(Q,"base64"));return U.add(Y),Buffer.from(U.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=v.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 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||!V8[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||!V8[q])throw X.invalidAdapter(q);if(!Z||typeof Z!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=l({codeHash:A($.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:A($.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=56A6C6A4FE4F63A164756E2164756E21
3
+ //# debugId=34C00E87ED3CFAFB64756E2164756E21