@actioncodes/protocol 2.0.8 → 2.0.10

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