simple-hpke 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var ke=Object.defineProperty;var i=(e,t)=>ke(e,"name",{value:t,configurable:!0});var m=(e,t)=>{for(var r in t)ke(e,r,{get:t[r],enumerable:!0})};function H(e=0){return new Uint8Array(e)}i(H,"allocUnsafe");var ie={};m(ie,{base10:()=>gt});var an=new Uint8Array(0);function Ie(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(Ie,"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 Be(e){return new TextEncoder().encode(e)}i(Be,"fromString");function Le(e){return new TextDecoder().decode(e)}i(Le,"toString");function ht(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),h=Math.log(c)/Math.log(256),x=Math.log(256)/Math.log(c);function D(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 d=0,k=0,b=0,g=f.length;b!==g&&f[b]===0;)b++,d++;for(var A=(g-b)*x+1>>>0,l=new Uint8Array(A);b!==g;){for(var U=f[b],K=0,w=A-1;(U!==0||K<k)&&w!==-1;w--,K++)U+=256*l[w]>>>0,l[w]=U%c>>>0,U=U/c>>>0;if(U!==0)throw new Error("Non-zero carry");k=K,b++}for(var S=A-k;S!==A&&l[S]===0;)S++;for(var _=u.repeat(d);S<A;++S)_+=e.charAt(l[S]);return _}i(D,"encode");function B(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var d=0;if(f[d]!==" "){for(var k=0,b=0;f[d]===u;)k++,d++;for(var g=(f.length-d)*h+1>>>0,A=new Uint8Array(g);f[d];){var l=r[f.charCodeAt(d)];if(l===255)return;for(var U=0,K=g-1;(l!==0||U<b)&&K!==-1;K--,U++)l+=c*A[K]>>>0,A[K]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");b=U,d++}if(f[d]!==" "){for(var w=g-b;w!==g&&A[w]===0;)w++;for(var S=new Uint8Array(k+(g-w)),_=k;w!==g;)S[_++]=A[w++];return S}}}i(B,"decodeUnsafe");function X(f){var d=B(f);if(d)return d;throw new Error(`Non-${t} character`)}return i(X,"decode"),{encode:D,decodeUnsafe:B,decode:X}}i(ht,"base");var lt=ht,mt=lt,Me=mt;var te=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")}},re=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 ze(this,t)}},ne=class{static{i(this,"ComposedDecoder")}decoders;constructor(t){this.decoders=t}or(t){return ze(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 ze(e,t){return new ne({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}i(ze,"or");var oe=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 te(t,r,n),this.decoder=new re(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function L({name:e,prefix:t,encode:r,decode:n}){return new oe(e,t,r,n)}i(L,"from");function P({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Me(r,e);return L({prefix:t,name:e,encode:n,decode:i(a=>C(o(a)),"decode")})}i(P,"baseX");function bt(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 h=0;h<o;++h){let x=t[e[h]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|x,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(bt,"decode");function wt(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(wt,"encode");function xt(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(xt,"createAlphabetIdx");function p({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=xt(n);return L({prefix:t,name:e,encode(a){return wt(a,n,r)},decode(a){return bt(a,o,r,e)}})}i(p,"rfc4648");var gt=P({prefix:"9",name:"base10",alphabet:"0123456789"});var ae={};m(ae,{base16:()=>At,base16upper:()=>Ut});var At=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ut=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var se={};m(se,{base2:()=>vt});var vt=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ce={};m(ce,{base256emoji:()=>Pt});var Ne=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}"),Et=Ne.reduce((e,t,r)=>(e[r]=t,e),[]),St=Ne.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ct(e){return e.reduce((t,r)=>(t+=Et[r],t),"")}i(Ct,"encode");function Kt(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=St[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(Kt,"decode");var Pt=L({prefix:"\u{1F680}",name:"base256emoji",encode:Ct,decode:Kt});var fe={};m(fe,{base32:()=>T,base32hex:()=>Bt,base32hexpad:()=>Tt,base32hexpadupper:()=>Mt,base32hexupper:()=>Lt,base32pad:()=>kt,base32padupper:()=>It,base32upper:()=>Dt,base32z:()=>zt});var T=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Dt=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kt=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),It=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Bt=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lt=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mt=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zt=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pe={};m(pe,{base36:()=>$,base36upper:()=>Nt});var $=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nt=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ue={};m(ue,{base58btc:()=>v,base58flickr:()=>Ot});var v=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ot=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ye={};m(ye,{base64:()=>$t,base64pad:()=>Rt,base64url:()=>Vt,base64urlpad:()=>Ft});var $t=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Rt=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vt=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ft=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var de={};m(de,{base8:()=>qt});var qt=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var he={};m(he,{identity:()=>Gt});var Gt=L({prefix:"\0",name:"identity",encode:i(e=>Le(e),"encode"),decode:i(e=>Be(e),"decode")});var Kn=new TextEncoder,Pn=new TextDecoder;var me={};m(me,{identity:()=>dr});var _t=Re,Oe=128,Ht=127,Jt=~Ht,Qt=Math.pow(2,31);function Re(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Qt;)t[r++]=e&255|Oe,e/=128;for(;e&Jt;)t[r++]=e&255|Oe,e>>>=7;return t[r]=e|0,Re.bytes=r-n+1,t}i(Re,"encode");var Wt=le,Zt=128,$e=127;function le(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw le.bytes=0,new RangeError("Could not decode varint");s=e[a++],r+=o<28?(s&$e)<<o:(s&$e)*Math.pow(2,o),o+=7}while(s>=Zt);return le.bytes=a-n,r}i(le,"read");var Yt=Math.pow(2,7),er=Math.pow(2,14),tr=Math.pow(2,21),rr=Math.pow(2,28),nr=Math.pow(2,35),or=Math.pow(2,42),ir=Math.pow(2,49),ar=Math.pow(2,56),sr=Math.pow(2,63),cr=i(function(e){return e<Yt?1:e<er?2:e<tr?3:e<rr?4:e<nr?5:e<or?6:e<ir?7:e<ar?8:e<sr?9:10},"length"),fr={encode:_t,decode:Wt,encodingLength:cr},pr=fr,R=pr;function V(e,t=0){return[R.decode(e,t),R.decode.bytes]}i(V,"decode");function M(e,t,r=0){return R.encode(e,t,r),t}i(M,"encodeTo");function z(e){return R.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 N(e,r,t,a)}i(O,"create");function Ve(e){let t=C(e),[r,n]=V(t),[o,a]=V(t.subarray(n)),s=t.subarray(n+a);if(s.byteLength!==o)throw new Error("Incorrect length");return new N(r,o,s,t)}i(Ve,"decode");function Fe(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ie(e.bytes,r.bytes)}}i(Fe,"equals");var N=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,ur="identity",Ge=C;function yr(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,Ge(e))}i(yr,"digest");var dr={code:qe,name:ur,encode:Ge,digest:yr};var xe={};m(xe,{sha256:()=>lr,sha512:()=>mr});var hr=20;function we({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new be(e,t,r,n,o)}i(we,"from");var be=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??hr,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?je(n,this.code,r?.truncate):n.then(o=>je(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function je(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(je,"createDigest");function _e(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}i(_e,"sha");var lr=we({name:"sha2-256",code:18,encode:_e("SHA-256")}),mr=we({name:"sha2-512",code:19,encode:_e("SHA-512")});function He(e,t){let{bytes:r,version:n}=e;return n===0?wr(r,ge(e),t??v.encoder):xr(r,ge(e),t??T.encoder)}i(He,"format");var Je=new WeakMap;function ge(e){let t=Je.get(e);if(t==null){let r=new Map;return Je.set(e,r),r}return t}i(ge,"baseCache");var Q=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!==gr)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&&Fe(t.multihash,n.multihash)}toString(t){return He(this,t)}toJSON(){return{"/":He(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??Qe(n,o,a.bytes))}else if(r[Ar]===!0){let{version:n,multihash:o,code:a}=r,s=Ve(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=Qe(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 N(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[D,B]=V(t.subarray(r));return r+=B,D},"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(),h=r+u,x=h-s;return{version:o,codec:a,multihashCode:c,digestSize:u,multihashSize:x,size:h}}static parse(t,r){let[n,o]=br(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 ge(a).set(n,t),a}};function br(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 T.prefix:{let r=t??T;return[T.prefix,r.decode(e)]}case $.prefix:{let r=t??$;return[$.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(br,"parseCIDtoBytes");function wr(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(wr,"toStringV0");function xr(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(xr,"toStringV1");var q=112,gr=18;function Qe(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(Qe,"encodeCID");var Ar=Symbol.for("@ipld/js-cid/CID");var Ae={...he,...se,...de,...ie,...ae,...fe,...pe,...ue,...ye,...ce},io={...xe,...me};function Ze(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}i(Ze,"createCodec");var We=Ze("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Ue=Ze("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=H(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ur={utf8:We,"utf-8":We,hex:Ae.base16,latin1:Ue,ascii:Ue,binary:Ue,...Ae},W=Ur;function Z(e,t="utf8"){let r=W[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}i(Z,"fromString");function ve(e,t="utf8"){let r=W[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}i(ve,"toString");var y=globalThis.crypto.subtle,rt=32,vr=1,Er=2,nt=32,Sr=32,Ke=12,j=32,ot=16,Cr=0,it=new TextEncoder().encode("HPKE-v1"),Ye=E(new TextEncoder().encode("KEM"),I(rt,2)),G=E(new TextEncoder().encode("HPKE"),I(rt,2),I(vr,2),I(Er,2));async function Kr(e,t,r){let n=at(r?.info),o;if(t instanceof Uint8Array)et(t),o=t;else if(t)o=await Br(t),et(o);else{let X=r?.keysize??256;Ir(X),o=globalThis.crypto.getRandomValues(new Uint8Array(X/8))}let a=await zr(e),{sharedSecret:s,enc:c}=await Nr(a),{key:u,baseNonce:h}=await ut(s,n),x=await $r(u,h,o),D=E(c,x),B=await st(o);return{wrapped:D,key:B}}i(Kr,"seal");async function Pr(e,t,r){let n=await Pe(e,t,r);return st(n)}i(Pr,"openBytes");async function Pe(e,t,r){if(t.byteLength<j+ot)throw new Error("malformed envelope: too short");let n=at(r?.info),o=t.slice(0,j),a=t.slice(j),s=await Or(o,e),{key:c,baseNonce:u}=await ut(s,n);return Rr(c,u,a)}i(Pe,"openRawBytes");var ko=Object.assign(Pr,{raw:Pe}),Y=2,Io=Object.assign(yt,{asString:Vr}),Bo=Object.assign(De,{asString:Dr,fromString:kr});async function De(e,t,r){if(t.byteLength<Y)throw new Error("malformed message: too short");let n=t[0]<<8|t[1],o=Y+n,a=o+Ke;if(t.byteLength<a+ot)throw new Error("malformed message: too short");let s=t.slice(Y,o),c=t.slice(o,a),u=t.slice(a),h=await Pe(e,s,r?.info!==void 0?{info:r.info}:void 0),x=await Lr(h),D=await y.decrypt({name:"AES-GCM",iv:c},x,u);return new Uint8Array(D)}i(De,"decryptBytes");async function Dr(e,t,r){let n=await De(e,t,r);return new TextDecoder().decode(n)}i(Dr,"decryptToString");async function kr(e,t,r){let n=Z(t,"base64url"),o=await De(e,n,r?.info!==void 0?{info:r.info}:void 0);return r?.buffer?o:new TextDecoder().decode(o)}i(kr,"decryptFromString");function Ir(e){if(e!==128&&e!==256)throw new Error(`invalid keysize: ${e} (expected 128 or 256)`)}i(Ir,"validateKeysize");function et(e){if(e.length!==16&&e.length!==32)throw new Error(`invalid aesKey length: ${e.length} bytes (expected 16 or 32)`)}i(et,"validateRawKeyBytes");function at(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(at,"normalizeInfo");async function Br(e){if(!e.extractable)throw new Error("aesKey must be extractable: its raw bytes are what get sealed");return new Uint8Array(await y.exportKey("raw",e))}i(Br,"exportAesKeyBytes");async function st(e){return y.importKey("raw",e,{name:"AES-GCM"},!0,["encrypt","decrypt"])}i(st,"importAesKey");async function Lr(e){return y.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(Lr,"importAesKeyDecryptOnly");function I(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(I,"i2osp");function E(...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(E,"concat");async function ct(e,t){let r=await y.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return new Uint8Array(await y.sign("HMAC",r,t))}i(ct,"hmac");async function Tr(e,t){let r=e.length===0?new Uint8Array(nt):e;return ct(r,t)}i(Tr,"extract");async function Mr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await ct(e,E(o,t,I(s,1)));let c=Math.min(o.length,r-a);n.set(o.subarray(0,c),a),a+=c,s++}return n}i(Mr,"expand");async function ee(e,t,r,n){let o=E(it,e,new TextEncoder().encode(r),n);return Tr(t,o)}i(ee,"labeledExtract");async function Ee(e,t,r,n,o){let a=E(I(o,2),it,e,new TextEncoder().encode(r),n);return Mr(t,a,o)}i(Ee,"labeledExpand");async function Se(e){return new Uint8Array(await y.exportKey("raw",e))}i(Se,"exportRawPublic");async function tt(e){if(e.length!==j)throw new Error(`invalid public key length: ${e.length} bytes (expected ${j})`);return y.importKey("raw",e,{name:"X25519"},!0,[])}i(tt,"importRawPublic");async function zr(e){if(e instanceof Uint8Array)return tt(e);if(e instanceof CryptoKey){if(e.type!=="public")throw new Error("recipient CryptoKey must be a public key");return Ce(e,"recipient CryptoKey"),e}if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e;return tt(Z(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 Ce(t.publicKey,"recipient keypair publicKey"),t.publicKey}throw new Error("unrecognized recipient key form")}i(zr,"resolveRecipientPublicKey");function Ce(e,t){if(e.algorithm.name!=="X25519")throw new Error(`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Ce,"assertX25519Algorithm");async function ft(e,t){let r=await y.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(ft,"dh");async function pt(e,t){let r=await ee(Ye,new Uint8Array(0),"eae_prk",e);return Ee(Ye,r,"shared_secret",t,nt)}i(pt,"extractAndExpand");async function Nr(e){let t=await y.generateKey({name:"X25519"},!1,["deriveBits"]),r=await ft(t.privateKey,e),n=await Se(t.publicKey),o=await Se(e),a=E(n,o);return{sharedSecret:await pt(r,a),enc:n}}i(Nr,"encap");async function Or(e,t){if(t.privateKey.type!=="private")throw new Error("keypair.privateKey must be a private key");Ce(t.privateKey,"keypair.privateKey");let r=await y.importKey("raw",e,{name:"X25519"},!1,[]),n=await ft(t.privateKey,r),o=await Se(t.publicKey),a=E(e,o);return pt(n,a)}i(Or,"decap");async function ut(e,t){let r=new Uint8Array(0),n=await ee(G,r,"psk_id_hash",r),o=await ee(G,r,"info_hash",t),a=E(new Uint8Array([Cr]),n,o),s=await ee(G,e,"secret",r),c=await Ee(G,s,"key",a,Sr),u=await Ee(G,s,"base_nonce",a,Ke);return{key:c,baseNonce:u}}i(ut,"keySchedule");async function $r(e,t,r){let n=await y.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),o=await y.encrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i($r,"aeadSeal");async function Rr(e,t,r){let n=await y.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),o=await y.decrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(Rr,"aeadOpen");async function yt(e,t,r,n){let o=typeof t=="string"?new TextEncoder().encode(t):t,{wrapped:a,key:s}=await Kr(e,r,n),c=globalThis.crypto.getRandomValues(new Uint8Array(Ke)),u=new Uint8Array(await y.encrypt({name:"AES-GCM",iv:c},s,o));return E(I(a.length,Y),a,c,u)}i(yt,"encryptBytes");async function Vr(e,t,r,n){let o=await yt(e,t,r,n);return ve(o,n?.encoding??"base64url")}i(Vr,"encryptToString");export{Bo as decrypt,Io as encrypt,ko as open,Kr as seal};
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:()=>Lt});var fn=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 Ct(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),y=Math.log(c)/Math.log(256),g=Math.log(256)/Math.log(c);function k(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 d=0,I=0,w=0,A=f.length;w!==A&&f[w]===0;)w++,d++;for(var U=(A-w)*g+1>>>0,h=new Uint8Array(U);w!==A;){for(var E=f[w],K=0,x=U-1;(E!==0||K<I)&&x!==-1;x--,K++)E+=256*h[x]>>>0,h[x]=E%c>>>0,E=E/c>>>0;if(E!==0)throw new Error("Non-zero carry");I=K,w++}for(var S=U-I;S!==U&&h[S]===0;)S++;for(var W=u.repeat(d);S<U;++S)W+=e.charAt(h[S]);return W}i(k,"encode");function B(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var d=0;if(f[d]!==" "){for(var I=0,w=0;f[d]===u;)I++,d++;for(var A=(f.length-d)*y+1>>>0,U=new Uint8Array(A);f[d];){var h=r[f.charCodeAt(d)];if(h===255)return;for(var E=0,K=A-1;(h!==0||E<w)&&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");w=E,d++}if(f[d]!==" "){for(var x=A-w;x!==A&&U[x]===0;)x++;for(var S=new Uint8Array(I+(A-x)),W=I;x!==A;)S[W++]=U[x++];return S}}}i(B,"decodeUnsafe");function Q(f){var d=B(f);if(d)return d;throw new Error(`Non-${t} character`)}return i(Q,"decode"),{encode:k,decodeUnsafe:B,decode:Q}}i(Ct,"base");var Kt=Ct,Pt=Kt,$e=Pt;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 T({name:e,prefix:t,encode:r,decode:n}){return new se(e,t,r,n)}i(T,"from");function P({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=$e(r,e);return T({prefix:t,name:e,encode:n,decode:i(a=>C(o(a)),"decode")})}i(P,"baseX");function Dt(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 y=0;y<o;++y){let g=t[e[y]];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(Dt,"decode");function kt(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(kt,"encode");function It(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(It,"createAlphabetIdx");function p({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=It(n);return T({prefix:t,name:e,encode(a){return kt(a,n,r)},decode(a){return Dt(a,o,r,e)}})}i(p,"rfc4648");var Lt=P({prefix:"9",name:"base10",alphabet:"0123456789"});var fe={};l(fe,{base16:()=>Bt,base16upper:()=>Tt});var Bt=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tt=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pe={};l(pe,{base2:()=>Nt});var Nt=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};l(ue,{base256emoji:()=>_t});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}"),Mt=Fe.reduce((e,t,r)=>(e[r]=t,e),[]),zt=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 Rt(e){return e.reduce((t,r)=>(t+=Mt[r],t),"")}i(Rt,"encode");function Ot(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=zt[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(Ot,"decode");var _t=T({prefix:"\u{1F680}",name:"base256emoji",encode:Rt,decode:Ot});var ye={};l(ye,{base32:()=>N,base32hex:()=>Gt,base32hexpad:()=>qt,base32hexpadupper:()=>Xt,base32hexupper:()=>Ht,base32pad:()=>Vt,base32padupper:()=>Ft,base32upper:()=>$t,base32z:()=>jt});var N=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$t=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vt=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ft=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gt=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ht=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xt=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jt=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var de={};l(de,{base36:()=>V,base36upper:()=>Jt});var V=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jt=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var he={};l(he,{base58btc:()=>v,base58flickr:()=>Qt});var v=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qt=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var le={};l(le,{base64:()=>Wt,base64pad:()=>Zt,base64url:()=>Yt,base64urlpad:()=>er});var Wt=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zt=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yt=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),er=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var me={};l(me,{base8:()=>tr});var tr=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var be={};l(be,{identity:()=>rr});var rr=T({prefix:"\0",name:"identity",encode:i(e=>Oe(e),"encode"),decode:i(e=>Re(e),"decode")});var kn=new TextEncoder,In=new TextDecoder;var xe={};l(xe,{identity:()=>Sr});var ir=qe,Ge=128,ar=127,sr=~ar,cr=Math.pow(2,31);function qe(e,t,r){t=t||[],r=r||0;for(var n=r;e>=cr;)t[r++]=e&255|Ge,e/=128;for(;e&sr;)t[r++]=e&255|Ge,e>>>=7;return t[r]=e|0,qe.bytes=r-n+1,t}i(qe,"encode");var fr=we,pr=128,He=127;function we(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw we.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>=pr);return we.bytes=a-n,r}i(we,"read");var ur=Math.pow(2,7),yr=Math.pow(2,14),dr=Math.pow(2,21),hr=Math.pow(2,28),lr=Math.pow(2,35),mr=Math.pow(2,42),br=Math.pow(2,49),wr=Math.pow(2,56),xr=Math.pow(2,63),gr=i(function(e){return e<ur?1:e<yr?2:e<dr?3:e<hr?4:e<lr?5:e<mr?6:e<br?7:e<wr?8:e<xr?9:10},"length"),Ar={encode:ir,decode:fr,encodingLength:gr},Ur=Ar,F=Ur;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,Er="identity",Qe=C;function vr(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(vr,"digest");var Sr={code:Je,name:Er,encode:Qe,digest:vr};var Ue={};l(Ue,{sha256:()=>Kr,sha512:()=>Pr});var Cr=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??Cr,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 Kr=Ae({name:"sha2-256",code:18,encode:Ye("SHA-256")}),Pr=Ae({name:"sha2-512",code:19,encode:Ye("SHA-512")});function et(e,t){let{bytes:r,version:n}=e;return n===0?kr(r,Ee(e),t??v.encoder):Ir(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!==Lr)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[Br]===!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[k,B]=G(t.subarray(r));return r+=B,k},"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(),y=r+u,g=y-s;return{version:o,codec:a,multihashCode:c,digestSize:u,multihashSize:g,size:y}}static parse(t,r){let[n,o]=Dr(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 Dr(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(Dr,"parseCIDtoBytes");function kr(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(kr,"toStringV0");function Ir(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(Ir,"toStringV1");var q=112,Lr=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 Br=Symbol.for("@ipld/js-cid/CID");var ve={...be,...pe,...me,...ce,...fe,...ye,...de,...he,...le,...ue},co={...Ue,...xe};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,Nr=1,Mr=2,Ke=32,at=32,j=12,L=32,Pe=16,st=0,De=new TextEncoder().encode("HPKE-v1"),_=2,ke=m(new TextEncoder().encode("KEM"),D(it,2)),$=m(new TextEncoder().encode("HPKE"),D(it,2),D(Nr,2),D(Mr,2));var b=globalThis.crypto.subtle;async function ft(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(ft,"aeadSeal");async function pt(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(pt,"aeadOpen");async function Be(e,t,r,n){let o=typeof t=="string"?new TextEncoder().encode(t):t,a,s;if(r){let y=await xt(e,r,n);a=y.enc,s=y.key}else{let y=await wt(e,n);a=y.enc,s=y.key}let 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 ut(e,t,r,n){let o=await Be(e,t,r,n);return Ce(o,n?.encoding??"base64url")}i(ut,"encryptToString");async function yt(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(yt,"hmac");async function zr(e,t){let r=e.length===0?new Uint8Array(Ke):e;return yt(r,t)}i(zr,"extract");async function Rr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await yt(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(Rr,"expand");async function J(e,t,r,n){let o=m(De,e,new TextEncoder().encode(r),n);return zr(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 Rr(t,a,o)}i(re,"labeledExpand");async function Ie(e){return new Uint8Array(await b.exportKey("raw",e))}i(Ie,"exportRawPublic");async function ct(e){if(e.length!==L)throw new Error(`invalid public key length: ${e.length} bytes (expected ${L})`);return b.importKey("raw",e,{name:"X25519"},!0,[])}i(ct,"importRawPublic");async function dt(e){if(e instanceof Uint8Array)return ct(e);if(e instanceof CryptoKey){if(e.type!=="public")throw new Error("recipient CryptoKey must be a public key");return Le(e,"recipient CryptoKey"),e}if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e;return ct(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 Le(t.publicKey,"recipient keypair publicKey"),t.publicKey}throw new Error("unrecognized recipient key form")}i(dt,"resolveRecipientPublicKey");function Le(e,t){if(e.algorithm.name!=="X25519")throw new Error(`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Le,"assertX25519Algorithm");async function ht(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(ht,"dh");async function lt(e,t){let r=await J(ke,new Uint8Array(0),"eae_prk",e);return re(ke,r,"shared_secret",t,Ke)}i(lt,"extractAndExpand");async function mt(e){let t=await b.generateKey({name:"X25519"},!1,["deriveBits"]),r=await ht(t.privateKey,e),n=await Ie(t.publicKey),o=await Ie(e),a=m(n,o);return{sharedSecret:await lt(r,a),enc:n}}i(mt,"encap");async function bt(e,t){if(t.privateKey.type!=="private")throw new Error("keypair.privateKey must be a private key");Le(t.privateKey,"keypair.privateKey");let r=await b.importKey("raw",e,{name:"X25519"},!1,[]),n=await ht(t.privateKey,r),o=await Ie(t.publicKey),a=m(e,o);return lt(n,a)}i(bt,"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");var ne=globalThis.crypto.subtle;async function wt(e,t){let{wrapped:r,key:n}=await vt(e,null,t);return{enc:r,key:n}}i(wt,"create");async function xt(e,t,r){let{wrapped:n,key:o}=await vt(e,t,r);return{enc:n,key:o}}i(xt,"seal");var Vo=Object.assign(Gr,{raw:Ne}),Fo=Object.assign(Be,{asString:ut}),Go=Object.assign(Te,{asString:Or,fromString:_r});async function Te(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),y=await Ne(e,s,r?.info!==void 0?{info:r.info}:void 0),g=await Fr(y),k=await ne.decrypt({name:"AES-GCM",iv:c},g,u);return new Uint8Array(k)}i(Te,"decryptBytes");async function Or(e,t,r){let n=await Te(e,t,r);return new TextDecoder().decode(n)}i(Or,"decryptToString");async function _r(e,t,r){let n=X(t,"base64url"),o=await Te(e,n,r?.info!==void 0?{info:r.info}:void 0);return r?.buffer?o:new TextDecoder().decode(o)}i(_r,"decryptFromString");function $r(e){if(e!==128&&e!==256)throw new Error(`invalid keysize: ${e} (expected 128 or 256)`)}i($r,"validateKeysize");function gt(e){if(e.length!==16&&e.length!==32)throw new Error(`invalid aesKey length: ${e.length} bytes (expected 16 or 32)`)}i(gt,"validateRawKeyBytes");function At(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(At,"normalizeInfo");async function Vr(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(Vr,"exportAesKeyBytes");async function Ut(e){return ne.importKey("raw",e,{name:"AES-GCM"},!0,["encrypt","decrypt"])}i(Ut,"importAesKey");async function Fr(e){return ne.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(Fr,"importAesKeyDecryptOnly");async function Et(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(Et,"keySchedule");async function Ne(e,t,r){if(t.byteLength<L+Pe)throw new Error("malformed envelope: too short");let n=At(r?.info),o=t.slice(0,L),a=t.slice(L),s=await bt(o,e),{key:c,baseNonce:u}=await Et(s,n);return pt(c,u,a)}i(Ne,"openRawBytes");async function Gr(e,t,r){let n=await Ne(e,t,r);return Ut(n)}i(Gr,"openBytes");async function vt(e,t,r){let n=At(r?.info),o;if(t instanceof Uint8Array)gt(t),o=t;else if(t)o=await Vr(t),gt(o);else{let Q=r?.size??256;$r(Q),o=globalThis.crypto.getRandomValues(new Uint8Array(Q/8))}let a=await dt(e),{sharedSecret:s,enc:c}=await mt(a),{key:u,baseNonce:y}=await Et(s,n),g=await ft(u,y,o),k=m(c,g),B=await Ut(o);return{wrapped:k,key:B}}i(vt,"encryptKey");export{wt as create,Go as decrypt,Fo as encrypt,Vo as open,xt as seal};
2
2
  //# sourceMappingURL=index.min.js.map