viveworker 0.7.0-beta.3 → 0.8.0
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/README.md +33 -4
- package/package.json +7 -3
- package/scripts/lib/remote-pairing/README.md +164 -0
- package/scripts/lib/remote-pairing/_browser-bundle-entry.mjs +86 -0
- package/scripts/lib/remote-pairing/audit.mjs +122 -0
- package/scripts/lib/remote-pairing/bridge-relay-client.mjs +737 -0
- package/scripts/lib/remote-pairing/control.mjs +156 -0
- package/scripts/lib/remote-pairing/envelope.mjs +224 -0
- package/scripts/lib/remote-pairing/http-dispatch.mjs +530 -0
- package/scripts/lib/remote-pairing/keys-core.mjs +110 -0
- package/scripts/lib/remote-pairing/keys.mjs +181 -0
- package/scripts/lib/remote-pairing/noise.mjs +436 -0
- package/scripts/lib/remote-pairing/orchestrator.mjs +356 -0
- package/scripts/lib/remote-pairing/pairings.mjs +446 -0
- package/scripts/lib/remote-pairing/rpc.mjs +381 -0
- package/scripts/moltbook-scout-auto.sh +16 -8
- package/scripts/share-cli.mjs +14 -130
- package/scripts/viveworker-bridge.mjs +1696 -223
- package/scripts/viveworker.mjs +27 -6
- package/web/app.css +727 -9
- package/web/app.js +1810 -232
- package/web/i18n.js +207 -17
- package/web/index.html +115 -1
- package/web/remote-pairing/api-router.js +873 -0
- package/web/remote-pairing/keys.js +237 -0
- package/web/remote-pairing/pairing-state.js +313 -0
- package/web/remote-pairing/rpc-client.js +765 -0
- package/web/remote-pairing/transport.js +804 -0
- package/web/remote-pairing/wake.js +149 -0
- package/web/remote-pairing-test.html +400 -0
- package/web/remote-pairing.bundle.js +3 -0
- package/web/remote-pairing.bundle.js.LEGAL.txt +15 -0
- package/web/remote-pairing.bundle.js.map +7 -0
- package/web/sw.js +190 -20
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"// remote-pairing.bundle.js — generated by scripts/build-remote-pairing-bundle.mjs\n// Source modules: scripts/lib/remote-pairing/{noise,envelope,keys-core}.mjs + @noble/*\n// DO NOT EDIT BY HAND — re-run the build script after touching the source modules."
|
|
2
|
+
function Gt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function he(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function Ot(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Gt(t.outputLen),Gt(t.blockLen)}function St(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function We(t,e){he(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var kt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var je=t=>t instanceof Uint8Array;var Vt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),st=(t,e)=>t<<32-e|t>>>e,sr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!sr)throw new Error("Non little-endian hardware is not supported");function ue(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function pt(t){if(typeof t=="string"&&(t=ue(t)),!je(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Qe(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!je(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}var Lt=class{clone(){return this._cloneInto()}},ys={}.toString;function Yt(t){let e=r=>t().update(pt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function le(t=32){if(kt&&typeof kt.getRandomValues=="function")return kt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function ir(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),f=r?4:0,h=r?0:4;t.setUint32(e+f,i,r),t.setUint32(e+h,c,r)}var Ut=class extends Lt{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Vt(this.buffer)}update(e){St(this);let{view:n,buffer:r,blockLen:o}=this;e=pt(e);let s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=Vt(e);for(;o<=s-i;i+=o)this.process(f,i);continue}r.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){St(this),We(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:s}=this,{pos:i}=this;n[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(r,0),i=0);for(let l=i;l<o;l++)n[l]=0;ir(r,o-8,BigInt(this.length*8),s),this.process(r,0);let c=Vt(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=f/4,a=this.get();if(h>a.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<h;l++)c.setUint32(4*l,a[l],s)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:c}=this;return e.length=o,e.pos=c,e.finished=s,e.destroyed=i,o%n&&e.buffer.set(r),e}};var Xt=BigInt(4294967295),de=BigInt(32);function Je(t,e=!1){return e?{h:Number(t&Xt),l:Number(t>>de&Xt)}:{h:Number(t>>de&Xt)|0,l:Number(t&Xt)|0}}function cr(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let o=0;o<t.length;o++){let{h:s,l:i}=Je(t[o],e);[n[o],r[o]]=[s,i]}return[n,r]}var fr=(t,e)=>BigInt(t>>>0)<<de|BigInt(e>>>0),ar=(t,e,n)=>t>>>n,hr=(t,e,n)=>t<<32-n|e>>>n,ur=(t,e,n)=>t>>>n|e<<32-n,lr=(t,e,n)=>t<<32-n|e>>>n,dr=(t,e,n)=>t<<64-n|e>>>n-32,pr=(t,e,n)=>t>>>n-32|e<<64-n,xr=(t,e)=>e,yr=(t,e)=>t,gr=(t,e,n)=>t<<n|e>>>32-n,wr=(t,e,n)=>e<<n|t>>>32-n,Er=(t,e,n)=>e<<n-32|t>>>64-n,br=(t,e,n)=>t<<n-32|e>>>64-n;function mr(t,e,n,r){let o=(e>>>0)+(r>>>0);return{h:t+n+(o/2**32|0)|0,l:o|0}}var Ar=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),_r=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Br=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Rr=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,Sr=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),Lr=(t,e,n,r,o,s)=>e+n+r+o+s+(t/2**32|0)|0;var Ur={fromBig:Je,split:cr,toBig:fr,shrSH:ar,shrSL:hr,rotrSH:ur,rotrSL:lr,rotrBH:dr,rotrBL:pr,rotr32H:xr,rotr32L:yr,rotlSH:gr,rotlSL:wr,rotlBH:Er,rotlBL:br,add:mr,add3L:Ar,add3H:_r,add4L:Br,add4H:Rr,add5H:Lr,add5L:Sr},N=Ur;var[Ir,Tr]=N.split(["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(t=>BigInt(t))),xt=new Uint32Array(80),yt=new Uint32Array(80),pe=class extends Ut{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:n,Bh:r,Bl:o,Ch:s,Cl:i,Dh:c,Dl:f,Eh:h,El:a,Fh:l,Fl:x,Gh:w,Gl:E,Hh:m,Hl:g}=this;return[e,n,r,o,s,i,c,f,h,a,l,x,w,E,m,g]}set(e,n,r,o,s,i,c,f,h,a,l,x,w,E,m,g){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=f|0,this.Eh=h|0,this.El=a|0,this.Fh=l|0,this.Fl=x|0,this.Gh=w|0,this.Gl=E|0,this.Hh=m|0,this.Hl=g|0}process(e,n){for(let d=0;d<16;d++,n+=4)xt[d]=e.getUint32(n),yt[d]=e.getUint32(n+=4);for(let d=16;d<80;d++){let R=xt[d-15]|0,B=yt[d-15]|0,F=N.rotrSH(R,B,1)^N.rotrSH(R,B,8)^N.shrSH(R,B,7),V=N.rotrSL(R,B,1)^N.rotrSL(R,B,8)^N.shrSL(R,B,7),M=xt[d-2]|0,L=yt[d-2]|0,O=N.rotrSH(M,L,19)^N.rotrBH(M,L,61)^N.shrSH(M,L,6),T=N.rotrSL(M,L,19)^N.rotrBL(M,L,61)^N.shrSL(M,L,6),v=N.add4L(V,T,yt[d-7],yt[d-16]),U=N.add4H(v,F,O,xt[d-7],xt[d-16]);xt[d]=U|0,yt[d]=v|0}let{Ah:r,Al:o,Bh:s,Bl:i,Ch:c,Cl:f,Dh:h,Dl:a,Eh:l,El:x,Fh:w,Fl:E,Gh:m,Gl:g,Hh:S,Hl:I}=this;for(let d=0;d<80;d++){let R=N.rotrSH(l,x,14)^N.rotrSH(l,x,18)^N.rotrBH(l,x,41),B=N.rotrSL(l,x,14)^N.rotrSL(l,x,18)^N.rotrBL(l,x,41),F=l&w^~l&m,V=x&E^~x&g,M=N.add5L(I,B,V,Tr[d],yt[d]),L=N.add5H(M,S,R,F,Ir[d],xt[d]),O=M|0,T=N.rotrSH(r,o,28)^N.rotrBH(r,o,34)^N.rotrBH(r,o,39),v=N.rotrSL(r,o,28)^N.rotrBL(r,o,34)^N.rotrBL(r,o,39),U=r&s^r&c^s&c,K=o&i^o&f^i&f;S=m|0,I=g|0,m=w|0,g=E|0,w=l|0,E=x|0,{h:l,l:x}=N.add(h|0,a|0,L|0,O|0),h=c|0,a=f|0,c=s|0,f=i|0,s=r|0,i=o|0;let q=N.add3L(O,v,K);r=N.add3H(q,L,T,U),o=q|0}({h:r,l:o}=N.add(this.Ah|0,this.Al|0,r|0,o|0)),{h:s,l:i}=N.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:f}=N.add(this.Ch|0,this.Cl|0,c|0,f|0),{h,l:a}=N.add(this.Dh|0,this.Dl|0,h|0,a|0),{h:l,l:x}=N.add(this.Eh|0,this.El|0,l|0,x|0),{h:w,l:E}=N.add(this.Fh|0,this.Fl|0,w|0,E|0),{h:m,l:g}=N.add(this.Gh|0,this.Gl|0,m|0,g|0),{h:S,l:I}=N.add(this.Hh|0,this.Hl|0,S|0,I|0),this.set(r,o,s,i,c,f,h,a,l,x,w,E,m,g,S,I)}roundClean(){xt.fill(0),yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var xe=Yt(()=>new pe);var Ss=BigInt(0),Hr=BigInt(1),Nr=BigInt(2),Zt=t=>t instanceof Uint8Array,Or=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function zt(t){if(!Zt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Or[t[n]];return e}function tn(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function en(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){let o=r*2,s=t.slice(o,o+2),i=Number.parseInt(s,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[r]=i}return n}function nn(t){return tn(zt(t))}function at(t){if(!Zt(t))throw new Error("Uint8Array expected");return tn(zt(Uint8Array.from(t).reverse()))}function ye(t,e){return en(t.toString(16).padStart(e*2,"0"))}function At(t,e){return ye(t,e).reverse()}function et(t,e,n){let r;if(typeof e=="string")try{r=en(e)}catch(s){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${s}`)}else if(Zt(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function ge(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!Zt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length}),e}var rn=t=>(Nr<<BigInt(t-1))-Hr;var Mr={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||t instanceof Uint8Array,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function gt(t,e,n={}){let r=(o,s,i)=>{let c=Mr[s];if(typeof c!="function")throw new Error(`Invalid validator "${s}", expected function`);let f=t[o];if(!(i&&f===void 0)&&!c(f,t))throw new Error(`Invalid param ${String(o)}=${f} (${typeof f}), expected ${s}`)};for(let[o,s]of Object.entries(e))r(o,s,!1);for(let[o,s]of Object.entries(n))r(o,s,!0);return t}var W=BigInt(0),Z=BigInt(1),_t=BigInt(2),Cr=BigInt(3),we=BigInt(4),on=BigInt(5),sn=BigInt(8),Dr=BigInt(9),Fr=BigInt(16);function Y(t,e){let n=t%e;return n>=W?n:e+n}function Ee(t,e,n){if(n<=W||e<W)throw new Error("Expected power/modulo > 0");if(n===Z)return W;let r=Z;for(;e>W;)e&Z&&(r=r*t%n),t=t*t%n,e>>=Z;return r}function ot(t,e,n){let r=t;for(;e-- >W;)r*=r,r%=n;return r}function cn(t,e){if(t===W||e<=W)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=Y(t,e),r=e,o=W,s=Z,i=Z,c=W;for(;n!==W;){let h=r/n,a=r%n,l=o-i*h,x=s-c*h;r=n,n=a,o=i,s=c,i=l,c=x}if(r!==Z)throw new Error("invert: does not exist");return Y(o,e)}function qr(t){let e=(t-Z)/_t,n,r,o;for(n=t-Z,r=0;n%_t===W;n/=_t,r++);for(o=_t;o<t&&Ee(o,e,t)!==t-Z;o++);if(r===1){let i=(t+Z)/we;return function(f,h){let a=f.pow(h,i);if(!f.eql(f.sqr(a),h))throw new Error("Cannot find square root");return a}}let s=(n+Z)/_t;return function(c,f){if(c.pow(f,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let h=r,a=c.pow(c.mul(c.ONE,o),n),l=c.pow(f,s),x=c.pow(f,n);for(;!c.eql(x,c.ONE);){if(c.eql(x,c.ZERO))return c.ZERO;let w=1;for(let m=c.sqr(x);w<h&&!c.eql(m,c.ONE);w++)m=c.sqr(m);let E=c.pow(a,Z<<BigInt(h-w-1));a=c.sqr(E),l=c.mul(l,E),x=c.mul(x,a),h=w}return l}}function Pr(t){if(t%we===Cr){let e=(t+Z)/we;return function(r,o){let s=r.pow(o,e);if(!r.eql(r.sqr(s),o))throw new Error("Cannot find square root");return s}}if(t%sn===on){let e=(t-on)/sn;return function(r,o){let s=r.mul(o,_t),i=r.pow(s,e),c=r.mul(o,i),f=r.mul(r.mul(c,_t),i),h=r.mul(c,r.sub(f,r.ONE));if(!r.eql(r.sqr(h),o))throw new Error("Cannot find square root");return h}}return t%Fr,qr(t)}var fn=(t,e)=>(Y(t,e)&Z)===Z,$r=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function an(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=$r.reduce((r,o)=>(r[o]="function",r),e);return gt(t,n)}function Kr(t,e,n){if(n<W)throw new Error("Expected power > 0");if(n===W)return t.ONE;if(n===Z)return e;let r=t.ONE,o=e;for(;n>W;)n&Z&&(r=t.mul(r,o)),o=t.sqr(o),n>>=Z;return r}function Gr(t,e){let n=new Array(e.length),r=e.reduce((s,i,c)=>t.is0(i)?s:(n[c]=s,t.mul(s,i)),t.ONE),o=t.inv(r);return e.reduceRight((s,i,c)=>t.is0(i)?s:(n[c]=t.mul(s,n[c]),t.mul(s,i)),o),n}function be(t,e){let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function hn(t,e,n=!1,r={}){if(t<=W)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:o,nByteLength:s}=be(t,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=Pr(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:s,MASK:rn(o),ZERO:W,ONE:Z,create:f=>Y(f,t),isValid:f=>{if(typeof f!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof f}`);return W<=f&&f<t},is0:f=>f===W,isOdd:f=>(f&Z)===Z,neg:f=>Y(-f,t),eql:(f,h)=>f===h,sqr:f=>Y(f*f,t),add:(f,h)=>Y(f+h,t),sub:(f,h)=>Y(f-h,t),mul:(f,h)=>Y(f*h,t),pow:(f,h)=>Kr(c,f,h),div:(f,h)=>Y(f*cn(h,t),t),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>cn(f,t),sqrt:r.sqrt||(f=>i(c,f)),invertBatch:f=>Gr(c,f),cmov:(f,h,a)=>a?h:f,toBytes:f=>n?At(f,s):ye(f,s),fromBytes:f=>{if(f.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${f.length}`);return n?at(f):nn(f)}});return Object.freeze(c)}function un(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let n=t.sqrt(e);return t.isOdd(n)?t.neg(n):n}var kr=BigInt(0),me=BigInt(1);function ln(t,e){let n=(o,s)=>{let i=s.negate();return o?i:s},r=o=>{let s=Math.ceil(e/o)+1,i=2**(o-1);return{windows:s,windowSize:i}};return{constTimeNegate:n,unsafeLadder(o,s){let i=t.ZERO,c=o;for(;s>kr;)s&me&&(i=i.add(c)),c=c.double(),s>>=me;return i},precomputeWindow(o,s){let{windows:i,windowSize:c}=r(s),f=[],h=o,a=h;for(let l=0;l<i;l++){a=h,f.push(a);for(let x=1;x<c;x++)a=a.add(h),f.push(a);h=a.double()}return f},wNAF(o,s,i){let{windows:c,windowSize:f}=r(o),h=t.ZERO,a=t.BASE,l=BigInt(2**o-1),x=2**o,w=BigInt(o);for(let E=0;E<c;E++){let m=E*f,g=Number(i&l);i>>=w,g>f&&(g-=x,i+=me);let S=m,I=m+Math.abs(g)-1,d=E%2!==0,R=g<0;g===0?a=a.add(n(d,s[S])):h=h.add(n(R,s[I]))}return{p:h,f:a}},wNAFCached(o,s,i,c){let f=o._WINDOW_SIZE||1,h=s.get(o);return h||(h=this.precomputeWindow(o,f),f!==1&&s.set(o,c(h))),this.wNAF(f,h,i)}}}function dn(t){return an(t.Fp),gt(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...be(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var it=BigInt(0),nt=BigInt(1),Wt=BigInt(2),Vr=BigInt(8),Yr={zip215:!0};function Xr(t){let e=dn(t);return gt(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Ae(t){let e=Xr(t),{Fp:n,n:r,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:f}=e,h=Wt<<BigInt(c*8)-nt,a=n.create,l=e.uvRatio||((p,u)=>{try{return{isValid:!0,value:n.sqrt(p*n.inv(u))}}catch{return{isValid:!1,value:it}}}),x=e.adjustScalarBytes||(p=>p),w=e.domain||((p,u,y)=>{if(u.length||y)throw new Error("Contexts/pre-hash are not supported");return p}),E=p=>typeof p=="bigint"&&it<p,m=(p,u)=>E(p)&&E(u)&&p<u,g=p=>p===it||m(p,h);function S(p,u){if(m(p,u))return p;throw new Error(`Expected valid scalar < ${u}, got ${typeof p} ${p}`)}function I(p){return p===it?p:S(p,r)}let d=new Map;function R(p){if(!(p instanceof B))throw new Error("ExtendedPoint expected")}class B{constructor(u,y,A,_){if(this.ex=u,this.ey=y,this.ez=A,this.et=_,!g(u))throw new Error("x required");if(!g(y))throw new Error("y required");if(!g(A))throw new Error("z required");if(!g(_))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(u){if(u instanceof B)throw new Error("extended point not allowed");let{x:y,y:A}=u||{};if(!g(y)||!g(A))throw new Error("invalid affine point");return new B(y,A,nt,a(y*A))}static normalizeZ(u){let y=n.invertBatch(u.map(A=>A.ez));return u.map((A,_)=>A.toAffine(y[_])).map(B.fromAffine)}_setWindowSize(u){this._WINDOW_SIZE=u,d.delete(this)}assertValidity(){let{a:u,d:y}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:A,ey:_,ez:H,et:D}=this,$=a(A*A),C=a(_*_),P=a(H*H),X=a(P*P),z=a($*u),ct=a(P*a(z+C)),tt=a(X+a(y*a($*C)));if(ct!==tt)throw new Error("bad point: equation left != right (1)");let dt=a(A*_),ft=a(H*D);if(dt!==ft)throw new Error("bad point: equation left != right (2)")}equals(u){R(u);let{ex:y,ey:A,ez:_}=this,{ex:H,ey:D,ez:$}=u,C=a(y*$),P=a(H*_),X=a(A*$),z=a(D*_);return C===P&&X===z}is0(){return this.equals(B.ZERO)}negate(){return new B(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:u}=e,{ex:y,ey:A,ez:_}=this,H=a(y*y),D=a(A*A),$=a(Wt*a(_*_)),C=a(u*H),P=y+A,X=a(a(P*P)-H-D),z=C+D,ct=z-$,tt=C-D,dt=a(X*ct),ft=a(z*tt),$t=a(X*tt),Kt=a(ct*z);return new B(dt,ft,Kt,$t)}add(u){R(u);let{a:y,d:A}=e,{ex:_,ey:H,ez:D,et:$}=this,{ex:C,ey:P,ez:X,et:z}=u;if(y===BigInt(-1)){let Ge=a((H-_)*(P+C)),ke=a((H+_)*(P-C)),ae=a(ke-Ge);if(ae===it)return this.double();let Ve=a(D*Wt*z),Ye=a($*Wt*X),Xe=Ye+Ve,Ze=ke+Ge,ze=Ye-Ve,er=a(Xe*ae),nr=a(Ze*ze),rr=a(Xe*ze),or=a(ae*Ze);return new B(er,nr,or,rr)}let ct=a(_*C),tt=a(H*P),dt=a($*A*z),ft=a(D*X),$t=a((_+H)*(C+P)-ct-tt),Kt=ft-dt,$e=ft+dt,Ke=a(tt-y*ct),jn=a($t*Kt),Qn=a($e*Ke),Jn=a($t*Ke),tr=a(Kt*$e);return new B(jn,Qn,tr,Jn)}subtract(u){return this.add(u.negate())}wNAF(u){return M.wNAFCached(this,d,u,B.normalizeZ)}multiply(u){let{p:y,f:A}=this.wNAF(S(u,r));return B.normalizeZ([y,A])[0]}multiplyUnsafe(u){let y=I(u);return y===it?V:this.equals(V)||y===nt?this:this.equals(F)?this.wNAF(y).p:M.unsafeLadder(this,y)}isSmallOrder(){return this.multiplyUnsafe(f).is0()}isTorsionFree(){return M.unsafeLadder(this,r).is0()}toAffine(u){let{ex:y,ey:A,ez:_}=this,H=this.is0();u==null&&(u=H?Vr:n.inv(_));let D=a(y*u),$=a(A*u),C=a(_*u);if(H)return{x:it,y:nt};if(C!==nt)throw new Error("invZ was invalid");return{x:D,y:$}}clearCofactor(){let{h:u}=e;return u===nt?this:this.multiplyUnsafe(u)}static fromHex(u,y=!1){let{d:A,a:_}=e,H=n.BYTES;u=et("pointHex",u,H);let D=u.slice(),$=u[H-1];D[H-1]=$&-129;let C=at(D);C===it||(y?S(C,h):S(C,n.ORDER));let P=a(C*C),X=a(P-nt),z=a(A*P-_),{isValid:ct,value:tt}=l(X,z);if(!ct)throw new Error("Point.fromHex: invalid y coordinate");let dt=(tt&nt)===nt,ft=($&128)!==0;if(!y&&tt===it&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==dt&&(tt=a(-tt)),B.fromAffine({x:tt,y:C})}static fromPrivateKey(u){return T(u).point}toRawBytes(){let{x:u,y}=this.toAffine(),A=At(y,n.BYTES);return A[A.length-1]|=u&nt?128:0,A}toHex(){return zt(this.toRawBytes())}}B.BASE=new B(e.Gx,e.Gy,nt,a(e.Gx*e.Gy)),B.ZERO=new B(it,nt,nt,it);let{BASE:F,ZERO:V}=B,M=ln(B,c*8);function L(p){return Y(p,r)}function O(p){return L(at(p))}function T(p){let u=c;p=et("private key",p,u);let y=et("hashed private key",s(p),2*u),A=x(y.slice(0,u)),_=y.slice(u,2*u),H=O(A),D=F.multiply(H),$=D.toRawBytes();return{head:A,prefix:_,scalar:H,point:D,pointBytes:$}}function v(p){return T(p).pointBytes}function U(p=new Uint8Array,...u){let y=ge(...u);return O(s(w(y,et("context",p),!!o)))}function K(p,u,y={}){p=et("message",p),o&&(p=o(p));let{prefix:A,scalar:_,pointBytes:H}=T(u),D=U(y.context,A,p),$=F.multiply(D).toRawBytes(),C=U(y.context,$,H,p),P=L(D+C*_);I(P);let X=ge($,At(P,n.BYTES));return et("result",X,c*2)}let q=Yr;function G(p,u,y,A=q){let{context:_,zip215:H}=A,D=n.BYTES;p=et("signature",p,2*D),u=et("message",u),o&&(u=o(u));let $=at(p.slice(D,2*D)),C,P,X;try{C=B.fromHex(y,H),P=B.fromHex(p.slice(0,D),H),X=F.multiplyUnsafe($)}catch{return!1}if(!H&&C.isSmallOrder())return!1;let z=U(_,P.toRawBytes(),C.toRawBytes(),u);return P.add(C.multiplyUnsafe(z)).subtract(X).clearCofactor().equals(B.ZERO)}return F._setWindowSize(8),{CURVE:e,getPublicKey:v,sign:K,verify:G,ExtendedPoint:B,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(n.BYTES),precompute(p=8,u=B.BASE){return u._setWindowSize(p),u.multiply(BigInt(3)),u}}}}var Mt=BigInt(0),_e=BigInt(1);function Zr(t){return gt(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function pn(t){let e=Zr(t),{P:n}=e,r=d=>Y(d,n),o=e.montgomeryBits,s=Math.ceil(o/8),i=e.nByteLength,c=e.adjustScalarBytes||(d=>d),f=e.powPminus2||(d=>Ee(d,n-BigInt(2),n));function h(d,R,B){let F=r(d*(R-B));return R=r(R-F),B=r(B+F),[R,B]}function a(d){if(typeof d=="bigint"&&Mt<=d&&d<n)return d;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function x(d,R){let B=a(d),F=a(R),V=B,M=_e,L=Mt,O=B,T=_e,v=Mt,U;for(let q=BigInt(o-1);q>=Mt;q--){let G=F>>q&_e;v^=G,U=h(v,M,O),M=U[0],O=U[1],U=h(v,L,T),L=U[0],T=U[1],v=G;let k=M+L,p=r(k*k),u=M-L,y=r(u*u),A=p-y,_=O+T,H=O-T,D=r(H*k),$=r(_*u),C=D+$,P=D-$;O=r(C*C),T=r(V*r(P*P)),M=r(p*y),L=r(A*(p+r(l*A)))}U=h(v,M,O),M=U[0],O=U[1],U=h(v,L,T),L=U[0],T=U[1];let K=f(L);return r(M*K)}function w(d){return At(r(d),s)}function E(d){let R=et("u coordinate",d,s);return i===s&&(R[i-1]&=127),at(R)}function m(d){let R=et("scalar",d);if(R.length!==s&&R.length!==i)throw new Error(`Expected ${s} or ${i} bytes, got ${R.length}`);return at(c(R))}function g(d,R){let B=E(R),F=m(d),V=x(B,F);if(V===Mt)throw new Error("Invalid private or public key received");return w(V)}let S=w(e.Gu);function I(d){return g(d,S)}return{scalarMult:g,scalarMultBase:I,getSharedSecret:(d,R)=>g(d,R),getPublicKey:d=>I(d),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:S}}var vt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),xn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ks=BigInt(0),zr=BigInt(1),Be=BigInt(2),Wr=BigInt(5),yn=BigInt(10),jr=BigInt(20),Qr=BigInt(40),gn=BigInt(80);function wn(t){let e=vt,r=t*t%e*t%e,o=ot(r,Be,e)*r%e,s=ot(o,zr,e)*t%e,i=ot(s,Wr,e)*s%e,c=ot(i,yn,e)*i%e,f=ot(c,jr,e)*c%e,h=ot(f,Qr,e)*f%e,a=ot(h,gn,e)*h%e,l=ot(a,gn,e)*h%e,x=ot(l,yn,e)*i%e;return{pow_p_5_8:ot(x,Be,e)*t%e,b2:r}}function En(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Jr(t,e){let n=vt,r=Y(e*e*e,n),o=Y(r*r*e,n),s=wn(t*o).pow_p_5_8,i=Y(t*r*s,n),c=Y(e*i*i,n),f=i,h=Y(i*xn,n),a=c===t,l=c===Y(-t,n),x=c===Y(-t*xn,n);return a&&(i=f),(l||x)&&(i=h),fn(i,n)&&(i=Y(-i,n)),{isValid:a||l,value:i}}var ht=hn(vt,void 0,!0),bn={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ht,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:xe,randomBytes:le,adjustScalarBytes:En,uvRatio:Jr};function mn(t,e,n){if(e.length>255)throw new Error("Context is too big");return Qe(ue("SigEd25519 no Ed25519 collisions"),new Uint8Array([n?1:0,e.length]),e,t)}var Vs=Ae({...bn,domain:mn}),Ys=Ae({...bn,domain:mn,prehash:xe}),wt=pn({P:vt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=vt,{pow_p_5_8:n,b2:r}=wn(t);return Y(ot(n,BigInt(3),e)*r,e)},adjustScalarBytes:En,randomBytes:le});var to=(ht.ORDER+BigInt(3))/BigInt(8),Xs=ht.pow(Be,to),Zs=ht.sqrt(ht.neg(ht.ONE)),zs=(ht.ORDER-BigInt(5))/BigInt(8),Ws=BigInt(486662);var js=un(ht,ht.neg(BigInt(486664)));var Qs=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Js=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ti=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ei=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var ni=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function _n(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function jt(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Qt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function J(t,...e){if(!_n(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Re(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Bn(t,e){J(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ut(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function lt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function eo(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var no=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ro(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Jt(t){if(typeof t=="string")t=ro(t);else if(_n(t))t=te(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function Rn(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function Sn(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}var Se=(t,e)=>{function n(r,...o){if(J(r),!no)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){let a=o[0];if(!a)throw new Error("nonce / iv required");t.varSizeNonce?J(a):J(a,t.nonceLength)}let s=t.tagLength;s&&o[1]!==void 0&&J(o[1]);let i=e(r,...o),c=(a,l)=>{if(l!==void 0){if(a!==2)throw new Error("cipher output not supported");J(l)}},f=!1;return{encrypt(a,l){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,J(a),c(i.encrypt.length,l),i.encrypt(a,l)},decrypt(a,l){if(J(a),s&&a.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return c(i.decrypt.length,l),i.decrypt(a,l)}}}return Object.assign(n,t),n};function Le(t,e,n=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(n&&!oo(e))throw new Error("invalid output, must be aligned");return e}function An(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),f=r?4:0,h=r?0:4;t.setUint32(e+f,i,r),t.setUint32(e+h,c,r)}function Ln(t,e,n){jt(n);let r=new Uint8Array(16),o=eo(r);return An(o,0,BigInt(e),n),An(o,8,BigInt(t),n),r}function oo(t){return t.byteOffset%4===0}function te(t){return Uint8Array.from(t)}var In=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),so=In("expand 16-byte k"),io=In("expand 32-byte k"),co=ut(so),fo=ut(io);function b(t,e){return t<<e|t>>>32-e}function Ue(t){return t.byteOffset%4===0}var ee=64,ao=16,Tn=2**32-1,Un=new Uint32Array;function ho(t,e,n,r,o,s,i,c){let f=o.length,h=new Uint8Array(ee),a=ut(h),l=Ue(o)&&Ue(s),x=l?ut(o):Un,w=l?ut(s):Un;for(let E=0;E<f;i++){if(t(e,n,r,a,i,c),i>=Tn)throw new Error("arx: counter overflow");let m=Math.min(ee,f-E);if(l&&m===ee){let g=E/4;if(E%4!==0)throw new Error("arx: invalid block position");for(let S=0,I;S<ao;S++)I=g+S,w[I]=x[I]^a[S];E+=ee;continue}for(let g=0,S;g<m;g++)S=E+g,s[S]=o[S]^h[g];E+=m}}function Ie(t,e){let{allowShortKeys:n,extendNonceFn:r,counterLength:o,counterRight:s,rounds:i}=Rn({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Qt(o),Qt(i),jt(s),jt(n),(c,f,h,a,l=0)=>{J(c),J(f),J(h);let x=h.length;if(a===void 0&&(a=new Uint8Array(x)),J(a),Qt(l),l<0||l>=Tn)throw new Error("arx: counter overflow");if(a.length<x)throw new Error(`arx: output (${a.length}) is shorter than data (${x})`);let w=[],E=c.length,m,g;if(E===32)w.push(m=te(c)),g=fo;else if(E===16&&n)m=new Uint8Array(32),m.set(c),m.set(c,16),g=co,w.push(m);else throw new Error(`arx: invalid 32-byte key, got length=${E}`);Ue(f)||w.push(f=te(f));let S=ut(m);if(r){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(g,S,ut(f.subarray(0,16)),S),f=f.subarray(16)}let I=16-o;if(I!==f.length)throw new Error(`arx: nonce must be ${I} or 16 bytes`);if(I!==12){let R=new Uint8Array(12);R.set(f,s?0:12-f.length),f=R,w.push(f)}let d=ut(f);return ho(t,g,S,d,h,a,l,i),lt(...w),a}}var j=(t,e)=>t[e++]&255|(t[e++]&255)<<8,Te=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Jt(e),J(e,32);let n=j(e,0),r=j(e,2),o=j(e,4),s=j(e,6),i=j(e,8),c=j(e,10),f=j(e,12),h=j(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|c<<2)&8191,this.r[7]=(c>>>11|f<<5)&8065,this.r[8]=(f>>>8|h<<8)&8191,this.r[9]=h>>>5&127;for(let a=0;a<8;a++)this.pad[a]=j(e,16+2*a)}process(e,n,r=!1){let o=r?0:2048,{h:s,r:i}=this,c=i[0],f=i[1],h=i[2],a=i[3],l=i[4],x=i[5],w=i[6],E=i[7],m=i[8],g=i[9],S=j(e,n+0),I=j(e,n+2),d=j(e,n+4),R=j(e,n+6),B=j(e,n+8),F=j(e,n+10),V=j(e,n+12),M=j(e,n+14),L=s[0]+(S&8191),O=s[1]+((S>>>13|I<<3)&8191),T=s[2]+((I>>>10|d<<6)&8191),v=s[3]+((d>>>7|R<<9)&8191),U=s[4]+((R>>>4|B<<12)&8191),K=s[5]+(B>>>1&8191),q=s[6]+((B>>>14|F<<2)&8191),G=s[7]+((F>>>11|V<<5)&8191),k=s[8]+((V>>>8|M<<8)&8191),p=s[9]+(M>>>5|o),u=0,y=u+L*c+O*(5*g)+T*(5*m)+v*(5*E)+U*(5*w);u=y>>>13,y&=8191,y+=K*(5*x)+q*(5*l)+G*(5*a)+k*(5*h)+p*(5*f),u+=y>>>13,y&=8191;let A=u+L*f+O*c+T*(5*g)+v*(5*m)+U*(5*E);u=A>>>13,A&=8191,A+=K*(5*w)+q*(5*x)+G*(5*l)+k*(5*a)+p*(5*h),u+=A>>>13,A&=8191;let _=u+L*h+O*f+T*c+v*(5*g)+U*(5*m);u=_>>>13,_&=8191,_+=K*(5*E)+q*(5*w)+G*(5*x)+k*(5*l)+p*(5*a),u+=_>>>13,_&=8191;let H=u+L*a+O*h+T*f+v*c+U*(5*g);u=H>>>13,H&=8191,H+=K*(5*m)+q*(5*E)+G*(5*w)+k*(5*x)+p*(5*l),u+=H>>>13,H&=8191;let D=u+L*l+O*a+T*h+v*f+U*c;u=D>>>13,D&=8191,D+=K*(5*g)+q*(5*m)+G*(5*E)+k*(5*w)+p*(5*x),u+=D>>>13,D&=8191;let $=u+L*x+O*l+T*a+v*h+U*f;u=$>>>13,$&=8191,$+=K*c+q*(5*g)+G*(5*m)+k*(5*E)+p*(5*w),u+=$>>>13,$&=8191;let C=u+L*w+O*x+T*l+v*a+U*h;u=C>>>13,C&=8191,C+=K*f+q*c+G*(5*g)+k*(5*m)+p*(5*E),u+=C>>>13,C&=8191;let P=u+L*E+O*w+T*x+v*l+U*a;u=P>>>13,P&=8191,P+=K*h+q*f+G*c+k*(5*g)+p*(5*m),u+=P>>>13,P&=8191;let X=u+L*m+O*E+T*w+v*x+U*l;u=X>>>13,X&=8191,X+=K*a+q*h+G*f+k*c+p*(5*g),u+=X>>>13,X&=8191;let z=u+L*g+O*m+T*E+v*w+U*x;u=z>>>13,z&=8191,z+=K*l+q*a+G*h+k*f+p*c,u+=z>>>13,z&=8191,u=(u<<2)+u|0,u=u+y|0,y=u&8191,u=u>>>13,A+=u,s[0]=y,s[1]=A,s[2]=_,s[3]=H,s[4]=D,s[5]=$,s[6]=C,s[7]=P,s[8]=X,s[9]=z}finalize(){let{h:e,pad:n}=this,r=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=o,o=e[c]>>>13,e[c]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,r[0]=e[0]+5,o=r[0]>>>13,r[0]&=8191;for(let c=1;c<10;c++)r[c]=e[c]+o,o=r[c]>>>13,r[c]&=8191;r[9]-=8192;let s=(o^1)-1;for(let c=0;c<10;c++)r[c]&=s;s=~s;for(let c=0;c<10;c++)e[c]=e[c]&s|r[c];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+n[0];e[0]=i&65535;for(let c=1;c<8;c++)i=(e[c]+n[c]|0)+(i>>>16)|0,e[c]=i&65535;lt(r)}update(e){Re(this),e=Jt(e),J(e);let{buffer:n,blockLen:r}=this,o=e.length;for(let s=0;s<o;){let i=Math.min(r-this.pos,o-s);if(i===r){for(;r<=o-s;s+=r)this.process(e,s);continue}n.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){lt(this.h,this.r,this.buffer,this.pad)}digestInto(e){Re(this),Bn(e,this),this.finished=!0;let{buffer:n,h:r}=this,{pos:o}=this;if(o){for(n[o++]=1;o<16;o++)n[o]=0;this.process(n,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)e[s++]=r[i]>>>0,e[s++]=r[i]>>>8;return e}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}};function uo(t){let e=(r,o)=>t(o).update(Jt(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}var Hn=uo(t=>new Te(t));function Mn(t,e,n,r,o,s=20){let i=t[0],c=t[1],f=t[2],h=t[3],a=e[0],l=e[1],x=e[2],w=e[3],E=e[4],m=e[5],g=e[6],S=e[7],I=o,d=n[0],R=n[1],B=n[2],F=i,V=c,M=f,L=h,O=a,T=l,v=x,U=w,K=E,q=m,G=g,k=S,p=I,u=d,y=R,A=B;for(let H=0;H<s;H+=2)F=F+O|0,p=b(p^F,16),K=K+p|0,O=b(O^K,12),F=F+O|0,p=b(p^F,8),K=K+p|0,O=b(O^K,7),V=V+T|0,u=b(u^V,16),q=q+u|0,T=b(T^q,12),V=V+T|0,u=b(u^V,8),q=q+u|0,T=b(T^q,7),M=M+v|0,y=b(y^M,16),G=G+y|0,v=b(v^G,12),M=M+v|0,y=b(y^M,8),G=G+y|0,v=b(v^G,7),L=L+U|0,A=b(A^L,16),k=k+A|0,U=b(U^k,12),L=L+U|0,A=b(A^L,8),k=k+A|0,U=b(U^k,7),F=F+T|0,A=b(A^F,16),G=G+A|0,T=b(T^G,12),F=F+T|0,A=b(A^F,8),G=G+A|0,T=b(T^G,7),V=V+v|0,p=b(p^V,16),k=k+p|0,v=b(v^k,12),V=V+v|0,p=b(p^V,8),k=k+p|0,v=b(v^k,7),M=M+U|0,u=b(u^M,16),K=K+u|0,U=b(U^K,12),M=M+U|0,u=b(u^M,8),K=K+u|0,U=b(U^K,7),L=L+O|0,y=b(y^L,16),q=q+y|0,O=b(O^q,12),L=L+O|0,y=b(y^L,8),q=q+y|0,O=b(O^q,7);let _=0;r[_++]=i+F|0,r[_++]=c+V|0,r[_++]=f+M|0,r[_++]=h+L|0,r[_++]=a+O|0,r[_++]=l+T|0,r[_++]=x+v|0,r[_++]=w+U|0,r[_++]=E+K|0,r[_++]=m+q|0,r[_++]=g+G|0,r[_++]=S+k|0,r[_++]=I+p|0,r[_++]=d+u|0,r[_++]=R+y|0,r[_++]=B+A|0}function lo(t,e,n,r){let o=t[0],s=t[1],i=t[2],c=t[3],f=e[0],h=e[1],a=e[2],l=e[3],x=e[4],w=e[5],E=e[6],m=e[7],g=n[0],S=n[1],I=n[2],d=n[3];for(let B=0;B<20;B+=2)o=o+f|0,g=b(g^o,16),x=x+g|0,f=b(f^x,12),o=o+f|0,g=b(g^o,8),x=x+g|0,f=b(f^x,7),s=s+h|0,S=b(S^s,16),w=w+S|0,h=b(h^w,12),s=s+h|0,S=b(S^s,8),w=w+S|0,h=b(h^w,7),i=i+a|0,I=b(I^i,16),E=E+I|0,a=b(a^E,12),i=i+a|0,I=b(I^i,8),E=E+I|0,a=b(a^E,7),c=c+l|0,d=b(d^c,16),m=m+d|0,l=b(l^m,12),c=c+l|0,d=b(d^c,8),m=m+d|0,l=b(l^m,7),o=o+h|0,d=b(d^o,16),E=E+d|0,h=b(h^E,12),o=o+h|0,d=b(d^o,8),E=E+d|0,h=b(h^E,7),s=s+a|0,g=b(g^s,16),m=m+g|0,a=b(a^m,12),s=s+a|0,g=b(g^s,8),m=m+g|0,a=b(a^m,7),i=i+l|0,S=b(S^i,16),x=x+S|0,l=b(l^x,12),i=i+l|0,S=b(S^i,8),x=x+S|0,l=b(l^x,7),c=c+f|0,I=b(I^c,16),w=w+I|0,f=b(f^w,12),c=c+f|0,I=b(I^c,8),w=w+I|0,f=b(f^w,7);let R=0;r[R++]=o,r[R++]=s,r[R++]=i,r[R++]=c,r[R++]=g,r[R++]=S,r[R++]=I,r[R++]=d}var po=Ie(Mn,{counterRight:!1,counterLength:4,allowShortKeys:!1}),xo=Ie(Mn,{counterRight:!1,counterLength:8,extendNonceFn:lo,allowShortKeys:!1});var yo=new Uint8Array(16),Nn=(t,e)=>{t.update(e);let n=e.length%16;n&&t.update(yo.subarray(n))},go=new Uint8Array(32);function On(t,e,n,r,o){let s=t(e,n,go),i=Hn.create(s);o&&Nn(i,o),Nn(i,r);let c=Ln(r.length,o?o.length:0,!0);i.update(c);let f=i.digest();return lt(s,c),f}var vn=t=>(e,n,r)=>({encrypt(s,i){let c=s.length;i=Le(c+16,i,!1),i.set(s);let f=i.subarray(0,-16);t(e,n,f,f,1);let h=On(t,e,n,f,r);return i.set(h,c),lt(h),i},decrypt(s,i){i=Le(s.length-16,i,!1);let c=s.subarray(0,-16),f=s.subarray(-16),h=On(t,e,n,c,r);if(!Sn(f,h))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),t(e,n,i,i,1),lt(h),i}}),He=Se({blockSize:64,nonceLength:12,tagLength:16},vn(po)),di=Se({blockSize:64,nonceLength:24,tagLength:16},vn(xo));var wo=(t,e,n)=>t&e^~t&n,Eo=(t,e,n)=>t&e^t&n^e&n,bo=new Uint32Array([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]),Et=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),bt=new Uint32Array(64),Ne=class extends Ut{constructor(){super(64,32,8,!1),this.A=Et[0]|0,this.B=Et[1]|0,this.C=Et[2]|0,this.D=Et[3]|0,this.E=Et[4]|0,this.F=Et[5]|0,this.G=Et[6]|0,this.H=Et[7]|0}get(){let{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:f}=this;return[e,n,r,o,s,i,c,f]}set(e,n,r,o,s,i,c,f){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=f|0}process(e,n){for(let l=0;l<16;l++,n+=4)bt[l]=e.getUint32(n,!1);for(let l=16;l<64;l++){let x=bt[l-15],w=bt[l-2],E=st(x,7)^st(x,18)^x>>>3,m=st(w,17)^st(w,19)^w>>>10;bt[l]=m+bt[l-7]+E+bt[l-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:f,G:h,H:a}=this;for(let l=0;l<64;l++){let x=st(c,6)^st(c,11)^st(c,25),w=a+x+wo(c,f,h)+bo[l]+bt[l]|0,m=(st(r,2)^st(r,13)^st(r,22))+Eo(r,o,s)|0;a=h,h=f,f=c,c=i+w|0,i=s,s=o,o=r,r=w+m|0}r=r+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,h=h+this.G|0,a=a+this.H|0,this.set(r,o,s,i,c,f,h,a)}roundClean(){bt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ct=Yt(()=>new Ne);var ne=class extends Lt{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Ot(e);let r=pt(n);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(r.length>o?e.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(e){return St(this),this.iHash.update(e),this}digestInto(e){St(this),he(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:r,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},re=(t,e,n)=>new ne(t,e).update(n).digest();re.create=(t,e)=>new ne(t,e);function mo(t,e,n){return Ot(t),n===void 0&&(n=new Uint8Array(t.outputLen)),re(t,pt(n),pt(e))}var Oe=new Uint8Array([0]),Cn=new Uint8Array;function Ao(t,e,n,r=32){if(Ot(t),Gt(r),r>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");let o=Math.ceil(r/t.outputLen);n===void 0&&(n=Cn);let s=new Uint8Array(o*t.outputLen),i=re.create(t,e),c=i._cloneInto(),f=new Uint8Array(i.outputLen);for(let h=0;h<o;h++)Oe[0]=h+1,c.update(h===0?Cn:f).update(n).update(Oe).digestInto(f),s.set(f,t.outputLen*h),i._cloneInto(c);return i.destroy(),c.destroy(),f.fill(0),Oe.fill(0),s.slice(0,r)}var Dn=(t,e,n,r,o)=>Ao(t,mo(t,e,n),r,o);var De="Noise_IK_25519_ChaChaPoly_SHA256",It=32,oe=32,Bt=32,Me=16,Fn=0xffffffffffffffffn,Ii=new TextEncoder().encode(De);function ve(...t){let e=0;for(let o of t)e+=o.length;let n=new Uint8Array(e),r=0;for(let o of t)n.set(o,r),r+=o.length;return n}function rt(t){if(t==null)return new Uint8Array(0);if(t instanceof Uint8Array)return t;if(typeof t=="string")return new TextEncoder().encode(t);if(Array.isArray(t))return new Uint8Array(t);throw new TypeError(`unsupported input type: ${typeof t}`)}function qn(t){return Ct(t)}function Pn(t,e,n){let r=n*It,o=Dn(Ct,e,t,new Uint8Array(0),r),s=[];for(let i=0;i<n;i++)s.push(o.slice(i*It,(i+1)*It));return s}function $n(){let t=wt.utils.randomPrivateKey(),e=wt.getPublicKey(t);return{priv:t,pub:e}}function mt(t,e){return wt.getSharedSecret(t,e)}function Kn(t){let e=new Uint8Array(12),n=BigInt(t);for(let r=4;r<12;r++)e[r]=Number(n&0xffn),n>>=8n;return e}function _o(t,e,n,r){return He(t,Kn(e),rt(n)).encrypt(rt(r))}function Bo(t,e,n,r){return He(t,Kn(e),rt(n)).decrypt(rt(r))}var Dt=class{constructor(e=null){this.k=e,this.n=0n}hasKey(){return this.k!=null}setKey(e){this.k=e,this.n=0n}encryptWithAd(e,n){if(!this.hasKey())return rt(n);if(this.n>=Fn)throw new Error("nonce exhausted");let r=_o(this.k,this.n,e,n);return this.n+=1n,r}decryptWithAd(e,n){if(!this.hasKey())return rt(n);if(this.n>=Fn)throw new Error("nonce exhausted");let r=Bo(this.k,this.n,e,n);return this.n+=1n,r}},Ce=class{constructor(e){let n=rt(e);n.length<=It?(this.h=new Uint8Array(It),this.h.set(n,0)):this.h=qn(n),this.ck=this.h.slice(),this.cipher=new Dt}mixKey(e){let[n,r]=Pn(this.ck,e,2);this.ck=n,this.cipher.setKey(r.slice(0,oe))}mixHash(e){this.h=qn(ve(this.h,rt(e)))}encryptAndHash(e){let n=this.cipher.encryptWithAd(this.h,e);return this.mixHash(n),n}decryptAndHash(e){let n=this.cipher.decryptWithAd(this.h,e);return this.mixHash(e),n}split(){let[e,n]=Pn(this.ck,new Uint8Array(0),2);return[new Dt(e.slice(0,oe)),new Dt(n.slice(0,oe))]}},Ft=class{constructor({initiator:e,staticKeypair:n,remoteStatic:r,prologue:o=new Uint8Array(0)}){if(typeof e!="boolean")throw new TypeError("initiator must be boolean");if(!n?.priv||!n?.pub)throw new TypeError("staticKeypair required");if(e&&!r)throw new Error("initiator requires remoteStatic (responder's public key)");this.initiator=e,this.s=n,this.rs=r?rt(r):null,this.e=null,this.re=null,this.symmetric=new Ce(De),this.symmetric.mixHash(o),e?this.symmetric.mixHash(this.rs):this.symmetric.mixHash(this.s.pub),this.step=0,this.transportCiphers=null,this.handshakeHash=null}writeMessage(e=new Uint8Array(0)){let n=rt(e);if(this.step===0&&this.initiator){this.e=$n();let r=[];return r.push(this.e.pub),this.symmetric.mixHash(this.e.pub),this.symmetric.mixKey(mt(this.e.priv,this.rs)),r.push(this.symmetric.encryptAndHash(this.s.pub)),this.symmetric.mixKey(mt(this.s.priv,this.rs)),r.push(this.symmetric.encryptAndHash(n)),this.step=1,ve(...r)}if(this.step===1&&!this.initiator){this.e=$n();let r=[];return r.push(this.e.pub),this.symmetric.mixHash(this.e.pub),this.symmetric.mixKey(mt(this.e.priv,this.re)),this.symmetric.mixKey(mt(this.e.priv,this.rs)),r.push(this.symmetric.encryptAndHash(n)),this._finalize(),ve(...r)}throw new Error(`writeMessage called in unexpected state (step=${this.step}, initiator=${this.initiator})`)}readMessage(e){let n=rt(e),r=0;if(this.step===0&&!this.initiator){let o=n.slice(r,r+Bt);r+=Bt,this.re=o,this.symmetric.mixHash(o),this.symmetric.mixKey(mt(this.s.priv,o));let s=n.slice(r,r+Bt+Me);r+=Bt+Me;let i=this.symmetric.decryptAndHash(s);this.rs=i,this.symmetric.mixKey(mt(this.s.priv,i));let c=this.symmetric.decryptAndHash(n.slice(r));return this.step=1,c}if(this.step===1&&this.initiator){let o=n.slice(r,r+Bt);r+=Bt,this.re=o,this.symmetric.mixHash(o),this.symmetric.mixKey(mt(this.e.priv,o)),this.symmetric.mixKey(mt(this.s.priv,o));let s=this.symmetric.decryptAndHash(n.slice(r));return this._finalize(),s}throw new Error(`readMessage called in unexpected state (step=${this.step}, initiator=${this.initiator})`)}_finalize(){this.handshakeHash=this.symmetric.h.slice();let[e,n]=this.symmetric.split();this.transportCiphers=[e,n],this.step=2}isHandshakeFinished(){return this.step===2}intoSession(){if(!this.isHandshakeFinished())throw new Error("handshake not finished");let[e,n]=this.transportCiphers;return new se({initiator:this.initiator,sendCipher:this.initiator?e:n,recvCipher:this.initiator?n:e,handshakeHash:this.handshakeHash,remoteStatic:this.initiator?this.rs:this.rs})}},se=class{constructor({initiator:e,sendCipher:n,recvCipher:r,handshakeHash:o,remoteStatic:s}){this.initiator=e,this.sendCipher=n,this.recvCipher=r,this.handshakeHash=o,this.remoteStatic=s}send(e,n=new Uint8Array(0)){return this.sendCipher.encryptWithAd(rt(n),e)}recv(e,n=new Uint8Array(0)){return this.recvCipher.decryptWithAd(rt(n),e)}getChannelBinding(){return this.handshakeHash.slice()}};function Ro({staticKeypair:t,remoteStatic:e,prologue:n}){return new Ft({initiator:!0,staticKeypair:t,remoteStatic:e,prologue:n})}function So({staticKeypair:t,prologue:e}){return new Ft({initiator:!1,staticKeypair:t,prologue:e})}var Lo=1,Uo=2,Io=3,To=4,Ho=5,No=6,Oo=7,Mo=1,vo=2,Co=3,Do=16;function Gn(t){if(t==null)return new Uint8Array(0);if(t instanceof Uint8Array)return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new TypeError(`unsupported envelope input: ${typeof t}`)}function ie(t,e){return t.getUint32(e,!1)}function ce(t,e,n){if(n<0||n>4294967295)throw new RangeError(`u32 out of range: ${n}`);t.setUint32(e,n>>>0,!1)}function Fo(){let t=new Uint8Array(16);if(typeof globalThis.crypto?.getRandomValues=="function")globalThis.crypto.getRandomValues(t);else for(let e=0;e<16;e++)t[e]=Math.floor(Math.random()*256);return t}function qo(t){let e="";for(let n=0;n<t.length;n++)e+=t[n].toString(16).padStart(2,"0");return e}function Po({seq:t,mid:e,payload:n}){let r=Gn(n);if(e.length!==16)throw new RangeError("mid must be 16 bytes");let o=new Uint8Array(21+r.length),s=new DataView(o.buffer);return o[0]=1,ce(s,1,t),o.set(e,5),o.set(r,21),o}function $o(t){let e=new Uint8Array(5),n=new DataView(e.buffer);return e[0]=2,ce(n,1,t),e}function Ko(){return new Uint8Array([3])}function Go(){return new Uint8Array([4])}function ko(t){let e=new Uint8Array(5),n=new DataView(e.buffer);return e[0]=5,ce(n,1,t),e}function Vo(t){let e=new Uint8Array(5),n=new DataView(e.buffer);return e[0]=6,ce(n,1,t),e}function Yo(t){return new Uint8Array([7,t&255])}function Xo(t){let e=Gn(t);if(e.length<1)throw new Error("envelope: empty frame");let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e[0];switch(r){case 1:{if(e.length<21)throw new Error("envelope: DATA frame too short");let o=ie(n,1),s=e.slice(5,21),i=e.slice(21);return{type:r,seq:o,mid:s,payload:i}}case 2:{if(e.length!==5)throw new Error("envelope: ACK frame wrong length");return{type:r,seq:ie(n,1)}}case 3:if(e.length!==1)throw new Error("envelope: PING frame wrong length");return{type:r};case 4:if(e.length!==1)throw new Error("envelope: PONG frame wrong length");return{type:r};case 5:{if(e.length!==5)throw new Error("envelope: RESUME_REQ frame wrong length");return{type:r,lastSeenSeq:ie(n,1)}}case 6:{if(e.length!==5)throw new Error("envelope: RESUME_OK frame wrong length");return{type:r,currentSeq:ie(n,1)}}case 7:{if(e.length!==2)throw new Error("envelope: RESUME_FAIL frame wrong length");return{type:r,reason:e[1]}}default:throw new Error(`envelope: unknown frame type 0x${r.toString(16)}`)}}function Zo(t){switch(t){case 1:return"DATA";case 2:return"ACK";case 3:return"PING";case 4:return"PONG";case 5:return"RESUME_REQ";case 6:return"RESUME_OK";case 7:return"RESUME_FAIL";default:return`UNKNOWN(0x${t.toString(16)})`}}var kn=32,zo=/^[0-9a-fA-F]+$/;function Wo(t){if(!(t instanceof Uint8Array))throw new TypeError("bytesToHex expects Uint8Array");let e="";for(let n=0;n<t.length;n++)e+=t[n].toString(16).padStart(2,"0");return e}function jo(t){if(typeof t!="string"||t.length===0||t.length%2!==0||!zo.test(t))throw new TypeError(`invalid hex: ${typeof t=="string"?t.slice(0,16):typeof t}\u2026`);let e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++)e[n]=parseInt(t.slice(n*2,n*2+2),16);return e}function Qo(){let t=wt.utils.randomPrivateKey(),e=wt.getPublicKey(t);return{priv:t,pub:e}}function Jo(t){return wt.getPublicKey(t)}function ts(t){if(!(t instanceof Uint8Array))throw new TypeError("pub must be Uint8Array");if(t.length!==kn)throw new RangeError("pub must be 32 bytes");let e=Ct(t),n="0123456789ABCDEFGHJKMNPQRSTVWXYZ",r=0n;for(let s=0;s<8;s++)r=r<<8n|BigInt(e[s]);r>>=4n;let o="";for(let s=0;s<12;s++){let i=Number(r&31n);o=n[i]+o,r>>=5n}return`${o.slice(0,4)}-${o.slice(4,8)}-${o.slice(8,12)}`}var es=new TextEncoder,ns=new TextDecoder("utf-8",{fatal:!0}),Fe=64,qt=64,Rt=8*1024,qe=16,Pe=4*1024,Ht=4*1024*1024,Pt=128,Q=Object.freeze({REQUEST:"req",RESPONSE:"res",CANCEL:"cancel",EVENT:"evt"}),rs=new Set([Q.REQUEST,Q.RESPONSE,Q.CANCEL,Q.EVENT]);function os(t){if(typeof t?.id!="string")throw new TypeError("request.id required (string)");if(typeof t.method!="string")throw new TypeError("request.method required (string)");if(typeof t.path!="string")throw new TypeError("request.path required (string)");Nt(t.id),Vn(t.method),Yn(t.path);let e=Xn(t.headers),{body:n,bodyEncoding:r}=zn(t.body,t.bodyEncoding),o={t:Q.REQUEST,id:t.id,method:t.method,path:t.path};return e&&(o.headers=e),n!==void 0&&(o.body=n,r&&r!=="utf8"&&(o.bodyEncoding=r)),fe(o)}function ss(t){if(typeof t?.id!="string")throw new TypeError("response.id required (string)");if(!Number.isInteger(t.status)||t.status<100||t.status>599)throw new RangeError("response.status must be an integer in [100, 599]");Nt(t.id);let e=Xn(t.headers),{body:n,bodyEncoding:r}=zn(t.body,t.bodyEncoding),o={t:Q.RESPONSE,id:t.id,status:t.status};return e&&(o.headers=e),n!==void 0&&(o.body=n,r&&r!=="utf8"&&(o.bodyEncoding=r)),fe(o)}function is(t){if(typeof t!="string")throw new TypeError("cancel.id required (string)");return Nt(t),fe({t:Q.CANCEL,id:t})}function cs(t){if(typeof t?.topic!="string")throw new TypeError("event.topic required (string)");if(t.topic.length>Pt)throw new RangeError(`event.topic exceeds ${Pt} chars`);let e={t:Q.EVENT,topic:t.topic};return t.data!==void 0&&(e.data=t.data),fe(e)}function fs(t){if(!(t instanceof Uint8Array))throw new TypeError("decode requires Uint8Array");if(t.length>Ht+64*1024)throw new RangeError(`rpc frame too large: ${t.length} bytes`);let e;try{e=ns.decode(t)}catch(o){throw new Error(`rpc frame: invalid UTF-8 (${o.message})`)}let n;try{n=JSON.parse(e)}catch(o){throw new Error(`rpc frame: invalid JSON (${o.message})`)}if(n==null||typeof n!="object"||Array.isArray(n))throw new Error("rpc frame: not a JSON object");let r=n.t;if(typeof r!="string"||!rs.has(r))throw new Error(`rpc frame: unknown type ${JSON.stringify(r)}`);switch(r){case Q.REQUEST:return as(n);case Q.RESPONSE:return hs(n);case Q.CANCEL:return us(n);case Q.EVENT:return ls(n)}throw new Error("unreachable")}function as(t){let e=Tt(t.id,"id"),n=Tt(t.method,"method"),r=Tt(t.path,"path");Nt(e),Vn(n),Yn(r);let o=Zn(t.headers),{body:s,bodyEncoding:i}=Wn(t);return{type:Q.REQUEST,id:e,method:n,path:r,headers:o,body:s,bodyEncoding:i}}function hs(t){let e=Tt(t.id,"id");Nt(e);let n=t.status;if(!Number.isInteger(n)||n<100||n>599)throw new RangeError("response.status must be an integer in [100, 599]");let r=Zn(t.headers),{body:o,bodyEncoding:s}=Wn(t);return{type:Q.RESPONSE,id:e,status:n,headers:r,body:o,bodyEncoding:s}}function us(t){let e=Tt(t.id,"id");return Nt(e),{type:Q.CANCEL,id:e}}function ls(t){let e=Tt(t.topic,"topic");if(e.length>Pt)throw new RangeError(`event.topic exceeds ${Pt} chars`);return{type:Q.EVENT,topic:e,data:t.data}}function Tt(t,e){if(typeof t!="string")throw new TypeError(`${e} required (string)`);return t}function Nt(t){if(t.length===0)throw new RangeError("id must be non-empty");if(t.length>Fe)throw new RangeError(`id exceeds ${Fe} chars`)}function Vn(t){if(t.length===0)throw new RangeError("method must be non-empty");if(t.length>qe)throw new RangeError(`method exceeds ${qe} chars`)}function Yn(t){if(!t.startsWith("/"))throw new RangeError(`path must start with "/" (got ${JSON.stringify(t.slice(0,32))})`);if(t.length>Pe)throw new RangeError(`path exceeds ${Pe} chars`)}function Xn(t){if(t==null)return;if(typeof t!="object"||Array.isArray(t))throw new TypeError("headers must be a plain object");let e=Object.entries(t);if(e.length===0)return;if(e.length>qt)throw new RangeError(`headers exceeds ${qt} entries`);let n={};for(let[r,o]of e){if(typeof r!="string"||typeof o!="string")throw new TypeError(`headers must be string\u2192string (got ${r}=${typeof o})`);if(r.length>Rt||o.length>Rt)throw new RangeError(`header ${JSON.stringify(r)} exceeds ${Rt} chars`);n[r.toLowerCase()]=o}return n}function Zn(t){if(t==null)return{};if(typeof t!="object"||Array.isArray(t))throw new Error("headers must be a JSON object");let e=Object.entries(t);if(e.length>qt)throw new RangeError(`headers exceeds ${qt} entries`);let n={};for(let[r,o]of e){if(typeof r!="string"||typeof o!="string")throw new Error(`headers must be string\u2192string (got ${r}=${typeof o})`);if(r.length>Rt||o.length>Rt)throw new RangeError(`header ${JSON.stringify(r)} exceeds ${Rt} chars`);n[r.toLowerCase()]=o}return n}function zn(t,e){if(t==null||t==="")return{body:void 0};if(typeof t!="string")throw new TypeError('body must be a string (binary callers: base64-encode and set bodyEncoding="base64")');if(e!=null&&e!=="utf8"&&e!=="base64")throw new RangeError(`bodyEncoding must be "utf8" or "base64" (got ${JSON.stringify(e)})`);if(t.length>Ht)throw new RangeError(`body exceeds ${Ht} chars`);return{body:t,bodyEncoding:e??"utf8"}}function Wn(t){if(t.body===void 0)return{body:void 0};if(typeof t.body!="string")throw new Error("body must be a string");if(t.body.length>Ht)throw new RangeError(`body exceeds ${Ht} chars`);let e="utf8";if(t.bodyEncoding!==void 0){if(t.bodyEncoding!=="utf8"&&t.bodyEncoding!=="base64")throw new Error('bodyEncoding must be "utf8" or "base64"');e=t.bodyEncoding}return{body:t.body,bodyEncoding:e}}function fe(t){return es.encode(JSON.stringify(t))}export{Bt as DHLEN,Uo as FRAME_ACK,Lo as FRAME_DATA,Io as FRAME_PING,To as FRAME_PONG,Oo as FRAME_RESUME_FAIL,No as FRAME_RESUME_OK,Ho as FRAME_RESUME_REQ,It as HASHLEN,Ft as HandshakeState,kn as IDENTITY_KEY_BYTES,oe as KEYLEN,Ht as MAX_BODY_BYTES,qt as MAX_HEADERS,Rt as MAX_HEADER_LEN,qe as MAX_METHOD_LEN,Pe as MAX_PATH_LEN,Fe as MAX_RPC_ID_LEN,Pt as MAX_TOPIC_LEN,Do as MID_BYTES,se as NoiseSession,De as PROTOCOL_NAME,Mo as RESUME_FAIL_BUFFER_EXPIRED,Co as RESUME_FAIL_HIBERNATED,vo as RESUME_FAIL_UNKNOWN_PAIRING,Q as RPC,Me as TAGLEN,Wo as bytesToHex,Ro as createInitiator,So as createResponder,Xo as decode,fs as decodeRpc,$o as encodeAck,is as encodeCancel,Po as encodeData,cs as encodeEvent,Ko as encodePing,Go as encodePong,os as encodeRequest,ss as encodeResponse,Yo as encodeResumeFail,Vo as encodeResumeOk,ko as encodeResumeReq,ts as fingerprintIdentity,Zo as frameTypeName,Qo as generateIdentityKeypair,Fo as generateMid,jo as hexToBytes,qo as midToHex,Jo as publicFromPrivate};
|
|
3
|
+
//# sourceMappingURL=remote-pairing.bundle.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Bundled license information:
|
|
2
|
+
|
|
3
|
+
@noble/hashes/esm/utils.js:
|
|
4
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
|
|
6
|
+
@noble/curves/esm/abstract/utils.js:
|
|
7
|
+
@noble/curves/esm/abstract/modular.js:
|
|
8
|
+
@noble/curves/esm/abstract/curve.js:
|
|
9
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
10
|
+
@noble/curves/esm/abstract/montgomery.js:
|
|
11
|
+
@noble/curves/esm/ed25519.js:
|
|
12
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
+
|
|
14
|
+
@noble/ciphers/esm/utils.js:
|
|
15
|
+
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|