@libp2p/keychain
Version:
Key management and cryptographically protected messages
2 lines • 179 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 tf=Object.create;var pn=Object.defineProperty;var rf=Object.getOwnPropertyDescriptor;var nf=Object.getOwnPropertyNames;var sf=Object.getPrototypeOf,of=Object.prototype.hasOwnProperty;var wr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),he=(r,e)=>{for(var t in e)pn(r,t,{get:e[t],enumerable:!0})},Fi=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of nf(e))!of.call(r,s)&&s!==t&&pn(r,s,{get:()=>e[s],enumerable:!(n=rf(e,s))||n.enumerable});return r};var Oi=(r,e,t)=>(t=r!=null?tf(sf(r)):{},Fi(e||!r||!r.__esModule?pn(t,"default",{value:r,enumerable:!0}):t,r)),af=r=>Fi(pn({},"__esModule",{value:!0}),r);var ru=wr((jy,tu)=>{"use strict";function Kh(r){return r>=55296&&r<=56319}function Vh(r){return r>=56320&&r<=57343}tu.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],Kh(i)&&Vh(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 su=wr((qy,nu)=>{"use strict";function Hh(r){return r>=55296&&r<=56319}function Mh(r){return r>=56320&&r<=57343}nu.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),Mh(s)?o!=null&&Hh(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 iu=wr(($y,ou)=>{"use strict";var Ph=ru(),jh=su();ou.exports=Ph.bind(null,jh)});var uu=wr((zy,cu)=>{"use strict";var qh=iu(),$h=/[\/\?<>\\:\*\|"]/g,zh=/[\x00-\x1f\x80-\x9f]/g,Gh=/^\.+$/,Zh=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;function Yh(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 au(r,e){if(typeof r!="string")throw new Error("Input must be string");var t=r.replace($h,e).replace(zh,e).replace(Gh,e).replace(Zh,e);return t=Yh(t,e),qh(t,255)}cu.exports=function(r,e){var t=e&&e.replacement||"",n=au(r,t);return t===""?n:au(n,"")}});var fu=wr(pr=>{"use strict";var Xh="[object ArrayBuffer]",Qe=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Xh}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",Jh=/^[0-9a-f\s]+$/i,Qh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ed=/^[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=Qe.toUint8Array(e),n="";for(let o=0;o<t.length;o++)n+=String.fromCharCode(t[o]);return decodeURIComponent(escape(n))}},Ce=class{static toString(e,t=!1){let n=Qe.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&&Jh.test(e)}static isBase64(e){return typeof e===Si&&Qh.test(e)}static isBase64Url(e){return typeof e===Si&&ed.test(e)}static ToString(e,t="utf8"){let n=Qe.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 Ce.toString(n,!0);case"utf16":case"utf16be":return Ce.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 Ce.fromString(e,!0);case"utf16":case"utf16be":return Ce.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Qe.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 Ce.fromString(e);case"utf16le":case"usc2":return Ce.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 Ce.toString(e);case"utf16le":case"usc2":return Ce.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=Qe.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return n}static ToHex(e){let t=Qe.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 Ce.toString(e,t)}static FromUtf16String(e,t=!1){return Ce.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 td(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 rd(...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 nd(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}pr.BufferSourceConverter=Qe;pr.Convert=ns;pr.assign=td;pr.combine=rd;pr.isEqual=nd});var Nd={};he(Nd,{isKeychain:()=>Td,keychain:()=>Cd});var xr=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},vr=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 Ki={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 Q=Ki;var U=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Pt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},Er=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 jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Vi=Symbol.for("@libp2p/service-capabilities");var Xs={};he(Xs,{base58btc:()=>ee,base58flickr:()=>pf});var u0=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 ze(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 Mi(r){return new TextEncoder().encode(r)}function Pi(r){return new TextDecoder().decode(r)}function cf(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(t[i]!==255)throw new TypeError(o+" is ambiguous");t[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,g=0,y=0,E=m.length;y!==E&&m[y]===0;)y++,x++;for(var A=(E-y)*l+1>>>0,N=new Uint8Array(A);y!==E;){for(var _=m[y],F=0,R=A-1;(_!==0||F<g)&&R!==-1;R--,F++)_+=256*N[R]>>>0,N[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");g=F,y++}for(var C=A-g;C!==A&&N[C]===0;)C++;for(var O=c.repeat(x);C<A;++C)O+=r.charAt(N[C]);return O}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var g=0,y=0;m[x]===c;)g++,x++;for(var E=(m.length-x)*u+1>>>0,A=new Uint8Array(E);m[x];){var N=t[m.charCodeAt(x)];if(N===255)return;for(var _=0,F=E-1;(N!==0||_<y)&&F!==-1;F--,_++)N+=a*A[F]>>>0,A[F]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");y=_,x++}if(m[x]!==" "){for(var R=E-y;R!==E&&A[R]===0;)R++;for(var C=new Uint8Array(g+(E-R)),O=g;R!==E;)C[O++]=A[R++];return C}}}function d(m){var x=h(m);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:d}}var uf=cf,ff=uf,qi=ff;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 qt({name:r,prefix:e,encode:t,decode:n}){return new Ws(r,e,t,n)}function it({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=qi(t,r);return qt({prefix:e,name:r,encode:n,decode:o=>ze(s(o))})}function lf(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 hf(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 df(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Z({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let s=df(n);return qt({prefix:e,name:r,encode(o){return hf(o,n,t)},decode(o){return lf(o,s,t,r)}})}var ee=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pf=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Js={};he(Js,{base32:()=>$t,base32hex:()=>bf,base32hexpad:()=>xf,base32hexpadupper:()=>vf,base32hexupper:()=>wf,base32pad:()=>mf,base32padupper:()=>yf,base32upper:()=>gf,base32z:()=>Ef});var $t=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),gf=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mf=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yf=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),bf=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),wf=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xf=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vf=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ef=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Qs={};he(Qs,{base36:()=>Br,base36upper:()=>Bf});var Br=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Bf=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Af=Zi,zi=128,Sf=127,kf=~Sf,If=Math.pow(2,31);function Zi(r,e,t){e=e||[],t=t||0;for(var n=t;r>=If;)e[t++]=r&255|zi,r/=128;for(;r&kf;)e[t++]=r&255|zi,r>>>=7;return e[t]=r|0,Zi.bytes=t-n+1,e}var Cf=eo,Tf=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>=Tf);return eo.bytes=o-n,t}var Nf=Math.pow(2,7),_f=Math.pow(2,14),Lf=Math.pow(2,21),Rf=Math.pow(2,28),Uf=Math.pow(2,35),Df=Math.pow(2,42),Ff=Math.pow(2,49),Of=Math.pow(2,56),Kf=Math.pow(2,63),Vf=function(r){return r<Nf?1:r<_f?2:r<Lf?3:r<Rf?4:r<Uf?5:r<Df?6:r<Ff?7:r<Of?8:r<Kf?9:10},Hf={encode:Af,decode:Cf,encodingLength:Vf},Mf=Hf,Ar=Mf;function Sr(r,e=0){return[Ar.decode(r,e),Ar.decode.bytes]}function zt(r,e,t=0){return Ar.encode(r,e,t),e}function Gt(r){return Ar.encodingLength(r)}function Oe(r,e){let t=e.byteLength,n=Gt(r),s=n+Gt(t),o=new Uint8Array(s+t);return zt(r,o,0),zt(t,o,n),o.set(e,s),new Zt(r,t,e,o)}function Yi(r){let e=ze(r),[t,n]=Sr(e),[s,o]=Sr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Zt(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 Zt=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=n,this.bytes=s}};function Xi(r,e){let{bytes:t,version:n}=r;return n===0?jf(t,to(r),e??ee.encoder):qf(t,to(r),e??$t.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 Se=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==$f)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=Oe(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[zf]===!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!==Ir)throw new Error(`Version 0 CID must use dag-pb (code: ${Ir}) 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,Ir,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=ze(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 Zt(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]=Sr(e.subarray(t));return t+=h,f},s=n(),o=Ir;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]=Pf(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 Pf(r,e){switch(r[0]){case"Q":{let t=e??ee;return[ee.prefix,t.decode(`${ee.prefix}${r}`)]}case ee.prefix:{let t=e??ee;return[ee.prefix,t.decode(r)]}case $t.prefix:{let t=e??$t;return[$t.prefix,t.decode(r)]}case Br.prefix:{let t=e??Br;return[Br.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 jf(r,e,t){let{prefix:n}=t;if(n!==ee.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 qf(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 Ir=112,$f=18;function Qi(r,e,t){let n=Gt(r),s=n+Gt(e),o=new Uint8Array(s+t.byteLength);return zt(r,o,0),zt(e,o,n),o.set(t,s),o}var zf=Symbol.for("@ipld/js-cid/CID");var ro={};he(ro,{identity:()=>Et});var ea=0,Gf="identity",ta=ze;function Zf(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 Oe(ea,ta(r))}var Et={code:ea,name:Gf,encode:ta,digest:Zf};function be(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,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,e,t.subarray());return n?.signal?.throwIfAborted(),o}function Ge(r=0){return new Uint8Array(r)}function Be(r=0){return new Uint8Array(r)}function Yt(r,e){e==null&&(e=r.reduce((s,o)=>s+o.length,0));let t=Be(e),n=0;for(let s of r)t.set(s,n),n+=s.length;return t}var ca=Symbol.for("@achingbrain/uint8arraylist");function aa(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 bn(r){return!!r?.[ca]}var de=class r{bufs;length;[ca]=!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(bn(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(bn(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=aa(this.bufs,e);return t.buf[t.index]}set(e,t){let n=aa(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(bn(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 Yt(n,s)}subarray(e,t){let{bufs:n,length:s}=this._subList(e,t);return n.length===1?n[0]:Yt(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(!bn(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=Be(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=Ge(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=Ge(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=Ge(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=Be(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=Ge(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=Ge(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=Ge(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=Ge(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=Ge(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(!be(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={};he(no,{base10:()=>Yf});var Yf=it({prefix:"9",name:"base10",alphabet:"0123456789"});var so={};he(so,{base16:()=>Wf,base16upper:()=>Xf});var Wf=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xf=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var oo={};he(oo,{base2:()=>Jf});var Jf=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};he(io,{base256emoji:()=>nl});var ua=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}"),Qf=ua.reduce((r,e,t)=>(r[t]=e,r),[]),el=ua.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function tl(r){return r.reduce((e,t)=>(e+=Qf[t],e),"")}function rl(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=el[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var nl=qt({prefix:"\u{1F680}",name:"base256emoji",encode:tl,decode:rl});var ao={};he(ao,{base64:()=>Bt,base64pad:()=>sl,base64url:()=>ol,base64urlpad:()=>il});var Bt=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sl=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ol=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),il=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var co={};he(co,{base8:()=>al});var al=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var uo={};he(uo,{identity:()=>cl});var cl=qt({prefix:"\0",name:"identity",encode:r=>Pi(r),decode:r=>Mi(r)});var G0=new TextEncoder,Z0=new TextDecoder;var ho={};he(ho,{sha256:()=>Wt,sha512:()=>hl});var ll=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??ll,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?fa(n,this.code,t?.truncate):n.then(s=>fa(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function fa(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 Oe(e,r)}function ha(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Wt=lo({name:"sha2-256",code:18,encode:ha("SHA-256")}),hl=lo({name:"sha2-512",code:19,encode:ha("SHA-512")});var po={...uo,...oo,...co,...no,...so,...Js,...Qs,...Xs,...ao,...io},ip={...ho,...ro};function pa(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var da=pa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),go=pa("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=Be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),dl={utf8:da,"utf-8":da,hex:po.base16,latin1:go,ascii:go,binary:go,...po},wn=dl;function H(r,e="utf8"){let t=wn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function j(r,e="utf8"){let t=wn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var pl=parseInt("11111",2),mo=parseInt("10000000",2),gl=parseInt("01111111",2),ga={0:Cr,1:Cr,2:ml,3:wl,4:xl,5:bl,6:yl,16:Cr,22:Cr,48:Cr};function Te(r,e={offset:0}){let t=r[e.offset]&pl;if(e.offset++,ga[t]!=null)return ga[t](r,e);throw new Error("No decoder for tag "+t)}function Tr(r,e){let t=0;if((r[e.offset]&mo)===mo){let n=r[e.offset]&gl,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 Cr(r,e){Tr(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=Te(r,e);if(n===null)break;t.push(n)}return t}function ml(r,e){let t=Tr(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 yl(r,e){let t=Tr(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 wl(r,e){let t=Tr(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 xl(r,e){let t=Tr(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function vl(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new de;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function xn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=vl(r.byteLength);return new de(Uint8Array.from([e.byteLength|mo]),e)}function pe(r){let e=new de,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new de(Uint8Array.from([2]),xn(e),e)}function Nr(r){let e=Uint8Array.from([0]),t=new de(e,r);return new de(Uint8Array.from([3]),xn(t),t)}function ma(r){return new de(Uint8Array.from([4]),xn(r),r)}function Ne(r,e=48){let t=new de;for(let n of r)t.append(n);return new de(Uint8Array.from([e]),xn(t),t)}var El=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Bl=Uint8Array.from([6,5,43,129,4,0,34]),Al=Uint8Array.from([6,5,43,129,4,0,35]),Sl={ext:!0,kty:"EC",crv:"P-256"},kl={ext:!0,kty:"EC",crv:"P-384"},Il={ext:!0,kty:"EC",crv:"P-521"},yo=32,bo=48,wo=66;function ya(r){let e=Te(r);return xo(e)}function xo(r){let e=r[1],t=j(e,"base64url"),n=r[2][1][0],s=1,o,i;if(e.byteLength===yo)return o=j(n.subarray(s,s+yo),"base64url"),i=j(n.subarray(s+yo),"base64url"),new Xt({...Sl,key_ops:["sign"],d:t,x:o,y:i});if(e.byteLength===bo)return o=j(n.subarray(s,s+bo),"base64url"),i=j(n.subarray(s+bo),"base64url"),new Xt({...kl,key_ops:["sign"],d:t,x:o,y:i});if(e.byteLength===wo)return o=j(n.subarray(s,s+wo),"base64url"),i=j(n.subarray(s+wo),"base64url"),new Xt({...Il,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 ba(r){return Ne([pe(Uint8Array.from([1])),ma(H(r.d??"","base64url")),Ne([xa(r.crv)],160),Ne([Nr(new de(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function wa(r){return Ne([pe(Uint8Array.from([1])),Ne([xa(r.crv)],160),Ne([Nr(new de(Uint8Array.from([4]),H(r.x??"","base64url"),H(r.y??"","base64url")))],161)]).subarray()}function xa(r){if(r==="P-256")return El;if(r==="P-384")return Bl;if(r==="P-521")return Al;throw new U(`Invalid curve ${r}`)}var vn=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=wa(this.jwk)),this._raw}toMultihash(){return Et.digest(Jt(this))}toCID(){return Se.createV1(114,this.toMultihash())}toString(){return ee.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}async verify(e,t,n){return ia(this.jwk,t,e,n)}},Xt=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new vn({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=ba(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(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 ke(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 we(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 Qt(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ke(r.outputLen),ke(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function er(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 En(r,e){we(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 xe(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function At(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _e(r,e){return r<<32-e|r>>>e}function Bn(r,e){return r<<e|r>>>32-e>>>0}var Ea=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cl=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function An(r){if(we(r),Ea)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=Cl[r[t]];return e}var Ze={_0:48,_9:57,A:65,F:70,a:97,f:102};function va(r){if(r>=Ze._0&&r<=Ze._9)return r-Ze._0;if(r>=Ze.A&&r<=Ze.F)return r-(Ze.A-10);if(r>=Ze.a&&r<=Ze.f)return r-(Ze.a-10)}function _r(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Ea)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=va(r.charCodeAt(o)),a=va(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 Tl=async()=>{};async function Ba(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 Tl(),n+=o)}}function Nl(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"?Nl(r):we(r,void 0,e)}function Bo(...r){let e=0;for(let n=0;n<r.length;n++){let s=r[n];we(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 Aa(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 Lr(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 Sn(r=32){ke(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 St=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=At(this.buffer)}update(e){er(this),we(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=At(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){er(this),En(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;t[i++]=128,xe(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=At(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()}},Ye=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ae=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Cn=BigInt(4294967295),Sa=BigInt(32);function _l(r,e=!1){return e?{h:Number(r&Cn),l:Number(r>>Sa&Cn)}:{h:Number(r>>Sa&Cn)|0,l:Number(r&Cn)|0}}function ka(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}=_l(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,kt=(r,e,t)=>r>>>t|e<<32-t,It=(r,e,t)=>r<<32-t|e>>>t,Rr=(r,e,t)=>r<<64-t|e>>>t-32,Ur=(r,e,t)=>r>>>t-32|e<<64-t;function Ke(r,e,t,n){let s=(e>>>0)+(n>>>0);return{h:r+t+(s/2**32|0)|0,l:s|0}}var Ia=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Ca=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Ta=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Na=(r,e,t,n,s)=>e+t+n+s+(r/2**32|0)|0,_a=(r,e,t,n,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(s>>>0),La=(r,e,t,n,s,o)=>e+t+n+s+o+(r/2**32|0)|0;var Rl=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]),at=new Uint32Array(64),Io=class extends St{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)at[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=at[f-15],d=at[f-2],m=_e(h,7)^_e(h,18)^h>>>3,x=_e(d,17)^_e(d,19)^d>>>10;at[f]=x+at[f-7]+m+at[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=_e(a,6)^_e(a,11)^_e(a,25),d=l+h+kn(a,c,u)+Rl[f]+at[f]|0,x=(_e(n,2)^_e(n,13)^_e(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+x|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(){xe(at)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),xe(this.buffer)}},Co=class extends Io{A=Ye[0]|0;B=Ye[1]|0;C=Ye[2]|0;D=Ye[3]|0;E=Ye[4]|0;F=Ye[5]|0;G=Ye[6]|0;H=Ye[7]|0;constructor(){super(32)}};var Ra=ka(["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))),Ul=Ra[0],Dl=Ra[1],ct=new Uint32Array(80),ut=new Uint32Array(80),To=class extends St{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:m,Hh:x,Hl:g}=this;return[e,t,n,s,o,i,a,c,u,l,f,h,d,m,x,g]}set(e,t,n,s,o,i,a,c,u,l,f,h,d,m,x,g){this.Ah=e|0,this.Al=t|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=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=x|0,this.Hl=g|0}process(e,t){for(let A=0;A<16;A++,t+=4)ct[A]=e.getUint32(t),ut[A]=e.getUint32(t+=4);for(let A=16;A<80;A++){let N=ct[A-15]|0,_=ut[A-15]|0,F=kt(N,_,1)^kt(N,_,8)^So(N,_,7),R=It(N,_,1)^It(N,_,8)^ko(N,_,7),C=ct[A-2]|0,O=ut[A-2]|0,z=kt(C,O,19)^Rr(C,O,61)^So(C,O,6),K=It(C,O,19)^Ur(C,O,61)^ko(C,O,6),p=Ta(R,K,ut[A-7],ut[A-16]),b=Na(p,F,z,ct[A-7],ct[A-16]);ct[A]=b|0,ut[A]=p|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:d,Fl:m,Gh:x,Gl:g,Hh:y,Hl:E}=this;for(let A=0;A<80;A++){let N=kt(f,h,14)^kt(f,h,18)^Rr(f,h,41),_=It(f,h,14)^It(f,h,18)^Ur(f,h,41),F=f&d^~f&x,R=h&m^~h&g,C=_a(E,_,R,Dl[A],ut[A]),O=La(C,y,N,F,Ul[A],ct[A]),z=C|0,K=kt(n,s,28)^Rr(n,s,34)^Rr(n,s,39),p=It(n,s,28)^Ur(n,s,34)^Ur(n,s,39),b=n&o^n&a^o&a,B=s&i^s&c^i&c;y=x|0,E=g|0,x=d|0,g=m|0,d=f|0,m=h|0,{h:f,l:h}=Ke(u|0,l|0,O|0,z|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let v=Ia(z,p,B);n