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