simple-hpke 0.3.1 → 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.
@@ -1,2 +1,2 @@
1
- "use strict";var Z=Object.defineProperty;var Kt=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Dt=Object.prototype.hasOwnProperty;var i=(e,t)=>Z(e,"name",{value:t,configurable:!0});var h=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},_t=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rt(t))!Dt.call(e,o)&&o!==r&&Z(e,o,{get:()=>t[o],enumerable:!(n=Kt(t,o))||n.enumerable});return e};var Pt=e=>_t(Z({},"__esModule",{value:!0}),e);var Qr={};h(Qr,{AEAD_ID:()=>It,AEAD_TAG_LENGTH:()=>ae,ENC_LENGTH:()=>P,HPKE_SUITE_ID:()=>k,HPKE_V1:()=>pe,KDF_ID:()=>Ct,KEM_ID:()=>Ve,KEM_SUITE_ID:()=>se,KEY_ID_LABEL:()=>St,KEY_ID_NONCE_LENGTH:()=>vt,MODE_BASE:()=>Be,NK:()=>Te,NN:()=>F,NSECRET:()=>ce,WRAPPED_LEN_PREFIX:()=>T});module.exports=Pt(Qr);function ee(e=0){return new Uint8Array(e)}i(ee,"allocUnsafe");var he={};h(he,{base10:()=>Vt});var mn=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 I(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(I,"coerce");function He(e){return new TextEncoder().encode(e)}i(He,"fromString");function Fe(e){return new TextDecoder().decode(e)}i(Fe,"toString");function Nt(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),l=Math.log(c)/Math.log(256),E=Math.log(256)/Math.log(c);function K(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 d=0,N=0,x=0,A=p.length;x!==A&&p[x]===0;)x++,d++;for(var U=(A-x)*E+1>>>0,m=new Uint8Array(U);x!==A;){for(var S=p[x],D=0,g=U-1;(S!==0||D<N)&&g!==-1;g--,D++)S+=256*m[g]>>>0,m[g]=S%c>>>0,S=S/c>>>0;if(S!==0)throw new Error("Non-zero carry");N=D,x++}for(var C=U-N;C!==U&&m[C]===0;)C++;for(var W=u.repeat(d);C<U;++C)W+=e.charAt(m[C]);return W}i(K,"encode");function R(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var d=0;if(p[d]!==" "){for(var N=0,x=0;p[d]===u;)N++,d++;for(var A=(p.length-d)*l+1>>>0,U=new Uint8Array(A);p[d];){var m=r[p.charCodeAt(d)];if(m===255)return;for(var S=0,D=A-1;(m!==0||S<x)&&D!==-1;D--,S++)m+=c*U[D]>>>0,U[D]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");x=S,d++}if(p[d]!==" "){for(var g=A-x;g!==A&&U[g]===0;)g++;for(var C=new Uint8Array(N+(A-g)),W=N;g!==A;)C[W++]=U[g++];return C}}}i(R,"decodeUnsafe");function Q(p){var d=R(p);if(d)return d;throw new Error(`Non-${t} character`)}return i(Q,"decode"),{encode:K,decodeUnsafe:R,decode:Q}}i(Nt,"base");var kt=Nt,Tt=kt,$e=Tt;var fe=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")}},ue=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)}},ye=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 ye({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}i(Ye,"or");var de=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 fe(t,r,n),this.decoder=new ue(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function B({name:e,prefix:t,encode:r,decode:n}){return new de(e,t,r,n)}i(B,"from");function _({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=$e(r,e);return B({prefix:t,name:e,encode:n,decode:i(a=>I(o(a)),"decode")})}i(_,"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 l=0;l<o;++l){let E=t[e[l]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|E,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 Mt(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(Mt,"encode");function Ot(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(Ot,"createAlphabetIdx");function f({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ot(n);return B({prefix:t,name:e,encode(a){return Mt(a,n,r)},decode(a){return Bt(a,o,r,e)}})}i(f,"rfc4648");var Vt=_({prefix:"9",name:"base10",alphabet:"0123456789"});var le={};h(le,{base16:()=>zt,base16upper:()=>Ht});var zt=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ht=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var me={};h(me,{base2:()=>Ft});var Ft=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var be={};h(be,{base256emoji:()=>Xt});var qe=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}"),Gt=qe.reduce((e,t,r)=>(e[r]=t,e),[]),$t=qe.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Yt(e){return e.reduce((t,r)=>(t+=Gt[r],t),"")}i(Yt,"encode");function qt(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=$t[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(qt,"decode");var Xt=B({prefix:"\u{1F680}",name:"base256emoji",encode:Yt,decode:qt});var we={};h(we,{base32:()=>M,base32hex:()=>Wt,base32hexpad:()=>er,base32hexpadupper:()=>tr,base32hexupper:()=>Zt,base32pad:()=>Jt,base32padupper:()=>Qt,base32upper:()=>jt,base32z:()=>rr});var M=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jt=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Jt=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qt=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wt=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zt=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),er=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tr=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rr=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xe={};h(xe,{base36:()=>G,base36upper:()=>nr});var G=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nr=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ge={};h(ge,{base58btc:()=>v,base58flickr:()=>or});var v=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),or=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ee={};h(Ee,{base64:()=>ir,base64pad:()=>ar,base64url:()=>sr,base64urlpad:()=>cr});var ir=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ar=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sr=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cr=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ae={};h(Ae,{base8:()=>pr});var pr=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ue={};h(Ue,{identity:()=>fr});var fr=B({prefix:"\0",name:"identity",encode:i(e=>Fe(e),"encode"),decode:i(e=>He(e),"decode")});var Bn=new TextEncoder,Mn=new TextDecoder;var ve={};h(ve,{identity:()=>Lr});var dr=Je,Xe=128,hr=127,lr=~hr,mr=Math.pow(2,31);function Je(e,t,r){t=t||[],r=r||0;for(var n=r;e>=mr;)t[r++]=e&255|Xe,e/=128;for(;e&lr;)t[r++]=e&255|Xe,e>>>=7;return t[r]=e|0,Je.bytes=r-n+1,t}i(Je,"encode");var br=Se,wr=128,je=127;function Se(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw Se.bytes=0,new RangeError("Could not decode varint");s=e[a++],r+=o<28?(s&je)<<o:(s&je)*Math.pow(2,o),o+=7}while(s>=wr);return Se.bytes=a-n,r}i(Se,"read");var xr=Math.pow(2,7),gr=Math.pow(2,14),Er=Math.pow(2,21),Ar=Math.pow(2,28),Ur=Math.pow(2,35),Sr=Math.pow(2,42),vr=Math.pow(2,49),Cr=Math.pow(2,56),Ir=Math.pow(2,63),Kr=i(function(e){return e<xr?1:e<gr?2:e<Er?3:e<Ar?4:e<Ur?5:e<Sr?6:e<vr?7:e<Cr?8:e<Ir?9:10},"length"),Rr={encode:dr,decode:br,encodingLength:Kr},Dr=Rr,$=Dr;function Y(e,t=0){return[$.decode(e,t),$.decode.bytes]}i(Y,"decode");function O(e,t,r=0){return $.encode(e,t,r),t}i(O,"encodeTo");function V(e){return $.encodingLength(e)}i(V,"encodingLength");function H(e,t){let r=t.byteLength,n=V(e),o=n+V(r),a=new Uint8Array(o+r);return O(e,a,0),O(r,a,n),a.set(t,o),new z(e,r,t,a)}i(H,"create");function Qe(e){let t=I(e),[r,n]=Y(t),[o,a]=Y(t.subarray(n)),s=t.subarray(n+a);if(s.byteLength!==o)throw new Error("Incorrect length");return new z(r,o,s,t)}i(Qe,"decode");function We(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(We,"equals");var z=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 Ze=0,_r="identity",et=I;function Pr(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 H(Ze,et(e))}i(Pr,"digest");var Lr={code:Ze,name:_r,encode:et,digest:Pr};var Ke={};h(Ke,{sha256:()=>kr,sha512:()=>Tr});var Nr=20;function Ie({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ce(e,t,r,n,o)}i(Ie,"from");var Ce=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??Nr,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?tt(n,this.code,r?.truncate):n.then(o=>tt(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function tt(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 H(t,e)}i(tt,"createDigest");function nt(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}i(nt,"sha");var kr=Ie({name:"sha2-256",code:18,encode:nt("SHA-256")}),Tr=Ie({name:"sha2-512",code:19,encode:nt("SHA-512")});function ot(e,t){let{bytes:r,version:n}=e;return n===0?Mr(r,Re(e),t??v.encoder):Or(r,Re(e),t??M.encoder)}i(ot,"format");var it=new WeakMap;function Re(e){let t=it.get(e);if(t==null){let r=new Map;return it.set(e,r),r}return t}i(Re,"baseCache");var re=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!==X)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vr)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=H(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&&We(t.multihash,n.multihash)}toString(t){return ot(this,t)}toJSON(){return{"/":ot(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??at(n,o,a.bytes))}else if(r[zr]===!0){let{version:n,multihash:o,code:a}=r,s=Qe(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!==X)throw new Error(`Version 0 CID must use dag-pb (code: ${X}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=at(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,X,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=I(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 z(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,R]=Y(t.subarray(r));return r+=R,K},"next"),o=n(),a=X;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(),l=r+u,E=l-s;return{version:o,codec:a,multihashCode:c,digestSize:u,multihashSize:E,size:l}}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 Re(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 M.prefix:{let r=t??M;return[M.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(Br,"parseCIDtoBytes");function Mr(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(Mr,"toStringV0");function Or(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(Or,"toStringV1");var X=112,Vr=18;function at(e,t,r){let n=V(e),o=n+V(t),a=new Uint8Array(o+r.byteLength);return O(e,a,0),O(t,a,n),a.set(r,o),a}i(at,"encodeCID");var zr=Symbol.for("@ipld/js-cid/CID");var De={...Ue,...me,...Ae,...he,...le,...we,...xe,...ge,...Ee,...be},mo={...Ke,...ve};function ct(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}i(ct,"createCodec");var st=ct("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),_e=ct("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=ee(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Hr={utf8:st,"utf-8":st,hex:De.base16,latin1:_e,ascii:_e,binary:_e,...De},ne=Hr;function j(e,t="utf8"){let r=ne[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}i(j,"fromString");function Pe(e,t="utf8"){let r=ne[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}i(Pe,"toString");var y=class extends Error{static{i(this,"HpkeError")}code;constructor(t,r,n){super(r,n),this.name="HpkeError",this.code=t}};var ie=globalThis.crypto.subtle;var $o=Object.assign(Xr,{raw:Ne}),Yo=Object.assign(ke,{asString:mt}),qo=Object.assign(Le,{asString:Fr,fromString:Gr});async function Le(e,t,r){if(t.byteLength<T)throw new y("ERR_MALFORMED_MESSAGE","malformed message: too short");let n=t[0]<<8|t[1],o=T+n,a=o+F;if(t.byteLength<a+ae)throw new y("ERR_MALFORMED_MESSAGE","malformed message: too short");let s=t.slice(T,o),c=t.slice(o,a),u=t.slice(a),l=await Ne(e,s,r?.info!==void 0?{info:r.info}:void 0),E=await qr(l),K;try{K=await ie.decrypt({name:"AES-GCM",iv:c},E,u)}catch(R){throw new y("ERR_DECRYPT_FAILED","failed to decrypt the message: tampered ciphertext",{cause:R})}return new Uint8Array(K)}i(Le,"decryptBytes");async function Fr(e,t,r){let n=await Le(e,t,r);return new TextDecoder().decode(n)}i(Fr,"decryptToString");async function Gr(e,t,r){let n=j(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(Gr,"decryptFromString");function $r(e){if(e!==128&&e!==256)throw new y("ERR_INVALID_KEYSIZE",`invalid keysize: ${e} (expected 128 or 256)`)}i($r,"validateKeysize");function pt(e){if(e.length!==16&&e.length!==32)throw new y("ERR_INVALID_AES_KEY",`invalid aesKey length: ${e.length} bytes (expected 16 or 32)`)}i(pt,"validateRawKeyBytes");function ft(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(ft,"normalizeInfo");async function Yr(e){if(!e.extractable)throw new y("ERR_INVALID_AES_KEY","aesKey must be extractable: its raw bytes are what get sealed");return new Uint8Array(await ie.exportKey("raw",e))}i(Yr,"exportAesKeyBytes");async function ut(e,t){return ie.importKey("raw",e,{name:"AES-GCM"},t,["encrypt","decrypt"])}i(ut,"importAesKey");async function qr(e){return ie.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(qr,"importAesKeyDecryptOnly");async function yt(e,t){let r=new Uint8Array(0),n=await J(k,r,"psk_id_hash",r),o=await J(k,r,"info_hash",t),a=b(new Uint8Array([Be]),n,o),s=await J(k,e,"secret",r),c=await oe(k,s,"key",a,Te),u=await oe(k,s,"base_nonce",a,F);return{key:c,baseNonce:u}}i(yt,"keySchedule");async function Ne(e,t,r){if(t.byteLength<P+ae)throw new y("ERR_MALFORMED_ENVELOPE","malformed envelope: too short");let n=ft(r?.info),o=t.slice(0,P),a=t.slice(P),s=await xt(o,e),{key:c,baseNonce:u}=await yt(s,n);return lt(c,u,a)}i(Ne,"openRawBytes");async function Xr(e,t,r){let n=await Ne(e,t,r);return ut(n,r?.extractable??!1)}i(Xr,"openBytes");async function dt(e,t,r){let n=ft(r?.info),o;if(t instanceof Uint8Array)pt(t),o=t;else if(t)o=await Yr(t),pt(o);else{let Q=r?.size??256;$r(Q),o=globalThis.crypto.getRandomValues(new Uint8Array(Q/8))}let a=await bt(e),{sharedSecret:s,enc:c}=await wt(a),{key:u,baseNonce:l}=await yt(s,n),E=await ht(u,l,o),K=b(c,E),R=await ut(o,r?.extractable??!1);return{wrapped:K,key:R}}i(dt,"encryptKey");var w=globalThis.crypto.subtle;async function ht(e,t,r){let n=await w.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),o=await w.encrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(ht,"aeadSeal");async function lt(e,t,r){let n=await w.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),o;try{o=await w.decrypt({name:"AES-GCM",iv:t},n,r)}catch(a){throw new y("ERR_DECRYPT_FAILED","failed to decrypt the wrapped key: wrong keypair, wrong info, or a tampered envelope",{cause:a})}return new Uint8Array(o)}i(lt,"aeadOpen");async function ke(e,t,r,n){let o=typeof t=="string"?new TextEncoder().encode(t):t,{wrapped:a,key:s}=await dt(e,r,n),c=globalThis.crypto.getRandomValues(new Uint8Array(F)),u=new Uint8Array(await w.encrypt({name:"AES-GCM",iv:c},s,o));return b(L(a.length,T),a,c,u)}i(ke,"encryptBytes");async function mt(e,t,r,n){let o=await ke(e,t,r,n);return Pe(o,n?.encoding??"base64url")}i(mt,"encryptToString");async function Et(e,t){let r=await w.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return new Uint8Array(await w.sign("HMAC",r,t))}i(Et,"hmac");async function jr(e,t){let r=e.length===0?new Uint8Array(ce):e;return Et(r,t)}i(jr,"extract");async function Jr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await Et(e,b(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(Jr,"expand");async function J(e,t,r,n){let o=b(pe,e,new TextEncoder().encode(r),n);return jr(t,o)}i(J,"labeledExtract");async function oe(e,t,r,n,o){let a=b(L(o,2),pe,e,new TextEncoder().encode(r),n);return Jr(t,a,o)}i(oe,"labeledExpand");async function Me(e){return new Uint8Array(await w.exportKey("raw",e))}i(Me,"exportRawPublic");async function gt(e){if(e.length!==P)throw new y("ERR_INVALID_RECIPIENT_KEY",`invalid public key length: ${e.length} bytes (expected ${P})`);return w.importKey("raw",e,{name:"X25519"},!0,[])}i(gt,"importRawPublic");async function bt(e){if(e instanceof Uint8Array)return gt(e);if(e instanceof CryptoKey){if(e.type!=="public")throw new y("ERR_INVALID_RECIPIENT_KEY","recipient CryptoKey must be a public key");return Oe(e,"recipient CryptoKey","ERR_INVALID_RECIPIENT_KEY"),e}if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e;return gt(j(r,n??"base64url"))}let t=e;if(t.publicKey instanceof CryptoKey){if(t.publicKey.type!=="public")throw new y("ERR_INVALID_RECIPIENT_KEY","recipient keypair publicKey must be a public key");return Oe(t.publicKey,"recipient keypair publicKey","ERR_INVALID_RECIPIENT_KEY"),t.publicKey}throw new y("ERR_INVALID_RECIPIENT_KEY","unrecognized recipient key form")}i(bt,"resolveRecipientPublicKey");function Oe(e,t,r){if(e.algorithm.name!=="X25519")throw new y(r,`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Oe,"assertX25519Algorithm");async function At(e,t){let r=await w.deriveBits({name:"X25519",public:t},e,256),n=new Uint8Array(r);if(n.every(o=>o===0))throw new y("ERR_SMALL_ORDER_KEY","X25519 shared secret is all-zero (small-order public key?)");return n}i(At,"dh");async function Ut(e,t){let r=await J(se,new Uint8Array(0),"eae_prk",e);return oe(se,r,"shared_secret",t,ce)}i(Ut,"extractAndExpand");async function wt(e){let t=await w.generateKey({name:"X25519"},!1,["deriveBits"]),r=await At(t.privateKey,e),n=await Me(t.publicKey),o=await Me(e),a=b(n,o);return{sharedSecret:await Ut(r,a),enc:n}}i(wt,"encap");async function xt(e,t){if(t.privateKey.type!=="private")throw new y("ERR_INVALID_KEYPAIR","keypair.privateKey must be a private key");Oe(t.privateKey,"keypair.privateKey","ERR_INVALID_KEYPAIR");let r=await w.importKey("raw",e,{name:"X25519"},!1,[]),n=await At(t.privateKey,r),o=await Me(t.publicKey),a=b(e,o);return Ut(n,a)}i(xt,"decap");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 b(...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(b,"concat");var Ve=32,Ct=1,It=2,ce=32,Te=32,F=12,P=32,ae=16,Be=0,pe=new TextEncoder().encode("HPKE-v1"),T=2,se=b(new TextEncoder().encode("KEM"),L(Ve,2)),k=b(new TextEncoder().encode("HPKE"),L(Ve,2),L(Ct,2),L(It,2)),St=new TextEncoder().encode("simple-hpke/keyId/v1"),vt=12;
1
+ "use strict";var Z=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Dt=Object.prototype.hasOwnProperty;var i=(e,t)=>Z(e,"name",{value:t,configurable:!0});var h=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},Lt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _t(t))!Dt.call(e,o)&&o!==r&&Z(e,o,{get:()=>t[o],enumerable:!(n=Rt(t,o))||n.enumerable});return e};var Pt=e=>Lt(Z({},"__esModule",{value:!0}),e);var Wr={};h(Wr,{AEAD_ID:()=>Kt,AEAD_TAG_LENGTH:()=>ae,ENC_LENGTH:()=>L,HPKE_SUITE_ID:()=>T,HPKE_V1:()=>fe,KDF_ID:()=>It,KEM_ID:()=>Oe,KEM_SUITE_ID:()=>se,KEY_ID_LABEL:()=>St,KEY_ID_NONCE_LENGTH:()=>Ct,MODE_BASE:()=>Me,NK:()=>ke,NN:()=>G,NSECRET:()=>ce,WRAPPED_LEN_PREFIX:()=>k});module.exports=Pt(Wr);function ee(e=0){return new Uint8Array(e)}i(ee,"allocUnsafe");var he={};h(he,{base10:()=>zt});var bn=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 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 He(e){return new TextEncoder().encode(e)}i(He,"fromString");function Ge(e){return new TextDecoder().decode(e)}i(Ge,"toString");function Tt(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),l=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 d=0,N=0,x=0,A=p.length;x!==A&&p[x]===0;)x++,d++;for(var U=(A-x)*E+1>>>0,m=new Uint8Array(U);x!==A;){for(var v=p[x],_=0,g=U-1;(v!==0||_<N)&&g!==-1;g--,_++)v+=256*m[g]>>>0,m[g]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");N=_,x++}for(var I=U-N;I!==U&&m[I]===0;)I++;for(var W=y.repeat(d);I<U;++I)W+=e.charAt(m[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 d=0;if(p[d]!==" "){for(var N=0,x=0;p[d]===y;)N++,d++;for(var A=(p.length-d)*l+1>>>0,U=new Uint8Array(A);p[d];){var m=r[p.charCodeAt(d)];if(m===255)return;for(var v=0,_=A-1;(m!==0||v<x)&&_!==-1;_--,v++)m+=c*U[_]>>>0,U[_]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");x=v,d++}if(p[d]!==" "){for(var g=A-x;g!==A&&U[g]===0;)g++;for(var I=new Uint8Array(N+(A-g)),W=N;g!==A;)I[W++]=U[g++];return I}}}i(R,"decodeUnsafe");function Q(p){var d=R(p);if(d)return d;throw new Error(`Non-${t} character`)}return i(Q,"decode"),{encode:C,decodeUnsafe:R,decode:Q}}i(Tt,"base");var kt=Tt,Mt=kt,Fe=Mt;var pe=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")}},ue=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 $e(this,t)}},ye=class{static{i(this,"ComposedDecoder")}decoders;constructor(t){this.decoders=t}or(t){return $e(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 $e(e,t){return new ye({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}i($e,"or");var de=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 pe(t,r,n),this.decoder=new ue(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function M({name:e,prefix:t,encode:r,decode:n}){return new de(e,t,r,n)}i(M,"from");function D({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Fe(r,e);return M({prefix:t,name:e,encode:n,decode:i(a=>K(o(a)),"decode")})}i(D,"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,y=0;for(let l=0;l<o;++l){let E=t[e[l]];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(Bt,"decode");function Vt(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(Vt,"encode");function Ot(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}i(Ot,"createAlphabetIdx");function u({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ot(n);return M({prefix:t,name:e,encode(a){return Vt(a,n,r)},decode(a){return Bt(a,o,r,e)}})}i(u,"rfc4648");var zt=D({prefix:"9",name:"base10",alphabet:"0123456789"});var le={};h(le,{base16:()=>Ht,base16upper:()=>Gt});var Ht=u({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gt=u({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var me={};h(me,{base2:()=>Yt});var Yt=u({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var be={};h(be,{base256emoji:()=>jt});var qe=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}"),Ft=qe.reduce((e,t,r)=>(e[r]=t,e),[]),$t=qe.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function qt(e){return e.reduce((t,r)=>(t+=Ft[r],t),"")}i(qt,"encode");function Xt(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=$t[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}i(Xt,"decode");var jt=M({prefix:"\u{1F680}",name:"base256emoji",encode:qt,decode:Xt});var we={};h(we,{base32:()=>B,base32hex:()=>Zt,base32hexpad:()=>tr,base32hexpadupper:()=>rr,base32hexupper:()=>er,base32pad:()=>Qt,base32padupper:()=>Wt,base32upper:()=>Jt,base32z:()=>nr});var B=u({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jt=u({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qt=u({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wt=u({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zt=u({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),er=u({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tr=u({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rr=u({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),nr=u({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xe={};h(xe,{base36:()=>Y,base36upper:()=>or});var Y=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),or=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ge={};h(ge,{base58btc:()=>S,base58flickr:()=>ir});var S=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ir=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ee={};h(Ee,{base64:()=>ar,base64pad:()=>sr,base64url:()=>cr,base64urlpad:()=>fr});var ar=u({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sr=u({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cr=u({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),fr=u({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ae={};h(Ae,{base8:()=>pr});var pr=u({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ue={};h(Ue,{identity:()=>ur});var ur=M({prefix:"\0",name:"identity",encode:i(e=>Ge(e),"encode"),decode:i(e=>He(e),"decode")});var Bn=new TextEncoder,Vn=new TextDecoder;var Se={};h(Se,{identity:()=>Nr});var hr=Je,Xe=128,lr=127,mr=~lr,br=Math.pow(2,31);function Je(e,t,r){t=t||[],r=r||0;for(var n=r;e>=br;)t[r++]=e&255|Xe,e/=128;for(;e&mr;)t[r++]=e&255|Xe,e>>>=7;return t[r]=e|0,Je.bytes=r-n+1,t}i(Je,"encode");var wr=ve,xr=128,je=127;function ve(e,n){var r=0,n=n||0,o=0,a=n,s,c=e.length;do{if(a>=c)throw ve.bytes=0,new RangeError("Could not decode varint");s=e[a++],r+=o<28?(s&je)<<o:(s&je)*Math.pow(2,o),o+=7}while(s>=xr);return ve.bytes=a-n,r}i(ve,"read");var gr=Math.pow(2,7),Er=Math.pow(2,14),Ar=Math.pow(2,21),Ur=Math.pow(2,28),vr=Math.pow(2,35),Sr=Math.pow(2,42),Cr=Math.pow(2,49),Ir=Math.pow(2,56),Kr=Math.pow(2,63),Rr=i(function(e){return e<gr?1:e<Er?2:e<Ar?3:e<Ur?4:e<vr?5:e<Sr?6:e<Cr?7:e<Ir?8:e<Kr?9:10},"length"),_r={encode:hr,decode:wr,encodingLength:Rr},Dr=_r,F=Dr;function $(e,t=0){return[F.decode(e,t),F.decode.bytes]}i($,"decode");function V(e,t,r=0){return F.encode(e,t,r),t}i(V,"encodeTo");function O(e){return F.encodingLength(e)}i(O,"encodingLength");function H(e,t){let r=t.byteLength,n=O(e),o=n+O(r),a=new Uint8Array(o+r);return V(e,a,0),V(r,a,n),a.set(t,o),new z(e,r,t,a)}i(H,"create");function Qe(e){let t=K(e),[r,n]=$(t),[o,a]=$(t.subarray(n)),s=t.subarray(n+a);if(s.byteLength!==o)throw new Error("Incorrect length");return new z(r,o,s,t)}i(Qe,"decode");function We(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(We,"equals");var z=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 Ze=0,Lr="identity",et=K;function Pr(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 H(Ze,et(e))}i(Pr,"digest");var Nr={code:Ze,name:Lr,encode:et,digest:Pr};var Ke={};h(Ke,{sha256:()=>kr,sha512:()=>Mr});var Tr=20;function Ie({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ce(e,t,r,n,o)}i(Ie,"from");var Ce=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??Tr,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?tt(n,this.code,r?.truncate):n.then(o=>tt(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function tt(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 H(t,e)}i(tt,"createDigest");function nt(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}i(nt,"sha");var kr=Ie({name:"sha2-256",code:18,encode:nt("SHA-256")}),Mr=Ie({name:"sha2-512",code:19,encode:nt("SHA-512")});function ot(e,t){let{bytes:r,version:n}=e;return n===0?Vr(r,Re(e),t??S.encoder):Or(r,Re(e),t??B.encoder)}i(ot,"format");var it=new WeakMap;function Re(e){let t=it.get(e);if(t==null){let r=new Map;return it.set(e,r),r}return t}i(Re,"baseCache");var re=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!==X)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zr)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=H(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&&We(t.multihash,n.multihash)}toString(t){return ot(this,t)}toJSON(){return{"/":ot(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??at(n,o,a.bytes))}else if(r[Hr]===!0){let{version:n,multihash:o,code:a}=r,s=Qe(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!==X)throw new Error(`Version 0 CID must use dag-pb (code: ${X}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=at(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,X,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 z(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]=$(t.subarray(r));return r+=R,C},"next"),o=n(),a=X;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(),l=r+y,E=l-s;return{version:o,codec:a,multihashCode:c,digestSize:y,multihashSize:E,size:l}}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 Re(a).set(n,t),a}};function Br(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 B.prefix:{let r=t??B;return[B.prefix,r.decode(e)]}case Y.prefix:{let r=t??Y;return[Y.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 Vr(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(Vr,"toStringV0");function Or(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(Or,"toStringV1");var X=112,zr=18;function at(e,t,r){let n=O(e),o=n+O(t),a=new Uint8Array(o+r.byteLength);return V(e,a,0),V(t,a,n),a.set(r,o),a}i(at,"encodeCID");var Hr=Symbol.for("@ipld/js-cid/CID");var _e={...Ue,...me,...Ae,...he,...le,...we,...xe,...ge,...Ee,...be},bo={...Ke,...Se};function ct(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}i(ct,"createCodec");var st=ct("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),De=ct("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=ee(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Gr={utf8:st,"utf-8":st,hex:_e.base16,latin1:De,ascii:De,binary:De,..._e},ne=Gr;function j(e,t="utf8"){let r=ne[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}i(j,"fromString");function Le(e,t="utf8"){let r=ne[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}i(Le,"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 ie=globalThis.crypto.subtle;var $o=Object.assign(jr,{raw:Ne}),qo=Object.assign(Te,{asString:mt}),Xo=Object.assign(Pe,{asString:Yr,fromString:Fr});async function Pe(e,t,r){if(t.byteLength<k)throw new f("ERR_MALFORMED_MESSAGE","malformed message: too short");let n=t[0]<<8|t[1],o=k+n,a=o+G;if(t.byteLength<a+ae)throw new f("ERR_MALFORMED_MESSAGE","malformed message: too short");let s=t.slice(k,o),c=t.slice(o,a),y=t.slice(a),l=await Ne(e,s,r?.info!==void 0?{info:r.info}:void 0),E=await Xr(l),C;try{C=await ie.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 Yr(e,t,r){let n=await Pe(e,t,r);return new TextDecoder().decode(n)}i(Yr,"decryptToString");async function Fr(e,t,r){let n;try{n=j(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(Fr,"decryptFromString");function $r(e){if(e!==128&&e!==256)throw new f("ERR_INVALID_KEYSIZE",`invalid keysize: ${e} (expected 128 or 256)`)}i($r,"validateKeysize");function ft(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(ft,"validateRawKeyBytes");function pt(e){return e==null?new Uint8Array(0):typeof e=="string"?new TextEncoder().encode(e):e}i(pt,"normalizeInfo");async function qr(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 ie.exportKey("raw",e))}i(qr,"exportAesKeyBytes");async function ut(e,t){return ie.importKey("raw",e,{name:"AES-GCM"},t,["encrypt","decrypt"])}i(ut,"importAesKey");async function Xr(e){return ie.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"])}i(Xr,"importAesKeyDecryptOnly");async function yt(e,t){let r=new Uint8Array(0),n=await J(T,r,"psk_id_hash",r),o=await J(T,r,"info_hash",t),a=b(new Uint8Array([Me]),n,o),s=await J(T,e,"secret",r),c=await oe(T,s,"key",a,ke),y=await oe(T,s,"base_nonce",a,G);return{key:c,baseNonce:y}}i(yt,"keySchedule");async function Ne(e,t,r){if(t.byteLength<L+ae)throw new f("ERR_MALFORMED_ENVELOPE","malformed envelope: too short");let n=pt(r?.info),o=t.slice(0,L),a=t.slice(L),s=await xt(o,e),{key:c,baseNonce:y}=await yt(s,n);return lt(c,y,a)}i(Ne,"openRawBytes");async function jr(e,t,r){let n=await Ne(e,t,r);return ut(n,r?.extractable??!1)}i(jr,"openBytes");async function dt(e,t,r){let n=pt(r?.info),o;if(t instanceof Uint8Array)ft(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 qr(t),ft(o)}else{let Q=r?.size??256;$r(Q),o=globalThis.crypto.getRandomValues(new Uint8Array(Q/8))}let a=await bt(e),{sharedSecret:s,enc:c}=await wt(a),{key:y,baseNonce:l}=await yt(s,n),E=await ht(y,l,o),C=b(c,E);if(t instanceof CryptoKey)return{wrapped:C,key:t};let R=await ut(o,r?.extractable??!1);return{wrapped:C,key:R}}i(dt,"encryptKey");var w=globalThis.crypto.subtle;async function ht(e,t,r){let n=await w.importKey("raw",e,{name:"AES-GCM"},!1,["encrypt"]),o=await w.encrypt({name:"AES-GCM",iv:t},n,r);return new Uint8Array(o)}i(ht,"aeadSeal");async function lt(e,t,r){let n=await w.importKey("raw",e,{name:"AES-GCM"},!1,["decrypt"]),o;try{o=await w.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(lt,"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 dt(e,r,n),c=globalThis.crypto.getRandomValues(new Uint8Array(G)),y=new Uint8Array(await w.encrypt({name:"AES-GCM",iv:c},s,o));return b(P(a.length,k),a,c,y)}i(Te,"encryptBytes");async function mt(e,t,r,n){let o=await Te(e,t,r,n);return Le(o,n?.encoding??"base64url")}i(mt,"encryptToString");async function At(e,t){let r=await w.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return new Uint8Array(await w.sign("HMAC",r,t))}i(At,"hmac");async function Jr(e,t){let r=e.length===0?new Uint8Array(ce):e;return At(r,t)}i(Jr,"extract");async function Qr(e,t,r){let n=new Uint8Array(r),o=new Uint8Array(0),a=0,s=1;for(;a<r;){o=await At(e,b(o,t,P(s,1)));let c=Math.min(o.length,r-a);n.set(o.subarray(0,c),a),a+=c,s++}return n}i(Qr,"expand");async function J(e,t,r,n){let o=b(fe,e,new TextEncoder().encode(r),n);return Jr(t,o)}i(J,"labeledExtract");async function oe(e,t,r,n,o){let a=b(P(o,2),fe,e,new TextEncoder().encode(r),n);return Qr(t,a,o)}i(oe,"labeledExpand");async function Be(e){return new Uint8Array(await w.exportKey("raw",e))}i(Be,"exportRawPublic");async function gt(e){if(e.length!==L)throw new f("ERR_INVALID_RECIPIENT_KEY",`invalid public key length: ${e.length} bytes (expected ${L})`);return w.importKey("raw",e,{name:"X25519"},!0,[])}i(gt,"importRawPublic");async function bt(e){if(e instanceof Uint8Array)return gt(e);if(e instanceof CryptoKey)return Et(e,"recipient CryptoKey");if(typeof e.publicKey=="string"){let{publicKey:r,encoding:n}=e,o;try{o=j(r,n??"base64url")}catch(a){throw new f("ERR_INVALID_RECIPIENT_KEY",`recipient publicKey string does not decode as ${n??"base64url"}`,{cause:a})}return gt(o)}let t=e;if(t.publicKey instanceof CryptoKey)return Et(t.publicKey,"recipient keypair publicKey");throw new f("ERR_INVALID_RECIPIENT_KEY","unrecognized recipient key form")}i(bt,"resolveRecipientPublicKey");function Et(e,t){if(e.type!=="public")throw new f("ERR_INVALID_RECIPIENT_KEY",`${t} must be a public key`);if(Ve(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(Et,"assertRecipientPublicKey");function Ve(e,t,r){if(e.algorithm.name!=="X25519")throw new f(r,`${t} must be an X25519 key (got ${e.algorithm.name})`)}i(Ve,"assertX25519Algorithm");async function Ut(e,t){let r;try{r=await w.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(Ut,"dh");async function vt(e,t){let r=await J(se,new Uint8Array(0),"eae_prk",e);return oe(se,r,"shared_secret",t,ce)}i(vt,"extractAndExpand");async function wt(e){let t=await w.generateKey({name:"X25519"},!1,["deriveBits"]),r=await Ut(t.privateKey,e),n=await Be(t.publicKey),o=await Be(e),a=b(n,o);return{sharedSecret:await vt(r,a),enc:n}}i(wt,"encap");async function xt(e,t){if(t.privateKey.type!=="private")throw new f("ERR_INVALID_KEYPAIR","keypair.privateKey must be a private key");if(Ve(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");Ve(t.publicKey,"keypair.publicKey","ERR_INVALID_KEYPAIR");let r=await w.importKey("raw",e,{name:"X25519"},!1,[]),n=await Ut(t.privateKey,r),o=await Be(t.publicKey),a=b(e,o);return vt(n,a)}i(xt,"decap");function P(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(P,"i2osp");function b(...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(b,"concat");var Oe=32,It=1,Kt=2,ce=32,ke=32,G=12,L=32,ae=16,Me=0,fe=new TextEncoder().encode("HPKE-v1"),k=2,se=b(new TextEncoder().encode("KEM"),P(Oe,2)),T=b(new TextEncoder().encode("HPKE"),P(Oe,2),P(It,2),P(Kt,2)),St=new TextEncoder().encode("simple-hpke/keyId/v1"),Ct=12;
2
2
  //# sourceMappingURL=constants.min.cjs.map