simple-hpke 0.2.0 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/util.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var Me=Object.defineProperty;var i=(e,t)=>Me(e,"name",{value:t,configurable:!0});var l=(e,t)=>{for(var r in t)Me(e,r,{get:t[r],enumerable:!0})};function Z(e=0){return new Uint8Array(e)}i(Z,"allocUnsafe");var ce={};l(ce,{base10:()=>It});var sn=new Uint8Array(0);function ze(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}i(ze,"equals");function C(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}i(C,"coerce");function Re(e){return new TextEncoder().encode(e)}i(Re,"fromString");function Oe(e){return new TextDecoder().decode(e)}i(Oe,"toString");function vt(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var a=e.charAt(o),s=a.charCodeAt(0);if(r[s]!==255)throw new TypeError(a+" is ambiguous");r[s]=o}var c=e.length,u=e.charAt(0),d=Math.log(c)/Math.log(256),g=Math.log(256)/Math.log(c);function I(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,L=0,x=0,A=f.length;x!==A&&f[x]===0;)x++,y++;for(var U=(A-x)*g+1>>>0,h=new Uint8Array(U);x!==A;){for(var E=f[x],K=0,w=U-1;(E!==0||K<L)&&w!==-1;w--,K++)E+=256*h[w]>>>0,h[w]=E%c>>>0,E=E/c>>>0;if(E!==0)throw new Error("Non-zero carry");L=K,x++}for(var S=U-L;S!==U&&h[S]===0;)S++;for(var W=u.repeat(y);S<U;++S)W+=e.charAt(h[S]);return W}i(I,"encode");function B(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var L=0,x=0;f[y]===u;)L++,y++;for(var A=(f.length-y)*d+1>>>0,U=new Uint8Array(A);f[y];){var h=r[f.charCodeAt(y)];if(h===255)return;for(var E=0,K=A-1;(h!==0||E<x)&&K!==-1;K--,E++)h+=c*U[K]>>>0,U[K]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");x=E,y++}if(f[y]!==" "){for(var w=A-x;w!==A&&U[w]===0;)w++;for(var S=new Uint8Array(L+(A-w)),W=L;w!==A;)S[W++]=U[w++];return S}}}i(B,"decodeUnsafe");function Q(f){var y=B(f);if(y)return y;throw new Error(`Non-${t} character`)}return i(Q,"decode"),{encode:I,decodeUnsafe:B,decode:Q}}i(vt,"base");var St=vt,Ct=St,$e=Ct;var oe=class{static{i(this,"Encoder")}name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ie=class{static{i(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ve(this,t)}},ae=class{static{i(this,"ComposedDecoder")}decoders;constructor(t){this.decoders=t}or(t){return Ve(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ve(e,t){return new ae({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}i(Ve,"or");var se=class{static{i(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new oe(t,r,n),this.decoder=new ie(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function k({name:e,prefix:t,encode:r,decode:n}){return new se(e,t,r,n)}i(k,"from");function P({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=$e(r,e);return k({prefix:t,name:e,encode:n,decode:i(a=>C(o(a)),"decode")})}i(P,"baseX");function Kt(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let a=new Uint8Array(o*r/8|0),s=0,c=0,u=0;for(let d=0;d<o;++d){let g=t[e[d]];if(g===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|g,s+=r,s>=8&&(s-=8,a[u++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return a}i(Kt,"decode");function Pt(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,a="",s=0,c=0;for(let u=0;u<e.length;++u)for(c=c<<8|e[u],s+=8;s>r;)s-=r,a+=t[o&c>>s];if(s!==0&&(a+=t[o&c<<r-s]),n)for(;(a.length*r&7)!==0;)a+="=";return a}i(Pt,"encode");function Dt(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(Dt,"createAlphabetIdx");function p({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Dt(n);return k({prefix:t,name:e,encode(a){return Pt(a,n,r)},decode(a){return Kt(a,o,r,e)}})}i(p,"rfc4648");var It=P({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};l(fe,{base16:()=>Lt,base16upper:()=>Tt});var Lt=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tt=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pe={};l(pe,{base2:()=>Bt});var Bt=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};l(ue,{base256emoji:()=>Rt});var Fe=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),kt=Fe.reduce((e,t,r)=>(e[r]=t,e),[]),Nt=Fe.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Mt(e){return e.reduce((t,r)=>(t+=kt[r],t),"")}i(Mt,"encode");function zt(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Nt[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(zt,"decode");var Rt=k({prefix:"\u{1F680}",name:"base256emoji",encode:Mt,decode:zt});var ye={};l(ye,{base32:()=>N,base32hex:()=>Vt,base32hexpad:()=>Gt,base32hexpadupper:()=>Ht,base32hexupper:()=>Ft,base32pad:()=>_t,base32padupper:()=>$t,base32upper:()=>Ot,base32z:()=>qt});var N=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ot=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_t=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$t=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vt=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ft=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ht=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),qt=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var de={};l(de,{base36:()=>V,base36upper:()=>Xt});var V=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xt=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var he={};l(he,{base58btc:()=>v,base58flickr:()=>jt});var v=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jt=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var le={};l(le,{base64:()=>Jt,base64pad:()=>Qt,base64url:()=>Wt,base64urlpad:()=>Zt});var Jt=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qt=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wt=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Zt=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var me={};l(me,{base8:()=>Yt});var Yt=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var be={};l(be,{identity:()=>er});var er=k({prefix:"\0",name:"identity",encode:i(e=>Oe(e),"encode"),decode:i(e=>Re(e),"decode")});var Pn=new TextEncoder,Dn=new TextDecoder;var we={};l(we,{identity:()=>Er});var nr=qe,Ge=128,or=127,ir=~or,ar=Math.pow(2,31);function qe(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ar;)t[r++]=e&255|Ge,e/=128;for(;e&ir;)t[r++]=e&255|Ge,e>>>=7;return t[r]=e|0,qe.bytes=r-n+1,t}i(qe,"encode");var sr=xe,cr=128,He=127;function xe(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw xe.bytes=0,new RangeError("Could not decode varint");s=e[a++],r+=o<28?(s&He)<<o:(s&He)*Math.pow(2,o),o+=7}while(s>=cr);return xe.bytes=a-n,r}i(xe,"read");var fr=Math.pow(2,7),pr=Math.pow(2,14),ur=Math.pow(2,21),yr=Math.pow(2,28),dr=Math.pow(2,35),hr=Math.pow(2,42),lr=Math.pow(2,49),mr=Math.pow(2,56),br=Math.pow(2,63),xr=i(function(e){return e<fr?1:e<pr?2:e<ur?3:e<yr?4:e<dr?5:e<hr?6:e<lr?7:e<mr?8:e<br?9:10},"length"),wr={encode:nr,decode:sr,encodingLength:xr},gr=wr,F=gr;function G(e,t=0){return[F.decode(e,t),F.decode.bytes]}i(G,"decode");function M(e,t,r=0){return F.encode(e,t,r),t}i(M,"encodeTo");function z(e){return F.encodingLength(e)}i(z,"encodingLength");function O(e,t){let r=t.byteLength,n=z(e),o=n+z(r),a=new Uint8Array(o+r);return M(e,a,0),M(r,a,n),a.set(t,o),new R(e,r,t,a)}i(O,"create");function Xe(e){let t=C(e),[r,n]=G(t),[o,a]=G(t.subarray(n)),s=t.subarray(n+a);if(s.byteLength!==o)throw new Error("Incorrect length");return new R(r,o,s,t)}i(Xe,"decode");function je(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ze(e.bytes,r.bytes)}}i(je,"equals");var R=class{static{i(this,"Digest")}code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Je=0,Ar="identity",Qe=C;function Ur(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return O(Je,Qe(e))}i(Ur,"digest");var Er={code:Je,name:Ar,encode:Qe,digest:Ur};var Ue={};l(Ue,{sha256:()=>Sr,sha512:()=>Cr});var vr=20;function Ae({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new ge(e,t,r,n,o)}i(Ae,"from");var ge=class{static{i(this,"Hasher")}name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,a){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??vr,this.maxDigestLength=a}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?We(n,this.code,r?.truncate):n.then(o=>We(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function We(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return O(t,e)}i(We,"createDigest");function Ye(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}i(Ye,"sha");var Sr=Ae({name:"sha2-256",code:18,encode:Ye("SHA-256")}),Cr=Ae({name:"sha2-512",code:19,encode:Ye("SHA-512")});function et(e,t){let{bytes:r,version:n}=e;return n===0?Pr(r,Ee(e),t??v.encoder):Dr(r,Ee(e),t??N.encoder)}i(et,"format");var tt=new WeakMap;function Ee(e){let t=tt.get(e);if(t==null){let r=new Map;return tt.set(e,r),r}return t}i(Ee,"baseCache");var ee=class e{static{i(this,"CID")}code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==q)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ir)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=O(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&je(t.multihash,n.multihash)}toString(t){return et(this,t)}toJSON(){return{"/":et(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:a,bytes:s}=r;return new e(n,o,a,s??rt(n,o,a.bytes))}else if(r[Lr]===!0){let{version:n,multihash:o,code:a}=r,s=Xe(o);return e.create(n,a,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==q)throw new Error(`Version 0 CID must use dag-pb (code: ${q}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=rt(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,q,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=C(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let a=o.subarray(r.multihashSize-r.digestSize),s=new R(r.multihashCode,r.digestSize,a,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=i(()=>{let[I,B]=G(t.subarray(r));return r+=B,I},"next"),o=n(),a=q;if(o===18?(o=0,r=0):a=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),u=n(),d=r+u,g=d-s;return{version:o,codec:a,multihashCode:c,digestSize:u,multihashSize:g,size:d}}static parse(t,r){let[n,o]=Kr(t,r),a=e.decode(o);if(a.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ee(a).set(n,t),a}};function Kr(e,t){switch(e[0]){case"Q":{let r=t??v;return[v.prefix,r.decode(`${v.prefix}${e}`)]}case v.prefix:{let r=t??v;return[v.prefix,r.decode(e)]}case N.prefix:{let r=t??N;return[N.prefix,r.decode(e)]}case V.prefix:{let r=t??V;return[V.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}i(Kr,"parseCIDtoBytes");function Pr(e,t,r){let{prefix:n}=r;if(n!==v.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let a=r.encode(e).slice(1);return t.set(n,a),a}else return o}i(Pr,"toStringV0");function Dr(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let a=r.encode(e);return t.set(n,a),a}else return o}i(Dr,"toStringV1");var q=112,Ir=18;function rt(e,t,r){let n=z(e),o=n+z(t),a=new Uint8Array(o+r.byteLength);return M(e,a,0),M(t,a,n),a.set(r,o),a}i(rt,"encodeCID");var Lr=Symbol.for("@ipld/js-cid/CID");var ve={...be,...pe,...me,...ce,...fe,...ye,...de,...he,...le,...ue},ao={...Ue,...we};function ot(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}i(ot,"createCodec");var nt=ot("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Se=ot("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Z(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Tr={utf8:nt,"utf-8":nt,hex:ve.base16,latin1:Se,ascii:Se,binary:Se,...ve},te=Tr;function X(e,t="utf8"){let r=te[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}i(X,"fromString");function Ce(e,t="utf8"){let r=te[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}i(Ce,"toString");var it=32,Br=1,kr=2,Ke=32,at=32,j=12,T=32,Pe=16,st=0,De=new TextEncoder().encode("HPKE-v1"),_=2,Ie=m(new TextEncoder().encode("KEM"),D(it,2)),$=m(new TextEncoder().encode("HPKE"),D(it,2),D(Br,2),D(kr,2));var ne=globalThis.crypto.subtle;var No=Object.assign(_r,{raw:Te}),Mo=Object.assign(Be,{asString:lt}),zo=Object.assign(Le,{asString:Nr,fromString:Mr});async function Le(e,t,r){if(t.byteLength<_)throw new Error("malformed message: too short");let n=t[0]<<8|t[1],o=_+n,a=o+j;if(t.byteLength<a+Pe)throw new Error("malformed message: too short");let s=t.slice(_,o),c=t.slice(o,a),u=t.slice(a),d=await Te(e,s,r?.info!==void 0?{info:r.info}:void 0),g=await Or(d),I=await ne.decrypt({name:"AES-GCM",iv:c},g,u);return new Uint8Array(I)}i(Le,"decryptBytes");async function Nr(e,t,r){let n=await Le(e,t,r);return new TextDecoder().decode(n)}i(Nr,"decryptToString");async function Mr(e,t,r){let n=X(t,"base64url"),o=await Le(e,n,r?.info!==void 0?{info:r.info}:void 0);return r?.buffer?o:new TextDecoder().decode(o)}i(Mr,"decryptFromString");function zr(e){if(e!==128&&e!==256)throw new Error(`invalid keysize: ${e} (expected 128 or 256)`)}i(zr,"validateKeysize");function ct(e){if(e.length!==16&&e.length!==32)throw new Error(`invalid aesKey length: ${e.length} bytes (expected 16 or 32)`)}i(ct,"validateRawKeyBytes");function ft(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(ft,"normalizeInfo");async function Rr(e){if(!e.extractable)throw new Error("aesKey must be extractable: its raw bytes are what get sealed");return new Uint8Array(await ne.exportKey("raw",e))}i(Rr,"exportAesKeyBytes");async function pt(e){return ne.importKey("raw",e,{name:"AES-GCM"},!0,["encrypt","decrypt"])}i(pt,"importAesKey");async function Or(e){return ne.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(Or,"importAesKeyDecryptOnly");async function ut(e,t){let r=new Uint8Array(0),n=await J($,r,"psk_id_hash",r),o=await J($,r,"info_hash",t),a=m(new Uint8Array([st]),n,o),s=await J($,e,"secret",r),c=await re($,s,"key",a,at),u=await re($,s,"base_nonce",a,j);return{key:c,baseNonce:u}}i(ut,"keySchedule");async function Te(e,t,r){if(t.byteLength<T+Pe)throw new Error("malformed envelope: too short");let n=ft(r?.info),o=t.slice(0,T),a=t.slice(T),s=await xt(o,e),{key:c,baseNonce:u}=await ut(s,n);return ht(c,u,a)}i(Te,"openRawBytes");async function _r(e,t,r){let n=await Te(e,t,r);return pt(n)}i(_r,"openBytes");async function yt(e,t,r){let n=ft(r?.info),o;if(t instanceof Uint8Array)ct(t),o=t;else if(t)o=await Rr(t),ct(o);else{let Q=r?.size??256;zr(Q),o=globalThis.crypto.getRandomValues(new Uint8Array(Q/8))}let a=await mt(e),{sharedSecret:s,enc:c}=await bt(a),{key:u,baseNonce:d}=await ut(s,n),g=await dt(u,d,o),I=m(c,g),B=await pt(o);return{enc:I,key:B}}i(yt,"encryptKey");var b=globalThis.crypto.subtle;async function dt(e,t,r){let n=await b.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),o=await b.encrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(dt,"aeadSeal");async function ht(e,t,r){let n=await b.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),o=await b.decrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(ht,"aeadOpen");async function Be(e,t,r,n){let o=typeof t=="string"?new TextEncoder().encode(t):t,{enc:a,key:s}=await yt(e,r,n),c=globalThis.crypto.getRandomValues(new Uint8Array(j)),u=new Uint8Array(await b.encrypt({name:"AES-GCM",iv:c},s,o));return m(D(a.length,_),a,c,u)}i(Be,"encryptBytes");async function lt(e,t,r,n){let o=await Be(e,t,r,n);return Ce(o,n?.encoding??"base64url")}i(lt,"encryptToString");async function gt(e,t){let r=await b.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return new Uint8Array(await b.sign("HMAC",r,t))}i(gt,"hmac");async function $r(e,t){let r=e.length===0?new Uint8Array(Ke):e;return gt(r,t)}i($r,"extract");async function Vr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await gt(e,m(o,t,D(s,1)));let c=Math.min(o.length,r-a);n.set(o.subarray(0,c),a),a+=c,s++}return n}i(Vr,"expand");async function J(e,t,r,n){let o=m(De,e,new TextEncoder().encode(r),n);return $r(t,o)}i(J,"labeledExtract");async function re(e,t,r,n,o){let a=m(D(o,2),De,e,new TextEncoder().encode(r),n);return Vr(t,a,o)}i(re,"labeledExpand");async function ke(e){return new Uint8Array(await b.exportKey("raw",e))}i(ke,"exportRawPublic");async function wt(e){if(e.length!==T)throw new Error(`invalid public key length: ${e.length} bytes (expected ${T})`);return b.importKey("raw",e,{name:"X25519"},!0,[])}i(wt,"importRawPublic");async function mt(e){if(e instanceof Uint8Array)return wt(e);if(e instanceof CryptoKey){if(e.type!=="public")throw new Error("recipient CryptoKey must be a public key");return Ne(e,"recipient CryptoKey"),e}if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e;return wt(X(r,n??"base64url"))}let t=e;if(t.publicKey instanceof CryptoKey){if(t.publicKey.type!=="public")throw new Error("recipient keypair publicKey must be a public key");return Ne(t.publicKey,"recipient keypair publicKey"),t.publicKey}throw new Error("unrecognized recipient key form")}i(mt,"resolveRecipientPublicKey");function Ne(e,t){if(e.algorithm.name!=="X25519")throw new Error(`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Ne,"assertX25519Algorithm");async function At(e,t){let r=await b.deriveBits({name:"X25519",public:t},e,256),n=new Uint8Array(r);if(n.every(o=>o===0))throw new Error("X25519 shared secret is all-zero (small-order public key?)");return n}i(At,"dh");async function Ut(e,t){let r=await J(Ie,new Uint8Array(0),"eae_prk",e);return re(Ie,r,"shared_secret",t,Ke)}i(Ut,"extractAndExpand");async function bt(e){let t=await b.generateKey({name:"X25519"},!1,["deriveBits"]),r=await At(t.privateKey,e),n=await ke(t.publicKey),o=await ke(e),a=m(n,o);return{sharedSecret:await Ut(r,a),enc:n}}i(bt,"encap");async function xt(e,t){if(t.privateKey.type!=="private")throw new Error("keypair.privateKey must be a private key");Ne(t.privateKey,"keypair.privateKey");let r=await b.importKey("raw",e,{name:"X25519"},!1,[]),n=await At(t.privateKey,r),o=await ke(t.publicKey),a=m(e,o);return Ut(n,a)}i(xt,"decap");function D(e,t){let r=new Uint8Array(t),n=e;for(let o=t-1;o>=0;o--)r[o]=n&255,n=Math.floor(n/256);return r}i(D,"i2osp");function m(...e){let t=0;for(let o of e)t+=o.length;let r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}i(m,"concat");export{ht as aeadOpen,dt as aeadSeal,m as concat,xt as decap,bt as encap,Be as encryptBytes,lt as encryptToString,gt as hmac,D as i2osp,re as labeledExpand,J as labeledExtract,mt as resolveRecipientPublicKey};
1
+ var Be=Object.defineProperty;var i=(e,t)=>Be(e,"name",{value:t,configurable:!0});var w=(e,t)=>{for(var r in t)Be(e,r,{get:t[r],enumerable:!0})};function Z(e=0){return new Uint8Array(e)}i(Z,"allocUnsafe");var ue={};w(ue,{base10:()=>Tt});var dn=new Uint8Array(0);function Ve(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}i(Ve,"equals");function K(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}i(K,"coerce");function Oe(e){return new TextEncoder().encode(e)}i(Oe,"fromString");function ze(e){return new TextDecoder().decode(e)}i(ze,"toString");function Rt(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var a=e.charAt(o),s=a.charCodeAt(0);if(r[s]!==255)throw new TypeError(a+" is ambiguous");r[s]=o}var c=e.length,y=e.charAt(0),m=Math.log(c)/Math.log(256),E=Math.log(256)/Math.log(c);function C(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,P=0,x=0,A=p.length;x!==A&&p[x]===0;)x++,h++;for(var U=(A-x)*E+1>>>0,b=new Uint8Array(U);x!==A;){for(var v=p[x],_=0,g=U-1;(v!==0||_<P)&&g!==-1;g--,_++)v+=256*b[g]>>>0,b[g]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");P=_,x++}for(var I=U-P;I!==U&&b[I]===0;)I++;for(var W=y.repeat(h);I<U;++I)W+=e.charAt(b[I]);return W}i(C,"encode");function R(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var P=0,x=0;p[h]===y;)P++,h++;for(var A=(p.length-h)*m+1>>>0,U=new Uint8Array(A);p[h];){var b=r[p.charCodeAt(h)];if(b===255)return;for(var v=0,_=A-1;(b!==0||v<x)&&_!==-1;_--,v++)b+=c*U[_]>>>0,U[_]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");x=v,h++}if(p[h]!==" "){for(var g=A-x;g!==A&&U[g]===0;)g++;for(var I=new Uint8Array(P+(A-g)),W=P;g!==A;)I[W++]=U[g++];return I}}}i(R,"decodeUnsafe");function Q(p){var h=R(p);if(h)return h;throw new Error(`Non-${t} character`)}return i(Q,"decode"),{encode:C,decodeUnsafe:R,decode:Q}}i(Rt,"base");var _t=Rt,Dt=_t,Ge=Dt;var se=class{static{i(this,"Encoder")}name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},ce=class{static{i(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ye(this,t)}},fe=class{static{i(this,"ComposedDecoder")}decoders;constructor(t){this.decoders=t}or(t){return Ye(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ye(e,t){return new fe({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}i(Ye,"or");var pe=class{static{i(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new se(t,r,n),this.decoder=new ce(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function T({name:e,prefix:t,encode:r,decode:n}){return new pe(e,t,r,n)}i(T,"from");function D({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ge(r,e);return T({prefix:t,name:e,encode:n,decode:i(a=>K(o(a)),"decode")})}i(D,"baseX");function Lt(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let a=new Uint8Array(o*r/8|0),s=0,c=0,y=0;for(let m=0;m<o;++m){let E=t[e[m]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|E,s+=r,s>=8&&(s-=8,a[y++]=255&c>>s)}if(s>=r||(255&c<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return a}i(Lt,"decode");function Pt(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,a="",s=0,c=0;for(let y=0;y<e.length;++y)for(c=c<<8|e[y],s+=8;s>r;)s-=r,a+=t[o&c>>s];if(s!==0&&(a+=t[o&c<<r-s]),n)for(;(a.length*r&7)!==0;)a+="=";return a}i(Pt,"encode");function Nt(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(Nt,"createAlphabetIdx");function u({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Nt(n);return T({prefix:t,name:e,encode(a){return Pt(a,n,r)},decode(a){return Lt(a,o,r,e)}})}i(u,"rfc4648");var Tt=D({prefix:"9",name:"base10",alphabet:"0123456789"});var ye={};w(ye,{base16:()=>kt,base16upper:()=>Mt});var kt=u({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mt=u({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var de={};w(de,{base2:()=>Bt});var Bt=u({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var he={};w(he,{base256emoji:()=>Gt});var Fe=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vt=Fe.reduce((e,t,r)=>(e[r]=t,e),[]),Ot=Fe.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function zt(e){return e.reduce((t,r)=>(t+=Vt[r],t),"")}i(zt,"encode");function Ht(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ot[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(Ht,"decode");var Gt=T({prefix:"\u{1F680}",name:"base256emoji",encode:zt,decode:Ht});var le={};w(le,{base32:()=>k,base32hex:()=>qt,base32hexpad:()=>jt,base32hexpadupper:()=>Jt,base32hexupper:()=>Xt,base32pad:()=>Ft,base32padupper:()=>$t,base32upper:()=>Yt,base32z:()=>Qt});var k=u({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yt=u({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ft=u({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$t=u({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qt=u({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xt=u({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),jt=u({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jt=u({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qt=u({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var me={};w(me,{base36:()=>G,base36upper:()=>Wt});var G=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wt=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var be={};w(be,{base58btc:()=>S,base58flickr:()=>Zt});var S=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zt=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var we={};w(we,{base64:()=>er,base64pad:()=>tr,base64url:()=>rr,base64urlpad:()=>nr});var er=u({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tr=u({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rr=u({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nr=u({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xe={};w(xe,{base8:()=>or});var or=u({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ge={};w(ge,{identity:()=>ir});var ir=T({prefix:"\0",name:"identity",encode:i(e=>ze(e),"encode"),decode:i(e=>Oe(e),"decode")});var Nn=new TextEncoder,Tn=new TextDecoder;var Ae={};w(Ae,{identity:()=>Kr});var cr=Xe,$e=128,fr=127,pr=~fr,ur=Math.pow(2,31);function Xe(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ur;)t[r++]=e&255|$e,e/=128;for(;e&pr;)t[r++]=e&255|$e,e>>>=7;return t[r]=e|0,Xe.bytes=r-n+1,t}i(Xe,"encode");var yr=Ee,dr=128,qe=127;function Ee(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw Ee.bytes=0,new RangeError("Could not decode varint");s=e[a++],r+=o<28?(s&qe)<<o:(s&qe)*Math.pow(2,o),o+=7}while(s>=dr);return Ee.bytes=a-n,r}i(Ee,"read");var hr=Math.pow(2,7),lr=Math.pow(2,14),mr=Math.pow(2,21),br=Math.pow(2,28),wr=Math.pow(2,35),xr=Math.pow(2,42),gr=Math.pow(2,49),Er=Math.pow(2,56),Ar=Math.pow(2,63),Ur=i(function(e){return e<hr?1:e<lr?2:e<mr?3:e<br?4:e<wr?5:e<xr?6:e<gr?7:e<Er?8:e<Ar?9:10},"length"),vr={encode:cr,decode:yr,encodingLength:Ur},Sr=vr,Y=Sr;function F(e,t=0){return[Y.decode(e,t),Y.decode.bytes]}i(F,"decode");function M(e,t,r=0){return Y.encode(e,t,r),t}i(M,"encodeTo");function B(e){return Y.encodingLength(e)}i(B,"encodingLength");function O(e,t){let r=t.byteLength,n=B(e),o=n+B(r),a=new Uint8Array(o+r);return M(e,a,0),M(r,a,n),a.set(t,o),new V(e,r,t,a)}i(O,"create");function je(e){let t=K(e),[r,n]=F(t),[o,a]=F(t.subarray(n)),s=t.subarray(n+a);if(s.byteLength!==o)throw new Error("Incorrect length");return new V(r,o,s,t)}i(je,"decode");function Je(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ve(e.bytes,r.bytes)}}i(Je,"equals");var V=class{static{i(this,"Digest")}code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Qe=0,Cr="identity",We=K;function Ir(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return O(Qe,We(e))}i(Ir,"digest");var Kr={code:Qe,name:Cr,encode:We,digest:Ir};var Se={};w(Se,{sha256:()=>_r,sha512:()=>Dr});var Rr=20;function ve({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ue(e,t,r,n,o)}i(ve,"from");var Ue=class{static{i(this,"Hasher")}name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,a){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Rr,this.maxDigestLength=a}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ze(n,this.code,r?.truncate):n.then(o=>Ze(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ze(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return O(t,e)}i(Ze,"createDigest");function tt(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}i(tt,"sha");var _r=ve({name:"sha2-256",code:18,encode:tt("SHA-256")}),Dr=ve({name:"sha2-512",code:19,encode:tt("SHA-512")});function rt(e,t){let{bytes:r,version:n}=e;return n===0?Pr(r,Ce(e),t??S.encoder):Nr(r,Ce(e),t??k.encoder)}i(rt,"format");var nt=new WeakMap;function Ce(e){let t=nt.get(e);if(t==null){let r=new Map;return nt.set(e,r),r}return t}i(Ce,"baseCache");var te=class e{static{i(this,"CID")}code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==q)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Tr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=O(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Je(t.multihash,n.multihash)}toString(t){return rt(this,t)}toJSON(){return{"/":rt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:a,bytes:s}=r;return new e(n,o,a,s??ot(n,o,a.bytes))}else if(r[kr]===!0){let{version:n,multihash:o,code:a}=r,s=je(o);return e.create(n,a,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==q)throw new Error(`Version 0 CID must use dag-pb (code: ${q}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ot(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,q,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=K(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let a=o.subarray(r.multihashSize-r.digestSize),s=new V(r.multihashCode,r.digestSize,a,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=i(()=>{let[C,R]=F(t.subarray(r));return r+=R,C},"next"),o=n(),a=q;if(o===18?(o=0,r=0):a=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,c=n(),y=n(),m=r+y,E=m-s;return{version:o,codec:a,multihashCode:c,digestSize:y,multihashSize:E,size:m}}static parse(t,r){let[n,o]=Lr(t,r),a=e.decode(o);if(a.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ce(a).set(n,t),a}};function Lr(e,t){switch(e[0]){case"Q":{let r=t??S;return[S.prefix,r.decode(`${S.prefix}${e}`)]}case S.prefix:{let r=t??S;return[S.prefix,r.decode(e)]}case k.prefix:{let r=t??k;return[k.prefix,r.decode(e)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}i(Lr,"parseCIDtoBytes");function Pr(e,t,r){let{prefix:n}=r;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let a=r.encode(e).slice(1);return t.set(n,a),a}else return o}i(Pr,"toStringV0");function Nr(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let a=r.encode(e);return t.set(n,a),a}else return o}i(Nr,"toStringV1");var q=112,Tr=18;function ot(e,t,r){let n=B(e),o=n+B(t),a=new Uint8Array(o+r.byteLength);return M(e,a,0),M(t,a,n),a.set(r,o),a}i(ot,"encodeCID");var kr=Symbol.for("@ipld/js-cid/CID");var Ie={...ge,...de,...xe,...ue,...ye,...le,...me,...be,...we,...he},yo={...Se,...Ae};function at(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}i(at,"createCodec");var it=at("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Ke=at("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Z(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Mr={utf8:it,"utf-8":it,hex:Ie.base16,latin1:Ke,ascii:Ke,binary:Ke,...Ie},re=Mr;function X(e,t="utf8"){let r=re[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}i(X,"fromString");function ne(e,t="utf8"){let r=re[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}i(ne,"toString");var f=class extends Error{static{i(this,"HpkeError")}code;constructor(t,r,n){super(r,n),this.name="HpkeError",this.code=t}};var st=32,Br=1,Vr=2,Re=32,ct=32,j=12,N=32,_e=16,ft=0,De=new TextEncoder().encode("HPKE-v1"),z=2,Le=l(new TextEncoder().encode("KEM"),L(st,2)),H=l(new TextEncoder().encode("HPKE"),L(st,2),L(Br,2),L(Vr,2)),oe=new TextEncoder().encode("simple-hpke/keyId/v1"),pt=12;var ae=globalThis.crypto.subtle;var Yo=Object.assign(Fr,{raw:Ne}),Fo=Object.assign(Te,{asString:wt}),$o=Object.assign(Pe,{asString:Or,fromString:zr});async function Pe(e,t,r){if(t.byteLength<z)throw new f("ERR_MALFORMED_MESSAGE","malformed message: too short");let n=t[0]<<8|t[1],o=z+n,a=o+j;if(t.byteLength<a+_e)throw new f("ERR_MALFORMED_MESSAGE","malformed message: too short");let s=t.slice(z,o),c=t.slice(o,a),y=t.slice(a),m=await Ne(e,s,r?.info!==void 0?{info:r.info}:void 0),E=await Yr(m),C;try{C=await ae.decrypt({name:"AES-GCM",iv:c},E,y)}catch(R){throw new f("ERR_DECRYPT_FAILED","failed to decrypt the message: tampered ciphertext",{cause:R})}return new Uint8Array(C)}i(Pe,"decryptBytes");async function Or(e,t,r){let n=await Pe(e,t,r);return new TextDecoder().decode(n)}i(Or,"decryptToString");async function zr(e,t,r){let n;try{n=X(t,"base64url")}catch(a){throw new f("ERR_MALFORMED_MESSAGE","malformed message: not base64url",{cause:a})}let o=await Pe(e,n,r?.info!==void 0?{info:r.info}:void 0);return r?.buffer?o:new TextDecoder().decode(o)}i(zr,"decryptFromString");function Hr(e){if(e!==128&&e!==256)throw new f("ERR_INVALID_KEYSIZE",`invalid keysize: ${e} (expected 128 or 256)`)}i(Hr,"validateKeysize");function ut(e){if(e.length!==16&&e.length!==32)throw new f("ERR_INVALID_AES_KEY",`invalid aesKey length: ${e.length} bytes (expected 16 or 32)`)}i(ut,"validateRawKeyBytes");function yt(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(yt,"normalizeInfo");async function Gr(e){if(!e.extractable)throw new f("ERR_INVALID_AES_KEY","aesKey must be extractable: its raw bytes are what get sealed");return new Uint8Array(await ae.exportKey("raw",e))}i(Gr,"exportAesKeyBytes");async function dt(e,t){return ae.importKey("raw",e,{name:"AES-GCM"},t,["encrypt","decrypt"])}i(dt,"importAesKey");async function Yr(e){return ae.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(Yr,"importAesKeyDecryptOnly");async function ht(e,t){let r=new Uint8Array(0),n=await J(H,r,"psk_id_hash",r),o=await J(H,r,"info_hash",t),a=l(new Uint8Array([ft]),n,o),s=await J(H,e,"secret",r),c=await ie(H,s,"key",a,ct),y=await ie(H,s,"base_nonce",a,j);return{key:c,baseNonce:y}}i(ht,"keySchedule");async function Ne(e,t,r){if(t.byteLength<N+_e)throw new f("ERR_MALFORMED_ENVELOPE","malformed envelope: too short");let n=yt(r?.info),o=t.slice(0,N),a=t.slice(N),s=await Et(o,e),{key:c,baseNonce:y}=await ht(s,n);return bt(c,y,a)}i(Ne,"openRawBytes");async function Fr(e,t,r){let n=await Ne(e,t,r);return dt(n,r?.extractable??!1)}i(Fr,"openBytes");async function lt(e,t,r){let n=yt(r?.info),o;if(t instanceof Uint8Array)ut(t),o=t;else if(t){if(t.algorithm.name!=="AES-GCM")throw new f("ERR_INVALID_AES_KEY","aesKey must be an AES-GCM key, got "+t.algorithm.name);o=await Gr(t),ut(o)}else{let Q=r?.size??256;Hr(Q),o=globalThis.crypto.getRandomValues(new Uint8Array(Q/8))}let a=await xt(e),{sharedSecret:s,enc:c}=await gt(a),{key:y,baseNonce:m}=await ht(s,n),E=await mt(y,m,o),C=l(c,E);if(t instanceof CryptoKey)return{wrapped:C,key:t};let R=await dt(o,r?.extractable??!1);return{wrapped:C,key:R}}i(lt,"encryptKey");var d=globalThis.crypto.subtle;async function mt(e,t,r){let n=await d.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),o=await d.encrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(mt,"aeadSeal");async function bt(e,t,r){let n=await d.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),o;try{o=await d.decrypt({name:"AES-GCM",iv:t},n,r)}catch(a){throw new f("ERR_DECRYPT_FAILED","failed to decrypt the wrapped key: wrong keypair, wrong info, or a tampered envelope",{cause:a})}return new Uint8Array(o)}i(bt,"aeadOpen");async function Te(e,t,r,n){if(r instanceof CryptoKey&&!r.usages.includes("encrypt"))throw new f("ERR_INVALID_AES_KEY",'aesKey is missing the "encrypt" usage, which encrypt needs to encrypt the message');let o=typeof t=="string"?new TextEncoder().encode(t):t,{wrapped:a,key:s}=await lt(e,r,n),c=globalThis.crypto.getRandomValues(new Uint8Array(j)),y=new Uint8Array(await d.encrypt({name:"AES-GCM",iv:c},s,o));return l(L(a.length,z),a,c,y)}i(Te,"encryptBytes");async function wt(e,t,r,n){let o=await Te(e,t,r,n);return ne(o,n?.encoding??"base64url")}i(wt,"encryptToString");async function St(e,t){let r=await d.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return new Uint8Array(await d.sign("HMAC",r,t))}i(St,"hmac");async function qr(e,t){let r=e.length===0?new Uint8Array(Re):e;return St(r,t)}i(qr,"extract");async function Xr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await St(e,l(o,t,L(s,1)));let c=Math.min(o.length,r-a);n.set(o.subarray(0,c),a),a+=c,s++}return n}i(Xr,"expand");async function J(e,t,r,n){let o=l(De,e,new TextEncoder().encode(r),n);return qr(t,o)}i(J,"labeledExtract");async function ie(e,t,r,n,o){let a=l(L(o,2),De,e,new TextEncoder().encode(r),n);return Xr(t,a,o)}i(ie,"labeledExpand");async function ke(e){return new Uint8Array(await d.exportKey("raw",e))}i(ke,"exportRawPublic");async function Ut(e){if(e.length!==N)throw new f("ERR_INVALID_RECIPIENT_KEY",`invalid public key length: ${e.length} bytes (expected ${N})`);return d.importKey("raw",e,{name:"X25519"},!0,[])}i(Ut,"importRawPublic");async function xt(e){if(e instanceof Uint8Array)return Ut(e);if(e instanceof CryptoKey)return vt(e,"recipient CryptoKey");if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e,o;try{o=X(r,n??"base64url")}catch(a){throw new f("ERR_INVALID_RECIPIENT_KEY",`recipient publicKey string does not decode as ${n??"base64url"}`,{cause:a})}return Ut(o)}let t=e;if(t.publicKey instanceof CryptoKey)return vt(t.publicKey,"recipient keypair publicKey");throw new f("ERR_INVALID_RECIPIENT_KEY","unrecognized recipient key form")}i(xt,"resolveRecipientPublicKey");function vt(e,t){if(e.type!=="public")throw new f("ERR_INVALID_RECIPIENT_KEY",`${t} must be a public key`);if(Me(e,t,"ERR_INVALID_RECIPIENT_KEY"),!e.extractable)throw new f("ERR_INVALID_RECIPIENT_KEY",`${t} must be extractable (the KEM exports it)`);return e}i(vt,"assertRecipientPublicKey");function Me(e,t,r){if(e.algorithm.name!=="X25519")throw new f(r,`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Me,"assertX25519Algorithm");async function Ct(e,t){let r;try{r=await d.deriveBits({name:"X25519",public:t},e,256)}catch(o){throw o?.name==="OperationError"?new f("ERR_SMALL_ORDER_KEY","X25519 deriveBits rejected a small-order public key",{cause:o}):o}let n=new Uint8Array(r);if(n.every(o=>o===0))throw new f("ERR_SMALL_ORDER_KEY","X25519 shared secret is all-zero (small-order public key?)");return n}i(Ct,"dh");async function It(e,t){let r=await J(Le,new Uint8Array(0),"eae_prk",e);return ie(Le,r,"shared_secret",t,Re)}i(It,"extractAndExpand");async function gt(e){let t=await d.generateKey({name:"X25519"},!1,["deriveBits"]),r=await Ct(t.privateKey,e),n=await ke(t.publicKey),o=await ke(e),a=l(n,o);return{sharedSecret:await It(r,a),enc:n}}i(gt,"encap");async function Et(e,t){if(t.privateKey.type!=="private")throw new f("ERR_INVALID_KEYPAIR","keypair.privateKey must be a private key");if(Me(t.privateKey,"keypair.privateKey","ERR_INVALID_KEYPAIR"),!t.privateKey.usages.includes("deriveBits"))throw new f("ERR_INVALID_KEYPAIR","keypair.privateKey must have the deriveBits usage");if(t.publicKey.type!=="public"||!t.publicKey.extractable)throw new f("ERR_INVALID_KEYPAIR","keypair.publicKey must be an extractable public key");Me(t.publicKey,"keypair.publicKey","ERR_INVALID_KEYPAIR");let r=await d.importKey("raw",e,{name:"X25519"},!1,[]),n=await Ct(t.privateKey,r),o=await ke(t.publicKey),a=l(e,o);return It(n,a)}i(Et,"decap");async function At(e){if(e.algorithm.name!=="AES-GCM")throw new f("ERR_INVALID_AES_KEY",`keyId needs an AES-GCM key (got ${e.algorithm.name})`);if(!e.usages.includes("encrypt"))throw new f("ERR_INVALID_AES_KEY","keyId needs a key with the 'encrypt' usage");let r=new Uint8Array(await d.digest("SHA-256",oe)).slice(0,pt),n=new Uint8Array(await d.encrypt({name:"AES-GCM",iv:r},e,oe)),o=await d.digest("SHA-256",l(oe,n));return ne(new Uint8Array(o),"base64url")}i(At,"keyId");async function $r(e,t){let r=await At(e);if(r.length!==t.length)return!1;let n=0;for(let o=0;o<r.length;o++)n|=r.charCodeAt(o)^t.charCodeAt(o);return n===0}i($r,"verifyKeyId");function L(e,t){let r=new Uint8Array(t),n=e;for(let o=t-1;o>=0;o--)r[o]=n&255,n=Math.floor(n/256);return r}i(L,"i2osp");function l(...e){let t=0;for(let o of e)t+=o.length;let r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}i(l,"concat");export{bt as aeadOpen,mt as aeadSeal,l as concat,Et as decap,gt as encap,Te as encryptBytes,wt as encryptToString,St as hmac,L as i2osp,At as keyId,ie as labeledExpand,J as labeledExtract,xt as resolveRecipientPublicKey,$r as verifyKeyId};
2
2
  //# sourceMappingURL=util.min.js.map