From 681800faefb3717b1cbaf52c9b5f5b18ff15f96c Mon Sep 17 00:00:00 2001 From: dajiaji Date: Wed, 26 Jul 2023 22:16:30 +0000 Subject: [PATCH] deploy: 1144b8c33937a1a76bb852601af6737167f5d30b --- dhkemSecp256k1HkdfSha256/index.html | 87 ----------------- dhkemSecp256k1HkdfSha256/src/.gitkeep | 0 .../src/hpke-dhkemSecp256k1HkdfSha256.js | 36 ------- dhkemSecp256k1HkdfSha256/src/hpke.js | 30 ------ index.html | 95 ------------------- src/.gitkeep | 0 src/hpke.js | 30 ------ 7 files changed, 278 deletions(-) delete mode 100644 dhkemSecp256k1HkdfSha256/index.html delete mode 100644 dhkemSecp256k1HkdfSha256/src/.gitkeep delete mode 100644 dhkemSecp256k1HkdfSha256/src/hpke-dhkemSecp256k1HkdfSha256.js delete mode 100644 dhkemSecp256k1HkdfSha256/src/hpke.js delete mode 100644 index.html delete mode 100644 src/.gitkeep delete mode 100644 src/hpke.js diff --git a/dhkemSecp256k1HkdfSha256/index.html b/dhkemSecp256k1HkdfSha256/index.html deleted file mode 100644 index ec8d4ab76..000000000 --- a/dhkemSecp256k1HkdfSha256/index.html +++ /dev/null @@ -1,87 +0,0 @@ - - hpke-js test - - - -

hpke-js test

