@libp2p/keychain
Version:
Key management and cryptographically protected messages
2 lines • 168 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PKeychain = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PKeychain=(()=>{var wl=Object.create;var Qr=Object.defineProperty;var xl=Object.getOwnPropertyDescriptor;var vl=Object.getOwnPropertyNames;var El=Object.getPrototypeOf,Bl=Object.prototype.hasOwnProperty;var Ee=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)Qr(r,e,{get:t[e],enumerable:!0})},ii=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of vl(t))!Bl.call(r,s)&&s!==e&&Qr(r,s,{get:()=>t[s],enumerable:!(n=xl(t,s))||n.enumerable});return r};var ks=(r,t,e)=>(e=r!=null?wl(El(r)):{},ii(t||!r||!r.__esModule?Qr(e,"default",{value:r,enumerable:!0}):e,r)),Al=r=>ii(Qr({},"__esModule",{value:!0}),r);var ac=Ee((Lm,ic)=>{"use strict";ic.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}});var dc=Ee((fc,hc)=>{"use strict";var Tn=ac(),{hasOwnProperty:lc}=Object.prototype,{propertyIsEnumerable:ph}=Object,cr=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),gh=fc,cc={concatArrays:!1,ignoreUndefined:!1},Ln=r=>{let t=[];for(let e in r)lc.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)ph.call(r,n)&&t.push(n)}return t};function lr(r){return Array.isArray(r)?yh(r):Tn(r)?mh(r):r}function yh(r){let t=r.slice(0,0);return Ln(r).forEach(e=>{cr(t,e,lr(r[e]))}),t}function mh(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return Ln(r).forEach(e=>{cr(t,e,lr(r[e]))}),t}var uc=(r,t,e,n)=>(e.forEach(s=>{typeof t[s]>"u"&&n.ignoreUndefined||(s in r&&r[s]!==Object.getPrototypeOf(r)?cr(r,s,Zo(r[s],t[s],n)):cr(r,s,lr(t[s])))}),r),bh=(r,t,e)=>{let n=r.slice(0,0),s=0;return[r,t].forEach(o=>{let i=[];for(let a=0;a<o.length;a++)lc.call(o,a)&&(i.push(String(a)),o===r?cr(n,s++,o[a]):cr(n,s++,lr(o[a])));n=uc(n,o,Ln(o).filter(a=>!i.includes(a)),e)}),n};function Zo(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?bh(r,t,e):!Tn(t)||!Tn(r)?lr(t):uc(r,t,Ln(t),e)}hc.exports=function(...r){let t=Zo(lr(cc),this!==gh&&this||{},cc),e={_:{}};for(let n of r)if(n!==void 0){if(!Tn(n))throw new TypeError("`"+n+"` is not an Option Object");e=Zo(e,{_:n},t)}return e._}});var mc=Ee((_m,yc)=>{"use strict";function wh(r){return r>=55296&&r<=56319}function xh(r){return r>=56320&&r<=57343}yc.exports=function(t,e,n){if(typeof e!="string")throw new Error("Input must be string");for(var s=e.length,o=0,i,a,c=0;c<s;c+=1){if(i=e.charCodeAt(c),a=e[c],wh(i)&&xh(e.charCodeAt(c+1))&&(c+=1,a+=e[c]),o+=t(a),o===n)return e.slice(0,c+1);if(o>n)return e.slice(0,c-a.length+1)}return e}});var wc=Ee((Dm,bc)=>{"use strict";function vh(r){return r>=55296&&r<=56319}function Eh(r){return r>=56320&&r<=57343}bc.exports=function(t){if(typeof t!="string")throw new Error("Input must be string");for(var e=t.length,n=0,s=null,o=null,i=0;i<e;i++)s=t.charCodeAt(i),Eh(s)?o!=null&&vh(o)?n+=1:n+=3:s<=127?n+=1:s>=128&&s<=2047?n+=2:s>=2048&&s<=65535&&(n+=3),o=s;return n}});var vc=Ee((Km,xc)=>{"use strict";var Bh=mc(),Ah=wc();xc.exports=Bh.bind(null,Ah)});var Ac=Ee((Om,Bc)=>{"use strict";var Sh=vc(),kh=/[\/\?<>\\:\*\|"]/g,Ch=/[\x00-\x1f\x80-\x9f]/g,Ih=/^\.+$/,Nh=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,Uh=/[\. ]+$/;function Ec(r,t){if(typeof r!="string")throw new Error("Input must be string");var e=r.replace(kh,t).replace(Ch,t).replace(Ih,t).replace(Nh,t).replace(Uh,t);return Sh(e,255)}Bc.exports=function(r,t){var e=t&&t.replacement||"",n=Ec(r,e);return e===""?n:Ec(n,"")}});var Sc=Ee(fr=>{"use strict";var Lh="[object ArrayBuffer]",Qt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Lh}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==s[o])return!1;return!0}static concat(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},Jo="string",Rh=/^[0-9a-f\s]+$/i,_h=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Dh=/^[a-zA-Z0-9-_]+$/,_n=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=Qt.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},Nt=class{static toString(t,e=!1){let n=Qt.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},Dn=class r{static isHex(t){return typeof t===Jo&&Rh.test(t)}static isBase64(t){return typeof t===Jo&&_h.test(t)}static isBase64Url(t){return typeof t===Jo&&Dh.test(t)}static ToString(t,e="utf8"){let n=Qt.toUint8Array(t);switch(e.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Nt.toString(n,!0);case"utf16":case"utf16be":return Nt.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return Nt.fromString(t,!0);case"utf16":case"utf16be":return Nt.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=Qt.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return _n.fromString(t);case"utf16":case"utf16be":return Nt.fromString(t);case"utf16le":case"usc2":return Nt.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return _n.toString(t);case"utf16":case"utf16be":return Nt.toString(t);case"utf16le":case"usc2":return Nt.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=Qt.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=Qt.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return Nt.toString(t,e)}static FromUtf16String(t,e=!1){return Nt.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};Dn.DEFAULT_UTF8_ENCODING="utf8";function Kh(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function Oh(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function Vh(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}fr.BufferSourceConverter=Qt;fr.Convert=Dn;fr.assign=Kh;fr.combine=Oh;fr.isEqual=Vh});var ed={};dt(ed,{keychain:()=>td});var yr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},tn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ai={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new tn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var xt=ai;var R=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Pe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},br=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var en=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Me=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ci=Symbol.for("@libp2p/service-capabilities"),ld=Symbol.for("@libp2p/service-dependencies");var Ts={};dt(Ts,{base58btc:()=>et,base58flickr:()=>Ul});var Ld=new Uint8Array(0);function li(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function qt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ui(r){return new TextEncoder().encode(r)}function fi(r){return new TextDecoder().decode(r)}function Sl(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var y=0,d=0,b=0,E=w.length;b!==E&&w[b]===0;)b++,y++;for(var p=(E-b)*l+1>>>0,S=new Uint8Array(p);b!==E;){for(var _=w[b],L=0,I=p-1;(_!==0||L<d)&&I!==-1;I--,L++)_+=256*S[I]>>>0,S[I]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");d=L,b++}for(var N=p-d;N!==p&&S[N]===0;)N++;for(var U=c.repeat(y);N<p;++N)U+=r.charAt(S[N]);return U}function h(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var y=0;if(w[y]!==" "){for(var d=0,b=0;w[y]===c;)d++,y++;for(var E=(w.length-y)*f+1>>>0,p=new Uint8Array(E);w[y];){var S=e[w.charCodeAt(y)];if(S===255)return;for(var _=0,L=E-1;(S!==0||_<b)&&L!==-1;L--,_++)S+=a*p[L]>>>0,p[L]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");b=_,y++}if(w[y]!==" "){for(var I=E-b;I!==E&&p[I]===0;)I++;for(var N=new Uint8Array(d+(E-I)),U=d;I!==E;)N[U++]=p[I++];return N}}}function m(w){var y=h(w);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:h,decode:m}}var kl=Sl,Cl=kl,di=Cl;var Cs=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Is=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 pi(this,t)}},Ns=class{decoders;constructor(t){this.decoders=t}or(t){return pi(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 pi(r,t){return new Ns({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Us=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new Cs(t,e,n),this.decoder=new Is(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Fe({name:r,prefix:t,encode:e,decode:n}){return new Us(r,t,e,n)}function ie({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=di(e,r);return Fe({prefix:t,name:r,encode:n,decode:o=>qt(s(o))})}function Il(r,t,e,n){let s={};for(let l=0;l<t.length;++l)s[t[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,f=0;for(let l=0;l<o;++l){let u=s[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Nl(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;(o.length*e&7)!==0;)o+="=";return o}function X({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Fe({prefix:t,name:r,encode(s){return Nl(s,n,e)},decode(s){return Il(s,n,e,r)}})}var et=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ul=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ls={};dt(Ls,{base32:()=>qe,base32hex:()=>_l,base32hexpad:()=>Kl,base32hexpadupper:()=>Ol,base32hexupper:()=>Dl,base32pad:()=>Ll,base32padupper:()=>Rl,base32upper:()=>Tl,base32z:()=>Vl});var qe=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Tl=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ll=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Rl=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_l=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Dl=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kl=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ol=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vl=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rs={};dt(Rs,{base36:()=>wr,base36upper:()=>Hl});var wr=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hl=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Pl=mi,gi=128,Ml=127,Fl=~Ml,ql=Math.pow(2,31);function mi(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ql;)t[e++]=r&255|gi,r/=128;for(;r&Fl;)t[e++]=r&255|gi,r>>>=7;return t[e]=r|0,mi.bytes=e-n+1,t}var jl=_s,$l=128,yi=127;function _s(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw _s.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&yi)<<s:(i&yi)*Math.pow(2,s),s+=7}while(i>=$l);return _s.bytes=o-n,e}var Gl=Math.pow(2,7),zl=Math.pow(2,14),Wl=Math.pow(2,21),Zl=Math.pow(2,28),Jl=Math.pow(2,35),Yl=Math.pow(2,42),Xl=Math.pow(2,49),Ql=Math.pow(2,56),tu=Math.pow(2,63),eu=function(r){return r<Gl?1:r<zl?2:r<Wl?3:r<Zl?4:r<Jl?5:r<Yl?6:r<Xl?7:r<Ql?8:r<tu?9:10},ru={encode:Pl,decode:jl,encodingLength:eu},nu=ru,xr=nu;function vr(r,t=0){return[xr.decode(r,t),xr.decode.bytes]}function je(r,t,e=0){return xr.encode(r,t,e),t}function $e(r){return xr.encodingLength(r)}function Tt(r,t){let e=t.byteLength,n=$e(r),s=n+$e(e),o=new Uint8Array(s+e);return je(r,o,0),je(e,o,n),o.set(t,s),new Ge(r,e,t,o)}function bi(r){let t=qt(r),[e,n]=vr(t),[s,o]=vr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Ge(e,s,i,t)}function wi(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&li(r.bytes,e.bytes)}}var Ge=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function xi(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ou(e,Ds(r),t??et.encoder);default:return iu(e,Ds(r),t??qe.encoder)}}var vi=new WeakMap;function Ds(r){let t=vi.get(r);if(t==null){let e=new Map;return vi.set(r,e),e}return t}var It=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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:e}=this;if(t!==Br)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==au)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=Tt(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&wi(t.multihash,n.multihash)}toString(t){return xi(this,t)}toJSON(){return{"/":xi(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??Ei(n,s,o.bytes))}else if(e[cu]===!0){let{version:n,multihash:s,code:o}=e,i=bi(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Br)throw new Error(`Version 0 CID must use dag-pb (code: ${Br}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Ei(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Br,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,s=qt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Ge(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,h]=vr(t.subarray(e));return e+=h,u},s=n(),o=Br;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),f=e+c,l=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=su(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ds(o).set(n,t),o}};function su(r,t){switch(r[0]){case"Q":{let e=t??et;return[et.prefix,e.decode(`${et.prefix}${r}`)]}case et.prefix:{let e=t??et;return[et.prefix,e.decode(r)]}case qe.prefix:{let e=t??qe;return[qe.prefix,e.decode(r)]}case wr.prefix:{let e=t??wr;return[wr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function ou(r,t,e){let{prefix:n}=e;if(n!==et.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function iu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Br=112,au=18;function Ei(r,t,e){let n=$e(r),s=n+$e(t),o=new Uint8Array(s+e.byteLength);return je(r,o,0),je(t,o,n),o.set(e,s),o}var cu=Symbol.for("@ipld/js-cid/CID");var Ks={};dt(Ks,{identity:()=>Be});var Bi=0,lu="identity",Ai=qt;function uu(r){return Tt(Bi,Ai(r))}var Be={code:Bi,name:lu,encode:Ai,digest:uu};function vt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function jt(r=0){return new Uint8Array(r)}function St(r=0){return new Uint8Array(r)}function ze(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=St(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var ki=Symbol.for("@achingbrain/uint8arraylist");function Si(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function nn(r){return!!r?.[ki]}var pt=class r{bufs;length;[ki]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(nn(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(nn(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Si(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Si(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(nn(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return ze(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:ze(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let f=t>=a&&t<c,l=e>a&&e<=c;if(f&&l){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!nn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let h=f;h>=0;h--){let m=this.get(u+h);if(n[h]!==m){l=Math.max(1,h-a[m]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=St(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=jt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=jt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=jt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=St(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=jt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=jt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=jt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=jt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=jt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!vt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};var Os={};dt(Os,{base10:()=>fu});var fu=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var Vs={};dt(Vs,{base16:()=>hu,base16upper:()=>du});var hu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),du=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hs={};dt(Hs,{base2:()=>pu});var pu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ps={};dt(Ps,{base256emoji:()=>wu});var Ci=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}"),gu=Ci.reduce((r,t,e)=>(r[e]=t,r),[]),yu=Ci.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function mu(r){return r.reduce((t,e)=>(t+=gu[e],t),"")}function bu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=yu[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var wu=Fe({prefix:"\u{1F680}",name:"base256emoji",encode:mu,decode:bu});var Ms={};dt(Ms,{base64:()=>Ae,base64pad:()=>xu,base64url:()=>vu,base64urlpad:()=>Eu});var Ae=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),xu=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vu=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Eu=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fs={};dt(Fs,{base8:()=>Bu});var Bu=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qs={};dt(qs,{identity:()=>Au});var Au=Fe({prefix:"\0",name:"identity",encode:r=>fi(r),decode:r=>ui(r)});var g0=new TextEncoder,y0=new TextDecoder;var Gs={};dt(Gs,{sha256:()=>We,sha512:()=>Cu});function $s({name:r,code:t,encode:e}){return new js(r,t,e)}var js=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Tt(this.code,e):e.then(n=>Tt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ni(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var We=$s({name:"sha2-256",code:18,encode:Ni("SHA-256")}),Cu=$s({name:"sha2-512",code:19,encode:Ni("SHA-512")});var zs={...qs,...Hs,...Fs,...Os,...Vs,...Ls,...Rs,...Ts,...Ms,...Ps},I0={...Gs,...Ks};function Ti(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ui=Ti("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ws=Ti("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=St(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Iu={utf8:Ui,"utf-8":Ui,hex:zs.base16,latin1:Ws,ascii:Ws,binary:Ws,...zs},sn=Iu;function H(r,t="utf8"){let e=sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function j(r,t="utf8"){let e=sn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Nu=parseInt("11111",2),Zs=parseInt("10000000",2),Uu=parseInt("01111111",2),Li={0:Ar,1:Ar,2:Tu,3:_u,4:Du,5:Ru,6:Lu,16:Ar,22:Ar,48:Ar};function Lt(r,t={offset:0}){let e=r[t.offset]Νif(t.offset++,Li[e]!=null)return Li[e](r,t);throw new Error("No decoder for tag "+e)}function Sr(r,t){let e=0;if((r[t.offset]&Zs)===Zs){let n=r[t.offset]&Uu,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,16)}else e=r[t.offset],t.offset++;return e}function Ar(r,t){Sr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Lt(r,t);if(n===null)break;e.push(n)}return e}function Tu(r,t){let e=Sr(r,t),n=t.offset,s=t.offset+e,o=[];for(let i=n;i<s;i++)i===n&&r[i]===0||o.push(r[i]);return t.offset+=e,Uint8Array.from(o)}function Lu(r,t){let e=Sr(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let l=0;for(let u=0;u<c.length;u++)l+=c[u]<<u*7;a+=`.${l}`,c=[]}}return a}function Ru(r,t){return t.offset++,null}function _u(r,t){let e=Sr(r,t),n=r[t.offset];t.offset++;let s=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Du(r,t){let e=Sr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Ku(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new pt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function on(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Ku(r.byteLength);return new pt(Uint8Array.from([t.byteLength|Zs]),t)}function gt(r){let t=new pt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new pt(Uint8Array.from([2]),on(t),t)}function kr(r){let t=Uint8Array.from([0]),e=new pt(t,r);return new pt(Uint8Array.from([3]),on(e),e)}function Ri(r){return new pt(Uint8Array.from([4]),on(r),r)}function Rt(r,t=48){let e=new pt;for(let n of r)e.append(n);return new pt(Uint8Array.from([t]),on(e),e)}var _i="1.2.840.10045.3.1.7",Di="1.3.132.0.34",Ki="1.3.132.0.35";async function Oi(r,t){let e=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},e,t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Vi(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Ou=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vu=Uint8Array.from([6,5,43,129,4,0,34]),Hu=Uint8Array.from([6,5,43,129,4,0,35]),Pu={ext:!0,kty:"EC",crv:"P-256"},Mu={ext:!0,kty:"EC",crv:"P-384"},Fu={ext:!0,kty:"EC",crv:"P-521"},Js=32,Ys=48,Xs=66;function Hi(r){let t=Lt(r);return Qs(t)}function Qs(r){let t=r[1],e=j(t,"base64url"),n=r[2][1][0],s=1,o,i;if(t.byteLength===Js)return o=j(n.subarray(s,s+Js),"base64url"),i=j(n.subarray(s+Js),"base64url"),new Ze({...Pu,key_ops:["sign"],d:e,x:o,y:i});if(t.byteLength===Ys)return o=j(n.subarray(s,s+Ys),"base64url"),i=j(n.subarray(s+Ys),"base64url"),new Ze({...Mu,key_ops:["sign"],d:e,x:o,y:i});if(t.byteLength===Xs)return o=j(n.subarray(s,s+Xs),"base64url"),i=j(n.subarray(s+Xs),"base64url"),new Ze({...Fu,key_ops:["sign"],d:e,x:o,y:i});throw new R(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Pi(r){return Rt([gt(Uint8Array.from([1])),Ri(H(r.d??"","base64url")),Rt([Fi(r.crv)],160),Rt([kr(new pt(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Mi(r){return Rt([gt(Uint8Array.from([1])),Rt([Fi(r.crv)],160),Rt([kr(new pt(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function Fi(r){if(r==="P-256")return Ou;if(r==="P-384")return Vu;if(r==="P-521")return Hu;throw new R(`Invalid curve ${r}`)}var an=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Mi(this.jwk)),this._raw}toMultihash(){return Be.digest(Je(this))}toCID(){return It.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:vt(this.raw,t.raw)}async verify(t,e){return Vi(this.jwk,e,t)}},Ze=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new an({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Pi(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:vt(this.raw,t.raw)}async sign(t){return Oi(this.jwk,t)}};function Ye(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function qu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xe(r,...t){if(!qu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function cn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ye(r.outputLen),Ye(r.blockLen)}function Qe(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function qi(r,t){Xe(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Se=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ke(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}function ln(r,t){return r<<t|r>>>32-t>>>0}var op=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";var ju=async()=>{};async function ji(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let o=Date.now()-n;o>=0&&o<t||(await ju(),n+=o)}}function $i(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function ae(r){return typeof r=="string"&&(r=$i(r)),Xe(r),r}function to(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Xe(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var tr=class{clone(){return this._cloneInto()}};function Gi(r,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function er(r){let t=n=>r().update(ae(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function rr(r=32){if(Se&&typeof Se.getRandomValues=="function")return Se.getRandomValues(new Uint8Array(r));if(Se&&typeof Se.randomBytes=="function")return Uint8Array.from(Se.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function $u(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}function un(r,t,e){return r&t^~r&e}function fn(r,t,e){return r&t^r&e^t&e}var ce=class extends tr{constructor(t,e,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=ke(this.buffer)}update(t){Qe(this);let{view:e,buffer:n,blockLen:s}=this;t=ae(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=ke(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Qe(this),qi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)e[u]=0;$u(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=ke(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var Gu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ue=new Uint32Array(64),eo=class extends ce{constructor(t=32){super(64,t,8,!1),this.A=le[0]|0,this.B=le[1]|0,this.C=le[2]|0,this.D=le[3]|0,this.E=le[4]|0,this.F=le[5]|0,this.G=le[6]|0,this.H=le[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)ue[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let h=ue[u-15],m=ue[u-2],w=_t(h,7)^_t(h,18)^h>>>3,y=_t(m,17)^_t(m,19)^m>>>10;ue[u]=y+ue[u-7]+w+ue[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let h=_t(a,6)^_t(a,11)^_t(a,25),m=l+h+un(a,c,f)+Gu[u]+ue[u]|0,y=(_t(n,2)^_t(n,13)^_t(n,22))+fn(n,s,o)|0;l=f,f=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+y|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,o,i,a,c,f,l)}roundClean(){ue.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var $t=er(()=>new eo);var hn=BigInt(4294967295),ro=BigInt(32);function zi(r,t=!1){return t?{h:Number(r&hn),l:Number(r>>ro&hn)}:{h:Number(r>>ro&hn)|0,l:Number(r&hn)|0}}function zu(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=zi(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Wu=(r,t)=>BigInt(r>>>0)<<ro|BigInt(t>>>0),Zu=(r,t,e)=>r>>>e,Ju=(r,t,e)=>r<<32-e|t>>>e,Yu=(r,t,e)=>r>>>e|t<<32-e,Xu=(r,t,e)=>r<<32-e|t>>>e,Qu=(r,t,e)=>r<<64-e|t>>>e-32,tf=(r,t,e)=>r>>>e-32|t<<64-e,ef=(r,t)=>t,rf=(r,t)=>r,nf=(r,t,e)=>r<<e|t>>>32-e,sf=(r,t,e)=>t<<e|r>>>32-e,of=(r,t,e)=>t<<e-32|r>>>64-e,af=(r,t,e)=>r<<e-32|t>>>64-e;function cf(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var lf=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),uf=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ff=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),hf=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,df=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),pf=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var gf={fromBig:zi,split:zu,toBig:Wu,shrSH:Zu,shrSL:Ju,rotrSH:Yu,rotrSL:Xu,rotrBH:Qu,rotrBL:tf,rotr32H:ef,rotr32L:rf,rotlSH:nf,rotlSL:sf,rotlBH:of,rotlBL:af,add:cf,add3L:lf,add3H:uf,add4L:ff,add4H:hf,add5H:pf,add5L:df},K=gf;var[yf,mf]=K.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),fe=new Uint32Array(80),he=new Uint32Array(80),no=class extends ce{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:h,Gh:m,Gl:w,Hh:y,Hl:d}=this;return[t,e,n,s,o,i,a,c,f,l,u,h,m,w,y,d]}set(t,e,n,s,o,i,a,c,f,l,u,h,m,w,y,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=h|0,this.Gh=m|0,this.Gl=w|0,this.Hh=y|0,this.Hl=d|0}process(t,e){for(let p=0;p<16;p++,e+=4)fe[p]=t.getUint32(e),he[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let S=fe[p-15]|0,_=he[p-15]|0,L=K.rotrSH(S,_,1)^K.rotrSH(S,_,8)^K.shrSH(S,_,7),I=K.rotrSL(S,_,1)^K.rotrSL(S,_,8)^K.shrSL(S,_,7),N=fe[p-2]|0,U=he[p-2]|0,W=K.rotrSH(N,U,19)^K.rotrBH(N,U,61)^K.shrSH(N,U,6),$=K.rotrSL(N,U,19)^K.rotrBL(N,U,61)^K.shrSL(N,U,6),V=K.add4L(I,$,he[p-7],he[p-16]),rt=K.add4H(V,L,W,fe[p-7],fe[p-16]);fe[p]=rt|0,he[p]=V|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:h,Fh:m,Fl:w,Gh:y,Gl:d,Hh:b,Hl:E}=this;for(let p=0;p<80;p++){let S=K.rotrSH(u,h,14)^K.rotrSH(u,h,18)^K.rotrBH(u,h,41),_=K.rotrSL(u,h,14)^K.rotrSL(u,h,18)^K.rotrBL(u,h,41),L=u&m^~u&y,I=h&w^~h&d,N=K.add5L(E,_,I,mf[p],he[p]),U=K.add5H(N,b,S,L,yf[p],fe[p]),W=N|0,$=K.rotrSH(n,s,28)^K.rotrBH(n,s,34)^K.rotrBH(n,s,39),V=K.rotrSL(n,s,28)^K.rotrBL(n,s,34)^K.rotrBL(n,s,39),rt=n&o^n&a^o&a,B=s&i^s&c^i&c;b=y|0,E=d|0,y=m|0,d=w|0,m=u|0,w=h|0,{h:u,l:h}=K.add(f|0,l|0,U|0,W|0),f=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let C=K.add3L(W,V,B);n=K.add3H(C,U,$,rt),s=C|0}({h:n,l:s}=K.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=K