diff --git a/chacha20poly1305/docs/classes/Chacha20Poly1305.html b/chacha20poly1305/docs/classes/Chacha20Poly1305.html index 4e1031c24..020f5b436 100644 --- a/chacha20poly1305/docs/classes/Chacha20Poly1305.html +++ b/chacha20poly1305/docs/classes/Chacha20Poly1305.html @@ -37,7 +37,7 @@
Protected_api: SubtleCrypto = undefined
Readonly
idReadonly
keyReadonly
nonceReadonly
tagProtectedReturns void
Inherited from Algorithm.init
Readonly
Readonly
keyReadonly
Readonly
nonceReadonly
Readonly
tagReadonly
Readonly
Readonly
idReadonly
Readonly
Readonly
idReadonly
Readonly
privateReadonly
Readonly
publicReadonly
Readonly
secretReadonly
Optional
infoOptional
Optional
pskOptional
Optional
senderOptional
Optional
Optional
nonOptional
Optional
pskOptional
Optional
senderOptional
Readonly
Readonly ExportReadonly
Readonly HkdfReadonly
Readonly DhkemProtected_api: SubtleCrypto = undefined
Protected
_kdfProtected
_primReadonly
encReadonly
idReadonly
privateReadonly
publicReadonly
secretProtectedReturns void
Protected_api: SubtleCrypto = undefined
Protected
_kdfProtected
_primReadonly
encReadonly
idReadonly
privateReadonly
publicReadonly
secretProtectedReturns void
I(p)&&I(l)&&p I(p)&&I(l)&&pHierarchy
+
@@ -76,7 +76,7 @@
constructorReturns DhkemX448HkdfSha512
Properties
Protected_api: SubtleCrypto = undefined
Protected
_kdfProtected
_primReadonly
encReadonly
idReadonly
privateReadonly
publicReadonly
secretProtectedReturns void
Private
_aeadPrivate
_apiPrivate
_kdfPrivate
_kemPrivate
_suitePrivate
_keyPrivate
_keyPrivate
_setupPrivate
Private
_validateUse DeserializeError
EncapError, MessageLimitReachedError, SealError, ValidationError
Readonly
Readonly
keyReadonly
Readonly
nonceReadonly
Readonly
tagReadonly
Readonly
Readonly
idReadonly
Readonly
Readonly
idReadonly
Readonly
privateReadonly
Readonly
publicReadonly
Readonly
secretReadonly
Initializes the instance by setting a SubtleCrypto API.
-Basically, you don't need to call this function directly. -This function is called byCipherSuite internally.
-A SubtleCrypto API.
-Optional
infoOptional
Optional
pskOptional
Optional
senderOptional
Optional
Optional
nonOptional
Optional
pskOptional
Optional
senderOptional
Use AeadId instead.
Use KdfId instead.
Use KdfId instead.
Readonly
AeadId instead.
Readonly
Readonly ExportReadonly
KdfId instead.
Readonly
Readonly HkdfReadonly
KdfId instead.
Readonly
Readonly Dhkem0");if(t===W)return Q;let n=W;for(;e>Q;)e&W&&(n=n*r%t),r=r*r%t,e>>=W;return n}function V(r,e,t){let n=r;for(;e-- >Q;)n*=n,n%=t;return n}function vn(r,e){if(r===Q||e<=Q)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,i=Q,o=W,s=W,a=Q;for(;t!==Q;){let u=n/t,f=n%t,h=i-s*u,d=o-a*u;n=t,t=f,i=s,o=a,s=h,a=d}if(n!==W)throw new Error("invert: does not exist");return j(i,e)}function _o(r){let e=(r-W)/Fe,t,n,i;for(t=r-W,n=0;t%Fe===Q;t/=Fe,n++);for(i=Fe;i(j(r,e)&W)===W,ko=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function An(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=ko.reduce((n,i)=>(n[i]="function",n),e);return Ae(r,t)}function vo(r,e,t){if(t 0");if(t===Q)return r.ONE;if(t===W)return e;let n=r.ONE,i=e;for(;t>Q;)t&W&&(n=r.mul(n,i)),i=r.sqr(i),t>>=W;return n}function So(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Ar(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Xt(r,e,t=!1,n={}){if(r<=Q)throw new Error(`Expected Fp ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Ar(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Eo(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:_n(i),ZERO:Q,ONE:W,create:c=>j(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&W)===W,neg:c=>j(-c,r),eql:(c,u)=>c===u,sqr:c=>j(c*c,r),add:(c,u)=>j(c+u,r),sub:(c,u)=>j(c-u,r),mul:(c,u)=>j(c*u,r),pow:(c,u)=>vo(a,c,u),div:(c,u)=>j(c*vn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>vn(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>So(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>t?ze(c,o):kr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?_e(c):Er(c)}});return Object.freeze(a)}function Pn(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 Ao=BigInt(0),Pr=BigInt(1);function In(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>Ao;)o&Pr&&(s=s.add(a)),a=a.double(),o>>=Pr;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,f=u;for(let h=0;h >=m,v>c&&(v-=d,s+=Pr);let $=_,X=_+Math.abs(v)-1,y=k%2!==0,L=v<0;v===0?f=f.add(t(y,o[$])):u=u.add(t(L,o[X]))}return{p:u,f}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function Bn(r){return An(r.Fp),Ae(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ar(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var we=BigInt(0),de=BigInt(1),Yt=BigInt(2),Po=BigInt(8),Io={zip215:!0};function Bo(r){let e=Bn(r);return Ae(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function $e(r){let e=Bo(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Yt<{try{return{isValid:!0,value:t.sqrt(p*t.inv(l))}}catch{return{isValid:!1,value:we}}}),d=e.adjustScalarBytes||(p=>p),m=e.domain||((p,l,b)=>{if(l.length||b)throw new Error("Contexts/pre-hash are not supported");return p}),k=p=>typeof p=="bigint"&&we k(p)&&k(l)&&p
p===we||_(p,u);function $(p,l){if(_(p,l))return p;throw new Error(`Expected valid scalar < ${l}, got ${typeof p} ${p}`)}function X(p){return p===we?p:$(p,n)}let y=new Map;function L(p){if(!(p instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(l,b,x,g){if(this.ex=l,this.ey=b,this.ez=x,this.et=g,!v(l))throw new Error("x required");if(!v(b))throw new Error("y required");if(!v(x))throw new Error("z required");if(!v(g))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(l){if(l instanceof E)throw new Error("extended point not allowed");let{x:b,y:x}=l||{};if(!v(b)||!v(x))throw new Error("invalid affine point");return new E(b,x,de,f(b*x))}static normalizeZ(l){let b=t.invertBatch(l.map(x=>x.ez));return l.map((x,g)=>x.toAffine(b[g])).map(E.fromAffine)}_setWindowSize(l){this._WINDOW_SIZE=l,y.delete(this)}assertValidity(){let{a:l,d:b}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:x,ey:g,ez:U,et:T}=this,z=f(x*x),O=f(g*g),D=f(U*U),Y=f(D*D),J=f(z*l),me=f(D*f(J+O)),fe=f(Y+f(b*f(z*O)));if(me!==fe)throw new Error("bad point: equation left != right (1)");let Ie=f(x*g),Ee=f(U*T);if(Ie!==Ee)throw new Error("bad point: equation left != right (2)")}equals(l){L(l);let{ex:b,ey:x,ez:g}=this,{ex:U,ey:T,ez:z}=l,O=f(b*z),D=f(U*g),Y=f(x*z),J=f(T*g);return O===D&&Y===J}is0(){return this.equals(E.ZERO)}negate(){return new E(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:l}=e,{ex:b,ey:x,ez:g}=this,U=f(b*b),T=f(x*x),z=f(Yt*f(g*g)),O=f(l*U),D=b+x,Y=f(f(D*D)-U-T),J=O+T,me=J-z,fe=O-T,Ie=f(Y*me),Ee=f(J*fe),mt=f(Y*fe),gt=f(me*J);return new E(Ie,Ee,gt,mt)}add(l){L(l);let{a:b,d:x}=e,{ex:g,ey:U,ez:T,et:z}=this,{ex:O,ey:D,ez:Y,et:J}=l;if(b===BigInt(-1)){let Nr=f((U-g)*(D+O)),Dr=f((U+g)*(D-O)),ur=f(Dr-Nr);if(ur===we)return this.double();let jr=f(T*Yt*J),zr=f(z*Yt*Y),Rr=zr+jr,Mr=Dr+Nr,qr=zr-jr,Qn=f(Rr*ur),ei=f(Mr*qr),ti=f(Rr*qr),ri=f(ur*Mr);return new E(Qn,ei,ri,ti)}let me=f(g*O),fe=f(U*D),Ie=f(z*x*J),Ee=f(T*Y),mt=f((g+U)*(O+D)-me-fe),gt=Ee-Ie,Tr=Ee+Ie,Cr=f(fe-b*me),Xn=f(mt*gt),Yn=f(Tr*Cr),Wn=f(mt*Cr),Jn=f(gt*Tr);return new E(Xn,Yn,Jn,Wn)}subtract(l){return this.add(l.negate())}wNAF(l){return K.wNAFCached(this,y,l,E.normalizeZ)}multiply(l){let{p:b,f:x}=this.wNAF($(l,n));return E.normalizeZ([b,x])[0]}multiplyUnsafe(l){let b=X(l);return b===we?M:this.equals(M)||b===de?this:this.equals(H)?this.wNAF(b).p:K.unsafeLadder(this,b)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return K.unsafeLadder(this,n).is0()}toAffine(l){let{ex:b,ey:x,ez:g}=this,U=this.is0();l==null&&(l=U?Po:t.inv(g));let T=f(b*l),z=f(x*l),O=f(g*l);if(U)return{x:we,y:de};if(O!==de)throw new Error("invZ was invalid");return{x:T,y:z}}clearCofactor(){let{h:l}=e;return l===de?this:this.multiplyUnsafe(l)}static fromHex(l,b=!1){let{d:x,a:g}=e,U=t.BYTES;l=le("pointHex",l,U);let T=l.slice(),z=l[U-1];T[U-1]=z&-129;let O=_e(T);O===we||(b?$(O,u):$(O,t.ORDER));let D=f(O*O),Y=f(D-de),J=f(x*D-g),{isValid:me,value:fe}=h(Y,J);if(!me)throw new Error("Point.fromHex: invalid y coordinate");let Ie=(fe&de)===de,Ee=(z&128)!==0;if(!b&&fe===we&&Ee)throw new Error("Point.fromHex: x=0 and x_0=1");return Ee!==Ie&&(fe=f(-fe)),E.fromAffine({x:fe,y:O})}static fromPrivateKey(l){return I(l).point}toRawBytes(){let{x:l,y:b}=this.toAffine(),x=ze(b,t.BYTES);return x[x.length-1]|=l&de?128:0,x}toHex(){return dt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,de,f(e.Gx*e.Gy)),E.ZERO=new E(we,de,de,we);let{BASE:H,ZERO:M}=E,K=In(E,a*8);function w(p){return j(p,n)}function B(p){return w(_e(p))}function I(p){let l=a;p=le("private key",p,l);let b=le("hashed private key",o(p),2*l),x=d(b.slice(0,l)),g=b.slice(l,2*l),U=B(x),T=H.multiply(U),z=T.toRawBytes();return{head:x,prefix:g,scalar:U,point:T,pointBytes:z}}function A(p){return I(p).pointBytes}function S(p=new Uint8Array,...l){let b=Vt(...l);return B(o(m(b,le("context",p),!!i)))}function q(p,l,b={}){p=le("message",p),i&&(p=i(p));let{prefix:x,scalar:g,pointBytes:U}=I(l),T=S(b.context,x,p),z=H.multiply(T).toRawBytes(),O=S(b.context,z,U,p),D=w(T+O*g);X(D);let Y=Vt(z,ze(D,t.BYTES));return le("result",Y,a*2)}let N=Io;function G(p,l,b,x=N){let{context:g,zip215:U}=x,T=t.BYTES;p=le("signature",p,2*T),l=le("message",l),i&&(l=i(l));let z=_e(p.slice(T,2*T)),O,D,Y;try{O=E.fromHex(b,U),D=E.fromHex(p.slice(0,T),U),Y=H.multiplyUnsafe(z)}catch{return!1}if(!U&&O.isSmallOrder())return!1;let J=S(g,D.toRawBytes(),O.toRawBytes(),l);return D.add(O.multiplyUnsafe(J)).subtract(Y).clearCofactor().equals(E.ZERO)}return H._setWindowSize(8),{CURVE:e,getPublicKey:A,sign:q,verify:G,ExtendedPoint:E,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>s(t.BYTES),precompute(p=8,l=E.BASE){return l._setWindowSize(p),l.multiply(BigInt(3)),l}}}}var pt=BigInt(0),Ir=BigInt(1);function Lo(r){return Ae(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Wt(r){let e=Lo(r),{P:t}=e,n=y=>j(y,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,a=e.adjustScalarBytes||(y=>y),c=e.powPminus2||(y=>Sr(y,t-BigInt(2),t));function u(y,L,E){let H=n(y*(L-E));return L=n(L-H),E=n(E+H),[L,E]}function f(y){if(typeof y=="bigint"&&pt<=y&&y =pt;N--){let G=H>>N&Ir;A^=G,S=u(A,K,B),K=S[0],B=S[1],S=u(A,w,I),w=S[0],I=S[1],A=G;let F=K+w,p=n(F*F),l=K-w,b=n(l*l),x=p-b,g=B+I,U=B-I,T=n(U*F),z=n(g*l),O=T+z,D=T-z;B=n(O*O),I=n(M*n(D*D)),K=n(p*b),w=n(x*(p+n(h*x)))}S=u(A,K,B),K=S[0],B=S[1],S=u(A,w,I),w=S[0],I=S[1];let q=c(w);return n(K*q)}function m(y){return ze(n(y),o)}function k(y){let L=le("u coordinate",y,o);return s===o&&(L[s-1]&=127),_e(L)}function _(y){let L=le("scalar",y);if(L.length!==o&&L.length!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${L.length}`);return _e(a(L))}function v(y,L){let E=k(L),H=_(y),M=d(E,H);if(M===pt)throw new Error("Invalid private or public key received");return m(M)}let $=m(e.Gu);function X(y){return v(y,$)}return{scalarMult:v,scalarMultBase:X,getSharedSecret:(y,L)=>v(y,L),getPublicKey:y=>X(y),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:$}}var bt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ln=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),wc=BigInt(0),Uo=BigInt(1),Br=BigInt(2),Oo=BigInt(5),Kn=BigInt(10),Ho=BigInt(20),To=BigInt(40),Un=BigInt(80);function On(r){let e=bt,n=r*r%e*r%e,i=V(n,Br,e)*n%e,o=V(i,Uo,e)*r%e,s=V(o,Oo,e)*o%e,a=V(s,Kn,e)*s%e,c=V(a,Ho,e)*a%e,u=V(c,To,e)*c%e,f=V(u,Un,e)*u%e,h=V(f,Un,e)*u%e,d=V(h,Kn,e)*s%e;return{pow_p_5_8:V(d,Br,e)*r%e,b2:n}}function Hn(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Co(r,e){let t=bt,n=j(e*e*e,t),i=j(n*n*e,t),o=On(r*i).pow_p_5_8,s=j(r*n*o,t),a=j(e*s*s,t),c=s,u=j(s*Ln,t),f=a===r,h=a===j(-r,t),d=a===j(-r*Ln,t);return f&&(s=c),(h||d)&&(s=u),Sn(s,t)&&(s=j(-s,t)),{isValid:f||h,value:s}}var Pe=Xt(bt,void 0,!0),Lr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Pe,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ut,randomBytes:Qe,adjustScalarBytes:Hn,uvRatio:Co},Tn=$e(Lr);function Cn(r,e,t){if(e.length>255)throw new Error("Context is too big");return Nt(ct("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var mc=$e({...Lr,domain:Cn}),gc=$e({...Lr,domain:Cn,prehash:ut}),Kr=(()=>Wt({P:bt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=bt,{pow_p_5_8:t,b2:n}=On(r);return j(V(t,BigInt(3),e)*n,e)},adjustScalarBytes:Hn,randomBytes:Qe}))();var No=(Pe.ORDER+BigInt(3))/BigInt(8),_c=Pe.pow(Br,No),Ec=Pe.sqrt(Pe.neg(Pe.ONE)),kc=(Pe.ORDER-BigInt(5))/BigInt(8),vc=BigInt(486662);var Sc=Pn(Pe,Pe.neg(BigInt(486664)));var Ac=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Pc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ic=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Bc=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Lc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ee=class{constructor(e,t,n,i=[]){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:void 0}),this.key=t,this.type=n,this.algorithm={name:e},this.usages=i,n==="public"&&(this.usages=[])}};var Ze="X25519",Jt=class extends ne{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=Tn.utils.randomPrivateKey(),t=new ee(Ze,e,"private",ce);return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(Z,it,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Mt,Z,this._nSk),i=new ee(Ze,new Uint8Array(n),"private",ce);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(Ze,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(Ze,new Uint8Array(e),t?"public":"private",t?[]:ce))})}_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(Ze,nt(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ze,nt(e.d),"private",ce)))})}_derivePublicKey(e){return new Promise(t=>{let n=Kr.getPublicKey(e.key);t(new ee(Ze,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Kr.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Qt=class extends se{constructor(){let e=new Ce,t=new Jt(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var[jn,zn,Rn]=[[],[],[]],Do=BigInt(0),yt=BigInt(1),jo=BigInt(2),zo=BigInt(7),Ro=BigInt(256),Mo=BigInt(113);for(let r=0,e=yt,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],jn.push(2*(5*n+t)),zn.push((r+1)*(r+2)/2%64);let i=Do;for(let o=0;o<7;o++)e=(e< >zo)*Mo)%Ro,e&jo&&(i^=yt<<(yt< t>32?P.rotlBH(r,e,t):P.rotlSH(r,e,t),Dn=(r,e,t)=>t>32?P.rotlBL(r,e,t):P.rotlSL(r,e,t);function Fo(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let s=0;s<10;s++)t[s]=r[s]^r[s+10]^r[s+20]^r[s+30]^r[s+40];for(let s=0;s<10;s+=2){let a=(s+8)%10,c=(s+2)%10,u=t[c],f=t[c+1],h=Nn(u,f,1)^t[a],d=Dn(u,f,1)^t[a+1];for(let m=0;m<50;m+=10)r[s+m]^=h,r[s+m+1]^=d}let i=r[2],o=r[3];for(let s=0;s<24;s++){let a=zn[s],c=Nn(i,o,a),u=Dn(i,o,a),f=jn[s];i=r[f],o=r[f+1],r[f]=c,r[f+1]=u}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)t[a]=r[s+a];for(let a=0;a<10;a++)r[s+a]^=~t[(a+2)%10]&t[(a+4)%10]}r[0]^=qo[n],r[1]^=Go[n]}t.fill(0)}var er=class r extends Be{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,oe.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=an(this.state)}keccak(){Fo(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){oe.exists(this);let{blockLen:t,state:n}=this;e=Le(e);let i=e.length;for(let o=0;o=n&&this.keccak();let s=Math.min(n-this.posOut,o-i);e.set(t.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return oe.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(oe.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:s}=this;return e||(e=new r(t,n,i,s,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=s,e.destroyed=this.destroyed,e}},Re=(r,e,t)=>he(()=>new er(e,r,t)),Zc=Re(6,144,224/8),Vc=Re(6,136,256/8),Xc=Re(6,104,384/8),Yc=Re(6,72,512/8),Wc=Re(1,144,224/8),Jc=Re(1,136,256/8),Qc=Re(1,104,384/8),ef=Re(1,72,512/8),Mn=(r,e,t)=>cn((n={})=>new er(e,r,n.dkLen===void 0?t:n.dkLen,!0)),tf=Mn(31,168,128/8),Ur=Mn(31,136,256/8);var $o=he(()=>Ur.create({dkLen:114})),Zo=he(()=>Ur.create({dkLen:64})),xt=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439");function qn(r){let e=xt,t=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(11),s=BigInt(22),a=BigInt(44),c=BigInt(88),u=BigInt(223),f=r*r*r%e,h=f*f*r%e,d=V(h,i,e)*h%e,m=V(d,i,e)*h%e,k=V(m,n,e)*f%e,_=V(k,o,e)*k%e,v=V(_,s,e)*_%e,$=V(v,a,e)*v%e,X=V($,c,e)*$%e,y=V(X,a,e)*v%e,L=V(y,n,e)*f%e,E=V(L,t,e)*r%e;return V(E,u,e)*L%e}function Gn(r){return r[0]&=252,r[55]|=128,r[56]=0,r}var Fn=Xt(xt,456,!0),uf=BigInt(4),$n={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:Fn,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:$o,randomBytes:Qe,adjustScalarBytes:Gn,domain:(r,e,t)=>{if(e.length>255)throw new Error(`Context is too big: ${e.length}`);return Nt(ct("SigEd448"),new Uint8Array([t?1:0,e.length]),e,r)},uvRatio:(r,e)=>{let t=xt,n=j(r*r*e,t),i=j(n*r,t),o=j(i*n*e,t),s=qn(o),a=j(i*s,t),c=j(a*a,t);return{isValid:j(c*e,t)===r,value:a}}},Zn=$e($n),lf=$e({...$n,prehash:Zo}),Or=(()=>Wt({a:BigInt(156326),montgomeryBits:448,nByteLength:57,P:xt,Gu:BigInt(5),powPminus2:r=>{let e=xt,t=qn(r),n=V(t,BigInt(2),e);return j(n*r,e)},adjustScalarBytes:Gn,randomBytes:Qe}))();var hf=(Fn.ORDER-BigInt(3))/BigInt(4),df=BigInt(156326);var Ve="X448",tr=class extends ne{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=Zn.utils.randomPrivateKey(),t=new ee(Ve,e,"private",ce);return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(Z,it,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Mt,Z,this._nSk),i=new ee(Ve,new Uint8Array(n),"private",ce);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(Ve,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(Ve,new Uint8Array(e),t?"public":"private",t?[]:ce))})}_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(Ve,nt(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ve,nt(e.d),"private",ce)))})}_derivePublicKey(e){return new Promise(t=>{let n=Or.getPublicKey(e.key);t(new ee(Ve,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Or.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var rr=class extends se{constructor(){let e=new je,t=new tr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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 Vo=new Uint8Array([115,101,99]),ot=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._emitError()}async open(e,t){return await this._emitError()}async export(e,t){if(e.byteLength>8192)throw new te("Too long exporter context");try{return await this._kdf.labeledExpand(this.exporterSecret,Vo,new Uint8Array(e),t)}catch(n){throw new vt(n)}}_emitError(){return new Promise((e,t)=>{t(new ge("Not available"))})}},nr=class extends ot{},ir=class extends ot{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 st=class extends ot{constructor(e,t,n){if(super(e,t,n.exporterSecret),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nT",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.key===void 0||n.baseNonce===void 0||n.seq===void 0)throw new Error("Required parameters are missing");this._aead=n.aead,this._nK=this._aead.keySize,this._nN=this._aead.nonceSize,this._nT=this._aead.tagSize;let i=this._aead.createEncryptionContext(n.key);this._ctx={key:i,baseNonce:n.baseNonce,seq:n.seq}}computeNonce(e){let t=xe(e.seq,e.baseNonce.byteLength);return yn(e.baseNonce,t)}incrementSeq(e){if(e.seq>Number.MAX_SAFE_INTEGER)throw new Pt("Message limit reached");e.seq+=1}};var or=class extends st{async open(e,t=Z){let n;try{n=await this._ctx.key.open(this.computeNonce(this._ctx),e,t)}catch(i){throw new At(i)}return this.incrementSeq(this._ctx),n}};var sr=class extends st{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=Z){let n;try{n=await this._ctx.key.seal(this.computeNonce(this._ctx),e,t)}catch(i){throw new St(i)}return this.incrementSeq(this._ctx),n}};var ar=class extends se{constructor(){let e=new Oe,t=new be(C.DhkemP256HkdfSha256,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}},cr=class extends se{constructor(){let e=new He,t=new be(C.DhkemP384HkdfSha384,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}},fr=class extends se{constructor(){let e=new Te,t=new be(C.DhkemP521HkdfSha512,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var Xo=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),Yo=new Uint8Array([101,120,112]),Wo=new Uint8Array([105,110,102,111,95,104,97,115,104]),Jo=new Uint8Array([107,101,121]),Qo=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),es=new Uint8Array([115,101,99,114,101,116]),ts=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),wt=class{constructor(e){if(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 C.DhkemP256HkdfSha256:this._kem=new ar;break;case C.DhkemP384HkdfSha384:this._kem=new cr;break;case C.DhkemP521HkdfSha512:this._kem=new fr;break;default:throw new te(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(typeof e.kdf!="number")this._kdf=e.kdf;else switch(e.kdf){case pe.HkdfSha256:this._kdf=new Oe;break;case pe.HkdfSha384:this._kdf=new He;break;default:this._kdf=new Te;break}if(typeof e.aead!="number")this._aead=e.aead;else switch(e.aead){case re.Aes128Gcm:this._aead=new Ye;break;case re.Aes256Gcm:this._aead=new We;break;case re.ExportOnly:this._aead=new Je;break;default:throw new te(`The AEAD (${e.aead}) cannot be specified by AeadId. Use submodule for the AEAD`)}this._suiteId=new Uint8Array(ts),this._suiteId.set(xe(this._kem.id,2),4),this._suiteId.set(xe(this._kdf.id,2),6),this._suiteId.set(xe(this._aead.id,2),8)}get kem(){return this._kem}get kdf(){return this._kdf}get aead(){return this._aead}async generateKeyPair(){return await this._setup(),await this._kem.generateKeyPair()}async deriveKeyPair(e){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?ve.AuthPsk:ve.Psk:n=e.senderKey!==void 0?ve.Auth:ve.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?ve.AuthPsk:ve.Psk:n=e.senderPublicKey!==void 0?ve.Auth:ve.Base,await this._keyScheduleR(n,t,e)}async seal(e,t,n=Z){let i=await this.createSenderContext(e);return{ct:await i.seal(t,n),enc:i.enc}}async open(e,t,n=Z){return await(await this.createRecipientContext(e)).open(t,n)}async _setup(){if(this._api!==void 0)return;let e=await Rt();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?Z:new Uint8Array(n.psk.id),o=await this._kdf.labeledExtract(Z,Qo,i),s=n.info===void 0?Z:new Uint8Array(n.info),a=await this._kdf.labeledExtract(Z,Wo,s),c=new Uint8Array(1+o.byteLength+a.byteLength);c.set(new Uint8Array([e]),0),c.set(new Uint8Array(o),1),c.set(new Uint8Array(a),1+o.byteLength);let u=n.psk===void 0?Z:new Uint8Array(n.psk.key),f=this._kdf.buildLabeledIkm(es,u),h=this._kdf.buildLabeledInfo(Yo,c,this._kdf.hashSize),d=await this._kdf.extractAndExpand(t,f,h,this._kdf.hashSize);if(this._aead.id===re.ExportOnly)return{aead:this._aead,exporterSecret:d};let m=this._kdf.buildLabeledInfo(Jo,c,this._aead.keySize),k=await this._kdf.extractAndExpand(t,f,m,this._aead.keySize),_=this._kdf.buildLabeledInfo(Xo,c,this._aead.nonceSize),v=await this._kdf.extractAndExpand(t,f,_,this._aead.nonceSize);return{aead:this._aead,exporterSecret:d,key:k,baseNonce:new Uint8Array(v),seq:0}}async _keyScheduleS(e,t,n,i){let o=await this._keySchedule(e,t,i);return o.key===void 0?new ir(this._api,this._kdf,o.exporterSecret,n):new sr(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 nr(this._api,this._kdf,i.exporterSecret):new or(this._api,this._kdf,i)}_validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>8192)throw new te("Too long info");if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new te(`PSK must have at least ${32} bytes`);if(e.psk.key.byteLength>8192)throw new te("Too long psk.key");if(e.psk.id.byteLength>8192)throw new te("Too long psk.id")}}};var Hr=class extends wt{constructor(e){if(typeof e.kem=="number")switch(e.kem){case C.DhkemP256HkdfSha256:e.kem=new Gt;break;case C.DhkemP384HkdfSha384:e.kem=new Ft;break;case C.DhkemP521HkdfSha512:e.kem=new $t;break;case C.DhkemX25519HkdfSha256:e.kem=new Qt;break;case C.DhkemX448HkdfSha512:e.kem=new rr;break;default:throw new te(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(typeof e.kdf=="number")switch(e.kdf){case pe.HkdfSha256:e.kdf=new Ce;break;case pe.HkdfSha384:e.kdf=new rt;break;default:e.kdf=new je;break}if(typeof e.aead=="number")switch(e.aead){case re.Aes128Gcm:e.aead=new Ye;break;case re.Aes256Gcm:e.aead=new We;break;case re.Chacha20Poly1305:e.aead=new Ht;break;default:e.aead=new Je;break}super(e)}};export{Zr as Aead,re as AeadId,Hr as CipherSuite,wt as CipherSuiteNative,kt as DecapError,It as DeriveKeyPairError,Xe as DeserializeError,Et as EncapError,vt as ExportError,ue as HpkeError,te as InvalidParamError,$r as Kdf,pe as KdfId,Fr as Kem,C as KemId,Pt as MessageLimitReachedError,ge as NotSupportedError,At as OpenError,St as SealError,_t as SerializeError,Gr as ValidationError}; +var ue=class extends Error{constructor(e){let t;e instanceof Error?t=e.message:typeof e=="string"?t=e:t="",super(t),this.name=this.constructor.name}},te=class extends ue{},Gr=class extends ue{},_t=class extends ue{},Xe=class extends ue{},Et=class extends ue{},kt=class extends ue{},vt=class extends ue{},St=class extends ue{},At=class extends ue{},Pt=class extends ue{},It=class extends ue{},me=class extends ue{};var ve={Base:0,Psk:1,Auth:2,AuthPsk:3},Fr={DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33},C=Fr,$r={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3},pe=$r,Zr={Aes128Gcm:1,Aes256Gcm:2,Chacha20Poly1305:3,ExportOnly:65535},re=Zr;var Z=new Uint8Array(0);var Bt=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}checkInit(){if(this._api===void 0)throw new Error("Not initialized. Call init()")}},ne=class extends Bt{constructor(){super()}init(e){this._api=e}},Lt=class extends Bt{constructor(){super(),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:Z})}init(e,t){this._api=e,this._suiteId=t}};var Vr=["encrypt","decrypt"];var Kt=class{constructor(e,t){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,Vr)}},Ye=class extends ne{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:re.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})}createEncryptionContext(e){return this.checkInit(),new Kt(this._api,e)}},We=class extends ne{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:re.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})}createEncryptionContext(e){return this.checkInit(),new Kt(this._api,e)}};var Je=class extends ne{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:re.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})}createEncryptionContext(e){throw new me("createEncryptionContext() is not supported on ExportOnly")}};var ri=r=>r instanceof Uint8Array;var Se=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Xr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ni=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ni)throw new Error("Non little-endian hardware is not supported");function Ot(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ut(r){if(typeof r=="string"&&(r=Ot(r)),!ri(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var ii=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function Yr(r,e){if(e!==void 0&&(typeof e!="object"||!ii(e)))throw new Error("options must be object or undefined");return Object.assign(r,e)}function Me(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 Wr(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),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}function hr(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 Jr(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 si(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("hash must be wrapped by utils.wrapConstructor");hr(r.outputLen),hr(r.blockLen)}function ai(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 ci(r,e){Jr(r);let t=e.outputLen;if(r.length r[e++]&255|(r[e++]&255)<<8,dr=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=Ut(e),Me(e,32);let t=ie(e,0),n=ie(e,2),i=ie(e,4),o=ie(e,6),s=ie(e,8),a=ie(e,10),c=ie(e,12),u=ie(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|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let f=0;f<8;f++)this.pad[f]=ie(e,16+2*f)}process(e,t,n=!1){let i=n?0:2048,{h:o,r:s}=this,a=s[0],c=s[1],u=s[2],f=s[3],h=s[4],d=s[5],m=s[6],k=s[7],_=s[8],v=s[9],$=ie(e,t+0),X=ie(e,t+2),y=ie(e,t+4),L=ie(e,t+6),E=ie(e,t+8),H=ie(e,t+10),M=ie(e,t+12),K=ie(e,t+14),w=o[0]+($&8191),B=o[1]+(($>>>13|X<<3)&8191),I=o[2]+((X>>>10|y<<6)&8191),A=o[3]+((y>>>7|L<<9)&8191),S=o[4]+((L>>>4|E<<12)&8191),q=o[5]+(E>>>1&8191),N=o[6]+((E>>>14|H<<2)&8191),G=o[7]+((H>>>11|M<<5)&8191),F=o[8]+((M>>>8|K<<8)&8191),p=o[9]+(K>>>5|i),l=0,b=l+w*a+B*(5*v)+I*(5*_)+A*(5*k)+S*(5*m);l=b>>>13,b&=8191,b+=q*(5*d)+N*(5*h)+G*(5*f)+F*(5*u)+p*(5*c),l+=b>>>13,b&=8191;let x=l+w*c+B*a+I*(5*v)+A*(5*_)+S*(5*k);l=x>>>13,x&=8191,x+=q*(5*m)+N*(5*d)+G*(5*h)+F*(5*f)+p*(5*u),l+=x>>>13,x&=8191;let g=l+w*u+B*c+I*a+A*(5*v)+S*(5*_);l=g>>>13,g&=8191,g+=q*(5*k)+N*(5*m)+G*(5*d)+F*(5*h)+p*(5*f),l+=g>>>13,g&=8191;let O=l+w*f+B*u+I*c+A*a+S*(5*v);l=O>>>13,O&=8191,O+=q*(5*_)+N*(5*k)+G*(5*m)+F*(5*d)+p*(5*h),l+=O>>>13,O&=8191;let T=l+w*h+B*f+I*u+A*c+S*a;l=T>>>13,T&=8191,T+=q*(5*v)+N*(5*_)+G*(5*k)+F*(5*m)+p*(5*d),l+=T>>>13,T&=8191;let z=l+w*d+B*h+I*f+A*u+S*c;l=z>>>13,z&=8191,z+=q*a+N*(5*v)+G*(5*_)+F*(5*k)+p*(5*m),l+=z>>>13,z&=8191;let U=l+w*m+B*d+I*h+A*f+S*u;l=U>>>13,U&=8191,U+=q*c+N*a+G*(5*v)+F*(5*_)+p*(5*k),l+=U>>>13,U&=8191;let D=l+w*k+B*m+I*d+A*h+S*f;l=D>>>13,D&=8191,D+=q*u+N*c+G*a+F*(5*v)+p*(5*_),l+=D>>>13,D&=8191;let Y=l+w*_+B*k+I*m+A*d+S*h;l=Y>>>13,Y&=8191,Y+=q*f+N*u+G*c+F*a+p*(5*v),l+=Y>>>13,Y&=8191;let J=l+w*v+B*_+I*k+A*m+S*d;l=J>>>13,J&=8191,J+=q*h+N*f+G*u+F*c+p*a,l+=J>>>13,J&=8191,l=(l<<2)+l|0,l=l+b|0,b=l&8191,l=l>>>13,x+=l,o[0]=b,o[1]=x,o[2]=g,o[3]=O,o[4]=T,o[5]=z,o[6]=U,o[7]=D,o[8]=Y,o[9]=J}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=i,i=e[a]>>>13,e[a]&=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 a=1;a<10;a++)n[a]=e[a]+i,i=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(i^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];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 s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535}update(e){ae.exists(this);let{buffer:t,blockLen:n}=this;e=Ut(e);let i=e.length;for(let o=0;o>>0,e[o++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function ui(r){let e=(n,i)=>r(i).update(Ut(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var Qr=ui(r=>new dr(r));var li=Ot("expand 16-byte k"),hi=Ot("expand 32-byte k"),di=Se(li),pi=Se(hi),en=r=>!(r.byteOffset%4),tn=r=>{let{core:e,rounds:t,counterRight:n,counterLen:i,allow128bitKeys:o,extendNonceFn:s,blockLen:a}=Yr({rounds:20,counterRight:!1,counterLen:8,allow128bitKeys:!0,blockLen:64},r);ae.number(i),ae.number(t),ae.number(a),ae.bool(n),ae.bool(o);let c=a/4;if(a%4!==0)throw new Error("Salsa/ChaCha: blockLen must be aligned to 4 bytes");return(u,f,h,d,m=0)=>{if(ae.bytes(u),ae.bytes(f),ae.bytes(h),d||(d=new Uint8Array(h.length)),ae.bytes(d),ae.number(m),m<0||m>=2**32-1)throw new Error("Salsa/ChaCha: counter overflow");if(d.length =2**32-1)throw new Error("Salsa/ChaCha: counter overflow");let I=Math.min(a,K-w);if(I===a&&M&&H){let A=w/4;if(w%4!==0)throw new Error("Salsa/ChaCha: invalid block position");for(let S=0;S r< >>32-e;function bi(r,e,t,n,i,o=20){let s=r[0],a=r[1],c=r[2],u=r[3],f=e[0],h=e[1],d=e[2],m=e[3],k=e[4],_=e[5],v=e[6],$=e[7],X=i,y=t[0],L=t[1],E=t[2],H=s,M=a,K=c,w=u,B=f,I=h,A=d,S=m,q=k,N=_,G=v,F=$,p=X,l=y,b=L,x=E;for(let O=0;O {r.update(e);let t=e.length%16;t&&r.update(xi.subarray(t))},nn=(r,e,t,n,i)=>{let o=r(e,t,new Uint8Array(32)),s=Qr.create(o);i&&rn(s,i),rn(s,n);let a=new Uint8Array(16),c=Xr(a);lr(c,0,BigInt(i?i.length:0),!0),lr(c,8,BigInt(n.length),!0),s.update(a);let u=s.digest();return o.fill(0),u},wi=r=>(e,t,n)=>(Me(e,32),Me(t),{tagLength:16,encrypt:(o,s)=>{let a=o.length,c=a+16;s?Me(s,c):s=new Uint8Array(c),r(e,t,o,s,1);let u=nn(r,e,t,s.subarray(0,-16),n);return s.set(u,a),s},decrypt:(o,s)=>{let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");s?Me(s,c):s=new Uint8Array(c);let u=o.subarray(0,-16),f=o.subarray(-16),h=nn(r,e,t,u,n);if(!Wr(f,h))throw new Error("invalid tag");return r(e,t,u,s,1),s}}),pr=wi(yi);var br=class{constructor(e,t){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=pr(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=pr(this._key,new Uint8Array(e),new Uint8Array(n)).decrypt(new Uint8Array(t));i(o.buffer)})}},Ht=class extends ne{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:re.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})}createEncryptionContext(e){return new br(this._api,e)}};function yr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`Wrong positive integer: ${r}`)}function mi(r){if(typeof r!="boolean")throw new Error(`Expected boolean, not ${r}`)}function on(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 gi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yr(r.outputLen),yr(r.blockLen)}function _i(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 Ei(r,e){on(r);let t=e.outputLen;if(r.length r instanceof Uint8Array;var an=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Ct=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ye=(r,e)=>r<<32-e|r>>>e,vi=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!vi)throw new Error("Non little-endian hardware is not supported");var Us=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 Le(r){if(typeof r=="string"&&(r=ct(r)),!sn(r))throw new Error(`expected Uint8Array, got ${typeof r}`);return r}function Nt(...r){let e=new Uint8Array(r.reduce((n,i)=>n+i.length,0)),t=0;return r.forEach(n=>{if(!sn(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var Be=class{clone(){return this._cloneInto()}};function he(r){let e=n=>r().update(Le(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function cn(r){let e=(n,i)=>r(i).update(Le(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}function Qe(r=32){if(Tt&&typeof Tt.getRandomValues=="function")return Tt.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}var Dt=class extends Be{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,oe.hash(e);let n=Le(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 s=0;s new Dt(r,e).update(t).digest();qe.create=(r,e)=>new Dt(r,e);function Si(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),c=n?4:0,u=n?0:4;r.setUint32(e+c,s,n),r.setUint32(e+u,a,n)}var et=class extends Be{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=Ct(this.buffer)}update(e){oe.exists(this);let{view:t,buffer:n,blockLen:i}=this;e=Le(e);let o=e.length;for(let s=0;s i-s&&(this.process(n,0),s=0);for(let h=s;hf.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;hr&e^~r&t,Pi=(r,e,t)=>r&e^r&t^e&t,Ii=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]),Ke=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Oe=new Uint32Array(64),jt=class extends et{constructor(){super(64,32,8,!1),this.A=Ke[0]|0,this.B=Ke[1]|0,this.C=Ke[2]|0,this.D=Ke[3]|0,this.E=Ke[4]|0,this.F=Ke[5]|0,this.G=Ke[6]|0,this.H=Ke[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,t,n,i,o,s,a,c]}set(e,t,n,i,o,s,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,t){for(let h=0;h<16;h++,t+=4)Oe[h]=e.getUint32(t,!1);for(let h=16;h<64;h++){let d=Oe[h-15],m=Oe[h-2],k=ye(d,7)^ye(d,18)^d>>>3,_=ye(m,17)^ye(m,19)^m>>>10;Oe[h]=_+Oe[h-7]+k+Oe[h-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let d=ye(a,6)^ye(a,11)^ye(a,25),m=f+d+Ai(a,c,u)+Ii[h]+Oe[h]|0,_=(ye(n,2)^ye(n,13)^ye(n,22))+Pi(n,i,o)|0;f=u,u=c,c=a,a=s+m|0,s=o,o=i,i=n,n=m+_|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,o,s,a,c,u,f)}roundClean(){Oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},xr=class extends jt{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}},fn=he(()=>new jt),qs=he(()=>new xr);var un=new Uint8Array([72,80,75,69,45,118,49]),ft=class extends Lt{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:pe.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(un,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(un,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)throw new te("The salt length must be the same as the hashSize");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),s=new Uint8Array(o),a=Z,c=new Uint8Array(t),u=new Uint8Array(1);if(n>255*this.hashSize)throw new Error("Entropy limit reached");let f=new Uint8Array(this.hashSize+c.length+1);for(let h=1,d=0;d =a.length?(s.set(a,d),d+=a.length):(s.set(a.slice(0,s.length-d),d),d+=s.length-d);return o}async extractAndExpand(e,t,n,i){this.checkInit();let o=await this._api.importKey("raw",t,"HKDF",!1,["deriveBits"]);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 ft{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:pe.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}})}},He=class extends ft{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:pe.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}})}},Te=class extends ft{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:pe.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 Ce=class extends Ue{async extract(e,t){if(this.checkInit(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return qe(fn,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)}};var zt=BigInt(4294967295),wr=BigInt(32);function ln(r,e=!1){return e?{h:Number(r&zt),l:Number(r>>wr&zt)}:{h:Number(r>>wr&zt)|0,l:Number(r&zt)|0}}function Bi(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i BigInt(r>>>0)< >>0),Ki=(r,e,t)=>r>>>t,Oi=(r,e,t)=>r<<32-t|e>>>t,Ui=(r,e,t)=>r>>>t|e<<32-t,Hi=(r,e,t)=>r<<32-t|e>>>t,Ti=(r,e,t)=>r<<64-t|e>>>t-32,Ci=(r,e,t)=>r>>>t-32|e<<64-t,Ni=(r,e)=>e,Di=(r,e)=>r,ji=(r,e,t)=>r< >>32-t,zi=(r,e,t)=>e< >>32-t,Ri=(r,e,t)=>e< >>64-t,Mi=(r,e,t)=>r< >>64-t;function qi(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Gi=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Fi=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,$i=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Zi=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,Vi=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),Xi=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0,Yi={fromBig:ln,split:Bi,toBig:Li,shrSH:Ki,shrSL:Oi,rotrSH:Ui,rotrSL:Hi,rotrBH:Ti,rotrBL:Ci,rotr32H:Ni,rotr32L:Di,rotlSH:ji,rotlSL:zi,rotlBH:Ri,rotlBL:Mi,add:qi,add3L:Gi,add3H:Fi,add4L:$i,add4H:Zi,add5H:Xi,add5L:Vi},P=Yi;var[Wi,Ji]=P.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))),Ne=new Uint32Array(80),De=new Uint32Array(80),tt=class extends et{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:s,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:d,Gh:m,Gl:k,Hh:_,Hl:v}=this;return[e,t,n,i,o,s,a,c,u,f,h,d,m,k,_,v]}set(e,t,n,i,o,s,a,c,u,f,h,d,m,k,_,v){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=d|0,this.Gh=m|0,this.Gl=k|0,this.Hh=_|0,this.Hl=v|0}process(e,t){for(let y=0;y<16;y++,t+=4)Ne[y]=e.getUint32(t),De[y]=e.getUint32(t+=4);for(let y=16;y<80;y++){let L=Ne[y-15]|0,E=De[y-15]|0,H=P.rotrSH(L,E,1)^P.rotrSH(L,E,8)^P.shrSH(L,E,7),M=P.rotrSL(L,E,1)^P.rotrSL(L,E,8)^P.shrSL(L,E,7),K=Ne[y-2]|0,w=De[y-2]|0,B=P.rotrSH(K,w,19)^P.rotrBH(K,w,61)^P.shrSH(K,w,6),I=P.rotrSL(K,w,19)^P.rotrBL(K,w,61)^P.shrSL(K,w,6),A=P.add4L(M,I,De[y-7],De[y-16]),S=P.add4H(A,H,B,Ne[y-7],Ne[y-16]);Ne[y]=S|0,De[y]=A|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:d,Fh:m,Fl:k,Gh:_,Gl:v,Hh:$,Hl:X}=this;for(let y=0;y<80;y++){let L=P.rotrSH(h,d,14)^P.rotrSH(h,d,18)^P.rotrBH(h,d,41),E=P.rotrSL(h,d,14)^P.rotrSL(h,d,18)^P.rotrBL(h,d,41),H=h&m^~h&_,M=d&k^~d&v,K=P.add5L(X,E,M,Ji[y],De[y]),w=P.add5H(K,$,L,H,Wi[y],Ne[y]),B=K|0,I=P.rotrSH(n,i,28)^P.rotrBH(n,i,34)^P.rotrBH(n,i,39),A=P.rotrSL(n,i,28)^P.rotrBL(n,i,34)^P.rotrBL(n,i,39),S=n&o^n&a^o&a,q=i&s^i&c^s&c;$=_|0,X=v|0,_=m|0,v=k|0,m=h|0,k=d|0,{h,l:d}=P.add(u|0,f|0,w|0,B|0),u=a|0,f=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let N=P.add3L(B,A,q);n=P.add3H(N,w,I,S),i=N|0}({h:n,l:i}=P.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=P.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=P.add(this.Dh|0,this.Dl|0,u|0,f|0),{h,l:d}=P.add(this.Eh|0,this.El|0,h|0,d|0),{h:m,l:k}=P.add(this.Fh|0,this.Fl|0,m|0,k|0),{h:_,l:v}=P.add(this.Gh|0,this.Gl|0,_|0,v|0),{h:$,l:X}=P.add(this.Hh|0,this.Hl|0,$|0,X|0),this.set(n,i,o,s,a,c,u,f,h,d,m,k,_,v,$,X)}roundClean(){Ne.fill(0),De.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)}},mr=class extends tt{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}},gr=class extends tt{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}},_r=class extends tt{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}},ut=he(()=>new tt),ra=he(()=>new mr),na=he(()=>new gr),hn=he(()=>new _r);var rt=class extends He{async extract(e,t){if(this.checkInit(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return qe(hn,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)}};var je=class extends Te{async extract(e,t){if(this.checkInit(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return qe(ut,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)}};var Qi={},dn=eo(globalThis,Qi);function eo(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(s=>!o.has(s)),...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 pn=()=>typeof dn<"u",bn=()=>typeof caches<"u";var lt=r=>typeof r=="object"&&r!==null&&typeof r.privateKey=="object"&&typeof r.publicKey=="object";function ge(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 yn(r,e){if(r.byteLength!==e.byteLength)throw new Error("xor: different length inputs");let t=new Uint8Array(r.byteLength);for(let n=0;n 8192)throw new te("Too long ikm");await this._setup();try{return await this._prim.deriveKeyPair(e)}catch(t){throw new It(t)}}async serializePublicKey(e){await this._setup();try{return await this._prim.serializePublicKey(e)}catch(t){throw new _t(t)}}async deserializePublicKey(e){await this._setup();try{return await this._prim.deserializePublicKey(e)}catch(t){throw new Xe(t)}}async importKey(e,t,n=!0){await this._setup();try{return await this._prim.importKey(e,t,n)}catch(i){throw new Xe(i)}}async encap(e){await this._setup();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=lt(e.senderKey)?e.senderKey.privateKey:e.senderKey,u=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey)),f=new Uint8Array(await this._prim.dh(c,e.recipientPublicKey));o=ht(u,f)}let s;if(e.senderKey===void 0)s=ht(new Uint8Array(n),new Uint8Array(i));else{let c=lt(e.senderKey)?e.senderKey.publicKey:await this._prim.derivePublicKey(e.senderKey),u=await this._prim.serializePublicKey(c);s=xn(new Uint8Array(n),new Uint8Array(i),new Uint8Array(u))}let a=await this._generateSharedSecret(o,s);return{enc:n,sharedSecret:a}}catch(t){throw new Et(t)}}async decap(e){let t;await this._setup();try{t=await this._prim.deserializePublicKey(e.enc)}catch(n){throw new Xe(n)}try{let n=lt(e.recipientKey)?e.recipientKey.privateKey:e.recipientKey,i=lt(e.recipientKey)?e.recipientKey.publicKey:await this._prim.derivePublicKey(e.recipientKey),o=await this._prim.serializePublicKey(i),s;if(e.senderPublicKey===void 0)s=new Uint8Array(await this._prim.dh(n,t));else{let c=new Uint8Array(await this._prim.dh(n,t)),u=new Uint8Array(await this._prim.dh(n,e.senderPublicKey));s=ht(c,u)}let a;if(e.senderPublicKey===void 0)a=ht(new Uint8Array(e.enc),new Uint8Array(o));else{let c=await this._prim.serializePublicKey(e.senderPublicKey);a=new Uint8Array(e.enc.byteLength+o.byteLength+c.byteLength),a.set(new Uint8Array(e.enc),0),a.set(new Uint8Array(o),e.enc.byteLength),a.set(new Uint8Array(c),e.enc.byteLength+o.byteLength)}return await this._generateSharedSecret(s,a)}catch(n){throw new kt(n)}}async _setup(){if(this._api!==void 0)return;let e=await Rt(),t=new Uint8Array(ro);t.set(ge(this.id,2),3),this._prim.init(e),this._kdf.init(e,t),super.init(e)}async _generateSharedSecret(e,t){let n=this._kdf.buildLabeledIkm(no,e),i=this._kdf.buildLabeledInfo(io,t,this.secretSize);return await this._kdf.extractAndExpand(Z,n,i,this.secretSize)}};var ce=["deriveBits"],it=new Uint8Array([100,107,112,95,112,114,107]),Mt=new Uint8Array([115,107]);var qt=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;e e[t])return!1}return!1}};var oo=new Uint8Array([99,97,110,100,105,100,97,116,101]),so=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]),ao=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]),co=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]),fo=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]),uo=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]),lo=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]),be=class extends ne{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 C.DhkemP256HkdfSha256:this._alg={name:"ECDH",namedCurve:"P-256"},this._nPk=65,this._nSk=32,this._nDh=32,this._order=so,this._bitmask=255,this._pkcs8AlgId=fo;break;case C.DhkemP384HkdfSha384:this._alg={name:"ECDH",namedCurve:"P-384"},this._nPk=97,this._nSk=48,this._nDh=48,this._order=ao,this._bitmask=255,this._pkcs8AlgId=uo;break;default:this._alg={name:"ECDH",namedCurve:"P-521"},this._nPk=133,this._nSk=66,this._nDh=66,this._order=co,this._bitmask=1,this._pkcs8AlgId=lo;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,ce)}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,ce)}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,ce)}async deriveKeyPair(e){this.checkInit();let t=await this._hkdf.labeledExtract(Z,it,new Uint8Array(e)),n=new qt(this._nSk);for(let s=0;n.isZero()||!n.lessThan(this._order);s++){if(s>255)throw new Error("Faild to derive a key pair");let a=new Uint8Array(await this._hkdf.labeledExpand(t,oo,ge(s,1),this._nSk));a[0]=a[0]&this._bitmask,n.set(a)}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,ce);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 Gt=class extends se{constructor(){let e=new Ce,t=new be(C.DhkemP256HkdfSha256,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var Ft=class extends se{constructor(){let e=new rt,t=new be(C.DhkemP384HkdfSha384,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var $t=class extends se{constructor(){let e=new je,t=new be(C.DhkemP521HkdfSha512,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var $a=BigInt(0),ho=BigInt(1),po=BigInt(2),Zt=r=>r instanceof Uint8Array,bo=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function dt(r){if(!Zt(r))throw new Error("Uint8Array expected");let e="";for(let t=0;t n+i.length,0)),t=0;return r.forEach(n=>{if(!Zt(n))throw new Error("Uint8Array expected");e.set(n,t),t+=n.length}),e}var gn=r=>(po< 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 Ae(r,e,t={}){let n=(i,o,s)=>{let a=yo[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[i];if(!(s&&c===void 0)&&!a(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),W=BigInt(1),Fe=BigInt(2),wo=BigInt(3),vr=BigInt(4),_n=BigInt(5),En=BigInt(8),mo=BigInt(9),go=BigInt(16);function j(r,e){let t=r%e;return t>=Q?t:e+t}function Sr(r,e,t){if(t<=Q||e 0");if(t===W)return Q;let n=W;for(;e>Q;)e&W&&(n=n*r%t),r=r*r%t,e>>=W;return n}function V(r,e,t){let n=r;for(;e-- >Q;)n*=n,n%=t;return n}function kn(r,e){if(r===Q||e<=Q)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=j(r,e),n=e,i=Q,o=W,s=W,a=Q;for(;t!==Q;){let u=n/t,f=n%t,h=i-s*u,d=o-a*u;n=t,t=f,i=s,o=a,s=h,a=d}if(n!==W)throw new Error("invert: does not exist");return j(i,e)}function _o(r){let e=(r-W)/Fe,t,n,i;for(t=r-W,n=0;t%Fe===Q;t/=Fe,n++);for(i=Fe;i(j(r,e)&W)===W,ko=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Sn(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=ko.reduce((n,i)=>(n[i]="function",n),e);return Ae(r,t)}function vo(r,e,t){if(t 0");if(t===Q)return r.ONE;if(t===W)return e;let n=r.ONE,i=e;for(;t>Q;)t&W&&(n=r.mul(n,i)),i=r.sqr(i),t>>=W;return n}function So(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Ar(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Xt(r,e,t=!1,n={}){if(r<=Q)throw new Error(`Expected Fp ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Ar(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Eo(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:gn(i),ZERO:Q,ONE:W,create:c=>j(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&W)===W,neg:c=>j(-c,r),eql:(c,u)=>c===u,sqr:c=>j(c*c,r),add:(c,u)=>j(c+u,r),sub:(c,u)=>j(c-u,r),mul:(c,u)=>j(c*u,r),pow:(c,u)=>vo(a,c,u),div:(c,u)=>j(c*kn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>kn(c,r),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>So(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>t?ze(c,o):kr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return t?_e(c):Er(c)}});return Object.freeze(a)}function An(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 Ao=BigInt(0),Pr=BigInt(1);function Pn(r,e){let t=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:t,unsafeLadder(i,o){let s=r.ZERO,a=i;for(;o>Ao;)o&Pr&&(s=s.add(a)),a=a.double(),o>>=Pr;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,f=u;for(let h=0;h >=m,v>c&&(v-=d,s+=Pr);let $=_,X=_+Math.abs(v)-1,y=k%2!==0,L=v<0;v===0?f=f.add(t(y,o[$])):u=u.add(t(L,o[X]))}return{p:u,f}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function In(r){return Sn(r.Fp),Ae(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ar(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var xe=BigInt(0),de=BigInt(1),Yt=BigInt(2),Po=BigInt(8),Io={zip215:!0};function Bo(r){let e=In(r);return Ae(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function $e(r){let e=Bo(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Yt<{try{return{isValid:!0,value:t.sqrt(p*t.inv(l))}}catch{return{isValid:!1,value:xe}}}),d=e.adjustScalarBytes||(p=>p),m=e.domain||((p,l,b)=>{if(l.length||b)throw new Error("Contexts/pre-hash are not supported");return p}),k=p=>typeof p=="bigint"&&xe k(p)&&k(l)&&p
p===xe||_(p,u);function $(p,l){if(_(p,l))return p;throw new Error(`Expected valid scalar < ${l}, got ${typeof p} ${p}`)}function X(p){return p===xe?p:$(p,n)}let y=new Map;function L(p){if(!(p instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(l,b,x,g){if(this.ex=l,this.ey=b,this.ez=x,this.et=g,!v(l))throw new Error("x required");if(!v(b))throw new Error("y required");if(!v(x))throw new Error("z required");if(!v(g))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(l){if(l instanceof E)throw new Error("extended point not allowed");let{x:b,y:x}=l||{};if(!v(b)||!v(x))throw new Error("invalid affine point");return new E(b,x,de,f(b*x))}static normalizeZ(l){let b=t.invertBatch(l.map(x=>x.ez));return l.map((x,g)=>x.toAffine(b[g])).map(E.fromAffine)}_setWindowSize(l){this._WINDOW_SIZE=l,y.delete(this)}assertValidity(){let{a:l,d:b}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:x,ey:g,ez:O,et:T}=this,z=f(x*x),U=f(g*g),D=f(O*O),Y=f(D*D),J=f(z*l),we=f(D*f(J+U)),fe=f(Y+f(b*f(z*U)));if(we!==fe)throw new Error("bad point: equation left != right (1)");let Ie=f(x*g),Ee=f(O*T);if(Ie!==Ee)throw new Error("bad point: equation left != right (2)")}equals(l){L(l);let{ex:b,ey:x,ez:g}=this,{ex:O,ey:T,ez:z}=l,U=f(b*z),D=f(O*g),Y=f(x*z),J=f(T*g);return U===D&&Y===J}is0(){return this.equals(E.ZERO)}negate(){return new E(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:l}=e,{ex:b,ey:x,ez:g}=this,O=f(b*b),T=f(x*x),z=f(Yt*f(g*g)),U=f(l*O),D=b+x,Y=f(f(D*D)-O-T),J=U+T,we=J-z,fe=U-T,Ie=f(Y*we),Ee=f(J*fe),mt=f(Y*fe),gt=f(we*J);return new E(Ie,Ee,gt,mt)}add(l){L(l);let{a:b,d:x}=e,{ex:g,ey:O,ez:T,et:z}=this,{ex:U,ey:D,ez:Y,et:J}=l;if(b===BigInt(-1)){let Nr=f((O-g)*(D+U)),Dr=f((O+g)*(D-U)),ur=f(Dr-Nr);if(ur===xe)return this.double();let jr=f(T*Yt*J),zr=f(z*Yt*Y),Rr=zr+jr,Mr=Dr+Nr,qr=zr-jr,Jn=f(Rr*ur),Qn=f(Mr*qr),ei=f(Rr*qr),ti=f(ur*Mr);return new E(Jn,Qn,ti,ei)}let we=f(g*U),fe=f(O*D),Ie=f(z*x*J),Ee=f(T*Y),mt=f((g+O)*(U+D)-we-fe),gt=Ee-Ie,Tr=Ee+Ie,Cr=f(fe-b*we),Vn=f(mt*gt),Xn=f(Tr*Cr),Yn=f(mt*Cr),Wn=f(gt*Tr);return new E(Vn,Xn,Wn,Yn)}subtract(l){return this.add(l.negate())}wNAF(l){return K.wNAFCached(this,y,l,E.normalizeZ)}multiply(l){let{p:b,f:x}=this.wNAF($(l,n));return E.normalizeZ([b,x])[0]}multiplyUnsafe(l){let b=X(l);return b===xe?M:this.equals(M)||b===de?this:this.equals(H)?this.wNAF(b).p:K.unsafeLadder(this,b)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return K.unsafeLadder(this,n).is0()}toAffine(l){let{ex:b,ey:x,ez:g}=this,O=this.is0();l==null&&(l=O?Po:t.inv(g));let T=f(b*l),z=f(x*l),U=f(g*l);if(O)return{x:xe,y:de};if(U!==de)throw new Error("invZ was invalid");return{x:T,y:z}}clearCofactor(){let{h:l}=e;return l===de?this:this.multiplyUnsafe(l)}static fromHex(l,b=!1){let{d:x,a:g}=e,O=t.BYTES;l=le("pointHex",l,O);let T=l.slice(),z=l[O-1];T[O-1]=z&-129;let U=_e(T);U===xe||(b?$(U,u):$(U,t.ORDER));let D=f(U*U),Y=f(D-de),J=f(x*D-g),{isValid:we,value:fe}=h(Y,J);if(!we)throw new Error("Point.fromHex: invalid y coordinate");let Ie=(fe&de)===de,Ee=(z&128)!==0;if(!b&&fe===xe&&Ee)throw new Error("Point.fromHex: x=0 and x_0=1");return Ee!==Ie&&(fe=f(-fe)),E.fromAffine({x:fe,y:U})}static fromPrivateKey(l){return I(l).point}toRawBytes(){let{x:l,y:b}=this.toAffine(),x=ze(b,t.BYTES);return x[x.length-1]|=l&de?128:0,x}toHex(){return dt(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,de,f(e.Gx*e.Gy)),E.ZERO=new E(xe,de,de,xe);let{BASE:H,ZERO:M}=E,K=Pn(E,a*8);function w(p){return j(p,n)}function B(p){return w(_e(p))}function I(p){let l=a;p=le("private key",p,l);let b=le("hashed private key",o(p),2*l),x=d(b.slice(0,l)),g=b.slice(l,2*l),O=B(x),T=H.multiply(O),z=T.toRawBytes();return{head:x,prefix:g,scalar:O,point:T,pointBytes:z}}function A(p){return I(p).pointBytes}function S(p=new Uint8Array,...l){let b=Vt(...l);return B(o(m(b,le("context",p),!!i)))}function q(p,l,b={}){p=le("message",p),i&&(p=i(p));let{prefix:x,scalar:g,pointBytes:O}=I(l),T=S(b.context,x,p),z=H.multiply(T).toRawBytes(),U=S(b.context,z,O,p),D=w(T+U*g);X(D);let Y=Vt(z,ze(D,t.BYTES));return le("result",Y,a*2)}let N=Io;function G(p,l,b,x=N){let{context:g,zip215:O}=x,T=t.BYTES;p=le("signature",p,2*T),l=le("message",l),i&&(l=i(l));let z=_e(p.slice(T,2*T)),U,D,Y;try{U=E.fromHex(b,O),D=E.fromHex(p.slice(0,T),O),Y=H.multiplyUnsafe(z)}catch{return!1}if(!O&&U.isSmallOrder())return!1;let J=S(g,D.toRawBytes(),U.toRawBytes(),l);return D.add(U.multiplyUnsafe(J)).subtract(Y).clearCofactor().equals(E.ZERO)}return H._setWindowSize(8),{CURVE:e,getPublicKey:A,sign:q,verify:G,ExtendedPoint:E,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>s(t.BYTES),precompute(p=8,l=E.BASE){return l._setWindowSize(p),l.multiply(BigInt(3)),l}}}}var pt=BigInt(0),Ir=BigInt(1);function Lo(r){return Ae(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Wt(r){let e=Lo(r),{P:t}=e,n=y=>j(y,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,a=e.adjustScalarBytes||(y=>y),c=e.powPminus2||(y=>Sr(y,t-BigInt(2),t));function u(y,L,E){let H=n(y*(L-E));return L=n(L-H),E=n(E+H),[L,E]}function f(y){if(typeof y=="bigint"&&pt<=y&&y =pt;N--){let G=H>>N&Ir;A^=G,S=u(A,K,B),K=S[0],B=S[1],S=u(A,w,I),w=S[0],I=S[1],A=G;let F=K+w,p=n(F*F),l=K-w,b=n(l*l),x=p-b,g=B+I,O=B-I,T=n(O*F),z=n(g*l),U=T+z,D=T-z;B=n(U*U),I=n(M*n(D*D)),K=n(p*b),w=n(x*(p+n(h*x)))}S=u(A,K,B),K=S[0],B=S[1],S=u(A,w,I),w=S[0],I=S[1];let q=c(w);return n(K*q)}function m(y){return ze(n(y),o)}function k(y){let L=le("u coordinate",y,o);return s===o&&(L[s-1]&=127),_e(L)}function _(y){let L=le("scalar",y);if(L.length!==o&&L.length!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${L.length}`);return _e(a(L))}function v(y,L){let E=k(L),H=_(y),M=d(E,H);if(M===pt)throw new Error("Invalid private or public key received");return m(M)}let $=m(e.Gu);function X(y){return v(y,$)}return{scalarMult:v,scalarMultBase:X,getSharedSecret:(y,L)=>v(y,L),getPublicKey:y=>X(y),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:$}}var bt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Bn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),wc=BigInt(0),Oo=BigInt(1),Br=BigInt(2),Uo=BigInt(5),Ln=BigInt(10),Ho=BigInt(20),To=BigInt(40),Kn=BigInt(80);function On(r){let e=bt,n=r*r%e*r%e,i=V(n,Br,e)*n%e,o=V(i,Oo,e)*r%e,s=V(o,Uo,e)*o%e,a=V(s,Ln,e)*s%e,c=V(a,Ho,e)*a%e,u=V(c,To,e)*c%e,f=V(u,Kn,e)*u%e,h=V(f,Kn,e)*u%e,d=V(h,Ln,e)*s%e;return{pow_p_5_8:V(d,Br,e)*r%e,b2:n}}function Un(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Co(r,e){let t=bt,n=j(e*e*e,t),i=j(n*n*e,t),o=On(r*i).pow_p_5_8,s=j(r*n*o,t),a=j(e*s*s,t),c=s,u=j(s*Bn,t),f=a===r,h=a===j(-r,t),d=a===j(-r*Bn,t);return f&&(s=c),(h||d)&&(s=u),vn(s,t)&&(s=j(-s,t)),{isValid:f||h,value:s}}var Pe=Xt(bt,void 0,!0),Lr={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Pe,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ut,randomBytes:Qe,adjustScalarBytes:Un,uvRatio:Co},Hn=$e(Lr);function Tn(r,e,t){if(e.length>255)throw new Error("Context is too big");return Nt(ct("SigEd25519 no Ed25519 collisions"),new Uint8Array([t?1:0,e.length]),e,r)}var mc=$e({...Lr,domain:Tn}),gc=$e({...Lr,domain:Tn,prehash:ut}),Kr=(()=>Wt({P:bt,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=bt,{pow_p_5_8:t,b2:n}=On(r);return j(V(t,BigInt(3),e)*n,e)},adjustScalarBytes:Un,randomBytes:Qe}))();var No=(Pe.ORDER+BigInt(3))/BigInt(8),_c=Pe.pow(Br,No),Ec=Pe.sqrt(Pe.neg(Pe.ONE)),kc=(Pe.ORDER-BigInt(5))/BigInt(8),vc=BigInt(486662);var Sc=An(Pe,Pe.neg(BigInt(486664)));var Ac=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Pc=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ic=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Bc=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var Lc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var ee=class{constructor(e,t,n,i=[]){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:void 0}),this.key=t,this.type=n,this.algorithm={name:e},this.usages=i,n==="public"&&(this.usages=[])}};var Ze="X25519",Jt=class extends ne{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=Hn.utils.randomPrivateKey(),t=new ee(Ze,e,"private",ce);return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(Z,it,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Mt,Z,this._nSk),i=new ee(Ze,new Uint8Array(n),"private",ce);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(Ze,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(Ze,new Uint8Array(e),t?"public":"private",t?[]:ce))})}_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(Ze,nt(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ze,nt(e.d),"private",ce)))})}_derivePublicKey(e){return new Promise(t=>{let n=Kr.getPublicKey(e.key);t(new ee(Ze,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Kr.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Qt=class extends se{constructor(){let e=new Ce,t=new Jt(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var[Dn,jn,zn]=[[],[],[]],Do=BigInt(0),yt=BigInt(1),jo=BigInt(2),zo=BigInt(7),Ro=BigInt(256),Mo=BigInt(113);for(let r=0,e=yt,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],Dn.push(2*(5*n+t)),jn.push((r+1)*(r+2)/2%64);let i=Do;for(let o=0;o<7;o++)e=(e< >zo)*Mo)%Ro,e&jo&&(i^=yt<<(yt< t>32?P.rotlBH(r,e,t):P.rotlSH(r,e,t),Nn=(r,e,t)=>t>32?P.rotlBL(r,e,t):P.rotlSL(r,e,t);function Fo(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let s=0;s<10;s++)t[s]=r[s]^r[s+10]^r[s+20]^r[s+30]^r[s+40];for(let s=0;s<10;s+=2){let a=(s+8)%10,c=(s+2)%10,u=t[c],f=t[c+1],h=Cn(u,f,1)^t[a],d=Nn(u,f,1)^t[a+1];for(let m=0;m<50;m+=10)r[s+m]^=h,r[s+m+1]^=d}let i=r[2],o=r[3];for(let s=0;s<24;s++){let a=jn[s],c=Cn(i,o,a),u=Nn(i,o,a),f=Dn[s];i=r[f],o=r[f+1],r[f]=c,r[f+1]=u}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)t[a]=r[s+a];for(let a=0;a<10;a++)r[s+a]^=~t[(a+2)%10]&t[(a+4)%10]}r[0]^=qo[n],r[1]^=Go[n]}t.fill(0)}var er=class r extends Be{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,oe.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=an(this.state)}keccak(){Fo(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){oe.exists(this);let{blockLen:t,state:n}=this;e=Le(e);let i=e.length;for(let o=0;o=n&&this.keccak();let s=Math.min(n-this.posOut,o-i);e.set(t.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return oe.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(oe.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:s}=this;return e||(e=new r(t,n,i,s,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=s,e.destroyed=this.destroyed,e}},Re=(r,e,t)=>he(()=>new er(e,r,t)),Zc=Re(6,144,224/8),Vc=Re(6,136,256/8),Xc=Re(6,104,384/8),Yc=Re(6,72,512/8),Wc=Re(1,144,224/8),Jc=Re(1,136,256/8),Qc=Re(1,104,384/8),ef=Re(1,72,512/8),Rn=(r,e,t)=>cn((n={})=>new er(e,r,n.dkLen===void 0?t:n.dkLen,!0)),tf=Rn(31,168,128/8),Or=Rn(31,136,256/8);var $o=he(()=>Or.create({dkLen:114})),Zo=he(()=>Or.create({dkLen:64})),xt=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439");function Mn(r){let e=xt,t=BigInt(1),n=BigInt(2),i=BigInt(3),o=BigInt(11),s=BigInt(22),a=BigInt(44),c=BigInt(88),u=BigInt(223),f=r*r*r%e,h=f*f*r%e,d=V(h,i,e)*h%e,m=V(d,i,e)*h%e,k=V(m,n,e)*f%e,_=V(k,o,e)*k%e,v=V(_,s,e)*_%e,$=V(v,a,e)*v%e,X=V($,c,e)*$%e,y=V(X,a,e)*v%e,L=V(y,n,e)*f%e,E=V(L,t,e)*r%e;return V(E,u,e)*L%e}function qn(r){return r[0]&=252,r[55]|=128,r[56]=0,r}var Gn=Xt(xt,456,!0),uf=BigInt(4),Fn={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:Gn,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:$o,randomBytes:Qe,adjustScalarBytes:qn,domain:(r,e,t)=>{if(e.length>255)throw new Error(`Context is too big: ${e.length}`);return Nt(ct("SigEd448"),new Uint8Array([t?1:0,e.length]),e,r)},uvRatio:(r,e)=>{let t=xt,n=j(r*r*e,t),i=j(n*r,t),o=j(i*n*e,t),s=Mn(o),a=j(i*s,t),c=j(a*a,t);return{isValid:j(c*e,t)===r,value:a}}},$n=$e(Fn),lf=$e({...Fn,prehash:Zo}),Ur=(()=>Wt({a:BigInt(156326),montgomeryBits:448,nByteLength:57,P:xt,Gu:BigInt(5),powPminus2:r=>{let e=xt,t=Mn(r),n=V(t,BigInt(2),e);return j(n*r,e)},adjustScalarBytes:qn,randomBytes:Qe}))();var hf=(Gn.ORDER-BigInt(3))/BigInt(4),df=BigInt(156326);var Ve="X448",tr=class extends ne{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=$n.utils.randomPrivateKey(),t=new ee(Ve,e,"private",ce);return{publicKey:await this.derivePublicKey(t),privateKey:t}}async deriveKeyPair(e){let t=await this._hkdf.labeledExtract(Z,it,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,Mt,Z,this._nSk),i=new ee(Ve,new Uint8Array(n),"private",ce);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(Ve,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(Ve,new Uint8Array(e),t?"public":"private",t?[]:ce))})}_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(Ve,nt(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new ee(Ve,nt(e.d),"private",ce)))})}_derivePublicKey(e){return new Promise(t=>{let n=Ur.getPublicKey(e.key);t(new ee(Ve,n,"public"))})}_dh(e,t){return new Promise((n,i)=>{try{n(Ur.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var rr=class extends se{constructor(){let e=new je,t=new tr(e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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 Vo=new Uint8Array([115,101,99]),ot=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._emitError()}async open(e,t){return await this._emitError()}async export(e,t){if(e.byteLength>8192)throw new te("Too long exporter context");try{return await this._kdf.labeledExpand(this.exporterSecret,Vo,new Uint8Array(e),t)}catch(n){throw new vt(n)}}_emitError(){return new Promise((e,t)=>{t(new me("Not available"))})}},nr=class extends ot{},ir=class extends ot{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 st=class extends ot{constructor(e,t,n){if(super(e,t,n.exporterSecret),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nT",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.key===void 0||n.baseNonce===void 0||n.seq===void 0)throw new Error("Required parameters are missing");this._aead=n.aead,this._nK=this._aead.keySize,this._nN=this._aead.nonceSize,this._nT=this._aead.tagSize;let i=this._aead.createEncryptionContext(n.key);this._ctx={key:i,baseNonce:n.baseNonce,seq:n.seq}}computeNonce(e){let t=ge(e.seq,e.baseNonce.byteLength);return yn(e.baseNonce,t)}incrementSeq(e){if(e.seq>Number.MAX_SAFE_INTEGER)throw new Pt("Message limit reached");e.seq+=1}};var or=class extends st{async open(e,t=Z){let n;try{n=await this._ctx.key.open(this.computeNonce(this._ctx),e,t)}catch(i){throw new At(i)}return this.incrementSeq(this._ctx),n}};var sr=class extends st{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=Z){let n;try{n=await this._ctx.key.seal(this.computeNonce(this._ctx),e,t)}catch(i){throw new St(i)}return this.incrementSeq(this._ctx),n}};var ar=class extends se{constructor(){let e=new Ue,t=new be(C.DhkemP256HkdfSha256,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}},cr=class extends se{constructor(){let e=new He,t=new be(C.DhkemP384HkdfSha384,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}},fr=class extends se{constructor(){let e=new Te,t=new be(C.DhkemP521HkdfSha512,e);super(t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:C.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})}};var Xo=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),Yo=new Uint8Array([101,120,112]),Wo=new Uint8Array([105,110,102,111,95,104,97,115,104]),Jo=new Uint8Array([107,101,121]),Qo=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),es=new Uint8Array([115,101,99,114,101,116]),ts=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),wt=class{constructor(e){if(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 C.DhkemP256HkdfSha256:this._kem=new ar;break;case C.DhkemP384HkdfSha384:this._kem=new cr;break;case C.DhkemP521HkdfSha512:this._kem=new fr;break;default:throw new te(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(typeof e.kdf!="number")this._kdf=e.kdf;else switch(e.kdf){case pe.HkdfSha256:this._kdf=new Ue;break;case pe.HkdfSha384:this._kdf=new He;break;default:this._kdf=new Te;break}if(typeof e.aead!="number")this._aead=e.aead;else switch(e.aead){case re.Aes128Gcm:this._aead=new Ye;break;case re.Aes256Gcm:this._aead=new We;break;case re.ExportOnly:this._aead=new Je;break;default:throw new te(`The AEAD (${e.aead}) cannot be specified by AeadId. Use submodule for the AEAD`)}this._suiteId=new Uint8Array(ts),this._suiteId.set(ge(this._kem.id,2),4),this._suiteId.set(ge(this._kdf.id,2),6),this._suiteId.set(ge(this._aead.id,2),8)}get kem(){return this._kem}get kdf(){return this._kdf}get aead(){return this._aead}async generateKeyPair(){return await this._setup(),await this._kem.generateKeyPair()}async deriveKeyPair(e){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?ve.AuthPsk:ve.Psk:n=e.senderKey!==void 0?ve.Auth:ve.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?ve.AuthPsk:ve.Psk:n=e.senderPublicKey!==void 0?ve.Auth:ve.Base,await this._keyScheduleR(n,t,e)}async seal(e,t,n=Z){let i=await this.createSenderContext(e);return{ct:await i.seal(t,n),enc:i.enc}}async open(e,t,n=Z){return await(await this.createRecipientContext(e)).open(t,n)}async _setup(){if(this._api!==void 0)return;let e=await Rt();this._kdf.init(e,this._suiteId),this._aead.init(e),this._api=e}async _keySchedule(e,t,n){let i=n.psk===void 0?Z:new Uint8Array(n.psk.id),o=await this._kdf.labeledExtract(Z,Qo,i),s=n.info===void 0?Z:new Uint8Array(n.info),a=await this._kdf.labeledExtract(Z,Wo,s),c=new Uint8Array(1+o.byteLength+a.byteLength);c.set(new Uint8Array([e]),0),c.set(new Uint8Array(o),1),c.set(new Uint8Array(a),1+o.byteLength);let u=n.psk===void 0?Z:new Uint8Array(n.psk.key),f=this._kdf.buildLabeledIkm(es,u),h=this._kdf.buildLabeledInfo(Yo,c,this._kdf.hashSize),d=await this._kdf.extractAndExpand(t,f,h,this._kdf.hashSize);if(this._aead.id===re.ExportOnly)return{aead:this._aead,exporterSecret:d};let m=this._kdf.buildLabeledInfo(Jo,c,this._aead.keySize),k=await this._kdf.extractAndExpand(t,f,m,this._aead.keySize),_=this._kdf.buildLabeledInfo(Xo,c,this._aead.nonceSize),v=await this._kdf.extractAndExpand(t,f,_,this._aead.nonceSize);return{aead:this._aead,exporterSecret:d,key:k,baseNonce:new Uint8Array(v),seq:0}}async _keyScheduleS(e,t,n,i){let o=await this._keySchedule(e,t,i);return o.key===void 0?new ir(this._api,this._kdf,o.exporterSecret,n):new sr(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 nr(this._api,this._kdf,i.exporterSecret):new or(this._api,this._kdf,i)}_validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>8192)throw new te("Too long info");if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new te(`PSK must have at least ${32} bytes`);if(e.psk.key.byteLength>8192)throw new te("Too long psk.key");if(e.psk.id.byteLength>8192)throw new te("Too long psk.id")}}};var Hr=class extends wt{constructor(e){if(typeof e.kem=="number")switch(e.kem){case C.DhkemP256HkdfSha256:e.kem=new Gt;break;case C.DhkemP384HkdfSha384:e.kem=new Ft;break;case C.DhkemP521HkdfSha512:e.kem=new $t;break;case C.DhkemX25519HkdfSha256:e.kem=new Qt;break;case C.DhkemX448HkdfSha512:e.kem=new rr;break;default:throw new te(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(typeof e.kdf=="number")switch(e.kdf){case pe.HkdfSha256:e.kdf=new Ce;break;case pe.HkdfSha384:e.kdf=new rt;break;default:e.kdf=new je;break}if(typeof e.aead=="number")switch(e.aead){case re.Aes128Gcm:e.aead=new Ye;break;case re.Aes256Gcm:e.aead=new We;break;case re.Chacha20Poly1305:e.aead=new Ht;break;default:e.aead=new Je;break}super(e)}};export{Zr as Aead,re as AeadId,Hr as CipherSuite,wt as CipherSuiteNative,kt as DecapError,It as DeriveKeyPairError,Xe as DeserializeError,Et as EncapError,vt as ExportError,ue as HpkeError,te as InvalidParamError,$r as Kdf,pe as KdfId,Fr as Kem,C as KemId,Pt as MessageLimitReachedError,me as NotSupportedError,At as OpenError,St as SealError,_t as SerializeError,Gr as ValidationError}; /*! Bundled license information: @noble/ciphers/esm/utils.js:
Initializes the instance by setting a SubtleCrypto API.
-Basically, you don't need to call this function directly. -This function is called byCipherSuite internally.
-