UNPKG

@libp2p/crypto

Version:
2 lines • 117 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var Libp2PCrypto=(()=>{var dn=Object.defineProperty;var Aa=Object.getOwnPropertyDescriptor;var va=Object.getOwnPropertyNames;var Ba=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var r in t)dn(e,r,{get:t[r],enumerable:!0})},_a=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of va(t))!Ba.call(e,o)&&o!==r&&dn(e,o,{get:()=>t[o],enumerable:!(n=Aa(t,o))||n.enumerable});return e};var Ia=e=>_a(dn({},"__esModule",{value:!0}),e);var xu={};it(xu,{hmac:()=>_r,keys:()=>Xo,pbkdf2:()=>Jo,randomBytes:()=>Uo});var _r={};it(_r,{create:()=>pn});var ze=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Ze=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Br=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var es={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Br("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Y=es;var rs={SHA1:20,SHA256:32,SHA512:64};var Ta={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},La=async(e,t)=>{let r=await Y.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function pn(e,t){let r=Ta[e],n=await Y.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return La(n,o)},length:rs[e]}}var Xo={};it(Xo,{generateEphemeralKeyPair:()=>ba,generateKeyPair:()=>ou,generateKeyPairFromSeed:()=>su,keyStretcher:()=>ga,privateKeyFromCryptoKeyPair:()=>mu,privateKeyFromProtobuf:()=>fu,privateKeyFromRaw:()=>uu,privateKeyToCryptoKeyPair:()=>pu,privateKeyToProtobuf:()=>lu,publicKeyFromMultihash:()=>cu,publicKeyFromProtobuf:()=>iu,publicKeyFromRaw:()=>au,publicKeyToProtobuf:()=>se});var k=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ye=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var qt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var gn={};it(gn,{base58btc:()=>rt,base58flickr:()=>Oa});var Lu=new Uint8Array(0);function ns(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ft(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function os(e){return new TextEncoder().encode(e)}function ss(e){return new TextDecoder().decode(e)}function Ra(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(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 E=0,d=0,y=0,S=m.length;y!==S&&m[y]===0;)y++,E++;for(var B=(S-y)*u+1>>>0,D=new Uint8Array(B);y!==S;){for(var L=m[y],U=0,K=B-1;(L!==0||U<d)&&K!==-1;K--,U++)L+=256*D[K]>>>0,D[K]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");d=U,y++}for(var I=B-d;I!==B&&D[I]===0;)I++;for(var F=f.repeat(E);I<B;++I)F+=e.charAt(D[I]);return F}function b(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var d=0,y=0;m[E]===f;)d++,E++;for(var S=(m.length-E)*c+1>>>0,B=new Uint8Array(S);m[E];){var D=r[m.charCodeAt(E)];if(D===255)return;for(var L=0,U=S-1;(D!==0||L<y)&&U!==-1;U--,L++)D+=a*B[U]>>>0,B[U]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");y=L,E++}if(m[E]!==" "){for(var K=S-y;K!==S&&B[K]===0;)K++;for(var I=new Uint8Array(d+(S-K)),F=d;K!==S;)I[F++]=B[K++];return I}}}function p(m){var E=b(m);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:p}}var Da=Ra,Ka=Da,as=Ka;var mn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},yn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},bn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cs(e,t){return new bn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var xn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new mn(t,r,n),this.decoder=new yn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:e,prefix:t,encode:r,decode:n}){return new xn(e,t,r,n)}function Vt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=as(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>Ft(o(s))})}function Ca(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ua(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Fa(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Fa(n);return ge({prefix:t,name:e,encode(s){return Ua(s,n,r)},decode(s){return Ca(s,o,r,e)}})}var rt=Vt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Oa=Vt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wn={};it(wn,{base32:()=>we,base32hex:()=>Ha,base32hexpad:()=>qa,base32hexpadupper:()=>Va,base32hexupper:()=>Ma,base32pad:()=>Pa,base32padupper:()=>Na,base32upper:()=>ka,base32z:()=>ja});var we=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ka=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pa=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Na=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ha=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ma=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qa=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Va=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ja=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};it(En,{base36:()=>$e,base36upper:()=>za});var $e=Vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),za=Vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Za=ls,fs=128,Ya=127,$a=~Ya,Ga=Math.pow(2,31);function ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ga;)t[r++]=e&255|fs,e/=128;for(;e&$a;)t[r++]=e&255|fs,e>>>=7;return t[r]=e|0,ls.bytes=r-n+1,t}var Xa=Sn,Wa=128,us=127;function Sn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Sn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&us)<<o:(i&us)*Math.pow(2,o),o+=7}while(i>=Wa);return Sn.bytes=s-n,r}var Ja=Math.pow(2,7),Qa=Math.pow(2,14),tc=Math.pow(2,21),ec=Math.pow(2,28),rc=Math.pow(2,35),nc=Math.pow(2,42),oc=Math.pow(2,49),sc=Math.pow(2,56),ic=Math.pow(2,63),ac=function(e){return e<Ja?1:e<Qa?2:e<tc?3:e<ec?4:e<rc?5:e<nc?6:e<oc?7:e<sc?8:e<ic?9:10},cc={encode:Za,decode:Xa,encodingLength:ac},fc=cc,Ge=fc;function Xe(e,t=0){return[Ge.decode(e,t),Ge.decode.bytes]}function Ee(e,t,r=0){return Ge.encode(e,t,r),t}function Se(e){return Ge.encodingLength(e)}function Lt(e,t){let r=t.byteLength,n=Se(e),o=n+Se(r),s=new Uint8Array(o+r);return Ee(e,s,0),Ee(r,s,n),s.set(t,o),new Ae(e,r,t,s)}function hs(e){let t=Ft(e),[r,n]=Xe(t),[o,s]=Xe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ae(r,o,i,t)}function ds(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ns(e.bytes,r.bytes)}}var Ae=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ps(e,t){let{bytes:r,version:n}=e;return n===0?lc(r,An(e),t??rt.encoder):hc(r,An(e),t??we.encoder)}var ms=new WeakMap;function An(e){let t=ms.get(e);if(t==null){let r=new Map;return ms.set(e,r),r}return t}var gt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==dc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Lt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ds(t.multihash,n.multihash)}toString(t){return ps(this,t)}toJSON(){return{"/":ps(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ys(n,o,s.bytes))}else if(r[pc]===!0){let{version:n,multihash:o,code:s}=r,i=hs(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ys(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Je,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ft(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ae(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,b]=Xe(t.subarray(r));return r+=b,l},o=n(),s=Je;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=uc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return An(s).set(n,t),s}};function uc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case we.prefix:{let r=t??we;return[we.prefix,r.decode(e)]}case $e.prefix:{let r=t??$e;return[$e.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function lc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function hc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Je=112,dc=18;function ys(e,t,r){let n=Se(e),o=n+Se(t),s=new Uint8Array(o+r.byteLength);return Ee(e,s,0),Ee(t,s,n),s.set(r,o),s}var pc=Symbol.for("@ipld/js-cid/CID");var vn={};it(vn,{identity:()=>ne});var bs=0,mc="identity",xs=Ft;function yc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Lt(bs,xs(e))}var ne={code:bs,name:mc,encode:xs,digest:yc};function at(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var Bn="1.2.840.10045.3.1.7",_n="1.3.132.0.34",In="1.3.132.0.35";async function gs(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function ws(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Es(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}function Ot(e=0){return new Uint8Array(e)}function mt(e=0){return new Uint8Array(e)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=mt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var As=Symbol.for("@achingbrain/uint8arraylist");function Ss(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Tr(e){return!!e?.[As]}var ft=class e{bufs;length;[As]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Tr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Tr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ss(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ss(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Tr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Tr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let b=c;b>=0;b--){let p=this.get(l+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!at(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Tn={};it(Tn,{base10:()=>bc});var bc=Vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ln={};it(Ln,{base16:()=>xc,base16upper:()=>gc});var xc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};it(Rn,{base2:()=>wc});var wc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Dn={};it(Dn,{base256emoji:()=>Bc});var vs=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}"),Ec=vs.reduce((e,t,r)=>(e[r]=t,e),[]),Sc=vs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ac(e){return e.reduce((t,r)=>(t+=Ec[r],t),"")}function vc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Bc=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Ac,decode:vc});var Cn={};it(Cn,{base64:()=>Kn,base64pad:()=>_c,base64url:()=>Ic,base64urlpad:()=>Tc});var Kn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_c=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ic=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Tc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};it(Un,{base8:()=>Lc});var Lc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fn={};it(Fn,{identity:()=>Rc});var Rc=ge({prefix:"\0",name:"identity",encode:e=>ss(e),decode:e=>os(e)});var dl=new TextEncoder,pl=new TextDecoder;var Pn={};it(Pn,{sha256:()=>Lr,sha512:()=>Uc});var Cc=20;function kn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new On(e,t,r,n,o)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Cc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Bs(n,this.code,r?.truncate):n.then(o=>Bs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Bs(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Lt(t,e)}function Is(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Lr=kn({name:"sha2-256",code:18,encode:Is("SHA-256")}),Uc=kn({name:"sha2-512",code:19,encode:Is("SHA-512")});var Nn={...Fn,...Rn,...Un,...Tn,...Ln,...wn,...En,...gn,...Cn,...Dn},_l={...Pn,...vn};function Ls(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ts=Ls("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Hn=Ls("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=mt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Fc={utf8:Ts,"utf-8":Ts,hex:Nn.base16,latin1:Hn,ascii:Hn,binary:Hn,...Nn},Rr=Fc;function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Oc=parseInt("11111",2),Mn=parseInt("10000000",2),kc=parseInt("01111111",2),Rs={0:Qe,1:Qe,2:Pc,3:Mc,4:qc,5:Hc,6:Nc,16:Qe,22:Qe,48:Qe};function yt(e,t={offset:0}){let r=e[t.offset]&Oc;if(t.offset++,Rs[r]!=null)return Rs[r](e,t);throw new Error("No decoder for tag "+r)}function tr(e,t){let r=0;if((e[t.offset]&Mn)===Mn){let n=e[t.offset]&kc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Qe(e,t){tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=yt(e,t);if(n===null)break;r.push(n)}return r}function Pc(e,t){let r=tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nc(e,t){let r=tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;a+=`.${u}`,f=[]}}return a}function Hc(e,t){return t.offset++,null}function Mc(e,t){let r=tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qc(e,t){let r=tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ft;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Dr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vc(e.byteLength);return new ft(Uint8Array.from([t.byteLength|Mn]),t)}function ut(e){let t=new ft,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ft(Uint8Array.from([2]),Dr(t),t)}function er(e){let t=Uint8Array.from([0]),r=new ft(t,e);return new ft(Uint8Array.from([3]),Dr(r),r)}function Ds(e){return new ft(Uint8Array.from([4]),Dr(e),e)}function Et(e,t=48){let r=new ft;for(let n of e)r.append(n);return new ft(Uint8Array.from([t]),Dr(r),r)}var jc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zc=Uint8Array.from([6,5,43,129,4,0,34]),Zc=Uint8Array.from([6,5,43,129,4,0,35]),Ks={ext:!0,kty:"EC",crv:"P-256"},Cs={ext:!0,kty:"EC",crv:"P-384"},Us={ext:!0,kty:"EC",crv:"P-521"},ve=32,Be=48,_e=66;function Fs(e){let t=yt(e);return qn(t)}function qn(e){let t=e[1],r=M(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===ve)return s=M(n.subarray(o,o+ve),"base64url"),i=M(n.subarray(o+ve),"base64url"),new kt({...Ks,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Be)return s=M(n.subarray(o,o+Be),"base64url"),i=M(n.subarray(o+Be),"base64url"),new kt({...Cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===_e)return s=M(n.subarray(o,o+_e),"base64url"),i=M(n.subarray(o+_e),"base64url"),new kt({...Us,key_ops:["sign"],d:r,x:s,y:i});throw new k(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Vn(e){let t=yt(e);return jn(t)}function jn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ve*2+1)return n=M(t.subarray(r,r+ve),"base64url"),o=M(t.subarray(r+ve),"base64url"),new oe({...Ks,key_ops:["verify"],x:n,y:o});if(t.byteLength===Be*2+1)return n=M(t.subarray(r,r+Be),"base64url"),o=M(t.subarray(r+Be),"base64url"),new oe({...Cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===_e*2+1)return n=M(t.subarray(r,r+_e),"base64url"),o=M(t.subarray(r+_e),"base64url"),new oe({...Us,key_ops:["verify"],x:n,y:o});throw new k(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Os(e){return Et([ut(Uint8Array.from([1])),Ds(z(e.d??"","base64url")),Et([Ps(e.crv)],160),Et([er(new ft(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function ks(e){return Et([ut(Uint8Array.from([1])),Et([Ps(e.crv)],160),Et([er(new ft(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Ps(e){if(e==="P-256")return jc;if(e==="P-384")return zc;if(e==="P-521")return Zc;throw new k(`Invalid curve ${e}`)}async function Ns(e="P-256"){let t=await gs(e);return new kt(t.privateKey)}var oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ks(this.jwk)),this._raw}toMultihash(){return ne.digest(se(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,r,n){return Es(this.jwk,r,t,n)}},kt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new oe({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Os(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async sign(t,r){return ws(this.jwk,t,r)}};function zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function wt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function dt(e,t,r=""){let n=zn(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Ie(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(wt(e.outputLen),wt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Te(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Kr(e,t){dt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function pt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Le(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function St(e,t){return e<<32-t|e>>>t}function Cr(e,t){return e<<t|e>>>32-t>>>0}var Ms=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ur(e){if(dt(e),Ms)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Yc[e[r]];return t}var Pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hs(e){if(e>=Pt._0&&e<=Pt._9)return e-Pt._0;if(e>=Pt.A&&e<=Pt.F)return e-(Pt.A-10);if(e>=Pt.a&&e<=Pt.f)return e-(Pt.a-10)}function rr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Ms)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Hs(e.charCodeAt(s)),a=Hs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function $c(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Zn(e,t=""){return typeof e=="string"?$c(e):dt(e,void 0,t)}function Yn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];dt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function qs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(e,t)}function nr(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Fr(e=32){wt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var $n=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Or(e,t,r){return e&t^~e&r}function kr(e,t,r){return e&t^e&r^t&r}var ie=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Le(this.buffer)}update(t){Te(this),dt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=Le(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Te(this),Kr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,pt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Le(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),Vs=BigInt(32);function Gc(e,t=!1){return t?{h:Number(e&Pr),l:Number(e>>Vs&Pr)}:{h:Number(e>>Vs&Pr)|0,l:Number(e&Pr)|0}}function js(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Gc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Gn=(e,t,r)=>e>>>r,Xn=(e,t,r)=>e<<32-r|t>>>r,ae=(e,t,r)=>e>>>r|t<<32-r,ce=(e,t,r)=>e<<32-r|t>>>r,or=(e,t,r)=>e<<64-r|t>>>r-32,sr=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var zs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Zs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ys=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),$s=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Gs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Xs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Wc=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]),jt=new Uint32Array(64),Wn=class extends ie{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=jt[l-15],p=jt[l-2],m=St(b,7)^St(b,18)^b>>>3,E=St(p,17)^St(p,19)^p>>>10;jt[l]=E+jt[l-7]+m+jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let l=0;l<64;l++){let b=St(a,6)^St(a,11)^St(a,25),p=u+b+Or(a,f,c)+Wc[l]+jt[l]|0,E=(St(n,2)^St(n,13)^St(n,22))+kr(n,o,s)|0;u=c,c=f,f=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){pt(jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pt(this.buffer)}},Jn=class extends Wn{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var Ws=js(["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(e=>BigInt(e))),Jc=Ws[0],Qc=Ws[1],zt=new Uint32Array(80),Zt=new Uint32Array(80),Qn=class extends ie{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:l,Fl:b,Gh:p,Gl:m,Hh:E,Hl:d}=this;return[t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d]}set(t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=p|0,this.Gl=m|0,this.Hh=E|0,this.Hl=d|0}process(t,r){for(let B=0;B<16;B++,r+=4)zt[B]=t.getUint32(r),Zt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let D=zt[B-15]|0,L=Zt[B-15]|0,U=ae(D,L,1)^ae(D,L,8)^Gn(D,L,7),K=ce(D,L,1)^ce(D,L,8)^Xn(D,L,7),I=zt[B-2]|0,F=Zt[B-2]|0,V=ae(I,F,19)^or(I,F,61)^Gn(I,F,6),O=ce(I,F,19)^sr(I,F,61)^Xn(I,F,6),h=Ys(K,O,Zt[B-7],Zt[B-16]),x=$s(h,U,V,zt[B-7],zt[B-16]);zt[B]=x|0,Zt[B]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:b,Fh:p,Fl:m,Gh:E,Gl:d,Hh:y,Hl:S}=this;for(let B=0;B<80;B++){let D=ae(l,b,14)^ae(l,b,18)^or(l,b,41),L=ce(l,b,14)^ce(l,b,18)^sr(l,b,41),U=l&p^~l&E,K=b&m^~b&d,I=Gs(S,L,K,Qc[B],Zt[B]),F=Xs(I,y,D,U,Jc[B],zt[B]),V=I|0,O=ae(n,o,28)^or(n,o,34)^or(n,o,39),h=ce(n,o,28)^sr(n,o,34)^sr(n,o,39),x=n&s^n&a^s&a,A=o&i^o&f^i&f;y=E|0,S=d|0,E=p|0,d=m|0,p=l|0,m=b|0,{h:l,l:b}=Dt(c|0,u|0,F|0,V|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let w=zs(V,h,A);n=Zs(w,F,O,x),o=w|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Dt(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Dt(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:b}=Dt(this.Eh|0,this.El|0,l|0,b|0),{h:p,l:m}=Dt(this.Fh|0,this.Fl|0,p|0,m|0),{h:E,l:d}=Dt(this.Gh|0,this.Gl|0,E|0,d|0),{h:y,l:S}=Dt(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,a,f,c,u,l,b,p,m,E,d,y,S)}roundClean(){pt(zt,Zt)}destroy(){this.destroyed=!0,pt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},to=class extends Qn{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var Yt=nr(()=>new Jn,$n(1));var Re=nr(()=>new to,$n(3));var H=(e,t,r)=>dt(e,t,r),ro=wt,De=Ur,Q=(...e)=>Yn(...e),Ke=e=>rr(e),fe=zn,ir=e=>Fr(e),Hr=BigInt(0),eo=BigInt(1);function At(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Mr(e){if(typeof e=="bigint"){if(!Nr(e))throw new RangeError("positive bigint expected, got "+e)}else ro(e);return e}function vt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function ar(e){let t=Mr(e).toString(16);return t.length&1?"0"+t:t}function Js(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Hr:BigInt("0x"+e)}function ue(e){return Js(Ur(e))}function Kt(e){return Js(Ur(cr(dt(e)).reverse()))}function qr(e,t){if(wt(t),t===0)throw new RangeError("zero length");e=Mr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return rr(r.padStart(t*2,"0"))}function no(e,t){return qr(e,t).reverse()}function Qs(e,t){if(e=H(e),t=H(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function cr(e){return Uint8Array.from(H(e))}function Vr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Nr=e=>typeof e=="bigint"&&Hr<=e;function tf(e,t,r){return Nr(e)&&Nr(t)&&Nr(r)&&t<=e&&e<r}function Ce(e,t,r,n){if(!tf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ue(e){if(e<Hr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Hr;e>>=eo,t+=1);return t}var fr=e=>(eo<<BigInt(e))-eo;function ti(e,t,r){if(wt(e,"hashLen"),wt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=d=>new Uint8Array(d),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,l=()=>{f.fill(1),c.fill(0),u=0},b=(...d)=>r(c,Q(f,...d)),p=(d=o)=>{c=b(s,d),f=b(),d.length!==0&&(c=b(i,d),f=b())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let d=0,y=[];for(;d<t;){f=b();let S=f.slice();y.push(S),d+=f.length}return Q(...y)};return(d,y)=>{l(),p(d);let S;for(;(S=y(m()))===void 0;)p();return l(),S}}function Bt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var oo=()=>{throw new Error("not implemented")};var st=BigInt(0),G=BigInt(1),le=BigInt(2),oi=BigInt(3),si=BigInt(4),ii=BigInt(5),ef=BigInt(7),ai=BigInt(8),rf=BigInt(9),ci=BigInt(16);function W(e,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=st?r:t+r}function Z(e,t,r){if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >st;)n*=n,n%=r;return n}function ei(e,t){if(e===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=st,s=G,i=G,a=st;for(;r!==st;){let c=n/r,u=n-r*c,l=o-i*c,b=s-a*c;n=r,r=u,o=i,s=a,i=l,a=b}if(n!==G)throw new Error("invert: does not exist");return W(o,t)}function so(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function fi(e,t){let r=e,n=(r.ORDER+G)/si,o=r.pow(t,n);return so(r,o,t),o}function nf(e,t){let r=e,n=(r.ORDER-ii)/ai,o=r.mul(t,le),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,le),s),f=r.mul(i,r.sub(a,r.ONE));return so(r,f,t),f}function of(e){let t=Fe(e),r=ui(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+ef)/ci;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),b=c.mul(u,o),p=c.mul(u,s),m=c.eql(c.sqr(l),f),E=c.eql(c.sqr(b),f);u=c.cmov(u,l,m),l=c.cmov(p,b,E);let d=c.eql(c.sqr(l),f),y=c.cmov(u,l,d);return so(c,y,f),y})}function ui(e){if(e<oi)throw new Error("sqrt is not defined for small field");let t=e-G,r=0;for(;t%le===st;)t/=le,r++;let n=le,o=Fe(e);for(;ri(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fi;let s=o.pow(n,t),i=(t+G)/le;return function(f,c){let u=f;if(u.is0(c))return c;if(ri(u,c)!==1)throw new Error("Cannot find square root");let l=r,b=u.mul(u.ONE,s),p=u.pow(c,t),m=u.pow(c,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let E=1,d=u.sqr(p);for(;!u.eql(d,u.ONE);)if(E++,d=u.sqr(d),E===l)throw new Error("Cannot find square root");let y=G<<BigInt(l-E-1),S=u.pow(b,y);l=E,b=u.sqr(S),p=u.mul(p,b),m=u.mul(m,S)}return m}}function sf(e){return e%si===oi?fi:e%ai===ii?nf:e%ci===rf?of(e):ui(e)}var Ht=(e,t)=>(W(e,t)&G)===G,af=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function io(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=af.reduce((n,o)=>(n[o]="function",n),t);if(Bt(e,r),vt(e.BYTES,"BYTES"),vt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid