@libp2p/keychain
Version:
Key management and cryptographically protected messages
2 lines • 180 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 nf=Object.create;var yn=Object.defineProperty;var sf=Object.getOwnPropertyDescriptor;var of=Object.getOwnPropertyNames;var af=Object.getPrototypeOf,cf=Object.prototype.hasOwnProperty;var xr=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},de=(r,e)=>{for(var t in e)yn(r,t,{get:e[t],enumerable:!0})},Fi=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of of(e))!cf.call(r,s)&&s!==t&&yn(r,s,{get:()=>e[s],enumerable:!(n=sf(e,s))||n.enumerable});return r};var Oi=(r,e,t)=>(t=r!=null?nf(af(r)):{},Fi(e||!r||!r.__esModule?yn(t,"default",{value:r,enumerable:!0}):t,r)),uf=r=>Fi(yn({},"__esModule",{value:!0}),r);var su=xr((zm,nu)=>{"use strict";function jh(r){return r>=55296&&r<=56319}function qh(r){return r>=56320&&r<=57343}nu.exports=function(e,t,n){if(typeof t!="string")throw new Error("Input must be string");for(var s=t.length,o=0,i,a,c=0;c<s;c+=1){if(i=t.charCodeAt(c),a=t[c],jh(i)&&qh(t.charCodeAt(c+1))&&(c+=1,a+=t[c]),o+=e(a),o===n)return t.slice(0,c+1);if(o>n)return t.slice(0,c-a.length+1)}return t}});var iu=xr((Gm,ou)=>{"use strict";function $h(r){return r>=55296&&r<=56319}function zh(r){return r>=56320&&r<=57343}ou.exports=function(e){if(typeof e!="string")throw new Error("Input must be string");for(var t=e.length,n=0,s=null,o=null,i=0;i<t;i++)s=e.charCodeAt(i),zh(s)?o!=null&&$h(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 cu=xr((Zm,au)=>{"use strict";var Gh=su(),Zh=iu();au.exports=Gh.bind(null,Zh)});var lu=xr((Ym,fu)=>{"use strict";var Yh=cu(),Wh=/[\/\?<>\\:\*\|"]/g,Xh=/[\x00-\x1f\x80-\x9f]/g,Jh=/^\.+$/,Qh=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;function ed(r,e){for(var t=r.length;t>0&&(r[t-1]==="."||r[t-1]===" ");)t--;return t<r.length?r.slice(0,t)+e:r}function uu(r,e){if(typeof r!="string")throw new Error("Input must be string");var t=r.replace(Wh,e).replace(Xh,e).replace(Jh,e).replace(Qh,e);return t=ed(t,e),Yh(t,255)}fu.exports=function(r,e){var t=e&&e.replacement||"",n=uu(r,t);return t===""?n:uu(n,"")}});var hu=xr(yr=>{"use strict";var rd="[object ArrayBuffer]",et=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===rd}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),s=r.toUint8Array(t);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(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let i of t)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of t){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}},Si="string",nd=/^[0-9a-f\s]+$/i,sd=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,od=/^[a-zA-Z0-9-_]+$/,rs=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n.buffer}static toString(e){let t=et.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Ne=class{static toString(e,t=!1){let n=et.toArrayBuffer(e),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,t);o+=String.fromCharCode(a)}return o}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),s=new DataView(n);for(let o=0;o<e.length;o++)s.setUint16(o*2,e.charCodeAt(o),t);return n}},ns=class r{static isHex(e){return typeof e===Si&&nd.test(e)}static isBase64(e){return typeof e===Si&&sd.test(e)}static isBase64Url(e){return typeof e===Si&&od.test(e)}static ToString(e,t="utf8"){let n=et.toUint8Array(e);switch(t.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 Ne.toString(n,!0);case"utf16":case"utf16be":return Ne.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Ne.fromString(e,!0);case"utf16":case"utf16be":return Ne.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=et.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return rs.fromString(e);case"utf16":case"utf16be":return Ne.fromString(e);case"utf16le":case"usc2":return Ne.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return rs.toString(e);case"utf16":case"utf16be":return Ne.toString(e);case"utf16le":case"usc2":return Ne.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return n.buffer}static ToBinary(e){let t=et.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=et.toUint8Array(e),n="",s=t.length;for(let o=0;o<s;o++){let i=t[o];i<16&&(n+="0"),n+=i.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){let o=t.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,t=!1){return Ne.toString(e,t)}static FromUtf16String(e,t=!1){return Ne.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};ns.DEFAULT_UTF8_ENCODING="utf8";function id(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)t[o]=s[o]}return t}function ad(...r){let e=r.map(s=>s.byteLength).reduce((s,o)=>s+o),t=new Uint8Array(e),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)t[n++]=o}),t.buffer}function cd(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let s=0;s<r.byteLength;s++)if(t[s]!==n[s])return!1;return!0}yr.BufferSourceConverter=et;yr.Convert=ns;yr.assign=id;yr.combine=ad;yr.isEqual=cd});var Dd={};de(Dd,{isKeychain:()=>Ud,keychain:()=>Rd});function ff(r){return r.buffer instanceof ArrayBuffer}function G(r){return ff(r)?r:r.slice()}var vr=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},Er=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},gn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var ee={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new gn("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 e}};var U=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},jt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Br=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var mn=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var qt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ki=Symbol.for("@libp2p/service-capabilities");var Xs={};de(Xs,{base58btc:()=>te,base58flickr:()=>bf});var d0=new Uint8Array(0);function Hi(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function ke(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return Bt(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return Bt(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Mi(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Vi=4096;function Pi(r){let e=r.length;if(e<=Vi)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Vi));return t}function lf(r){return r?.buffer instanceof ArrayBuffer}function Bt(r){return lf(r)?r:r.slice()}function hf(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=o,t){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=o),u!==a&&(n[u]=o)}}var l=r.length,f=r.charAt(0),h=Math.log(l)/Math.log(256),d=Math.log(256)/Math.log(l);function w(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var v=0,S=0,N=0,_=y.length;N!==_&&y[N]===0;)N++,v++;for(var O=(_-N)*d+1>>>0,R=new Uint8Array(O);N!==_;){for(var k=y[N],K=0,V=O-1;(k!==0||K<S)&&V!==-1;V--,K++)k+=256*R[V]>>>0,R[V]=k%l>>>0,k=k/l>>>0;if(k!==0)throw new Error("Non-zero carry");S=K,N++}for(var F=O-S;F!==O&&R[F]===0;)F++;for(var p=f.repeat(v);F<O;++F)p+=r.charAt(R[F]);return p}function E(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var v=0;if(y[v]!==" "){for(var S=0,N=0;y[v]===f;)S++,v++;for(var _=(y.length-v)*h+1>>>0,O=new Uint8Array(_);y[v];){var R=n[y.charCodeAt(v)];if(R===255)return;for(var k=0,K=_-1;(R!==0||k<N)&&K!==-1;K--,k++)R+=l*O[K]>>>0,O[K]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");N=k,v++}if(y[v]!==" "){for(var V=_-N;V!==_&&O[V]===0;)V++;for(var F=new Uint8Array(S+(_-V)),p=S;V!==_;)F[p++]=O[V++];return F}}}function g(y){var v=E(y);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:E,decode:g}}var df=hf,pf=df,qi=pf;var Gs=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Zs=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return $i(this,e)}},Ys=class{decoders;constructor(e){this.decoders=e}or(e){return $i(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function $i(r,e){return new Ys({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ws=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new Gs(e,t,n),this.decoder=new Zs(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $t({name:r,prefix:e,encode:t,decode:n}){return new Ws(r,e,t,n)}function at({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:o}=qi(t,r,n);return $t({prefix:e,name:r,encode:s,decode:i=>ke(o(i))})}function yf(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let l=e[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|l,i+=t,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function gf(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<t-i]),n)for(;(o.length*t&7)!==0;)o+="=";return o}function mf(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),o=r[n].toUpperCase();s!==r[n]&&(t[s]=n),o!==r[n]&&(t[o]=n)}return t}function Y({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let o=mf(n,s);return $t({prefix:e,name:r,encode(i){return gf(i,n,t)},decode(i){return yf(i,o,t,r)}})}var te=at({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bf=at({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Js={};de(Js,{base32:()=>zt,base32hex:()=>Ef,base32hexpad:()=>Af,base32hexpadupper:()=>Sf,base32hexupper:()=>Bf,base32pad:()=>xf,base32padupper:()=>vf,base32upper:()=>wf,base32z:()=>kf});var zt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),wf=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),xf=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),vf=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ef=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Bf=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Af=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Sf=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),kf=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qs={};de(Qs,{base36:()=>Ar,base36upper:()=>If});var Ar=at({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),If=at({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Cf=Zi,zi=128,Tf=127,Nf=~Tf,_f=Math.pow(2,31);function Zi(r,e,t){e=e||[],t=t||0;for(var n=t;r>=_f;)e[t++]=r&255|zi,r/=128;for(;r&Nf;)e[t++]=r&255|zi,r>>>=7;return e[t]=r|0,Zi.bytes=t-n+1,e}var Lf=eo,Rf=128,Gi=127;function eo(r,n){var t=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw eo.bytes=0,new RangeError("Could not decode varint");i=r[o++],t+=s<28?(i&Gi)<<s:(i&Gi)*Math.pow(2,s),s+=7}while(i>=Rf);return eo.bytes=o-n,t}var Uf=Math.pow(2,7),Df=Math.pow(2,14),Ff=Math.pow(2,21),Of=Math.pow(2,28),Kf=Math.pow(2,35),Vf=Math.pow(2,42),Hf=Math.pow(2,49),Mf=Math.pow(2,56),Pf=Math.pow(2,63),jf=function(r){return r<Uf?1:r<Df?2:r<Ff?3:r<Of?4:r<Kf?5:r<Vf?6:r<Hf?7:r<Mf?8:r<Pf?9:10},qf={encode:Cf,decode:Lf,encodingLength:jf},$f=qf,Sr=$f;function kr(r,e=0){return[Sr.decode(r,e),Sr.decode.bytes]}function Gt(r,e,t=0){return Sr.encode(r,e,t),e}function Zt(r){return Sr.encodingLength(r)}function Ve(r,e){let t=e.byteLength,n=Zt(r),s=n+Zt(t),o=new Uint8Array(s+t);return Gt(r,o,0),Gt(t,o,n),o.set(e,s),new Yt(r,t,e,o)}function Yi(r){let e=ke(r),[t,n]=kr(e),[s,o]=kr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Yt(t,s,i,e)}function Wi(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Hi(r.bytes,t.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=Bt(n),this.bytes=Bt(s)}};function Xi(r,e){let{bytes:t,version:n}=r;return n===0?Gf(t,to(r),e??te.encoder):Zf(t,to(r),e??zt.encoder)}var Ji=new WeakMap;function to(r){let e=Ji.get(r);if(e==null){let t=new Map;return Ji.set(r,t),t}return e}var Ie=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=Bt(s),this["/"]=this.bytes}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:e,multihash:t}=this;if(e!==Cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Yf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=Ve(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Wi(e.multihash,n.multihash)}toString(e){return Xi(this,e)}toJSON(){return{"/":Xi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:s,multihash:o,bytes:i}=t;return new r(n,s,o,i??Qi(n,s,o.bytes))}else if(t[Wf]===!0){let{version:n,multihash:s,code:o}=t,i=Yi(s);return r.create(n,o,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Cr)throw new Error(`Version 0 CID must use dag-pb (code: ${Cr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=Qi(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Cr,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,s=ke(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=s.subarray(t.multihashSize-t.digestSize),i=new Yt(t.multihashCode,t.digestSize,o,s);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,h]=kr(e.subarray(t));return t+=h,f},s=n(),o=Cr;if(s===18?(s=0,t=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,s]=zf(e,t),o=r.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return to(o).set(n,e),o}};function zf(r,e){switch(r[0]){case"Q":{let t=e??te;return[te.prefix,t.decode(`${te.prefix}${r}`)]}case te.prefix:{let t=e??te;return[te.prefix,t.decode(r)]}case zt.prefix:{let t=e??zt;return[zt.prefix,t.decode(r)]}case Ar.prefix:{let t=e??Ar;return[Ar.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Gf(r,e,t){let{prefix:n}=t;if(n!==te.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return s}function Zf(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let o=t.encode(r);return e.set(n,o),o}else return s}var Cr=112,Yf=18;function Qi(r,e,t){let n=Zt(r),s=n+Zt(e),o=new Uint8Array(s+t.byteLength);return Gt(r,o,0),Gt(e,o,n),o.set(t,s),o}var Wf=Symbol.for("@ipld/js-cid/CID");var ro={};de(ro,{identity:()=>At});var ea=0,Xf="identity",ta=ke;function Jf(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Ve(ea,ta(r))}var At={code:ea,name:Xf,encode:ta,digest:Jf};function we(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var ra="1.2.840.10045.3.1.7",na="1.3.132.0.34",sa="1.3.132.0.35";async function oa(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let s=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,G(e.subarray()));return t?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ia(r,e,t,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,G(e),G(t.subarray()));return n?.signal?.throwIfAborted(),o}function Ze(r=0){return new Uint8Array(r)}function Ae(r=0){return new Uint8Array(r)}function Qf(r){return r?.buffer instanceof ArrayBuffer}function aa(r){if(Qf(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Wt(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=Ae(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return aa(t)}var ua=Symbol.for("@achingbrain/uint8arraylist");function ca(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let s=t+n.byteLength;if(e<s)return{buf:n,index:e-t};t=s}throw new RangeError("index is out of bounds")}function wn(r){return!!r?.[ua]}var pe=class r{bufs;length;[ua]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(wn(n)){t+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(wn(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ca(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ca(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(wn(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:s}=this._subList(e,t);return Wt(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Wt(n,s)}sublist(e,t){let{bufs:n,length:s}=this._subList(e,t),o=new r;return o.length=s,o.bufs=n,o}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===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,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!wn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;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 f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let h=u;h>=0;h--){let d=this.get(f+h);if(n[h]!==d){l=Math.max(1,h-a[d]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Ae(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let s=Ze(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,t,n),this.write(s,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let s=Ze(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,t,n),this.write(s,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let s=Ze(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,t,n),this.write(s,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Ae(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let s=Ze(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,t,n),this.write(s,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let s=Ze(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,t,n),this.write(s,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let s=Ze(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,t,n),this.write(s,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let s=Ze(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,t,n),this.write(s,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let s=Ze(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,t,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!we(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((s,o)=>s+o.byteLength,0)),n.length=t,n}};var no={};de(no,{base10:()=>el});var el=at({prefix:"9",name:"base10",alphabet:"0123456789"});var so={};de(so,{base16:()=>tl,base16upper:()=>rl});var tl=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),rl=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var oo={};de(oo,{base2:()=>nl});var nl=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};de(io,{base256emoji:()=>cl});var fa=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}"),sl=fa.reduce((r,e,t)=>(r[t]=e,r),[]),ol=fa.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function il(r){return r.reduce((e,t)=>(e+=sl[t],e),"")}function al(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=ol[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var cl=$t({prefix:"\u{1F680}",name:"base256emoji",encode:il,decode:al});var ao={};de(ao,{base64:()=>St,base64pad:()=>ul,base64url:()=>fl,base64urlpad:()=>ll});var St=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ul=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fl=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ll=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var co={};de(co,{base8:()=>hl});var hl=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var uo={};de(uo,{identity:()=>dl});var dl=$t({prefix:"\0",name:"identity",encode:r=>Pi(ke(r)),decode:r=>ke(Mi(r))});var X0=new TextEncoder,J0=new TextDecoder;var ho={};de(ho,{sha256:()=>Xt,sha512:()=>ml});var gl=20;function lo({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new fo(r,e,t,n,s)}var fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??gl,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?la(n,this.code,t?.truncate):n.then(s=>la(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function la(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Ve(e,r)}function da(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Xt=lo({name:"sha2-256",code:18,encode:da("SHA-256")}),ml=lo({name:"sha2-512",code:19,encode:da("SHA-512")});var po={...uo,...oo,...co,...no,...so,...Js,...Qs,...Xs,...ao,...io},fp={...ho,...ro};function ya(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var pa=ya("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),yo=ya("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),bl={utf8:pa,"utf-8":pa,hex:po.base16,latin1:yo,ascii:yo,binary:yo,...po},xn=bl;function M(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function q(r,e="utf8"){let t=xn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var wl=parseInt("11111",2),go=parseInt("10000000",2),xl=parseInt("01111111",2),ga={0:Tr,1:Tr,2:vl,3:Al,4:Sl,5:Bl,6:El,16:Tr,22:Tr,48:Tr};function _e(r,e={offset:0}){let t=r[e.offset]&wl;if(e.offset++,ga[t]!=null)return ga[t](r,e);throw new Error("No decoder for tag "+t)}function Nr(r,e){let t=0;if((r[e.offset]&go)===go){let n=r[e.offset]&xl,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++)s+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(s,16)}else t=r[e.offset],e.offset++;return t}function Tr(r,e){Nr(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=_e(r,e);if(n===null)break;t.push(n)}return t}function vl(r,e){let t=Nr(r,e),n=e.offset,s=e.offset+t,o=[];for(let i=n;i<s;i++)i===n&&r[i]===0||o.push(r[i]);return e.offset+=t,Uint8Array.from(o)}function El(r,e){let t=Nr(r,e),n=e.offset+t,s=r[e.offset];e.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(;e.offset<n;){let u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Bl(r,e){return e.offset++,null}function Al(r,e){let t=Nr(r,e),n=r[e.offset];e.offset++;let s=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Sl(r,e){let t=Nr(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function kl(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new pe;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function vn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=kl(r.byteLength);return new pe(Uint8Array.from([e.byteLength|go]),e)}function ye(r){let e=new pe,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new pe(Uint8Array.from([2]),vn(e),e)}function _r(r){let e=Uint8Array.from([0]),t=new pe(e,r);return new pe(Uint8Array.from([3]),vn(t),t)}function ma(r){return new pe(Uint8Array.from([4]),vn(r),r)}function Le(r,e=48){let t=new pe;for(let n of r)t.append(n);return new pe(Uint8Array.from([e]),vn(t),t)}var Il=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Cl=Uint8Array.from([6,5,43,129,4,0,34]),Tl=Uint8Array.from([6,5,43,129,4,0,35]),Nl={ext:!0,kty:"EC",crv:"P-256"},_l={ext:!0,kty:"EC",crv:"P-384"},Ll={ext:!0,kty:"EC",crv:"P-521"},mo=32,bo=48,wo=66;function ba(r){let e=_e(r);return xo(e)}function xo(r){let e=r[1],t=q(e,"base64url"),n=r[2][1][0],s=1,o,i;if(e.byteLength===mo)return o=q(n.subarray(s,s+mo),"base64url"),i=q(n.subarray(s+mo),"base64url"),new Jt({...Nl,key_ops:["sign"],d:t,x:o,y:i});if(e.byteLength===bo)return o=q(n.subarray(s,s+bo),"base64url"),i=q(n.subarray(s+bo),"base64url"),new Jt({..._l,key_ops:["sign"],d:t,x:o,y:i});if(e.byteLength===wo)return o=q(n.subarray(s,s+wo),"base64url"),i=q(n.subarray(s+wo),"base64url"),new Jt({...Ll,key_ops:["sign"],d:t,x:o,y:i});throw new U(`Private key length was wrong length, got ${e.byteLength}, expected 32, 48 or 66`)}function wa(r){return Le([ye(Uint8Array.from([1])),ma(M(r.d??"","base64url")),Le([va(r.crv)],160),Le([_r(new pe(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function xa(r){return Le([ye(Uint8Array.from([1])),Le([va(r.crv)],160),Le([_r(new pe(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function va(r){if(r==="P-256")return Il;if(r==="P-384")return Cl;if(r==="P-521")return Tl;throw new U(`Invalid curve ${r}`)}var En=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=xa(this.jwk)),this._raw}toMultihash(){return At.digest(Qt(this))}toCID(){return Ie.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}async verify(e,t,n){return ia(this.jwk,t,e,n)}},Jt=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new En({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=wa(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:we(this.raw,e.raw)}async sign(e,t){return oa(this.jwk,e,t)}};function vo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Ce(r,e=""){if(typeof r!="number"){let t=e&&`"${e}" `;throw new TypeError(`${t}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new RangeError(`${t}expected integer >= 0, got ${r}`)}}function xe(r,e,t=""){let n=vo(r),s=r?.length,o=e!==void 0;if(!n||o&&s!==e){let i=t&&`"${t}" `,a=o?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof r}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return r}function er(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Ce(r.outputLen),Ce(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function tr(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Bn(r,e){xe(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new RangeError('"digestInto() output" expected to be of length >='+t)}function ve(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function kt(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Re(r,e){return r<<32-e|r>>>e}function An(r,e){return r<<e|r>>>32-e>>>0}var Ba=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Rl=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function Sn(r){if(xe(r),Ba)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=Rl[r[t]];return e}var Ye={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ea(r){if(r>=Ye._0&&r<=Ye._9)return r-Ye._0;if(r>=Ye.A&&r<=Ye.F)return r-(Ye.A-10);if(r>=Ye.a&&r<=Ye.f)return r-(Ye.a-10)}function Lr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Ba)try{return Uint8Array.fromHex(r)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=r.length,t=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let s=0,o=0;s<t;s++,o+=2){let i=Ea(r.charCodeAt(o)),a=Ea(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}var Ul=async()=>{};async function Aa(r,e,t){let n=Date.now();for(let s=0;s<r;s++){t(s);let o=Date.now()-n;o>=0&&o<e||(await Ul(),n+=o)}}function Dl(r){if(typeof r!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Eo(r,e=""){return typeof r=="string"?Dl(r):xe(r,void 0,e)}function Bo(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];xe(s),e+=s.length}let t=new Uint8Array(e);for(let n=0,s=0;n<r.length;n++){let o=r[n];t.set(o,s),s+=o.length}return t}function Sa(r,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(r,e)}function Rr(r,e={}){let t=(s,o)=>r(o).update(s).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.canXOF=n.canXOF,t.create=s=>r(s),Object.assign(t,e),Object.freeze(t)}function ka(r=32){Ce(r,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return e.getRandomValues(new Uint8Array(r))}var Ao=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function kn(r,e,t){return r&e^~r&t}function In(r,e,t){return r&e^r&t^e&t}var It=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,s){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=kt(this.buffer)}update(e){tr(this),xe(e);let{view:t,buffer:n,blockLen:s}=this,o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=kt(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tr(this),Bn(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,ve(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)t[f]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=kt(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=o,e.length=s,e.pos=a,s%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},We=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ce=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Cn=BigInt(4294967295),Ia=BigInt(32);function Fl(r,e=!1){return e?{h:Number(r&Cn),l:Number(r>>Ia&Cn)}:{h:Number(r>>Ia&Cn)|0,l:Number(r&Cn)|0}}function Ca(r,e=!1){let t=r.length,n=new Uint32Array(t),s=new Uint32Array(t);for(let o=0;o<t;o++){let{h:i,l:a}=Fl(r[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var So=(r,e,t)=>r>>>t,ko=(r,e,t)=>r<<32-t|e>>>t,Ct=(r,e,t)=>r>>>t|e<<32-t,Tt=(r,e,t)=>r<<32-t|e>>>t,Ur=(r,e,t)=>r<<64-t|e>>>t-32,Dr=(r,e,t)=>r>>>t-32|e<<64-t;function He(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Ta=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Na=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,_a=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),La=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,Ra=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),Ua=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Kl=Uint32Array.from([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]),ct=new Uint32Array(64),Io=class extends It{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,t,n,s,o,i,a,c]}set(e,t,n,s,o,i,a,c){this.A=e|0,this.B=t|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(e,t){for(let f=0;f<16;f++,t+=4)ct[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=ct[f-15],d=ct[f-2],w=Re(h,7)^Re(h,18)^h>>>3,E=Re(d,17)^Re(d,19)^d>>>10;ct[f]=E+ct[f-7]+w+ct[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=Re(a,6)^Re(a,11)^Re(a,25),d=l+h+kn(a,c,u)+Kl[f]+ct[f]|0,E=(Re(n,2)^Re(n,13)^Re(n,22))+In(n,s,o)|0;l=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+E|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,u=u+this.G|0,l=l+this.H|0,this.set(n,s,o,i,a,c,u,l)}roundClean(){ve(ct)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ve(this.buffer)}},Co=class extends Io{A=We[0]|0;B=We[1]|0;C=We[2]|0;D=We[3]|0;E=We[4]|0;F=We[5]|0;G=We[6]|0;H=We[7]|0;constructor(){super(32)}};var Da=Ca(["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))),Vl=Da[0],Hl=Da[1],ut=new Uint32Array(80),ft=new Uint32Array(80),To=class extends It{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:d,Gl:w,Hh:E,Hl:g}=this;return[e,t,n,s,o,i,a,c,u,l,f,h,d,w,E,g]}set(e