@actioncodes/protocol 2.0.9 → 2.0.11
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/ActionCodesProtocol.d.ts +6 -6
- package/dist/ActionCodesProtocol.d.ts.map +1 -1
- package/dist/adapters/BaseChainAdapter.d.ts +30 -24
- package/dist/adapters/BaseChainAdapter.d.ts.map +1 -1
- package/dist/adapters/SolanaAdapter.d.ts +20 -9
- package/dist/adapters/SolanaAdapter.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +9 -9
- package/dist/index.js +2 -2
- package/dist/index.js.map +9 -9
- package/dist/strategy/DelegationStrategy.d.ts +12 -10
- package/dist/strategy/DelegationStrategy.d.ts.map +1 -1
- package/dist/strategy/WalletStrategy.d.ts +2 -2
- package/dist/strategy/WalletStrategy.d.ts.map +1 -1
- package/dist/types.d.ts +3 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/canonical.d.ts +3 -5
- package/dist/utils/canonical.d.ts.map +1 -1
- package/dist/utils/crypto.d.ts +0 -2
- package/dist/utils/crypto.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class W8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function P0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function Z8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let q=$&&`"${$}" `;throw Error(`${q}expected integer >= 0, got ${Q}`)}}function y(Q,$,q=""){let Z=P0(Q),J=Q?.length,Y=$!==void 0;if(!Z||Y&&J!==$){let X=q&&`"${q}" `,U=Y?` of length ${$}`:"",j=Z?`length=${J}`:`type=${typeof Q}`;throw Error(X+"expected Uint8Array"+U+", got "+j)}return Q}function c(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");Z8(Q.outputLen),Z8(Q.blockLen)}function g(Q,$=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if($&&Q.finished)throw Error("Hash#digest() has already been called")}function f8(Q,$){y(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function V(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function J8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function k(Q,$){return Q<<32-$|Q>>>$}function _8(Q,$={}){let q=(J,Y)=>Q(Y).update(J).digest(),Z=Q(void 0);return q.outputLen=Z.outputLen,q.blockLen=Z.blockLen,q.create=(J)=>Q(J),Object.assign(q,$),Object.freeze(q)}var p8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function A8(Q,$,q){return Q&$^~Q&q}function g8(Q,$,q){return Q&$^Q&q^$&q}class Y8{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=J8(this.buffer)}update(Q){g(this),y(Q);let{view:$,buffer:q,blockLen:Z}=this,J=Q.length;for(let Y=0;Y<J;){let X=Math.min(Z-this.pos,J-Y);if(X===Z){let U=J8(Q);for(;Z<=J-Y;Y+=Z)this.process(U,Y);continue}if(q.set(Q.subarray(Y,Y+X),this.pos),this.pos+=X,Y+=X,this.pos===Z)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){g(this),f8(Q,this),this.finished=!0;let{buffer:$,view:q,blockLen:Z,isLE:J}=this,{pos:Y}=this;if($[Y++]=128,V(this.buffer.subarray(Y)),this.padOffset>Z-Y)this.process(q,0),Y=0;for(let z=Y;z<Z;z++)$[z]=0;q.setBigUint64(Z-8,BigInt(this.length*8),J),this.process(q,0);let X=J8(Q),U=this.outputLen;if(U%4)throw Error("_sha2: outputLen must be aligned to 32bit");let j=U/4,N=this.get();if(j>N.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<j;z++)X.setUint32(4*z,N[z],J)}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:J,destroyed:Y,pos:X}=this;if(Q.destroyed=Y,Q.finished=J,Q.length=Z,Q.pos=X,Z%$)Q.buffer.set(q);return Q}clone(){return this._cloneInto()}}var b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),x=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]),v=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var X8=BigInt(4294967295),S8=BigInt(32);function W0(Q,$=!1){if($)return{h:Number(Q&X8),l:Number(Q>>S8&X8)};return{h:Number(Q>>S8&X8)|0,l:Number(Q&X8)|0}}function u8(Q,$=!1){let q=Q.length,Z=new Uint32Array(q),J=new Uint32Array(q);for(let Y=0;Y<q;Y++){let{h:X,l:U}=W0(Q[Y],$);[Z[Y],J[Y]]=[X,U]}return[Z,J]}var v8=(Q,$,q)=>Q>>>q,w8=(Q,$,q)=>Q<<32-q|$>>>q,_=(Q,$,q)=>Q>>>q|$<<32-q,p=(Q,$,q)=>Q<<32-q|$>>>q,n=(Q,$,q)=>Q<<64-q|$>>>q-32,s=(Q,$,q)=>Q>>>q-32|$<<64-q;function T(Q,$,q,Z){let J=($>>>0)+(Z>>>0);return{h:Q+q+(J/4294967296|0)|0,l:J|0}}var d8=(Q,$,q)=>(Q>>>0)+($>>>0)+(q>>>0),h8=(Q,$,q,Z)=>$+q+Z+(Q/4294967296|0)|0,l8=(Q,$,q,Z)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0),c8=(Q,$,q,Z,J)=>$+q+Z+J+(Q/4294967296|0)|0,n8=(Q,$,q,Z,J)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0)+(J>>>0),s8=(Q,$,q,Z,J,Y)=>$+q+Z+J+Y+(Q/4294967296|0)|0;var w0=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),C=new Uint32Array(64);class L8 extends Y8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:q,D:Z,E:J,F:Y,G:X,H:U}=this;return[Q,$,q,Z,J,Y,X,U]}set(Q,$,q,Z,J,Y,X,U){this.A=Q|0,this.B=$|0,this.C=q|0,this.D=Z|0,this.E=J|0,this.F=Y|0,this.G=X|0,this.H=U|0}process(Q,$){for(let z=0;z<16;z++,$+=4)C[z]=Q.getUint32($,!1);for(let z=16;z<64;z++){let G=C[z-15],R=C[z-2],P=k(G,7)^k(G,18)^G>>>3,D=k(R,17)^k(R,19)^R>>>10;C[z]=D+C[z-7]+P+C[z-16]|0}let{A:q,B:Z,C:J,D:Y,E:X,F:U,G:j,H:N}=this;for(let z=0;z<64;z++){let G=k(X,6)^k(X,11)^k(X,25),R=N+G+A8(X,U,j)+w0[z]+C[z]|0,D=(k(q,2)^k(q,13)^k(q,22))+g8(q,Z,J)|0;N=j,j=U,U=X,X=Y+R|0,Y=J,J=Z,Z=q,q=R+D|0}q=q+this.A|0,Z=Z+this.B|0,J=J+this.C|0,Y=Y+this.D|0,X=X+this.E|0,U=U+this.F|0,j=j+this.G|0,N=N+this.H|0,this.set(q,Z,J,Y,X,U,j,N)}roundClean(){V(C)}destroy(){this.set(0,0,0,0,0,0,0,0),V(this.buffer)}}class o8 extends L8{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 L0 extends L8{A=x[0]|0;B=x[1]|0;C=x[2]|0;D=x[3]|0;E=x[4]|0;F=x[5]|0;G=x[6]|0;H=x[7]|0;constructor(){super(28)}}var r8=(()=>u8(["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))))(),M0=(()=>r8[0])(),V0=(()=>r8[1])(),H=new Uint32Array(80),f=new Uint32Array(80);class o extends Y8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:q,Bl:Z,Ch:J,Cl:Y,Dh:X,Dl:U,Eh:j,El:N,Fh:z,Fl:G,Gh:R,Gl:P,Hh:D,Hl:M}=this;return[Q,$,q,Z,J,Y,X,U,j,N,z,G,R,P,D,M]}set(Q,$,q,Z,J,Y,X,U,j,N,z,G,R,P,D,M){this.Ah=Q|0,this.Al=$|0,this.Bh=q|0,this.Bl=Z|0,this.Ch=J|0,this.Cl=Y|0,this.Dh=X|0,this.Dl=U|0,this.Eh=j|0,this.El=N|0,this.Fh=z|0,this.Fl=G|0,this.Gh=R|0,this.Gl=P|0,this.Hh=D|0,this.Hl=M|0}process(Q,$){for(let O=0;O<16;O++,$+=4)H[O]=Q.getUint32($),f[O]=Q.getUint32($+=4);for(let O=16;O<80;O++){let B=H[O-15]|0,m=f[O-15]|0,O8=_(B,m,1)^_(B,m,8)^v8(B,m,7),F8=p(B,m,1)^p(B,m,8)^w8(B,m,7),I=H[O-2]|0,E=f[O-2]|0,$8=_(I,E,19)^n(I,E,61)^v8(I,E,6),D8=p(I,E,19)^s(I,E,61)^w8(I,E,6),q8=l8(F8,D8,f[O-7],f[O-16]),P8=c8(q8,O8,$8,H[O-7],H[O-16]);H[O]=P8|0,f[O]=q8|0}let{Ah:q,Al:Z,Bh:J,Bl:Y,Ch:X,Cl:U,Dh:j,Dl:N,Eh:z,El:G,Fh:R,Fl:P,Gh:D,Gl:M,Hh:F,Hl:l}=this;for(let O=0;O<80;O++){let B=_(z,G,14)^_(z,G,18)^n(z,G,41),m=p(z,G,14)^p(z,G,18)^s(z,G,41),O8=z&R^~z&D,F8=G&P^~G&M,I=n8(l,m,F8,V0[O],f[O]),E=s8(I,F,B,O8,M0[O],H[O]),$8=I|0,D8=_(q,Z,28)^n(q,Z,34)^n(q,Z,39),q8=p(q,Z,28)^s(q,Z,34)^s(q,Z,39),P8=q&J^q&X^J&X,D0=Z&Y^Z&U^Y&U;F=D|0,l=M|0,D=R|0,M=P|0,R=z|0,P=G|0,{h:z,l:G}=T(j|0,N|0,E|0,$8|0),j=X|0,N=U|0,X=J|0,U=Y|0,J=q|0,Y=Z|0;let H8=d8($8,q8,D0);q=h8(H8,E,D8,P8),Z=H8|0}({h:q,l:Z}=T(this.Ah|0,this.Al|0,q|0,Z|0)),{h:J,l:Y}=T(this.Bh|0,this.Bl|0,J|0,Y|0),{h:X,l:U}=T(this.Ch|0,this.Cl|0,X|0,U|0),{h:j,l:N}=T(this.Dh|0,this.Dl|0,j|0,N|0),{h:z,l:G}=T(this.Eh|0,this.El|0,z|0,G|0),{h:R,l:P}=T(this.Fh|0,this.Fl|0,R|0,P|0),{h:D,l:M}=T(this.Gh|0,this.Gl|0,D|0,M|0),{h:F,l}=T(this.Hh|0,this.Hl|0,F|0,l|0),this.set(q,Z,J,Y,X,U,j,N,z,G,R,P,D,M,F,l)}roundClean(){V(H,f)}destroy(){V(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class k0 extends o{Ah=v[0]|0;Al=v[1]|0;Bh=v[2]|0;Bl=v[3]|0;Ch=v[4]|0;Cl=v[5]|0;Dh=v[6]|0;Dl=v[7]|0;Eh=v[8]|0;El=v[9]|0;Fh=v[10]|0;Fl=v[11]|0;Gh=v[12]|0;Gl=v[13]|0;Hh=v[14]|0;Hl=v[15]|0;constructor(){super(64)}}class T0 extends o{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 w=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),L=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class I0 extends o{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(28)}}class E0 extends o{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(32)}}var U8=_8(()=>new o8,p8(1));class M8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if(c(Q),y($,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 J=0;J<Z.length;J++)Z[J]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let J=0;J<Z.length;J++)Z[J]^=106;this.oHash.update(Z),V(Z)}update(Q){return g(this),this.iHash.update(Q),this}digestInto(Q){g(this),y(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:J,blockLen:Y,outputLen:X}=this;return Q=Q,Q.finished=Z,Q.destroyed=J,Q.blockLen=Y,Q.outputLen=X,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 S=(Q,$,q)=>new M8(Q,$).update(q).digest();S.create=(Q,$)=>new M8(Q,$);function b0(Q,$,q){if(c(Q),q===void 0)q=new Uint8Array(Q.outputLen);return S(Q,q,$)}var V8=Uint8Array.of(0),i8=Uint8Array.of();function x0(Q,$,q,Z=32){c(Q),Z8(Z,"length");let J=Q.outputLen;if(Z>255*J)throw Error("Length must be <= 255*HashLen");let Y=Math.ceil(Z/J);if(q===void 0)q=i8;else y(q,void 0,"info");let X=new Uint8Array(Y*J),U=S.create(Q,$),j=U._cloneInto(),N=new Uint8Array(U.outputLen);for(let z=0;z<Y;z++)V8[0]=z+1,j.update(z===0?i8:N).update(q).update(V8).digestInto(N),X.set(N,J*z),U._cloneInto(j);return U.destroy(),j.destroy(),V(N,V8),X.slice(0,Z)}var a8=(Q,$,q,Z,J)=>x0(Q,b0(Q,$,q),Z,J);function u(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function d(Q){return U8(u(Q))}function r(Q,$){return S(U8,u(Q),u($))}function a0(Q,$,{salt:q,info:Z}={}){let J=q?u(q):new Uint8Array(32),Y=u(Q),X=Z?u(Z):new Uint8Array(0);return a8(U8,Y,J,X,$)}var e8="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function e0(Q){let $=0,q=0,Z="";for(let J=0;J<Q.length;J++){q=q<<8|Q[J],$+=8;while($>=5)Z+=e8[q>>>$-5&31],$-=5}if($>0)Z+=e8[q<<5-$&31];return Z}function k8(Q,$){let q=Math.ceil($/8),Z=new Uint8Array(q),J=Math.min(q,Q.length);Z.set(Q.subarray(0,J));let Y=q*8-$;if(Y>0){let X=255<<Y;Z[q-1]=Z[q-1]&X}return Z}function T8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let q="",Z=Q[Q.length-1]&15;for(let J=0;q.length<$;J++){let Y=(Z+J*4)%Math.max(1,Q.length-4),j=(((Q[Y]&127)<<24|Q[Y+1]<<16|Q[Y+2]<<8|Q[Y+3])%1e9).toString().padStart(9,"0");q+=j}return q.slice(0,$)}function t8(Q){let $=d(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}function t0(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}function Q0(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}var $0=1,B0="actioncodes",m0="actioncodes-revoke";function A(Q){let $=JSON.stringify({id:B0,ver:$0,pubkey:Q.pubkey,windowStart:Q.windowStart,...Q.secret&&{secret:Q.secret}});return new TextEncoder().encode($)}function q0(Q){let $=JSON.stringify({id:m0,ver:$0,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function Z0(Q,$,q=3600000,Z="solana"){let J=Date.now();return{version:"1.0",delegator:Q,delegatedPubkey:$,issuedAt:J,expiresAt:J+q,nonce:Q0(),chain:Z}}function z8(Q){let $=JSON.stringify({version:Q.version,delegator:Q.delegator,delegatedPubkey:Q.delegatedPubkey,issuedAt:Q.issuedAt,expiresAt:Q.expiresAt,nonce:Q.nonce,chain:Q.chain});return new TextEncoder().encode($)}function j8(Q){if(!Q.version||!Q.delegator||!Q.delegatedPubkey||!Q.issuedAt||!Q.expiresAt||!Q.nonce||!Q.chain||!Q.signature)return!1;if(Q.version!=="1.0")return!1;if(Q.issuedAt>=Q.expiresAt)return!1;if(Q.issuedAt>Date.now())return!1;if(Q.expiresAt<Date.now())return!1;return!0}function K8(Q,$,q){let Z=Math.floor(Date.now()/$)*$;return A({pubkey:Q,windowStart:Z,secret:q})}var I8="NFC",i=256,E8=6,b8=24,ZQ=8,JQ="0123456789",YQ=["solana"];var x8="actioncodes:";function B8(Q){let $=J0(Q);if($.int!=null)N8($.int);let q=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let J=JSON.stringify($.p);N8(J),q.push(`p=${encodeURIComponent(J)}`)}let Z=x8+q.join("&");return Y0(Z),Z}function G8(Q){if(!Q.startsWith(x8))throw Error("protocol meta must start with actioncodes:");let q=Q.slice(x8.length).split("&").filter(Boolean),Z=new Map;for(let R of q){let[P,D]=R.split("=",2);if(!P)continue;let M=D!=null?decodeURIComponent(D):"";Z.set(P,M)}let J=Z.get("ver"),Y=Z.get("id"),X=Z.get("int"),U=Z.get("p");if(J==null||Y==null||X==null)throw Error("protocol meta missing required fields ver or id or int");let j=Number(J);if(!Number.isInteger(j)||j<=0)throw Error("protocol meta ver must be positive integer");let N;if(U!=null&&U!=="")try{if(N=JSON.parse(U),typeof N!=="object"||N===null||Array.isArray(N))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let z=J0({ver:j,id:Y,int:X,p:N});if(z.int!=null)N8(z.int);if(z.p!=null)N8(JSON.stringify(z.p));if([...Z.keys()].filter((R)=>R!=="ver"&&R!=="id"&&R!=="int"&&R!=="p").length>0)throw Error("protocol meta contains unsupported keys");return Y0(B8(z)),z}function zQ(Q){try{return G8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function J0(Q){let $=Q.id.normalize(I8).trim(),q={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)q.int=Q.int.normalize(I8).trim();if(Q.p!=null)q.p=Q.p;return q}function Y0(Q){if(new TextEncoder().encode(Q).length>i)throw Error(`protocol meta exceeds ${i} bytes`)}function N8(Q){if(new TextEncoder().encode(Q).length>i)throw Error(`protocol meta params exceed ${i} bytes`)}var y0;((F)=>{F.EXPIRED_CODE="EXPIRED_CODE";F.INVALID_CODE="INVALID_CODE";F.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";F.INVALID_SIGNATURE="INVALID_SIGNATURE";F.MISSING_META="MISSING_META";F.INVALID_META_FORMAT="INVALID_META_FORMAT";F.META_MISMATCH="META_MISMATCH";F.META_TOO_LARGE="META_TOO_LARGE";F.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";F.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";F.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";F.INVALID_INPUT="INVALID_INPUT";F.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";F.CRYPTO_ERROR="CRYPTO_ERROR";F.INVALID_DIGEST="INVALID_DIGEST";F.INVALID_ADAPTER="INVALID_ADAPTER"})(y0||={});class K extends Error{code;details;constructor(Q,$,q){super($);this.code=Q;this.details=q;this.name="ProtocolError"}static expiredCode(Q,$,q){return new X0(Q,$,q)}static invalidCode(Q,$){return new K("INVALID_CODE",`Invalid code: expected '${Q}', got '${$}'`,{expected:Q,actual:$})}static invalidCodeFormat(Q,$){return new G0(Q,$)}static invalidSignature(Q){return new N0(Q)}static missingMeta(){return new U0}static invalidMetaFormat(Q){return new K("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,q){return new z0(Q,$,q)}static metaTooLarge(Q,$){return new K("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new j0(Q,$)}static invalidTransactionFormat(Q){return new K("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new K0(Q,$)}static invalidInput(Q,$,q){return new K("INVALID_INPUT",`Invalid ${Q}: ${q}`,{field:Q,value:$,reason:q})}static missingRequiredField(Q){return new K("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new K("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new K("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new R0(Q)}static create(Q,$,q){return new K(Q,$,q)}}class X0 extends K{constructor(Q,$,q){super("EXPIRED_CODE",`Action code '${Q}' expired at ${$}, current time: ${q}`,{code:Q,expiresAt:$,currentTime:q});this.name="ExpiredCodeError"}}class U0 extends K{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class z0 extends K{constructor(Q,$,q){super("META_MISMATCH",`Meta ${q} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:q});this.name="MetaMismatchError"}}class j0 extends K{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 K0 extends K{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class N0 extends K{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class G0 extends K{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class R0 extends K{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}import O0 from"bs58";class a{config;constructor(Q){this.config=Q}generateCode(Q,$,q){let Z=Q,J=JSON.parse(new TextDecoder().decode(Z)),Y=J.pubkey,X=J.windowStart,U=q,j;if($){let D=O0.decode($);j=r(D,Z)}else if(U)j=r(U,Z);else j=d(Z);let N=Math.max(E8,Math.min(b8,this.config.codeLength)),z=8*Math.ceil(N/2),G=k8(j,z);return{actionCode:{code:T8(G,N),pubkey:Y,timestamp:X,expiresAt:X+this.config.ttlMs,...$&&{signature:$},...U&&{secret:U}},canonicalMessage:Z}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw K.expiredCode(Q.code,Q.expiresAt,$);let q=A({pubkey:Q.pubkey,windowStart:Q.timestamp,secret:Q.secret}),Z;if(Q.signature){let U=O0.decode(Q.signature);Z=r(U,q)}else if(Q.secret)Z=r(Q.secret,q);else Z=d(q);let J=Math.max(E8,Math.min(b8,this.config.codeLength)),Y=k8(Z,8*Math.ceil(J/2)),X=T8(Y,J);if(X!==Q.code)throw K.invalidCode(X,Q.code)}getCanonicalMessageParts(Q,$){return K8(Q,this.config.ttlMs,$)}}class m8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new a(Q)}generateDelegatedCode(Q,$){if(!this.validateCertificateStructure(Q))throw Error("Invalid delegation certificate");let q=this.hashCertificate(Q),Z=Math.floor(Date.now()/this.config.ttlMs)*this.config.ttlMs,J=A({pubkey:Q.delegator,windowStart:Z,secret:q});return{actionCode:{...this.walletStrategy.generateCode(J,$,q).actionCode,delegationId:this.hashCertificate(Q),delegatedBy:Q.delegator,delegatedSignature:$,delegatedPubkey:Q.delegatedPubkey}}}validateDelegatedCode(Q,$){if(this.walletStrategy.validateCode(Q),!this.validateCertificateStructure($))throw Error("Delegation certificate expired or invalid");if(Q.delegationId!==this.hashCertificate($))throw Error("Action code does not match delegation certificate");if(Q.delegatedBy!==$.delegator)throw Error("Action code delegator does not match certificate");if(Q.delegatedPubkey!==$.delegatedPubkey)throw Error("Action code delegated pubkey does not match certificate");if(!Q.delegatedSignature)throw Error("Delegated signature is required")}getWalletStrategy(){return this.walletStrategy}createDelegationCertificateTemplate(Q,$,q=3600000,Z="solana"){return Z0(Q,$,q,Z)}hashCertificate(Q){let $=this.serializeCertificate(Q),q=new TextEncoder().encode(Q.signature),Z=new Uint8Array($.length+q.length);Z.set($,0),Z.set(q,$.length);let J=d(Z);return Array.from(J).map((Y)=>Y.toString(16).padStart(2,"0")).join("")}serializeCertificate(Q){return z8(Q)}validateCertificateStructure(Q){return j8(Q)}getCanonicalMessageParts(Q,$){return K8(Q,this.config.ttlMs,$)}}import y8 from"tweetnacl";import C8 from"bs58";import{PublicKey as F0,Transaction as h,VersionedTransaction as R8,TransactionInstruction as C0,MessageV0 as e}from"@solana/web3.js";import{createMemoInstruction as H0,MEMO_PROGRAM_ID as t}from"@solana/spl-memo";class Q8 extends W8{normalizePubkey(Q){if(typeof Q==="string")return new F0(Q);return Q}verifyWithWallet(Q){if(Q.chain!=="solana")return!1;if(!Q.canonicalMessageParts.pubkey||!Q.signature||!Q.canonicalMessageParts)return!1;try{let $=A(Q.canonicalMessageParts),q=this.normalizePubkey(Q.canonicalMessageParts.pubkey),Z=C8.decode(Q.signature),J=q.toBytes();if(Z.length!==64||J.length!==32)return!1;return y8.sign.detached.verify($,Z,J)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!=="solana")return!1;if(!Q.pubkey||!Q.signature||!Q.certificate)return!1;let $=Q.certificate;if(!j8($))return!1;if($.delegator!==Q.pubkey)return!1;if($.chain!==Q.chain)return!1;try{let q={version:$.version,delegator:$.delegator,delegatedPubkey:$.delegatedPubkey,issuedAt:$.issuedAt,expiresAt:$.expiresAt,nonce:$.nonce,chain:$.chain},Z=z8(q),J=this.normalizePubkey(Q.pubkey),Y=C8.decode(Q.signature),X=J.toBytes();if(Y.length!==64||X.length!==32)return!1;return y8.sign.detached.verify(Z,Y,X)}catch{return!1}}verifyRevokeWithWallet(Q){if(Q.chain!=="solana")return!1;if(!Q.canonicalRevokeMessageParts||!Q.canonicalRevokeMessageParts.pubkey||!Q.signature)return!1;try{let $=q0(Q.canonicalRevokeMessageParts),q=this.normalizePubkey(Q.canonicalRevokeMessageParts.pubkey),Z=C8.decode(Q.signature),J=q.toBytes();if(Z.length!==64||J.length!==32)return!1;return y8.sign.detached.verify($,Z,J)}catch{return!1}}static createProtocolMetaIx(Q){let $=B8(Q);return H0($)}getProtocolMeta(Q){try{let $=this.deserializeTransaction(Q);for(let q of this.getMemoInstructions($)){let Z=q.data;try{let J=new TextDecoder().decode(Z);if(G8(J))return J}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let $=R8.deserialize(Buffer.from(Q,"base64"));if($.message instanceof e)return $;else return h.from(Buffer.from(Q,"base64"))}catch{try{return h.from(Buffer.from(Q,"base64"))}catch{throw K.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return G8($)}getMemoInstructions(Q){if(Q instanceof h)return Q.instructions.filter(($)=>$.programId.equals(t));else{let q=Q.message;if(q instanceof e){let Z=[];for(let J of q.compiledInstructions){let Y=q.staticAccountKeys[J.programIdIndex];if(Y&&Y.equals(t)){let X=J.accountKeyIndexes.map((U)=>({pubkey:q.staticAccountKeys[U],isSigner:!1,isWritable:!1}));Z.push(new C0({keys:X,programId:Y,data:J.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,$){let q=Date.now();if(q>Q.expiresAt)throw K.expiredCode(Q.code,Q.expiresAt,q);let Z=this.parseMeta($);if(!Z)throw K.missingMeta();if(Z.ver!==2)throw K.metaMismatch("2",String(Z.ver),"ver");let J=t8(Q.code);if(Z.id!==J)throw K.metaMismatch(J,Z.id,"id");if(Z.int!==Q.pubkey)throw K.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw K.missingMeta();let q=$.int;if(!q)throw K.invalidMetaFormat("Missing 'int' (intendedFor) field");let Z;try{Z=new F0(q)}catch{throw K.invalidPubkeyFormat(q,"Invalid public key format")}let J=this.deserializeTransaction(Q),Y=[];if(J instanceof h){if(!J.signatures.some((U)=>{if(!U.signature)return!1;return Y.push(U.publicKey.toString()),U.publicKey.equals(Z)}))throw K.transactionNotSignedByIntendedOwner(q,Y);return}if(J instanceof R8){let X=J.message;if(X instanceof e){let U=X.header.numRequiredSignatures;for(let j=0;j<U;j++){let N=X.staticAccountKeys[j];if(N){if(Y.push(N.toString()),N.equals(Z))return}}throw K.transactionNotSignedByIntendedOwner(q,Y)}}throw K.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,$){if(new Q8().getProtocolMeta(Q))throw K.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let J=Q8.createProtocolMetaIx($);try{let Y=R8.deserialize(Buffer.from(Q,"base64"));if(Y.message instanceof e){let X=Y.message,U=[...X.staticAccountKeys];if(!U.some((R)=>R.equals(t)))U.push(t);let N={programIdIndex:U.findIndex((R)=>R.equals(t)),accountKeyIndexes:[],data:J.data},z=new e({header:X.header,staticAccountKeys:U,recentBlockhash:X.recentBlockhash,compiledInstructions:[...X.compiledInstructions,N],addressTableLookups:X.addressTableLookups}),G=new R8(z);return G.signatures=Y.signatures,Buffer.from(G.serialize()).toString("base64")}else{let X=h.from(Buffer.from(Q,"base64"));return X.add(J),Buffer.from(X.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let Y=h.from(Buffer.from(Q,"base64"));return Y.add(J),Buffer.from(Y.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw K.invalidTransactionFormat("Invalid base64 transaction format")}}}}class f0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new Q8,this._walletStrategy=new a(Q),this._delegationStrategy=new m8(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}generateCode(Q,$,q,Z){if(Q==="wallet"){if(!q)throw K.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode($,q,Z)}else{if(!q)throw K.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode($,q)}}validateCode(Q,$,q){if(Q==="wallet"){if(this.walletStrategy.validateCode($),!q)return;let Z=q,J=this.getAdapter(Z.chain);if(!J)throw K.invalidAdapter(Z.chain);if(!J.verifyWithWallet({...Z,canonicalMessageParts:{pubkey:$.pubkey,windowStart:$.timestamp}}))throw Error("Signature verification failed")}else{let Z=q;this.delegationStrategy.validateDelegatedCode($,Z);let J=this.getAdapter(Z.chain);if(!J)throw K.invalidAdapter(Z.chain);if(!J.verifyWithDelegation({chain:Z.chain,pubkey:Z.delegator,signature:Z.signature,certificate:Z}))throw Error("Signature verification failed")}}}export{zQ as validateProtocolMetaFormat,j8 as validateCertificateStructure,k8 as truncateBits,d as sha256,z8 as serializeCertificate,q0 as serializeCanonicalRevoke,A as serializeCanonical,G8 as parseProtocolMeta,r as hmacSha256,a0 as hkdfSha256,K8 as getCanonicalMessageParts,t0 as generateRandomSecret,Q0 as generateNonce,T8 as digestToDigits,Z0 as createDelegationCertificateTemplate,t8 as codeHash,B8 as buildProtocolMeta,e0 as base32EncodeCrockford,a as WalletStrategy,j0 as TransactionNotSignedByIntendedOwnerError,Q8 as SolanaAdapter,YQ as SUPPORTED_CHAINS,x8 as SCHEME,y0 as ProtocolErrorCode,K as ProtocolError,I8 as PROTOCOL_NORMALIZATION,i as PROTOCOL_META_MAX_BYTES,U0 as MissingMetaError,z0 as MetaMismatchError,N0 as InvalidSignatureError,K0 as InvalidPubkeyFormatError,G0 as InvalidCodeFormatError,R0 as InvalidAdapterError,X0 as ExpiredCodeError,m8 as DelegationStrategy,E8 as CODE_MIN_LENGTH,b8 as CODE_MAX_LENGTH,ZQ as CODE_DEFAULT_LENGTH,JQ as CODE_CHARSET_DIGITS,m0 as CANONICAL_REVOKE_MESSAGE_PREFIX,$0 as CANONICAL_MESSAGE_VERSION,B0 as CANONICAL_MESSAGE_PREFIX,W8 as BaseChainAdapter,f0 as ActionCodesProtocol};
|
1
|
+
class G8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function O0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function J8(Q,X=""){if(!Number.isSafeInteger(Q)||Q<0){let $=X&&`"${X}" `;throw Error(`${$}expected integer >= 0, got ${Q}`)}}function B(Q,X,$=""){let Z=O0(Q),q=Q?.length,J=X!==void 0;if(!Z||J&&q!==X){let R=$&&`"${$}" `,N=J?` of length ${X}`:"",U=Z?`length=${q}`:`type=${typeof Q}`;throw Error(R+"expected Uint8Array"+N+", got "+U)}return Q}function s(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");J8(Q.outputLen),J8(Q.blockLen)}function A(Q,X=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if(X&&Q.finished)throw Error("Hash#digest() has already been called")}function S8(Q,X){B(Q,void 0,"digestInto() output");let $=X.outputLen;if(Q.length<$)throw Error('"digestInto() output" expected to be of length >='+$)}function V(...Q){for(let X=0;X<Q.length;X++)Q[X].fill(0)}function R8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function T(Q,X){return Q<<32-X|Q>>>X}function H8(Q,X={}){let $=(q,J)=>Q(J).update(q).digest(),Z=Q(void 0);return $.outputLen=Z.outputLen,$.blockLen=Z.blockLen,$.create=(q)=>Q(q),Object.assign($,X),Object.freeze($)}var _8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function f8(Q,X,$){return Q&X^~Q&$}function A8(Q,X,$){return Q&X^Q&$^X&$}class Y8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,X,$,Z){this.blockLen=Q,this.outputLen=X,this.padOffset=$,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=R8(this.buffer)}update(Q){A(this),B(Q);let{view:X,buffer:$,blockLen:Z}=this,q=Q.length;for(let J=0;J<q;){let R=Math.min(Z-this.pos,q-J);if(R===Z){let N=R8(Q);for(;Z<=q-J;J+=Z)this.process(N,J);continue}if($.set(Q.subarray(J,J+R),this.pos),this.pos+=R,J+=R,this.pos===Z)this.process(X,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){A(this),S8(Q,this),this.finished=!0;let{buffer:X,view:$,blockLen:Z,isLE:q}=this,{pos:J}=this;if(X[J++]=128,V(this.buffer.subarray(J)),this.padOffset>Z-J)this.process($,0),J=0;for(let Y=J;Y<Z;Y++)X[Y]=0;$.setBigUint64(Z-8,BigInt(this.length*8),q),this.process($,0);let R=R8(Q),N=this.outputLen;if(N%4)throw Error("_sha2: outputLen must be aligned to 32bit");let U=N/4,j=this.get();if(U>j.length)throw Error("_sha2: outputLen bigger than state");for(let Y=0;Y<U;Y++)R.setUint32(4*Y,j[Y],q)}digest(){let{buffer:Q,outputLen:X}=this;this.digestInto(Q);let $=Q.slice(0,X);return this.destroy(),$}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:X,buffer:$,length:Z,finished:q,destroyed:J,pos:R}=this;if(Q.destroyed=J,Q.finished=q,Q.length=Z,Q.pos=R,Z%X)Q.buffer.set($);return Q}clone(){return this._cloneInto()}}var x=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),G=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),F=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var N8=BigInt(4294967295),u8=BigInt(32);function W0(Q,X=!1){if(X)return{h:Number(Q&N8),l:Number(Q>>u8&N8)};return{h:Number(Q>>u8&N8)|0,l:Number(Q&N8)|0}}function g8(Q,X=!1){let $=Q.length,Z=new Uint32Array($),q=new Uint32Array($);for(let J=0;J<$;J++){let{h:R,l:N}=W0(Q[J],X);[Z[J],q[J]]=[R,N]}return[Z,q]}var F8=(Q,X,$)=>Q>>>$,w8=(Q,X,$)=>Q<<32-$|X>>>$,H=(Q,X,$)=>Q>>>$|X<<32-$,_=(Q,X,$)=>Q<<32-$|X>>>$,i=(Q,X,$)=>Q<<64-$|X>>>$-32,r=(Q,X,$)=>Q>>>$-32|X<<64-$;function I(Q,X,$,Z){let q=(X>>>0)+(Z>>>0);return{h:Q+$+(q/4294967296|0)|0,l:q|0}}var c8=(Q,X,$)=>(Q>>>0)+(X>>>0)+($>>>0),h8=(Q,X,$,Z)=>X+$+Z+(Q/4294967296|0)|0,d8=(Q,X,$,Z)=>(Q>>>0)+(X>>>0)+($>>>0)+(Z>>>0),n8=(Q,X,$,Z,q)=>X+$+Z+q+(Q/4294967296|0)|0,l8=(Q,X,$,Z,q)=>(Q>>>0)+(X>>>0)+($>>>0)+(Z>>>0)+(q>>>0),s8=(Q,X,$,Z,q,J)=>X+$+Z+q+J+(Q/4294967296|0)|0;var G0=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]),P=new Uint32Array(64);class k8 extends Y8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:X,C:$,D:Z,E:q,F:J,G:R,H:N}=this;return[Q,X,$,Z,q,J,R,N]}set(Q,X,$,Z,q,J,R,N){this.A=Q|0,this.B=X|0,this.C=$|0,this.D=Z|0,this.E=q|0,this.F=J|0,this.G=R|0,this.H=N|0}process(Q,X){for(let Y=0;Y<16;Y++,X+=4)P[Y]=Q.getUint32(X,!1);for(let Y=16;Y<64;Y++){let v=P[Y-15],K=P[Y-2],w=T(v,7)^T(v,18)^v>>>3,D=T(K,17)^T(K,19)^K>>>10;P[Y]=D+P[Y-7]+w+P[Y-16]|0}let{A:$,B:Z,C:q,D:J,E:R,F:N,G:U,H:j}=this;for(let Y=0;Y<64;Y++){let v=T(R,6)^T(R,11)^T(R,25),K=j+v+f8(R,N,U)+G0[Y]+P[Y]|0,D=(T($,2)^T($,13)^T($,22))+A8($,Z,q)|0;j=U,U=N,N=R,R=J+K|0,J=q,q=Z,Z=$,$=K+D|0}$=$+this.A|0,Z=Z+this.B|0,q=q+this.C|0,J=J+this.D|0,R=R+this.E|0,N=N+this.F|0,U=U+this.G|0,j=j+this.H|0,this.set($,Z,q,J,R,N,U,j)}roundClean(){V(P)}destroy(){this.set(0,0,0,0,0,0,0,0),V(this.buffer)}}class i8 extends k8{A=x[0]|0;B=x[1]|0;C=x[2]|0;D=x[3]|0;E=x[4]|0;F=x[5]|0;G=x[6]|0;H=x[7]|0;constructor(){super(32)}}class F0 extends k8{A=E[0]|0;B=E[1]|0;C=E[2]|0;D=E[3]|0;E=E[4]|0;F=E[5]|0;G=E[6]|0;H=E[7]|0;constructor(){super(28)}}var r8=(()=>g8(["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))))(),w0=(()=>r8[0])(),k0=(()=>r8[1])(),p=new Uint32Array(80),S=new Uint32Array(80);class a extends Y8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:X,Bh:$,Bl:Z,Ch:q,Cl:J,Dh:R,Dl:N,Eh:U,El:j,Fh:Y,Fl:v,Gh:K,Gl:w,Hh:D,Hl:L}=this;return[Q,X,$,Z,q,J,R,N,U,j,Y,v,K,w,D,L]}set(Q,X,$,Z,q,J,R,N,U,j,Y,v,K,w,D,L){this.Ah=Q|0,this.Al=X|0,this.Bh=$|0,this.Bl=Z|0,this.Ch=q|0,this.Cl=J|0,this.Dh=R|0,this.Dl=N|0,this.Eh=U|0,this.El=j|0,this.Fh=Y|0,this.Fl=v|0,this.Gh=K|0,this.Gl=w|0,this.Hh=D|0,this.Hl=L|0}process(Q,X){for(let O=0;O<16;O++,X+=4)p[O]=Q.getUint32(X),S[O]=Q.getUint32(X+=4);for(let O=16;O<80;O++){let y=p[O-15]|0,m=S[O-15]|0,K8=H(y,m,1)^H(y,m,8)^F8(y,m,7),O8=_(y,m,1)^_(y,m,8)^w8(y,m,7),b=p[O-2]|0,C=S[O-2]|0,Z8=H(b,C,19)^i(b,C,61)^F8(b,C,6),W8=_(b,C,19)^r(b,C,61)^w8(b,C,6),q8=d8(O8,W8,S[O-7],S[O-16]),D8=n8(q8,K8,Z8,p[O-7],p[O-16]);p[O]=D8|0,S[O]=q8|0}let{Ah:$,Al:Z,Bh:q,Bl:J,Ch:R,Cl:N,Dh:U,Dl:j,Eh:Y,El:v,Fh:K,Fl:w,Gh:D,Gl:L,Hh:W,Hl:l}=this;for(let O=0;O<80;O++){let y=H(Y,v,14)^H(Y,v,18)^i(Y,v,41),m=_(Y,v,14)^_(Y,v,18)^r(Y,v,41),K8=Y&K^~Y&D,O8=v&w^~v&L,b=l8(l,m,O8,k0[O],S[O]),C=s8(b,W,y,K8,w0[O],p[O]),Z8=b|0,W8=H($,Z,28)^i($,Z,34)^i($,Z,39),q8=_($,Z,28)^r($,Z,34)^r($,Z,39),D8=$&q^$&R^q&R,K0=Z&J^Z&N^J&N;W=D|0,l=L|0,D=K|0,L=w|0,K=Y|0,w=v|0,{h:Y,l:v}=I(U|0,j|0,C|0,Z8|0),U=R|0,j=N|0,R=q|0,N=J|0,q=$|0,J=Z|0;let p8=c8(Z8,q8,K0);$=h8(p8,C,W8,D8),Z=p8|0}({h:$,l:Z}=I(this.Ah|0,this.Al|0,$|0,Z|0)),{h:q,l:J}=I(this.Bh|0,this.Bl|0,q|0,J|0),{h:R,l:N}=I(this.Ch|0,this.Cl|0,R|0,N|0),{h:U,l:j}=I(this.Dh|0,this.Dl|0,U|0,j|0),{h:Y,l:v}=I(this.Eh|0,this.El|0,Y|0,v|0),{h:K,l:w}=I(this.Fh|0,this.Fl|0,K|0,w|0),{h:D,l:L}=I(this.Gh|0,this.Gl|0,D|0,L|0),{h:W,l}=I(this.Hh|0,this.Hl|0,W|0,l|0),this.set($,Z,q,J,R,N,U,j,Y,v,K,w,D,L,W,l)}roundClean(){V(p,S)}destroy(){V(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class M0 extends a{Ah=F[0]|0;Al=F[1]|0;Bh=F[2]|0;Bl=F[3]|0;Ch=F[4]|0;Cl=F[5]|0;Dh=F[6]|0;Dl=F[7]|0;Eh=F[8]|0;El=F[9]|0;Fh=F[10]|0;Fl=F[11]|0;Gh=F[12]|0;Gl=F[13]|0;Hh=F[14]|0;Hl=F[15]|0;constructor(){super(64)}}class L0 extends a{Ah=G[0]|0;Al=G[1]|0;Bh=G[2]|0;Bl=G[3]|0;Ch=G[4]|0;Cl=G[5]|0;Dh=G[6]|0;Dl=G[7]|0;Eh=G[8]|0;El=G[9]|0;Fh=G[10]|0;Fl=G[11]|0;Gh=G[12]|0;Gl=G[13]|0;Hh=G[14]|0;Hl=G[15]|0;constructor(){super(48)}}var k=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 V0 extends a{Ah=k[0]|0;Al=k[1]|0;Bh=k[2]|0;Bl=k[3]|0;Ch=k[4]|0;Cl=k[5]|0;Dh=k[6]|0;Dl=k[7]|0;Eh=k[8]|0;El=k[9]|0;Fh=k[10]|0;Fl=k[11]|0;Gh=k[12]|0;Gl=k[13]|0;Hh=k[14]|0;Hl=k[15]|0;constructor(){super(28)}}class T0 extends a{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 z8=H8(()=>new i8,_8(1));class M8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,X){if(s(Q),B(X,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 $=this.blockLen,Z=new Uint8Array($);Z.set(X.length>$?Q.create().update(X).digest():X);for(let q=0;q<Z.length;q++)Z[q]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let q=0;q<Z.length;q++)Z[q]^=106;this.oHash.update(Z),V(Z)}update(Q){return A(this),this.iHash.update(Q),this}digestInto(Q){A(this),B(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:X,iHash:$,finished:Z,destroyed:q,blockLen:J,outputLen:R}=this;return Q=Q,Q.finished=Z,Q.destroyed=q,Q.blockLen=J,Q.outputLen=R,Q.oHash=X._cloneInto(Q.oHash),Q.iHash=$._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var u=(Q,X,$)=>new M8(Q,X).update($).digest();u.create=(Q,X)=>new M8(Q,X);function I0(Q,X,$){if(s(Q),$===void 0)$=new Uint8Array(Q.outputLen);return u(Q,$,X)}var L8=Uint8Array.of(0),a8=Uint8Array.of();function b0(Q,X,$,Z=32){s(Q),J8(Z,"length");let q=Q.outputLen;if(Z>255*q)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/q);if($===void 0)$=a8;else B($,void 0,"info");let R=new Uint8Array(J*q),N=u.create(Q,X),U=N._cloneInto(),j=new Uint8Array(N.outputLen);for(let Y=0;Y<J;Y++)L8[0]=Y+1,U.update(Y===0?a8:j).update($).update(L8).digestInto(j),R.set(j,q*Y),N._cloneInto(U);return N.destroy(),U.destroy(),V(j,L8),R.slice(0,Z)}var e8=(Q,X,$,Z,q)=>b0(Q,I0(Q,X,$),Z,q);function g(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function C0(Q){return z8(g(Q))}function V8(Q,X){return u(z8,g(Q),g(X))}function s0(Q,X,{salt:$,info:Z}={}){let q=$?g($):new Uint8Array(32),J=g(Q),R=Z?g(Z):new Uint8Array(0);return e8(z8,J,q,R,X)}var t8="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function i0(Q){let X=0,$=0,Z="";for(let q=0;q<Q.length;q++){$=$<<8|Q[q],X+=8;while(X>=5)Z+=t8[$>>>X-5&31],X-=5}if(X>0)Z+=t8[$<<5-X&31];return Z}function T8(Q,X){let $=Math.ceil(X/8),Z=new Uint8Array($),q=Math.min($,Q.length);Z.set(Q.subarray(0,q));let J=$*8-X;if(J>0){let R=255<<J;Z[$-1]=Z[$-1]&R}return Z}function I8(Q,X){if(Q.length===0)throw Error("digestToDigits: empty digest");let $="",Z=Q[Q.length-1]&15;for(let q=0;$.length<X;q++){let J=(Z+q*4)%Math.max(1,Q.length-4),U=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");$+=U}return $.slice(0,X)}function o8(Q){let X=C0(Q);return Array.from(X).map(($)=>$.toString(16).padStart(2,"0")).join("")}var a0=1,e0="actioncodes",t0="actioncodes-revoke";function c(Q){let X=JSON.stringify({id:"actioncodes",ver:1,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode(X)}function b8(Q){let X=JSON.stringify({id:"actioncodes-revoke",ver:1,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode(X)}function e(Q,X){let $=Math.floor(Date.now()/X)*X;return c({pubkey:Q,windowStart:$})}function C8(Q){let X=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(X)}var x8="NFC",t=256,E8=6,y8=24,QQ=8,XQ="0123456789",$Q=["solana"];var m8="actioncodes:";function B8(Q){let X=Q0(Q);if(X.int!=null)U8(X.int);let $=[`ver=${X.ver}`,`id=${encodeURIComponent(X.id)}`,`int=${encodeURIComponent(X.int)}`];if(X.p!=null&&Object.keys(X.p).length>0){let q=JSON.stringify(X.p);U8(q),$.push(`p=${encodeURIComponent(q)}`)}let Z=m8+$.join("&");return X0(Z),Z}function j8(Q){if(!Q.startsWith(m8))throw Error("protocol meta must start with actioncodes:");let $=Q.slice(m8.length).split("&").filter(Boolean),Z=new Map;for(let K of $){let[w,D]=K.split("=",2);if(!w)continue;let L=D!=null?decodeURIComponent(D):"";Z.set(w,L)}let q=Z.get("ver"),J=Z.get("id"),R=Z.get("int"),N=Z.get("p");if(q==null||J==null||R==null)throw Error("protocol meta missing required fields ver or id or int");let U=Number(q);if(!Number.isInteger(U)||U<=0)throw Error("protocol meta ver must be positive integer");let j;if(N!=null&&N!=="")try{if(j=JSON.parse(N),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 Y=Q0({ver:U,id:J,int:R,p:j});if(Y.int!=null)U8(Y.int);if(Y.p!=null)U8(JSON.stringify(Y.p));if([...Z.keys()].filter((K)=>K!=="ver"&&K!=="id"&&K!=="int"&&K!=="p").length>0)throw Error("protocol meta contains unsupported keys");return X0(B8(Y)),Y}function JQ(Q){try{return j8(Q),{ok:!0}}catch(X){return{ok:!1,reason:String(X)}}}function Q0(Q){let X=Q.id.normalize(x8).trim(),$={ver:Q.ver,id:X,int:Q.int};if(Q.int!=null)$.int=Q.int.normalize(x8).trim();if(Q.p!=null)$.p=Q.p;return $}function X0(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta exceeds ${t} bytes`)}function U8(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta params exceed ${t} bytes`)}var x0;((W)=>{W.EXPIRED_CODE="EXPIRED_CODE";W.INVALID_CODE="INVALID_CODE";W.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";W.INVALID_SIGNATURE="INVALID_SIGNATURE";W.MISSING_META="MISSING_META";W.INVALID_META_FORMAT="INVALID_META_FORMAT";W.META_MISMATCH="META_MISMATCH";W.META_TOO_LARGE="META_TOO_LARGE";W.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";W.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";W.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";W.INVALID_INPUT="INVALID_INPUT";W.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";W.CRYPTO_ERROR="CRYPTO_ERROR";W.INVALID_DIGEST="INVALID_DIGEST";W.INVALID_ADAPTER="INVALID_ADAPTER"})(x0||={});class z extends Error{code;details;constructor(Q,X,$){super(X);this.code=Q;this.details=$;this.name="ProtocolError"}static expiredCode(Q,X,$){return new $0(Q,X,$)}static invalidCode(Q,X){return new z("INVALID_CODE",`Invalid code: expected '${Q}', got '${X}'`,{expected:Q,actual:X})}static invalidCodeFormat(Q,X){return new N0(Q,X)}static invalidSignature(Q){return new Y0(Q)}static missingMeta(){return new Z0}static invalidMetaFormat(Q){return new z("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,X,$){return new q0(Q,X,$)}static metaTooLarge(Q,X){return new z("META_TOO_LARGE",`Protocol meta too large: ${X} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:X})}static transactionNotSignedByIntendedOwner(Q,X){return new J0(Q,X)}static invalidTransactionFormat(Q){return new z("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,X){return new R0(Q,X)}static invalidInput(Q,X,$){return new z("INVALID_INPUT",`Invalid ${Q}: ${$}`,{field:Q,value:X,reason:$})}static missingRequiredField(Q){return new z("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,X){return new z("CRYPTO_ERROR",`Crypto error in ${Q}: ${X}`,{operation:Q,reason:X})}static invalidDigest(Q){return new z("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new z0(Q)}static create(Q,X,$){return new z(Q,X,$)}}class $0 extends z{constructor(Q,X,$){super("EXPIRED_CODE",`Action code '${Q}' expired at ${X}, current time: ${$}`,{code:Q,expiresAt:X,currentTime:$});this.name="ExpiredCodeError"}}class Z0 extends z{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class q0 extends z{constructor(Q,X,$){super("META_MISMATCH",`Meta ${$} mismatch: expected '${Q}', got '${X}'`,{expected:Q,actual:X,field:$});this.name="MetaMismatchError"}}class J0 extends z{constructor(Q,X){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${X.join(", ")}]`,{intended:Q,actualSigners:X});this.name="TransactionNotSignedByIntendedOwnerError"}}class R0 extends z{constructor(Q,X){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${X}`,{pubkey:Q,reason:X});this.name="InvalidPubkeyFormatError"}}class Y0 extends z{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class N0 extends z{constructor(Q,X){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${X}`,{code:Q,reason:X});this.name="InvalidCodeFormatError"}}class z0 extends z{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}import U0 from"bs58";class o{config;constructor(Q){this.config=Q}generateCode(Q,X){let $=Q,Z=JSON.parse(new TextDecoder().decode($)),q=Z.pubkey,J=Z.windowStart,R=U0.decode(X),N=V8(R,$),U=Math.max(E8,Math.min(y8,this.config.codeLength)),j=8*Math.ceil(U/2),Y=T8(N,j);return{actionCode:{code:I8(Y,U),pubkey:q,timestamp:J,expiresAt:J+this.config.ttlMs,signature:X},canonicalMessage:$}}validateCode(Q){let X=Date.now();if(X>Q.expiresAt+(this.config.clockSkewMs??0))throw z.expiredCode(Q.code,Q.expiresAt,X);let $=c({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw z.missingRequiredField("signature");let Z=U0.decode(Q.signature),q=V8(Z,$),J=Math.max(E8,Math.min(y8,this.config.codeLength)),R=T8(q,8*Math.ceil(J/2)),N=I8(R,J);if(N!==Q.code)throw z.invalidCode(N,Q.code)}getCanonicalMessageParts(Q){return e(Q,this.config.ttlMs)}}import{PublicKey as j0}from"@solana/web3.js";class P8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new o(Q)}generateDelegatedCode(Q,X){this.validateDelegationProof(Q);let $=e(Q.delegatedPubkey,this.config.ttlMs);return{actionCode:{...this.walletStrategy.generateCode($,X).actionCode,delegationProof:Q,delegatedSignature:X}}}validateDelegatedCode(Q,X){if(this.walletStrategy.validateCode(Q),this.validateDelegationProof(X),Q.delegationProof.walletPubkey!==X.walletPubkey)throw z.invalidInput("walletPubkey",Q.delegationProof.walletPubkey,"Action code wallet pubkey does not match delegation proof");if(Q.delegationProof.delegatedPubkey!==X.delegatedPubkey)throw z.invalidInput("delegatedPubkey",Q.delegationProof.delegatedPubkey,"Invalid delegatedPubkey: Action code delegated pubkey does not match delegation proof");if(Q.delegationProof.expiresAt!==X.expiresAt)throw z.invalidInput("expiresAt",Q.delegationProof.expiresAt,"Action code delegation expiration does not match delegation proof");if(Q.delegationProof.signature!==X.signature)throw z.invalidInput("signature",Q.delegationProof.signature,"Invalid signature: Action code delegation signature does not match delegation proof");if(!Q.delegatedSignature)throw z.missingRequiredField("delegatedSignature")}validateDelegationProof(Q){if(!Q.walletPubkey||typeof Q.walletPubkey!=="string")throw z.invalidInput("walletPubkey",Q.walletPubkey,"Wallet pubkey is required and must be a string");try{new j0(Q.walletPubkey)}catch{throw z.invalidInput("walletPubkey",Q.walletPubkey,"Invalid wallet pubkey format")}if(!Q.delegatedPubkey||typeof Q.delegatedPubkey!=="string")throw z.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Delegated pubkey is required and must be a string");try{new j0(Q.delegatedPubkey)}catch{throw z.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Invalid delegated pubkey format")}if(!Q.chain||typeof Q.chain!=="string")throw z.invalidInput("chain",Q.chain,"Chain is required and must be a string");if(Q.chain.length===0||Q.chain.length>50)throw z.invalidInput("chain",Q.chain,"Chain must be between 1 and 50 characters");if(!/^[a-z0-9-]+$/.test(Q.chain))throw z.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 z.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be a valid integer timestamp");if(Q.expiresAt<=0)throw z.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be positive");let X=Date.now(),$=31536000000;if(Q.expiresAt>X+$)throw z.invalidInput("expiresAt",Q.expiresAt,"Expiration time is too far in the future");if(Q.expiresAt<X)throw z.expiredCode("Delegation proof has expired",Q.expiresAt,X);if(!Q.signature||typeof Q.signature!=="string")throw z.invalidInput("signature",Q.signature,"Delegation signature is required and must be a string");if(Q.signature.length===0||Q.signature.length>200)throw z.invalidInput("signature",Q.signature,"Delegation signature must be between 1 and 200 characters")}getWalletStrategy(){return this.walletStrategy}getCanonicalMessageParts(Q){return e(Q,this.config.ttlMs)}}import f from"tweetnacl";import h from"bs58";import{PublicKey as v0,Transaction as d,VersionedTransaction as v8,TransactionInstruction as E0,MessageV0 as Q8}from"@solana/web3.js";import{createMemoInstruction as y0,MEMO_PROGRAM_ID as X8}from"@solana/spl-memo";var n="solana";class $8 extends G8{normalizePubkey(Q){if(typeof Q==="string")return new v0(Q);return Q}verifyWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.walletSignature)return!1;try{let X=c(Q.message),$=this.normalizePubkey(Q.message.pubkey),Z=h.decode(Q.walletSignature),q=$.toBytes();if(Z.length!==64||q.length!==32)return!1;return f.sign.detached.verify(X,Z,q)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.message.pubkey||!Q.delegatedSignature||!Q.delegationProof)return!1;let X=Q.delegationProof;if(!X.walletPubkey||!X.delegatedPubkey||!X.chain||!X.expiresAt||!X.signature)return!1;if(X.chain!==n)return!1;if(X.delegatedPubkey!==Q.message.pubkey)return!1;if(X.expiresAt<Date.now())return!1;try{let $=C8(X),Z=this.normalizePubkey(X.walletPubkey),q=h.decode(X.signature),J=Z.toBytes(),R=c(Q.message),N=this.normalizePubkey(X.delegatedPubkey),U=h.decode(Q.delegatedSignature),j=N.toBytes();if(q.length!==64||J.length!==32)return!1;if(U.length!==64||j.length!==32)return!1;let Y=f.sign.detached.verify($,q,J),v=f.sign.detached.verify(R,U,j);return Y&&v}catch{return!1}}verifyRevokeWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.walletSignature)return!1;try{let X=b8(Q.message),$=this.normalizePubkey(Q.message.pubkey),Z=h.decode(Q.walletSignature),q=$.toBytes();if(Z.length!==64||q.length!==32)return!1;return f.sign.detached.verify(X,Z,q)}catch{return!1}}verifyRevokeWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.delegatedSignature||!Q.delegationProof)return!1;let X=Q.delegationProof;if(!X.walletPubkey||!X.delegatedPubkey||!X.chain||!X.expiresAt||!X.signature)return!1;if(X.chain!==n)return!1;if(X.delegatedPubkey!==Q.message.pubkey)return!1;if(X.expiresAt<Date.now())return!1;try{let $=C8(X),Z=this.normalizePubkey(X.walletPubkey),q=h.decode(X.signature),J=Z.toBytes();if(q.length!==64||J.length!==32)return!1;if(!f.sign.detached.verify($,q,J))return!1;let N=b8(Q.message),U=this.normalizePubkey(X.delegatedPubkey),j=h.decode(Q.delegatedSignature),Y=U.toBytes();if(j.length!==64||Y.length!==32)return!1;return f.sign.detached.verify(N,j,Y)}catch{return!1}}static createProtocolMetaIx(Q){let X=B8(Q);return y0(X)}getProtocolMeta(Q){try{let X=this.deserializeTransaction(Q);for(let $ of this.getMemoInstructions(X)){let Z=$.data;try{let q=new TextDecoder().decode(Z);if(j8(q))return q}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let X=v8.deserialize(Buffer.from(Q,"base64"));if(X.message instanceof Q8)return X;else return d.from(Buffer.from(Q,"base64"))}catch{try{return d.from(Buffer.from(Q,"base64"))}catch{throw z.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let X=this.getProtocolMeta(Q);if(!X)return null;return j8(X)}getMemoInstructions(Q){if(Q instanceof d)return Q.instructions.filter((X)=>X.programId.equals(X8));else{let $=Q.message;if($ instanceof Q8){let Z=[];for(let q of $.compiledInstructions){let J=$.staticAccountKeys[q.programIdIndex];if(J&&J.equals(X8)){let R=q.accountKeyIndexes.map((N)=>({pubkey:$.staticAccountKeys[N],isSigner:!1,isWritable:!1}));Z.push(new E0({keys:R,programId:J,data:q.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,X){let $=Date.now();if($>Q.expiresAt)throw z.expiredCode(Q.code,Q.expiresAt,$);let Z=this.parseMeta(X);if(!Z)throw z.missingMeta();if(Z.ver!==2)throw z.metaMismatch("2",String(Z.ver),"ver");let q=o8(Q.code);if(Z.id!==q)throw z.metaMismatch(q,Z.id,"id");if(Z.int!==Q.pubkey)throw z.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let X=this.parseMeta(Q);if(!X)throw z.missingMeta();let $=X.int;if(!$)throw z.invalidMetaFormat("Missing 'int' (intendedFor) field");let Z;try{Z=new v0($)}catch{throw z.invalidPubkeyFormat($,"Invalid public key format")}let q=this.deserializeTransaction(Q),J=[];if(q instanceof d){if(!q.signatures.some((N)=>{if(!N.signature)return!1;return J.push(N.publicKey.toString()),N.publicKey.equals(Z)}))throw z.transactionNotSignedByIntendedOwner($,J);return}if(q instanceof v8){let R=q.message;if(R instanceof Q8){let N=R.header.numRequiredSignatures;for(let U=0;U<N;U++){let j=R.staticAccountKeys[U];if(j){if(J.push(j.toString()),j.equals(Z))return}}throw z.transactionNotSignedByIntendedOwner($,J)}}throw z.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,X){if(new $8().getProtocolMeta(Q))throw z.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let q=$8.createProtocolMetaIx(X);try{let J=v8.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof Q8){let R=J.message,N=[...R.staticAccountKeys];if(!N.some((K)=>K.equals(X8)))N.push(X8);let j={programIdIndex:N.findIndex((K)=>K.equals(X8)),accountKeyIndexes:[],data:q.data},Y=new Q8({header:R.header,staticAccountKeys:N,recentBlockhash:R.recentBlockhash,compiledInstructions:[...R.compiledInstructions,j],addressTableLookups:R.addressTableLookups}),v=new v8(Y);return v.signatures=J.signatures,Buffer.from(v.serialize()).toString("base64")}else{let R=d.from(Buffer.from(Q,"base64"));return R.add(q),Buffer.from(R.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=d.from(Buffer.from(Q,"base64"));return J.add(q),Buffer.from(J.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw z.invalidTransactionFormat("Invalid base64 transaction format")}}}}class m0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new $8,this._walletStrategy=new o(Q),this._delegationStrategy=new P8(Q)}getConfig(){return this.config}registerAdapter(Q,X){this.adapters[Q]=X}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}generateCode(Q,X,$){if(Q==="wallet"){if(!$)throw z.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(X,$)}else{if(!$)throw z.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(X,$)}}validateCode(Q,X,$){if(Q==="wallet"){if(this.walletStrategy.validateCode(X),!$)return;let Z=$,q=this.getAdapter(Z.chain);if(!q)throw z.invalidAdapter(Z.chain);if(!q.verifyWithWallet({...Z,message:{pubkey:X.pubkey,windowStart:X.timestamp}}))throw z.invalidSignature("Wallet signature verification failed")}else{let Z=$;this.delegationStrategy.validateDelegatedCode(X,Z.delegationProof);let q=this.getAdapter(Z.chain);if(!q)throw z.invalidAdapter(Z.chain);if(!q.verifyWithDelegation({...Z,message:{pubkey:X.pubkey,windowStart:X.timestamp}}))throw z.invalidSignature("Delegation signature verification failed")}}}export{JQ as validateProtocolMetaFormat,T8 as truncateBits,C0 as sha256,C8 as serializeDelegationProof,b8 as serializeCanonicalRevoke,c as serializeCanonical,j8 as parseProtocolMeta,V8 as hmacSha256,s0 as hkdfSha256,e as getCanonicalMessageParts,I8 as digestToDigits,o8 as codeHash,B8 as buildProtocolMeta,i0 as base32EncodeCrockford,o as WalletStrategy,J0 as TransactionNotSignedByIntendedOwnerError,$8 as SolanaAdapter,$Q as SUPPORTED_CHAINS,m8 as SCHEME,x0 as ProtocolErrorCode,z as ProtocolError,x8 as PROTOCOL_NORMALIZATION,t as PROTOCOL_META_MAX_BYTES,Z0 as MissingMetaError,q0 as MetaMismatchError,Y0 as InvalidSignatureError,R0 as InvalidPubkeyFormatError,N0 as InvalidCodeFormatError,z0 as InvalidAdapterError,$0 as ExpiredCodeError,P8 as DelegationStrategy,E8 as CODE_MIN_LENGTH,y8 as CODE_MAX_LENGTH,QQ as CODE_DEFAULT_LENGTH,XQ as CODE_CHARSET_DIGITS,t0 as CANONICAL_REVOKE_MESSAGE_PREFIX,a0 as CANONICAL_MESSAGE_VERSION,e0 as CANONICAL_MESSAGE_PREFIX,G8 as BaseChainAdapter,m0 as ActionCodesProtocol,n as ADAPTER_CHAIN_NAME};
|
2
2
|
|
3
|
-
//# debugId=
|
3
|
+
//# debugId=856032EB4655E73B64756E2164756E21
|