@actioncodes/protocol 2.0.18 → 2.0.19

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 G8{}/*! 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,X=""){if(!Number.isSafeInteger(Q)||Q<0){let $=X&&`"${X}" `;throw Error(`${$}expected integer >= 0, got ${Q}`)}}function B(Q,X,$=""){let Z=D0(Q),q=Q?.length,J=X!==void 0;if(!Z||J&&q!==X){let R=$&&`"${$}" `,z=J?` of length ${X}`:"",U=Z?`length=${q}`:`type=${typeof Q}`;throw Error(R+"expected Uint8Array"+z+", got "+U)}return Q}function s(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");J8(Q.outputLen),J8(Q.blockLen)}function u(Q,X=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if(X&&Q.finished)throw Error("Hash#digest() has already been called")}function S8(Q,X){B(Q,void 0,"digestInto() output");let $=X.outputLen;if(Q.length<$)throw Error('"digestInto() output" expected to be of length >='+$)}function V(...Q){for(let X=0;X<Q.length;X++)Q[X].fill(0)}function R8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function I(Q,X){return Q<<32-X|Q>>>X}function H8(Q,X={}){let $=(q,J)=>Q(J).update(q).digest(),Z=Q(void 0);return $.outputLen=Z.outputLen,$.blockLen=Z.blockLen,$.create=(q)=>Q(q),Object.assign($,X),Object.freeze($)}var _8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function A8(Q,X,$){return Q&X^~Q&$}function f8(Q,X,$){return Q&X^Q&$^X&$}class Y8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,X,$,Z){this.blockLen=Q,this.outputLen=X,this.padOffset=$,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=R8(this.buffer)}update(Q){u(this),B(Q);let{view:X,buffer:$,blockLen:Z}=this,q=Q.length;for(let J=0;J<q;){let R=Math.min(Z-this.pos,q-J);if(R===Z){let z=R8(Q);for(;Z<=q-J;J+=Z)this.process(z,J);continue}if($.set(Q.subarray(J,J+R),this.pos),this.pos+=R,J+=R,this.pos===Z)this.process(X,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){u(this),S8(Q,this),this.finished=!0;let{buffer:X,view:$,blockLen:Z,isLE:q}=this,{pos:J}=this;if(X[J++]=128,V(this.buffer.subarray(J)),this.padOffset>Z-J)this.process($,0),J=0;for(let N=J;N<Z;N++)X[N]=0;$.setBigUint64(Z-8,BigInt(this.length*8),q),this.process($,0);let R=R8(Q),z=this.outputLen;if(z%4)throw Error("_sha2: outputLen must be aligned to 32bit");let U=z/4,j=this.get();if(U>j.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<U;N++)R.setUint32(4*N,j[N],q)}digest(){let{buffer:Q,outputLen:X}=this;this.digestInto(Q);let $=Q.slice(0,X);return this.destroy(),$}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:X,buffer:$,length:Z,finished:q,destroyed:J,pos:R}=this;if(Q.destroyed=J,Q.finished=q,Q.length=Z,Q.pos=R,Z%X)Q.buffer.set($);return Q}clone(){return this._cloneInto()}}var C=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),G=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),F=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var N8=BigInt(4294967295),u8=BigInt(32);function G0(Q,X=!1){if(X)return{h:Number(Q&N8),l:Number(Q>>u8&N8)};return{h:Number(Q>>u8&N8)|0,l:Number(Q&N8)|0}}function g8(Q,X=!1){let $=Q.length,Z=new Uint32Array($),q=new Uint32Array($);for(let J=0;J<$;J++){let{h:R,l:z}=G0(Q[J],X);[Z[J],q[J]]=[R,z]}return[Z,q]}var F8=(Q,X,$)=>Q>>>$,w8=(Q,X,$)=>Q<<32-$|X>>>$,_=(Q,X,$)=>Q>>>$|X<<32-$,A=(Q,X,$)=>Q<<32-$|X>>>$,i=(Q,X,$)=>Q<<64-$|X>>>$-32,r=(Q,X,$)=>Q>>>$-32|X<<64-$;function T(Q,X,$,Z){let q=(X>>>0)+(Z>>>0);return{h:Q+$+(q/4294967296|0)|0,l:q|0}}var c8=(Q,X,$)=>(Q>>>0)+(X>>>0)+($>>>0),h8=(Q,X,$,Z)=>X+$+Z+(Q/4294967296|0)|0,d8=(Q,X,$,Z)=>(Q>>>0)+(X>>>0)+($>>>0)+(Z>>>0),n8=(Q,X,$,Z,q)=>X+$+Z+q+(Q/4294967296|0)|0,l8=(Q,X,$,Z,q)=>(Q>>>0)+(X>>>0)+($>>>0)+(Z>>>0)+(q>>>0),s8=(Q,X,$,Z,q,J)=>X+$+Z+q+J+(Q/4294967296|0)|0;var 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]),P=new Uint32Array(64);class k8 extends Y8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:X,C:$,D:Z,E:q,F:J,G:R,H:z}=this;return[Q,X,$,Z,q,J,R,z]}set(Q,X,$,Z,q,J,R,z){this.A=Q|0,this.B=X|0,this.C=$|0,this.D=Z|0,this.E=q|0,this.F=J|0,this.G=R|0,this.H=z|0}process(Q,X){for(let N=0;N<16;N++,X+=4)P[N]=Q.getUint32(X,!1);for(let N=16;N<64;N++){let K=P[N-15],O=P[N-2],w=I(K,7)^I(K,18)^K>>>3,D=I(O,17)^I(O,19)^O>>>10;P[N]=D+P[N-7]+w+P[N-16]|0}let{A:$,B:Z,C:q,D:J,E:R,F:z,G:U,H:j}=this;for(let N=0;N<64;N++){let K=I(R,6)^I(R,11)^I(R,25),O=j+K+A8(R,z,U)+w0[N]+P[N]|0,D=(I($,2)^I($,13)^I($,22))+f8($,Z,q)|0;j=U,U=z,z=R,R=J+O|0,J=q,q=Z,Z=$,$=O+D|0}$=$+this.A|0,Z=Z+this.B|0,q=q+this.C|0,J=J+this.D|0,R=R+this.E|0,z=z+this.F|0,U=U+this.G|0,j=j+this.H|0,this.set($,Z,q,J,R,z,U,j)}roundClean(){V(P)}destroy(){this.set(0,0,0,0,0,0,0,0),V(this.buffer)}}class i8 extends k8{A=C[0]|0;B=C[1]|0;C=C[2]|0;D=C[3]|0;E=C[4]|0;F=C[5]|0;G=C[6]|0;H=C[7]|0;constructor(){super(32)}}class k0 extends k8{A=E[0]|0;B=E[1]|0;C=E[2]|0;D=E[3]|0;E=E[4]|0;F=E[5]|0;G=E[6]|0;H=E[7]|0;constructor(){super(28)}}var r8=(()=>g8(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((Q)=>BigInt(Q))))(),L0=(()=>r8[0])(),M0=(()=>r8[1])(),p=new Uint32Array(80),S=new Uint32Array(80);class a extends Y8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:X,Bh:$,Bl:Z,Ch:q,Cl:J,Dh:R,Dl:z,Eh:U,El:j,Fh:N,Fl:K,Gh:O,Gl:w,Hh:D,Hl:M}=this;return[Q,X,$,Z,q,J,R,z,U,j,N,K,O,w,D,M]}set(Q,X,$,Z,q,J,R,z,U,j,N,K,O,w,D,M){this.Ah=Q|0,this.Al=X|0,this.Bh=$|0,this.Bl=Z|0,this.Ch=q|0,this.Cl=J|0,this.Dh=R|0,this.Dl=z|0,this.Eh=U|0,this.El=j|0,this.Fh=N|0,this.Fl=K|0,this.Gh=O|0,this.Gl=w|0,this.Hh=D|0,this.Hl=M|0}process(Q,X){for(let v=0;v<16;v++,X+=4)p[v]=Q.getUint32(X),S[v]=Q.getUint32(X+=4);for(let v=16;v<80;v++){let y=p[v-15]|0,m=S[v-15]|0,O8=_(y,m,1)^_(y,m,8)^F8(y,m,7),v8=A(y,m,1)^A(y,m,8)^w8(y,m,7),x=p[v-2]|0,b=S[v-2]|0,Z8=_(x,b,19)^i(x,b,61)^F8(x,b,6),W8=A(x,b,19)^r(x,b,61)^w8(x,b,6),q8=d8(v8,W8,S[v-7],S[v-16]),D8=n8(q8,O8,Z8,p[v-7],p[v-16]);p[v]=D8|0,S[v]=q8|0}let{Ah:$,Al:Z,Bh:q,Bl:J,Ch:R,Cl:z,Dh:U,Dl:j,Eh:N,El:K,Fh:O,Fl:w,Gh:D,Gl:M,Hh:W,Hl:l}=this;for(let v=0;v<80;v++){let y=_(N,K,14)^_(N,K,18)^i(N,K,41),m=A(N,K,14)^A(N,K,18)^r(N,K,41),O8=N&O^~N&D,v8=K&w^~K&M,x=l8(l,m,v8,M0[v],S[v]),b=s8(x,W,y,O8,L0[v],p[v]),Z8=x|0,W8=_($,Z,28)^i($,Z,34)^i($,Z,39),q8=A($,Z,28)^r($,Z,34)^r($,Z,39),D8=$&q^$&R^q&R,W0=Z&J^Z&z^J&z;W=D|0,l=M|0,D=O|0,M=w|0,O=N|0,w=K|0,{h:N,l:K}=T(U|0,j|0,b|0,Z8|0),U=R|0,j=z|0,R=q|0,z=J|0,q=$|0,J=Z|0;let p8=c8(Z8,q8,W0);$=h8(p8,b,W8,D8),Z=p8|0}({h:$,l:Z}=T(this.Ah|0,this.Al|0,$|0,Z|0)),{h:q,l:J}=T(this.Bh|0,this.Bl|0,q|0,J|0),{h:R,l:z}=T(this.Ch|0,this.Cl|0,R|0,z|0),{h:U,l:j}=T(this.Dh|0,this.Dl|0,U|0,j|0),{h:N,l:K}=T(this.Eh|0,this.El|0,N|0,K|0),{h:O,l:w}=T(this.Fh|0,this.Fl|0,O|0,w|0),{h:D,l:M}=T(this.Gh|0,this.Gl|0,D|0,M|0),{h:W,l}=T(this.Hh|0,this.Hl|0,W|0,l|0),this.set($,Z,q,J,R,z,U,j,N,K,O,w,D,M,W,l)}roundClean(){V(p,S)}destroy(){V(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class V0 extends a{Ah=F[0]|0;Al=F[1]|0;Bh=F[2]|0;Bl=F[3]|0;Ch=F[4]|0;Cl=F[5]|0;Dh=F[6]|0;Dl=F[7]|0;Eh=F[8]|0;El=F[9]|0;Fh=F[10]|0;Fl=F[11]|0;Gh=F[12]|0;Gl=F[13]|0;Hh=F[14]|0;Hl=F[15]|0;constructor(){super(64)}}class I0 extends a{Ah=G[0]|0;Al=G[1]|0;Bh=G[2]|0;Bl=G[3]|0;Ch=G[4]|0;Cl=G[5]|0;Dh=G[6]|0;Dl=G[7]|0;Eh=G[8]|0;El=G[9]|0;Fh=G[10]|0;Fl=G[11]|0;Gh=G[12]|0;Gl=G[13]|0;Hh=G[14]|0;Hl=G[15]|0;constructor(){super(48)}}var k=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),L=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class T0 extends a{Ah=k[0]|0;Al=k[1]|0;Bh=k[2]|0;Bl=k[3]|0;Ch=k[4]|0;Cl=k[5]|0;Dh=k[6]|0;Dl=k[7]|0;Eh=k[8]|0;El=k[9]|0;Fh=k[10]|0;Fl=k[11]|0;Gh=k[12]|0;Gl=k[13]|0;Hh=k[14]|0;Hl=k[15]|0;constructor(){super(28)}}class x0 extends a{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=H8(()=>new i8,_8(1));class L8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,X){if(s(Q),B(X,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let $=this.blockLen,Z=new Uint8Array($);Z.set(X.length>$?Q.create().update(X).digest():X);for(let q=0;q<Z.length;q++)Z[q]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let q=0;q<Z.length;q++)Z[q]^=106;this.oHash.update(Z),V(Z)}update(Q){return u(this),this.iHash.update(Q),this}digestInto(Q){u(this),B(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:X,iHash:$,finished:Z,destroyed:q,blockLen:J,outputLen:R}=this;return Q=Q,Q.finished=Z,Q.destroyed=q,Q.blockLen=J,Q.outputLen=R,Q.oHash=X._cloneInto(Q.oHash),Q.iHash=$._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var g=(Q,X,$)=>new L8(Q,X).update($).digest();g.create=(Q,X)=>new L8(Q,X);function b0(Q,X,$){if(s(Q),$===void 0)$=new Uint8Array(Q.outputLen);return g(Q,$,X)}var M8=Uint8Array.of(0),a8=Uint8Array.of();function C0(Q,X,$,Z=32){s(Q),J8(Z,"length");let q=Q.outputLen;if(Z>255*q)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/q);if($===void 0)$=a8;else B($,void 0,"info");let R=new Uint8Array(J*q),z=g.create(Q,X),U=z._cloneInto(),j=new Uint8Array(z.outputLen);for(let N=0;N<J;N++)M8[0]=N+1,U.update(N===0?a8:j).update($).update(M8).digestInto(j),R.set(j,q*N),z._cloneInto(U);return z.destroy(),U.destroy(),V(j,M8),R.slice(0,Z)}var e8=(Q,X,$,Z,q)=>C0(Q,b0(Q,X,$),Z,q);function c(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function E0(Q){return z8(c(Q))}function V8(Q,X){return g(z8,c(Q),c(X))}function r0(Q,X,{salt:$,info:Z}={}){let q=$?c($):new Uint8Array(32),J=c(Q),R=Z?c(Z):new Uint8Array(0);return e8(z8,J,q,R,X)}var t8="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function a0(Q){let X=0,$=0,Z="";for(let q=0;q<Q.length;q++){$=$<<8|Q[q],X+=8;while(X>=5)Z+=t8[$>>>X-5&31],X-=5}if(X>0)Z+=t8[$<<5-X&31];return Z}function I8(Q,X){let $=Math.ceil(X/8),Z=new Uint8Array($),q=Math.min($,Q.length);Z.set(Q.subarray(0,q));let J=$*8-X;if(J>0){let R=255<<J;Z[$-1]=Z[$-1]&R}return Z}function T8(Q,X){if(Q.length===0)throw Error("digestToDigits: empty digest");let $="",Z=Q[Q.length-1]&15;for(let q=0;$.length<X;q++){let J=(Z+q*4)%Math.max(1,Q.length-4),U=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");$+=U}return $.slice(0,X)}function o8(Q){let X=E0(Q);return Array.from(X).map(($)=>$.toString(16).padStart(2,"0")).join("")}var t0=1,o0="actioncodes",QQ="actioncodes-revoke";function H(Q){let X=JSON.stringify({id:"actioncodes",ver:1,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode(X)}function x8(Q){let X=JSON.stringify({id:"actioncodes-revoke",ver:1,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode(X)}function e(Q){return H({pubkey:Q,windowStart:Date.now()})}function b8(Q){let X=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(X)}var C8="NFC",t=256,E8=6,y8=24,$Q=8,ZQ="0123456789",qQ=["solana"];var m8="actioncodes:";function B8(Q){let X=Q0(Q);if(X.int!=null)U8(X.int);let $=[`ver=${X.ver}`,`id=${encodeURIComponent(X.id)}`,`int=${encodeURIComponent(X.int)}`];if(X.p!=null&&Object.keys(X.p).length>0){let q=JSON.stringify(X.p);U8(q),$.push(`p=${encodeURIComponent(q)}`)}let Z=m8+$.join("&");return X0(Z),Z}function j8(Q){if(!Q.startsWith(m8))throw Error("protocol meta must start with actioncodes:");let $=Q.slice(m8.length).split("&").filter(Boolean),Z=new Map;for(let O of $){let[w,D]=O.split("=",2);if(!w)continue;let M=D!=null?decodeURIComponent(D):"";Z.set(w,M)}let q=Z.get("ver"),J=Z.get("id"),R=Z.get("int"),z=Z.get("p");if(q==null||J==null||R==null)throw Error("protocol meta missing required fields ver or id or int");let U=Number(q);if(!Number.isInteger(U)||U<=0)throw Error("protocol meta ver must be positive integer");let j;if(z!=null&&z!=="")try{if(j=JSON.parse(z),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 N=Q0({ver:U,id:J,int:R,p:j});if(N.int!=null)U8(N.int);if(N.p!=null)U8(JSON.stringify(N.p));if([...Z.keys()].filter((O)=>O!=="ver"&&O!=="id"&&O!=="int"&&O!=="p").length>0)throw Error("protocol meta contains unsupported keys");return X0(B8(N)),N}function YQ(Q){try{return j8(Q),{ok:!0}}catch(X){return{ok:!1,reason:String(X)}}}function Q0(Q){let X=Q.id.normalize(C8).trim(),$={ver:Q.ver,id:X,int:Q.int};if(Q.int!=null)$.int=Q.int.normalize(C8).trim();if(Q.p!=null)$.p=Q.p;return $}function X0(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta exceeds ${t} bytes`)}function U8(Q){if(new TextEncoder().encode(Q).length>t)throw Error(`protocol meta params exceed ${t} bytes`)}var y0;((W)=>{W.EXPIRED_CODE="EXPIRED_CODE";W.INVALID_CODE="INVALID_CODE";W.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";W.INVALID_SIGNATURE="INVALID_SIGNATURE";W.MISSING_META="MISSING_META";W.INVALID_META_FORMAT="INVALID_META_FORMAT";W.META_MISMATCH="META_MISMATCH";W.META_TOO_LARGE="META_TOO_LARGE";W.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";W.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";W.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";W.INVALID_INPUT="INVALID_INPUT";W.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";W.CRYPTO_ERROR="CRYPTO_ERROR";W.INVALID_DIGEST="INVALID_DIGEST";W.INVALID_ADAPTER="INVALID_ADAPTER"})(y0||={});class Y extends Error{code;details;constructor(Q,X,$){super(X);this.code=Q;this.details=$;this.name="ProtocolError"}static expiredCode(Q,X,$){return new $0(Q,X,$)}static invalidCode(){return new Y("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,X){return new N0(Q,X)}static invalidSignature(Q){return new Y0(Q)}static missingMeta(){return new Z0}static invalidMetaFormat(Q){return new Y("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,X,$){return new q0(Q,X,$)}static metaTooLarge(Q,X){return new Y("META_TOO_LARGE",`Protocol meta too large: ${X} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:X})}static transactionNotSignedByIntendedOwner(Q,X){return new J0(Q,X)}static invalidTransactionFormat(Q){return new Y("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,X){return new R0(Q,X)}static invalidInput(Q,X,$){return new Y("INVALID_INPUT",`Invalid ${Q}: ${$}`,{field:Q,value:X,reason:$})}static missingRequiredField(Q){return new Y("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,X){return new Y("CRYPTO_ERROR",`Crypto error in ${Q}: ${X}`,{operation:Q,reason:X})}static invalidDigest(Q){return new Y("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new z0(Q)}static create(Q,X,$){return new Y(Q,X,$)}}class $0 extends Y{constructor(Q,X,$){super("EXPIRED_CODE",`Action code '${Q}' expired at ${X}, current time: ${$}`,{code:Q,expiresAt:X,currentTime:$});this.name="ExpiredCodeError"}}class Z0 extends Y{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class q0 extends Y{constructor(Q,X,$){super("META_MISMATCH",`Meta ${$} mismatch: expected '${Q}', got '${X}'`,{expected:Q,actual:X,field:$});this.name="MetaMismatchError"}}class J0 extends Y{constructor(Q,X){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${X.join(", ")}]`,{intended:Q,actualSigners:X});this.name="TransactionNotSignedByIntendedOwnerError"}}class R0 extends Y{constructor(Q,X){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${X}`,{pubkey:Q,reason:X});this.name="InvalidPubkeyFormatError"}}class Y0 extends Y{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class N0 extends Y{constructor(Q,X){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${X}`,{code:Q,reason:X});this.name="InvalidCodeFormatError"}}class z0 extends Y{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}import U0 from"bs58";class o{config;constructor(Q){this.config=Q}generateCode(Q,X){let $=Q,Z=JSON.parse(new TextDecoder().decode($)),q=Z.pubkey,J=Z.windowStart,R;try{R=U0.decode(X)}catch{throw Y.invalidSignature("Invalid Base58 signature format")}let z=V8(R,$),U=Math.max(E8,Math.min(y8,this.config.codeLength)),j=8*Math.ceil(U/2),N=I8(z,j);return{actionCode:{code:T8(N,U),pubkey:q,timestamp:J,expiresAt:J+this.config.ttlMs,signature:X},canonicalMessage:$}}validateCode(Q){let X=Date.now();if(X>Q.expiresAt+(this.config.clockSkewMs??0))throw Y.expiredCode(Q.code,Q.expiresAt,X);let $=H({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw Y.missingRequiredField("signature");let Z;try{Z=U0.decode(Q.signature)}catch{throw Y.invalidSignature("Invalid Base58 signature format")}let q=V8(Z,$),J=Math.max(E8,Math.min(y8,this.config.codeLength)),R=I8(q,8*Math.ceil(J/2));if(T8(R,J)!==Q.code)throw Y.invalidCode()}getCanonicalMessageParts(Q){return e(Q)}}import{PublicKey as j0}from"@solana/web3.js";import K0 from"tweetnacl";import O0 from"bs58";class P8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new o(Q)}generateDelegatedCode(Q,X){this.validateDelegationProof(Q);let $=e(Q.delegatedPubkey);return{actionCode:{...this.walletStrategy.generateCode($,X).actionCode,pubkey:Q.walletPubkey,delegationProof:Q}}}validateDelegatedCode(Q,X){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw Y.expiredCode(Q.code,Q.expiresAt,$);if(this.validateDelegationProof(X),Q.pubkey!==X.walletPubkey||Q.pubkey!==Q.delegationProof.walletPubkey)throw Y.invalidInput("walletPubkey",Q.delegationProof.walletPubkey,"Action code wallet pubkey does not match delegation proof");if(Q.delegationProof.delegatedPubkey!==X.delegatedPubkey)throw Y.invalidInput("delegatedPubkey",Q.delegationProof.delegatedPubkey,"Invalid delegatedPubkey: Action code delegated pubkey does not match delegation proof");if(Q.delegationProof.expiresAt!==X.expiresAt)throw Y.invalidInput("expiresAt",Q.delegationProof.expiresAt,"Action code delegation expiration does not match delegation proof");if(!Q.delegationProof.signature)throw Y.missingRequiredField("delegationProof.signature");if(Q.delegationProof.signature!==X.signature)throw Y.invalidInput("signature",Q.delegationProof.signature,"Invalid signature: Action code delegation signature does not match delegation proof");let Z=H({pubkey:X.delegatedPubkey,windowStart:Q.timestamp}),q;try{q=O0.decode(Q.signature??"")}catch{throw Y.invalidSignature("Invalid Base58 delegated signature format")}let J=O0.decode(X.delegatedPubkey);if(!K0.sign.detached.verify(Z,q,J))throw Y.invalidSignature("Delegated signature verification failed")}validateDelegationProof(Q){if(!Q.walletPubkey||typeof Q.walletPubkey!=="string")throw Y.invalidInput("walletPubkey",Q.walletPubkey,"Wallet pubkey is required and must be a string");try{new j0(Q.walletPubkey)}catch{throw Y.invalidInput("walletPubkey",Q.walletPubkey,"Invalid wallet pubkey format")}if(!Q.delegatedPubkey||typeof Q.delegatedPubkey!=="string")throw Y.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Delegated pubkey is required and must be a string");try{new j0(Q.delegatedPubkey)}catch{throw Y.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Invalid delegated pubkey format")}if(!Q.chain||typeof Q.chain!=="string")throw Y.invalidInput("chain",Q.chain,"Chain is required and must be a string");if(Q.chain.length===0||Q.chain.length>50)throw Y.invalidInput("chain",Q.chain,"Chain must be between 1 and 50 characters");if(!/^[a-z0-9-]+$/.test(Q.chain))throw Y.invalidInput("chain",Q.chain,"Chain contains invalid characters (only lowercase letters, numbers, and hyphens allowed)");if(typeof Q.expiresAt!=="number"||!Number.isInteger(Q.expiresAt))throw Y.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be a valid integer timestamp");if(Q.expiresAt<=0)throw Y.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be positive");let X=Date.now(),$=31536000000;if(Q.expiresAt>X+$)throw Y.invalidInput("expiresAt",Q.expiresAt,"Expiration time is too far in the future");if(Q.expiresAt<X)throw Y.expiredCode("Delegation proof has expired",Q.expiresAt,X);if(!Q.signature||typeof Q.signature!=="string")throw Y.invalidInput("signature",Q.signature,"Delegation signature is required and must be a string");if(Q.signature.length===0||Q.signature.length>200)throw Y.invalidInput("signature",Q.signature,"Delegation signature must be between 1 and 200 characters")}getCanonicalMessageParts(Q){return e(Q)}}import f from"tweetnacl";import h from"bs58";import{PublicKey as v0,Transaction as d,VersionedTransaction as K8,TransactionInstruction as m0,MessageV0 as Q8}from"@solana/web3.js";import{createMemoInstruction as B0,MEMO_PROGRAM_ID as X8}from"@solana/spl-memo";var n="solana";class $8 extends G8{normalizePubkey(Q){if(typeof Q==="string")return new v0(Q);return Q}verifyWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.walletSignature)return!1;try{let X=H(Q.message),$=this.normalizePubkey(Q.message.pubkey),Z=h.decode(Q.walletSignature),q=$.toBytes();if(Z.length!==64||q.length!==32)return!1;return f.sign.detached.verify(X,Z,q)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.message.pubkey||!Q.delegatedSignature||!Q.delegationProof)return!1;let X=Q.delegationProof;if(!X.walletPubkey||!X.delegatedPubkey||!X.chain||!X.expiresAt||!X.signature)return!1;if(X.chain!==n)return!1;if(X.delegatedPubkey!==Q.message.pubkey)return!1;if(X.expiresAt<Date.now())return!1;try{let $=b8(X),Z=this.normalizePubkey(X.walletPubkey),q=h.decode(X.signature),J=Z.toBytes(),R=H(Q.message),z=this.normalizePubkey(X.delegatedPubkey),U=h.decode(Q.delegatedSignature),j=z.toBytes();if(q.length!==64||J.length!==32)return!1;if(U.length!==64||j.length!==32)return!1;let N=f.sign.detached.verify($,q,J),K=f.sign.detached.verify(R,U,j);return N&&K}catch{return!1}}verifyRevokeWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.walletSignature)return!1;try{let X=x8(Q.message),$=this.normalizePubkey(Q.message.pubkey),Z=h.decode(Q.walletSignature),q=$.toBytes();if(Z.length!==64||q.length!==32)return!1;return f.sign.detached.verify(X,Z,q)}catch{return!1}}verifyRevokeWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.message||!Q.message.pubkey||!Q.delegatedSignature||!Q.delegationProof)return!1;let X=Q.delegationProof;if(!X.walletPubkey||!X.delegatedPubkey||!X.chain||!X.expiresAt||!X.signature)return!1;if(X.chain!==n)return!1;if(X.delegatedPubkey!==Q.message.pubkey)return!1;if(X.expiresAt<Date.now())return!1;try{let $=b8(X),Z=this.normalizePubkey(X.walletPubkey),q=h.decode(X.signature),J=Z.toBytes();if(q.length!==64||J.length!==32)return!1;if(!f.sign.detached.verify($,q,J))return!1;let z=x8(Q.message),U=this.normalizePubkey(X.delegatedPubkey),j=h.decode(Q.delegatedSignature),N=U.toBytes();if(j.length!==64||N.length!==32)return!1;return f.sign.detached.verify(z,j,N)}catch{return!1}}static createProtocolMetaIx(Q){let X=B8(Q);return B0(X)}getProtocolMeta(Q){try{let X=this.deserializeTransaction(Q);for(let $ of this.getMemoInstructions(X)){let Z=$.data;try{let q=new TextDecoder().decode(Z);if(j8(q))return q}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let X=K8.deserialize(Buffer.from(Q,"base64"));if(X.message instanceof Q8)return X;else return d.from(Buffer.from(Q,"base64"))}catch{try{return d.from(Buffer.from(Q,"base64"))}catch{throw Y.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let X=this.getProtocolMeta(Q);if(!X)return null;return j8(X)}getMemoInstructions(Q){if(Q instanceof d)return Q.instructions.filter((X)=>X.programId.equals(X8));else{let $=Q.message;if($ instanceof Q8){let Z=[];for(let q of $.compiledInstructions){let J=$.staticAccountKeys[q.programIdIndex];if(J&&J.equals(X8)){let R=q.accountKeyIndexes.map((z)=>({pubkey:$.staticAccountKeys[z],isSigner:!1,isWritable:!1}));Z.push(new m0({keys:R,programId:J,data:q.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,X){let $=Date.now();if($>Q.expiresAt)throw Y.expiredCode(Q.code,Q.expiresAt,$);let Z=this.parseMeta(X);if(!Z)throw Y.missingMeta();if(Z.ver!==2)throw Y.metaMismatch("2",String(Z.ver),"ver");let q=o8(Q.code);if(Z.id!==q)throw Y.metaMismatch(q,Z.id,"id");if(Z.int!==Q.pubkey)throw Y.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let X=this.parseMeta(Q);if(!X)throw Y.missingMeta();let $=X.int;if(!$)throw Y.invalidMetaFormat("Missing 'int' (intendedFor) field");let Z;try{Z=new v0($)}catch{throw Y.invalidPubkeyFormat($,"Invalid public key format")}let q=this.deserializeTransaction(Q),J=[];if(q instanceof d){if(!q.signatures.some((z)=>{if(!z.signature)return!1;return J.push(z.publicKey.toString()),z.publicKey.equals(Z)}))throw Y.transactionNotSignedByIntendedOwner($,J);return}if(q instanceof K8){let R=q.message;if(R instanceof Q8){let z=R.header.numRequiredSignatures;for(let U=0;U<z;U++){let j=R.staticAccountKeys[U];if(j){if(J.push(j.toString()),j.equals(Z))return}}throw Y.transactionNotSignedByIntendedOwner($,J)}}throw Y.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,X){if(new $8().getProtocolMeta(Q))throw Y.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let q=$8.createProtocolMetaIx(X);try{let J=K8.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof Q8){let R=J.message,z=[...R.staticAccountKeys];if(!z.some((O)=>O.equals(X8)))z.push(X8);let j={programIdIndex:z.findIndex((O)=>O.equals(X8)),accountKeyIndexes:[],data:q.data},N=new Q8({header:R.header,staticAccountKeys:z,recentBlockhash:R.recentBlockhash,compiledInstructions:[...R.compiledInstructions,j],addressTableLookups:R.addressTableLookups}),K=new K8(N);return K.signatures=J.signatures,Buffer.from(K.serialize()).toString("base64")}else{let R=d.from(Buffer.from(Q,"base64"));return R.add(q),Buffer.from(R.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=d.from(Buffer.from(Q,"base64"));return J.add(q),Buffer.from(J.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw Y.invalidTransactionFormat("Invalid base64 transaction format")}}}}class P0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new $8,this._walletStrategy=new o(Q),this._delegationStrategy=new P8(Q)}getConfig(){return this.config}registerAdapter(Q,X){this.adapters[Q]=X}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}generateCode(Q,X,$){if(Q==="wallet"){if(!$)throw Y.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(X,$)}else{if(!$)throw Y.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(X,$)}}validateCode(Q,X,$){if(Q==="wallet"){if(this.walletStrategy.validateCode(X),!$)return;let Z=$,q=this.getAdapter(Z.chain);if(!q)throw Y.invalidAdapter(Z.chain);if(!q.verifyWithWallet({...Z,message:{pubkey:X.pubkey,windowStart:X.timestamp}}))throw Y.invalidSignature("Wallet signature verification failed")}else{let Z=$;this.delegationStrategy.validateDelegatedCode(X,Z.delegationProof);let q=this.getAdapter(Z.chain);if(!q)throw Y.invalidAdapter(Z.chain);if(!q.verifyWithDelegation({...Z,message:{pubkey:Z.delegationProof.delegatedPubkey,windowStart:X.timestamp}}))throw Y.invalidSignature("Delegation signature verification failed")}}}export{YQ as validateProtocolMetaFormat,I8 as truncateBits,E0 as sha256,b8 as serializeDelegationProof,x8 as serializeCanonicalRevoke,H as serializeCanonical,j8 as parseProtocolMeta,V8 as hmacSha256,r0 as hkdfSha256,e as getCanonicalMessageParts,T8 as digestToDigits,o8 as codeHash,B8 as buildProtocolMeta,a0 as base32EncodeCrockford,o as WalletStrategy,J0 as TransactionNotSignedByIntendedOwnerError,$8 as SolanaAdapter,qQ as SUPPORTED_CHAINS,m8 as SCHEME,y0 as ProtocolErrorCode,Y as ProtocolError,C8 as PROTOCOL_NORMALIZATION,t as PROTOCOL_META_MAX_BYTES,Z0 as MissingMetaError,q0 as MetaMismatchError,Y0 as InvalidSignatureError,R0 as InvalidPubkeyFormatError,N0 as InvalidCodeFormatError,z0 as InvalidAdapterError,$0 as ExpiredCodeError,P8 as DelegationStrategy,E8 as CODE_MIN_LENGTH,y8 as CODE_MAX_LENGTH,$Q as CODE_DEFAULT_LENGTH,ZQ as CODE_CHARSET_DIGITS,QQ as CANONICAL_REVOKE_MESSAGE_PREFIX,t0 as CANONICAL_MESSAGE_VERSION,o0 as CANONICAL_MESSAGE_PREFIX,G8 as BaseChainAdapter,P0 as ActionCodesProtocol,n as ADAPTER_CHAIN_NAME};
1
+ class F8{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function F0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function X8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let Z=$&&`"${$}" `;throw Error(`${Z}expected integer >= 0, got ${Q}`)}}function P(Q,$,Z=""){let q=F0(Q),Y=Q?.length,J=$!==void 0;if(!q||J&&Y!==$){let U=Z&&`"${Z}" `,K=J?` of length ${$}`:"",G=q?`length=${Y}`:`type=${typeof Q}`;throw Error(U+"expected Uint8Array"+K+", got "+G)}return Q}function r(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");X8(Q.outputLen),X8(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 C8(Q,$){P(Q,void 0,"digestInto() output");let Z=$.outputLen;if(Q.length<Z)throw Error('"digestInto() output" expected to be of length >='+Z)}function V(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function U8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function k(Q,$){return Q<<32-$|Q>>>$}function p8(Q,$={}){let Z=(Y,J)=>Q(J).update(Y).digest(),q=Q(void 0);return Z.outputLen=q.outputLen,Z.blockLen=q.blockLen,Z.create=(Y)=>Q(Y),Object.assign(Z,$),Object.freeze(Z)}var u8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function A8(Q,$,Z){return Q&$^~Q&Z}function g8(Q,$,Z){return Q&$^Q&Z^$&Z}class z8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,Z,q){this.blockLen=Q,this.outputLen=$,this.padOffset=Z,this.isLE=q,this.buffer=new Uint8Array(Q),this.view=U8(this.buffer)}update(Q){A(this),P(Q);let{view:$,buffer:Z,blockLen:q}=this,Y=Q.length;for(let J=0;J<Y;){let U=Math.min(q-this.pos,Y-J);if(U===q){let K=U8(Q);for(;q<=Y-J;J+=q)this.process(K,J);continue}if(Z.set(Q.subarray(J,J+U),this.pos),this.pos+=U,J+=U,this.pos===q)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){A(this),C8(Q,this),this.finished=!0;let{buffer:$,view:Z,blockLen:q,isLE:Y}=this,{pos:J}=this;if($[J++]=128,V(this.buffer.subarray(J)),this.padOffset>q-J)this.process(Z,0),J=0;for(let z=J;z<q;z++)$[z]=0;Z.setBigUint64(q-8,BigInt(this.length*8),Y),this.process(Z,0);let U=U8(Q),K=this.outputLen;if(K%4)throw Error("_sha2: outputLen must be aligned to 32bit");let G=K/4,j=this.get();if(G>j.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<G;z++)U.setUint32(4*z,j[z],Y)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let Z=Q.slice(0,$);return this.destroy(),Z}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:Z,length:q,finished:Y,destroyed:J,pos:U}=this;if(Q.destroyed=J,Q.finished=Y,Q.length=q,Q.pos=U,q%$)Q.buffer.set(Z);return Q}clone(){return this._cloneInto()}}var b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),B=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 K8=BigInt(4294967295),h8=BigInt(32);function w0(Q,$=!1){if($)return{h:Number(Q&K8),l:Number(Q>>h8&K8)};return{h:Number(Q>>h8&K8)|0,l:Number(Q&K8)|0}}function c8(Q,$=!1){let Z=Q.length,q=new Uint32Array(Z),Y=new Uint32Array(Z);for(let J=0;J<Z;J++){let{h:U,l:K}=w0(Q[J],$);[q[J],Y[J]]=[U,K]}return[q,Y]}var w8=(Q,$,Z)=>Q>>>Z,x8=(Q,$,Z)=>Q<<32-Z|$>>>Z,C=(Q,$,Z)=>Q>>>Z|$<<32-Z,p=(Q,$,Z)=>Q<<32-Z|$>>>Z,a=(Q,$,Z)=>Q<<64-Z|$>>>Z-32,t=(Q,$,Z)=>Q>>>Z-32|$<<64-Z;function T(Q,$,Z,q){let Y=($>>>0)+(q>>>0);return{h:Q+Z+(Y/4294967296|0)|0,l:Y|0}}var d8=(Q,$,Z)=>(Q>>>0)+($>>>0)+(Z>>>0),l8=(Q,$,Z,q)=>$+Z+q+(Q/4294967296|0)|0,s8=(Q,$,Z,q)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0),n8=(Q,$,Z,q,Y)=>$+Z+q+Y+(Q/4294967296|0)|0,i8=(Q,$,Z,q,Y)=>(Q>>>0)+($>>>0)+(Z>>>0)+(q>>>0)+(Y>>>0),r8=(Q,$,Z,q,Y,J)=>$+Z+q+Y+J+(Q/4294967296|0)|0;var L0=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]),H=new Uint32Array(64);class L8 extends z8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:Z,D:q,E:Y,F:J,G:U,H:K}=this;return[Q,$,Z,q,Y,J,U,K]}set(Q,$,Z,q,Y,J,U,K){this.A=Q|0,this.B=$|0,this.C=Z|0,this.D=q|0,this.E=Y|0,this.F=J|0,this.G=U|0,this.H=K|0}process(Q,$){for(let z=0;z<16;z++,$+=4)H[z]=Q.getUint32($,!1);for(let z=16;z<64;z++){let N=H[z-15],R=H[z-2],v=k(N,7)^k(N,18)^N>>>3,O=k(R,17)^k(R,19)^R>>>10;H[z]=O+H[z-7]+v+H[z-16]|0}let{A:Z,B:q,C:Y,D:J,E:U,F:K,G,H:j}=this;for(let z=0;z<64;z++){let N=k(U,6)^k(U,11)^k(U,25),R=j+N+A8(U,K,G)+L0[z]+H[z]|0,O=(k(Z,2)^k(Z,13)^k(Z,22))+g8(Z,q,Y)|0;j=G,G=K,K=U,U=J+R|0,J=Y,Y=q,q=Z,Z=R+O|0}Z=Z+this.A|0,q=q+this.B|0,Y=Y+this.C|0,J=J+this.D|0,U=U+this.E|0,K=K+this.F|0,G=G+this.G|0,j=j+this.H|0,this.set(Z,q,Y,J,U,K,G,j)}roundClean(){V(H)}destroy(){this.set(0,0,0,0,0,0,0,0),V(this.buffer)}}class a8 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 M0 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(28)}}var t8=(()=>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))))(),V0=(()=>t8[0])(),k0=(()=>t8[1])(),S=new Uint32Array(80),_=new Uint32Array(80);class e extends z8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:Z,Bl:q,Ch:Y,Cl:J,Dh:U,Dl:K,Eh:G,El:j,Fh:z,Fl:N,Gh:R,Gl:v,Hh:O,Hl:M}=this;return[Q,$,Z,q,Y,J,U,K,G,j,z,N,R,v,O,M]}set(Q,$,Z,q,Y,J,U,K,G,j,z,N,R,v,O,M){this.Ah=Q|0,this.Al=$|0,this.Bh=Z|0,this.Bl=q|0,this.Ch=Y|0,this.Cl=J|0,this.Dh=U|0,this.Dl=K|0,this.Eh=G|0,this.El=j|0,this.Fh=z|0,this.Fl=N|0,this.Gh=R|0,this.Gl=v|0,this.Hh=O|0,this.Hl=M|0}process(Q,$){for(let W=0;W<16;W++,$+=4)S[W]=Q.getUint32($),_[W]=Q.getUint32($+=4);for(let W=16;W<80;W++){let y=S[W-15]|0,E=_[W-15]|0,W8=C(y,E,1)^C(y,E,8)^w8(y,E,7),D8=p(y,E,1)^p(y,E,8)^x8(y,E,7),I=S[W-2]|0,m=_[W-2]|0,Y8=C(I,m,19)^a(I,m,61)^w8(I,m,6),v8=p(I,m,19)^t(I,m,61)^x8(I,m,6),J8=s8(D8,v8,_[W-7],_[W-16]),O8=n8(J8,W8,Y8,S[W-7],S[W-16]);S[W]=O8|0,_[W]=J8|0}let{Ah:Z,Al:q,Bh:Y,Bl:J,Ch:U,Cl:K,Dh:G,Dl:j,Eh:z,El:N,Fh:R,Fl:v,Gh:O,Gl:M,Hh:D,Hl:i}=this;for(let W=0;W<80;W++){let y=C(z,N,14)^C(z,N,18)^a(z,N,41),E=p(z,N,14)^p(z,N,18)^t(z,N,41),W8=z&R^~z&O,D8=N&v^~N&M,I=i8(i,E,D8,k0[W],_[W]),m=r8(I,D,y,W8,V0[W],S[W]),Y8=I|0,v8=C(Z,q,28)^a(Z,q,34)^a(Z,q,39),J8=p(Z,q,28)^t(Z,q,34)^t(Z,q,39),O8=Z&Y^Z&U^Y&U,O0=q&J^q&K^J&K;D=O|0,i=M|0,O=R|0,M=v|0,R=z|0,v=N|0,{h:z,l:N}=T(G|0,j|0,m|0,Y8|0),G=U|0,j=K|0,U=Y|0,K=J|0,Y=Z|0,J=q|0;let f8=d8(Y8,J8,O0);Z=l8(f8,m,v8,O8),q=f8|0}({h:Z,l:q}=T(this.Ah|0,this.Al|0,Z|0,q|0)),{h:Y,l:J}=T(this.Bh|0,this.Bl|0,Y|0,J|0),{h:U,l:K}=T(this.Ch|0,this.Cl|0,U|0,K|0),{h:G,l:j}=T(this.Dh|0,this.Dl|0,G|0,j|0),{h:z,l:N}=T(this.Eh|0,this.El|0,z|0,N|0),{h:R,l:v}=T(this.Fh|0,this.Fl|0,R|0,v|0),{h:O,l:M}=T(this.Gh|0,this.Gl|0,O|0,M|0),{h:D,l:i}=T(this.Hh|0,this.Hl|0,D|0,i|0),this.set(Z,q,Y,J,U,K,G,j,z,N,R,v,O,M,D,i)}roundClean(){V(S,_)}destroy(){V(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class T0 extends e{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 I0 extends e{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 x=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 e{Ah=x[0]|0;Al=x[1]|0;Bh=x[2]|0;Bl=x[3]|0;Ch=x[4]|0;Cl=x[5]|0;Dh=x[6]|0;Dl=x[7]|0;Eh=x[8]|0;El=x[9]|0;Fh=x[10]|0;Fl=x[11]|0;Gh=x[12]|0;Gl=x[13]|0;Hh=x[14]|0;Hl=x[15]|0;constructor(){super(28)}}class b0 extends e{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 j8=p8(()=>new a8,u8(1));class M8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if(r(Q),P($,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let Z=this.blockLen,q=new Uint8Array(Z);q.set($.length>Z?Q.create().update($).digest():$);for(let Y=0;Y<q.length;Y++)q[Y]^=54;this.iHash.update(q),this.oHash=Q.create();for(let Y=0;Y<q.length;Y++)q[Y]^=106;this.oHash.update(q),V(q)}update(Q){return A(this),this.iHash.update(Q),this}digestInto(Q){A(this),P(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:$,iHash:Z,finished:q,destroyed:Y,blockLen:J,outputLen:U}=this;return Q=Q,Q.finished=q,Q.destroyed=Y,Q.blockLen=J,Q.outputLen=U,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=Z._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var g=(Q,$,Z)=>new M8(Q,$).update(Z).digest();g.create=(Q,$)=>new M8(Q,$);function B0(Q,$,Z){if(r(Q),Z===void 0)Z=new Uint8Array(Q.outputLen);return g(Q,Z,$)}var V8=Uint8Array.of(0),e8=Uint8Array.of();function y0(Q,$,Z,q=32){r(Q),X8(q,"length");let Y=Q.outputLen;if(q>255*Y)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(q/Y);if(Z===void 0)Z=e8;else P(Z,void 0,"info");let U=new Uint8Array(J*Y),K=g.create(Q,$),G=K._cloneInto(),j=new Uint8Array(K.outputLen);for(let z=0;z<J;z++)V8[0]=z+1,G.update(z===0?e8:j).update(Z).update(V8).digestInto(j),U.set(j,Y*z),K._cloneInto(G);return K.destroy(),G.destroy(),V(j,V8),U.slice(0,q)}var o8=(Q,$,Z,q,Y)=>y0(Q,B0(Q,$,Z),q,Y);function h(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function E0(Q){return j8(h(Q))}function k8(Q,$){return g(j8,h(Q),h($))}function o0(Q,$,{salt:Z,info:q}={}){let Y=Z?h(Z):new Uint8Array(32),J=h(Q),U=q?h(q):new Uint8Array(0);return o8(j8,J,Y,U,$)}var Q0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function QQ(Q){let $=0,Z=0,q="";for(let Y=0;Y<Q.length;Y++){Z=Z<<8|Q[Y],$+=8;while($>=5)q+=Q0[Z>>>$-5&31],$-=5}if($>0)q+=Q0[Z<<5-$&31];return q}function T8(Q,$){let Z=Math.ceil($/8),q=new Uint8Array(Z),Y=Math.min(Z,Q.length);q.set(Q.subarray(0,Y));let J=Z*8-$;if(J>0){let U=255<<J;q[Z-1]=q[Z-1]&U}return q}function I8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let Z="",q=Q[Q.length-1]&15;for(let Y=0;Z.length<$;Y++){let J=(q+Y*4)%Math.max(1,Q.length-4),G=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");Z+=G}return Z.slice(0,$)}function u(Q){let $=E0(Q);return Array.from($).map((Z)=>Z.toString(16).padStart(2,"0")).join("")}var P0;((D)=>{D.EXPIRED_CODE="EXPIRED_CODE";D.INVALID_CODE="INVALID_CODE";D.INVALID_CODE_FORMAT="INVALID_CODE_FORMAT";D.INVALID_SIGNATURE="INVALID_SIGNATURE";D.MISSING_META="MISSING_META";D.INVALID_META_FORMAT="INVALID_META_FORMAT";D.META_MISMATCH="META_MISMATCH";D.META_TOO_LARGE="META_TOO_LARGE";D.TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER="TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER";D.INVALID_TRANSACTION_FORMAT="INVALID_TRANSACTION_FORMAT";D.INVALID_PUBKEY_FORMAT="INVALID_PUBKEY_FORMAT";D.INVALID_INPUT="INVALID_INPUT";D.MISSING_REQUIRED_FIELD="MISSING_REQUIRED_FIELD";D.CRYPTO_ERROR="CRYPTO_ERROR";D.INVALID_DIGEST="INVALID_DIGEST";D.INVALID_ADAPTER="INVALID_ADAPTER"})(P0||={});class X extends Error{code;details;constructor(Q,$,Z){super($);this.code=Q;this.details=Z;this.name="ProtocolError"}static expiredCode(Q,$,Z){return new $0(Q,$,Z)}static invalidCode(){return new X("INVALID_CODE","Invalid code provided",{})}static invalidCodeFormat(Q,$){return new U0(Q,$)}static invalidSignature(Q){return new X0(Q)}static missingMeta(){return new Z0}static invalidMetaFormat(Q){return new X("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,Z){return new q0(Q,$,Z)}static metaTooLarge(Q,$){return new X("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new Y0(Q,$)}static invalidTransactionFormat(Q){return new X("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new J0(Q,$)}static invalidInput(Q,$,Z){return new X("INVALID_INPUT",`Invalid ${Q}: ${Z}`,{field:Q,value:$,reason:Z})}static missingRequiredField(Q){return new X("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new X("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new X("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new z0(Q)}static create(Q,$,Z){return new X(Q,$,Z)}}class $0 extends X{constructor(Q,$,Z){super("EXPIRED_CODE",`Action code '${Q}' has expired`,{code:Q,expiresAt:$,currentTime:Z});this.name="ExpiredCodeError"}}class Z0 extends X{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class q0 extends X{constructor(Q,$,Z){super("META_MISMATCH",`Meta ${Z} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:Z});this.name="MetaMismatchError"}}class Y0 extends X{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${$.join(", ")}]`,{intended:Q,actualSigners:$});this.name="TransactionNotSignedByIntendedOwnerError"}}class J0 extends X{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class X0 extends X{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class U0 extends X{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class z0 extends X{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}var K0=1,H0="actioncodes",S0="actioncodes-revoke";function f(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey))throw X.invalidInput("pubkey",Q.pubkey,"contains invalid characters for public key or JSON");let $=JSON.stringify({id:H0,ver:K0,pubkey:Q.pubkey,windowStart:Q.windowStart});return new TextEncoder().encode($)}function c(Q){if(typeof Q.pubkey!=="string")throw X.invalidInput("pubkey",Q.pubkey,"must be a string");if(typeof Q.codeHash!=="string")throw X.invalidInput("codeHash",Q.codeHash,"must be a string");if(Q.pubkey.length===0)throw X.invalidInput("pubkey",Q.pubkey,"cannot be empty");if(Q.pubkey.length>100)throw X.invalidInput("pubkey",Q.pubkey,"too long (max 100 characters)");if(Q.codeHash.length===0)throw X.invalidInput("codeHash",Q.codeHash,"cannot be empty");if(Q.codeHash.length>100)throw X.invalidInput("codeHash",Q.codeHash,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Q.pubkey)||/["\\\x00-\x1f\x7f-\x9f]/.test(Q.codeHash))throw X.invalidInput("input","contains invalid characters for identifiers or JSON","contains invalid characters");let $=JSON.stringify({id:S0,ver:K0,pubkey:Q.pubkey,codeHash:Q.codeHash,windowStart:Q.windowStart});return new TextEncoder().encode($)}function m8(Q){return f({pubkey:Q,windowStart:Date.now()})}function b8(Q){let $=["walletPubkey","delegatedPubkey","chain"];for(let q of $){let Y=Q[q];if(typeof Y!=="string")throw X.invalidInput(q,Y,"must be a string");if(Y.length===0)throw X.invalidInput(q,Y,"cannot be empty");if(Y.length>100)throw X.invalidInput(q,Y,"too long (max 100 characters)");if(/["\\\x00-\x1f\x7f-\x9f]/.test(Y))throw X.invalidInput(q,Y,"contains invalid characters for identifiers or JSON")}let Z=JSON.stringify({walletPubkey:Q.walletPubkey,delegatedPubkey:Q.delegatedPubkey,expiresAt:Q.expiresAt,chain:Q.chain});return new TextEncoder().encode(Z)}var B8="NFC",o=256,y8=6,E8=24,JQ=8,XQ="0123456789",P8=["solana"];var H8="actioncodes:";function S8(Q){let $=j0(Q);if($.int!=null)G8($.int);let Z=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let Y=JSON.stringify($.p);G8(Y),Z.push(`p=${encodeURIComponent(Y)}`)}let q=H8+Z.join("&");return G0(q),q}function N8(Q){if(!Q.startsWith(H8))throw Error("protocol meta must start with actioncodes:");let Z=Q.slice(H8.length).split("&").filter(Boolean),q=new Map;for(let R of Z){let[v,O]=R.split("=",2);if(!v)continue;let M=O!=null?decodeURIComponent(O):"";q.set(v,M)}let Y=q.get("ver"),J=q.get("id"),U=q.get("int"),K=q.get("p");if(Y==null||J==null||U==null)throw Error("protocol meta missing required fields ver or id or int");let G=Number(Y);if(!Number.isInteger(G)||G<=0)throw Error("protocol meta ver must be positive integer");let j;if(K!=null&&K!=="")try{if(j=JSON.parse(K),typeof j!=="object"||j===null||Array.isArray(j))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let z=j0({ver:G,id:J,int:U,p:j});if(z.int!=null)G8(z.int);if(z.p!=null)G8(JSON.stringify(z.p));if([...q.keys()].filter((R)=>R!=="ver"&&R!=="id"&&R!=="int"&&R!=="p").length>0)throw Error("protocol meta contains unsupported keys");return G0(S8(z)),z}function KQ(Q){try{return N8(Q),{ok:!0}}catch($){return{ok:!1,reason:String($)}}}function j0(Q){let $=Q.id.normalize(B8).trim(),Z={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)Z.int=Q.int.normalize(B8).trim();if(Q.p!=null)Z.p=Q.p;return Z}function G0(Q){if(new TextEncoder().encode(Q).length>o)throw Error(`protocol meta exceeds ${o} bytes`)}function G8(Q){if(new TextEncoder().encode(Q).length>o)throw Error(`protocol meta params exceed ${o} bytes`)}import N0 from"bs58";class Q8{config;constructor(Q){this.config=Q}generateCode(Q,$,Z){let q=Q,Y=JSON.parse(new TextDecoder().decode(q)),J=Y.pubkey,U=Y.windowStart,K;try{K=N0.decode(Z)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let G=k8(K,q),j=Math.max(y8,Math.min(E8,this.config.codeLength)),z=8*Math.ceil(j/2),N=T8(G,z),R=I8(N,j);return{chain:$,code:R,pubkey:J,timestamp:U,expiresAt:U+this.config.ttlMs,signature:Z}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);let Z=f({pubkey:Q.pubkey,windowStart:Q.timestamp});if(!Q.signature)throw X.missingRequiredField("signature");let q;try{q=N0.decode(Q.signature)}catch{throw X.invalidSignature("Invalid Base58 signature format")}let Y=k8(q,Z),J=Math.max(y8,Math.min(E8,this.config.codeLength)),U=T8(Y,8*Math.ceil(J/2));if(I8(U,J)!==Q.code)throw X.invalidCode()}}import{PublicKey as R0}from"@solana/web3.js";import W0 from"tweetnacl";import D0 from"bs58";class _8{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new Q8(Q)}generateDelegatedCode(Q,$,Z,q){return this.validateDelegationProof(Q),{...this.walletStrategy.generateCode($,Z,q),delegationProof:Q}}validateDelegatedCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw X.expiredCode(Q.code,Q.expiresAt,$);if(this.validateDelegationProof(Q.delegationProof),Q.pubkey!==Q.delegationProof.delegatedPubkey)throw X.invalidInput("delegatedPubkey",Q.delegationProof.delegatedPubkey,"Action code pubkey does not match delegated signer");if(Q.expiresAt>Q.delegationProof.expiresAt)throw X.invalidInput("expiresAt",Q.expiresAt,"Action code cannot expire after delegation proof expiration");if(!Q.delegationProof.signature)throw X.missingRequiredField("delegationProof.signature");let Z=f({pubkey:Q.delegationProof.delegatedPubkey,windowStart:Q.timestamp}),q;try{q=D0.decode(Q.signature??"")}catch{throw X.invalidSignature("Invalid Base58 delegated signature format")}let Y=D0.decode(Q.delegationProof.delegatedPubkey);if(!W0.sign.detached.verify(Z,q,Y))throw X.invalidSignature("Delegated signature verification failed")}validateDelegationProof(Q){if(!Q.walletPubkey||typeof Q.walletPubkey!=="string")throw X.invalidInput("walletPubkey",Q.walletPubkey,"Wallet pubkey is required and must be a string");try{new R0(Q.walletPubkey)}catch{throw X.invalidInput("walletPubkey",Q.walletPubkey,"Invalid wallet pubkey format")}if(!Q.delegatedPubkey||typeof Q.delegatedPubkey!=="string")throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Delegated pubkey is required and must be a string");try{new R0(Q.delegatedPubkey)}catch{throw X.invalidInput("delegatedPubkey",Q.delegatedPubkey,"Invalid delegated pubkey format")}if(!Q.chain||typeof Q.chain!=="string")throw X.invalidInput("chain",Q.chain,"Chain is required and must be a string");if(Q.chain.length===0||Q.chain.length>50)throw X.invalidInput("chain",Q.chain,"Chain must be between 1 and 50 characters");if(!/^[a-z0-9-]+$/.test(Q.chain))throw X.invalidInput("chain",Q.chain,"Chain contains invalid characters (only lowercase letters, numbers, and hyphens allowed)");if(typeof Q.expiresAt!=="number"||!Number.isInteger(Q.expiresAt))throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be a valid integer timestamp");if(Q.expiresAt<=0)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time must be positive");let $=Date.now(),Z=31536000000;if(Q.expiresAt>$+Z)throw X.invalidInput("expiresAt",Q.expiresAt,"Expiration time is too far in the future");if(Q.expiresAt<$)throw X.expiredCode("Delegation proof has expired",Q.expiresAt,$);if(!Q.signature||typeof Q.signature!=="string")throw X.invalidInput("signature",Q.signature,"Delegation signature is required and must be a string");if(Q.signature.length===0||Q.signature.length>200)throw X.invalidInput("signature",Q.signature,"Delegation signature must be between 1 and 200 characters")}}import d from"tweetnacl";import l from"bs58";import{PublicKey as v0,Transaction as s,VersionedTransaction as R8,TransactionInstruction as _0,MessageV0 as $8}from"@solana/web3.js";import{createMemoInstruction as f0,MEMO_PROGRAM_ID as Z8}from"@solana/spl-memo";var n="solana";class q8 extends F8{normalizePubkey(Q){if(typeof Q==="string")return new v0(Q);return Q}verifyWithWallet(Q){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;try{let $=f({pubkey:Q.pubkey,windowStart:Q.timestamp}),Z=this.normalizePubkey(Q.pubkey),q=l.decode(Q.signature),Y=Z.toBytes();if(q.length!==64||Y.length!==32)return!1;return d.sign.detached.verify($,q,Y)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature)return!1;let $=Q.delegationProof;if(!$.walletPubkey||!$.delegatedPubkey||!$.chain||!$.expiresAt||!$.signature)return!1;if($.chain!==n)return!1;if(Q.pubkey!==$.delegatedPubkey)return!1;if($.expiresAt<Date.now())return!1;try{let Z=b8($),q=this.normalizePubkey($.walletPubkey),Y=l.decode($.signature),J=q.toBytes(),U=f({pubkey:$.delegatedPubkey,windowStart:Q.timestamp}),K=this.normalizePubkey($.delegatedPubkey),G=l.decode(Q.signature),j=K.toBytes();if(Y.length!==64||J.length!==32)return!1;if(G.length!==64||j.length!==32)return!1;let z=d.sign.detached.verify(Z,Y,J),N=d.sign.detached.verify(U,G,j);return z&&N}catch{return!1}}verifyRevokeWithWallet(Q,$){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!$)return!1;try{let Z=c({pubkey:Q.pubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),q=this.normalizePubkey(Q.pubkey),Y=l.decode($),J=q.toBytes();if(Y.length!==64||J.length!==32)return!1;return d.sign.detached.verify(Z,Y,J)}catch{return!1}}verifyRevokeWithDelegation(Q,$){if(Q.chain!==n)return!1;if(!Q.pubkey||!Q.timestamp||!Q.signature||!Q.delegationProof)return!1;let Z=Q.delegationProof;if(!Z.walletPubkey||!Z.delegatedPubkey||!Z.chain||!Z.expiresAt||!Z.signature)return!1;if(Z.chain!==n)return!1;if(Q.pubkey!==Z.delegatedPubkey)return!1;if(Z.expiresAt<Date.now())return!1;try{let q=b8(Z),Y=this.normalizePubkey(Z.walletPubkey),J=l.decode(Z.signature),U=Y.toBytes(),K=c({pubkey:Z.delegatedPubkey,codeHash:u(Q.code),windowStart:Q.timestamp}),G=this.normalizePubkey(Z.delegatedPubkey),j=l.decode($),z=G.toBytes();if(J.length!==64||U.length!==32)return!1;if(j.length!==64||z.length!==32)return!1;let N=d.sign.detached.verify(q,J,U),R=d.sign.detached.verify(K,j,z);return N&&R}catch{return!1}}static createProtocolMetaIx(Q){let $=S8(Q);return f0($)}getProtocolMeta(Q){try{let $=this.deserializeTransaction(Q);for(let Z of this.getMemoInstructions($)){let q=Z.data;try{let Y=new TextDecoder().decode(q);if(N8(Y))return Y}catch{}}return null}catch{return null}}deserializeTransaction(Q){try{let $=R8.deserialize(Buffer.from(Q,"base64"));if($.message instanceof $8)return $;else return s.from(Buffer.from(Q,"base64"))}catch{try{return s.from(Buffer.from(Q,"base64"))}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return N8($)}getMemoInstructions(Q){if(Q instanceof s)return Q.instructions.filter(($)=>$.programId.equals(Z8));else{let Z=Q.message;if(Z instanceof $8){let q=[];for(let Y of Z.compiledInstructions){let J=Z.staticAccountKeys[Y.programIdIndex];if(J&&J.equals(Z8)){let U=Y.accountKeyIndexes.map((K)=>({pubkey:Z.staticAccountKeys[K],isSigner:!1,isWritable:!1}));q.push(new _0({keys:U,programId:J,data:Y.data}))}}return q}return[]}}verifyTransactionMatchesCode(Q,$){let Z=Date.now();if(Z>Q.expiresAt)throw X.expiredCode(Q.code,Q.expiresAt,Z);let q=this.parseMeta($);if(!q)throw X.missingMeta();if(q.ver!==2)throw X.metaMismatch("2",String(q.ver),"ver");let Y=u(Q.code);if(q.id!==Y)throw X.metaMismatch(Y,q.id,"id");if(q.int!==Q.pubkey)throw X.metaMismatch(Q.pubkey,q.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw X.missingMeta();let Z=$.int;if(!Z)throw X.invalidMetaFormat("Missing 'int' (intendedFor) field");let q;try{q=new v0(Z)}catch{throw X.invalidPubkeyFormat(Z,"Invalid public key format")}let Y=this.deserializeTransaction(Q),J=[];if(Y instanceof s){if(!Y.signatures.some((K)=>{if(!K.signature)return!1;return J.push(K.publicKey.toString()),K.publicKey.equals(q)}))throw X.transactionNotSignedByIntendedOwner(Z,J);return}if(Y instanceof R8){let U=Y.message;if(U instanceof $8){let K=U.header.numRequiredSignatures;for(let G=0;G<K;G++){let j=U.staticAccountKeys[G];if(j){if(J.push(j.toString()),j.equals(q))return}}throw X.transactionNotSignedByIntendedOwner(Z,J)}}throw X.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,$){if(new q8().getProtocolMeta(Q))throw X.invalidTransactionFormat("Transaction already contains protocol meta. Cannot attach additional protocol meta.");let Y=q8.createProtocolMetaIx($);try{let J=R8.deserialize(Buffer.from(Q,"base64"));if(J.message instanceof $8){let U=J.message,K=[...U.staticAccountKeys];if(!K.some((R)=>R.equals(Z8)))K.push(Z8);let j={programIdIndex:K.findIndex((R)=>R.equals(Z8)),accountKeyIndexes:[],data:Y.data},z=new $8({header:U.header,staticAccountKeys:K,recentBlockhash:U.recentBlockhash,compiledInstructions:[...U.compiledInstructions,j],addressTableLookups:U.addressTableLookups}),N=new R8(z);return N.signatures=J.signatures,Buffer.from(N.serialize()).toString("base64")}else{let U=s.from(Buffer.from(Q,"base64"));return U.add(Y),Buffer.from(U.serialize({requireAllSignatures:!1})).toString("base64")}}catch{try{let J=s.from(Buffer.from(Q,"base64"));return J.add(Y),Buffer.from(J.serialize({requireAllSignatures:!1})).toString("base64")}catch{throw X.invalidTransactionFormat("Invalid base64 transaction format")}}}}class C0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new q8,this._walletStrategy=new Q8(Q),this._delegationStrategy=new _8(Q)}getConfig(){return this.config}registerAdapter(Q,$){this.adapters[Q]=$}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}async generate(Q,$,Z,q){if(!Z||!P8.includes(Z))throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=m8($),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode(Y,Z,J)}else{let Y=$,J=m8(Y.delegatedPubkey),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return this.delegationStrategy.generateDelegatedCode(Y,J,Z,U)}}async revoke(Q,$,Z,q){if(!Z||!P8.includes(Z))throw X.invalidAdapter(Z);if(!q||typeof q!=="function")throw X.invalidSignature("Missing signature function");if(Q==="wallet"){let Y=c({codeHash:u($.code),pubkey:$.pubkey,windowStart:$.timestamp}),J=await q(Y,Z);if(!J)throw X.invalidSignature("Missing signature over canonical message");return{...$,revokeSignature:J}}else{let Y=$,J=c({codeHash:u($.code),pubkey:Y.delegationProof.delegatedPubkey,windowStart:$.timestamp}),U=await q(J,Z);if(!U)throw X.invalidSignature("Missing delegated signature");return{...$,revokeSignature:U}}}validate(Q,$){if(Q==="wallet"){this.walletStrategy.validateCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithWallet($))throw X.invalidSignature("Wallet signature verification failed")}else{this.delegationStrategy.validateDelegatedCode($);let Z=this.getAdapter($.chain);if(!Z)throw X.invalidAdapter($.chain);if(!Z.verifyWithDelegation($))throw X.invalidSignature("Delegation signature verification failed")}}}export{KQ as validateProtocolMetaFormat,T8 as truncateBits,E0 as sha256,b8 as serializeDelegationProof,c as serializeCanonicalRevoke,f as serializeCanonical,N8 as parseProtocolMeta,k8 as hmacSha256,o0 as hkdfSha256,m8 as getCanonicalMessageParts,I8 as digestToDigits,u as codeHash,S8 as buildProtocolMeta,QQ as base32EncodeCrockford,Q8 as WalletStrategy,Y0 as TransactionNotSignedByIntendedOwnerError,q8 as SolanaAdapter,P8 as SUPPORTED_CHAINS,H8 as SCHEME,P0 as ProtocolErrorCode,X as ProtocolError,B8 as PROTOCOL_NORMALIZATION,o as PROTOCOL_META_MAX_BYTES,Z0 as MissingMetaError,q0 as MetaMismatchError,X0 as InvalidSignatureError,J0 as InvalidPubkeyFormatError,U0 as InvalidCodeFormatError,z0 as InvalidAdapterError,$0 as ExpiredCodeError,_8 as DelegationStrategy,y8 as CODE_MIN_LENGTH,E8 as CODE_MAX_LENGTH,JQ as CODE_DEFAULT_LENGTH,XQ as CODE_CHARSET_DIGITS,S0 as CANONICAL_REVOKE_MESSAGE_PREFIX,K0 as CANONICAL_MESSAGE_VERSION,H0 as CANONICAL_MESSAGE_PREFIX,F8 as BaseChainAdapter,C0 as ActionCodesProtocol,n as ADAPTER_CHAIN_NAME};
2
2
 
3
- //# debugId=735D358405976EF364756E2164756E21
3
+ //# debugId=38619AD1907C6B5664756E2164756E21