@actioncodes/protocol 2.0.9 → 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 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 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=418BFCAAB80D3F2564756E2164756E21
3
+ //# debugId=AA589150D1EA6CB564756E2164756E21