- -
- - -
- -
- -
- - - - - - - - - -
pass: -
fail: -
-
- - diff --git a/dhkemSecp256k1HkdfSha256/src/.gitkeep b/dhkemSecp256k1HkdfSha256/src/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/dhkemSecp256k1HkdfSha256/src/hpke-dhkemSecp256k1HkdfSha256.js b/dhkemSecp256k1HkdfSha256/src/hpke-dhkemSecp256k1HkdfSha256.js deleted file mode 100644 index 382f74c15..000000000 --- a/dhkemSecp256k1HkdfSha256/src/hpke-dhkemSecp256k1HkdfSha256.js +++ /dev/null @@ -1,36 +0,0 @@ -var Jr=Object.defineProperty;var tn=(r,t)=>{for(var e in t)Jr(r,e,{get:t[e],enumerable:!0})};function Ae(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function en(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function or(r,...t){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(r.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${r.length}`)}function rn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ae(r.outputLen),Ae(r.blockLen)}function nn(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function on(r,t){or(r);let e=t.outputLen;if(r.lengthr instanceof Uint8Array;var cr=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),ne=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),at=(r,t)=>r<<32-t|r>>>t,cn=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!cn)throw new Error("Non little-endian hardware is not supported");var Xi=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Et(r){if(typeof r=="string"&&(r=Mt(r)),!sr(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Ct(...r){let t=new Uint8Array(r.reduce((n,i)=>n+i.length,0)),e=0;return r.forEach(n=>{if(!sr(n))throw new Error("Uint8Array expected");t.set(n,e),e+=n.length}),t}var gt=class{clone(){return this._cloneInto()}};function rt(r){let t=n=>r().update(Et(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ar(r){let t=(n,i)=>r(i).update(Et(n)).digest(),e=r({});return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}function Kt(r=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function an(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let i=BigInt(32),c=BigInt(4294967295),o=Number(e>>i&c),s=Number(e&c),a=n?4:0,u=n?0:4;r.setUint32(t+a,o,n),r.setUint32(t+u,s,n)}var Dt=class extends gt{constructor(t,e,n,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=ne(this.buffer)}update(t){et.exists(this);let{view:e,buffer:n,blockLen:i}=this;t=Et(t);let c=t.length;for(let o=0;oi-o&&(this.process(n,0),o=0);for(let l=o;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;lr&t^~r&e,un=(r,t,e)=>r&t^r&e^t&e,ln=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]),_t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vt=new Uint32Array(64),ie=class extends Dt{constructor(){super(64,32,8,!1),this.A=_t[0]|0,this.B=_t[1]|0,this.C=_t[2]|0,this.D=_t[3]|0,this.E=_t[4]|0,this.F=_t[5]|0,this.G=_t[6]|0,this.H=_t[7]|0}get(){let{A:t,B:e,C:n,D:i,E:c,F:o,G:s,H:a}=this;return[t,e,n,i,c,o,s,a]}set(t,e,n,i,c,o,s,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=i|0,this.E=c|0,this.F=o|0,this.G=s|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)vt[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let w=vt[l-15],P=vt[l-2],v=at(w,7)^at(w,18)^w>>>3,d=at(P,17)^at(P,19)^P>>>10;vt[l]=d+vt[l-7]+v+vt[l-16]|0}let{A:n,B:i,C:c,D:o,E:s,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let w=at(s,6)^at(s,11)^at(s,25),P=f+w+fn(s,a,u)+ln[l]+vt[l]|0,d=(at(n,2)^at(n,13)^at(n,22))+un(n,i,c)|0;f=u,u=a,a=s,s=o+P|0,o=c,c=i,i=n,n=P+d|0}n=n+this.A|0,i=i+this.B|0,c=c+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,c,o,s,a,u,f)}roundClean(){vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Pe=class extends ie{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}},oe=rt(()=>new ie),ro=rt(()=>new Pe);var ae={};tn(ae,{bitGet:()=>yn,bitLen:()=>pn,bitMask:()=>Zt,bitSet:()=>xn,bytesToHex:()=>dt,bytesToNumberBE:()=>ft,bytesToNumberLE:()=>ht,concatBytes:()=>ut,createHmacDrbg:()=>Le,ensureBytes:()=>M,equalBytes:()=>dr,hexToBytes:()=>Ot,hexToNumber:()=>ke,numberToBytesBE:()=>yt,numberToBytesLE:()=>Bt,numberToHexUnpadded:()=>lr,numberToVarBytesBE:()=>bn,utf8ToBytes:()=>hr,validateObject:()=>ot});var ur=BigInt(0),se=BigInt(1),dn=BigInt(2),ce=r=>r instanceof Uint8Array,hn=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function dt(r){if(!ce(r))throw new Error("Uint8Array expected");let t="";for(let e=0;en+i.length,0)),e=0;return r.forEach(n=>{if(!ce(n))throw new Error("Uint8Array expected");t.set(n,e),e+=n.length}),t}function dr(r,t){if(r.length!==t.length)return!1;for(let e=0;eur;r>>=se,t+=1);return t}function yn(r,t){return r>>BigInt(t)&se}var xn=(r,t,e)=>r|(e?se:ur)<(dn<new Uint8Array(r),fr=r=>Uint8Array.from(r);function Le(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Ie(r),i=Ie(r),c=0,o=()=>{n.fill(1),i.fill(0),c=0},s=(...l)=>e(i,n,...l),a=(l=Ie())=>{i=s(fr([0]),l),n=s(),l.length!==0&&(i=s(fr([1]),l),n=s())},u=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,w=[];for(;l{o(),a(l);let P;for(;!(P=w(u()));)a();return o(),P}}var wn={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ot(r,t,e={}){let n=(i,c,o)=>{let s=wn[c];if(typeof s!="function")throw new Error(`Invalid validator "${c}", expected function`);let a=r[i];if(!(o&&a===void 0)&&!s(a,r))throw new Error(`Invalid param ${String(i)}=${a} (${typeof a}), expected ${c}`)};for(let[i,c]of Object.entries(t))n(i,c,!1);for(let[i,c]of Object.entries(e))n(i,c,!0);return r}var F=BigInt(0),G=BigInt(1),Ut=BigInt(2),mn=BigInt(3),Ke=BigInt(4),br=BigInt(5),pr=BigInt(8),gn=BigInt(9),En=BigInt(16);function R(r,t){let e=r%t;return e>=F?e:t+e}function yr(r,t,e){if(e<=F||t 0");if(e===G)return F;let n=G;for(;t>F;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function C(r,t,e){let n=r;for(;t-- >F;)n*=n,n%=e;return n}function fe(r,t){if(r===F||t<=F)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=R(r,t),n=t,i=F,c=G,o=G,s=F;for(;e!==F;){let u=n/e,f=n%e,l=i-o*u,w=c-s*u;n=e,e=f,i=o,c=s,o=l,s=w}if(n!==G)throw new Error("invert: does not exist");return R(i,t)}function _n(r){let t=(r-G)/Ut,e,n,i;for(e=r-G,n=0;e%Ut===F;e/=Ut,n++);for(i=Ut;i(R(r,t)&G)===G,Bn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oe(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Bn.reduce((n,i)=>(n[i]="function",n),t);return ot(r,e)}function Sn(r,t,e){if(e 0");if(e===F)return r.ONE;if(e===G)return t;let n=r.ONE,i=t;for(;e>F;)e&G&&(n=r.mul(n,i)),i=r.sqr(i),e>>=G;return n}function An(r,t){let e=new Array(t.length),n=t.reduce((c,o,s)=>r.is0(o)?c:(e[s]=c,r.mul(c,o)),r.ONE),i=r.inv(n);return t.reduceRight((c,o,s)=>r.is0(o)?c:(e[s]=r.mul(c,e[s]),r.mul(c,o)),i),e}function ue(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Nt(r,t,e=!1,n={}){if(r<=F)throw new Error(`Expected Fp ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:c}=ue(r,t);if(c>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=vn(r),s=Object.freeze({ORDER:r,BITS:i,BYTES:c,MASK:Zt(i),ZERO:F,ONE:G,create:a=>R(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof a}`);return F<=a&&aa===F,isOdd:a=>(a&G)===G,neg:a=>R(-a,r),eql:(a,u)=>a===u,sqr:a=>R(a*a,r),add:(a,u)=>R(a+u,r),sub:(a,u)=>R(a-u,r),mul:(a,u)=>R(a*u,r),pow:(a,u)=>Sn(s,a,u),div:(a,u)=>R(a*fe(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>fe(a,r),sqrt:n.sqrt||(a=>o(s,a)),invertBatch:a=>An(s,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>e?Bt(a,c):yt(a,c),fromBytes:a=>{if(a.length!==c)throw new Error(`Fp.fromBytes: expected ${c}, got ${a.length}`);return e?ht(a):ft(a)}});return Object.freeze(s)}function wr(r,t){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let e=r.sqrt(t);return r.isOdd(e)?r.neg(e):e}function mr(r,t,e=!1){r=M("privateHash",r);let n=r.length,i=ue(t).nByteLength+8;if(i<24||n1024)throw new Error(`hashToPrivateScalar: expected ${i}-1024 bytes of input, got ${n}`);let c=e?ht(r):ft(r);return R(c,t-G)+G}var In=BigInt(0),Ue=BigInt(1);function le(r,t){let e=(i,c)=>{let o=c.negate();return i?o:c},n=i=>{let c=Math.ceil(t/i)+1,o=2**(i-1);return{windows:c,windowSize:o}};return{constTimeNegate:e,unsafeLadder(i,c){let o=r.ZERO,s=i;for(;c>In;)c&Ue&&(o=o.add(s)),s=s.double(),c>>=Ue;return o},precomputeWindow(i,c){let{windows:o,windowSize:s}=n(c),a=[],u=i,f=u;for(let l=0;l>=P,b>a&&(b-=w,o+=Ue);let x=d,S=d+Math.abs(b)-1,m=v%2!==0,K=b<0;b===0?f=f.add(e(m,c[x])):u=u.add(e(K,c[S]))}return{p:u,f}},wNAFCached(i,c,o,s){let a=i._WINDOW_SIZE||1,u=c.get(i);return u||(u=this.precomputeWindow(i,a),a!==1&&c.set(i,s(u))),this.wNAF(a,u,o)}}}function Gt(r){return Oe(r.Fp),ot(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ue(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}function kn(r){let t=Gt(r);ot(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:i}=t;if(e){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Ln,hexToBytes:Kn}=ae,Ht={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Ht;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Ln(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Ht,e=typeof r=="string"?Kn(r):r;if(!(e instanceof Uint8Array))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:i,l:c}=Ht._parseInt(e.subarray(2)),{d:o,l:s}=Ht._parseInt(c);if(s.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(r){let t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,e=u=>{let f=u.toString(16);return f.length&1?`0${f}`:f},n=t(e(r.s)),i=t(e(r.r)),c=n.length/2,o=i.length/2,s=e(c),a=e(o);return`30${e(o+c+4)}02${a}${i}02${s}${n}`}},xt=BigInt(0),st=BigInt(1),lo=BigInt(2),gr=BigInt(3),ho=BigInt(4);function On(r){let t=kn(r),{Fp:e}=t,n=t.toBytes||((v,d,b)=>{let x=d.toAffine();return ut(Uint8Array.from([4]),e.toBytes(x.x),e.toBytes(x.y))}),i=t.fromBytes||(v=>{let d=v.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),x=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:x}});function c(v){let{a:d,b}=t,x=e.sqr(v),S=e.mul(x,v);return e.add(e.add(S,e.mul(v,d)),b)}if(!e.eql(e.sqr(t.Gy),c(t.Gx)))throw new Error("bad generator point: equation left != right");function o(v){return typeof v=="bigint"&&xte.eql(m,e.ZERO);return S(b)&&S(x)?l.ZERO:new l(b,x,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=e.invertBatch(d.map(x=>x.pz));return d.map((x,S)=>x.toAffine(b[S])).map(l.fromAffine)}static fromHex(d){let b=l.fromAffine(i(M("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return l.BASE.multiply(a(d))}_setWindowSize(d){this._WINDOW_SIZE=d,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint)return;throw new Error("bad point: ZERO")}let{x:d,y:b}=this.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");let x=e.sqr(b),S=c(d);if(!e.eql(x,S))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:b,py:x,pz:S}=this,{px:m,py:K,pz:g}=d,B=e.eql(e.mul(b,g),e.mul(m,S)),k=e.eql(e.mul(x,g),e.mul(K,S));return B&&k}negate(){return new l(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,x=e.mul(b,gr),{px:S,py:m,pz:K}=this,g=e.ZERO,B=e.ZERO,k=e.ZERO,I=e.mul(S,S),Z=e.mul(m,m),q=e.mul(K,K),U=e.mul(S,m);return U=e.add(U,U),k=e.mul(S,K),k=e.add(k,k),g=e.mul(d,k),B=e.mul(x,q),B=e.add(g,B),g=e.sub(Z,B),B=e.add(Z,B),B=e.mul(g,B),g=e.mul(U,g),k=e.mul(x,k),q=e.mul(d,q),U=e.sub(I,q),U=e.mul(d,U),U=e.add(U,k),k=e.add(I,I),I=e.add(k,I),I=e.add(I,q),I=e.mul(I,U),B=e.add(B,I),q=e.mul(m,K),q=e.add(q,q),I=e.mul(q,U),g=e.sub(g,I),k=e.mul(q,Z),k=e.add(k,k),k=e.add(k,k),new l(g,B,k)}add(d){f(d);let{px:b,py:x,pz:S}=this,{px:m,py:K,pz:g}=d,B=e.ZERO,k=e.ZERO,I=e.ZERO,Z=t.a,q=e.mul(t.b,gr),U=e.mul(b,m),$=e.mul(x,K),Y=e.mul(S,g),it=e.add(b,x),p=e.add(m,K);it=e.mul(it,p),p=e.add(U,$),it=e.sub(it,p),p=e.add(b,S);let _=e.add(m,g);return p=e.mul(p,_),_=e.add(U,Y),p=e.sub(p,_),_=e.add(x,S),B=e.add(K,g),_=e.mul(_,B),B=e.add($,Y),_=e.sub(_,B),I=e.mul(Z,p),B=e.mul(q,Y),I=e.add(B,I),B=e.sub($,I),I=e.add($,I),k=e.mul(B,I),$=e.add(U,U),$=e.add($,U),Y=e.mul(Z,Y),p=e.mul(q,p),$=e.add($,Y),Y=e.sub(U,Y),Y=e.mul(Z,Y),p=e.add(p,Y),U=e.mul($,p),k=e.add(k,U),U=e.mul(_,p),B=e.mul(it,B),B=e.sub(B,U),U=e.mul(it,$),I=e.mul(_,I),I=e.add(I,U),new l(B,k,I)}subtract(d){return this.add(d.negate())}is0(){return this.equals(l.ZERO)}wNAF(d){return P.wNAFCached(this,u,d,b=>{let x=e.invertBatch(b.map(S=>S.pz));return b.map((S,m)=>S.toAffine(x[m])).map(l.fromAffine)})}multiplyUnsafe(d){let b=l.ZERO;if(d===xt)return b;if(s(d),d===st)return this;let{endo:x}=t;if(!x)return P.unsafeLadder(this,d);let{k1neg:S,k1:m,k2neg:K,k2:g}=x.splitScalar(d),B=b,k=b,I=this;for(;m>xt||g>xt;)m&st&&(B=B.add(I)),g&st&&(k=k.add(I)),I=I.double(),m>>=st,g>>=st;return S&&(B=B.negate()),K&&(k=k.negate()),k=new l(e.mul(k.px,x.beta),k.py,k.pz),B.add(k)}multiply(d){s(d);let b=d,x,S,{endo:m}=t;if(m){let{k1neg:K,k1:g,k2neg:B,k2:k}=m.splitScalar(b),{p:I,f:Z}=this.wNAF(g),{p:q,f:U}=this.wNAF(k);I=P.constTimeNegate(K,I),q=P.constTimeNegate(B,q),q=new l(e.mul(q.px,m.beta),q.py,q.pz),x=I.add(q),S=Z.add(U)}else{let{p:K,f:g}=this.wNAF(b);x=K,S=g}return l.normalizeZ([x,S])[0]}multiplyAndAddUnsafe(d,b,x){let S=l.BASE,m=(g,B)=>B===xt||B===st||!g.equals(S)?g.multiplyUnsafe(B):g.multiply(B),K=m(this,b).add(m(d,x));return K.is0()?void 0:K}toAffine(d){let{px:b,py:x,pz:S}=this,m=this.is0();d==null&&(d=m?e.ONE:e.inv(S));let K=e.mul(b,d),g=e.mul(x,d),B=e.mul(S,d);if(m)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:K,y:g}}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===st)return!0;if(b)return b(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===st?this:b?b(l,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return this.assertValidity(),n(l,this,d)}toHex(d=!0){return dt(this.toRawBytes(d))}}l.BASE=new l(t.Gx,t.Gy,e.ONE),l.ZERO=new l(e.ZERO,e.ONE,e.ZERO);let w=t.nBitLength,P=le(l,t.endo?Math.ceil(w/2):w);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:c,isWithinCurveOrder:o}}function Un(r){let t=Gt(r);return ot(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Er(r){let t=Un(r),{Fp:e,n}=t,i=e.BYTES+1,c=2*e.BYTES+1;function o(p){return xtdt(yt(p,t.nByteLength));function v(p){let _=n>>st;return p>_}function d(p){return v(p)?s(-p):p}let b=(p,_,H)=>ft(p.slice(_,H));class x{constructor(_,H,y){this.r=_,this.s=H,this.recovery=y,this.assertValidity()}static fromCompact(_){let H=t.nByteLength;return _=M("compactSignature",_,H*2),new x(b(_,0,H),b(_,H,2*H))}static fromDER(_){let{r:H,s:y}=Ht.toSig(M("DER",_));return new x(H,y)}assertValidity(){if(!w(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!w(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(_){return new x(this.r,this.s,_)}recoverPublicKey(_){let{r:H,s:y,recovery:h}=this,E=k(M("msgHash",_));if(h==null||![0,1,2,3].includes(h))throw new Error("recovery id invalid");let A=h===2||h===3?H+t.n:H;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let O=h&1?"03":"02",T=u.fromHex(O+P(A)),D=a(A),j=s(-E*D),N=s(y*D),z=u.BASE.multiplyAndAddUnsafe(T,j,N);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return v(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Ot(this.toDERHex())}toDERHex(){return Ht.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ot(this.toCompactHex())}toCompactHex(){return P(this.r)+P(this.s)}}let S={isValidPrivateKey(p){try{return f(p),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let p=t.randomBytes(e.BYTES+8),_=mr(p,n);return yt(_,t.nByteLength)},precompute(p=8,_=u.BASE){return _._setWindowSize(p),_.multiply(BigInt(3)),_}};function m(p,_=!0){return u.fromPrivateKey(p).toRawBytes(_)}function K(p){let _=p instanceof Uint8Array,H=typeof p=="string",y=(_||H)&&p.length;return _?y===i||y===c:H?y===2*i||y===2*c:p instanceof u}function g(p,_,H=!0){if(K(p))throw new Error("first arg must be private key");if(!K(_))throw new Error("second arg must be public key");return u.fromHex(_).multiply(f(p)).toRawBytes(H)}let B=t.bits2int||function(p){let _=ft(p),H=p.length*8-t.nBitLength;return H>0?_>>BigInt(H):_},k=t.bits2int_modN||function(p){return s(B(p))},I=Zt(t.nBitLength);function Z(p){if(typeof p!="bigint")throw new Error("bigint expected");if(!(xt<=p&&pV in H))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:h}=t,{lowS:E,prehash:A,extraEntropy:O}=H;E==null&&(E=!0),p=M("msgHash",p),A&&(p=M("prehashed msgHash",y(p)));let T=k(p),D=f(_),j=[Z(D),Z(T)];if(O!=null){let V=O===!0?h(e.BYTES):O;j.push(M("extraEntropy",V,e.BYTES))}let N=ut(...j),z=T;function X(V){let Q=B(V);if(!w(Q))return;let J=a(Q),W=u.BASE.multiply(Q).toAffine(),tt=s(W.x);if(tt===xt)return;let pt=s(J*s(z+tt*D));if(pt===xt)return;let Lt=(W.x===tt?0:2)|Number(W.y&st),jt=pt;return E&&v(pt)&&(jt=d(pt),Lt^=1),new x(tt,jt,Lt)}return{seed:N,k2sig:X}}let U={lowS:t.lowS,prehash:!1},$={lowS:t.lowS,prehash:!1};function Y(p,_,H=U){let{seed:y,k2sig:h}=q(p,_,H),E=t;return Le(E.hash.outputLen,E.nByteLength,E.hmac)(y,h)}u.BASE._setWindowSize(8);function it(p,_,H,y=$){let h=p;if(_=M("msgHash",_),H=M("publicKey",H),"strict"in y)throw new Error("options.strict was renamed to lowS");let{lowS:E,prehash:A}=y,O,T;try{if(typeof h=="string"||h instanceof Uint8Array)try{O=x.fromDER(h)}catch(W){if(!(W instanceof Ht.Err))throw W;O=x.fromCompact(h)}else if(typeof h=="object"&&typeof h.r=="bigint"&&typeof h.s=="bigint"){let{r:W,s:tt}=h;O=new x(W,tt)}else throw new Error("PARSE");T=u.fromHex(H)}catch(W){if(W.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(E&&O.hasHighS())return!1;A&&(_=t.hash(_));let{r:D,s:j}=O,N=k(_),z=a(j),X=s(N*z),V=s(D*z),Q=u.BASE.multiplyAndAddUnsafe(T,X,V)?.toAffine();return Q?s(Q.x)===D:!1}return{CURVE:t,getPublicKey:m,getSharedSecret:g,sign:Y,verify:it,ProjectivePoint:u,Signature:x,utils:S}}var de=class extends gt{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,et.hash(t);let n=Et(e);if(this.iHash=t.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 i=this.blockLen,c=new Uint8Array(i);c.set(n.length>i?t.create().update(n).digest():n);for(let o=0;onew de(r,t).update(e).digest();Tt.create=(r,t)=>new de(r,t);function Hn(r){return{hash:r,hmac:(t,...e)=>Tt(r,t,Ct(...e)),randomBytes:Kt}}function _r(r,t){let e=n=>Er({...r,...Hn(n)});return Object.freeze({...e(t),create:e})}var Ar=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vr=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Tn=BigInt(1),He=BigInt(2),Br=(r,t)=>(r+t/He)/t;function Rn(r){let t=Ar,e=BigInt(3),n=BigInt(6),i=BigInt(11),c=BigInt(22),o=BigInt(23),s=BigInt(44),a=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=C(f,e,t)*f%t,w=C(l,e,t)*f%t,P=C(w,He,t)*u%t,v=C(P,i,t)*P%t,d=C(v,c,t)*v%t,b=C(d,s,t)*d%t,x=C(b,a,t)*b%t,S=C(x,s,t)*d%t,m=C(S,e,t)*f%t,K=C(m,o,t)*v%t,g=C(K,n,t)*u%t,B=C(g,He,t);if(!Te.eql(Te.sqr(B),r))throw new Error("Cannot find square root");return B}var Te=Nt(Ar,void 0,void 0,{sqrt:Rn}),Vt=_r({a:BigInt(0),b:BigInt(7),Fp:Te,n:vr,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=vr,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Tn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),c=e,o=BigInt("0x100000000000000000000000000000000"),s=Br(c*r,t),a=Br(-n*r,t),u=R(r-s*e-a*i,t),f=R(-s*n-a*c,t),l=u>o,w=f>o;if(l&&(u=t-u),w&&(f=t-f),u>o||f>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:w,k2:f}}}},oe),Ho=BigInt(0);var To=Vt.ProjectivePoint;var Yt=["deriveBits"];var ct=new Uint8Array(0),Re=new Uint8Array([72,80,75,69,45,118,49]),Co=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),Pr=new Uint8Array([75,69,77,0,0]),$t=new Uint8Array([100,107,112,95,112,114,107]),Ir=new Uint8Array([101,97,101,95,112,114,107]),Do=new Uint8Array([105,110,102,111,95,104,97,115,104]),No=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),qo=new Uint8Array([115,101,99,114,101,116]),kr=new Uint8Array([115,104,97,114,101,100,95,115,101,99,114,101,116]),zo=new Uint8Array([107,101,121]),jo=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),Mo=new Uint8Array([101,120,112]),Zo=new Uint8Array([115,101,99]),Cn=new Uint8Array([99,97,110,100,105,100,97,116,101]),he=new Uint8Array([115,107]),Dn=new Uint8Array([255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,188,230,250,173,167,23,158,132,243,185,202,194,252,99,37,81]),Nn=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,199,99,77,129,244,55,45,223,88,26,13,178,72,176,167,122,236,236,25,106,204,197,41,115]),qn=new Uint8Array([1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,81,134,135,131,191,47,150,107,127,204,1,72,247,9,165,208,59,181,201,184,137,156,71,174,187,111,183,30,145,56,100,9]);var be=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}checkInit(){if(typeof this._api>"u")throw new Error("Not initialized. Call init()")}},wt=class extends be{constructor(){super()}init(t){this._api=t}},pe=class extends be{constructor(){super(),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:ct})}init(t,e){this._api=t,this._suiteId=e}};var zn={DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256K1HkdfSha256:19,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33},Xt=zn,jn={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3},Ce=jn;var bt=class{constructor(t,e,n){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extractable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"usages",{enumerable:!0,configurable:!0,writable:!0,value:Yt}),this.key=e,this.type=n,this.algorithm={name:t},n==="public"&&(this.usages=[])}};var ye=BigInt(4294967295),De=BigInt(32);function Lr(r,t=!1){return t?{h:Number(r&ye),l:Number(r>>De&ye)}:{h:Number(r>>De&ye)|0,l:Number(r&ye)|0}}function Mn(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;iBigInt(r>>>0)<>>0),Gn=(r,t,e)=>r>>>e,Vn=(r,t,e)=>r<<32-e|t>>>e,Yn=(r,t,e)=>r>>>e|t<<32-e,$n=(r,t,e)=>r<<32-e|t>>>e,Xn=(r,t,e)=>r<<64-e|t>>>e-32,Wn=(r,t,e)=>r>>>e-32|t<<64-e,Fn=(r,t)=>t,Qn=(r,t)=>r,Jn=(r,t,e)=>r<>>32-e,ti=(r,t,e)=>t<>>32-e,ei=(r,t,e)=>t<>>64-e,ri=(r,t,e)=>r<>>64-e;function ni(r,t,e,n){let i=(t>>>0)+(n>>>0);return{h:r+e+(i/2**32|0)|0,l:i|0}}var ii=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),oi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,si=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ci=(r,t,e,n,i)=>t+e+n+i+(r/2**32|0)|0,ai=(r,t,e,n,i)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(i>>>0),fi=(r,t,e,n,i,c)=>t+e+n+i+c+(r/2**32|0)|0,ui={fromBig:Lr,split:Mn,toBig:Zn,shrSH:Gn,shrSL:Vn,rotrSH:Yn,rotrSL:$n,rotrBH:Xn,rotrBL:Wn,rotr32H:Fn,rotr32L:Qn,rotlSH:Jn,rotlSL:ti,rotlBH:ei,rotlBL:ri,add:ni,add3L:ii,add3H:oi,add4L:si,add4H:ci,add5H:fi,add5L:ai},L=ui;var[li,di]=L.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(r=>BigInt(r))),At=new Uint32Array(80),Pt=new Uint32Array(80),qt=class extends Dt{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:t,Al:e,Bh:n,Bl:i,Ch:c,Cl:o,Dh:s,Dl:a,Eh:u,El:f,Fh:l,Fl:w,Gh:P,Gl:v,Hh:d,Hl:b}=this;return[t,e,n,i,c,o,s,a,u,f,l,w,P,v,d,b]}set(t,e,n,i,c,o,s,a,u,f,l,w,P,v,d,b){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=i|0,this.Ch=c|0,this.Cl=o|0,this.Dh=s|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=w|0,this.Gh=P|0,this.Gl=v|0,this.Hh=d|0,this.Hl=b|0}process(t,e){for(let m=0;m<16;m++,e+=4)At[m]=t.getUint32(e),Pt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let K=At[m-15]|0,g=Pt[m-15]|0,B=L.rotrSH(K,g,1)^L.rotrSH(K,g,8)^L.shrSH(K,g,7),k=L.rotrSL(K,g,1)^L.rotrSL(K,g,8)^L.shrSL(K,g,7),I=At[m-2]|0,Z=Pt[m-2]|0,q=L.rotrSH(I,Z,19)^L.rotrBH(I,Z,61)^L.shrSH(I,Z,6),U=L.rotrSL(I,Z,19)^L.rotrBL(I,Z,61)^L.shrSL(I,Z,6),$=L.add4L(k,U,Pt[m-7],Pt[m-16]),Y=L.add4H($,B,q,At[m-7],At[m-16]);At[m]=Y|0,Pt[m]=$|0}let{Ah:n,Al:i,Bh:c,Bl:o,Ch:s,Cl:a,Dh:u,Dl:f,Eh:l,El:w,Fh:P,Fl:v,Gh:d,Gl:b,Hh:x,Hl:S}=this;for(let m=0;m<80;m++){let K=L.rotrSH(l,w,14)^L.rotrSH(l,w,18)^L.rotrBH(l,w,41),g=L.rotrSL(l,w,14)^L.rotrSL(l,w,18)^L.rotrBL(l,w,41),B=l&P^~l&d,k=w&v^~w&b,I=L.add5L(S,g,k,di[m],Pt[m]),Z=L.add5H(I,x,K,B,li[m],At[m]),q=I|0,U=L.rotrSH(n,i,28)^L.rotrBH(n,i,34)^L.rotrBH(n,i,39),$=L.rotrSL(n,i,28)^L.rotrBL(n,i,34)^L.rotrBL(n,i,39),Y=n&c^n&s^c&s,it=i&o^i&a^o&a;x=d|0,S=b|0,d=P|0,b=v|0,P=l|0,v=w|0,{h:l,l:w}=L.add(u|0,f|0,Z|0,q|0),u=s|0,f=a|0,s=c|0,a=o|0,c=n|0,o=i|0;let p=L.add3L(q,$,it);n=L.add3H(p,Z,U,Y),i=p|0}({h:n,l:i}=L.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:c,l:o}=L.add(this.Bh|0,this.Bl|0,c|0,o|0),{h:s,l:a}=L.add(this.Ch|0,this.Cl|0,s|0,a|0),{h:u,l:f}=L.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:w}=L.add(this.Eh|0,this.El|0,l|0,w|0),{h:P,l:v}=L.add(this.Fh|0,this.Fl|0,P|0,v|0),{h:d,l:b}=L.add(this.Gh|0,this.Gl|0,d|0,b|0),{h:x,l:S}=L.add(this.Hh|0,this.Hl|0,x|0,S|0),this.set(n,i,c,o,s,a,u,f,l,w,P,v,d,b,x,S)}roundClean(){At.fill(0),Pt.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)}},Ne=class extends qt{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}},qe=class extends qt{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}},ze=class extends qt{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}},Wt=rt(()=>new qt),Qo=rt(()=>new Ne),Jo=rt(()=>new qe),Kr=rt(()=>new ze);var je=class extends pe{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ce.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}buildLabeledIkm(t,e){let n=new Uint8Array(7+this._suiteId.byteLength+t.byteLength+e.byteLength);return n.set(Re,0),n.set(this._suiteId,7),n.set(t,7+this._suiteId.byteLength),n.set(e,7+this._suiteId.byteLength+t.byteLength),n}buildLabeledInfo(t,e,n){let i=new Uint8Array(9+this._suiteId.byteLength+t.byteLength+e.byteLength);return i.set(new Uint8Array([0,n]),0),i.set(Re,2),i.set(this._suiteId,9),i.set(t,9+this._suiteId.byteLength),i.set(e,9+this._suiteId.byteLength+t.byteLength),i}async extract(t,e){if(this.checkInit(),t.byteLength===0&&(t=new ArrayBuffer(this.hashSize)),t.byteLength!==this.hashSize)switch(this.algHash.hash){case"SHA-256":return Tt(oe,new Uint8Array(t),new Uint8Array(e));case"SHA-384":return Tt(Kr,new Uint8Array(t),new Uint8Array(e));default:return Tt(Wt,new Uint8Array(t),new Uint8Array(e))}let n=await this._api.importKey("raw",t,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,e)}async expand(t,e,n){this.checkInit();let i=await this._api.importKey("raw",t,this.algHash,!1,["sign"]),c=new ArrayBuffer(n),o=new Uint8Array(c),s=ct,a=new Uint8Array(e),u=new Uint8Array(1);if(n>255*this.hashSize)throw new Error("Entropy limit reached");let f=new Uint8Array(this.hashSize+a.length+1);for(let l=1,w=0;w=s.length?(o.set(s,w),w+=s.length):(o.set(s.slice(0,o.length-w),w),w+=o.length-w);return c}async extractAndExpand(t,e,n,i){this.checkInit();let c=await this._api.importKey("raw",e,"HKDF",!1,Yt);return await this._api.deriveBits({name:"HKDF",hash:this.algHash.hash,salt:t,info:n},c,i*8)}async labeledExtract(t,e,n){return await this.extract(t,this.buildLabeledIkm(e,n))}async labeledExpand(t,e,n,i){return await this.expand(t,this.buildLabeledInfo(e,n,i),i)}},Ft=class extends je{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ce.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}};var hi={},bi=pi(globalThis,hi);function pi(r,t){return new Proxy(r,{get(e,n,i){return n in t?t[n]:r[n]},set(e,n,i){return n in t&&delete t[n],r[n]=i,!0},deleteProperty(e,n){let i=!1;return n in t&&(delete t[n],i=!0),n in r&&(delete r[n],i=!0),i},ownKeys(e){let n=Reflect.ownKeys(r),i=Reflect.ownKeys(t),c=new Set(i);return[...n.filter(o=>!c.has(o)),...i]},defineProperty(e,n,i){return n in t&&delete t[n],Reflect.defineProperty(r,n,i),!0},getOwnPropertyDescriptor(e,n){return n in t?Reflect.getOwnPropertyDescriptor(t,n):Reflect.getOwnPropertyDescriptor(r,n)},has(e,n){return n in t||n in r}})}var Qt=r=>typeof r=="object"&&r!==null&&typeof r.privateKey=="object"&&typeof r.publicKey=="object";function Me(r,t){if(t<=0)throw new Error("i2Osp: too small size");if(r>=256**t)throw new Error("i2Osp: too large integer");let e=new Uint8Array(t);for(let n=0;n>8;return e}function Jt(r,t){let e=new Uint8Array(r.length+t.length);return e.set(r,0),e.set(t,r.length),e}function Or(r,t,e){let n=new Uint8Array(r.length+t.length+e.length);return n.set(r,0),n.set(t,r.length),n.set(e,r.length+t.length),n}var bs=new Uint8Array([48,65,2,1,0,48,19,6,7,42,134,72,206,61,2,1,6,8,42,134,72,206,61,3,1,7,4,39,48,37,2,1,1,4,32]),ps=new Uint8Array([48,78,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,34,4,55,48,53,2,1,1,4,48]),ys=new Uint8Array([48,96,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,35,4,73,48,71,2,1,1,4,66]);var lt=BigInt(0),nt=BigInt(1),xe=BigInt(2),xi=BigInt(8),wi={zip215:!0};function mi(r){let t=Gt(r);return ot(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Rt(r){let t=mi(r),{Fp:e,n,prehash:i,hash:c,randomBytes:o,nByteLength:s,h:a}=t,u=xe<{try{return{isValid:!0,value:e.sqrt(y*e.inv(h))}}catch{return{isValid:!1,value:lt}}}),w=t.adjustScalarBytes||(y=>y),P=t.domain||((y,h,E)=>{if(h.length||E)throw new Error("Contexts/pre-hash are not supported");return y}),v=y=>typeof y=="bigint"&<v(y)&&v(h)&&yy===lt||d(y,u);function x(y,h){if(d(y,h))return y;throw new Error(`Expected valid scalar < ${h}, got ${typeof y} ${y}`)}function S(y){return y===lt?y:x(y,n)}let m=new Map;function K(y){if(!(y instanceof g))throw new Error("ExtendedPoint expected")}class g{constructor(h,E,A,O){if(this.ex=h,this.ey=E,this.ez=A,this.et=O,!b(h))throw new Error("x required");if(!b(E))throw new Error("y required");if(!b(A))throw new Error("z required");if(!b(O))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(h){if(h instanceof g)throw new Error("extended point not allowed");let{x:E,y:A}=h||{};if(!b(E)||!b(A))throw new Error("invalid affine point");return new g(E,A,nt,f(E*A))}static normalizeZ(h){let E=e.invertBatch(h.map(A=>A.ez));return h.map((A,O)=>A.toAffine(E[O])).map(g.fromAffine)}_setWindowSize(h){this._WINDOW_SIZE=h,m.delete(this)}assertValidity(){let{a:h,d:E}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:A,ey:O,ez:T,et:D}=this,j=f(A*A),N=f(O*O),z=f(T*T),X=f(z*z),V=f(j*h),Q=f(z*f(V+N)),J=f(X+f(E*f(j*N)));if(Q!==J)throw new Error("bad point: equation left != right (1)");let W=f(A*O),tt=f(T*D);if(W!==tt)throw new Error("bad point: equation left != right (2)")}equals(h){K(h);let{ex:E,ey:A,ez:O}=this,{ex:T,ey:D,ez:j}=h,N=f(E*j),z=f(T*O),X=f(A*j),V=f(D*O);return N===z&&X===V}is0(){return this.equals(g.ZERO)}negate(){return new g(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:h}=t,{ex:E,ey:A,ez:O}=this,T=f(E*E),D=f(A*A),j=f(xe*f(O*O)),N=f(h*T),z=E+A,X=f(f(z*z)-T-D),V=N+D,Q=V-j,J=N-D,W=f(X*Q),tt=f(V*J),pt=f(X*J),Lt=f(Q*V);return new g(W,tt,Lt,pt)}add(h){K(h);let{a:E,d:A}=t,{ex:O,ey:T,ez:D,et:j}=this,{ex:N,ey:z,ez:X,et:V}=h;if(E===BigInt(-1)){let Qe=f((T-O)*(z+N)),Je=f((T+O)*(z-N)),Se=f(Je-Qe);if(Se===lt)return this.double();let tr=f(D*xe*V),er=f(j*xe*X),rr=er+tr,nr=Je+Qe,ir=er-tr,Xr=f(rr*Se),Wr=f(nr*ir),Fr=f(rr*ir),Qr=f(Se*nr);return new g(Xr,Wr,Qr,Fr)}let Q=f(O*N),J=f(T*z),W=f(j*A*V),tt=f(D*X),pt=f((O+T)*(N+z)-Q-J),Lt=tt-W,jt=tt+W,Fe=f(J-E*Q),Gr=f(pt*Lt),Vr=f(jt*Fe),Yr=f(pt*Fe),$r=f(Lt*jt);return new g(Gr,Vr,$r,Yr)}subtract(h){return this.add(h.negate())}wNAF(h){return I.wNAFCached(this,m,h,g.normalizeZ)}multiply(h){let{p:E,f:A}=this.wNAF(x(h,n));return g.normalizeZ([E,A])[0]}multiplyUnsafe(h){let E=S(h);return E===lt?k:this.equals(k)||E===nt?this:this.equals(B)?this.wNAF(E).p:I.unsafeLadder(this,E)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return I.unsafeLadder(this,n).is0()}toAffine(h){let{ex:E,ey:A,ez:O}=this,T=this.is0();h==null&&(h=T?xi:e.inv(O));let D=f(E*h),j=f(A*h),N=f(O*h);if(T)return{x:lt,y:nt};if(N!==nt)throw new Error("invZ was invalid");return{x:D,y:j}}clearCofactor(){let{h}=t;return h===nt?this:this.multiplyUnsafe(h)}static fromHex(h,E=!1){let{d:A,a:O}=t,T=e.BYTES;h=M("pointHex",h,T);let D=h.slice(),j=h[T-1];D[T-1]=j&-129;let N=ht(D);N===lt||(E?x(N,u):x(N,e.ORDER));let z=f(N*N),X=f(z-nt),V=f(A*z-O),{isValid:Q,value:J}=l(X,V);if(!Q)throw new Error("Point.fromHex: invalid y coordinate");let W=(J&nt)===nt,tt=(j&128)!==0;if(!E&&J===lt&&tt)throw new Error("Point.fromHex: x=0 and x_0=1");return tt!==W&&(J=f(-J)),g.fromAffine({x:J,y:N})}static fromPrivateKey(h){return U(h).point}toRawBytes(){let{x:h,y:E}=this.toAffine(),A=Bt(E,e.BYTES);return A[A.length-1]|=h&nt?128:0,A}toHex(){return dt(this.toRawBytes())}}g.BASE=new g(t.Gx,t.Gy,nt,f(t.Gx*t.Gy)),g.ZERO=new g(lt,nt,nt,lt);let{BASE:B,ZERO:k}=g,I=le(g,s*8);function Z(y){return R(y,n)}function q(y){return Z(ht(y))}function U(y){let h=s;y=M("private key",y,h);let E=M("hashed private key",c(y),2*h),A=w(E.slice(0,h)),O=E.slice(h,2*h),T=q(A),D=B.multiply(T),j=D.toRawBytes();return{head:A,prefix:O,scalar:T,point:D,pointBytes:j}}function $(y){return U(y).pointBytes}function Y(y=new Uint8Array,...h){let E=ut(...h);return q(c(P(E,M("context",y),!!i)))}function it(y,h,E={}){y=M("message",y),i&&(y=i(y));let{prefix:A,scalar:O,pointBytes:T}=U(h),D=Y(E.context,A,y),j=B.multiply(D).toRawBytes(),N=Y(E.context,j,T,y),z=Z(D+N*O);S(z);let X=ut(j,Bt(z,e.BYTES));return M("result",X,s*2)}let p=wi;function _(y,h,E,A=p){let{context:O,zip215:T}=A,D=e.BYTES;y=M("signature",y,2*D),h=M("message",h),i&&(h=i(h));let j=ht(y.slice(D,2*D)),N,z,X;try{N=g.fromHex(E,T),z=g.fromHex(y.slice(0,D),T),X=B.multiplyUnsafe(j)}catch{return!1}if(!T&&N.isSmallOrder())return!1;let V=Y(O,z.toRawBytes(),N.toRawBytes(),h);return z.add(N.multiplyUnsafe(V)).subtract(X).clearCofactor().equals(g.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:$,sign:it,verify:_,ExtendedPoint:g,utils:{getExtendedPublicKey:U,randomPrivateKey:()=>o(e.BYTES),precompute(y=8,h=g.BASE){return h._setWindowSize(y),h.multiply(BigInt(3)),h}}}}var Bs=BigInt(0),Ss=BigInt(1);var Ge=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ur=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ts=BigInt(0),Ei=BigInt(1),Ze=BigInt(2),_i=BigInt(5),Hr=BigInt(10),vi=BigInt(20),Bi=BigInt(40),Tr=BigInt(80);function Si(r){let t=Ge,n=r*r%t*r%t,i=C(n,Ze,t)*n%t,c=C(i,Ei,t)*r%t,o=C(c,_i,t)*c%t,s=C(o,Hr,t)*o%t,a=C(s,vi,t)*s%t,u=C(a,Bi,t)*a%t,f=C(u,Tr,t)*u%t,l=C(f,Tr,t)*u%t,w=C(l,Hr,t)*o%t;return{pow_p_5_8:C(w,Ze,t)*r%t,b2:n}}function Ai(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Pi(r,t){let e=Ge,n=R(t*t*t,e),i=R(n*n*t,e),c=Si(r*i).pow_p_5_8,o=R(r*n*c,e),s=R(t*o*o,e),a=o,u=R(o*Ur,e),f=s===r,l=s===R(-r,e),w=s===R(-r*Ur,e);return f&&(o=a),(l||w)&&(o=u),xr(o,e)&&(o=R(-o,e)),{isValid:f||l,value:o}}var mt=Nt(Ge,void 0,!0),Ve={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:mt,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Wt,randomBytes:Kt,adjustScalarBytes:Ai,uvRatio:Pi},Ii=Rt(Ve);function Rr(r,t,e){if(t.length>255)throw new Error("Context is too big");return Ct(Mt("SigEd25519 no Ed25519 collisions"),new Uint8Array([e?1:0,t.length]),t,r)}var Rs=Rt({...Ve,domain:Rr}),Cs=Rt({...Ve,domain:Rr,prehash:Wt});var ki=(mt.ORDER+BigInt(3))/BigInt(8),Ds=mt.pow(Ze,ki),Ns=mt.sqrt(mt.neg(mt.ONE)),qs=(mt.ORDER-BigInt(5))/BigInt(8),zs=BigInt(486662);var js=wr(mt,mt.neg(BigInt(486664)));var Ms=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Zs=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Gs=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vs=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Ys=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var[Nr,qr,zr]=[[],[],[]],Ki=BigInt(0),te=BigInt(1),Oi=BigInt(2),Ui=BigInt(7),Hi=BigInt(256),Ti=BigInt(113);for(let r=0,t=te,e=1,n=0;r<24;r++){[e,n]=[n,(2*e+3*n)%5],Nr.push(2*(5*n+e)),qr.push((r+1)*(r+2)/2%64);let i=Ki;for(let c=0;c<7;c++)t=(t<>Ui)*Ti)%Hi,t&Oi&&(i^=te<<(te<e>32?L.rotlBH(r,t,e):L.rotlSH(r,t,e),Dr=(r,t,e)=>e>32?L.rotlBL(r,t,e):L.rotlSL(r,t,e);function Di(r,t=24){let e=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let o=0;o<10;o++)e[o]=r[o]^r[o+10]^r[o+20]^r[o+30]^r[o+40];for(let o=0;o<10;o+=2){let s=(o+8)%10,a=(o+2)%10,u=e[a],f=e[a+1],l=Cr(u,f,1)^e[s],w=Dr(u,f,1)^e[s+1];for(let P=0;P<50;P+=10)r[o+P]^=l,r[o+P+1]^=w}let i=r[2],c=r[3];for(let o=0;o<24;o++){let s=qr[o],a=Cr(i,c,s),u=Dr(i,c,s),f=Nr[o];i=r[f],c=r[f+1],r[f]=a,r[f+1]=u}for(let o=0;o<50;o+=10){for(let s=0;s<10;s++)e[s]=r[o+s];for(let s=0;s<10;s++)r[o+s]^=~e[(s+2)%10]&e[(s+4)%10]}r[0]^=Ri[n],r[1]^=Ci[n]}e.fill(0)}var we=class r extends gt{constructor(t,e,n,i=!1,c=24){if(super(),this.blockLen=t,this.suffix=e,this.outputLen=n,this.enableXOF=i,this.rounds=c,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,et.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=cr(this.state)}keccak(){Di(this.state32,this.rounds),this.posOut=0,this.pos=0}update(t){et.exists(this);let{blockLen:e,state:n}=this;t=Et(t);let i=t.length;for(let c=0;c=n&&this.keccak();let o=Math.min(n-this.posOut,c-i);t.set(e.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return et.number(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(et.output(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(t){let{blockLen:e,suffix:n,outputLen:i,rounds:c,enableXOF:o}=this;return t||(t=new r(e,n,i,o,c)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=c,t.suffix=n,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}},It=(r,t,e)=>rt(()=>new we(t,r,e)),ic=It(6,144,224/8),oc=It(6,136,256/8),sc=It(6,104,384/8),cc=It(6,72,512/8),ac=It(1,144,224/8),fc=It(1,136,256/8),uc=It(1,104,384/8),lc=It(1,72,512/8),jr=(r,t,e)=>ar((n={})=>new we(t,r,n.dkLen===void 0?e:n.dkLen,!0)),dc=jr(31,168,128/8),Ye=jr(31,136,256/8);var Ni=rt(()=>Ye.create({dkLen:114})),qi=rt(()=>Ye.create({dkLen:64})),$e=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439");function zi(r){let t=$e,e=BigInt(1),n=BigInt(2),i=BigInt(3),c=BigInt(11),o=BigInt(22),s=BigInt(44),a=BigInt(88),u=BigInt(223),f=r*r*r%t,l=f*f*r%t,w=C(l,i,t)*l%t,P=C(w,i,t)*l%t,v=C(P,n,t)*f%t,d=C(v,c,t)*v%t,b=C(d,o,t)*d%t,x=C(b,s,t)*b%t,S=C(x,a,t)*x%t,m=C(S,s,t)*b%t,K=C(m,n,t)*f%t,g=C(K,e,t)*r%t;return C(g,u,t)*K%t}function ji(r){return r[0]&=252,r[55]|=128,r[56]=0,r}var Mr=Nt($e,456,!0),gc=BigInt(4),Zr={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:Mr,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:Ni,randomBytes:Kt,adjustScalarBytes:ji,domain:(r,t,e)=>{if(t.length>255)throw new Error(`Context is too big: ${t.length}`);return Ct(Mt("SigEd448"),new Uint8Array([e?1:0,t.length]),t,r)},uvRatio:(r,t)=>{let e=$e,n=R(r*r*t,e),i=R(n*r,e),c=R(i*n*t,e),o=zi(c),s=R(i*o,e),a=R(s*s,e);return{isValid:R(a*t,e)===r,value:s}}},Mi=Rt(Zr),Ec=Rt({...Zr,prehash:qi});var _c=(Mr.ORDER-BigInt(3))/BigInt(4),vc=BigInt(156326);var kt=class extends Error{constructor(t){let e;t instanceof Error?e=t.message:typeof t=="string"?e=t:e="",super(e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.message===""?this.message=this.name:this.message=this.name+": "+this.message}};var me=class extends kt{},zt=class extends kt{},ge=class extends kt{},Ee=class extends kt{};var _e=class extends kt{},ve=class extends kt{};var Be=class extends wt{constructor(t,e){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Xt.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prim",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._prim=t,this._kdf=e}init(t){super.init(t);let e=new Uint8Array(Pr);e.set(Me(this.id,2),3),this._prim.init(t),this._kdf.init(t,e),super.init(t)}async generateKeyPair(){try{return await this._prim.generateKeyPair()}catch(t){throw new ve(t)}}async deriveKeyPair(t){try{return await this._prim.deriveKeyPair(t)}catch(e){throw new _e(e)}}async serializePublicKey(t){try{return await this._prim.serializePublicKey(t)}catch(e){throw new me(e)}}async deserializePublicKey(t){try{return await this._prim.deserializePublicKey(t)}catch(e){throw new zt(e)}}async importKey(t,e,n){try{return await this._prim.importKey(t,e,n)}catch(i){throw new zt(i)}}async encap(t){try{let e=t.nonEphemeralKeyPair===void 0?await this.generateKeyPair():t.nonEphemeralKeyPair,n=await this._prim.serializePublicKey(e.publicKey),i=await this._prim.serializePublicKey(t.recipientPublicKey),c;if(t.senderKey===void 0)c=new Uint8Array(await this._prim.dh(e.privateKey,t.recipientPublicKey));else{let a=Qt(t.senderKey)?t.senderKey.privateKey:t.senderKey,u=new Uint8Array(await this._prim.dh(e.privateKey,t.recipientPublicKey)),f=new Uint8Array(await this._prim.dh(a,t.recipientPublicKey));c=Jt(u,f)}let o;if(t.senderKey===void 0)o=Jt(new Uint8Array(n),new Uint8Array(i));else{let a=Qt(t.senderKey)?t.senderKey.publicKey:await this._prim.derivePublicKey(t.senderKey),u=await this._prim.serializePublicKey(a);o=Or(new Uint8Array(n),new Uint8Array(i),new Uint8Array(u))}let s=await this.generateSharedSecret(c,o);return{enc:n,sharedSecret:s}}catch(e){throw new ge(e)}}async decap(t){let e;try{e=await this._prim.deserializePublicKey(t.enc)}catch(n){throw new zt(n)}try{let n=Qt(t.recipientKey)?t.recipientKey.privateKey:t.recipientKey,i=Qt(t.recipientKey)?t.recipientKey.publicKey:await this._prim.derivePublicKey(t.recipientKey),c=await this._prim.serializePublicKey(i),o;if(t.senderPublicKey===void 0)o=new Uint8Array(await this._prim.dh(n,e));else{let a=new Uint8Array(await this._prim.dh(n,e)),u=new Uint8Array(await this._prim.dh(n,t.senderPublicKey));o=Jt(a,u)}let s;if(t.senderPublicKey===void 0)s=Jt(new Uint8Array(t.enc),new Uint8Array(c));else{let a=await this._prim.serializePublicKey(t.senderPublicKey);s=new Uint8Array(t.enc.byteLength+c.byteLength+a.byteLength),s.set(new Uint8Array(t.enc),0),s.set(new Uint8Array(c),t.enc.byteLength),s.set(new Uint8Array(a),t.enc.byteLength+c.byteLength)}return await this.generateSharedSecret(o,s)}catch(n){throw new Ee(n)}}async generateSharedSecret(t,e){let n=this._kdf.buildLabeledIkm(Ir,t),i=this._kdf.buildLabeledInfo(kr,e,this.secretSize);return await this._kdf.extractAndExpand(ct,n,i,this.secretSize)}};var ee="ECDH",Xe=class extends wt{constructor(t){super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=t,this._nPk=33,this._nSk=32}async serializePublicKey(t){return await this._serializePublicKey(t)}async deserializePublicKey(t){return await this._deserializePublicKey(t)}async importKey(t,e,n){if(t!=="raw")throw new Error("Unsupported format");return await this._importKey(e,n)}async derivePublicKey(t){return await this._derivePublicKey(t)}async generateKeyPair(){let t=Vt.utils.randomPrivateKey(),e=new bt(ee,t,"private");return{publicKey:await this.derivePublicKey(e),privateKey:e}}async deriveKeyPair(t){let e=await this._hkdf.labeledExtract(ct,$t,new Uint8Array(t)),n=await this._hkdf.labeledExpand(e,he,ct,this._nSk),i=new bt(ee,new Uint8Array(n),"private");return{privateKey:i,publicKey:await this.derivePublicKey(i)}}async dh(t,e){return await this._dh(t,e)}_serializePublicKey(t){return new Promise(e=>{e(t.key.buffer)})}_deserializePublicKey(t){return new Promise((e,n)=>{t.byteLength!==this._nPk?n(new Error("Invalid public key for the ciphersuite")):e(new bt(ee,new Uint8Array(t),"public"))})}_importKey(t,e){return new Promise((n,i)=>{e&&t.byteLength!==this._nPk&&i(new Error("Invalid public key for the ciphersuite")),!e&&t.byteLength!==this._nSk&&i(new Error("Invalid private key for the ciphersuite")),n(new bt(ee,new Uint8Array(t),e?"public":"private"))})}_derivePublicKey(t){return new Promise(e=>{let n=Vt.getPublicKey(t.key);e(new bt(ee,n,"public"))})}_dh(t,e){return new Promise((n,i)=>{try{n(Vt.getSharedSecret(t.key,e.key).buffer)}catch(c){i(c)}})}},We=class extends Be{constructor(){let t=new Ft,e=new Xe(t);super(e,t),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Xt.DhkemSecp256K1HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}};export{We as DhkemSecp256k1HkdfSha256}; -/*! Bundled license information: - -@noble/hashes/esm/utils.js: - (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/utils.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/modular.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/curve.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/weierstrass.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/_shortw_utils.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/secp256k1.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/edwards.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/montgomery.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed25519.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed448.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) -*/ diff --git a/dhkemSecp256k1HkdfSha256/src/hpke.js b/dhkemSecp256k1HkdfSha256/src/hpke.js deleted file mode 100644 index cdd8b2f0e..000000000 --- a/dhkemSecp256k1HkdfSha256/src/hpke.js +++ /dev/null @@ -1,30 +0,0 @@ -var ae=class extends Error{constructor(e){let t;e instanceof Error?t=e.message:typeof e=="string"?t=e:t="",super(t),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.message===""?this.message=this.name:this.message=this.name+": "+this.message}},he=class extends ae{},Rr=class extends ae{},At=class extends ae{},$e=class extends ae{},Pt=class extends ae{},Bt=class extends ae{},It=class extends ae{},Ce=class extends ae{},je=class extends ae{},Lt=class extends ae{},Ot=class extends ae{},de=class extends ae{};var _e={Base:0,Psk:1,Auth:2,AuthPsk:3},Mr={DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256K1HkdfSha256:19,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33},J=Mr,qr={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3},Ee=qr,Gr={Aes128Gcm:1,Aes256Gcm:2,Chacha20Poly1305:3,ExportOnly:65535},te=Gr;var ke=["deriveBits"],Fr=["encrypt","decrypt"];var G=new Uint8Array(0),or=new Uint8Array([72,80,75,69,45,118,49]),$r=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),Zr=new Uint8Array([75,69,77,0,0]),Ze=new Uint8Array([100,107,112,95,112,114,107]),Vr=new Uint8Array([101,97,101,95,112,114,107]),Xr=new Uint8Array([105,110,102,111,95,104,97,115,104]),Yr=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),Wr=new Uint8Array([115,101,99,114,101,116]),Jr=new Uint8Array([115,104,97,114,101,100,95,115,101,99,114,101,116]),Qr=new Uint8Array([107,101,121]),en=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),tn=new Uint8Array([101,120,112]),rn=new Uint8Array([115,101,99]),nn=new Uint8Array([99,97,110,100,105,100,97,116,101]),Kt=new Uint8Array([115,107]),on=new Uint8Array([255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,188,230,250,173,167,23,158,132,243,185,202,194,252,99,37,81]),sn=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,199,99,77,129,244,55,45,223,88,26,13,178,72,176,167,122,236,236,25,106,204,197,41,115]),an=new Uint8Array([1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,81,134,135,131,191,47,150,107,127,204,1,72,247,9,165,208,59,181,201,184,137,156,71,174,187,111,183,30,145,56,100,9]);var Ve=class{constructor(e,t,n){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exporterSecret",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._kdf=t,this.exporterSecret=n}async seal(e,t){return await this._emitError1()}async open(e,t){return await this._emitError1()}async setupBidirectional(e,t){return await this._emitError2()}async export(e,t){if(e.byteLength>128)throw new he("Too long exporter context");try{return await this._kdf.labeledExpand(this.exporterSecret,rn,new Uint8Array(e),t)}catch(n){throw new It(n)}}_emitError1(){return new Promise((e,t)=>{t(new de("Not available on export-only mode"))})}_emitError2(){return new Promise((e,t)=>{t(new de("Not available on export-only mode"))})}},Ut=class extends Ve{},Ht=class extends Ve{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}};var Tt=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}checkInit(){if(typeof this._api>"u")throw new Error("Not initialized. Call init()")}},re=class extends Tt{constructor(){super()}init(e){this._api=e}},Nt=class extends Tt{constructor(){super(),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:G})}init(e,t){this._api=e,this._suiteId=t}};var Ct=class{constructor(e,t){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_rawKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._rawKey=t}async seal(e,t,n){this._key===void 0&&(this._key=await this.importKey(this._rawKey),new Uint8Array(this._rawKey).fill(0));let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.encrypt(i,this._key,t)}async open(e,t,n){this._key===void 0&&(this._key=await this.importKey(this._rawKey),new Uint8Array(this._rawKey).fill(0));let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.decrypt(i,this._key,t)}async importKey(e){return await this._api.importKey("raw",e,{name:"AES-GCM"},!0,Fr)}},sr=class extends Ct{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}},ar=class extends Ct{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes256Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}},nt=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return this.checkInit(),new sr(this._api,e)}},it=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes256Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return this.checkInit(),new ar(this._api,e)}};var jt=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.ExportOnly}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:0})}createAeadKey(e){throw new de("createAeadKey() is not supported on ExportOnly")}};var pi=r=>r instanceof Uint8Array;var le=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),cn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),bi=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!bi)throw new Error("Non little-endian hardware is not supported");function Dt(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function zt(r){if(typeof r=="string"&&(r=Dt(r)),!pi(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var yi=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function un(r,e){if(e!==void 0&&(typeof e!="object"||!yi(e)))throw new Error("Options should be object or undefined");return Object.assign(r,e)}function ot(r,e){if(!(r instanceof Uint8Array))throw new Error("Uint8Array expected");if(typeof e=="number"&&r.length!==e)throw new Error(`Uint8Array length ${e} expected`)}function fn(r,e){if(r.length!==e.length)throw new Error("equalBytes: Different size of Uint8Arrays");let t=!0;for(let n=0;n>i&o),s=Number(t&o),c=n?4:0,f=n?0:4;r.setUint32(e+c,a,n),r.setUint32(e+f,s,n)}function ur(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function xi(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function ln(r,...e){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function wi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ur(r.outputLen),ur(r.blockLen)}function mi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function gi(r,e){ln(r);let t=e.outputLen;if(r.lengthr[e++]&255|(r[e++]&255)<<8,fr=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=zt(e),ot(e,32);let t=ne(e,0),n=ne(e,2),i=ne(e,4),o=ne(e,6),a=ne(e,8),s=ne(e,10),c=ne(e,12),f=ne(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|s<<2)&8191,this.r[7]=(s>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=ne(e,16+2*u)}process(e,t,n=!1){let i=n?0:2048,{h:o,r:a}=this,s=a[0],c=a[1],f=a[2],u=a[3],h=a[4],d=a[5],x=a[6],g=a[7],w=a[8],_=a[9],H=ne(e,t+0),C=ne(e,t+2),p=ne(e,t+4),S=ne(e,t+6),m=ne(e,t+8),B=ne(e,t+10),D=ne(e,t+12),U=ne(e,t+14),v=o[0]+(H&8191),K=o[1]+((H>>>13|C<<3)&8191),O=o[2]+((C>>>10|p<<6)&8191),I=o[3]+((p>>>7|S<<9)&8191),P=o[4]+((S>>>4|m<<12)&8191),F=o[5]+(m>>>1&8191),z=o[6]+((m>>>14|B<<2)&8191),$=o[7]+((B>>>11|D<<5)&8191),Z=o[8]+((D>>>8|U<<8)&8191),b=o[9]+(U>>>5|i),l=0,y=l+v*s+K*(5*_)+O*(5*w)+I*(5*g)+P*(5*x);l=y>>>13,y&=8191,y+=F*(5*d)+z*(5*h)+$*(5*u)+Z*(5*f)+b*(5*c),l+=y>>>13,y&=8191;let E=l+v*c+K*s+O*(5*_)+I*(5*w)+P*(5*g);l=E>>>13,E&=8191,E+=F*(5*x)+z*(5*d)+$*(5*h)+Z*(5*u)+b*(5*f),l+=E>>>13,E&=8191;let A=l+v*f+K*c+O*s+I*(5*_)+P*(5*w);l=A>>>13,A&=8191,A+=F*(5*g)+z*(5*x)+$*(5*d)+Z*(5*h)+b*(5*u),l+=A>>>13,A&=8191;let T=l+v*u+K*f+O*c+I*s+P*(5*_);l=T>>>13,T&=8191,T+=F*(5*w)+z*(5*g)+$*(5*x)+Z*(5*d)+b*(5*h),l+=T>>>13,T&=8191;let j=l+v*h+K*u+O*f+I*c+P*s;l=j>>>13,j&=8191,j+=F*(5*_)+z*(5*w)+$*(5*g)+Z*(5*x)+b*(5*d),l+=j>>>13,j&=8191;let q=l+v*d+K*h+O*u+I*f+P*c;l=q>>>13,q&=8191,q+=F*s+z*(5*_)+$*(5*w)+Z*(5*g)+b*(5*x),l+=q>>>13,q&=8191;let N=l+v*x+K*d+O*h+I*u+P*f;l=N>>>13,N&=8191,N+=F*c+z*s+$*(5*_)+Z*(5*w)+b*(5*g),l+=N>>>13,N&=8191;let R=l+v*g+K*x+O*d+I*h+P*u;l=R>>>13,R&=8191,R+=F*f+z*c+$*s+Z*(5*_)+b*(5*w),l+=R>>>13,R&=8191;let X=l+v*w+K*g+O*x+I*d+P*h;l=X>>>13,X&=8191,X+=F*u+z*f+$*c+Z*s+b*(5*_),l+=X>>>13,X&=8191;let W=l+v*_+K*w+O*g+I*x+P*d;l=W>>>13,W&=8191,W+=F*h+z*u+$*f+Z*c+b*s,l+=W>>>13,W&=8191,l=(l<<2)+l|0,l=l+y|0,y=l&8191,l=l>>>13,E+=l,o[0]=y,o[1]=E,o[2]=A,o[3]=T,o[4]=j,o[5]=q,o[6]=N,o[7]=R,o[8]=X,o[9]=W}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let s=2;s<10;s++)e[s]+=i,i=e[s]>>>13,e[s]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let s=1;s<10;s++)n[s]=e[s]+i,i=n[s]>>>13,n[s]&=8191;n[9]-=8192;let o=(i^1)-1;for(let s=0;s<10;s++)n[s]&=o;o=~o;for(let s=0;s<10;s++)e[s]=e[s]&o|n[s];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 a=e[0]+t[0];e[0]=a&65535;for(let s=1;s<8;s++)a=(e[s]+t[s]|0)+(a>>>16)|0,e[s]=a&65535}update(e){oe.exists(this);let{buffer:t,blockLen:n}=this;e=zt(e);let i=e.length;for(let o=0;o>>0,e[o++]=n[a]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Ei(r){let e=(n,i)=>r(i).update(zt(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var hn=Ei(r=>new fr(r));var ki=Dt("expand 16-byte k"),vi=Dt("expand 32-byte k"),Si=le(ki),Ai=le(vi),dn=r=>!(r.byteOffset%4),Ye=r=>{let{core:e,rounds:t,counterRight:n,counterLen:i,allow128bitKeys:o,extendNonceFn:a,blockLen:s}=un({rounds:20,counterRight:!1,counterLen:8,allow128bitKeys:!0,blockLen:64},r);oe.number(i),oe.number(t),oe.number(s),oe.bool(n),oe.bool(o);let c=s/4;if(s%4!==0)throw new Error("Salsa/ChaCha: blockLen should be aligned to 4 bytes");return(f,u,h,d,x=0)=>{if(oe.bytes(f),oe.bytes(u),oe.bytes(h),d||(d=new Uint8Array(h.length)),oe.bytes(d),oe.number(x),x<0||x>=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");if(d.length=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");let O=Math.min(s,U-v);if(O===s&&D&&B){let I=v/4;if(v%4!==0)throw new Error("Salsa/ChaCha: wrong block position");for(let P=0;Pr<>>32-e;function st(r,e,t,n,i,o=20){let a=r[0],s=r[1],c=r[2],f=r[3],u=e[0],h=e[1],d=e[2],x=e[3],g=e[4],w=e[5],_=e[6],H=e[7],C=i,p=t[0],S=t[1],m=t[2],B=a,D=s,U=c,v=f,K=u,O=h,I=d,P=x,F=g,z=w,$=_,Z=H,b=C,l=p,y=S,E=m;for(let T=0;T{r.update(e);let t=e.length%16;t&&r.update(Li.subarray(t))},bn=(r,e,t,n,i)=>{let o=r(e,t,new Uint8Array(32)),a=hn.create(o);i&&pn(a,i),pn(a,n);let s=new Uint8Array(16),c=cn(s);cr(c,0,BigInt(i?i.length:0),!0),cr(c,8,BigInt(n.length),!0),a.update(s);let f=a.digest();return o.fill(0),f},yn=r=>(e,t,n)=>(ot(e,32),ot(t),{tagLength:16,encrypt:o=>{let a=new Uint8Array(o.length+16);r(e,t,o,a,1);let s=bn(r,e,t,a.subarray(0,-16),n);return a.set(s,o.length),a},decrypt:o=>{if(o.length<16)throw new Error("Encrypted data should be at least 16");let a=o.subarray(-16),s=o.subarray(0,-16),c=bn(r,e,t,s,n);if(!fn(a,c))throw new Error("Wrong tag");return r(e,t,s,void 0,1)}}),lr=yn(Bi),ks=yn(Ii);var hr=class{constructor(e,t){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._key=new Uint8Array(t)}async seal(e,t,n){return await this._seal(e,t,n)}async open(e,t,n){return await this._open(e,t,n)}_seal(e,t,n){return new Promise(i=>{let o=lr(this._key,new Uint8Array(e),new Uint8Array(n)).encrypt(new Uint8Array(t));i(o.buffer)})}_open(e,t,n){return new Promise(i=>{let o=lr(this._key,new Uint8Array(e),new Uint8Array(n)).decrypt(new Uint8Array(t));i(o.buffer)})}},at=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return new hr(this._api,e)}};function dr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Oi(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function xn(r,...e){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Ki(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");dr(r.outputLen),dr(r.blockLen)}function Ui(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Hi(r,e){xn(r);let t=e.outputLen;if(r.lengthr instanceof Uint8Array;var mn=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Mt=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),be=(r,e)=>r<<32-e|r>>>e,Ni=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ni)throw new Error("Non little-endian hardware is not supported");var Ks=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ct(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Be(r){if(typeof r=="string"&&(r=ct(r)),!wn(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function qt(...r){let e=new Uint8Array(r.reduce((n,i)=>n+i.length,0)),t=0;return r.forEach(n=>{if(!wn(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Pe=class{clone(){return this._cloneInto()}};function ue(r){let e=n=>r().update(Be(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function gn(r){let e=(n,i)=>r(i).update(Be(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}function We(r=32){if(Rt&&typeof Rt.getRandomValues=="function")return Rt.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var Gt=class extends Pe{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ie.hash(e);let n=Be(t);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 i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let a=0;anew Gt(r,e).update(t).digest();ut.create=(r,e)=>new Gt(r,e);function Ci(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),a=Number(t>>i&o),s=Number(t&o),c=n?4:0,f=n?0:4;r.setUint32(e+c,a,n),r.setUint32(e+f,s,n)}var Je=class extends Pe{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Mt(this.buffer)}update(e){ie.exists(this);let{view:t,buffer:n,blockLen:i}=this;e=Be(e);let o=e.length;for(let a=0;ai-a&&(this.process(n,0),a=0);for(let h=a;hu.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;hr&e^~r&t,Di=(r,e,t)=>r&e^r&t^e&t,zi=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]),Ie=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Le=new Uint32Array(64),Ft=class extends Je{constructor(){super(64,32,8,!1),this.A=Ie[0]|0,this.B=Ie[1]|0,this.C=Ie[2]|0,this.D=Ie[3]|0,this.E=Ie[4]|0,this.F=Ie[5]|0,this.G=Ie[6]|0,this.H=Ie[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:a,G:s,H:c}=this;return[e,t,n,i,o,a,s,c]}set(e,t,n,i,o,a,s,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=a|0,this.G=s|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Le[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let d=Le[h-15],x=Le[h-2],g=be(d,7)^be(d,18)^d>>>3,w=be(x,17)^be(x,19)^x>>>10;Le[h]=w+Le[h-7]+g+Le[h-16]|0}let{A:n,B:i,C:o,D:a,E:s,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let d=be(s,6)^be(s,11)^be(s,25),x=u+d+ji(s,c,f)+zi[h]+Le[h]|0,w=(be(n,2)^be(n,13)^be(n,22))+Di(n,i,o)|0;u=f,f=c,c=s,s=a+x|0,a=o,o=i,i=n,n=x+w|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,a=a+this.D|0,s=s+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,i,o,a,s,c,f,u)}roundClean(){Le.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},pr=class extends Ft{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}},_n=ue(()=>new Ft),Ms=ue(()=>new pr);var $t=BigInt(4294967295),br=BigInt(32);function En(r,e=!1){return e?{h:Number(r&$t),l:Number(r>>br&$t)}:{h:Number(r>>br&$t)|0,l:Number(r&$t)|0}}function Ri(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;iBigInt(r>>>0)<>>0),qi=(r,e,t)=>r>>>t,Gi=(r,e,t)=>r<<32-t|e>>>t,Fi=(r,e,t)=>r>>>t|e<<32-t,$i=(r,e,t)=>r<<32-t|e>>>t,Zi=(r,e,t)=>r<<64-t|e>>>t-32,Vi=(r,e,t)=>r>>>t-32|e<<64-t,Xi=(r,e)=>e,Yi=(r,e)=>r,Wi=(r,e,t)=>r<>>32-t,Ji=(r,e,t)=>e<>>32-t,Qi=(r,e,t)=>e<>>64-t,eo=(r,e,t)=>r<>>64-t;function to(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var ro=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),no=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,io=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),oo=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,so=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),ao=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0,co={fromBig:En,split:Ri,toBig:Mi,shrSH:qi,shrSL:Gi,rotrSH:Fi,rotrSL:$i,rotrBH:Zi,rotrBL:Vi,rotr32H:Xi,rotr32L:Yi,rotlSH:Wi,rotlSL:Ji,rotlBH:Qi,rotlBL:eo,add:to,add3L:ro,add3H:no,add4L:io,add4H:oo,add5H:ao,add5L:so},L=co;var[uo,fo]=L.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(r=>BigInt(r))),Oe=new Uint32Array(80),Ke=new Uint32Array(80),Qe=class extends Je{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:t,Bh:n,Bl:i,Ch:o,Cl:a,Dh:s,Dl:c,Eh:f,El:u,Fh:h,Fl:d,Gh:x,Gl:g,Hh:w,Hl:_}=this;return[e,t,n,i,o,a,s,c,f,u,h,d,x,g,w,_]}set(e,t,n,i,o,a,s,c,f,u,h,d,x,g,w,_){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=a|0,this.Dh=s|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=d|0,this.Gh=x|0,this.Gl=g|0,this.Hh=w|0,this.Hl=_|0}process(e,t){for(let p=0;p<16;p++,t+=4)Oe[p]=e.getUint32(t),Ke[p]=e.getUint32(t+=4);for(let p=16;p<80;p++){let S=Oe[p-15]|0,m=Ke[p-15]|0,B=L.rotrSH(S,m,1)^L.rotrSH(S,m,8)^L.shrSH(S,m,7),D=L.rotrSL(S,m,1)^L.rotrSL(S,m,8)^L.shrSL(S,m,7),U=Oe[p-2]|0,v=Ke[p-2]|0,K=L.rotrSH(U,v,19)^L.rotrBH(U,v,61)^L.shrSH(U,v,6),O=L.rotrSL(U,v,19)^L.rotrBL(U,v,61)^L.shrSL(U,v,6),I=L.add4L(D,O,Ke[p-7],Ke[p-16]),P=L.add4H(I,B,K,Oe[p-7],Oe[p-16]);Oe[p]=P|0,Ke[p]=I|0}let{Ah:n,Al:i,Bh:o,Bl:a,Ch:s,Cl:c,Dh:f,Dl:u,Eh:h,El:d,Fh:x,Fl:g,Gh:w,Gl:_,Hh:H,Hl:C}=this;for(let p=0;p<80;p++){let S=L.rotrSH(h,d,14)^L.rotrSH(h,d,18)^L.rotrBH(h,d,41),m=L.rotrSL(h,d,14)^L.rotrSL(h,d,18)^L.rotrBL(h,d,41),B=h&x^~h&w,D=d&g^~d&_,U=L.add5L(C,m,D,fo[p],Ke[p]),v=L.add5H(U,H,S,B,uo[p],Oe[p]),K=U|0,O=L.rotrSH(n,i,28)^L.rotrBH(n,i,34)^L.rotrBH(n,i,39),I=L.rotrSL(n,i,28)^L.rotrBL(n,i,34)^L.rotrBL(n,i,39),P=n&o^n&s^o&s,F=i&a^i&c^a&c;H=w|0,C=_|0,w=x|0,_=g|0,x=h|0,g=d|0,{h,l:d}=L.add(f|0,u|0,v|0,K|0),f=s|0,u=c|0,s=o|0,c=a|0,o=n|0,a=i|0;let z=L.add3L(K,I,F);n=L.add3H(z,v,O,P),i=z|0}({h:n,l:i}=L.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:a}=L.add(this.Bh|0,this.Bl|0,o|0,a|0),{h:s,l:c}=L.add(this.Ch|0,this.Cl|0,s|0,c|0),{h:f,l:u}=L.add(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:d}=L.add(this.Eh|0,this.El|0,h|0,d|0),{h:x,l:g}=L.add(this.Fh|0,this.Fl|0,x|0,g|0),{h:w,l:_}=L.add(this.Gh|0,this.Gl|0,w|0,_|0),{h:H,l:C}=L.add(this.Hh|0,this.Hl|0,H|0,C|0),this.set(n,i,o,a,s,c,f,u,h,d,x,g,w,_,H,C)}roundClean(){Oe.fill(0),Ke.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)}},yr=class extends Qe{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}},xr=class extends Qe{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}},wr=class extends Qe{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}},ft=ue(()=>new Qe),Vs=ue(()=>new yr),Xs=ue(()=>new xr),kn=ue(()=>new wr);var lt=class extends Nt{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}buildLabeledIkm(e,t){let n=new Uint8Array(7+this._suiteId.byteLength+e.byteLength+t.byteLength);return n.set(or,0),n.set(this._suiteId,7),n.set(e,7+this._suiteId.byteLength),n.set(t,7+this._suiteId.byteLength+e.byteLength),n}buildLabeledInfo(e,t,n){let i=new Uint8Array(9+this._suiteId.byteLength+e.byteLength+t.byteLength);return i.set(new Uint8Array([0,n]),0),i.set(or,2),i.set(this._suiteId,9),i.set(e,9+this._suiteId.byteLength),i.set(t,9+this._suiteId.byteLength+e.byteLength),i}async extract(e,t){if(this.checkInit(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)switch(this.algHash.hash){case"SHA-256":return ut(_n,new Uint8Array(e),new Uint8Array(t));case"SHA-384":return ut(kn,new Uint8Array(e),new Uint8Array(t));default:return ut(ft,new Uint8Array(e),new Uint8Array(t))}let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}async expand(e,t,n){this.checkInit();let i=await this._api.importKey("raw",e,this.algHash,!1,["sign"]),o=new ArrayBuffer(n),a=new Uint8Array(o),s=G,c=new Uint8Array(t),f=new Uint8Array(1);if(n>255*this.hashSize)throw new Error("Entropy limit reached");let u=new Uint8Array(this.hashSize+c.length+1);for(let h=1,d=0;d=s.length?(a.set(s,d),d+=s.length):(a.set(s.slice(0,a.length-d),d),d+=a.length-d);return o}async extractAndExpand(e,t,n,i){this.checkInit();let o=await this._api.importKey("raw",t,"HKDF",!1,ke);return await this._api.deriveBits({name:"HKDF",hash:this.algHash.hash,salt:e,info:n},o,i*8)}async labeledExtract(e,t,n){return await this.extract(e,this.buildLabeledIkm(t,n))}async labeledExpand(e,t,n,i){return await this.expand(e,this.buildLabeledInfo(t,n,i),i)}},Ue=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}},ze=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha384}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-384",length:384}})}},He=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha512}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-512",length:512}})}};var lo={},vn=ho(globalThis,lo);function ho(r,e){return new Proxy(r,{get(t,n,i){return n in e?e[n]:r[n]},set(t,n,i){return n in e&&delete e[n],r[n]=i,!0},deleteProperty(t,n){let i=!1;return n in e&&(delete e[n],i=!0),n in r&&(delete r[n],i=!0),i},ownKeys(t){let n=Reflect.ownKeys(r),i=Reflect.ownKeys(e),o=new Set(i);return[...n.filter(a=>!o.has(a)),...i]},defineProperty(t,n,i){return n in e&&delete e[n],Reflect.defineProperty(r,n,i),!0},getOwnPropertyDescriptor(t,n){return n in e?Reflect.getOwnPropertyDescriptor(e,n):Reflect.getOwnPropertyDescriptor(r,n)},has(t,n){return n in e||n in r}})}var Sn=()=>typeof vn<"u",An=()=>typeof caches<"u";var ht=r=>typeof r=="object"&&r!==null&&typeof r.privateKey=="object"&&typeof r.publicKey=="object";function we(r,e){if(e<=0)throw new Error("i2Osp: too small size");if(r>=256**e)throw new Error("i2Osp: too large integer");let t=new Uint8Array(e);for(let n=0;n>8;return t}function Pn(r,e){if(r.byteLength!==e.byteLength)throw new Error("xor: different length inputs");let t=new Uint8Array(r.byteLength);for(let n=0;nNumber.MAX_SAFE_INTEGER)throw new Lt("Message limit reached");e.seq+=1}async setupBidirectional(e,t){try{this._r.baseNonce=new Uint8Array(await this.export(t,this._nN));let n=await this.export(e,this._nK);this._r.key=this._aead.createAeadKey(n),this._r.seq=0}catch(n){throw this._r.baseNonce=G,n}}};var Zt=class extends tt{async seal(e,t=G){if(this._r.baseNonce.length===0)throw new Ce("Bidirectional encryption is not setup");let n;try{n=await this._r.key.seal(this.computeNonce(this._r),e,t)}catch(i){throw new Ce(i)}return this.incrementSeq(this._r),n}async open(e,t=G){let n;try{n=await this._f.key.open(this.computeNonce(this._f),e,t)}catch(i){throw new je(i)}return this.incrementSeq(this._f),n}};var Vt=class extends tt{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}async seal(e,t=G){let n;try{n=await this._f.key.seal(this.computeNonce(this._f),e,t)}catch(i){throw new Ce(i)}return this.incrementSeq(this._f),n}async open(e,t=G){if(this._r.baseNonce.length===0)throw new je("Bidirectional encryption is not setup");let n;try{n=await this._r.key.open(this.computeNonce(this._r),e,t)}catch(i){throw new je(i)}return this.incrementSeq(this._r),n}};async function In(){if((Sn()||An())&&globalThis.crypto!==void 0)return globalThis.crypto.subtle;try{let{webcrypto:r}=await import("crypto");return r.subtle}catch{throw new de("Web Cryptograph API not supported")}}var Xt=class{constructor(e){Object.defineProperty(this,"_num",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._num=new Uint8Array(e)}val(){return this._num}reset(){this._num.fill(0)}set(e){if(e.length!==this._num.length)throw new Error("Bignum.set: invalid argument");this._num.set(e)}isZero(){for(let e=0;ee[t])return!1}return!1}};var bo=new Uint8Array([48,65,2,1,0,48,19,6,7,42,134,72,206,61,2,1,6,8,42,134,72,206,61,3,1,7,4,39,48,37,2,1,1,4,32]),yo=new Uint8Array([48,78,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,34,4,55,48,53,2,1,1,4,48]),xo=new Uint8Array([48,96,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,35,4,73,48,71,2,1,1,4,66]),rt=class extends re{constructor(e,t){switch(super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_alg",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nDh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_order",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bitmask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pkcs8AlgId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=t,e){case J.DhkemP256HkdfSha256:this._alg={name:"ECDH",namedCurve:"P-256"},this._nPk=65,this._nSk=32,this._nDh=32,this._order=on,this._bitmask=255,this._pkcs8AlgId=bo;break;case J.DhkemP384HkdfSha384:this._alg={name:"ECDH",namedCurve:"P-384"},this._nPk=97,this._nSk=48,this._nDh=48,this._order=sn,this._bitmask=255,this._pkcs8AlgId=yo;break;default:this._alg={name:"ECDH",namedCurve:"P-521"},this._nPk=133,this._nSk=66,this._nDh=66,this._order=an,this._bitmask=1,this._pkcs8AlgId=xo;break}}async serializePublicKey(e){this.checkInit();let t=await this._api.exportKey("raw",e);if(t.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");return t}async deserializePublicKey(e){if(this.checkInit(),e.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");try{return await this._api.importKey("raw",e,this._alg,!0,[])}catch{throw new Error("Invalid public key for the ciphersuite")}}async importKey(e,t,n){if(this.checkInit(),e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async _importRawKey(e,t){if(t&&e.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");if(!t&&e.byteLength!==this._nSk)throw new Error("Invalid private key for the ciphersuite");try{if(t)return await this._api.importKey("raw",e,this._alg,!0,[]);let n=new Uint8Array(e),i=new Uint8Array(this._pkcs8AlgId.length+n.length);return i.set(this._pkcs8AlgId,0),i.set(n,this._pkcs8AlgId.length),await this._api.importKey("pkcs8",i,this._alg,!0,ke)}catch{throw new Error("Invalid key for the ciphersuite")}}async _importJWK(e,t){if(typeof e.crv>"u"||e.crv!==this._alg.namedCurve)throw new Error(`Invalid crv: ${e.crv}`);if(t){if(typeof e.d<"u")throw new Error("Invalid key: `d` should not be set");return await this._api.importKey("jwk",e,this._alg,!0,[])}if(typeof e.d>"u")throw new Error("Invalid key: `d` not found");return await this._api.importKey("jwk",e,this._alg,!0,ke)}async derivePublicKey(e){this.checkInit();let t=await this._api.exportKey("jwk",e);return delete t.d,delete t.key_ops,await this._api.importKey("jwk",t,this._alg,!0,[])}async generateKeyPair(){return this.checkInit(),await this._api.generateKey(this._alg,!0,ke)}async deriveKeyPair(e){this.checkInit();let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=new Xt(this._nSk);for(let a=0;n.isZero()||!n.lessThan(this._order);a++){if(a>255)throw new Error("Faild to derive a key pair");let s=new Uint8Array(await this._hkdf.labeledExpand(t,nn,we(a,1),this._nSk));s[0]=s[0]&this._bitmask,n.set(s)}let i=new Uint8Array(this._pkcs8AlgId.length+n.val().length);i.set(this._pkcs8AlgId,0),i.set(n.val(),this._pkcs8AlgId.length);let o=await this._api.importKey("pkcs8",i,this._alg,!0,ke);return n.reset(),{privateKey:o,publicKey:await this.derivePublicKey(o)}}async dh(e,t){return this.checkInit(),await this._api.deriveBits({name:"ECDH",public:t},e,this._nDh*8)}};var _a=BigInt(0),wo=BigInt(1),mo=BigInt(2),Yt=r=>r instanceof Uint8Array,go=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function pt(r){if(!Yt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;tn+i.length,0)),t=0;return r.forEach(n=>{if(!Yt(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Kn=r=>(mo<typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ve(r,e,t={}){let n=(i,o,a)=>{let s=_o[o];if(typeof s!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(a&&c===void 0)&&!s(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Q=BigInt(0),Y=BigInt(1),Re=BigInt(2),ko=BigInt(3),_r=BigInt(4),Un=BigInt(5),Hn=BigInt(8),vo=BigInt(9),So=BigInt(16);function M(r,e){let t=r%e;return t>=Q?t:e+t}function Er(r,e,t){if(t<=Q||e 0");if(t===Y)return Q;let n=Y;for(;e>Q;)e&Y&&(n=n*r%t),r=r*r%t,e>>=Y;return n}function V(r,e,t){let n=r;for(;e-- >Q;)n*=n,n%=t;return n}function Tn(r,e){if(r===Q||e<=Q)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=M(r,e),n=e,i=Q,o=Y,a=Y,s=Q;for(;t!==Q;){let f=n/t,u=n%t,h=i-a*f,d=o-s*f;n=t,t=u,i=a,o=s,a=h,s=d}if(n!==Y)throw new Error("invert: does not exist");return M(i,e)}function Ao(r){let e=(r-Y)/Re,t,n,i;for(t=r-Y,n=0;t%Re===Q;t/=Re,n++);for(i=Re;i(M(r,e)&Y)===Y,Bo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Cn(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Bo.reduce((n,i)=>(n[i]="function",n),e);return ve(r,t)}function Io(r,e,t){if(t 0");if(t===Q)return r.ONE;if(t===Y)return e;let n=r.ONE,i=e;for(;t>Q;)t&Y&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Y;return n}function Lo(r,e){let t=new Array(e.length),n=e.reduce((o,a,s)=>r.is0(a)?o:(t[s]=o,r.mul(o,a)),r.ONE),i=r.inv(n);return e.reduceRight((o,a,s)=>r.is0(a)?o:(t[s]=r.mul(o,t[s]),r.mul(o,a)),i),t}function kr(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Jt(r,e,t=!1,n={}){if(r<=Q)throw new Error(`Expected Fp ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=kr(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let a=Po(r),s=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Kn(i),ZERO:Q,ONE:Y,create:c=>M(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Q<=c&&cc===Q,isOdd:c=>(c&Y)===Y,neg:c=>M(-c,r),eql:(c,f)=>c===f,sqr:c=>M(c*c,r),add:(c,f)=>M(c+f,r),sub:(c,f)=>M(c-f,r),mul:(c,f)=>M(c*f,r),pow:(c,f)=>Io(s,c,f),div:(c,f)=>M(c*Tn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Tn(c,r),sqrt:n.sqrt||(c=>a(s,c)),invertBatch:c=>Lo(s,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?Te(c,o):gr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?me(c):mr(c)}});return Object.freeze(s)}function jn(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}var Oo=BigInt(0),vr=BigInt(1);function Dn(r,e){let t=(i,o)=>{let a=o.negate();return i?a:o},n=i=>{let o=Math.ceil(e/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,o){let a=r.ZERO,s=i;for(;o>Oo;)o&vr&&(a=a.add(s)),s=s.double(),o>>=vr;return a},precomputeWindow(i,o){let{windows:a,windowSize:s}=n(o),c=[],f=i,u=f;for(let h=0;h>=x,_>c&&(_-=d,a+=vr);let H=w,C=w+Math.abs(_)-1,p=g%2!==0,S=_<0;_===0?u=u.add(t(p,o[H])):f=f.add(t(S,o[C]))}return{p:f,f:u}},wNAFCached(i,o,a,s){let c=i._WINDOW_SIZE||1,f=o.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&o.set(i,s(f))),this.wNAF(c,f,a)}}}function zn(r){return Cn(r.Fp),ve(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kr(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ye=BigInt(0),fe=BigInt(1),Qt=BigInt(2),Ko=BigInt(8),Uo={zip215:!0};function Ho(r){let e=zn(r);return ve(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Me(r){let e=Ho(r),{Fp:t,n,prehash:i,hash:o,randomBytes:a,nByteLength:s,h:c}=e,f=Qt<{try{return{isValid:!0,value:t.sqrt(b*t.inv(l))}}catch{return{isValid:!1,value:ye}}}),d=e.adjustScalarBytes||(b=>b),x=e.domain||((b,l,y)=>{if(l.length||y)throw new Error("Contexts/pre-hash are not supported");return b}),g=b=>typeof b=="bigint"&&yeg(b)&&g(l)&&bb===ye||w(b,f);function H(b,l){if(w(b,l))return b;throw new Error(`Expected valid scalar < ${l}, got ${typeof b} ${b}`)}function C(b){return b===ye?b:H(b,n)}let p=new Map;function S(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}class m{constructor(l,y,E,A){if(this.ex=l,this.ey=y,this.ez=E,this.et=A,!_(l))throw new Error("x required");if(!_(y))throw new Error("y required");if(!_(E))throw new Error("z required");if(!_(A))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(l){if(l instanceof m)throw new Error("extended point not allowed");let{x:y,y:E}=l||{};if(!_(y)||!_(E))throw new Error("invalid affine point");return new m(y,E,fe,u(y*E))}static normalizeZ(l){let y=t.invertBatch(l.map(E=>E.ez));return l.map((E,A)=>E.toAffine(y[A])).map(m.fromAffine)}_setWindowSize(l){this._WINDOW_SIZE=l,p.delete(this)}assertValidity(){let{a:l,d:y}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:E,ey:A,ez:T,et:j}=this,q=u(E*E),N=u(A*A),R=u(T*T),X=u(R*R),W=u(q*l),xe=u(R*u(W+N)),se=u(X+u(y*u(q*N)));if(xe!==se)throw new Error("bad point: equation left != right (1)");let Ae=u(E*A),ge=u(T*j);if(Ae!==ge)throw new Error("bad point: equation left != right (2)")}equals(l){S(l);let{ex:y,ey:E,ez:A}=this,{ex:T,ey:j,ez:q}=l,N=u(y*q),R=u(T*A),X=u(E*q),W=u(j*A);return N===R&&X===W}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:l}=e,{ex:y,ey:E,ez:A}=this,T=u(y*y),j=u(E*E),q=u(Qt*u(A*A)),N=u(l*T),R=y+E,X=u(u(R*R)-T-j),W=N+j,xe=W-q,se=N-j,Ae=u(X*xe),ge=u(W*se),vt=u(X*se),St=u(xe*W);return new m(Ae,ge,St,vt)}add(l){S(l);let{a:y,d:E}=e,{ex:A,ey:T,ez:j,et:q}=this,{ex:N,ey:R,ez:X,et:W}=l;if(y===BigInt(-1)){let Hr=u((T-A)*(R+N)),Tr=u((T+A)*(R-N)),ir=u(Tr-Hr);if(ir===ye)return this.double();let Nr=u(j*Qt*W),Cr=u(q*Qt*X),jr=Cr+Nr,Dr=Tr+Hr,zr=Cr-Nr,fi=u(jr*ir),li=u(Dr*zr),hi=u(jr*zr),di=u(ir*Dr);return new m(fi,li,di,hi)}let xe=u(A*N),se=u(T*R),Ae=u(q*E*W),ge=u(j*X),vt=u((A+T)*(N+R)-xe-se),St=ge-Ae,Kr=ge+Ae,Ur=u(se-y*xe),si=u(vt*St),ai=u(Kr*Ur),ci=u(vt*Ur),ui=u(St*Kr);return new m(si,ai,ui,ci)}subtract(l){return this.add(l.negate())}wNAF(l){return U.wNAFCached(this,p,l,m.normalizeZ)}multiply(l){let{p:y,f:E}=this.wNAF(H(l,n));return m.normalizeZ([y,E])[0]}multiplyUnsafe(l){let y=C(l);return y===ye?D:this.equals(D)||y===fe?this:this.equals(B)?this.wNAF(y).p:U.unsafeLadder(this,y)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(l){let{ex:y,ey:E,ez:A}=this,T=this.is0();l==null&&(l=T?Ko:t.inv(A));let j=u(y*l),q=u(E*l),N=u(A*l);if(T)return{x:ye,y:fe};if(N!==fe)throw new Error("invZ was invalid");return{x:j,y:q}}clearCofactor(){let{h:l}=e;return l===fe?this:this.multiplyUnsafe(l)}static fromHex(l,y=!1){let{d:E,a:A}=e,T=t.BYTES;l=ce("pointHex",l,T);let j=l.slice(),q=l[T-1];j[T-1]=q&-129;let N=me(j);N===ye||(y?H(N,f):H(N,t.ORDER));let R=u(N*N),X=u(R-fe),W=u(E*R-A),{isValid:xe,value:se}=h(X,W);if(!xe)throw new Error("Point.fromHex: invalid y coordinate");let Ae=(se&fe)===fe,ge=(q&128)!==0;if(!y&&se===ye&&ge)throw new Error("Point.fromHex: x=0 and x_0=1");return ge!==Ae&&(se=u(-se)),m.fromAffine({x:se,y:N})}static fromPrivateKey(l){return O(l).point}toRawBytes(){let{x:l,y}=this.toAffine(),E=Te(y,t.BYTES);return E[E.length-1]|=l&fe?128:0,E}toHex(){return pt(this.toRawBytes())}}m.BASE=new m(e.Gx,e.Gy,fe,u(e.Gx*e.Gy)),m.ZERO=new m(ye,fe,fe,ye);let{BASE:B,ZERO:D}=m,U=Dn(m,s*8);function v(b){return M(b,n)}function K(b){return v(me(b))}function O(b){let l=s;b=ce("private key",b,l);let y=ce("hashed private key",o(b),2*l),E=d(y.slice(0,l)),A=y.slice(l,2*l),T=K(E),j=B.multiply(T),q=j.toRawBytes();return{head:E,prefix:A,scalar:T,point:j,pointBytes:q}}function I(b){return O(b).pointBytes}function P(b=new Uint8Array,...l){let y=Wt(...l);return K(o(x(y,ce("context",b),!!i)))}function F(b,l,y={}){b=ce("message",b),i&&(b=i(b));let{prefix:E,scalar:A,pointBytes:T}=O(l),j=P(y.context,E,b),q=B.multiply(j).toRawBytes(),N=P(y.context,q,T,b),R=v(j+N*A);C(R);let X=Wt(q,Te(R,t.BYTES));return ce("result",X,s*2)}let z=Uo;function $(b,l,y,E=z){let{context:A,zip215:T}=E,j=t.BYTES;b=ce("signature",b,2*j),l=ce("message",l),i&&(l=i(l));let q=me(b.slice(j,2*j)),N,R,X;try{N=m.fromHex(y,T),R=m.fromHex(b.slice(0,j),T),X=B.multiplyUnsafe(q)}catch{return!1}if(!T&&N.isSmallOrder())return!1;let W=P(A,R.toRawBytes(),N.toRawBytes(),l);return R.add(N.multiplyUnsafe(W)).subtract(X).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:I,sign:F,verify:$,ExtendedPoint:m,utils:{getExtendedPublicKey:O,randomPrivateKey:()=>a(t.BYTES),precompute(b=8,l=m.BASE){return l._setWindowSize(b),l.multiply(BigInt(3)),l}}}}var bt=BigInt(0),Sr=BigInt(1);function To(r){return ve(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function er(r){let e=To(r),{P:t}=e,n=p=>M(p,t),i=e.montgomeryBits,o=Math.ceil(i/8),a=e.nByteLength,s=e.adjustScalarBytes||(p=>p),c=e.powPminus2||(p=>Er(p,t-BigInt(2),t));function f(p,S,m){let B=n(p*(S-m));return S=n(S-B),m=n(m+B),[S,m]}function u(p){if(typeof p=="bigint"&&bt<=p&&p=bt;z--){let $=B>>z&Sr;I^=$,P=f(I,U,K),U=P[0],K=P[1],P=f(I,v,O),v=P[0],O=P[1],I=$;let Z=U+v,b=n(Z*Z),l=U-v,y=n(l*l),E=b-y,A=K+O,T=K-O,j=n(T*Z),q=n(A*l),N=j+q,R=j-q;K=n(N*N),O=n(D*n(R*R)),U=n(b*y),v=n(E*(b+n(h*E)))}P=f(I,U,K),U=P[0],K=P[1],P=f(I,v,O),v=P[0],O=P[1];let F=c(v);return n(U*F)}function x(p){return Te(n(p),o)}function g(p){let S=ce("u coordinate",p,o);return a===o&&(S[a-1]&=127),me(S)}function w(p){let S=ce("scalar",p);if(S.length!==o&&S.length!==a)throw new Error(`Expected ${o} or ${a} bytes, got ${S.length}`);return me(s(S))}function _(p,S){let m=g(S),B=w(p),D=d(m,B);if(D===bt)throw new Error("Invalid private or public key received");return x(D)}let H=x(e.Gu);function C(p){return _(p,H)}return{scalarMult:_,scalarMultBase:C,getSharedSecret:(p,S)=>_(p,S),getPublicKey:p=>C(p),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:H}}var yt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Rn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Za=BigInt(0),Co=BigInt(1),Ar=BigInt(2),jo=BigInt(5),Mn=BigInt(10),Do=BigInt(20),zo=BigInt(40),qn=BigInt(80);function Gn(r){let e=yt,n=r*r%e*r%e,i=V(n,Ar,e)*n%e,o=V(i,Co,e)*r%e,a=V(o,jo,e)*o%e,s=V(a,Mn,e)*a%e,c=V(s,Do,e)*s%e,f=V(c,zo,e)*c%e,u=V(f,qn,e)*f%e,h=V(u,qn,e)*f%e,d=V(h,Mn,e)*a%e;return{pow_p_5_8:V(d,Ar,e)*r%e,b2:n}}function Fn(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ro(r,e){let t=yt,n=M(e*e*e,t),i=M(n*n*e,t),o=Gn(r*i).pow_p_5_8,a=M(r*n*o,t),s=M(e*a*a,t),c=a,f=M(a*Rn,t),u=s===r,h=s===M(-r,t),d=s===M(-r*Rn,t);return u&&(a=c),(h||d)&&(a=f),Nn(a,t)&&(a=M(-a,t)),{isValid:u||h,value:a}}var Se=Jt(yt,void 0,!0),Pr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Se,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ft,randomBytes:We,adjustScalarBytes:Fn,uvRatio:Ro},$n=Me(Pr);function Zn(r,e,t){if(e.length>255)throw new Error("Context is too big");return qt(ct("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var Va=Me({...Pr,domain:Zn}),Xa=Me({...Pr,domain:Zn,prehash:ft}),Br=(()=>er({P:yt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=yt,{pow_p_5_8:t,b2:n}=Gn(r);return M(V(t,BigInt(3),e)*n,e)},adjustScalarBytes:Fn,randomBytes:We}))();var Mo=(Se.ORDER+BigInt(3))/BigInt(8),Ya=Se.pow(Ar,Mo),Wa=Se.sqrt(Se.neg(Se.ONE)),Ja=(Se.ORDER-BigInt(5))/BigInt(8),Qa=BigInt(486662);var ec=jn(Se,Se.neg(BigInt(486664)));var tc=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),rc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),nc=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ic=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var oc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ee=class{constructor(e,t,n){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extractable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"usages",{enumerable:!0,configurable:!0,writable:!0,value:ke}),this.key=t,this.type=n,this.algorithm={name:e},n==="public"&&(this.usages=[])}};var qe="X25519",tr=class extends re{constructor(e){super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=32,this._nSk=32}async serializePublicKey(e){return await this._serializePublicKey(e)}async deserializePublicKey(e){return await this._deserializePublicKey(e)}async importKey(e,t,n){if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async derivePublicKey(e){return await this._derivePublicKey(e)}async generateKeyPair(){let e=$n.utils.randomPrivateKey(),t=new ee(qe,e,"private");return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Kt,G,this._nSk),i=new ee(qe,new Uint8Array(n),"private");return{privateKey:i,publicKey:await this.derivePublicKey(i)}}async dh(e,t){return await this._dh(e,t)}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_deserializePublicKey(e){return new Promise((t,n)=>{e.byteLength!==this._nPk?n(new Error("Invalid public key for the ciphersuite")):t(new ee(qe,new Uint8Array(e),"public"))})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid public key for the ciphersuite")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid private key for the ciphersuite")),n(new ee(qe,new Uint8Array(e),t?"public":"private"))})}_importJWK(e,t){return new Promise((n,i)=>{(typeof e.kty>"u"||e.kty!=="OKP")&&i(new Error(`Invalid kty: ${e.kty}`)),(typeof e.crv>"u"||e.crv!=="X25519")&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x>"u"&&i(new Error("Invalid key: `x` not found")),n(new ee(qe,et(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(qe,et(e.d),"private")))})}_derivePublicKey(e){return new Promise(t=>{let n=Br.getPublicKey(e.key);t(new ee(qe,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Br.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var[Yn,Wn,Jn]=[[],[],[]],qo=BigInt(0),xt=BigInt(1),Go=BigInt(2),Fo=BigInt(7),$o=BigInt(256),Zo=BigInt(113);for(let r=0,e=xt,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],Yn.push(2*(5*n+t)),Wn.push((r+1)*(r+2)/2%64);let i=qo;for(let o=0;o<7;o++)e=(e<>Fo)*Zo)%$o,e&Go&&(i^=xt<<(xt<t>32?L.rotlBH(r,e,t):L.rotlSH(r,e,t),Xn=(r,e,t)=>t>32?L.rotlBL(r,e,t):L.rotlSL(r,e,t);function Yo(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let a=0;a<10;a++)t[a]=r[a]^r[a+10]^r[a+20]^r[a+30]^r[a+40];for(let a=0;a<10;a+=2){let s=(a+8)%10,c=(a+2)%10,f=t[c],u=t[c+1],h=Vn(f,u,1)^t[s],d=Xn(f,u,1)^t[s+1];for(let x=0;x<50;x+=10)r[a+x]^=h,r[a+x+1]^=d}let i=r[2],o=r[3];for(let a=0;a<24;a++){let s=Wn[a],c=Vn(i,o,s),f=Xn(i,o,s),u=Yn[a];i=r[u],o=r[u+1],r[u]=c,r[u+1]=f}for(let a=0;a<50;a+=10){for(let s=0;s<10;s++)t[s]=r[a+s];for(let s=0;s<10;s++)r[a+s]^=~t[(s+2)%10]&t[(s+4)%10]}r[0]^=Vo[n],r[1]^=Xo[n]}t.fill(0)}var rr=class r extends Pe{constructor(e,t,n,i=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=i,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,ie.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=mn(this.state)}keccak(){Yo(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){ie.exists(this);let{blockLen:t,state:n}=this;e=Be(e);let i=e.length;for(let o=0;o=n&&this.keccak();let a=Math.min(n-this.posOut,o-i);e.set(t.subarray(this.posOut,this.posOut+a),i),this.posOut+=a,i+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ie.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ie.output(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:i,rounds:o,enableXOF:a}=this;return e||(e=new r(t,n,i,a,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=i,e.enableXOF=a,e.destroyed=this.destroyed,e}},Ne=(r,e,t)=>ue(()=>new rr(e,r,t)),yc=Ne(6,144,224/8),xc=Ne(6,136,256/8),wc=Ne(6,104,384/8),mc=Ne(6,72,512/8),gc=Ne(1,144,224/8),_c=Ne(1,136,256/8),Ec=Ne(1,104,384/8),kc=Ne(1,72,512/8),Qn=(r,e,t)=>gn((n={})=>new rr(e,r,n.dkLen===void 0?t:n.dkLen,!0)),vc=Qn(31,168,128/8),Ir=Qn(31,136,256/8);var Wo=ue(()=>Ir.create({dkLen:114})),Jo=ue(()=>Ir.create({dkLen:64})),wt=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439");function ei(r){let e=wt,t=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(11),a=BigInt(22),s=BigInt(44),c=BigInt(88),f=BigInt(223),u=r*r*r%e,h=u*u*r%e,d=V(h,i,e)*h%e,x=V(d,i,e)*h%e,g=V(x,n,e)*u%e,w=V(g,o,e)*g%e,_=V(w,a,e)*w%e,H=V(_,s,e)*_%e,C=V(H,c,e)*H%e,p=V(C,s,e)*_%e,S=V(p,n,e)*u%e,m=V(S,t,e)*r%e;return V(m,f,e)*S%e}function ti(r){return r[0]&=252,r[55]|=128,r[56]=0,r}var ri=Jt(wt,456,!0),Kc=BigInt(4),ni={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:ri,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:Wo,randomBytes:We,adjustScalarBytes:ti,domain:(r,e,t)=>{if(e.length>255)throw new Error(`Context is too big: ${e.length}`);return qt(ct("SigEd448"),new Uint8Array([t?1:0,e.length]),e,r)},uvRatio:(r,e)=>{let t=wt,n=M(r*r*e,t),i=M(n*r,t),o=M(i*n*e,t),a=ei(o),s=M(i*a,t),c=M(s*s,t);return{isValid:M(c*e,t)===r,value:s}}},ii=Me(ni),Uc=Me({...ni,prehash:Jo}),Lr=(()=>er({a:BigInt(156326),montgomeryBits:448,nByteLength:57,P:wt,Gu:BigInt(5),powPminus2:r=>{let e=wt,t=ei(r),n=V(t,BigInt(2),e);return M(n*r,e)},adjustScalarBytes:ti,randomBytes:We}))();var Hc=(ri.ORDER-BigInt(3))/BigInt(4),Tc=BigInt(156326);var Ge="X448",nr=class extends re{constructor(e){super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=56,this._nSk=56}async serializePublicKey(e){return await this._serializePublicKey(e)}async deserializePublicKey(e){return await this._deserializePublicKey(e)}async importKey(e,t,n){if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async derivePublicKey(e){return await this._derivePublicKey(e)}async generateKeyPair(){let e=ii.utils.randomPrivateKey(),t=new ee(Ge,e,"private");return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Kt,G,this._nSk),i=new ee(Ge,new Uint8Array(n),"private");return{privateKey:i,publicKey:await this.derivePublicKey(i)}}async dh(e,t){return await this._dh(e,t)}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_deserializePublicKey(e){return new Promise((t,n)=>{e.byteLength!==this._nPk?n(new Error("Invalid public key for the ciphersuite")):t(new ee(Ge,new Uint8Array(e),"public"))})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid public key for the ciphersuite")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid private key for the ciphersuite")),n(new ee(Ge,new Uint8Array(e),t?"public":"private"))})}_importJWK(e,t){return new Promise((n,i)=>{e.kty!=="OKP"&&i(new Error(`Invalid kty: ${e.kty}`)),e.crv!=="X448"&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x!="string"&&i(new Error("Invalid key: `x` not found")),n(new ee(Ge,et(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ge,et(e.d),"private")))})}_derivePublicKey(e){return new Promise(t=>{let n=Lr.getPublicKey(e.key);t(new ee(Ge,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Lr.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Fe=class extends re{constructor(e,t){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prim",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._prim=e,this._kdf=t}init(e){super.init(e);let t=new Uint8Array(Zr);t.set(we(this.id,2),3),this._prim.init(e),this._kdf.init(e,t),super.init(e)}async generateKeyPair(){try{return await this._prim.generateKeyPair()}catch(e){throw new de(e)}}async deriveKeyPair(e){try{return await this._prim.deriveKeyPair(e)}catch(t){throw new Ot(t)}}async serializePublicKey(e){try{return await this._prim.serializePublicKey(e)}catch(t){throw new At(t)}}async deserializePublicKey(e){try{return await this._prim.deserializePublicKey(e)}catch(t){throw new $e(t)}}async importKey(e,t,n){try{return await this._prim.importKey(e,t,n)}catch(i){throw new $e(i)}}async encap(e){try{let t=e.nonEphemeralKeyPair===void 0?await this.generateKeyPair():e.nonEphemeralKeyPair,n=await this._prim.serializePublicKey(t.publicKey),i=await this._prim.serializePublicKey(e.recipientPublicKey),o;if(e.senderKey===void 0)o=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey));else{let c=ht(e.senderKey)?e.senderKey.privateKey:e.senderKey,f=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey)),u=new Uint8Array(await this._prim.dh(c,e.recipientPublicKey));o=dt(f,u)}let a;if(e.senderKey===void 0)a=dt(new Uint8Array(n),new Uint8Array(i));else{let c=ht(e.senderKey)?e.senderKey.publicKey:await this._prim.derivePublicKey(e.senderKey),f=await this._prim.serializePublicKey(c);a=Bn(new Uint8Array(n),new Uint8Array(i),new Uint8Array(f))}let s=await this.generateSharedSecret(o,a);return{enc:n,sharedSecret:s}}catch(t){throw new Pt(t)}}async decap(e){let t;try{t=await this._prim.deserializePublicKey(e.enc)}catch(n){throw new $e(n)}try{let n=ht(e.recipientKey)?e.recipientKey.privateKey:e.recipientKey,i=ht(e.recipientKey)?e.recipientKey.publicKey:await this._prim.derivePublicKey(e.recipientKey),o=await this._prim.serializePublicKey(i),a;if(e.senderPublicKey===void 0)a=new Uint8Array(await this._prim.dh(n,t));else{let c=new Uint8Array(await this._prim.dh(n,t)),f=new Uint8Array(await this._prim.dh(n,e.senderPublicKey));a=dt(c,f)}let s;if(e.senderPublicKey===void 0)s=dt(new Uint8Array(e.enc),new Uint8Array(o));else{let c=await this._prim.serializePublicKey(e.senderPublicKey);s=new Uint8Array(e.enc.byteLength+o.byteLength+c.byteLength),s.set(new Uint8Array(e.enc),0),s.set(new Uint8Array(o),e.enc.byteLength),s.set(new Uint8Array(c),e.enc.byteLength+o.byteLength)}return await this.generateSharedSecret(a,s)}catch(n){throw new Bt(n)}}async generateSharedSecret(e,t){let n=this._kdf.buildLabeledIkm(Vr,e),i=this._kdf.buildLabeledInfo(Jr,t,this.secretSize);return await this._kdf.extractAndExpand(G,n,i,this.secretSize)}},mt=class extends Fe{constructor(){let e=new Ue,t=new rt(J.DhkemP256HkdfSha256,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}},gt=class extends Fe{constructor(){let e=new ze,t=new rt(J.DhkemP384HkdfSha384,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP384HkdfSha384}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:48})}},_t=class extends Fe{constructor(){let e=new He,t=new rt(J.DhkemP521HkdfSha512,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP521HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:64})}},Et=class extends Fe{constructor(){let e=new Ue,t=new tr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemX25519HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}},kt=class extends Fe{constructor(){let e=new He,t=new nr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemX448HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56})}};var Or=class{constructor(e){if(Object.defineProperty(this,"kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),typeof e.kem!="number")this._kem=e.kem;else switch(e.kem){case J.DhkemP256HkdfSha256:this._kem=new mt;break;case J.DhkemP384HkdfSha384:this._kem=new gt;break;case J.DhkemP521HkdfSha512:this._kem=new _t;break;case J.DhkemX25519HkdfSha256:this._kem=new Et;break;case J.DhkemX448HkdfSha512:this._kem=new kt;break;default:throw new he(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(this.kem=this._kem.id,typeof e.kdf!="number")this._kdf=e.kdf;else switch(e.kdf){case Ee.HkdfSha256:this._kdf=new Ue;break;case Ee.HkdfSha384:this._kdf=new ze;break;default:this._kdf=new He;break}if(this.kdf=this._kdf.id,typeof e.aead!="number")this._aead=e.aead;else switch(e.aead){case te.Aes128Gcm:this._aead=new nt;break;case te.Aes256Gcm:this._aead=new it;break;case te.Chacha20Poly1305:this._aead=new at;break;default:this._aead=new jt;break}this.aead=this._aead.id,this._suiteId=new Uint8Array($r),this._suiteId.set(we(this.kem,2),4),this._suiteId.set(we(this.kdf,2),6),this._suiteId.set(we(this.aead,2),8)}get kemSecretSize(){return this._kem.secretSize}get kemEncSize(){return this._kem.encSize}get kemPublicKeySize(){return this._kem.publicKeySize}get kemPrivateKeySize(){return this._kem.privateKeySize}get aeadKeySize(){return this._aead.keySize}get aeadNonceSize(){return this._aead.nonceSize}get aeadTagSize(){return this._aead.tagSize}async kemContext(){return await this.setup(),this._kem}async kdfContext(){return await this.setup(),this._kdf}async createAeadKey(e){return await this.setup(),this._aead.createAeadKey(e)}async generateKeyPair(){return await this.setup(),await this._kem.generateKeyPair()}async deriveKeyPair(e){if(e.byteLength>128)throw new he("Too long ikm");return await this.setup(),await this._kem.deriveKeyPair(e)}async importKey(e,t,n=!0){return await this.setup(),await this._kem.importKey(e,t,n)}async createSenderContext(e){this.validateInputLength(e),await this.setup();let t=await this._kem.encap(e),n;return e.psk!==void 0?n=e.senderKey!==void 0?_e.AuthPsk:_e.Psk:n=e.senderKey!==void 0?_e.Auth:_e.Base,await this.keyScheduleS(n,t.sharedSecret,t.enc,e)}async createRecipientContext(e){this.validateInputLength(e),await this.setup();let t=await this._kem.decap(e),n;return e.psk!==void 0?n=e.senderPublicKey!==void 0?_e.AuthPsk:_e.Psk:n=e.senderPublicKey!==void 0?_e.Auth:_e.Base,await this.keyScheduleR(n,t,e)}async seal(e,t,n=G){let i=await this.createSenderContext(e);return{ct:await i.seal(t,n),enc:i.enc}}async open(e,t,n=G){return await(await this.createRecipientContext(e)).open(t,n)}async setup(){if(this._api!==void 0)return;let e=await In();this._kem.init(e),this._kdf.init(e,this._suiteId),this._aead.init(e),this._api=e}async keySchedule(e,t,n){let i=n.psk===void 0?G:new Uint8Array(n.psk.id),o=await this._kdf.labeledExtract(G,Yr,i),a=n.info===void 0?G:new Uint8Array(n.info),s=await this._kdf.labeledExtract(G,Xr,a),c=new Uint8Array(1+o.byteLength+s.byteLength);c.set(new Uint8Array([e]),0),c.set(new Uint8Array(o),1),c.set(new Uint8Array(s),1+o.byteLength);let f=n.psk===void 0?G:new Uint8Array(n.psk.key),u=this._kdf.buildLabeledIkm(Wr,f),h=this._kdf.buildLabeledInfo(tn,c,this._kdf.hashSize),d=await this._kdf.extractAndExpand(t,u,h,this._kdf.hashSize);if(this._aead.id===te.ExportOnly)return{aead:this._aead,exporterSecret:d};let x=this._kdf.buildLabeledInfo(Qr,c,this._aead.keySize),g=await this._kdf.extractAndExpand(t,u,x,this._aead.keySize),w=this._kdf.buildLabeledInfo(en,c,this._aead.nonceSize),_=await this._kdf.extractAndExpand(t,u,w,this._aead.nonceSize);return{aead:this._aead,exporterSecret:d,key:g,baseNonce:new Uint8Array(_),seq:0}}async keyScheduleS(e,t,n,i){let o=await this.keySchedule(e,t,i);return o.key===void 0?new Ht(this._api,this._kdf,o.exporterSecret,n):new Vt(this._api,this._kdf,o,n)}async keyScheduleR(e,t,n){let i=await this.keySchedule(e,t,n);return i.key===void 0?new Ut(this._api,this._kdf,i.exporterSecret):new Zt(this._api,this._kdf,i)}validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>128)throw new he("Too long info");if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new he(`PSK must have at least ${32} bytes`);if(e.psk.key.byteLength>128)throw new he("Too long psk.key");if(e.psk.id.byteLength>128)throw new he("Too long psk.id")}}};export{Gr as Aead,te as AeadId,nt as Aes128Gcm,it as Aes256Gcm,at as Chacha20Poly1305,Or as CipherSuite,Bt as DecapError,Ot as DeriveKeyPairError,$e as DeserializeError,mt as DhkemP256HkdfSha256,gt as DhkemP384HkdfSha384,_t as DhkemP521HkdfSha512,Et as DhkemX25519HkdfSha256,kt as DhkemX448HkdfSha512,Pt as EncapError,It as ExportError,Ue as HkdfSha256,ze as HkdfSha384,He as HkdfSha512,he as InvalidParamError,qr as Kdf,Ee as KdfId,Mr as Kem,J as KemId,Lt as MessageLimitReachedError,de as NotSupportedError,je as OpenError,Ce as SealError,At as SerializeError,Rr as ValidationError}; -/*! Bundled license information: - -@noble/ciphers/esm/utils.js: - (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *) - -@noble/hashes/esm/utils.js: - (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/utils.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/modular.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/curve.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/edwards.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/montgomery.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed25519.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed448.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) -*/ diff --git a/index.html b/index.html deleted file mode 100644 index 030be424a..000000000 --- a/index.html +++ /dev/null @@ -1,95 +0,0 @@ - - hpke-js test - - - -

hpke-js test

- -
- - -
- -
- -
- - - - - - - - - -
pass: -
fail: -
-
- - diff --git a/src/.gitkeep b/src/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/hpke.js b/src/hpke.js deleted file mode 100644 index cdd8b2f0e..000000000 --- a/src/hpke.js +++ /dev/null @@ -1,30 +0,0 @@ -var ae=class extends Error{constructor(e){let t;e instanceof Error?t=e.message:typeof e=="string"?t=e:t="",super(t),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.message===""?this.message=this.name:this.message=this.name+": "+this.message}},he=class extends ae{},Rr=class extends ae{},At=class extends ae{},$e=class extends ae{},Pt=class extends ae{},Bt=class extends ae{},It=class extends ae{},Ce=class extends ae{},je=class extends ae{},Lt=class extends ae{},Ot=class extends ae{},de=class extends ae{};var _e={Base:0,Psk:1,Auth:2,AuthPsk:3},Mr={DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256K1HkdfSha256:19,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33},J=Mr,qr={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3},Ee=qr,Gr={Aes128Gcm:1,Aes256Gcm:2,Chacha20Poly1305:3,ExportOnly:65535},te=Gr;var ke=["deriveBits"],Fr=["encrypt","decrypt"];var G=new Uint8Array(0),or=new Uint8Array([72,80,75,69,45,118,49]),$r=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),Zr=new Uint8Array([75,69,77,0,0]),Ze=new Uint8Array([100,107,112,95,112,114,107]),Vr=new Uint8Array([101,97,101,95,112,114,107]),Xr=new Uint8Array([105,110,102,111,95,104,97,115,104]),Yr=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),Wr=new Uint8Array([115,101,99,114,101,116]),Jr=new Uint8Array([115,104,97,114,101,100,95,115,101,99,114,101,116]),Qr=new Uint8Array([107,101,121]),en=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),tn=new Uint8Array([101,120,112]),rn=new Uint8Array([115,101,99]),nn=new Uint8Array([99,97,110,100,105,100,97,116,101]),Kt=new Uint8Array([115,107]),on=new Uint8Array([255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,188,230,250,173,167,23,158,132,243,185,202,194,252,99,37,81]),sn=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,199,99,77,129,244,55,45,223,88,26,13,178,72,176,167,122,236,236,25,106,204,197,41,115]),an=new Uint8Array([1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,81,134,135,131,191,47,150,107,127,204,1,72,247,9,165,208,59,181,201,184,137,156,71,174,187,111,183,30,145,56,100,9]);var Ve=class{constructor(e,t,n){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exporterSecret",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._kdf=t,this.exporterSecret=n}async seal(e,t){return await this._emitError1()}async open(e,t){return await this._emitError1()}async setupBidirectional(e,t){return await this._emitError2()}async export(e,t){if(e.byteLength>128)throw new he("Too long exporter context");try{return await this._kdf.labeledExpand(this.exporterSecret,rn,new Uint8Array(e),t)}catch(n){throw new It(n)}}_emitError1(){return new Promise((e,t)=>{t(new de("Not available on export-only mode"))})}_emitError2(){return new Promise((e,t)=>{t(new de("Not available on export-only mode"))})}},Ut=class extends Ve{},Ht=class extends Ve{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}};var Tt=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}checkInit(){if(typeof this._api>"u")throw new Error("Not initialized. Call init()")}},re=class extends Tt{constructor(){super()}init(e){this._api=e}},Nt=class extends Tt{constructor(){super(),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:G})}init(e,t){this._api=e,this._suiteId=t}};var Ct=class{constructor(e,t){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_rawKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._rawKey=t}async seal(e,t,n){this._key===void 0&&(this._key=await this.importKey(this._rawKey),new Uint8Array(this._rawKey).fill(0));let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.encrypt(i,this._key,t)}async open(e,t,n){this._key===void 0&&(this._key=await this.importKey(this._rawKey),new Uint8Array(this._rawKey).fill(0));let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.decrypt(i,this._key,t)}async importKey(e){return await this._api.importKey("raw",e,{name:"AES-GCM"},!0,Fr)}},sr=class extends Ct{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}},ar=class extends Ct{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes256Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}},nt=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return this.checkInit(),new sr(this._api,e)}},it=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Aes256Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return this.checkInit(),new ar(this._api,e)}};var jt=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.ExportOnly}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:0})}createAeadKey(e){throw new de("createAeadKey() is not supported on ExportOnly")}};var pi=r=>r instanceof Uint8Array;var le=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),cn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),bi=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!bi)throw new Error("Non little-endian hardware is not supported");function Dt(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function zt(r){if(typeof r=="string"&&(r=Dt(r)),!pi(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var yi=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function un(r,e){if(e!==void 0&&(typeof e!="object"||!yi(e)))throw new Error("Options should be object or undefined");return Object.assign(r,e)}function ot(r,e){if(!(r instanceof Uint8Array))throw new Error("Uint8Array expected");if(typeof e=="number"&&r.length!==e)throw new Error(`Uint8Array length ${e} expected`)}function fn(r,e){if(r.length!==e.length)throw new Error("equalBytes: Different size of Uint8Arrays");let t=!0;for(let n=0;n>i&o),s=Number(t&o),c=n?4:0,f=n?0:4;r.setUint32(e+c,a,n),r.setUint32(e+f,s,n)}function ur(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function xi(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function ln(r,...e){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function wi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ur(r.outputLen),ur(r.blockLen)}function mi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function gi(r,e){ln(r);let t=e.outputLen;if(r.lengthr[e++]&255|(r[e++]&255)<<8,fr=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=zt(e),ot(e,32);let t=ne(e,0),n=ne(e,2),i=ne(e,4),o=ne(e,6),a=ne(e,8),s=ne(e,10),c=ne(e,12),f=ne(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|s<<2)&8191,this.r[7]=(s>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=ne(e,16+2*u)}process(e,t,n=!1){let i=n?0:2048,{h:o,r:a}=this,s=a[0],c=a[1],f=a[2],u=a[3],h=a[4],d=a[5],x=a[6],g=a[7],w=a[8],_=a[9],H=ne(e,t+0),C=ne(e,t+2),p=ne(e,t+4),S=ne(e,t+6),m=ne(e,t+8),B=ne(e,t+10),D=ne(e,t+12),U=ne(e,t+14),v=o[0]+(H&8191),K=o[1]+((H>>>13|C<<3)&8191),O=o[2]+((C>>>10|p<<6)&8191),I=o[3]+((p>>>7|S<<9)&8191),P=o[4]+((S>>>4|m<<12)&8191),F=o[5]+(m>>>1&8191),z=o[6]+((m>>>14|B<<2)&8191),$=o[7]+((B>>>11|D<<5)&8191),Z=o[8]+((D>>>8|U<<8)&8191),b=o[9]+(U>>>5|i),l=0,y=l+v*s+K*(5*_)+O*(5*w)+I*(5*g)+P*(5*x);l=y>>>13,y&=8191,y+=F*(5*d)+z*(5*h)+$*(5*u)+Z*(5*f)+b*(5*c),l+=y>>>13,y&=8191;let E=l+v*c+K*s+O*(5*_)+I*(5*w)+P*(5*g);l=E>>>13,E&=8191,E+=F*(5*x)+z*(5*d)+$*(5*h)+Z*(5*u)+b*(5*f),l+=E>>>13,E&=8191;let A=l+v*f+K*c+O*s+I*(5*_)+P*(5*w);l=A>>>13,A&=8191,A+=F*(5*g)+z*(5*x)+$*(5*d)+Z*(5*h)+b*(5*u),l+=A>>>13,A&=8191;let T=l+v*u+K*f+O*c+I*s+P*(5*_);l=T>>>13,T&=8191,T+=F*(5*w)+z*(5*g)+$*(5*x)+Z*(5*d)+b*(5*h),l+=T>>>13,T&=8191;let j=l+v*h+K*u+O*f+I*c+P*s;l=j>>>13,j&=8191,j+=F*(5*_)+z*(5*w)+$*(5*g)+Z*(5*x)+b*(5*d),l+=j>>>13,j&=8191;let q=l+v*d+K*h+O*u+I*f+P*c;l=q>>>13,q&=8191,q+=F*s+z*(5*_)+$*(5*w)+Z*(5*g)+b*(5*x),l+=q>>>13,q&=8191;let N=l+v*x+K*d+O*h+I*u+P*f;l=N>>>13,N&=8191,N+=F*c+z*s+$*(5*_)+Z*(5*w)+b*(5*g),l+=N>>>13,N&=8191;let R=l+v*g+K*x+O*d+I*h+P*u;l=R>>>13,R&=8191,R+=F*f+z*c+$*s+Z*(5*_)+b*(5*w),l+=R>>>13,R&=8191;let X=l+v*w+K*g+O*x+I*d+P*h;l=X>>>13,X&=8191,X+=F*u+z*f+$*c+Z*s+b*(5*_),l+=X>>>13,X&=8191;let W=l+v*_+K*w+O*g+I*x+P*d;l=W>>>13,W&=8191,W+=F*h+z*u+$*f+Z*c+b*s,l+=W>>>13,W&=8191,l=(l<<2)+l|0,l=l+y|0,y=l&8191,l=l>>>13,E+=l,o[0]=y,o[1]=E,o[2]=A,o[3]=T,o[4]=j,o[5]=q,o[6]=N,o[7]=R,o[8]=X,o[9]=W}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let s=2;s<10;s++)e[s]+=i,i=e[s]>>>13,e[s]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let s=1;s<10;s++)n[s]=e[s]+i,i=n[s]>>>13,n[s]&=8191;n[9]-=8192;let o=(i^1)-1;for(let s=0;s<10;s++)n[s]&=o;o=~o;for(let s=0;s<10;s++)e[s]=e[s]&o|n[s];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 a=e[0]+t[0];e[0]=a&65535;for(let s=1;s<8;s++)a=(e[s]+t[s]|0)+(a>>>16)|0,e[s]=a&65535}update(e){oe.exists(this);let{buffer:t,blockLen:n}=this;e=zt(e);let i=e.length;for(let o=0;o>>0,e[o++]=n[a]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function Ei(r){let e=(n,i)=>r(i).update(zt(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var hn=Ei(r=>new fr(r));var ki=Dt("expand 16-byte k"),vi=Dt("expand 32-byte k"),Si=le(ki),Ai=le(vi),dn=r=>!(r.byteOffset%4),Ye=r=>{let{core:e,rounds:t,counterRight:n,counterLen:i,allow128bitKeys:o,extendNonceFn:a,blockLen:s}=un({rounds:20,counterRight:!1,counterLen:8,allow128bitKeys:!0,blockLen:64},r);oe.number(i),oe.number(t),oe.number(s),oe.bool(n),oe.bool(o);let c=s/4;if(s%4!==0)throw new Error("Salsa/ChaCha: blockLen should be aligned to 4 bytes");return(f,u,h,d,x=0)=>{if(oe.bytes(f),oe.bytes(u),oe.bytes(h),d||(d=new Uint8Array(h.length)),oe.bytes(d),oe.number(x),x<0||x>=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");if(d.length=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");let O=Math.min(s,U-v);if(O===s&&D&&B){let I=v/4;if(v%4!==0)throw new Error("Salsa/ChaCha: wrong block position");for(let P=0;Pr<>>32-e;function st(r,e,t,n,i,o=20){let a=r[0],s=r[1],c=r[2],f=r[3],u=e[0],h=e[1],d=e[2],x=e[3],g=e[4],w=e[5],_=e[6],H=e[7],C=i,p=t[0],S=t[1],m=t[2],B=a,D=s,U=c,v=f,K=u,O=h,I=d,P=x,F=g,z=w,$=_,Z=H,b=C,l=p,y=S,E=m;for(let T=0;T{r.update(e);let t=e.length%16;t&&r.update(Li.subarray(t))},bn=(r,e,t,n,i)=>{let o=r(e,t,new Uint8Array(32)),a=hn.create(o);i&&pn(a,i),pn(a,n);let s=new Uint8Array(16),c=cn(s);cr(c,0,BigInt(i?i.length:0),!0),cr(c,8,BigInt(n.length),!0),a.update(s);let f=a.digest();return o.fill(0),f},yn=r=>(e,t,n)=>(ot(e,32),ot(t),{tagLength:16,encrypt:o=>{let a=new Uint8Array(o.length+16);r(e,t,o,a,1);let s=bn(r,e,t,a.subarray(0,-16),n);return a.set(s,o.length),a},decrypt:o=>{if(o.length<16)throw new Error("Encrypted data should be at least 16");let a=o.subarray(-16),s=o.subarray(0,-16),c=bn(r,e,t,s,n);if(!fn(a,c))throw new Error("Wrong tag");return r(e,t,s,void 0,1)}}),lr=yn(Bi),ks=yn(Ii);var hr=class{constructor(e,t){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._key=new Uint8Array(t)}async seal(e,t,n){return await this._seal(e,t,n)}async open(e,t,n){return await this._open(e,t,n)}_seal(e,t,n){return new Promise(i=>{let o=lr(this._key,new Uint8Array(e),new Uint8Array(n)).encrypt(new Uint8Array(t));i(o.buffer)})}_open(e,t,n){return new Promise(i=>{let o=lr(this._key,new Uint8Array(e),new Uint8Array(n)).decrypt(new Uint8Array(t));i(o.buffer)})}},at=class extends re{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:te.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createAeadKey(e){return new hr(this._api,e)}};function dr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function Oi(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function xn(r,...e){if(!(r instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(r.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`)}function Ki(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");dr(r.outputLen),dr(r.blockLen)}function Ui(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Hi(r,e){xn(r);let t=e.outputLen;if(r.lengthr instanceof Uint8Array;var mn=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Mt=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),be=(r,e)=>r<<32-e|r>>>e,Ni=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ni)throw new Error("Non little-endian hardware is not supported");var Ks=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function ct(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Be(r){if(typeof r=="string"&&(r=ct(r)),!wn(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function qt(...r){let e=new Uint8Array(r.reduce((n,i)=>n+i.length,0)),t=0;return r.forEach(n=>{if(!wn(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Pe=class{clone(){return this._cloneInto()}};function ue(r){let e=n=>r().update(Be(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function gn(r){let e=(n,i)=>r(i).update(Be(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}function We(r=32){if(Rt&&typeof Rt.getRandomValues=="function")return Rt.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var Gt=class extends Pe{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,ie.hash(e);let n=Be(t);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 i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let a=0;anew Gt(r,e).update(t).digest();ut.create=(r,e)=>new Gt(r,e);function Ci(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),a=Number(t>>i&o),s=Number(t&o),c=n?4:0,f=n?0:4;r.setUint32(e+c,a,n),r.setUint32(e+f,s,n)}var Je=class extends Pe{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Mt(this.buffer)}update(e){ie.exists(this);let{view:t,buffer:n,blockLen:i}=this;e=Be(e);let o=e.length;for(let a=0;ai-a&&(this.process(n,0),a=0);for(let h=a;hu.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;hr&e^~r&t,Di=(r,e,t)=>r&e^r&t^e&t,zi=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]),Ie=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Le=new Uint32Array(64),Ft=class extends Je{constructor(){super(64,32,8,!1),this.A=Ie[0]|0,this.B=Ie[1]|0,this.C=Ie[2]|0,this.D=Ie[3]|0,this.E=Ie[4]|0,this.F=Ie[5]|0,this.G=Ie[6]|0,this.H=Ie[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:a,G:s,H:c}=this;return[e,t,n,i,o,a,s,c]}set(e,t,n,i,o,a,s,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=a|0,this.G=s|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Le[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let d=Le[h-15],x=Le[h-2],g=be(d,7)^be(d,18)^d>>>3,w=be(x,17)^be(x,19)^x>>>10;Le[h]=w+Le[h-7]+g+Le[h-16]|0}let{A:n,B:i,C:o,D:a,E:s,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let d=be(s,6)^be(s,11)^be(s,25),x=u+d+ji(s,c,f)+zi[h]+Le[h]|0,w=(be(n,2)^be(n,13)^be(n,22))+Di(n,i,o)|0;u=f,f=c,c=s,s=a+x|0,a=o,o=i,i=n,n=x+w|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,a=a+this.D|0,s=s+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,i,o,a,s,c,f,u)}roundClean(){Le.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},pr=class extends Ft{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}},_n=ue(()=>new Ft),Ms=ue(()=>new pr);var $t=BigInt(4294967295),br=BigInt(32);function En(r,e=!1){return e?{h:Number(r&$t),l:Number(r>>br&$t)}:{h:Number(r>>br&$t)|0,l:Number(r&$t)|0}}function Ri(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;iBigInt(r>>>0)<>>0),qi=(r,e,t)=>r>>>t,Gi=(r,e,t)=>r<<32-t|e>>>t,Fi=(r,e,t)=>r>>>t|e<<32-t,$i=(r,e,t)=>r<<32-t|e>>>t,Zi=(r,e,t)=>r<<64-t|e>>>t-32,Vi=(r,e,t)=>r>>>t-32|e<<64-t,Xi=(r,e)=>e,Yi=(r,e)=>r,Wi=(r,e,t)=>r<>>32-t,Ji=(r,e,t)=>e<>>32-t,Qi=(r,e,t)=>e<>>64-t,eo=(r,e,t)=>r<>>64-t;function to(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var ro=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),no=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,io=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),oo=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,so=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),ao=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0,co={fromBig:En,split:Ri,toBig:Mi,shrSH:qi,shrSL:Gi,rotrSH:Fi,rotrSL:$i,rotrBH:Zi,rotrBL:Vi,rotr32H:Xi,rotr32L:Yi,rotlSH:Wi,rotlSL:Ji,rotlBH:Qi,rotlBL:eo,add:to,add3L:ro,add3H:no,add4L:io,add4H:oo,add5H:ao,add5L:so},L=co;var[uo,fo]=L.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(r=>BigInt(r))),Oe=new Uint32Array(80),Ke=new Uint32Array(80),Qe=class extends Je{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:t,Bh:n,Bl:i,Ch:o,Cl:a,Dh:s,Dl:c,Eh:f,El:u,Fh:h,Fl:d,Gh:x,Gl:g,Hh:w,Hl:_}=this;return[e,t,n,i,o,a,s,c,f,u,h,d,x,g,w,_]}set(e,t,n,i,o,a,s,c,f,u,h,d,x,g,w,_){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=a|0,this.Dh=s|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=d|0,this.Gh=x|0,this.Gl=g|0,this.Hh=w|0,this.Hl=_|0}process(e,t){for(let p=0;p<16;p++,t+=4)Oe[p]=e.getUint32(t),Ke[p]=e.getUint32(t+=4);for(let p=16;p<80;p++){let S=Oe[p-15]|0,m=Ke[p-15]|0,B=L.rotrSH(S,m,1)^L.rotrSH(S,m,8)^L.shrSH(S,m,7),D=L.rotrSL(S,m,1)^L.rotrSL(S,m,8)^L.shrSL(S,m,7),U=Oe[p-2]|0,v=Ke[p-2]|0,K=L.rotrSH(U,v,19)^L.rotrBH(U,v,61)^L.shrSH(U,v,6),O=L.rotrSL(U,v,19)^L.rotrBL(U,v,61)^L.shrSL(U,v,6),I=L.add4L(D,O,Ke[p-7],Ke[p-16]),P=L.add4H(I,B,K,Oe[p-7],Oe[p-16]);Oe[p]=P|0,Ke[p]=I|0}let{Ah:n,Al:i,Bh:o,Bl:a,Ch:s,Cl:c,Dh:f,Dl:u,Eh:h,El:d,Fh:x,Fl:g,Gh:w,Gl:_,Hh:H,Hl:C}=this;for(let p=0;p<80;p++){let S=L.rotrSH(h,d,14)^L.rotrSH(h,d,18)^L.rotrBH(h,d,41),m=L.rotrSL(h,d,14)^L.rotrSL(h,d,18)^L.rotrBL(h,d,41),B=h&x^~h&w,D=d&g^~d&_,U=L.add5L(C,m,D,fo[p],Ke[p]),v=L.add5H(U,H,S,B,uo[p],Oe[p]),K=U|0,O=L.rotrSH(n,i,28)^L.rotrBH(n,i,34)^L.rotrBH(n,i,39),I=L.rotrSL(n,i,28)^L.rotrBL(n,i,34)^L.rotrBL(n,i,39),P=n&o^n&s^o&s,F=i&a^i&c^a&c;H=w|0,C=_|0,w=x|0,_=g|0,x=h|0,g=d|0,{h,l:d}=L.add(f|0,u|0,v|0,K|0),f=s|0,u=c|0,s=o|0,c=a|0,o=n|0,a=i|0;let z=L.add3L(K,I,F);n=L.add3H(z,v,O,P),i=z|0}({h:n,l:i}=L.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:a}=L.add(this.Bh|0,this.Bl|0,o|0,a|0),{h:s,l:c}=L.add(this.Ch|0,this.Cl|0,s|0,c|0),{h:f,l:u}=L.add(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:d}=L.add(this.Eh|0,this.El|0,h|0,d|0),{h:x,l:g}=L.add(this.Fh|0,this.Fl|0,x|0,g|0),{h:w,l:_}=L.add(this.Gh|0,this.Gl|0,w|0,_|0),{h:H,l:C}=L.add(this.Hh|0,this.Hl|0,H|0,C|0),this.set(n,i,o,a,s,c,f,u,h,d,x,g,w,_,H,C)}roundClean(){Oe.fill(0),Ke.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)}},yr=class extends Qe{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}},xr=class extends Qe{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}},wr=class extends Qe{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}},ft=ue(()=>new Qe),Vs=ue(()=>new yr),Xs=ue(()=>new xr),kn=ue(()=>new wr);var lt=class extends Nt{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}buildLabeledIkm(e,t){let n=new Uint8Array(7+this._suiteId.byteLength+e.byteLength+t.byteLength);return n.set(or,0),n.set(this._suiteId,7),n.set(e,7+this._suiteId.byteLength),n.set(t,7+this._suiteId.byteLength+e.byteLength),n}buildLabeledInfo(e,t,n){let i=new Uint8Array(9+this._suiteId.byteLength+e.byteLength+t.byteLength);return i.set(new Uint8Array([0,n]),0),i.set(or,2),i.set(this._suiteId,9),i.set(e,9+this._suiteId.byteLength),i.set(t,9+this._suiteId.byteLength+e.byteLength),i}async extract(e,t){if(this.checkInit(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)switch(this.algHash.hash){case"SHA-256":return ut(_n,new Uint8Array(e),new Uint8Array(t));case"SHA-384":return ut(kn,new Uint8Array(e),new Uint8Array(t));default:return ut(ft,new Uint8Array(e),new Uint8Array(t))}let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}async expand(e,t,n){this.checkInit();let i=await this._api.importKey("raw",e,this.algHash,!1,["sign"]),o=new ArrayBuffer(n),a=new Uint8Array(o),s=G,c=new Uint8Array(t),f=new Uint8Array(1);if(n>255*this.hashSize)throw new Error("Entropy limit reached");let u=new Uint8Array(this.hashSize+c.length+1);for(let h=1,d=0;d=s.length?(a.set(s,d),d+=s.length):(a.set(s.slice(0,a.length-d),d),d+=a.length-d);return o}async extractAndExpand(e,t,n,i){this.checkInit();let o=await this._api.importKey("raw",t,"HKDF",!1,ke);return await this._api.deriveBits({name:"HKDF",hash:this.algHash.hash,salt:e,info:n},o,i*8)}async labeledExtract(e,t,n){return await this.extract(e,this.buildLabeledIkm(t,n))}async labeledExpand(e,t,n,i){return await this.expand(e,this.buildLabeledInfo(t,n,i),i)}},Ue=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}},ze=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha384}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-384",length:384}})}},He=class extends lt{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Ee.HkdfSha512}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-512",length:512}})}};var lo={},vn=ho(globalThis,lo);function ho(r,e){return new Proxy(r,{get(t,n,i){return n in e?e[n]:r[n]},set(t,n,i){return n in e&&delete e[n],r[n]=i,!0},deleteProperty(t,n){let i=!1;return n in e&&(delete e[n],i=!0),n in r&&(delete r[n],i=!0),i},ownKeys(t){let n=Reflect.ownKeys(r),i=Reflect.ownKeys(e),o=new Set(i);return[...n.filter(a=>!o.has(a)),...i]},defineProperty(t,n,i){return n in e&&delete e[n],Reflect.defineProperty(r,n,i),!0},getOwnPropertyDescriptor(t,n){return n in e?Reflect.getOwnPropertyDescriptor(e,n):Reflect.getOwnPropertyDescriptor(r,n)},has(t,n){return n in e||n in r}})}var Sn=()=>typeof vn<"u",An=()=>typeof caches<"u";var ht=r=>typeof r=="object"&&r!==null&&typeof r.privateKey=="object"&&typeof r.publicKey=="object";function we(r,e){if(e<=0)throw new Error("i2Osp: too small size");if(r>=256**e)throw new Error("i2Osp: too large integer");let t=new Uint8Array(e);for(let n=0;n>8;return t}function Pn(r,e){if(r.byteLength!==e.byteLength)throw new Error("xor: different length inputs");let t=new Uint8Array(r.byteLength);for(let n=0;nNumber.MAX_SAFE_INTEGER)throw new Lt("Message limit reached");e.seq+=1}async setupBidirectional(e,t){try{this._r.baseNonce=new Uint8Array(await this.export(t,this._nN));let n=await this.export(e,this._nK);this._r.key=this._aead.createAeadKey(n),this._r.seq=0}catch(n){throw this._r.baseNonce=G,n}}};var Zt=class extends tt{async seal(e,t=G){if(this._r.baseNonce.length===0)throw new Ce("Bidirectional encryption is not setup");let n;try{n=await this._r.key.seal(this.computeNonce(this._r),e,t)}catch(i){throw new Ce(i)}return this.incrementSeq(this._r),n}async open(e,t=G){let n;try{n=await this._f.key.open(this.computeNonce(this._f),e,t)}catch(i){throw new je(i)}return this.incrementSeq(this._f),n}};var Vt=class extends tt{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}async seal(e,t=G){let n;try{n=await this._f.key.seal(this.computeNonce(this._f),e,t)}catch(i){throw new Ce(i)}return this.incrementSeq(this._f),n}async open(e,t=G){if(this._r.baseNonce.length===0)throw new je("Bidirectional encryption is not setup");let n;try{n=await this._r.key.open(this.computeNonce(this._r),e,t)}catch(i){throw new je(i)}return this.incrementSeq(this._r),n}};async function In(){if((Sn()||An())&&globalThis.crypto!==void 0)return globalThis.crypto.subtle;try{let{webcrypto:r}=await import("crypto");return r.subtle}catch{throw new de("Web Cryptograph API not supported")}}var Xt=class{constructor(e){Object.defineProperty(this,"_num",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._num=new Uint8Array(e)}val(){return this._num}reset(){this._num.fill(0)}set(e){if(e.length!==this._num.length)throw new Error("Bignum.set: invalid argument");this._num.set(e)}isZero(){for(let e=0;ee[t])return!1}return!1}};var bo=new Uint8Array([48,65,2,1,0,48,19,6,7,42,134,72,206,61,2,1,6,8,42,134,72,206,61,3,1,7,4,39,48,37,2,1,1,4,32]),yo=new Uint8Array([48,78,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,34,4,55,48,53,2,1,1,4,48]),xo=new Uint8Array([48,96,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,35,4,73,48,71,2,1,1,4,66]),rt=class extends re{constructor(e,t){switch(super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_alg",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nDh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_order",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bitmask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pkcs8AlgId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=t,e){case J.DhkemP256HkdfSha256:this._alg={name:"ECDH",namedCurve:"P-256"},this._nPk=65,this._nSk=32,this._nDh=32,this._order=on,this._bitmask=255,this._pkcs8AlgId=bo;break;case J.DhkemP384HkdfSha384:this._alg={name:"ECDH",namedCurve:"P-384"},this._nPk=97,this._nSk=48,this._nDh=48,this._order=sn,this._bitmask=255,this._pkcs8AlgId=yo;break;default:this._alg={name:"ECDH",namedCurve:"P-521"},this._nPk=133,this._nSk=66,this._nDh=66,this._order=an,this._bitmask=1,this._pkcs8AlgId=xo;break}}async serializePublicKey(e){this.checkInit();let t=await this._api.exportKey("raw",e);if(t.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");return t}async deserializePublicKey(e){if(this.checkInit(),e.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");try{return await this._api.importKey("raw",e,this._alg,!0,[])}catch{throw new Error("Invalid public key for the ciphersuite")}}async importKey(e,t,n){if(this.checkInit(),e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async _importRawKey(e,t){if(t&&e.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");if(!t&&e.byteLength!==this._nSk)throw new Error("Invalid private key for the ciphersuite");try{if(t)return await this._api.importKey("raw",e,this._alg,!0,[]);let n=new Uint8Array(e),i=new Uint8Array(this._pkcs8AlgId.length+n.length);return i.set(this._pkcs8AlgId,0),i.set(n,this._pkcs8AlgId.length),await this._api.importKey("pkcs8",i,this._alg,!0,ke)}catch{throw new Error("Invalid key for the ciphersuite")}}async _importJWK(e,t){if(typeof e.crv>"u"||e.crv!==this._alg.namedCurve)throw new Error(`Invalid crv: ${e.crv}`);if(t){if(typeof e.d<"u")throw new Error("Invalid key: `d` should not be set");return await this._api.importKey("jwk",e,this._alg,!0,[])}if(typeof e.d>"u")throw new Error("Invalid key: `d` not found");return await this._api.importKey("jwk",e,this._alg,!0,ke)}async derivePublicKey(e){this.checkInit();let t=await this._api.exportKey("jwk",e);return delete t.d,delete t.key_ops,await this._api.importKey("jwk",t,this._alg,!0,[])}async generateKeyPair(){return this.checkInit(),await this._api.generateKey(this._alg,!0,ke)}async deriveKeyPair(e){this.checkInit();let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=new Xt(this._nSk);for(let a=0;n.isZero()||!n.lessThan(this._order);a++){if(a>255)throw new Error("Faild to derive a key pair");let s=new Uint8Array(await this._hkdf.labeledExpand(t,nn,we(a,1),this._nSk));s[0]=s[0]&this._bitmask,n.set(s)}let i=new Uint8Array(this._pkcs8AlgId.length+n.val().length);i.set(this._pkcs8AlgId,0),i.set(n.val(),this._pkcs8AlgId.length);let o=await this._api.importKey("pkcs8",i,this._alg,!0,ke);return n.reset(),{privateKey:o,publicKey:await this.derivePublicKey(o)}}async dh(e,t){return this.checkInit(),await this._api.deriveBits({name:"ECDH",public:t},e,this._nDh*8)}};var _a=BigInt(0),wo=BigInt(1),mo=BigInt(2),Yt=r=>r instanceof Uint8Array,go=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function pt(r){if(!Yt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;tn+i.length,0)),t=0;return r.forEach(n=>{if(!Yt(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Kn=r=>(mo<typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function ve(r,e,t={}){let n=(i,o,a)=>{let s=_o[o];if(typeof s!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(a&&c===void 0)&&!s(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}var Q=BigInt(0),Y=BigInt(1),Re=BigInt(2),ko=BigInt(3),_r=BigInt(4),Un=BigInt(5),Hn=BigInt(8),vo=BigInt(9),So=BigInt(16);function M(r,e){let t=r%e;return t>=Q?t:e+t}function Er(r,e,t){if(t<=Q||e 0");if(t===Y)return Q;let n=Y;for(;e>Q;)e&Y&&(n=n*r%t),r=r*r%t,e>>=Y;return n}function V(r,e,t){let n=r;for(;e-- >Q;)n*=n,n%=t;return n}function Tn(r,e){if(r===Q||e<=Q)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=M(r,e),n=e,i=Q,o=Y,a=Y,s=Q;for(;t!==Q;){let f=n/t,u=n%t,h=i-a*f,d=o-s*f;n=t,t=u,i=a,o=s,a=h,s=d}if(n!==Y)throw new Error("invert: does not exist");return M(i,e)}function Ao(r){let e=(r-Y)/Re,t,n,i;for(t=r-Y,n=0;t%Re===Q;t/=Re,n++);for(i=Re;i(M(r,e)&Y)===Y,Bo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Cn(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=Bo.reduce((n,i)=>(n[i]="function",n),e);return ve(r,t)}function Io(r,e,t){if(t 0");if(t===Q)return r.ONE;if(t===Y)return e;let n=r.ONE,i=e;for(;t>Q;)t&Y&&(n=r.mul(n,i)),i=r.sqr(i),t>>=Y;return n}function Lo(r,e){let t=new Array(e.length),n=e.reduce((o,a,s)=>r.is0(a)?o:(t[s]=o,r.mul(o,a)),r.ONE),i=r.inv(n);return e.reduceRight((o,a,s)=>r.is0(a)?o:(t[s]=r.mul(o,t[s]),r.mul(o,a)),i),t}function kr(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Jt(r,e,t=!1,n={}){if(r<=Q)throw new Error(`Expected Fp ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=kr(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let a=Po(r),s=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:Kn(i),ZERO:Q,ONE:Y,create:c=>M(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Q<=c&&cc===Q,isOdd:c=>(c&Y)===Y,neg:c=>M(-c,r),eql:(c,f)=>c===f,sqr:c=>M(c*c,r),add:(c,f)=>M(c+f,r),sub:(c,f)=>M(c-f,r),mul:(c,f)=>M(c*f,r),pow:(c,f)=>Io(s,c,f),div:(c,f)=>M(c*Tn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Tn(c,r),sqrt:n.sqrt||(c=>a(s,c)),invertBatch:c=>Lo(s,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>t?Te(c,o):gr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?me(c):mr(c)}});return Object.freeze(s)}function jn(r,e){if(!r.isOdd)throw new Error("Field doesn't have isOdd");let t=r.sqrt(e);return r.isOdd(t)?r.neg(t):t}var Oo=BigInt(0),vr=BigInt(1);function Dn(r,e){let t=(i,o)=>{let a=o.negate();return i?a:o},n=i=>{let o=Math.ceil(e/i)+1,a=2**(i-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(i,o){let a=r.ZERO,s=i;for(;o>Oo;)o&vr&&(a=a.add(s)),s=s.double(),o>>=vr;return a},precomputeWindow(i,o){let{windows:a,windowSize:s}=n(o),c=[],f=i,u=f;for(let h=0;h>=x,_>c&&(_-=d,a+=vr);let H=w,C=w+Math.abs(_)-1,p=g%2!==0,S=_<0;_===0?u=u.add(t(p,o[H])):f=f.add(t(S,o[C]))}return{p:f,f:u}},wNAFCached(i,o,a,s){let c=i._WINDOW_SIZE||1,f=o.get(i);return f||(f=this.precomputeWindow(i,c),c!==1&&o.set(i,s(f))),this.wNAF(c,f,a)}}}function zn(r){return Cn(r.Fp),ve(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kr(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var ye=BigInt(0),fe=BigInt(1),Qt=BigInt(2),Ko=BigInt(8),Uo={zip215:!0};function Ho(r){let e=zn(r);return ve(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Me(r){let e=Ho(r),{Fp:t,n,prehash:i,hash:o,randomBytes:a,nByteLength:s,h:c}=e,f=Qt<{try{return{isValid:!0,value:t.sqrt(b*t.inv(l))}}catch{return{isValid:!1,value:ye}}}),d=e.adjustScalarBytes||(b=>b),x=e.domain||((b,l,y)=>{if(l.length||y)throw new Error("Contexts/pre-hash are not supported");return b}),g=b=>typeof b=="bigint"&&yeg(b)&&g(l)&&bb===ye||w(b,f);function H(b,l){if(w(b,l))return b;throw new Error(`Expected valid scalar < ${l}, got ${typeof b} ${b}`)}function C(b){return b===ye?b:H(b,n)}let p=new Map;function S(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}class m{constructor(l,y,E,A){if(this.ex=l,this.ey=y,this.ez=E,this.et=A,!_(l))throw new Error("x required");if(!_(y))throw new Error("y required");if(!_(E))throw new Error("z required");if(!_(A))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(l){if(l instanceof m)throw new Error("extended point not allowed");let{x:y,y:E}=l||{};if(!_(y)||!_(E))throw new Error("invalid affine point");return new m(y,E,fe,u(y*E))}static normalizeZ(l){let y=t.invertBatch(l.map(E=>E.ez));return l.map((E,A)=>E.toAffine(y[A])).map(m.fromAffine)}_setWindowSize(l){this._WINDOW_SIZE=l,p.delete(this)}assertValidity(){let{a:l,d:y}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:E,ey:A,ez:T,et:j}=this,q=u(E*E),N=u(A*A),R=u(T*T),X=u(R*R),W=u(q*l),xe=u(R*u(W+N)),se=u(X+u(y*u(q*N)));if(xe!==se)throw new Error("bad point: equation left != right (1)");let Ae=u(E*A),ge=u(T*j);if(Ae!==ge)throw new Error("bad point: equation left != right (2)")}equals(l){S(l);let{ex:y,ey:E,ez:A}=this,{ex:T,ey:j,ez:q}=l,N=u(y*q),R=u(T*A),X=u(E*q),W=u(j*A);return N===R&&X===W}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:l}=e,{ex:y,ey:E,ez:A}=this,T=u(y*y),j=u(E*E),q=u(Qt*u(A*A)),N=u(l*T),R=y+E,X=u(u(R*R)-T-j),W=N+j,xe=W-q,se=N-j,Ae=u(X*xe),ge=u(W*se),vt=u(X*se),St=u(xe*W);return new m(Ae,ge,St,vt)}add(l){S(l);let{a:y,d:E}=e,{ex:A,ey:T,ez:j,et:q}=this,{ex:N,ey:R,ez:X,et:W}=l;if(y===BigInt(-1)){let Hr=u((T-A)*(R+N)),Tr=u((T+A)*(R-N)),ir=u(Tr-Hr);if(ir===ye)return this.double();let Nr=u(j*Qt*W),Cr=u(q*Qt*X),jr=Cr+Nr,Dr=Tr+Hr,zr=Cr-Nr,fi=u(jr*ir),li=u(Dr*zr),hi=u(jr*zr),di=u(ir*Dr);return new m(fi,li,di,hi)}let xe=u(A*N),se=u(T*R),Ae=u(q*E*W),ge=u(j*X),vt=u((A+T)*(N+R)-xe-se),St=ge-Ae,Kr=ge+Ae,Ur=u(se-y*xe),si=u(vt*St),ai=u(Kr*Ur),ci=u(vt*Ur),ui=u(St*Kr);return new m(si,ai,ui,ci)}subtract(l){return this.add(l.negate())}wNAF(l){return U.wNAFCached(this,p,l,m.normalizeZ)}multiply(l){let{p:y,f:E}=this.wNAF(H(l,n));return m.normalizeZ([y,E])[0]}multiplyUnsafe(l){let y=C(l);return y===ye?D:this.equals(D)||y===fe?this:this.equals(B)?this.wNAF(y).p:U.unsafeLadder(this,y)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(l){let{ex:y,ey:E,ez:A}=this,T=this.is0();l==null&&(l=T?Ko:t.inv(A));let j=u(y*l),q=u(E*l),N=u(A*l);if(T)return{x:ye,y:fe};if(N!==fe)throw new Error("invZ was invalid");return{x:j,y:q}}clearCofactor(){let{h:l}=e;return l===fe?this:this.multiplyUnsafe(l)}static fromHex(l,y=!1){let{d:E,a:A}=e,T=t.BYTES;l=ce("pointHex",l,T);let j=l.slice(),q=l[T-1];j[T-1]=q&-129;let N=me(j);N===ye||(y?H(N,f):H(N,t.ORDER));let R=u(N*N),X=u(R-fe),W=u(E*R-A),{isValid:xe,value:se}=h(X,W);if(!xe)throw new Error("Point.fromHex: invalid y coordinate");let Ae=(se&fe)===fe,ge=(q&128)!==0;if(!y&&se===ye&&ge)throw new Error("Point.fromHex: x=0 and x_0=1");return ge!==Ae&&(se=u(-se)),m.fromAffine({x:se,y:N})}static fromPrivateKey(l){return O(l).point}toRawBytes(){let{x:l,y}=this.toAffine(),E=Te(y,t.BYTES);return E[E.length-1]|=l&fe?128:0,E}toHex(){return pt(this.toRawBytes())}}m.BASE=new m(e.Gx,e.Gy,fe,u(e.Gx*e.Gy)),m.ZERO=new m(ye,fe,fe,ye);let{BASE:B,ZERO:D}=m,U=Dn(m,s*8);function v(b){return M(b,n)}function K(b){return v(me(b))}function O(b){let l=s;b=ce("private key",b,l);let y=ce("hashed private key",o(b),2*l),E=d(y.slice(0,l)),A=y.slice(l,2*l),T=K(E),j=B.multiply(T),q=j.toRawBytes();return{head:E,prefix:A,scalar:T,point:j,pointBytes:q}}function I(b){return O(b).pointBytes}function P(b=new Uint8Array,...l){let y=Wt(...l);return K(o(x(y,ce("context",b),!!i)))}function F(b,l,y={}){b=ce("message",b),i&&(b=i(b));let{prefix:E,scalar:A,pointBytes:T}=O(l),j=P(y.context,E,b),q=B.multiply(j).toRawBytes(),N=P(y.context,q,T,b),R=v(j+N*A);C(R);let X=Wt(q,Te(R,t.BYTES));return ce("result",X,s*2)}let z=Uo;function $(b,l,y,E=z){let{context:A,zip215:T}=E,j=t.BYTES;b=ce("signature",b,2*j),l=ce("message",l),i&&(l=i(l));let q=me(b.slice(j,2*j)),N,R,X;try{N=m.fromHex(y,T),R=m.fromHex(b.slice(0,j),T),X=B.multiplyUnsafe(q)}catch{return!1}if(!T&&N.isSmallOrder())return!1;let W=P(A,R.toRawBytes(),N.toRawBytes(),l);return R.add(N.multiplyUnsafe(W)).subtract(X).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:e,getPublicKey:I,sign:F,verify:$,ExtendedPoint:m,utils:{getExtendedPublicKey:O,randomPrivateKey:()=>a(t.BYTES),precompute(b=8,l=m.BASE){return l._setWindowSize(b),l.multiply(BigInt(3)),l}}}}var bt=BigInt(0),Sr=BigInt(1);function To(r){return ve(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function er(r){let e=To(r),{P:t}=e,n=p=>M(p,t),i=e.montgomeryBits,o=Math.ceil(i/8),a=e.nByteLength,s=e.adjustScalarBytes||(p=>p),c=e.powPminus2||(p=>Er(p,t-BigInt(2),t));function f(p,S,m){let B=n(p*(S-m));return S=n(S-B),m=n(m+B),[S,m]}function u(p){if(typeof p=="bigint"&&bt<=p&&p=bt;z--){let $=B>>z&Sr;I^=$,P=f(I,U,K),U=P[0],K=P[1],P=f(I,v,O),v=P[0],O=P[1],I=$;let Z=U+v,b=n(Z*Z),l=U-v,y=n(l*l),E=b-y,A=K+O,T=K-O,j=n(T*Z),q=n(A*l),N=j+q,R=j-q;K=n(N*N),O=n(D*n(R*R)),U=n(b*y),v=n(E*(b+n(h*E)))}P=f(I,U,K),U=P[0],K=P[1],P=f(I,v,O),v=P[0],O=P[1];let F=c(v);return n(U*F)}function x(p){return Te(n(p),o)}function g(p){let S=ce("u coordinate",p,o);return a===o&&(S[a-1]&=127),me(S)}function w(p){let S=ce("scalar",p);if(S.length!==o&&S.length!==a)throw new Error(`Expected ${o} or ${a} bytes, got ${S.length}`);return me(s(S))}function _(p,S){let m=g(S),B=w(p),D=d(m,B);if(D===bt)throw new Error("Invalid private or public key received");return x(D)}let H=x(e.Gu);function C(p){return _(p,H)}return{scalarMult:_,scalarMultBase:C,getSharedSecret:(p,S)=>_(p,S),getPublicKey:p=>C(p),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:H}}var yt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Rn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Za=BigInt(0),Co=BigInt(1),Ar=BigInt(2),jo=BigInt(5),Mn=BigInt(10),Do=BigInt(20),zo=BigInt(40),qn=BigInt(80);function Gn(r){let e=yt,n=r*r%e*r%e,i=V(n,Ar,e)*n%e,o=V(i,Co,e)*r%e,a=V(o,jo,e)*o%e,s=V(a,Mn,e)*a%e,c=V(s,Do,e)*s%e,f=V(c,zo,e)*c%e,u=V(f,qn,e)*f%e,h=V(u,qn,e)*f%e,d=V(h,Mn,e)*a%e;return{pow_p_5_8:V(d,Ar,e)*r%e,b2:n}}function Fn(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ro(r,e){let t=yt,n=M(e*e*e,t),i=M(n*n*e,t),o=Gn(r*i).pow_p_5_8,a=M(r*n*o,t),s=M(e*a*a,t),c=a,f=M(a*Rn,t),u=s===r,h=s===M(-r,t),d=s===M(-r*Rn,t);return u&&(a=c),(h||d)&&(a=f),Nn(a,t)&&(a=M(-a,t)),{isValid:u||h,value:a}}var Se=Jt(yt,void 0,!0),Pr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Se,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ft,randomBytes:We,adjustScalarBytes:Fn,uvRatio:Ro},$n=Me(Pr);function Zn(r,e,t){if(e.length>255)throw new Error("Context is too big");return qt(ct("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var Va=Me({...Pr,domain:Zn}),Xa=Me({...Pr,domain:Zn,prehash:ft}),Br=(()=>er({P:yt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=yt,{pow_p_5_8:t,b2:n}=Gn(r);return M(V(t,BigInt(3),e)*n,e)},adjustScalarBytes:Fn,randomBytes:We}))();var Mo=(Se.ORDER+BigInt(3))/BigInt(8),Ya=Se.pow(Ar,Mo),Wa=Se.sqrt(Se.neg(Se.ONE)),Ja=(Se.ORDER-BigInt(5))/BigInt(8),Qa=BigInt(486662);var ec=jn(Se,Se.neg(BigInt(486664)));var tc=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),rc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),nc=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ic=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var oc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ee=class{constructor(e,t,n){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extractable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"usages",{enumerable:!0,configurable:!0,writable:!0,value:ke}),this.key=t,this.type=n,this.algorithm={name:e},n==="public"&&(this.usages=[])}};var qe="X25519",tr=class extends re{constructor(e){super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=32,this._nSk=32}async serializePublicKey(e){return await this._serializePublicKey(e)}async deserializePublicKey(e){return await this._deserializePublicKey(e)}async importKey(e,t,n){if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async derivePublicKey(e){return await this._derivePublicKey(e)}async generateKeyPair(){let e=$n.utils.randomPrivateKey(),t=new ee(qe,e,"private");return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Kt,G,this._nSk),i=new ee(qe,new Uint8Array(n),"private");return{privateKey:i,publicKey:await this.derivePublicKey(i)}}async dh(e,t){return await this._dh(e,t)}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_deserializePublicKey(e){return new Promise((t,n)=>{e.byteLength!==this._nPk?n(new Error("Invalid public key for the ciphersuite")):t(new ee(qe,new Uint8Array(e),"public"))})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid public key for the ciphersuite")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid private key for the ciphersuite")),n(new ee(qe,new Uint8Array(e),t?"public":"private"))})}_importJWK(e,t){return new Promise((n,i)=>{(typeof e.kty>"u"||e.kty!=="OKP")&&i(new Error(`Invalid kty: ${e.kty}`)),(typeof e.crv>"u"||e.crv!=="X25519")&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x>"u"&&i(new Error("Invalid key: `x` not found")),n(new ee(qe,et(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(qe,et(e.d),"private")))})}_derivePublicKey(e){return new Promise(t=>{let n=Br.getPublicKey(e.key);t(new ee(qe,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Br.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var[Yn,Wn,Jn]=[[],[],[]],qo=BigInt(0),xt=BigInt(1),Go=BigInt(2),Fo=BigInt(7),$o=BigInt(256),Zo=BigInt(113);for(let r=0,e=xt,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],Yn.push(2*(5*n+t)),Wn.push((r+1)*(r+2)/2%64);let i=qo;for(let o=0;o<7;o++)e=(e<>Fo)*Zo)%$o,e&Go&&(i^=xt<<(xt<t>32?L.rotlBH(r,e,t):L.rotlSH(r,e,t),Xn=(r,e,t)=>t>32?L.rotlBL(r,e,t):L.rotlSL(r,e,t);function Yo(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let a=0;a<10;a++)t[a]=r[a]^r[a+10]^r[a+20]^r[a+30]^r[a+40];for(let a=0;a<10;a+=2){let s=(a+8)%10,c=(a+2)%10,f=t[c],u=t[c+1],h=Vn(f,u,1)^t[s],d=Xn(f,u,1)^t[s+1];for(let x=0;x<50;x+=10)r[a+x]^=h,r[a+x+1]^=d}let i=r[2],o=r[3];for(let a=0;a<24;a++){let s=Wn[a],c=Vn(i,o,s),f=Xn(i,o,s),u=Yn[a];i=r[u],o=r[u+1],r[u]=c,r[u+1]=f}for(let a=0;a<50;a+=10){for(let s=0;s<10;s++)t[s]=r[a+s];for(let s=0;s<10;s++)r[a+s]^=~t[(s+2)%10]&t[(s+4)%10]}r[0]^=Vo[n],r[1]^=Xo[n]}t.fill(0)}var rr=class r extends Pe{constructor(e,t,n,i=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=i,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,ie.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=mn(this.state)}keccak(){Yo(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){ie.exists(this);let{blockLen:t,state:n}=this;e=Be(e);let i=e.length;for(let o=0;o=n&&this.keccak();let a=Math.min(n-this.posOut,o-i);e.set(t.subarray(this.posOut,this.posOut+a),i),this.posOut+=a,i+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ie.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ie.output(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:i,rounds:o,enableXOF:a}=this;return e||(e=new r(t,n,i,a,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=i,e.enableXOF=a,e.destroyed=this.destroyed,e}},Ne=(r,e,t)=>ue(()=>new rr(e,r,t)),yc=Ne(6,144,224/8),xc=Ne(6,136,256/8),wc=Ne(6,104,384/8),mc=Ne(6,72,512/8),gc=Ne(1,144,224/8),_c=Ne(1,136,256/8),Ec=Ne(1,104,384/8),kc=Ne(1,72,512/8),Qn=(r,e,t)=>gn((n={})=>new rr(e,r,n.dkLen===void 0?t:n.dkLen,!0)),vc=Qn(31,168,128/8),Ir=Qn(31,136,256/8);var Wo=ue(()=>Ir.create({dkLen:114})),Jo=ue(()=>Ir.create({dkLen:64})),wt=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439");function ei(r){let e=wt,t=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(11),a=BigInt(22),s=BigInt(44),c=BigInt(88),f=BigInt(223),u=r*r*r%e,h=u*u*r%e,d=V(h,i,e)*h%e,x=V(d,i,e)*h%e,g=V(x,n,e)*u%e,w=V(g,o,e)*g%e,_=V(w,a,e)*w%e,H=V(_,s,e)*_%e,C=V(H,c,e)*H%e,p=V(C,s,e)*_%e,S=V(p,n,e)*u%e,m=V(S,t,e)*r%e;return V(m,f,e)*S%e}function ti(r){return r[0]&=252,r[55]|=128,r[56]=0,r}var ri=Jt(wt,456,!0),Kc=BigInt(4),ni={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:ri,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:Wo,randomBytes:We,adjustScalarBytes:ti,domain:(r,e,t)=>{if(e.length>255)throw new Error(`Context is too big: ${e.length}`);return qt(ct("SigEd448"),new Uint8Array([t?1:0,e.length]),e,r)},uvRatio:(r,e)=>{let t=wt,n=M(r*r*e,t),i=M(n*r,t),o=M(i*n*e,t),a=ei(o),s=M(i*a,t),c=M(s*s,t);return{isValid:M(c*e,t)===r,value:s}}},ii=Me(ni),Uc=Me({...ni,prehash:Jo}),Lr=(()=>er({a:BigInt(156326),montgomeryBits:448,nByteLength:57,P:wt,Gu:BigInt(5),powPminus2:r=>{let e=wt,t=ei(r),n=V(t,BigInt(2),e);return M(n*r,e)},adjustScalarBytes:ti,randomBytes:We}))();var Hc=(ri.ORDER-BigInt(3))/BigInt(4),Tc=BigInt(156326);var Ge="X448",nr=class extends re{constructor(e){super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=56,this._nSk=56}async serializePublicKey(e){return await this._serializePublicKey(e)}async deserializePublicKey(e){return await this._deserializePublicKey(e)}async importKey(e,t,n){if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}async derivePublicKey(e){return await this._derivePublicKey(e)}async generateKeyPair(){let e=ii.utils.randomPrivateKey(),t=new ee(Ge,e,"private");return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(G,Ze,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Kt,G,this._nSk),i=new ee(Ge,new Uint8Array(n),"private");return{privateKey:i,publicKey:await this.derivePublicKey(i)}}async dh(e,t){return await this._dh(e,t)}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_deserializePublicKey(e){return new Promise((t,n)=>{e.byteLength!==this._nPk?n(new Error("Invalid public key for the ciphersuite")):t(new ee(Ge,new Uint8Array(e),"public"))})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid public key for the ciphersuite")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid private key for the ciphersuite")),n(new ee(Ge,new Uint8Array(e),t?"public":"private"))})}_importJWK(e,t){return new Promise((n,i)=>{e.kty!=="OKP"&&i(new Error(`Invalid kty: ${e.kty}`)),e.crv!=="X448"&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x!="string"&&i(new Error("Invalid key: `x` not found")),n(new ee(Ge,et(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ge,et(e.d),"private")))})}_derivePublicKey(e){return new Promise(t=>{let n=Lr.getPublicKey(e.key);t(new ee(Ge,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Lr.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Fe=class extends re{constructor(e,t){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prim",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._prim=e,this._kdf=t}init(e){super.init(e);let t=new Uint8Array(Zr);t.set(we(this.id,2),3),this._prim.init(e),this._kdf.init(e,t),super.init(e)}async generateKeyPair(){try{return await this._prim.generateKeyPair()}catch(e){throw new de(e)}}async deriveKeyPair(e){try{return await this._prim.deriveKeyPair(e)}catch(t){throw new Ot(t)}}async serializePublicKey(e){try{return await this._prim.serializePublicKey(e)}catch(t){throw new At(t)}}async deserializePublicKey(e){try{return await this._prim.deserializePublicKey(e)}catch(t){throw new $e(t)}}async importKey(e,t,n){try{return await this._prim.importKey(e,t,n)}catch(i){throw new $e(i)}}async encap(e){try{let t=e.nonEphemeralKeyPair===void 0?await this.generateKeyPair():e.nonEphemeralKeyPair,n=await this._prim.serializePublicKey(t.publicKey),i=await this._prim.serializePublicKey(e.recipientPublicKey),o;if(e.senderKey===void 0)o=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey));else{let c=ht(e.senderKey)?e.senderKey.privateKey:e.senderKey,f=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey)),u=new Uint8Array(await this._prim.dh(c,e.recipientPublicKey));o=dt(f,u)}let a;if(e.senderKey===void 0)a=dt(new Uint8Array(n),new Uint8Array(i));else{let c=ht(e.senderKey)?e.senderKey.publicKey:await this._prim.derivePublicKey(e.senderKey),f=await this._prim.serializePublicKey(c);a=Bn(new Uint8Array(n),new Uint8Array(i),new Uint8Array(f))}let s=await this.generateSharedSecret(o,a);return{enc:n,sharedSecret:s}}catch(t){throw new Pt(t)}}async decap(e){let t;try{t=await this._prim.deserializePublicKey(e.enc)}catch(n){throw new $e(n)}try{let n=ht(e.recipientKey)?e.recipientKey.privateKey:e.recipientKey,i=ht(e.recipientKey)?e.recipientKey.publicKey:await this._prim.derivePublicKey(e.recipientKey),o=await this._prim.serializePublicKey(i),a;if(e.senderPublicKey===void 0)a=new Uint8Array(await this._prim.dh(n,t));else{let c=new Uint8Array(await this._prim.dh(n,t)),f=new Uint8Array(await this._prim.dh(n,e.senderPublicKey));a=dt(c,f)}let s;if(e.senderPublicKey===void 0)s=dt(new Uint8Array(e.enc),new Uint8Array(o));else{let c=await this._prim.serializePublicKey(e.senderPublicKey);s=new Uint8Array(e.enc.byteLength+o.byteLength+c.byteLength),s.set(new Uint8Array(e.enc),0),s.set(new Uint8Array(o),e.enc.byteLength),s.set(new Uint8Array(c),e.enc.byteLength+o.byteLength)}return await this.generateSharedSecret(a,s)}catch(n){throw new Bt(n)}}async generateSharedSecret(e,t){let n=this._kdf.buildLabeledIkm(Vr,e),i=this._kdf.buildLabeledInfo(Jr,t,this.secretSize);return await this._kdf.extractAndExpand(G,n,i,this.secretSize)}},mt=class extends Fe{constructor(){let e=new Ue,t=new rt(J.DhkemP256HkdfSha256,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}},gt=class extends Fe{constructor(){let e=new ze,t=new rt(J.DhkemP384HkdfSha384,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP384HkdfSha384}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:48})}},_t=class extends Fe{constructor(){let e=new He,t=new rt(J.DhkemP521HkdfSha512,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemP521HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:64})}},Et=class extends Fe{constructor(){let e=new Ue,t=new tr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemX25519HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}},kt=class extends Fe{constructor(){let e=new He,t=new nr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:J.DhkemX448HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56})}};var Or=class{constructor(e){if(Object.defineProperty(this,"kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),typeof e.kem!="number")this._kem=e.kem;else switch(e.kem){case J.DhkemP256HkdfSha256:this._kem=new mt;break;case J.DhkemP384HkdfSha384:this._kem=new gt;break;case J.DhkemP521HkdfSha512:this._kem=new _t;break;case J.DhkemX25519HkdfSha256:this._kem=new Et;break;case J.DhkemX448HkdfSha512:this._kem=new kt;break;default:throw new he(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(this.kem=this._kem.id,typeof e.kdf!="number")this._kdf=e.kdf;else switch(e.kdf){case Ee.HkdfSha256:this._kdf=new Ue;break;case Ee.HkdfSha384:this._kdf=new ze;break;default:this._kdf=new He;break}if(this.kdf=this._kdf.id,typeof e.aead!="number")this._aead=e.aead;else switch(e.aead){case te.Aes128Gcm:this._aead=new nt;break;case te.Aes256Gcm:this._aead=new it;break;case te.Chacha20Poly1305:this._aead=new at;break;default:this._aead=new jt;break}this.aead=this._aead.id,this._suiteId=new Uint8Array($r),this._suiteId.set(we(this.kem,2),4),this._suiteId.set(we(this.kdf,2),6),this._suiteId.set(we(this.aead,2),8)}get kemSecretSize(){return this._kem.secretSize}get kemEncSize(){return this._kem.encSize}get kemPublicKeySize(){return this._kem.publicKeySize}get kemPrivateKeySize(){return this._kem.privateKeySize}get aeadKeySize(){return this._aead.keySize}get aeadNonceSize(){return this._aead.nonceSize}get aeadTagSize(){return this._aead.tagSize}async kemContext(){return await this.setup(),this._kem}async kdfContext(){return await this.setup(),this._kdf}async createAeadKey(e){return await this.setup(),this._aead.createAeadKey(e)}async generateKeyPair(){return await this.setup(),await this._kem.generateKeyPair()}async deriveKeyPair(e){if(e.byteLength>128)throw new he("Too long ikm");return await this.setup(),await this._kem.deriveKeyPair(e)}async importKey(e,t,n=!0){return await this.setup(),await this._kem.importKey(e,t,n)}async createSenderContext(e){this.validateInputLength(e),await this.setup();let t=await this._kem.encap(e),n;return e.psk!==void 0?n=e.senderKey!==void 0?_e.AuthPsk:_e.Psk:n=e.senderKey!==void 0?_e.Auth:_e.Base,await this.keyScheduleS(n,t.sharedSecret,t.enc,e)}async createRecipientContext(e){this.validateInputLength(e),await this.setup();let t=await this._kem.decap(e),n;return e.psk!==void 0?n=e.senderPublicKey!==void 0?_e.AuthPsk:_e.Psk:n=e.senderPublicKey!==void 0?_e.Auth:_e.Base,await this.keyScheduleR(n,t,e)}async seal(e,t,n=G){let i=await this.createSenderContext(e);return{ct:await i.seal(t,n),enc:i.enc}}async open(e,t,n=G){return await(await this.createRecipientContext(e)).open(t,n)}async setup(){if(this._api!==void 0)return;let e=await In();this._kem.init(e),this._kdf.init(e,this._suiteId),this._aead.init(e),this._api=e}async keySchedule(e,t,n){let i=n.psk===void 0?G:new Uint8Array(n.psk.id),o=await this._kdf.labeledExtract(G,Yr,i),a=n.info===void 0?G:new Uint8Array(n.info),s=await this._kdf.labeledExtract(G,Xr,a),c=new Uint8Array(1+o.byteLength+s.byteLength);c.set(new Uint8Array([e]),0),c.set(new Uint8Array(o),1),c.set(new Uint8Array(s),1+o.byteLength);let f=n.psk===void 0?G:new Uint8Array(n.psk.key),u=this._kdf.buildLabeledIkm(Wr,f),h=this._kdf.buildLabeledInfo(tn,c,this._kdf.hashSize),d=await this._kdf.extractAndExpand(t,u,h,this._kdf.hashSize);if(this._aead.id===te.ExportOnly)return{aead:this._aead,exporterSecret:d};let x=this._kdf.buildLabeledInfo(Qr,c,this._aead.keySize),g=await this._kdf.extractAndExpand(t,u,x,this._aead.keySize),w=this._kdf.buildLabeledInfo(en,c,this._aead.nonceSize),_=await this._kdf.extractAndExpand(t,u,w,this._aead.nonceSize);return{aead:this._aead,exporterSecret:d,key:g,baseNonce:new Uint8Array(_),seq:0}}async keyScheduleS(e,t,n,i){let o=await this.keySchedule(e,t,i);return o.key===void 0?new Ht(this._api,this._kdf,o.exporterSecret,n):new Vt(this._api,this._kdf,o,n)}async keyScheduleR(e,t,n){let i=await this.keySchedule(e,t,n);return i.key===void 0?new Ut(this._api,this._kdf,i.exporterSecret):new Zt(this._api,this._kdf,i)}validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>128)throw new he("Too long info");if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new he(`PSK must have at least ${32} bytes`);if(e.psk.key.byteLength>128)throw new he("Too long psk.key");if(e.psk.id.byteLength>128)throw new he("Too long psk.id")}}};export{Gr as Aead,te as AeadId,nt as Aes128Gcm,it as Aes256Gcm,at as Chacha20Poly1305,Or as CipherSuite,Bt as DecapError,Ot as DeriveKeyPairError,$e as DeserializeError,mt as DhkemP256HkdfSha256,gt as DhkemP384HkdfSha384,_t as DhkemP521HkdfSha512,Et as DhkemX25519HkdfSha256,kt as DhkemX448HkdfSha512,Pt as EncapError,It as ExportError,Ue as HkdfSha256,ze as HkdfSha384,He as HkdfSha512,he as InvalidParamError,qr as Kdf,Ee as KdfId,Mr as Kem,J as KemId,Lt as MessageLimitReachedError,de as NotSupportedError,je as OpenError,Ce as SealError,At as SerializeError,Rr as ValidationError}; -/*! Bundled license information: - -@noble/ciphers/esm/utils.js: - (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *) - -@noble/hashes/esm/utils.js: - (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/utils.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/modular.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/curve.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/edwards.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/abstract/montgomery.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed25519.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) - -@noble/curves/esm/ed448.js: - (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) -*/