@libp2p/crypto 5.1.0 → 5.1.1-185b23eac

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,32 +1,19 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PCrypto=(()=>{var Zr=Object.defineProperty;var ki=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Hi=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var r in t)Zr(e,r,{get:t[r],enumerable:!0})},Mi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Oi(t))!Hi.call(e,o)&&o!==r&&Zr(e,o,{get:()=>t[o],enumerable:!(n=ki(t,o))||n.enumerable});return e};var qi=e=>Mi(Zr({},"__esModule",{value:!0}),e);var tu={};st(tu,{hmac:()=>hr,keys:()=>Eo,pbkdf2:()=>So,randomBytes:()=>no});var hr={};st(hr,{create:()=>Yr});var Me=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},lr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _o={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new lr("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 it=_o;var Uo={SHA1:20,SHA256:32,SHA512:64};var Vi={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},zi=async(e,t)=>{let r=await it.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function Yr(e,t){let r=Vi[e],n=await it.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return zi(n,o)},length:Uo[e]}}var Eo={};st(Eo,{generateEphemeralKeyPair:()=>Si,generateKeyPair:()=>Mf,generateKeyPairFromSeed:()=>qf,keyStretcher:()=>vi,privateKeyFromCryptoKeyPair:()=>$f,privateKeyFromProtobuf:()=>jf,privateKeyFromRaw:()=>Gf,privateKeyToCryptoKeyPair:()=>Xf,privateKeyToProtobuf:()=>Zf,publicKeyFromMultihash:()=>Ff,publicKeyFromProtobuf:()=>Vf,publicKeyFromRaw:()=>zf,publicKeyToProtobuf:()=>ce});var N=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"}},Ve=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var zt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Qr={};st(Qr,{base58btc:()=>rt,base58flickr:()=>Wi});var lu=new Uint8Array(0);function Ro(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 Dt(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 Do(e){return new TextEncoder().encode(e)}function Po(e){return new TextDecoder().decode(e)}function Fi(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,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var b=0,h=0,x=0,A=g.length;x!==A&&g[x]===0;)x++,b++;for(var m=(A-x)*f+1>>>0,v=new Uint8Array(m);x!==A;){for(var _=g[x],T=0,I=m-1;(_!==0||T<h)&&I!==-1;I--,T++)_+=256*v[I]>>>0,v[I]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");h=T,x++}for(var C=m-h;C!==m&&v[C]===0;)C++;for(var L=c.repeat(b);C<m;++C)L+=e.charAt(v[C]);return L}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var b=0;if(g[b]!==" "){for(var h=0,x=0;g[b]===c;)h++,b++;for(var A=(g.length-b)*u+1>>>0,m=new Uint8Array(A);g[b];){var v=r[g.charCodeAt(b)];if(v===255)return;for(var _=0,T=A-1;(v!==0||_<x)&&T!==-1;T--,_++)v+=a*m[T]>>>0,m[T]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");x=_,b++}if(g[b]!==" "){for(var I=A-x;I!==A&&m[I]===0;)I++;for(var C=new Uint8Array(h+(A-I)),L=h;I!==A;)C[L++]=m[I++];return C}}}function E(g){var b=d(g);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:E}}var ji=Fi,Gi=ji,ko=Gi;var Wr=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")}},Xr=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 Oo(this,t)}},$r=class{decoders;constructor(t){this.decoders=t}or(t){return Oo(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 Oo(e,t){return new $r({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Jr=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 Wr(t,r,n),this.decoder=new Xr(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 Jr(e,t,r,n)}function Ft({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ko(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Zi(e,t,r,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),a=0,c=0,u=0;for(let f=0;f<s;++f){let l=o[e[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,a+=r,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=r||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Yi(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],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 $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return ge({prefix:t,name:e,encode(o){return Yi(o,n,r)},decode(o){return Zi(o,n,r,e)}})}var rt=Ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wi=Ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tn={};st(tn,{base32:()=>we,base32hex:()=>Qi,base32hexpad:()=>ea,base32hexpadupper:()=>ra,base32hexupper:()=>ta,base32pad:()=>$i,base32padupper:()=>Ji,base32upper:()=>Xi,base32z:()=>na});var we=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xi=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$i=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ji=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qi=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ta=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ea=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ra=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),na=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var en={};st(en,{base36:()=>ze,base36upper:()=>oa});var ze=Ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oa=Ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sa=qo,Ho=128,ia=127,aa=~ia,ca=Math.pow(2,31);function qo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ca;)t[r++]=e&255|Ho,e/=128;for(;e&aa;)t[r++]=e&255|Ho,e>>>=7;return t[r]=e|0,qo.bytes=r-n+1,t}var fa=rn,ua=128,Mo=127;function rn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw rn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Mo)<<o:(i&Mo)*Math.pow(2,o),o+=7}while(i>=ua);return rn.bytes=s-n,r}var la=Math.pow(2,7),ha=Math.pow(2,14),da=Math.pow(2,21),pa=Math.pow(2,28),ma=Math.pow(2,35),ya=Math.pow(2,42),ba=Math.pow(2,49),xa=Math.pow(2,56),ga=Math.pow(2,63),wa=function(e){return e<la?1:e<ha?2:e<da?3:e<pa?4:e<ma?5:e<ya?6:e<ba?7:e<xa?8:e<ga?9:10},Ea={encode:sa,decode:fa,encodingLength:wa},Aa=Ea,Fe=Aa;function je(e,t=0){return[Fe.decode(e,t),Fe.decode.bytes]}function Ee(e,t,r=0){return Fe.encode(e,t,r),t}function Ae(e){return Fe.encodingLength(e)}function St(e,t){let r=t.byteLength,n=Ae(e),o=n+Ae(r),s=new Uint8Array(o+r);return Ee(e,s,0),Ee(r,s,n),s.set(t,o),new Se(e,r,t,s)}function Vo(e){let t=Dt(e),[r,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(r,o,i,t)}function zo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ro(e.bytes,r.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Fo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ba(r,nn(e),t??rt.encoder);default:return va(r,nn(e),t??we.encoder)}}var jo=new WeakMap;function nn(e){let t=jo.get(e);if(t==null){let r=new Map;return jo.set(e,r),r}return t}var wt=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!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ia)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=St(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&&zo(t.multihash,n.multihash)}toString(t){return Fo(this,t)}toJSON(){return{"/":Fo(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??Go(n,o,s.bytes))}else if(r[La]===!0){let{version:n,multihash:o,code:s}=r,i=Vo(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!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Go(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ze,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=Dt(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 Se(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,d]=je(t.subarray(r));return r+=d,l},o=n(),s=Ze;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(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Sa(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 nn(s).set(n,t),s}};function Sa(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 ze.prefix:{let r=t??ze;return[ze.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 Ba(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 va(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 Ze=112,Ia=18;function Go(e,t,r){let n=Ae(e),o=n+Ae(t),s=new Uint8Array(o+r.byteLength);return Ee(e,s,0),Ee(t,s,n),s.set(r,o),s}var La=Symbol.for("@ipld/js-cid/CID");var on={};st(on,{identity:()=>ie});var Zo=0,Ka="identity",Yo=Dt;function Ca(e){return St(Zo,Yo(e))}var ie={code:Zo,name:Ka,encode:Yo,digest:Ca};function ct(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 Pt(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Tt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Xo=Symbol.for("@achingbrain/uint8arraylist");function Wo(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 pr(e){return!!e?.[Xo]}var lt=class e{bufs;length;[Xo]=!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(pr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(pr(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=Wo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Wo(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(pr(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 Tt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Tt(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,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){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(!pr(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,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let E=this.get(l+d);if(n[d]!==E){f=Math.max(1,d-a[E]);break}}if(f===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=bt(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=Pt(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=Pt(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=Pt(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=bt(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=Pt(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=Pt(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=Pt(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=Pt(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=Pt(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(!ct(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 sn={};st(sn,{base10:()=>Ta});var Ta=Ft({prefix:"9",name:"base10",alphabet:"0123456789"});var an={};st(an,{base16:()=>_a,base16upper:()=>Ua});var _a=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ua=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cn={};st(cn,{base2:()=>Ra});var Ra=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fn={};st(fn,{base256emoji:()=>Oa});var $o=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}"),Da=$o.reduce((e,t,r)=>(e[r]=t,e),[]),Pa=$o.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Na(e){return e.reduce((t,r)=>(t+=Da[r],t),"")}function ka(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Oa=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Na,decode:ka});var ln={};st(ln,{base64:()=>un,base64pad:()=>Ha,base64url:()=>Ma,base64urlpad:()=>qa});var un=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ha=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ma=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qa=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hn={};st(hn,{base8:()=>Va});var Va=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dn={};st(dn,{identity:()=>za});var za=ge({prefix:"\0",name:"identity",encode:e=>Po(e),decode:e=>Do(e)});var Yu=new TextEncoder,Wu=new TextDecoder;var yn={};st(yn,{sha256:()=>mr,sha512:()=>Ga});function mn({name:e,code:t,encode:r}){return new pn(e,t,r)}var pn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?St(this.code,r):r.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Qo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var mr=mn({name:"sha2-256",code:18,encode:Qo("SHA-256")}),Ga=mn({name:"sha2-512",code:19,encode:Qo("SHA-512")});var bn={...dn,...cn,...hn,...sn,...an,...tn,...en,...Qr,...ln,...fn},al={...yn,...on};function es(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ts=es("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),xn=es("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=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Za={utf8:ts,"utf-8":ts,hex:bn.base16,latin1:xn,ascii:xn,binary:xn,...bn},yr=Za;function G(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ya=parseInt("11111",2),gn=parseInt("10000000",2),Wa=parseInt("01111111",2),rs={0:Ye,1:Ye,2:Xa,3:Qa,4:tc,5:Ja,6:$a,16:Ye,22:Ye,48:Ye};function xt(e,t={offset:0}){let r=e[t.offset]&Ya;if(t.offset++,rs[r]!=null)return rs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&gn)===gn){let n=e[t.offset]&Wa,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 Ye(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=xt(e,t);if(n===null)break;r.push(n)}return r}function Xa(e,t){let r=We(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 $a(e,t){let r=We(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}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Ja(e,t){return t.offset++,null}function Qa(e,t){let r=We(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 tc(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ec(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function br(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ec(e.byteLength);return new lt(Uint8Array.from([t.byteLength|gn]),t)}function ht(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),br(t),t)}function Xe(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),br(r),r)}function ns(e){return new lt(Uint8Array.from([4]),br(e),e)}function Bt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),br(r),r)}var wn="1.2.840.10045.3.1.7",En="1.3.132.0.34",An="1.3.132.0.35";async function os(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 ss(e,t){let r=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},r,t.subarray());return new Uint8Array(n,0,n.byteLength)}async function is(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,r.subarray())}var rc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),nc=Uint8Array.from([6,5,43,129,4,0,34]),oc=Uint8Array.from([6,5,43,129,4,0,35]),as={ext:!0,kty:"EC",crv:"P-256"},cs={ext:!0,kty:"EC",crv:"P-384"},fs={ext:!0,kty:"EC",crv:"P-521"},Be=32,ve=48,Ie=66;function us(e){let t=xt(e);return Sn(t)}function Sn(e){let t=e[1],r=V(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Be)return s=V(n.subarray(o,o+Be),"base64url"),i=V(n.subarray(o+Be),"base64url"),new Nt({...as,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===ve)return s=V(n.subarray(o,o+ve),"base64url"),i=V(n.subarray(o+ve),"base64url"),new Nt({...cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=V(n.subarray(o,o+Ie),"base64url"),i=V(n.subarray(o+Ie),"base64url"),new Nt({...fs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Bn(e){let t=xt(e);return vn(t)}function vn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Be*2+1)return n=V(t.subarray(r,r+Be),"base64url"),o=V(t.subarray(r+Be),"base64url"),new ae({...as,key_ops:["verify"],x:n,y:o});if(t.byteLength===ve*2+1)return n=V(t.subarray(r,r+ve),"base64url"),o=V(t.subarray(r+ve),"base64url"),new ae({...cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=V(t.subarray(r,r+Ie),"base64url"),o=V(t.subarray(r+Ie),"base64url"),new ae({...fs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ls(e){return Bt([ht(Uint8Array.from([1])),ns(G(e.d??"","base64url")),Bt([ds(e.crv)],160),Bt([Xe(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function hs(e){return Bt([ht(Uint8Array.from([1])),Bt([ds(e.crv)],160),Bt([Xe(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function ds(e){if(e==="P-256")return rc;if(e==="P-384")return nc;if(e==="P-521")return oc;throw new N(`Invalid curve ${e}`)}async function ps(e="P-256"){let t=await os(e);return new Nt(t.privateKey)}var ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=hs(this.jwk)),this._raw}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r){return is(this.jwk,r,t)}},Nt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ae({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=ls(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async sign(t){return ss(this.jwk,t)}};function Le(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function sc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ke(e,...t){if(!sc(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function xr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Le(e.outputLen),Le(e.blockLen)}function Ce(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 ms(e,t){Ke(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _e(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}function gr(e,t){return e<<t|e>>>32-t>>>0}function ys(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function jt(e){return typeof e=="string"&&(e=ys(e)),Ke(e),e}function In(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Ke(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}var Te=class{clone(){return this._cloneInto()}};function bs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function Ue(e){let t=n=>e().update(jt(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Re(e=32){if(fe&&typeof fe.getRandomValues=="function")return fe.getRandomValues(new Uint8Array(e));if(fe&&typeof fe.randomBytes=="function")return fe.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function ic(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function wr(e,t,r){return e&t^~e&r}function Er(e,t,r){return e&t^e&r^t&r}var Gt=class extends Te{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=_e(this.buffer)}update(t){Ce(this);let{view:r,buffer:n,blockLen:o}=this;t=jt(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=_e(t);for(;o<=s-i;i+=o)this.process(c,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){Ce(this),ms(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;ic(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=_e(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[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||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%r&&t.buffer.set(n),t}};var Ar=BigInt(4294967295),Ln=BigInt(32);function xs(e,t=!1){return t?{h:Number(e&Ar),l:Number(e>>Ln&Ar)}:{h:Number(e>>Ln&Ar)|0,l:Number(e&Ar)|0}}function ac(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:s,l:i}=xs(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}var cc=(e,t)=>BigInt(e>>>0)<<Ln|BigInt(t>>>0),fc=(e,t,r)=>e>>>r,uc=(e,t,r)=>e<<32-r|t>>>r,lc=(e,t,r)=>e>>>r|t<<32-r,hc=(e,t,r)=>e<<32-r|t>>>r,dc=(e,t,r)=>e<<64-r|t>>>r-32,pc=(e,t,r)=>e>>>r-32|t<<64-r,mc=(e,t)=>t,yc=(e,t)=>e,bc=(e,t,r)=>e<<r|t>>>32-r,xc=(e,t,r)=>t<<r|e>>>32-r,gc=(e,t,r)=>t<<r-32|e>>>64-r,wc=(e,t,r)=>e<<r-32|t>>>64-r;function Ec(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ac=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Sc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Bc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),vc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ic=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Lc=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Kc={fromBig:xs,split:ac,toBig:cc,shrSH:fc,shrSL:uc,rotrSH:lc,rotrSL:hc,rotrBH:dc,rotrBL:pc,rotr32H:mc,rotr32L:yc,rotlSH:bc,rotlSL:xc,rotlBH:gc,rotlBL:wc,add:Ec,add3L:Ac,add3H:Sc,add4L:Bc,add4H:vc,add5H:Lc,add5L:Ic},P=Kc;var[Cc,Tc]=P.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Zt=new Uint32Array(80),Yt=new Uint32Array(80),Kn=class extends Gt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:E,Gl:g,Hh:b,Hl:h}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,E,g,b,h]}set(t,r,n,o,s,i,a,c,u,f,l,d,E,g,b,h){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=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=b|0,this.Hl=h|0}process(t,r){for(let m=0;m<16;m++,r+=4)Zt[m]=t.getUint32(r),Yt[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let v=Zt[m-15]|0,_=Yt[m-15]|0,T=P.rotrSH(v,_,1)^P.rotrSH(v,_,8)^P.shrSH(v,_,7),I=P.rotrSL(v,_,1)^P.rotrSL(v,_,8)^P.shrSL(v,_,7),C=Zt[m-2]|0,L=Yt[m-2]|0,Z=P.rotrSH(C,L,19)^P.rotrBH(C,L,61)^P.shrSH(C,L,6),M=P.rotrSL(C,L,19)^P.rotrBL(C,L,61)^P.shrSL(C,L,6),O=P.add4L(I,M,Yt[m-7],Yt[m-16]),J=P.add4H(O,T,Z,Zt[m-7],Zt[m-16]);Zt[m]=J|0,Yt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:E,Fl:g,Gh:b,Gl:h,Hh:x,Hl:A}=this;for(let m=0;m<80;m++){let v=P.rotrSH(l,d,14)^P.rotrSH(l,d,18)^P.rotrBH(l,d,41),_=P.rotrSL(l,d,14)^P.rotrSL(l,d,18)^P.rotrBL(l,d,41),T=l&E^~l&b,I=d&g^~d&h,C=P.add5L(A,_,I,Tc[m],Yt[m]),L=P.add5H(C,x,v,T,Cc[m],Zt[m]),Z=C|0,M=P.rotrSH(n,o,28)^P.rotrBH(n,o,34)^P.rotrBH(n,o,39),O=P.rotrSL(n,o,28)^P.rotrBL(n,o,34)^P.rotrBL(n,o,39),J=n&s^n&a^s&a,S=o&i^o&c^i&c;x=b|0,A=h|0,b=E|0,h=g|0,E=l|0,g=d|0,{h:l,l:d}=P.add(u|0,f|0,L|0,Z|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let K=P.add3L(Z,O,S);n=P.add3H(K,L,M,J),o=K|0}({h:n,l:o}=P.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=P.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=P.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=P.add(this.Eh|0,this.El|0,l|0,d|0),{h:E,l:g}=P.add(this.Fh|0,this.Fl|0,E|0,g|0),{h:b,l:h}=P.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:x,l:A}=P.add(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,a,c,u,f,l,d,E,g,b,h,x,A)}roundClean(){Zt.fill(0),Yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Sr=Ue(()=>new Kn);var Ir={};st(Ir,{aInRange:()=>mt,abool:()=>It,abytes:()=>De,bitGet:()=>Nc,bitLen:()=>Un,bitMask:()=>Je,bitSet:()=>kc,bytesToHex:()=>Ot,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>Xt,concatBytes:()=>Mt,createHmacDrbg:()=>Rn,ensureBytes:()=>X,equalBytes:()=>Dc,hexToBytes:()=>le,hexToNumber:()=>_n,inRange:()=>$e,isBytes:()=>Wt,memoized:()=>de,notImplemented:()=>Hc,numberToBytesBE:()=>$t,numberToBytesLE:()=>he,numberToHexUnpadded:()=>ue,numberToVarBytesBE:()=>Rc,utf8ToBytes:()=>Pc,validateObject:()=>_t});var Br=BigInt(0),vr=BigInt(1),_c=BigInt(2);function Wt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function De(e){if(!Wt(e))throw new Error("Uint8Array expected")}function It(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}var Uc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ot(e){De(e);let t="";for(let r=0;r<e.length;r++)t+=Uc[e[r]];return t}function ue(e){let t=e.toString(16);return t.length&1?"0"+t:t}function _n(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Br:BigInt("0x"+e)}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gs(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("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=gs(e.charCodeAt(s)),a=gs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ht(e){return _n(Ot(e))}function Xt(e){return De(e),_n(Ot(Uint8Array.from(e).reverse()))}function $t(e,t){return le(e.toString(16).padStart(t*2,"0"))}function he(e,t){return $t(e,t).reverse()}function Rc(e){return le(ue(e))}function X(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Wt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Mt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];De(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 Dc(e,t){if(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 Pc(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}var Cn=e=>typeof e=="bigint"&&Br<=e;function $e(e,t,r){return Cn(e)&&Cn(t)&&Cn(r)&&t<=e&&e<r}function mt(e,t,r,n){if(!$e(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Un(e){let t;for(t=0;e>Br;e>>=vr,t+=1);return t}function Nc(e,t){return e>>BigInt(t)&vr}function kc(e,t,r){return e|(r?vr:Br)<<BigInt(t)}var Je=e=>(_c<<BigInt(e-1))-vr,Tn=e=>new Uint8Array(e),ws=e=>Uint8Array.from(e);function Rn(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Tn(e),o=Tn(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>r(o,n,...l),c=(l=Tn())=>{o=a(ws([0]),l),n=a(),l.length!==0&&(o=a(ws([1]),l),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let E=n.slice();d.push(E),l+=n.length}return Mt(...d)};return(l,d)=>{i(),c(l);let E;for(;!(E=d(u()));)c();return i(),E}}var Oc={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Wt(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function _t(e,t,r={}){let n=(o,s,i)=>{let a=Oc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=e[o];if(!(i&&c===void 0)&&!a(c,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(r))n(o,s,!0);return e}var Hc=()=>{throw new Error("not implemented")};function de(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Q=BigInt(0),Y=BigInt(1),pe=BigInt(2),Mc=BigInt(3),Dn=BigInt(4),Es=BigInt(5),As=BigInt(8),qc=BigInt(9),Vc=BigInt(16);function z(e,t){let r=e%t;return r>=Q?r:t+r}function zc(e,t,r){if(t<Q)throw new Error("invalid exponent, negatives unsupported");if(r<=Q)throw new Error("invalid modulus");if(r===Y)return Q;let n=Y;for(;t>Q;)t&Y&&(n=n*e%r),e=e*e%r,t>>=Y;return n}function W(e,t,r){let n=e;for(;t-- >Q;)n*=n,n%=r;return n}function Lr(e,t){if(e===Q)throw new Error("invert: expected non-zero number");if(t<=Q)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=Q,s=Y,i=Y,a=Q;for(;r!==Q;){let u=n/r,f=n%r,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==Y)throw new Error("invert: does not exist");return z(o,t)}function Fc(e){let t=(e-Y)/pe,r,n,o;for(r=e-Y,n=0;r%pe===Q;r/=pe,n++);for(o=pe;o<e&&zc(o,t,e)!==e-Y;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(e+Y)/Dn;return function(c,u){let f=c.pow(u,i);if(!c.eql(c.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(r+Y)/pe;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,f=a.pow(a.mul(a.ONE,o),r),l=a.pow(c,s),d=a.pow(c,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let b=a.sqr(d);E<u&&!a.eql(b,a.ONE);E++)b=a.sqr(b);let g=a.pow(f,Y<<BigInt(u-E-1));f=a.sqr(g),l=a.mul(l,g),d=a.mul(d,f),u=E}return l}}function jc(e){if(e%Dn===Mc){let t=(e+Y)/Dn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(e%As===Es){let t=(e-Es)/As;return function(n,o){let s=n.mul(o,pe),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,pe),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return e%Vc,Fc(e)}var Ss=(e,t)=>(z(e,t)&Y)===Y,Gc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Gc.reduce((n,o)=>(n[o]="function",n),t);return _t(e,r)}function Zc(e,t,r){if(r<Q)throw new Error("invalid exponent, negatives unsupported");if(r===Q)return e.ONE;if(r===Y)return t;let n=e.ONE,o=t;for(;r>Q;)r&Y&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Y;return n}function Yc(e,t){let r=new Array(t.length),n=t.reduce((s,i,a)=>e.is0(i)?s:(r[a]=s,e.mul(s,i)),e.ONE),o=e.inv(n);return t.reduceRight((s,i,a)=>e.is0(i)?s:(r[a]=e.mul(s,r[a]),e.mul(s,i)),o),r}function Nn(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jt(e,t,r=!1,n={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:s}=Nn(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:s,MASK:Je(o),ZERO:Q,ONE:Y,create:c=>z(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Q<=c&&c<e},is0:c=>c===Q,isOdd:c=>(c&Y)===Y,neg:c=>z(-c,e),eql:(c,u)=>c===u,sqr:c=>z(c*c,e),add:(c,u)=>z(c+u,e),sub:(c,u)=>z(c-u,e),mul:(c,u)=>z(c*u,e),pow:(c,u)=>Zc(a,c,u),div:(c,u)=>z(c*Lr(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Lr(c,e),sqrt:n.sqrt||(c=>(i||(i=jc(e)),i(a,c))),invertBatch:c=>Yc(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>r?he(c,s):$t(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?Xt(c):Ht(c)}});return Object.freeze(a)}function Bs(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function kn(e){let t=Bs(e);return t+Math.ceil(t/2)}function vs(e,t,r=!1){let n=e.length,o=Bs(t),s=kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Xt(e):Ht(e),a=z(i,t-Y)+Y;return r?he(a,o):$t(a,o)}var Is=BigInt(0),Kr=BigInt(1);function On(e,t){let r=t.negate();return e?r:t}function Ls(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Hn(e,t){Ls(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Wc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Xc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Mn=new WeakMap,Ks=new WeakMap;function qn(e){return Ks.get(e)||1}function Cr(e,t){return{constTimeNegate:On,hasPrecomputes(r){return qn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Is;)n&Kr&&(o=o.add(s)),s=s.double(),n>>=Kr;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Hn(n,t),i=[],a=r,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let{windows:s,windowSize:i}=Hn(r,t),a=e.ZERO,c=e.BASE,u=BigInt(2**r-1),f=2**r,l=BigInt(r);for(let d=0;d<s;d++){let E=d*i,g=Number(o&u);o>>=l,g>i&&(g-=f,o+=Kr);let b=E,h=E+Math.abs(g)-1,x=d%2!==0,A=g<0;g===0?c=c.add(On(x,n[b])):a=a.add(On(A,n[h]))}return{p:a,f:c}},wNAFUnsafe(r,n,o,s=e.ZERO){let{windows:i,windowSize:a}=Hn(r,t),c=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let l=0;l<i;l++){let d=l*a;if(o===Is)break;let E=Number(o&c);if(o>>=f,E>a&&(E-=u,o+=Kr),E===0)continue;let g=n[d+Math.abs(E)-1];E<0&&(g=g.negate()),s=s.add(g)}return s},getPrecomputes(r,n,o){let s=Mn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Mn.set(n,o(s))),s},wNAFCached(r,n,o){let s=qn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=qn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Ls(n,t),Ks.set(r,n),Mn.delete(r)}}}function Tr(e,t,r,n){if(Wc(r,e),Xc(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,s=Un(BigInt(r.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let l=u;l>=0;l-=i){c.fill(o);for(let E=0;E<n.length;E++){let g=n[E],b=Number(g>>BigInt(l)&BigInt(a));c[b]=c[b].add(r[E])}let d=o;for(let E=c.length-1,g=o;E>0;E--)g=g.add(c[E]),d=d.add(g);if(f=f.add(d),l!==0)for(let E=0;E<i;E++)f=f.double()}return f}function Qe(e){return Pn(e.Fp),_t(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Nn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Lt=BigInt(0),yt=BigInt(1),_r=BigInt(2),$c=BigInt(8),Jc={zip215:!0};function Qc(e){let t=Qe(e);return _t(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Cs(e){let t=Qc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=_r<<BigInt(a*8)-yt,f=r.create,l=Jt(t.n,t.nBitLength),d=t.uvRatio||((y,p)=>{try{return{isValid:!0,value:r.sqrt(y*r.inv(p))}}catch{return{isValid:!1,value:Lt}}}),E=t.adjustScalarBytes||(y=>y),g=t.domain||((y,p,w)=>{if(It("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,p){mt("coordinate "+y,p,Lt,u)}function h(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let x=de((y,p)=>{let{ex:w,ey:B,ez:U}=y,R=y.is0();p==null&&(p=R?$c:r.inv(U));let k=f(w*p),H=f(B*p),D=f(U*p);if(R)return{x:Lt,y:yt};if(D!==yt)throw new Error("invZ was invalid");return{x:k,y:H}}),A=de(y=>{let{a:p,d:w}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:B,ey:U,ez:R,et:k}=y,H=f(B*B),D=f(U*U),q=f(R*R),F=f(q*q),tt=f(H*p),et=f(q*f(tt+D)),ot=f(F+f(w*f(H*D)));if(et!==ot)throw new Error("bad point: equation left != right (1)");let at=f(B*U),pt=f(R*k);if(at!==pt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,B,U){this.ex=p,this.ey=w,this.ez=B,this.et=U,b("x",p),b("y",w),b("z",B),b("t",U),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:w,y:B}=p||{};return b("x",w),b("y",B),new m(w,B,yt,f(w*B))}static normalizeZ(p){let w=r.invertBatch(p.map(B=>B.ez));return p.map((B,U)=>B.toAffine(w[U])).map(m.fromAffine)}static msm(p,w){return Tr(m,l,p,w)}_setWindowSize(p){T.setWindowSize(this,p)}assertValidity(){A(this)}equals(p){h(p);let{ex:w,ey:B,ez:U}=this,{ex:R,ey:k,ez:H}=p,D=f(w*H),q=f(R*U),F=f(B*H),tt=f(k*U);return D===q&&F===tt}is0(){return this.equals(m.ZERO)}negate(){return new m(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:p}=t,{ex:w,ey:B,ez:U}=this,R=f(w*w),k=f(B*B),H=f(_r*f(U*U)),D=f(p*R),q=w+B,F=f(f(q*q)-R-k),tt=D+k,et=tt-H,ot=D-k,at=f(F*et),pt=f(tt*ot),ut=f(F*ot),Ct=f(et*tt);return new m(at,pt,Ct,ut)}add(p){h(p);let{a:w,d:B}=t,{ex:U,ey:R,ez:k,et:H}=this,{ex:D,ey:q,ez:F,et:tt}=p;if(w===BigInt(-1)){let Bo=f((R-U)*(q+D)),vo=f((R+U)*(q-D)),Gr=f(vo-Bo);if(Gr===Lt)return this.double();let Io=f(k*_r*tt),Lo=f(H*_r*F),Ko=Lo+Io,Co=vo+Bo,To=Lo-Io,Ri=f(Ko*Gr),Di=f(Co*To),Pi=f(Ko*To),Ni=f(Gr*Co);return new m(Ri,Di,Ni,Pi)}let et=f(U*D),ot=f(R*q),at=f(H*B*tt),pt=f(k*F),ut=f((U+R)*(D+q)-et-ot),Ct=pt-at,Rt=pt+at,He=f(ot-w*et),Ci=f(ut*Ct),Ti=f(Rt*He),_i=f(ut*He),Ui=f(Ct*Rt);return new m(Ci,Ti,Ui,_i)}subtract(p){return this.add(p.negate())}wNAF(p){return T.wNAFCached(this,p,m.normalizeZ)}multiply(p){let w=p;mt("scalar",w,yt,n);let{p:B,f:U}=this.wNAF(w);return m.normalizeZ([B,U])[0]}multiplyUnsafe(p,w=m.ZERO){let B=p;return mt("scalar",B,Lt,n),B===Lt?_:this.is0()||B===yt?this:T.wNAFCachedUnsafe(this,B,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===yt?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:B,a:U}=t,R=r.BYTES;p=X("pointHex",p,R),It("zip215",w);let k=p.slice(),H=p[R-1];k[R-1]=H&-129;let D=Xt(k),q=w?u:r.ORDER;mt("pointHex.y",D,Lt,q);let F=f(D*D),tt=f(F-yt),et=f(B*F-U),{isValid:ot,value:at}=d(tt,et);if(!ot)throw new Error("Point.fromHex: invalid y coordinate");let pt=(at&yt)===yt,ut=(H&128)!==0;if(!w&&at===Lt&&ut)throw new Error("Point.fromHex: x=0 and x_0=1");return ut!==pt&&(at=f(-at)),m.fromAffine({x:at,y:D})}static fromPrivateKey(p){return L(p).point}toRawBytes(){let{x:p,y:w}=this.toAffine(),B=he(w,r.BYTES);return B[B.length-1]|=p&yt?128:0,B}toHex(){return Ot(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,yt,f(t.Gx*t.Gy)),m.ZERO=new m(Lt,yt,yt,Lt);let{BASE:v,ZERO:_}=m,T=Cr(m,a*8);function I(y){return z(y,n)}function C(y){return I(Xt(y))}function L(y){let p=r.BYTES;y=X("private key",y,p);let w=X("hashed private key",s(y),2*p),B=E(w.slice(0,p)),U=w.slice(p,2*p),R=C(B),k=v.multiply(R),H=k.toRawBytes();return{head:B,prefix:U,scalar:R,point:k,pointBytes:H}}function Z(y){return L(y).pointBytes}function M(y=new Uint8Array,...p){let w=Mt(...p);return C(s(g(w,X("context",y),!!o)))}function O(y,p,w={}){y=X("message",y),o&&(y=o(y));let{prefix:B,scalar:U,pointBytes:R}=L(p),k=M(w.context,B,y),H=v.multiply(k).toRawBytes(),D=M(w.context,H,R,y),q=I(k+D*U);mt("signature.s",q,Lt,n);let F=Mt(H,he(q,r.BYTES));return X("result",F,r.BYTES*2)}let J=Jc;function S(y,p,w,B=J){let{context:U,zip215:R}=B,k=r.BYTES;y=X("signature",y,2*k),p=X("message",p),w=X("publicKey",w,k),R!==void 0&&It("zip215",R),o&&(p=o(p));let H=Xt(y.slice(k,2*k)),D,q,F;try{D=m.fromHex(w,R),q=m.fromHex(y.slice(0,k),R),F=v.multiplyUnsafe(H)}catch{return!1}if(!R&&D.isSmallOrder())return!1;let tt=M(U,q.toRawBytes(),D.toRawBytes(),p);return q.add(D.multiplyUnsafe(tt)).subtract(F).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:O,verify:S,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(r.BYTES),precompute(y=8,p=m.BASE){return p._setWindowSize(y),p.multiply(BigInt(3)),p}}}}var Vn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ch=BigInt(0),tf=BigInt(1),_s=BigInt(2),fh=BigInt(3),ef=BigInt(5),rf=BigInt(8);function nf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Vn,a=e*e%s*e%s,c=W(a,_s,s)*a%s,u=W(c,tf,s)*e%s,f=W(u,ef,s)*u%s,l=W(f,t,s)*f%s,d=W(l,r,s)*l%s,E=W(d,n,s)*d%s,g=W(E,o,s)*E%s,b=W(g,o,s)*E%s,h=W(b,t,s)*f%s;return{pow_p_5_8:W(h,_s,s)*e%s,b2:a}}function of(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function sf(e,t){let r=Vn,n=z(t*t*t,r),o=z(n*n*t,r),s=nf(e*o).pow_p_5_8,i=z(e*n*s,r),a=z(t*i*i,r),c=i,u=z(i*Ts,r),f=a===e,l=a===z(-e,r),d=a===z(-e*Ts,r);return f&&(i=c),(l||d)&&(i=u),Ss(i,r)&&(i=z(-i,r)),{isValid:f||l,value:i}}var af=Jt(Vn,void 0,!0),cf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:af,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:rf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Sr,randomBytes:Re,adjustScalarBytes:of,uvRatio:sf},Pe=Cs(cf);var Qt=32,Et=64,Ur=32;function Us(){let e=Pe.utils.randomPrivateKey(),t=Pe.getPublicKey(e);return{privateKey:Ns(e,t),publicKey:t}}function Rs(e){if(e.length!==Ur)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Pe.getPublicKey(t);return{privateKey:Ns(t,r),publicKey:r}}function Ds(e,t){let r=e.subarray(0,Ur);return Pe.sign(t instanceof Uint8Array?t:t.subarray(),r)}function Ps(e,t,r){return Pe.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}function Ns(e,t){let r=new Uint8Array(Et);for(let n=0;n<Ur;n++)r[n]=e[n],r[Ur+n]=t[n];return r}var tr=class{type="Ed25519";raw;constructor(t){this.raw=Ne(t,Qt)}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return Ps(this.raw,r,t)}},me=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ne(t,Et),this.publicKey=new tr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return Ds(this.raw,t)}};function zn(e){if(e.length>Et){e=Ne(e,Et+Qt);let n=e.subarray(0,Et),o=e.subarray(Et,e.length);return new me(n,o)}e=Ne(e,Et);let t=e.subarray(0,Et),r=e.subarray(Qt);return new me(t,r)}function Rr(e){return e=Ne(e,Qt),new tr(e)}async function Os(){let{privateKey:e,publicKey:t}=Us();return new me(e,t)}async function Hs(e){let{privateKey:t,publicKey:r}=Rs(e);return new me(t,r)}function Ne(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ff=Math.pow(2,7),uf=Math.pow(2,14),lf=Math.pow(2,21),Ms=Math.pow(2,28),qs=Math.pow(2,35),Vs=Math.pow(2,42),zs=Math.pow(2,49),dt=128,te=127;function er(e){if(e<ff)return 1;if(e<uf)return 2;if(e<lf)return 3;if(e<Ms)return 4;if(e<qs)return 5;if(e<Vs)return 6;if(e<zs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fs(e,t,r=0){switch(er(e)){case 8:t[r++]=e&255|dt,e/=128;case 7:t[r++]=e&255|dt,e/=128;case 6:t[r++]=e&255|dt,e/=128;case 5:t[r++]=e&255|dt,e/=128;case 4:t[r++]=e&255|dt,e>>>=7;case 3:t[r++]=e&255|dt,e>>>=7;case 2:t[r++]=e&255|dt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function js(e,t){let r=e[t],n=0;if(n+=r&te,r<dt||(r=e[t+1],n+=(r&te)<<7,r<dt)||(r=e[t+2],n+=(r&te)<<14,r<dt)||(r=e[t+3],n+=(r&te)<<21,r<dt)||(r=e[t+4],n+=(r&te)*Ms,r<dt)||(r=e[t+5],n+=(r&te)*qs,r<dt)||(r=e[t+6],n+=(r&te)*Vs,r<dt)||(r=e[t+7],n+=(r&te)*zs,r<dt))return n;throw new RangeError("Could not decode varint")}var Fn=new Float32Array([-0]),ee=new Uint8Array(Fn.buffer);function Gs(e,t,r){Fn[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function Zs(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Fn[0]}var jn=new Float64Array([-0]),ft=new Uint8Array(jn.buffer);function Ys(e,t,r){jn[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Ws(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],jn[0]}var hf=BigInt(Number.MAX_SAFE_INTEGER),df=BigInt(Number.MIN_SAFE_INTEGER),gt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<hf&&t>df)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Xs&&(o=0n,++n>Xs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ye}},ye=new gt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Xs=4294967296n;function $s(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Js(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Gn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Dr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Zn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Dr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Dr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Zs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ws(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Js(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Dr(this.buf,this.pos+=4),r=Dr(this.buf,this.pos+=4);return new gt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=js(this.buf,this.pos);return this.pos+=er(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yn(e){return new Zn(e instanceof Uint8Array?e:e.subarray())}function Pr(e,t,r){let n=Yn(e);return t.decode(n,void 0,r)}function Wn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return bt(i);o+i>t&&(n=bt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Xn(){}var Jn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},pf=Wn();function mf(e){return globalThis.Buffer!=null?bt(e):pf(e)}var nr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(Xn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Nr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=gt.fromBigInt(t);return this._push(Nr,r.length(),r)}uint64Number(t){return this._push(Fs,er(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=gt.fromBigInt(t).zzEncode();return this._push(Nr,r.length(),r)}sint64Number(t){let r=gt.fromNumber(t).zzEncode();return this._push(Nr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push($n,1,t?1:0)}fixed32(t){return this._push(rr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=gt.fromBigInt(t);return this._push(rr,4,r.lo)._push(rr,4,r.hi)}fixed64Number(t){let r=gt.fromNumber(t);return this._push(rr,4,r.lo)._push(rr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Gs,4,t)}double(t){return this._push(Ys,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push($n,1,0):this.uint32(r)._push(bf,r,t)}string(t){let r=$s(t);return r!==0?this.uint32(r)._push(Gn,r,t):this._push($n,1,0)}fork(){return this.states=new Jn(this),this.head=this.tail=new be(Xn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new be(Xn,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=mf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function $n(e,t,r){t[r]=e&255}function yf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Qn=class extends be{next;constructor(t,r){super(yf,t,r),this.next=void 0}};function Nr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function rr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function bf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(nr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(xf,t,e),this},nr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(gf,t,e),this});function xf(e,t,r){t.set(e,r)}function gf(e,t,r){e.length<40?Gn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function to(){return new nr}function kr(e,t){let r=to();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ke;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ke||(ke={}));function Or(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function eo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Or("enum",ke.VARINT,r,n)}function Hr(e,t){return Or("message",ke.LENGTH_DELIMITED,e,t)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var ro;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ro||(ro={}));(function(e){e.codec=()=>eo(ro)})(j||(j={}));var Ut;(function(e){let t;e.codec=()=>(t==null&&(t=Hr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>kr(r,e.codec()),e.decode=(r,n)=>Pr(r,e.codec(),n)})(Ut||(Ut={}));var or;(function(e){let t;e.codec=()=>(t==null&&(t=Hr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>kr(r,e.codec()),e.decode=(r,n)=>Pr(r,e.codec(),n)})(or||(or={}));function no(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return Re(e)}var ir={};st(ir,{MAX_RSA_KEY_SIZE:()=>so,generateRSAKeyPair:()=>ho,jwkToJWKKeyPair:()=>ni,jwkToPkcs1:()=>Bf,jwkToPkix:()=>fo,jwkToRSAPrivateKey:()=>Vr,pkcs1MessageToJwk:()=>ao,pkcs1MessageToRSAPrivateKey:()=>Mr,pkcs1ToJwk:()=>Sf,pkcs1ToRSAPrivateKey:()=>uo,pkixMessageToJwk:()=>co,pkixMessageToRSAPublicKey:()=>qr,pkixToJwk:()=>vf,pkixToRSAPublicKey:()=>lo});var wf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ne=new Uint32Array(64),oo=class extends Gt{constructor(){super(64,32,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){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=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)ne[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=ne[l-15],E=ne[l-2],g=vt(d,7)^vt(d,18)^d>>>3,b=vt(E,17)^vt(E,19)^E>>>10;ne[l]=b+ne[l-7]+g+ne[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=vt(a,6)^vt(a,11)^vt(a,25),E=f+d+wr(a,c,u)+wf[l]+ne[l]|0,b=(vt(n,2)^vt(n,13)^vt(n,22))+Er(n,o,s)|0;f=u,u=c,c=a,a=i+E|0,i=s,s=o,o=n,n=E+b|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,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var oe=Ue(()=>new oo);var Oe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=ir.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return wt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return ri(this.jwk,r,t)}},sr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ir.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return ei(this.jwk,t)}};var so=8192,io=18,Ef=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Sf(e){let t=xt(e);return ao(t)}function ao(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function Bf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new N("JWK was missing components");return Bt([ht(Uint8Array.from([0])),ht(G(e.n,"base64url")),ht(G(e.e,"base64url")),ht(G(e.d,"base64url")),ht(G(e.p,"base64url")),ht(G(e.q,"base64url")),ht(G(e.dp,"base64url")),ht(G(e.dq,"base64url")),ht(G(e.qi,"base64url"))]).subarray()}function vf(e){let t=xt(e,{offset:0});return co(t)}function co(e){let t=xt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function fo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return Bt([Af,Xe(Bt([ht(G(e.n,"base64url")),ht(G(e.e,"base64url"))]))]).subarray()}function uo(e){let t=xt(e);return Mr(t)}function Mr(e){let t=ao(e);return Vr(t)}function lo(e,t){if(e.byteLength>=Ef)throw new xe("Key size is too large");let r=xt(e,{offset:0});return qr(r,e,t)}function qr(e,t,r){let n=co(e);if(r==null){let o=oe(Ut.encode({Type:j.RSA,Data:t}));r=St(io,o)}return new Oe(n,r)}function Vr(e){if(si(e)>so)throw new N("Key size is too large");let t=ni(e),r=oe(Ut.encode({Type:j.RSA,Data:fo(t.publicKey)})),n=St(io,r);return new sr(t.privateKey,new Oe(t.publicKey,n))}async function ho(e){if(e>so)throw new N("Key size is too large");let t=await oi(e),r=oe(Ut.encode({Type:j.RSA,Data:fo(t.publicKey)})),n=St(io,r);return new sr(t.privateKey,new Oe(t.publicKey,n))}function ni(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ii="1.2.840.113549.1.1.1";async function oi(e){let t=await it.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await If(t);return{privateKey:r[0],publicKey:r[1]}}async function ei(e,t){let r=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await it.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ri(e,t,r){let n=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return it.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function If(e){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");return Promise.all([it.get().subtle.exportKey("jwk",e.privateKey),it.get().subtle.exportKey("jwk",e.publicKey)])}function si(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return G(e.n,"base64url").length*8}var zr=class extends Te{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,xr(t);let n=jt(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ce(this),this.iHash.update(t),this}digestInto(t){Ce(this),Ke(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ar=(e,t,r)=>new zr(e,t).update(r).digest();ar.create=(e,t)=>new zr(e,t);function ai(e){e.lowS!==void 0&&It("lowS",e.lowS),e.prehash!==void 0&&It("prehash",e.prehash)}function Lf(e){let t=Qe(e);_t(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Kf,hexToBytes:Cf}=Ir,po=class extends Error{constructor(t=""){super(t)}},qt={Err:po,_tlv:{encode:(e,t)=>{let{Err:r}=qt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=ue(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ue(o.length/2|128):"";return ue(e)+s+o+t},decode(e,t){let{Err:r}=qt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=qt;if(e<Vt)throw new t("integer: negative integers are not allowed");let r=ue(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=qt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Kf(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=qt,o=typeof e=="string"?Cf(e):e;De(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=qt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Vt=BigInt(0),nt=BigInt(1),R0=BigInt(2),ci=BigInt(3),D0=BigInt(4);function Tf(e){let t=Lf(e),{Fp:r}=t,n=Jt(t.n,t.nBitLength),o=t.toBytes||((b,h,x)=>{let A=h.toAffine();return Mt(Uint8Array.from([4]),r.toBytes(A.x),r.toBytes(A.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),x=r.fromBytes(h.subarray(0,r.BYTES)),A=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x,y:A}});function i(b){let{a:h,b:x}=t,A=r.sqr(b),m=r.mul(A,b);return r.add(r.add(m,r.mul(b,h)),x)}if(!r.eql(r.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return $e(b,nt,t.n)}function c(b){let{allowedPrivateKeyLengths:h,nByteLength:x,wrapPrivateKey:A,n:m}=t;if(h&&typeof b!="bigint"){if(Wt(b)&&(b=Ot(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(x*2,"0")}let v;try{v=typeof b=="bigint"?b:Ht(X("private key",b,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof b)}return A&&(v=z(v,m)),mt("private key",v,nt,m),v}function u(b){if(!(b instanceof d))throw new Error("ProjectivePoint expected")}let f=de((b,h)=>{let{px:x,py:A,pz:m}=b;if(r.eql(m,r.ONE))return{x,y:A};let v=b.is0();h==null&&(h=v?r.ONE:r.inv(m));let _=r.mul(x,h),T=r.mul(A,h),I=r.mul(m,h);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(I,r.ONE))throw new Error("invZ was invalid");return{x:_,y:T}}),l=de(b=>{if(b.is0()){if(t.allowInfinityPoint&&!r.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:x}=b.toAffine();if(!r.isValid(h)||!r.isValid(x))throw new Error("bad point: x or y not FE");let A=r.sqr(x),m=i(h);if(!r.eql(A,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,x,A){if(this.px=h,this.py=x,this.pz=A,h==null||!r.isValid(h))throw new Error("x required");if(x==null||!r.isValid(x))throw new Error("y required");if(A==null||!r.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x,y:A}=h||{};if(!h||!r.isValid(x)||!r.isValid(A))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let m=v=>r.eql(v,r.ZERO);return m(x)&&m(A)?d.ZERO:new d(x,A,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let x=r.invertBatch(h.map(A=>A.pz));return h.map((A,m)=>A.toAffine(x[m])).map(d.fromAffine)}static fromHex(h){let x=d.fromAffine(s(X("pointHex",h)));return x.assertValidity(),x}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,x){return Tr(d,n,h,x)}_setWindowSize(h){g.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:x,py:A,pz:m}=this,{px:v,py:_,pz:T}=h,I=r.eql(r.mul(x,T),r.mul(v,m)),C=r.eql(r.mul(A,T),r.mul(_,m));return I&&C}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:x}=t,A=r.mul(x,ci),{px:m,py:v,pz:_}=this,T=r.ZERO,I=r.ZERO,C=r.ZERO,L=r.mul(m,m),Z=r.mul(v,v),M=r.mul(_,_),O=r.mul(m,v);return O=r.add(O,O),C=r.mul(m,_),C=r.add(C,C),T=r.mul(h,C),I=r.mul(A,M),I=r.add(T,I),T=r.sub(Z,I),I=r.add(Z,I),I=r.mul(T,I),T=r.mul(O,T),C=r.mul(A,C),M=r.mul(h,M),O=r.sub(L,M),O=r.mul(h,O),O=r.add(O,C),C=r.add(L,L),L=r.add(C,L),L=r.add(L,M),L=r.mul(L,O),I=r.add(I,L),M=r.mul(v,_),M=r.add(M,M),L=r.mul(M,O),T=r.sub(T,L),C=r.mul(M,Z),C=r.add(C,C),C=r.add(C,C),new d(T,I,C)}add(h){u(h);let{px:x,py:A,pz:m}=this,{px:v,py:_,pz:T}=h,I=r.ZERO,C=r.ZERO,L=r.ZERO,Z=t.a,M=r.mul(t.b,ci),O=r.mul(x,v),J=r.mul(A,_),S=r.mul(m,T),K=r.add(x,A),y=r.add(v,_);K=r.mul(K,y),y=r.add(O,J),K=r.sub(K,y),y=r.add(x,m);let p=r.add(v,T);return y=r.mul(y,p),p=r.add(O,S),y=r.sub(y,p),p=r.add(A,m),I=r.add(_,T),p=r.mul(p,I),I=r.add(J,S),p=r.sub(p,I),L=r.mul(Z,y),I=r.mul(M,S),L=r.add(I,L),I=r.sub(J,L),L=r.add(J,L),C=r.mul(I,L),J=r.add(O,O),J=r.add(J,O),S=r.mul(Z,S),y=r.mul(M,y),J=r.add(J,S),S=r.sub(O,S),S=r.mul(Z,S),y=r.add(y,S),O=r.mul(J,y),C=r.add(C,O),O=r.mul(p,y),I=r.mul(K,I),I=r.sub(I,O),O=r.mul(K,J),L=r.mul(p,L),L=r.add(L,O),new d(I,C,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return g.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:x,n:A}=t;mt("scalar",h,Vt,A);let m=d.ZERO;if(h===Vt)return m;if(this.is0()||h===nt)return this;if(!x||g.hasPrecomputes(this))return g.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:v,k1:_,k2neg:T,k2:I}=x.splitScalar(h),C=m,L=m,Z=this;for(;_>Vt||I>Vt;)_&nt&&(C=C.add(Z)),I&nt&&(L=L.add(Z)),Z=Z.double(),_>>=nt,I>>=nt;return v&&(C=C.negate()),T&&(L=L.negate()),L=new d(r.mul(L.px,x.beta),L.py,L.pz),C.add(L)}multiply(h){let{endo:x,n:A}=t;mt("scalar",h,nt,A);let m,v;if(x){let{k1neg:_,k1:T,k2neg:I,k2:C}=x.splitScalar(h),{p:L,f:Z}=this.wNAF(T),{p:M,f:O}=this.wNAF(C);L=g.constTimeNegate(_,L),M=g.constTimeNegate(I,M),M=new d(r.mul(M.px,x.beta),M.py,M.pz),m=L.add(M),v=Z.add(O)}else{let{p:_,f:T}=this.wNAF(h);m=_,v=T}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(h,x,A){let m=d.BASE,v=(T,I)=>I===Vt||I===nt||!T.equals(m)?T.multiplyUnsafe(I):T.multiply(I),_=v(this,x).add(v(h,A));return _.is0()?void 0:_}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:x}=t;if(h===nt)return!0;if(x)return x(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:x}=t;return h===nt?this:x?x(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return It("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return It("isCompressed",h),Ot(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);let E=t.nBitLength,g=Cr(d,t.endo?Math.ceil(E/2):E);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function _f(e){let t=Qe(e);return _t(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function fi(e){let t=_f(e),{Fp:r,n}=t,o=r.BYTES+1,s=2*r.BYTES+1;function i(S){return z(S,n)}function a(S){return Lr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=Tf({...t,toBytes(S,K,y){let p=K.toAffine(),w=r.toBytes(p.x),B=Mt;return It("isCompressed",y),y?B(Uint8Array.from([K.hasEvenY()?2:3]),w):B(Uint8Array.from([4]),w,r.toBytes(p.y))},fromBytes(S){let K=S.length,y=S[0],p=S.subarray(1);if(K===o&&(y===2||y===3)){let w=Ht(p);if(!$e(w,nt,r.ORDER))throw new Error("Point is not on curve");let B=f(w),U;try{U=r.sqrt(B)}catch(H){let D=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+D)}let R=(U&nt)===nt;return(y&1)===1!==R&&(U=r.neg(U)),{x:w,y:U}}else if(K===s&&y===4){let w=r.fromBytes(p.subarray(0,r.BYTES)),B=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:w,y:B}}else{let w=o,B=s;throw new Error("invalid Point, expected length of "+w+", or uncompressed "+B+", got "+K)}}}),d=S=>Ot($t(S,t.nByteLength));function E(S){let K=n>>nt;return S>K}function g(S){return E(S)?i(-S):S}let b=(S,K,y)=>Ht(S.slice(K,y));class h{constructor(K,y,p){this.r=K,this.s=y,this.recovery=p,this.assertValidity()}static fromCompact(K){let y=t.nByteLength;return K=X("compactSignature",K,y*2),new h(b(K,0,y),b(K,y,2*y))}static fromDER(K){let{r:y,s:p}=qt.toSig(X("DER",K));return new h(y,p)}assertValidity(){mt("r",this.r,nt,n),mt("s",this.s,nt,n)}addRecoveryBit(K){return new h(this.r,this.s,K)}recoverPublicKey(K){let{r:y,s:p,recovery:w}=this,B=T(X("msgHash",K));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let U=w===2||w===3?y+t.n:y;if(U>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(w&1)===0?"02":"03",k=c.fromHex(R+d(U)),H=a(U),D=i(-B*H),q=i(p*H),F=c.BASE.multiplyAndAddUnsafe(k,D,q);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return le(this.toDERHex())}toDERHex(){return qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return le(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=kn(t.n);return vs(t.randomBytes(S),t.n)},precompute(S=8,K=c.BASE){return K._setWindowSize(S),K.multiply(BigInt(3)),K}};function A(S,K=!0){return c.fromPrivateKey(S).toRawBytes(K)}function m(S){let K=Wt(S),y=typeof S=="string",p=(K||y)&&S.length;return K?p===o||p===s:y?p===2*o||p===2*s:S instanceof c}function v(S,K,y=!0){if(m(S))throw new Error("first arg must be private key");if(!m(K))throw new Error("second arg must be public key");return c.fromHex(K).multiply(u(S)).toRawBytes(y)}let _=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let K=Ht(S),y=S.length*8-t.nBitLength;return y>0?K>>BigInt(y):K},T=t.bits2int_modN||function(S){return i(_(S))},I=Je(t.nBitLength);function C(S){return mt("num < 2^"+t.nBitLength,S,Vt,I),$t(S,t.nByteLength)}function L(S,K,y=Z){if(["recovered","canonical"].some(et=>et in y))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:w}=t,{lowS:B,prehash:U,extraEntropy:R}=y;B==null&&(B=!0),S=X("msgHash",S),ai(y),U&&(S=X("prehashed msgHash",p(S)));let k=T(S),H=u(K),D=[C(H),C(k)];if(R!=null&&R!==!1){let et=R===!0?w(r.BYTES):R;D.push(X("extraEntropy",et))}let q=Mt(...D),F=k;function tt(et){let ot=_(et);if(!l(ot))return;let at=a(ot),pt=c.BASE.multiply(ot).toAffine(),ut=i(pt.x);if(ut===Vt)return;let Ct=i(at*i(F+ut*H));if(Ct===Vt)return;let Rt=(pt.x===ut?0:2)|Number(pt.y&nt),He=Ct;return B&&E(Ct)&&(He=g(Ct),Rt^=1),new h(ut,He,Rt)}return{seed:q,k2sig:tt}}let Z={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function O(S,K,y=Z){let{seed:p,k2sig:w}=L(S,K,y),B=t;return Rn(B.hash.outputLen,B.nByteLength,B.hmac)(p,w)}c.BASE._setWindowSize(8);function J(S,K,y,p=M){let w=S;K=X("msgHash",K),y=X("publicKey",y);let{lowS:B,prehash:U,format:R}=p;if(ai(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let k=typeof w=="string"||Wt(w),H=!k&&!R&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!k&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,q;try{if(H&&(D=new h(w.r,w.s)),k){try{R!=="compact"&&(D=h.fromDER(w))}catch(Rt){if(!(Rt instanceof qt.Err))throw Rt}!D&&R!=="der"&&(D=h.fromCompact(w))}q=c.fromHex(y)}catch{return!1}if(!D||B&&D.hasHighS())return!1;U&&(K=t.hash(K));let{r:F,s:tt}=D,et=T(K),ot=a(tt),at=i(et*ot),pt=i(F*ot),ut=c.BASE.multiplyAndAddUnsafe(q,at,pt)?.toAffine();return ut?i(ut.x)===F:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:v,sign:O,verify:J,ProjectivePoint:c,Signature:h,utils:x}}function Uf(e){return{hash:e,hmac:(t,...r)=>ar(e,t,In(...r)),randomBytes:Re}}function ui(e,t){let r=n=>fi({...e,...Uf(n)});return{...r(t),create:r}}var di=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),li=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Rf=BigInt(1),mo=BigInt(2),hi=(e,t)=>(e+t/mo)/t;function Df(e){let t=di,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=W(f,r,t)*f%t,d=W(l,r,t)*f%t,E=W(d,mo,t)*u%t,g=W(E,o,t)*E%t,b=W(g,s,t)*g%t,h=W(b,a,t)*b%t,x=W(h,c,t)*h%t,A=W(x,a,t)*b%t,m=W(A,r,t)*f%t,v=W(m,i,t)*g%t,_=W(v,n,t)*u%t,T=W(_,mo,t);if(!yo.eql(yo.sqr(T),e))throw new Error("Cannot find square root");return T}var yo=Jt(di,void 0,void 0,{sqrt:Df}),At=ui({a:BigInt(0),b:BigInt(7),Fp:yo,n:li,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=li,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Rf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=hi(s*e,t),c=hi(-n*e,t),u=z(e-a*r-c*o,t),f=z(-a*n-c*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},oe),z0=BigInt(0);var F0=At.ProjectivePoint;function bo(e,t){let r=G(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Tt([new Uint8Array(t-r.length),r])}return r}function xo(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var pi=33,mi=32;function yi(e,t){let r=mr.digest(t instanceof Uint8Array?t:t.subarray());if(xo(r))return r.then(({digest:n})=>At.sign(n,e).toDERRawBytes()).catch(n=>{throw new Me(String(n))});try{return At.sign(r.digest,e).toDERRawBytes()}catch(n){throw new Me(String(n))}}function bi(e,t,r){let n=mr.digest(r instanceof Uint8Array?r:r.subarray());if(xo(n))return n.then(({digest:o})=>At.verify(t,o,e)).catch(o=>{throw new qe(String(o))});try{return At.verify(t,n.digest,e)}catch(o){throw new qe(String(o))}}var cr=class{type="secp256k1";raw;_key;constructor(t){this._key=wi(t),this.raw=xi(this._key)}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return bi(this._key,r,t)}},fr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=gi(t),this.publicKey=new cr(r??Ei(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return yi(this.raw,t)}};function go(e){return new fr(e)}function Fr(e){return new cr(e)}async function Ai(){let e=Pf();return new fr(e)}function xi(e){return At.ProjectivePoint.fromHex(e).toRawBytes(!0)}function gi(e){try{return At.getPublicKey(e,!0),e}catch(t){throw new Ve(String(t))}}function wi(e){try{return At.ProjectivePoint.fromHex(e),e}catch(t){throw new xe(String(t))}}function Ei(e){try{return At.getPublicKey(e,!0)}catch(t){throw new Ve(String(t))}}function Pf(){return At.utils.randomPrivateKey()}var jr={"P-256":32,"P-384":48,"P-521":66},Nf=Object.keys(jr),wo=Nf.join(" / ");async function Si(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${wo}`);let t=await it.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await it.get().subtle.importKey("jwk",Of(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let c=await it.get().subtle.importKey("jwk",Bi(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await it.get().subtle.deriveBits({name:"ECDH",public:c},a,jr[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await it.get().subtle.exportKey("jwk",t.publicKey);return{key:kf(n),genSharedKey:r}}function kf(e){if(e.crv==null||e.x==null||e.y==null)throw new N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${wo}`);let t=jr[e.crv];return Tt([Uint8Array.from([4]),bo(e.x,t),bo(e.y,t)],1+t*2)}function Bi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${wo}`);let r=jr[e];if(!ct(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:V(t.subarray(1,r+1),"base64url"),y:V(t.subarray(1+r),"base64url"),ext:!0}}var Of=(e,t)=>({...Bi(e,t.public),d:V(t.private,"base64url")});var Hf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function vi(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=Hf[e],o=n.keySize,s=n.ivSize,i=20,a=G("key expansion"),c=2*(s+o+i),u=await Yr(t,r),f=await u.digest(a),l=[],d=0;for(;d<c;){let A=await u.digest(Tt([f,a])),m=A.length;d+m>c&&(m=c-d),l.push(A),d+=m,f=await u.digest(f)}let E=c/2,g=Tt(l),b=g.subarray(0,E),h=g.subarray(E,c),x=A=>({iv:A.subarray(0,s),cipherKey:A.subarray(s,s+o),macKey:A.subarray(s+o)});return{k1:x(b),k2:x(h)}}async function Mf(e,t){if(e==="Ed25519")return Os();if(e==="secp256k1")return Ai();if(e==="RSA")return ho(Yf(t));if(e==="ECDSA")return ps(Wf(t));throw new zt}async function qf(e,t){if(e!=="Ed25519")throw new zt("Seed key derivation only supported for Ed25519 keys");return Hs(t)}function Vf(e,t){let{Type:r,Data:n}=Ut.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return lo(o,t);case j.Ed25519:return Rr(o);case j.secp256k1:return Fr(o);case j.ECDSA:return Bn(o);default:throw new zt}}function zf(e){if(e.byteLength===Qt)return Rr(e);if(e.byteLength===pi)return Fr(e);let t=xt(e),r=t[1]?.[0];if(r===wn||r===En||r===An)return vn(t);if(t[0]?.[0]===ii)return qr(t,e);throw new N("Could not extract public key from raw bytes")}function Ff(e){let{Type:t,Data:r}=Ut.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Rr(n);case j.secp256k1:return Fr(n);case j.ECDSA:return Bn(n);default:throw new zt}}function ce(e){return Ut.encode({Type:j[e.type],Data:e.raw})}function jf(e){let t=or.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return uo(r);case j.Ed25519:return zn(r);case j.secp256k1:return go(r);case j.ECDSA:return us(r);default:throw new zt}}function Gf(e){if(e.byteLength===Et)return zn(e);if(e.byteLength===mi)return go(e);let t=xt(e),r=t[2]?.[0];if(r===wn||r===En||r===An)return Sn(t);if(t.length>8)return Mr(t);throw new N("Could not extract private key from raw bytes")}function Zf(e){return or.encode({Type:j[e.type],Data:e.raw})}function Yf(e){return e==null?2048:parseInt(e,10)}function Wf(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new N("Unsupported curve, should be P-256, P-384 or P-521")}async function Xf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new N("Only RSA and ECDSA keys are supported")}async function $f(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Vr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Nt(t)}throw new N("Only RSA and ECDSA keys are supported")}function Jf(e,t,r,n){xr(e);let o=bs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Le(s),Le(i),Le(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=jt(t),u=jt(r),f=new Uint8Array(i),l=ar.create(e,c),d=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function Qf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),o.fill(0),r}function Ii(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:c}=Jf(e,t,r,n),u,f=new Uint8Array(4),l=_e(f),d=new Uint8Array(a.outputLen);for(let E=1,g=0;g<s;E++,g+=a.outputLen){let b=i.subarray(g,g+a.outputLen);l.setInt32(0,E,!1),(u=c._cloneInto(u)).update(f).digestInto(d),b.set(d.subarray(0,b.length));for(let h=1;h<o;h++){a._cloneInto(u).update(d).digestInto(d);for(let x=0;x<b.length;x++)b[x]^=d[x]}}return Qf(a,c,i,u,d)}var ur=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),se=new Uint32Array(80),Ao=class extends Gt{constructor(){super(64,20,8,!1),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let c=0;c<16;c++,r+=4)se[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)se[c]=gr(se[c-3]^se[c-8]^se[c-14]^se[c-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let c=0;c<80;c++){let u,f;c<20?(u=wr(o,s,i),f=1518500249):c<40?(u=o^s^i,f=1859775393):c<60?(u=Er(o,s,i),f=2400959708):(u=o^s^i,f=3395469782);let l=gr(n,5)+u+a+f+se[c]|0;a=i,i=s,s=gr(o,30),o=n,n=l}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,this.set(n,o,s,i,a)}roundClean(){se.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},Li=Ue(()=>new Ao);var Ki={sha1:Li,"sha2-256":oe,"sha2-512":Sr};function So(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Ki).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Ki[o],i=Ii(s,e,t,{c:r,dkLen:n});return un.encode(i).substring(1)}return qi(tu);})();
2
+ "use strict";var Libp2PCrypto=(()=>{var Jr=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Qi=Object.getOwnPropertyNames;var ta=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)Jr(e,r,{get:t[r],enumerable:!0})},ea=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qi(t))!ta.call(e,o)&&o!==r&&Jr(e,o,{get:()=>t[o],enumerable:!(n=Ji(t,o))||n.enumerable});return e};var ra=e=>ea(Jr({},"__esModule",{value:!0}),e);var Hf={};ct(Hf,{hmac:()=>xr,keys:()=>Ko,pbkdf2:()=>Uo,randomBytes:()=>uo});var xr={};ct(xr,{create:()=>Qr});var Ve=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 To={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 st=To;var Do={SHA1:20,SHA256:32,SHA512:64};var na={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},oa=async(e,t)=>{let r=await st.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function Qr(e,t){let r=na[e],n=await st.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return oa(n,o)},length:Do[e]}}var Ko={};ct(Ko,{generateEphemeralKeyPair:()=>Mi,generateKeyPair:()=>vf,generateKeyPairFromSeed:()=>Bf,keyStretcher:()=>Vi,privateKeyFromCryptoKeyPair:()=>Pf,privateKeyFromProtobuf:()=>Kf,privateKeyFromRaw:()=>Uf,privateKeyToCryptoKeyPair:()=>Rf,privateKeyToProtobuf:()=>Cf,publicKeyFromMultihash:()=>Lf,publicKeyFromProtobuf:()=>If,publicKeyFromRaw:()=>_f,publicKeyToProtobuf:()=>ae});var H=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Fe=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Gt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var on={};ct(on,{base58btc:()=>et,base58flickr:()=>ua});var Wf=new Uint8Array(0);function Ro(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 Nt(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 Po(e){return new TextEncoder().encode(e)}function No(e){return new TextDecoder().decode(e)}function sa(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 c=e.length,a=e.charAt(0),h=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var m=0,D=0,K=0,O=S.length;K!==O&&S[K]===0;)K++,m++;for(var g=(O-K)*f+1>>>0,u=new Uint8Array(g);K!==O;){for(var b=S[K],v=0,B=g-1;(b!==0||v<D)&&B!==-1;B--,v++)b+=256*u[B]>>>0,u[B]=b%c>>>0,b=b/c>>>0;if(b!==0)throw new Error("Non-zero carry");D=v,K++}for(var _=g-D;_!==g&&u[_]===0;)_++;for(var R=a.repeat(m);_<g;++_)R+=e.charAt(u[_]);return R}function y(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var m=0;if(S[m]!==" "){for(var D=0,K=0;S[m]===a;)D++,m++;for(var O=(S.length-m)*h+1>>>0,g=new Uint8Array(O);S[m];){var u=r[S.charCodeAt(m)];if(u===255)return;for(var b=0,v=O-1;(u!==0||b<K)&&v!==-1;v--,b++)u+=c*g[v]>>>0,g[v]=u%256>>>0,u=u/256>>>0;if(u!==0)throw new Error("Non-zero carry");K=b,m++}if(S[m]!==" "){for(var B=O-K;B!==O&&g[B]===0;)B++;for(var _=new Uint8Array(D+(O-B)),R=D;B!==O;)_[R++]=g[B++];return _}}}function I(S){var m=y(S);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:I}}var ia=sa,aa=ia,Ho=aa;var tn=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")}},en=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 Oo(this,t)}},rn=class{decoders;constructor(t){this.decoders=t}or(t){return Oo(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 Oo(e,t){return new rn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var nn=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 tn(t,r,n),this.decoder=new en(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 nn(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ho(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function ca(e,t,r,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),c=0,a=0,h=0;for(let f=0;f<s;++f){let l=o[e[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,c+=r,c>=8&&(c-=8,i[h++]=255&a>>c)}if(c>=r||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function fa(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function X({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return ge({prefix:t,name:e,encode(o){return fa(o,n,r)},decode(o){return ca(o,n,r,e)}})}var et=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ua=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var sn={};ct(sn,{base32:()=>Ee,base32hex:()=>pa,base32hexpad:()=>ya,base32hexpadupper:()=>ba,base32hexupper:()=>ma,base32pad:()=>la,base32padupper:()=>da,base32upper:()=>ha,base32z:()=>xa});var Ee=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ha=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),la=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),da=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pa=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ma=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ya=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ba=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xa=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var an={};ct(an,{base36:()=>je,base36upper:()=>wa});var je=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wa=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ga=Vo,Mo=128,Ea=127,Aa=~Ea,Sa=Math.pow(2,31);function Vo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Sa;)t[r++]=e&255|Mo,e/=128;for(;e&Aa;)t[r++]=e&255|Mo,e>>>=7;return t[r]=e|0,Vo.bytes=r-n+1,t}var va=cn,Ba=128,qo=127;function cn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw cn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&qo)<<o:(i&qo)*Math.pow(2,o),o+=7}while(i>=Ba);return cn.bytes=s-n,r}var Ia=Math.pow(2,7),_a=Math.pow(2,14),La=Math.pow(2,21),Ka=Math.pow(2,28),Ua=Math.pow(2,35),Ca=Math.pow(2,42),Ta=Math.pow(2,49),Da=Math.pow(2,56),Ra=Math.pow(2,63),Pa=function(e){return e<Ia?1:e<_a?2:e<La?3:e<Ka?4:e<Ua?5:e<Ca?6:e<Ta?7:e<Da?8:e<Ra?9:10},Na={encode:ga,decode:va,encodingLength:Pa},ka=Na,Ge=ka;function Ze(e,t=0){return[Ge.decode(e,t),Ge.decode.bytes]}function Ae(e,t,r=0){return Ge.encode(e,t,r),t}function Se(e){return Ge.encodingLength(e)}function It(e,t){let r=t.byteLength,n=Se(e),o=n+Se(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new ve(e,r,t,s)}function zo(e){let t=Nt(e),[r,n]=Ze(t),[o,s]=Ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(r,o,i,t)}function Fo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ro(e.bytes,r.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function jo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Oa(r,fn(e),t??et.encoder);default:return Ma(r,fn(e),t??Ee.encoder)}}var Go=new WeakMap;function fn(e){let t=Go.get(e);if(t==null){let r=new Map;return Go.set(e,r),r}return t}var St=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!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qa)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=It(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&&Fo(t.multihash,n.multihash)}toString(t){return jo(this,t)}toJSON(){return{"/":jo(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??Zo(n,o,s.bytes))}else if(r[Va]===!0){let{version:n,multihash:o,code:s}=r,i=zo(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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,We,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=Nt(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 ve(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,y]=Ze(t.subarray(r));return r+=y,l},o=n(),s=We;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),h=r+a,f=h-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:h}}static parse(t,r){let[n,o]=Ha(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 fn(s).set(n,t),s}};function Ha(e,t){switch(e[0]){case"Q":{let r=t??et;return[et.prefix,r.decode(`${et.prefix}${e}`)]}case et.prefix:{let r=t??et;return[et.prefix,r.decode(e)]}case Ee.prefix:{let r=t??Ee;return[Ee.prefix,r.decode(e)]}case je.prefix:{let r=t??je;return[je.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 Oa(e,t,r){let{prefix:n}=r;if(n!==et.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 Ma(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 We=112,qa=18;function Zo(e,t,r){let n=Se(e),o=n+Se(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var Va=Symbol.for("@ipld/js-cid/CID");var un={};ct(un,{identity:()=>se});var Yo=0,za="identity",Wo=Nt;function Fa(e){return It(Yo,Wo(e))}var se={code:Yo,name:za,encode:Wo,digest:Fa};function ft(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 kt(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function Ct(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=wt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var $o=Symbol.for("@achingbrain/uint8arraylist");function Xo(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 gr(e){return!!e?.[$o]}var ht=class e{bufs;length;[$o]=!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(gr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(gr(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=Xo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Xo(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(gr(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 Ct(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ct(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let h=t>=c&&t<a,f=r>c&&r<=a;if(h&&f){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(f){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!gr(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 c=i,a=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let l=r;l<=a;l+=f){f=0;for(let y=h;y>=0;y--){let I=this.get(l+y);if(n[y]!==I){f=Math.max(1,y-c[I]);break}}if(f===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=wt(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=kt(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=kt(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=kt(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=wt(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=kt(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=kt(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=kt(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=kt(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=kt(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(!ft(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 hn={};ct(hn,{base10:()=>ja});var ja=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var ln={};ct(ln,{base16:()=>Ga,base16upper:()=>Za});var Ga=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Za=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var dn={};ct(dn,{base2:()=>Ya});var Ya=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pn={};ct(pn,{base256emoji:()=>Qa});var Jo=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}"),Wa=Jo.reduce((e,t,r)=>(e[r]=t,e),[]),Xa=Jo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function $a(e){return e.reduce((t,r)=>(t+=Wa[r],t),"")}function Ja(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Xa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Qa=ge({prefix:"\u{1F680}",name:"base256emoji",encode:$a,decode:Ja});var yn={};ct(yn,{base64:()=>mn,base64pad:()=>tc,base64url:()=>ec,base64urlpad:()=>rc});var mn=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tc=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ec=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),rc=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bn={};ct(bn,{base8:()=>nc});var nc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xn={};ct(xn,{identity:()=>oc});var oc=ge({prefix:"\0",name:"identity",encode:e=>No(e),decode:e=>Po(e)});var Tu=new TextEncoder,Du=new TextDecoder;var En={};ct(En,{sha256:()=>Er,sha512:()=>ac});function gn({name:e,code:t,encode:r}){return new wn(e,t,r)}var wn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?It(this.code,r):r.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ts(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Er=gn({name:"sha2-256",code:18,encode:ts("SHA-256")}),ac=gn({name:"sha2-512",code:19,encode:ts("SHA-512")});var An={...xn,...dn,...bn,...hn,...ln,...sn,...an,...on,...yn,...pn},ju={...En,...un};function rs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var es=rs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Sn=rs("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=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),cc={utf8:es,"utf-8":es,hex:An.base16,latin1:Sn,ascii:Sn,binary:Sn,...An},Ar=cc;function Z(e,t="utf8"){let r=Ar[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function F(e,t="utf8"){let r=Ar[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var fc=parseInt("11111",2),vn=parseInt("10000000",2),uc=parseInt("01111111",2),ns={0:Xe,1:Xe,2:hc,3:pc,4:mc,5:dc,6:lc,16:Xe,22:Xe,48:Xe};function gt(e,t={offset:0}){let r=e[t.offset]&fc;if(t.offset++,ns[r]!=null)return ns[r](e,t);throw new Error("No decoder for tag "+r)}function $e(e,t){let r=0;if((e[t.offset]&vn)===vn){let n=e[t.offset]&uc,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 Xe(e,t){$e(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=gt(e,t);if(n===null)break;r.push(n)}return r}function hc(e,t){let r=$e(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 lc(e,t){let r=$e(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let h=e[t.offset];if(t.offset++,a.push(h&127),h<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function dc(e,t){return t.offset++,null}function pc(e,t){let r=$e(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 mc(e,t){let r=$e(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function yc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ht;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Sr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=yc(e.byteLength);return new ht(Uint8Array.from([t.byteLength|vn]),t)}function lt(e){let t=new ht,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ht(Uint8Array.from([2]),Sr(t),t)}function Je(e){let t=Uint8Array.from([0]),r=new ht(t,e);return new ht(Uint8Array.from([3]),Sr(r),r)}function os(e){return new ht(Uint8Array.from([4]),Sr(e),e)}function _t(e,t=48){let r=new ht;for(let n of e)r.append(n);return new ht(Uint8Array.from([t]),Sr(r),r)}var Bn="1.2.840.10045.3.1.7",In="1.3.132.0.34",_n="1.3.132.0.35";async function ss(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 is(e,t){let r=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},r,t.subarray());return new Uint8Array(n,0,n.byteLength)}async function as(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,r.subarray())}var bc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),xc=Uint8Array.from([6,5,43,129,4,0,34]),wc=Uint8Array.from([6,5,43,129,4,0,35]),cs={ext:!0,kty:"EC",crv:"P-256"},fs={ext:!0,kty:"EC",crv:"P-384"},us={ext:!0,kty:"EC",crv:"P-521"},Be=32,Ie=48,_e=66;function hs(e){let t=gt(e);return Ln(t)}function Ln(e){let t=e[1],r=F(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Be)return s=F(n.subarray(o,o+Be),"base64url"),i=F(n.subarray(o+Be),"base64url"),new Ht({...cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=F(n.subarray(o,o+Ie),"base64url"),i=F(n.subarray(o+Ie),"base64url"),new Ht({...fs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===_e)return s=F(n.subarray(o,o+_e),"base64url"),i=F(n.subarray(o+_e),"base64url"),new Ht({...us,key_ops:["sign"],d:r,x:s,y:i});throw new H(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Kn(e){let t=gt(e);return Un(t)}function Un(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Be*2+1)return n=F(t.subarray(r,r+Be),"base64url"),o=F(t.subarray(r+Be),"base64url"),new ie({...cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=F(t.subarray(r,r+Ie),"base64url"),o=F(t.subarray(r+Ie),"base64url"),new ie({...fs,key_ops:["verify"],x:n,y:o});if(t.byteLength===_e*2+1)return n=F(t.subarray(r,r+_e),"base64url"),o=F(t.subarray(r+_e),"base64url"),new ie({...us,key_ops:["verify"],x:n,y:o});throw new H(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ls(e){return _t([lt(Uint8Array.from([1])),os(Z(e.d??"","base64url")),_t([ps(e.crv)],160),_t([Je(new ht(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function ds(e){return _t([lt(Uint8Array.from([1])),_t([ps(e.crv)],160),_t([Je(new ht(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function ps(e){if(e==="P-256")return bc;if(e==="P-384")return xc;if(e==="P-521")return wc;throw new H(`Invalid curve ${e}`)}async function ms(e="P-256"){let t=await ss(e);return new Ht(t.privateKey)}var ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ds(this.jwk)),this._raw}toMultihash(){return se.digest(ae(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async verify(t,r){return as(this.jwk,r,t)}},Ht=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ie({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=ls(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async sign(t){return is(this.jwk,t)}};var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function gc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Wt(e,...t){if(!gc(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function vr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Yt(e.outputLen),Yt(e.blockLen)}function Ke(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 ys(e,t){Wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function bt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ue(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}function Br(e,t){return e<<t|e>>>32-t>>>0}function Cn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Qe(e){return typeof e=="string"&&(e=Cn(e)),Wt(e),e}function Tn(e){return typeof e=="string"&&(e=Cn(e)),Wt(e),e}function Dn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Wt(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 bs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var Le=class{};function tr(e){let t=n=>e().update(Qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ce(e=32){if(ce&&typeof ce.getRandomValues=="function")return ce.getRandomValues(new Uint8Array(e));if(ce&&typeof ce.randomBytes=="function")return Uint8Array.from(ce.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ec(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,h=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+h,c,n)}function Ir(e,t,r){return e&t^~e&r}function _r(e,t,r){return e&t^e&r^t&r}var fe=class extends Le{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ue(this.buffer)}update(t){Ke(this),t=Qe(t),Wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Ue(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),ys(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,bt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Ec(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Ue(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=a/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<h;l++)c.setUint32(4*l,f[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||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Lr=BigInt(4294967295),xs=BigInt(32);function Ac(e,t=!1){return t?{h:Number(e&Lr),l:Number(e>>xs&Lr)}:{h:Number(e>>xs&Lr)|0,l:Number(e&Lr)|0}}function ws(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:c}=Ac(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Rn=(e,t,r)=>e>>>r,Pn=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,he=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Tt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var gs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Es=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,As=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ss=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,vs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Bs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var vc=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]),Xt=new Uint32Array(64),Kr=class extends fe{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Xt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let y=Xt[l-15],I=Xt[l-2],S=Lt(y,7)^Lt(y,18)^y>>>3,m=Lt(I,17)^Lt(I,19)^I>>>10;Xt[l]=m+Xt[l-7]+S+Xt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:h,H:f}=this;for(let l=0;l<64;l++){let y=Lt(c,6)^Lt(c,11)^Lt(c,25),I=f+y+Ir(c,a,h)+vc[l]+Xt[l]|0,m=(Lt(n,2)^Lt(n,13)^Lt(n,22))+_r(n,o,s)|0;f=h,h=a,a=c,c=i+I|0,i=s,s=o,o=n,n=I+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,c,a,h,f)}roundClean(){bt(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),bt(this.buffer)}};var Is=ws(["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))),Bc=Is[0],Ic=Is[1],$t=new Uint32Array(80),Jt=new Uint32Array(80),Ur=class extends fe{constructor(t=64){super(128,t,16,!1),this.Ah=it[0]|0,this.Al=it[1]|0,this.Bh=it[2]|0,this.Bl=it[3]|0,this.Ch=it[4]|0,this.Cl=it[5]|0,this.Dh=it[6]|0,this.Dl=it[7]|0,this.Eh=it[8]|0,this.El=it[9]|0,this.Fh=it[10]|0,this.Fl=it[11]|0,this.Gh=it[12]|0,this.Gl=it[13]|0,this.Hh=it[14]|0,this.Hl=it[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:h,El:f,Fh:l,Fl:y,Gh:I,Gl:S,Hh:m,Hl:D}=this;return[t,r,n,o,s,i,c,a,h,f,l,y,I,S,m,D]}set(t,r,n,o,s,i,c,a,h,f,l,y,I,S,m,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=c|0,this.Dl=a|0,this.Eh=h|0,this.El=f|0,this.Fh=l|0,this.Fl=y|0,this.Gh=I|0,this.Gl=S|0,this.Hh=m|0,this.Hl=D|0}process(t,r){for(let g=0;g<16;g++,r+=4)$t[g]=t.getUint32(r),Jt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let u=$t[g-15]|0,b=Jt[g-15]|0,v=ue(u,b,1)^ue(u,b,8)^Rn(u,b,7),B=he(u,b,1)^he(u,b,8)^Pn(u,b,7),_=$t[g-2]|0,R=Jt[g-2]|0,k=ue(_,R,19)^er(_,R,61)^Rn(_,R,6),U=he(_,R,19)^rr(_,R,61)^Pn(_,R,6),P=As(B,U,Jt[g-7],Jt[g-16]),T=Ss(P,v,k,$t[g-7],$t[g-16]);$t[g]=T|0,Jt[g]=P|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:h,Dl:f,Eh:l,El:y,Fh:I,Fl:S,Gh:m,Gl:D,Hh:K,Hl:O}=this;for(let g=0;g<80;g++){let u=ue(l,y,14)^ue(l,y,18)^er(l,y,41),b=he(l,y,14)^he(l,y,18)^rr(l,y,41),v=l&I^~l&m,B=y&S^~y&D,_=vs(O,b,B,Ic[g],Jt[g]),R=Bs(_,K,u,v,Bc[g],$t[g]),k=_|0,U=ue(n,o,28)^er(n,o,34)^er(n,o,39),P=he(n,o,28)^rr(n,o,34)^rr(n,o,39),T=n&s^n&c^s&c,J=o&i^o&a^i&a;K=m|0,O=D|0,m=I|0,D=S|0,I=l|0,S=y|0,{h:l,l:y}=Tt(h|0,f|0,R|0,k|0),h=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let E=gs(k,P,J);n=Es(E,R,U,T),o=E|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Tt(this.Ch|0,this.Cl|0,c|0,a|0),{h,l:f}=Tt(this.Dh|0,this.Dl|0,h|0,f|0),{h:l,l:y}=Tt(this.Eh|0,this.El|0,l|0,y|0),{h:I,l:S}=Tt(this.Fh|0,this.Fl|0,I|0,S|0),{h:m,l:D}=Tt(this.Gh|0,this.Gl|0,m|0,D|0),{h:K,l:O}=Tt(this.Hh|0,this.Hl|0,K|0,O|0),this.set(n,o,s,i,c,a,h,f,l,y,I,S,m,D,K,O)}roundClean(){bt($t,Jt)}destroy(){bt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Cr=tr(()=>new Kr);var Tr=tr(()=>new Ur);var On=BigInt(0),Hn=BigInt(1);function Te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Mn(e){if(!Te(e))throw new Error("Uint8Array expected")}function Dt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ks(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?On:BigInt("0x"+e)}var Us=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_c=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if(Mn(e),Us)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_c[e[r]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function _s(e){if(e>=Mt._0&&e<=Mt._9)return e-Mt._0;if(e>=Mt.A&&e<=Mt.F)return e-(Mt.A-10);if(e>=Mt.a&&e<=Mt.f)return e-(Mt.a-10)}function or(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Us)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("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=_s(e.charCodeAt(s)),c=_s(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function qt(e){return Ks(Qt(e))}function le(e){return Mn(e),Ks(Qt(Uint8Array.from(e).reverse()))}function de(e,t){return or(e.toString(16).padStart(t*2,"0"))}function De(e,t){return de(e,t).reverse()}function Y(e,t,r){let n;if(typeof t=="string")try{n=or(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Te(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function te(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Mn(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}var Nn=e=>typeof e=="bigint"&&On<=e;function Dr(e,t,r){return Nn(e)&&Nn(t)&&Nn(r)&&t<=e&&e<r}function Et(e,t,r,n){if(!Dr(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Cs(e){let t;for(t=0;e>On;e>>=Hn,t+=1);return t}var pe=e=>(Hn<<BigInt(e))-Hn,kn=e=>new Uint8Array(e),Ls=e=>Uint8Array.from(e);function Ts(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=kn(e),o=kn(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>r(o,n,...l),a=(l=kn(0))=>{o=c(Ls([0]),l),n=c(),l.length!==0&&(o=c(Ls([1]),l),n=c())},h=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<t;){n=c();let I=n.slice();y.push(I),l+=n.length}return te(...y)};return(l,y)=>{i(),a(l);let I;for(;!(I=y(h()));)a();return i(),I}}var Lc={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Te(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Vt(e,t,r={}){let n=(o,s,i)=>{let c=Lc[s];if(typeof c!="function")throw new Error("invalid validator function");let a=e[o];if(!(i&&a===void 0)&&!c(a,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(r))n(o,s,!0);return e}function Re(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),rt=BigInt(1),me=BigInt(2),Kc=BigInt(3),Rs=BigInt(4),Ps=BigInt(5),Ns=BigInt(8);function j(e,t){let r=e%t;return r>=dt?r:t+r}function W(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function Rr(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=j(e,t),n=t,o=dt,s=rt,i=rt,c=dt;for(;r!==dt;){let h=n/r,f=n%r,l=o-i*h,y=s-c*h;n=r,r=f,o=i,s=c,i=l,c=y}if(n!==rt)throw new Error("invert: does not exist");return j(o,t)}function ks(e,t){let r=(e.ORDER+rt)/Rs,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Uc(e,t){let r=(e.ORDER-Ps)/Ns,n=e.mul(t,me),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,me),o),c=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(c),t))throw new Error("Cannot find square root");return c}function Cc(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-rt,r=0;for(;t%me===dt;)t/=me,r++;let n=me,o=zt(e);for(;Ds(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ks;let s=o.pow(n,t),i=(t+rt)/me;return function(a,h){if(a.is0(h))return h;if(Ds(a,h)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,s),y=a.pow(h,t),I=a.pow(h,i);for(;!a.eql(y,a.ONE);){if(a.is0(y))return a.ZERO;let S=1,m=a.sqr(y);for(;!a.eql(m,a.ONE);)if(S++,m=a.sqr(m),S===f)throw new Error("Cannot find square root");let D=rt<<BigInt(f-S-1),K=a.pow(l,D);f=S,l=a.sqr(K),y=a.mul(y,l),I=a.mul(I,K)}return I}}function Tc(e){return e%Rs===Kc?ks:e%Ns===Ps?Uc:Cc(e)}var Hs=(e,t)=>(j(e,t)&rt)===rt,Dc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Dc.reduce((n,o)=>(n[o]="function",n),t);return Vt(e,r)}function Rc(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===rt)return t;let n=e.ONE,o=t;for(;r>dt;)r&rt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=rt;return n}function Pe(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ds(e,t){let r=(e.ORDER-rt)/me,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Vn(e,t){t!==void 0&&Yt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function zt(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:s}=Vn(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:s,MASK:pe(o),ZERO:dt,ONE:rt,create:a=>j(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return dt<=a&&a<e},is0:a=>a===dt,isOdd:a=>(a&rt)===rt,neg:a=>j(-a,e),eql:(a,h)=>a===h,sqr:a=>j(a*a,e),add:(a,h)=>j(a+h,e),sub:(a,h)=>j(a-h,e),mul:(a,h)=>j(a*h,e),pow:(a,h)=>Rc(c,a,h),div:(a,h)=>j(a*Rr(h,e),e),sqrN:a=>a*a,addN:(a,h)=>a+h,subN:(a,h)=>a-h,mulN:(a,h)=>a*h,inv:a=>Rr(a,e),sqrt:n.sqrt||(a=>(i||(i=Tc(e)),i(c,a))),toBytes:a=>r?De(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return r?le(a):qt(a)},invertBatch:a=>Pe(c,a),cmov:(a,h,f)=>f?h:a});return Object.freeze(c)}function Os(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function zn(e){let t=Os(e);return t+Math.ceil(t/2)}function Ms(e,t,r=!1){let n=e.length,o=Os(t),s=zn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?le(e):qt(e),c=j(i,t-rt)+rt;return r?De(c,o):de(c,o)}var qs=BigInt(0),Yn=BigInt(1);function Fn(e,t){let r=t.negate();return e?r:t}function zs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function jn(e,t){zs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=pe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Vs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Yn);let h=t*n,f=h+Math.abs(c)-1,l=c===0,y=c<0,I=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:y,isNegF:I,offsetF:h}}function Pc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Nc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Gn=new WeakMap,Fs=new WeakMap;function Zn(e){return Fs.get(e)||1}function Pr(e,t){return{constTimeNegate:Fn,hasPrecomputes(r){return Zn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>qs;)n&Yn&&(o=o.add(s)),s=s.double(),n>>=Yn;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=jn(n,t),i=[],c=r,a=c;for(let h=0;h<o;h++){a=c,i.push(a);for(let f=1;f<s;f++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,c=jn(r,t);for(let a=0;a<c.windows;a++){let{nextN:h,offset:f,isZero:l,isNeg:y,isNegF:I,offsetF:S}=Vs(o,a,c);o=h,l?i=i.add(Fn(I,n[S])):s=s.add(Fn(y,n[f]))}return{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=jn(r,t);for(let c=0;c<i.windows&&o!==qs;c++){let{nextN:a,offset:h,isZero:f,isNeg:l}=Vs(o,c,i);if(o=a,!f){let y=n[h];s=s.add(l?y.negate():y)}}return s},getPrecomputes(r,n,o){let s=Gn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Gn.set(n,o(s))),s},wNAFCached(r,n,o){let s=Zn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Zn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){zs(n,t),Fs.set(r,n),Gn.delete(r)}}}function Nr(e,t,r,n){Pc(r,e),Nc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Cs(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let h=pe(a),f=new Array(Number(h)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,y=i;for(let I=l;I>=0;I-=a){f.fill(i);for(let m=0;m<s;m++){let D=n[m],K=Number(D>>BigInt(I)&h);f[K]=f[K].add(r[m])}let S=i;for(let m=f.length-1,D=i;m>0;m--)D=D.add(f[m]),S=S.add(D);if(y=y.add(S),I!==0)for(let m=0;m<a;m++)y=y.double()}return y}function sr(e){return qn(e.Fp),Vt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Vn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Rt=BigInt(0),pt=BigInt(1),js=BigInt(2),kc=BigInt(8),Hc={zip215:!0};function Oc(e){let t=sr(e);return Vt(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Gs(e){let t=Oc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,h=js<<BigInt(c*8)-pt,f=r.create,l=zt(t.n,t.nBitLength);function y(x,d){let p=r.sqr(x),A=r.sqr(d),C=r.add(r.mul(t.a,p),A),N=r.add(r.ONE,r.mul(t.d,r.mul(p,A)));return r.eql(C,N)}if(!y(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let I=t.uvRatio||((x,d)=>{try{return{isValid:!0,value:r.sqrt(x*r.inv(d))}}catch{return{isValid:!1,value:Rt}}}),S=t.adjustScalarBytes||(x=>x),m=t.domain||((x,d,p)=>{if(Dt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return x});function D(x,d,p=!1){let A=p?pt:Rt;Et("coordinate "+x,d,A,h)}function K(x){if(!(x instanceof u))throw new Error("ExtendedPoint expected")}let O=Re((x,d)=>{let{ex:p,ey:A,ez:C}=x,N=x.is0();d==null&&(d=N?kc:r.inv(C));let M=f(p*d),q=f(A*d),V=f(C*d);if(N)return{x:Rt,y:pt};if(V!==pt)throw new Error("invZ was invalid");return{x:M,y:q}}),g=Re(x=>{let{a:d,d:p}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:N,et:M}=x,q=f(A*A),V=f(C*C),z=f(N*N),Q=f(z*z),$=f(q*d),ot=f(z*f($+V)),yt=f(Q+f(p*f(q*V)));if(ot!==yt)throw new Error("bad point: equation left != right (1)");let tt=f(A*C),at=f(N*M);if(tt!==at)throw new Error("bad point: equation left != right (2)");return!0});class u{constructor(d,p,A,C){D("x",d),D("y",p),D("z",A,!0),D("t",C),this.ex=d,this.ey=p,this.ez=A,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof u)throw new Error("extended point not allowed");let{x:p,y:A}=d||{};return D("x",p),D("y",A),new u(p,A,pt,f(p*A))}static normalizeZ(d){let p=Pe(r,d.map(A=>A.ez));return d.map((A,C)=>A.toAffine(p[C])).map(u.fromAffine)}static msm(d,p){return Nr(u,l,d,p)}_setWindowSize(d){B.setWindowSize(this,d)}assertValidity(){g(this)}equals(d){K(d);let{ex:p,ey:A,ez:C}=this,{ex:N,ey:M,ez:q}=d,V=f(p*q),z=f(N*C),Q=f(A*q),$=f(M*C);return V===z&&Q===$}is0(){return this.equals(u.ZERO)}negate(){return new u(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:d}=t,{ex:p,ey:A,ez:C}=this,N=f(p*p),M=f(A*A),q=f(js*f(C*C)),V=f(d*N),z=p+A,Q=f(f(z*z)-N-M),$=V+M,ot=$-q,yt=V-M,tt=f(Q*ot),at=f($*yt),xt=f(Q*yt),Bt=f(ot*$);return new u(tt,at,Bt,xt)}add(d){K(d);let{a:p,d:A}=t,{ex:C,ey:N,ez:M,et:q}=this,{ex:V,ey:z,ez:Q,et:$}=d,ot=f(C*V),yt=f(N*z),tt=f(q*A*$),at=f(M*Q),xt=f((C+N)*(V+z)-ot-yt),Bt=at-tt,qe=at+tt,Co=f(yt-p*ot),Yi=f(xt*Bt),Wi=f(qe*Co),Xi=f(xt*Co),$i=f(Bt*qe);return new u(Yi,Wi,$i,Xi)}subtract(d){return this.add(d.negate())}wNAF(d){return B.wNAFCached(this,d,u.normalizeZ)}multiply(d){let p=d;Et("scalar",p,pt,n);let{p:A,f:C}=this.wNAF(p);return u.normalizeZ([A,C])[0]}multiplyUnsafe(d,p=u.ZERO){let A=d;return Et("scalar",A,Rt,n),A===Rt?v:this.is0()||A===pt?this:B.wNAFCachedUnsafe(this,A,u.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(d){return O(this,d)}clearCofactor(){let{h:d}=t;return d===pt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:A,a:C}=t,N=r.BYTES;d=Y("pointHex",d,N),Dt("zip215",p);let M=d.slice(),q=d[N-1];M[N-1]=q&-129;let V=le(M),z=p?h:r.ORDER;Et("pointHex.y",V,Rt,z);let Q=f(V*V),$=f(Q-pt),ot=f(A*Q-C),{isValid:yt,value:tt}=I($,ot);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let at=(tt&pt)===pt,xt=(q&128)!==0;if(!p&&tt===Rt&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==at&&(tt=f(-tt)),u.fromAffine({x:tt,y:V})}static fromPrivateKey(d){let{scalar:p}=k(d);return b.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),A=De(p,r.BYTES);return A[A.length-1]|=d&pt?128:0,A}toHex(){return Qt(this.toRawBytes())}}u.BASE=new u(t.Gx,t.Gy,pt,f(t.Gx*t.Gy)),u.ZERO=new u(Rt,pt,pt,Rt);let{BASE:b,ZERO:v}=u,B=Pr(u,c*8);function _(x){return j(x,n)}function R(x){return _(le(x))}function k(x){let d=r.BYTES;x=Y("private key",x,d);let p=Y("hashed private key",s(x),2*d),A=S(p.slice(0,d)),C=p.slice(d,2*d),N=R(A);return{head:A,prefix:C,scalar:N}}function U(x){let{head:d,prefix:p,scalar:A}=k(x),C=b.multiply(A),N=C.toRawBytes();return{head:d,prefix:p,scalar:A,point:C,pointBytes:N}}function P(x){return U(x).pointBytes}function T(x=Uint8Array.of(),...d){let p=te(...d);return R(s(m(p,Y("context",x),!!o)))}function J(x,d,p={}){x=Y("message",x),o&&(x=o(x));let{prefix:A,scalar:C,pointBytes:N}=U(d),M=T(p.context,A,x),q=b.multiply(M).toRawBytes(),V=T(p.context,q,N,x),z=_(M+V*C);Et("signature.s",z,Rt,n);let Q=te(q,De(z,r.BYTES));return Y("result",Q,r.BYTES*2)}let E=Hc;function w(x,d,p,A=E){let{context:C,zip215:N}=A,M=r.BYTES;x=Y("signature",x,2*M),d=Y("message",d),p=Y("publicKey",p,M),N!==void 0&&Dt("zip215",N),o&&(d=o(d));let q=le(x.slice(M,2*M)),V,z,Q;try{V=u.fromHex(p,N),z=u.fromHex(x.slice(0,M),N),Q=b.multiplyUnsafe(q)}catch{return!1}if(!N&&V.isSmallOrder())return!1;let $=T(C,z.toRawBytes(),V.toRawBytes(),d);return z.add(V.multiplyUnsafe($)).subtract(Q).clearCofactor().equals(u.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:P,sign:J,verify:w,ExtendedPoint:u,utils:{getExtendedPublicKey:U,randomPrivateKey:()=>i(r.BYTES),precompute(x=8,d=u.BASE){return d._setWindowSize(x),d.multiply(BigInt(3)),d}}}}var Wn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),jh=BigInt(0),Mc=BigInt(1),Ys=BigInt(2),Gh=BigInt(3),qc=BigInt(5),Vc=BigInt(8);function zc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Wn,c=e*e%s*e%s,a=W(c,Ys,s)*c%s,h=W(a,Mc,s)*e%s,f=W(h,qc,s)*h%s,l=W(f,t,s)*f%s,y=W(l,r,s)*l%s,I=W(y,n,s)*y%s,S=W(I,o,s)*I%s,m=W(S,o,s)*I%s,D=W(m,t,s)*f%s;return{pow_p_5_8:W(D,Ys,s)*e%s,b2:c}}function Fc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function jc(e,t){let r=Wn,n=j(t*t*t,r),o=j(n*n*t,r),s=zc(e*o).pow_p_5_8,i=j(e*n*s,r),c=j(t*i*i,r),a=i,h=j(i*Zs,r),f=c===e,l=c===j(-e,r),y=c===j(-e*Zs,r);return f&&(i=a),(l||y)&&(i=h),Hs(i,r)&&(i=j(-i,r)),{isValid:f||l,value:i}}var Ws=zt(Wn,void 0,!0),Gc={a:Ws.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ws,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Vc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Tr,randomBytes:Ce,adjustScalarBytes:Fc,uvRatio:jc},Ne=Gs(Gc);var ee=32,vt=64,kr=32;function Xs(){let e=Ne.utils.randomPrivateKey(),t=Ne.getPublicKey(e);return{privateKey:ti(e,t),publicKey:t}}function $s(e){if(e.length!==kr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Ne.getPublicKey(t);return{privateKey:ti(t,r),publicKey:r}}function Js(e,t){let r=e.subarray(0,kr);return Ne.sign(t instanceof Uint8Array?t:t.subarray(),r)}function Qs(e,t,r){return Ne.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}function ti(e,t){let r=new Uint8Array(vt);for(let n=0;n<kr;n++)r[n]=e[n],r[kr+n]=t[n];return r}var ir=class{type="Ed25519";raw;constructor(t){this.raw=ke(t,ee)}toMultihash(){return se.digest(ae(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r){return Qs(this.raw,r,t)}},ye=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=ke(t,vt),this.publicKey=new ir(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return Js(this.raw,t)}};function Xn(e){if(e.length>vt){e=ke(e,vt+ee);let n=e.subarray(0,vt),o=e.subarray(vt,e.length);return new ye(n,o)}e=ke(e,vt);let t=e.subarray(0,vt),r=e.subarray(ee);return new ye(t,r)}function Hr(e){return e=ke(e,ee),new ir(e)}async function ri(){let{privateKey:e,publicKey:t}=Xs();return new ye(e,t)}async function ni(e){let{privateKey:t,publicKey:r}=$s(e);return new ye(t,r)}function ke(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new H(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Zc=Math.pow(2,7),Yc=Math.pow(2,14),Wc=Math.pow(2,21),oi=Math.pow(2,28),si=Math.pow(2,35),ii=Math.pow(2,42),ai=Math.pow(2,49),mt=128,re=127;function ar(e){if(e<Zc)return 1;if(e<Yc)return 2;if(e<Wc)return 3;if(e<oi)return 4;if(e<si)return 5;if(e<ii)return 6;if(e<ai)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ci(e,t,r=0){switch(ar(e)){case 8:t[r++]=e&255|mt,e/=128;case 7:t[r++]=e&255|mt,e/=128;case 6:t[r++]=e&255|mt,e/=128;case 5:t[r++]=e&255|mt,e/=128;case 4:t[r++]=e&255|mt,e>>>=7;case 3:t[r++]=e&255|mt,e>>>=7;case 2:t[r++]=e&255|mt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function fi(e,t){let r=e[t],n=0;if(n+=r&re,r<mt||(r=e[t+1],n+=(r&re)<<7,r<mt)||(r=e[t+2],n+=(r&re)<<14,r<mt)||(r=e[t+3],n+=(r&re)<<21,r<mt)||(r=e[t+4],n+=(r&re)*oi,r<mt)||(r=e[t+5],n+=(r&re)*si,r<mt)||(r=e[t+6],n+=(r&re)*ii,r<mt)||(r=e[t+7],n+=(r&re)*ai,r<mt))return n;throw new RangeError("Could not decode varint")}var $n=new Float32Array([-0]),ne=new Uint8Array($n.buffer);function ui(e,t,r){$n[0]=e,t[r]=ne[0],t[r+1]=ne[1],t[r+2]=ne[2],t[r+3]=ne[3]}function hi(e,t){return ne[0]=e[t],ne[1]=e[t+1],ne[2]=e[t+2],ne[3]=e[t+3],$n[0]}var Jn=new Float64Array([-0]),ut=new Uint8Array(Jn.buffer);function li(e,t,r){Jn[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function di(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],Jn[0]}var Xc=BigInt(Number.MAX_SAFE_INTEGER),$c=BigInt(Number.MIN_SAFE_INTEGER),At=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<Xc&&t>$c)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>pi&&(o=0n,++n>pi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):be}},be=new At(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var pi=4294967296n;function mi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function yi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Qn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Or(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var to=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Or(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Or(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=hi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=di(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return yi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new At(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Or(this.buf,this.pos+=4),r=Or(this.buf,this.pos+=4);return new At(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=fi(this.buf,this.pos);return this.pos+=ar(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function eo(e){return new to(e instanceof Uint8Array?e:e.subarray())}function Mr(e,t,r){let n=eo(e);return t.decode(n,void 0,r)}function ro(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return wt(i);o+i>t&&(n=wt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var xe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function no(){}var so=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Jc=ro();function Qc(e){return globalThis.Buffer!=null?wt(e):Jc(e)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(no,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new xe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new io((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(qr,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(qr,r.length(),r)}uint64Number(t){return this._push(ci,ar(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=At.fromBigInt(t).zzEncode();return this._push(qr,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(qr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(oo,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(cr,4,r.lo)._push(cr,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(cr,4,r.lo)._push(cr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ui,4,t)}double(t){return this._push(li,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(oo,1,0):this.uint32(r)._push(ef,r,t)}string(t){let r=mi(t);return r!==0?this.uint32(r)._push(Qn,r,t):this._push(oo,1,0)}fork(){return this.states=new so(this),this.head=this.tail=new xe(no,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(no,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Qc(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function oo(e,t,r){t[r]=e&255}function tf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var io=class extends xe{next;constructor(t,r){super(tf,t,r),this.next=void 0}};function qr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function cr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function ef(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(rf,t,e),this},fr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(nf,t,e),this});function rf(e,t,r){t.set(e,r)}function nf(e,t,r){e.length<40?Qn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function ao(){return new fr}function Vr(e,t){let r=ao();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var He;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(He||(He={}));function zr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function co(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return zr("enum",He.VARINT,r,n)}function Fr(e,t){return zr("message",He.LENGTH_DELIMITED,e,t)}var G;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(G||(G={}));var fo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(fo||(fo={}));(function(e){e.codec=()=>co(fo)})(G||(G={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=Fr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),G.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=G.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Vr(r,e.codec()),e.decode=(r,n)=>Mr(r,e.codec(),n)})(Pt||(Pt={}));var ur;(function(e){let t;e.codec=()=>(t==null&&(t=Fr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),G.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=G.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Vr(r,e.codec()),e.decode=(r,n)=>Mr(r,e.codec(),n)})(ur||(ur={}));function uo(e){if(isNaN(e)||e<=0)throw new H("random bytes length must be a Number bigger than 0");return Ce(e)}var lr={};ct(lr,{MAX_RSA_KEY_SIZE:()=>ho,generateRSAKeyPair:()=>wo,jwkToJWKKeyPair:()=>Ei,jwkToPkcs1:()=>cf,jwkToPkix:()=>yo,jwkToRSAPrivateKey:()=>Zr,pkcs1MessageToJwk:()=>po,pkcs1MessageToRSAPrivateKey:()=>jr,pkcs1ToJwk:()=>af,pkcs1ToRSAPrivateKey:()=>bo,pkixMessageToJwk:()=>mo,pkixMessageToRSAPublicKey:()=>Gr,pkixToJwk:()=>ff,pkixToRSAPublicKey:()=>xo});var Oe=Cr;var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return St.createV1(114,this._multihash)}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r){return gi(this.jwk,r,t)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return wi(this.jwk,t)}};var ho=8192,lo=18,of=1062,sf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function af(e){let t=gt(e);return po(t)}function po(e){return{n:F(e[1],"base64url"),e:F(e[2],"base64url"),d:F(e[3],"base64url"),p:F(e[4],"base64url"),q:F(e[5],"base64url"),dp:F(e[6],"base64url"),dq:F(e[7],"base64url"),qi:F(e[8],"base64url"),kty:"RSA"}}function cf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new H("JWK was missing components");return _t([lt(Uint8Array.from([0])),lt(Z(e.n,"base64url")),lt(Z(e.e,"base64url")),lt(Z(e.d,"base64url")),lt(Z(e.p,"base64url")),lt(Z(e.q,"base64url")),lt(Z(e.dp,"base64url")),lt(Z(e.dq,"base64url")),lt(Z(e.qi,"base64url"))]).subarray()}function ff(e){let t=gt(e,{offset:0});return mo(t)}function mo(e){let t=gt(e[1],{offset:0});return{kty:"RSA",n:F(t[0],"base64url"),e:F(t[1],"base64url")}}function yo(e){if(e.n==null||e.e==null)throw new H("JWK was missing components");return _t([sf,Je(_t([lt(Z(e.n,"base64url")),lt(Z(e.e,"base64url"))]))]).subarray()}function bo(e){let t=gt(e);return jr(t)}function jr(e){let t=po(e);return Zr(t)}function xo(e,t){if(e.byteLength>=of)throw new we("Key size is too large");let r=gt(e,{offset:0});return Gr(r,e,t)}function Gr(e,t,r){let n=mo(e);if(r==null){let o=Oe(Pt.encode({Type:G.RSA,Data:t}));r=It(lo,o)}return new Me(n,r)}function Zr(e){if(Si(e)>ho)throw new H("Key size is too large");let t=Ei(e),r=Oe(Pt.encode({Type:G.RSA,Data:yo(t.publicKey)})),n=It(lo,r);return new hr(t.privateKey,new Me(t.publicKey,n))}async function wo(e){if(e>ho)throw new H("Key size is too large");let t=await Ai(e),r=Oe(Pt.encode({Type:G.RSA,Data:yo(t.publicKey)})),n=It(lo,r);return new hr(t.privateKey,new Me(t.publicKey,n))}function Ei(e){if(e==null)throw new H("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var vi="1.2.840.113549.1.1.1";async function Ai(e){let t=await st.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await uf(t);return{privateKey:r[0],publicKey:r[1]}}async function wi(e,t){let r=await st.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await st.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function gi(e,t,r){let n=await st.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return st.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function uf(e){if(e.privateKey==null||e.publicKey==null)throw new H("Private and public key are required");return Promise.all([st.get().subtle.exportKey("jwk",e.privateKey),st.get().subtle.exportKey("jwk",e.publicKey)])}function Si(e){if(e.kty!=="RSA")throw new H("invalid key type");if(e.n==null)throw new H("invalid key modulus");return Z(e.n,"base64url").length*8}var Yr=class extends Le{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,vr(t);let n=Qe(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),bt(s)}update(t){return Ke(this),this.iHash.update(t),this}digestInto(t){Ke(this),Wt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},dr=(e,t,r)=>new Yr(e,t).update(r).digest();dr.create=(e,t)=>new Yr(e,t);function Bi(e){e.lowS!==void 0&&Dt("lowS",e.lowS),e.prehash!==void 0&&Dt("prehash",e.prehash)}function hf(e){let t=sr(e);Vt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Ao=class extends Error{constructor(t=""){super(t)}},Ft={Err:Ao,_tlv:{encode:(e,t)=>{let{Err:r}=Ft;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(e)+s+o+t},decode(e,t){let{Err:r}=Ft,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let h=t.subarray(n,n+a);if(h.length!==a)throw new r("tlv.decode: length bytes not complete");if(h[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of h)i=i<<8|f;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Ft;if(e<jt)throw new t("integer: negative integers are not allowed");let r=nr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ft;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ft,o=Y("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:h,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:r}=Ft,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};function go(e,t){return Qt(de(e,t))}var jt=BigInt(0),nt=BigInt(1),y0=BigInt(2),Eo=BigInt(3),lf=BigInt(4);function df(e){let t=hf(e),{Fp:r}=t,n=zt(t.n,t.nBitLength),o=t.toBytes||((g,u,b)=>{let v=u.toAffine();return te(Uint8Array.from([4]),r.toBytes(v.x),r.toBytes(v.y))}),s=t.fromBytes||(g=>{let u=g.subarray(1),b=r.fromBytes(u.subarray(0,r.BYTES)),v=r.fromBytes(u.subarray(r.BYTES,2*r.BYTES));return{x:b,y:v}});function i(g){let{a:u,b}=t,v=r.sqr(g),B=r.mul(v,g);return r.add(r.add(B,r.mul(g,u)),b)}function c(g,u){let b=r.sqr(u),v=i(g);return r.eql(b,v)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=r.mul(r.pow(t.a,Eo),lf),h=r.mul(r.sqr(t.b),BigInt(27));if(r.is0(r.add(a,h)))throw new Error("bad curve params: a or b");function f(g){return Dr(g,nt,t.n)}function l(g){let{allowedPrivateKeyLengths:u,nByteLength:b,wrapPrivateKey:v,n:B}=t;if(u&&typeof g!="bigint"){if(Te(g)&&(g=Qt(g)),typeof g!="string"||!u.includes(g.length))throw new Error("invalid private key");g=g.padStart(b*2,"0")}let _;try{_=typeof g=="bigint"?g:qt(Y("private key",g,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof g)}return v&&(_=j(_,B)),Et("private key",_,nt,B),_}function y(g){if(!(g instanceof m))throw new Error("ProjectivePoint expected")}let I=Re((g,u)=>{let{px:b,py:v,pz:B}=g;if(r.eql(B,r.ONE))return{x:b,y:v};let _=g.is0();u==null&&(u=_?r.ONE:r.inv(B));let R=r.mul(b,u),k=r.mul(v,u),U=r.mul(B,u);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql(U,r.ONE))throw new Error("invZ was invalid");return{x:R,y:k}}),S=Re(g=>{if(g.is0()){if(t.allowInfinityPoint&&!r.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:u,y:b}=g.toAffine();if(!r.isValid(u)||!r.isValid(b))throw new Error("bad point: x or y not FE");if(!c(u,b))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(u,b,v){if(u==null||!r.isValid(u))throw new Error("x required");if(b==null||!r.isValid(b)||r.is0(b))throw new Error("y required");if(v==null||!r.isValid(v))throw new Error("z required");this.px=u,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(u){let{x:b,y:v}=u||{};if(!u||!r.isValid(b)||!r.isValid(v))throw new Error("invalid affine point");if(u instanceof m)throw new Error("projective point not allowed");let B=_=>r.eql(_,r.ZERO);return B(b)&&B(v)?m.ZERO:new m(b,v,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(u){let b=Pe(r,u.map(v=>v.pz));return u.map((v,B)=>v.toAffine(b[B])).map(m.fromAffine)}static fromHex(u){let b=m.fromAffine(s(Y("pointHex",u)));return b.assertValidity(),b}static fromPrivateKey(u){return m.BASE.multiply(l(u))}static msm(u,b){return Nr(m,n,u,b)}_setWindowSize(u){O.setWindowSize(this,u)}assertValidity(){S(this)}hasEvenY(){let{y:u}=this.toAffine();if(r.isOdd)return!r.isOdd(u);throw new Error("Field doesn't support isOdd")}equals(u){y(u);let{px:b,py:v,pz:B}=this,{px:_,py:R,pz:k}=u,U=r.eql(r.mul(b,k),r.mul(_,B)),P=r.eql(r.mul(v,k),r.mul(R,B));return U&&P}negate(){return new m(this.px,r.neg(this.py),this.pz)}double(){let{a:u,b}=t,v=r.mul(b,Eo),{px:B,py:_,pz:R}=this,k=r.ZERO,U=r.ZERO,P=r.ZERO,T=r.mul(B,B),J=r.mul(_,_),E=r.mul(R,R),w=r.mul(B,_);return w=r.add(w,w),P=r.mul(B,R),P=r.add(P,P),k=r.mul(u,P),U=r.mul(v,E),U=r.add(k,U),k=r.sub(J,U),U=r.add(J,U),U=r.mul(k,U),k=r.mul(w,k),P=r.mul(v,P),E=r.mul(u,E),w=r.sub(T,E),w=r.mul(u,w),w=r.add(w,P),P=r.add(T,T),T=r.add(P,T),T=r.add(T,E),T=r.mul(T,w),U=r.add(U,T),E=r.mul(_,R),E=r.add(E,E),T=r.mul(E,w),k=r.sub(k,T),P=r.mul(E,J),P=r.add(P,P),P=r.add(P,P),new m(k,U,P)}add(u){y(u);let{px:b,py:v,pz:B}=this,{px:_,py:R,pz:k}=u,U=r.ZERO,P=r.ZERO,T=r.ZERO,J=t.a,E=r.mul(t.b,Eo),w=r.mul(b,_),L=r.mul(v,R),x=r.mul(B,k),d=r.add(b,v),p=r.add(_,R);d=r.mul(d,p),p=r.add(w,L),d=r.sub(d,p),p=r.add(b,B);let A=r.add(_,k);return p=r.mul(p,A),A=r.add(w,x),p=r.sub(p,A),A=r.add(v,B),U=r.add(R,k),A=r.mul(A,U),U=r.add(L,x),A=r.sub(A,U),T=r.mul(J,p),U=r.mul(E,x),T=r.add(U,T),U=r.sub(L,T),T=r.add(L,T),P=r.mul(U,T),L=r.add(w,w),L=r.add(L,w),x=r.mul(J,x),p=r.mul(E,p),L=r.add(L,x),x=r.sub(w,x),x=r.mul(J,x),p=r.add(p,x),w=r.mul(L,p),P=r.add(P,w),w=r.mul(A,p),U=r.mul(d,U),U=r.sub(U,w),w=r.mul(d,L),T=r.mul(A,T),T=r.add(T,w),new m(U,P,T)}subtract(u){return this.add(u.negate())}is0(){return this.equals(m.ZERO)}wNAF(u){return O.wNAFCached(this,u,m.normalizeZ)}multiplyUnsafe(u){let{endo:b,n:v}=t;Et("scalar",u,jt,v);let B=m.ZERO;if(u===jt)return B;if(this.is0()||u===nt)return this;if(!b||O.hasPrecomputes(this))return O.wNAFCachedUnsafe(this,u,m.normalizeZ);let{k1neg:_,k1:R,k2neg:k,k2:U}=b.splitScalar(u),P=B,T=B,J=this;for(;R>jt||U>jt;)R&nt&&(P=P.add(J)),U&nt&&(T=T.add(J)),J=J.double(),R>>=nt,U>>=nt;return _&&(P=P.negate()),k&&(T=T.negate()),T=new m(r.mul(T.px,b.beta),T.py,T.pz),P.add(T)}multiply(u){let{endo:b,n:v}=t;Et("scalar",u,nt,v);let B,_;if(b){let{k1neg:R,k1:k,k2neg:U,k2:P}=b.splitScalar(u),{p:T,f:J}=this.wNAF(k),{p:E,f:w}=this.wNAF(P);T=O.constTimeNegate(R,T),E=O.constTimeNegate(U,E),E=new m(r.mul(E.px,b.beta),E.py,E.pz),B=T.add(E),_=J.add(w)}else{let{p:R,f:k}=this.wNAF(u);B=R,_=k}return m.normalizeZ([B,_])[0]}multiplyAndAddUnsafe(u,b,v){let B=m.BASE,_=(k,U)=>U===jt||U===nt||!k.equals(B)?k.multiplyUnsafe(U):k.multiply(U),R=_(this,b).add(_(u,v));return R.is0()?void 0:R}toAffine(u){return I(this,u)}isTorsionFree(){let{h:u,isTorsionFree:b}=t;if(u===nt)return!0;if(b)return b(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:u,clearCofactor:b}=t;return u===nt?this:b?b(m,this):this.multiplyUnsafe(t.h)}toRawBytes(u=!0){return Dt("isCompressed",u),this.assertValidity(),o(m,this,u)}toHex(u=!0){return Dt("isCompressed",u),Qt(this.toRawBytes(u))}}m.BASE=new m(t.Gx,t.Gy,r.ONE),m.ZERO=new m(r.ZERO,r.ONE,r.ZERO);let{endo:D,nBitLength:K}=t,O=Pr(m,D?Math.ceil(K/2):K);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:f}}function pf(e){let t=sr(e);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ii(e){let t=pf(e),{Fp:r,n,nByteLength:o,nBitLength:s}=t,i=r.BYTES+1,c=2*r.BYTES+1;function a(E){return j(E,n)}function h(E){return Rr(E,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:y,isWithinCurveOrder:I}=df({...t,toBytes(E,w,L){let x=w.toAffine(),d=r.toBytes(x.x),p=te;return Dt("isCompressed",L),L?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,r.toBytes(x.y))},fromBytes(E){let w=E.length,L=E[0],x=E.subarray(1);if(w===i&&(L===2||L===3)){let d=qt(x);if(!Dr(d,nt,r.ORDER))throw new Error("Point is not on curve");let p=y(d),A;try{A=r.sqrt(p)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+q)}let C=(A&nt)===nt;return(L&1)===1!==C&&(A=r.neg(A)),{x:d,y:A}}else if(w===c&&L===4){let d=r.fromBytes(x.subarray(0,r.BYTES)),p=r.fromBytes(x.subarray(r.BYTES,2*r.BYTES));return{x:d,y:p}}else{let d=i,p=c;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function S(E){let w=n>>nt;return E>w}function m(E){return S(E)?a(-E):E}let D=(E,w,L)=>qt(E.slice(w,L));class K{constructor(w,L,x){Et("r",w,nt,n),Et("s",L,nt,n),this.r=w,this.s=L,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(w){let L=o;return w=Y("compactSignature",w,L*2),new K(D(w,0,L),D(w,L,2*L))}static fromDER(w){let{r:L,s:x}=Ft.toSig(Y("DER",w));return new K(L,x)}assertValidity(){}addRecoveryBit(w){return new K(this.r,this.s,w)}recoverPublicKey(w){let{r:L,s:x,recovery:d}=this,p=B(Y("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let A=d===2||d===3?L+t.n:L;if(A>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(d&1)===0?"02":"03",N=f.fromHex(C+go(A,r.BYTES)),M=h(A),q=a(-p*M),V=a(x*M),z=f.BASE.multiplyAndAddUnsafe(N,q,V);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return S(this.s)}normalizeS(){return this.hasHighS()?new K(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return Ft.hexFromSig(this)}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){let w=o;return go(this.r,w)+go(this.s,w)}}let O={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=zn(t.n);return Ms(t.randomBytes(E),t.n)},precompute(E=8,w=f.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function g(E,w=!0){return f.fromPrivateKey(E).toRawBytes(w)}function u(E){if(typeof E=="bigint")return!1;if(E instanceof f)return!0;let L=Y("key",E).length,x=r.BYTES,d=x+1,p=2*x+1;if(!(t.allowedPrivateKeyLengths||o===d))return L===d||L===p}function b(E,w,L=!0){if(u(E)===!0)throw new Error("first arg must be private key");if(u(w)===!1)throw new Error("second arg must be public key");return f.fromHex(w).multiply(l(E)).toRawBytes(L)}let v=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=qt(E),L=E.length*8-s;return L>0?w>>BigInt(L):w},B=t.bits2int_modN||function(E){return a(v(E))},_=pe(s);function R(E){return Et("num < 2^"+s,E,jt,_),de(E,o)}function k(E,w,L=U){if(["recovered","canonical"].some($=>$ in L))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:d}=t,{lowS:p,prehash:A,extraEntropy:C}=L;p==null&&(p=!0),E=Y("msgHash",E),Bi(L),A&&(E=Y("prehashed msgHash",x(E)));let N=B(E),M=l(w),q=[R(M),R(N)];if(C!=null&&C!==!1){let $=C===!0?d(r.BYTES):C;q.push(Y("extraEntropy",$))}let V=te(...q),z=N;function Q($){let ot=v($);if(!I(ot))return;let yt=h(ot),tt=f.BASE.multiply(ot).toAffine(),at=a(tt.x);if(at===jt)return;let xt=a(yt*a(z+at*M));if(xt===jt)return;let Bt=(tt.x===at?0:2)|Number(tt.y&nt),qe=xt;return p&&S(xt)&&(qe=m(xt),Bt^=1),new K(at,qe,Bt)}return{seed:V,k2sig:Q}}let U={lowS:t.lowS,prehash:!1},P={lowS:t.lowS,prehash:!1};function T(E,w,L=U){let{seed:x,k2sig:d}=k(E,w,L),p=t;return Ts(p.hash.outputLen,p.nByteLength,p.hmac)(x,d)}f.BASE._setWindowSize(8);function J(E,w,L,x=P){let d=E;w=Y("msgHash",w),L=Y("publicKey",L);let{lowS:p,prehash:A,format:C}=x;if(Bi(x),"strict"in x)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let N=typeof d=="string"||Te(d),M=!N&&!C&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!N&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,V;try{if(M&&(q=new K(d.r,d.s)),N){try{C!=="compact"&&(q=K.fromDER(d))}catch(Bt){if(!(Bt instanceof Ft.Err))throw Bt}!q&&C!=="der"&&(q=K.fromCompact(d))}V=f.fromHex(L)}catch{return!1}if(!q||p&&q.hasHighS())return!1;A&&(w=t.hash(w));let{r:z,s:Q}=q,$=B(w),ot=h(Q),yt=a($*ot),tt=a(z*ot),at=f.BASE.multiplyAndAddUnsafe(V,yt,tt)?.toAffine();return at?a(at.x)===z:!1}return{CURVE:t,getPublicKey:g,getSharedSecret:b,sign:T,verify:J,ProjectivePoint:f,Signature:K,utils:O}}function mf(e){return{hash:e,hmac:(t,...r)=>dr(e,t,Dn(...r)),randomBytes:Ce}}function _i(e,t){let r=n=>Ii({...e,...mf(n)});return{...r(t),create:r}}var Ui=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Li=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yf=BigInt(0),bf=BigInt(1),So=BigInt(2),Ki=(e,t)=>(e+t/So)/t;function xf(e){let t=Ui,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),h=e*e*e%t,f=h*h*e%t,l=W(f,r,t)*f%t,y=W(l,r,t)*f%t,I=W(y,So,t)*h%t,S=W(I,o,t)*I%t,m=W(S,s,t)*S%t,D=W(m,c,t)*m%t,K=W(D,a,t)*D%t,O=W(K,c,t)*m%t,g=W(O,r,t)*f%t,u=W(g,i,t)*S%t,b=W(u,n,t)*h%t,v=W(b,So,t);if(!vo.eql(vo.sqr(v),e))throw new Error("Cannot find square root");return v}var vo=zt(Ui,void 0,void 0,{sqrt:xf}),Ut=_i({a:yf,b:BigInt(7),Fp:vo,n:Li,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=Li,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-bf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),c=Ki(s*e,t),a=Ki(-n*e,t),h=j(e-c*r-a*o,t),f=j(-c*n-a*s,t),l=h>i,y=f>i;if(l&&(h=t-h),y&&(f=t-f),h>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:h,k2neg:y,k2:f}}}},Cr);function Bo(e,t){let r=Z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Ct([new Uint8Array(t-r.length),r])}return r}function Io(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ci=33,Ti=32;function Di(e,t){let r=Er.digest(t instanceof Uint8Array?t:t.subarray());if(Io(r))return r.then(({digest:n})=>Ut.sign(n,e).toDERRawBytes()).catch(n=>{throw new Ve(String(n))});try{return Ut.sign(r.digest,e).toDERRawBytes()}catch(n){throw new Ve(String(n))}}function Ri(e,t,r){let n=Er.digest(r instanceof Uint8Array?r:r.subarray());if(Io(n))return n.then(({digest:o})=>Ut.verify(t,o,e)).catch(o=>{throw new ze(String(o))});try{return Ut.verify(t,n.digest,e)}catch(o){throw new ze(String(o))}}var pr=class{type="secp256k1";raw;_key;constructor(t){this._key=ki(t),this.raw=Pi(this._key)}toMultihash(){return se.digest(ae(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r){return Ri(this._key,r,t)}},mr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Ni(t),this.publicKey=new pr(r??Hi(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return Di(this.raw,t)}};function _o(e){return new mr(e)}function Wr(e){return new pr(e)}async function Oi(){let e=wf();return new mr(e)}function Pi(e){return Ut.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Ni(e){try{return Ut.getPublicKey(e,!0),e}catch(t){throw new Fe(String(t))}}function ki(e){try{return Ut.ProjectivePoint.fromHex(e),e}catch(t){throw new we(String(t))}}function Hi(e){try{return Ut.getPublicKey(e,!0)}catch(t){throw new Fe(String(t))}}function wf(){return Ut.utils.randomPrivateKey()}var Xr={"P-256":32,"P-384":48,"P-521":66},gf=Object.keys(Xr),Lo=gf.join(" / ");async function Mi(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new H(`Unknown curve: ${e}. Must be ${Lo}`);let t=await st.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let c;i!=null?c=await st.get().subtle.importKey("jwk",Af(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):c=t.privateKey;let a=await st.get().subtle.importKey("jwk",qi(e,s),{name:"ECDH",namedCurve:e},!1,[]),h=await st.get().subtle.deriveBits({name:"ECDH",public:a},c,Xr[e]*8);return new Uint8Array(h,0,h.byteLength)},n=await st.get().subtle.exportKey("jwk",t.publicKey);return{key:Ef(n),genSharedKey:r}}function Ef(e){if(e.crv==null||e.x==null||e.y==null)throw new H("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new H(`Unknown curve: ${e.crv}. Must be ${Lo}`);let t=Xr[e.crv];return Ct([Uint8Array.from([4]),Bo(e.x,t),Bo(e.y,t)],1+t*2)}function qi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new H(`Unknown curve: ${e}. Must be ${Lo}`);let r=Xr[e];if(!ft(t.subarray(0,1),Uint8Array.from([4])))throw new H("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:F(t.subarray(1,r+1),"base64url"),y:F(t.subarray(1+r),"base64url"),ext:!0}}var Af=(e,t)=>({...qi(e,t.public),d:F(t.private,"base64url")});var Sf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Vi(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new H("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new H("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new H("Secret was missing or an incorrect type");let n=Sf[e],o=n.keySize,s=n.ivSize,i=20,c=Z("key expansion"),a=2*(s+o+i),h=await Qr(t,r),f=await h.digest(c),l=[],y=0;for(;y<a;){let O=await h.digest(Ct([f,c])),g=O.length;y+g>a&&(g=a-y),l.push(O),y+=g,f=await h.digest(f)}let I=a/2,S=Ct(l),m=S.subarray(0,I),D=S.subarray(I,a),K=O=>({iv:O.subarray(0,s),cipherKey:O.subarray(s,s+o),macKey:O.subarray(s+o)});return{k1:K(m),k2:K(D)}}async function vf(e,t){if(e==="Ed25519")return ri();if(e==="secp256k1")return Oi();if(e==="RSA")return wo(Tf(t));if(e==="ECDSA")return ms(Df(t));throw new Gt}async function Bf(e,t){if(e!=="Ed25519")throw new Gt("Seed key derivation only supported for Ed25519 keys");return ni(t)}function If(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case G.RSA:return xo(o,t);case G.Ed25519:return Hr(o);case G.secp256k1:return Wr(o);case G.ECDSA:return Kn(o);default:throw new Gt}}function _f(e){if(e.byteLength===ee)return Hr(e);if(e.byteLength===Ci)return Wr(e);let t=gt(e),r=t[1]?.[0];if(r===Bn||r===In||r===_n)return Un(t);if(t[0]?.[0]===vi)return Gr(t,e);throw new H("Could not extract public key from raw bytes")}function Lf(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case G.Ed25519:return Hr(n);case G.secp256k1:return Wr(n);case G.ECDSA:return Kn(n);default:throw new Gt}}function ae(e){return Pt.encode({Type:G[e.type],Data:e.raw})}function Kf(e){let t=ur.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case G.RSA:return bo(r);case G.Ed25519:return Xn(r);case G.secp256k1:return _o(r);case G.ECDSA:return hs(r);default:throw new Gt}}function Uf(e){if(e.byteLength===vt)return Xn(e);if(e.byteLength===Ti)return _o(e);let t=gt(e),r=t[2]?.[0];if(r===Bn||r===In||r===_n)return Ln(t);if(t.length>8)return jr(t);throw new H("Could not extract private key from raw bytes")}function Cf(e){return ur.encode({Type:G[e.type],Data:e.raw})}function Tf(e){return e==null?2048:parseInt(e,10)}function Df(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new H("Unsupported curve, should be P-256, P-384 or P-521")}async function Rf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new H("Only RSA and ECDSA keys are supported")}async function Pf(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Zr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Ht(t)}throw new H("Only RSA and ECDSA keys are supported")}function Nf(e,t,r,n){vr(e);let o=bs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(Yt(s),Yt(i),Yt(c),s<1)throw new Error("iterations (c) should be >= 1");let a=Tn(t),h=Tn(r),f=new Uint8Array(i),l=dr.create(e,a),y=l._cloneInto().update(h);return{c:s,dkLen:i,asyncTick:c,DK:f,PRF:l,PRFSalt:y}}function kf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),bt(o),r}function zi(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:c,PRFSalt:a}=Nf(e,t,r,n),h,f=new Uint8Array(4),l=Ue(f),y=new Uint8Array(c.outputLen);for(let I=1,S=0;S<s;I++,S+=c.outputLen){let m=i.subarray(S,S+c.outputLen);l.setInt32(0,I,!1),(h=a._cloneInto(h)).update(f).digestInto(y),m.set(y.subarray(0,m.length));for(let D=1;D<o;D++){c._cloneInto(h).update(y).digestInto(y);for(let K=0;K<m.length;K++)m[K]^=y[K]}}return kf(c,a,i,h,y)}var yr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),oe=new Uint32Array(80),$r=class extends fe{constructor(){super(64,20,8,!1),this.A=yr[0]|0,this.B=yr[1]|0,this.C=yr[2]|0,this.D=yr[3]|0,this.E=yr[4]|0}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let a=0;a<16;a++,r+=4)oe[a]=t.getUint32(r,!1);for(let a=16;a<80;a++)oe[a]=Br(oe[a-3]^oe[a-8]^oe[a-14]^oe[a-16],1);let{A:n,B:o,C:s,D:i,E:c}=this;for(let a=0;a<80;a++){let h,f;a<20?(h=Ir(o,s,i),f=1518500249):a<40?(h=o^s^i,f=1859775393):a<60?(h=_r(o,s,i),f=2400959708):(h=o^s^i,f=3395469782);let l=Br(n,5)+h+c+f+oe[a]|0;c=i,i=s,s=Br(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,this.set(n,o,s,i,c)}roundClean(){bt(oe)}destroy(){this.set(0,0,0,0,0),bt(this.buffer)}},Fi=tr(()=>new $r);var ji=Fi;var Gi=Tr;var Zi={sha1:ji,"sha2-256":Oe,"sha2-512":Gi};function Uo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let c=Object.keys(Zi).join(" / ");throw new H(`Hash '${o}' is unknown or not supported. Must be ${c}`)}let s=Zi[o],i=zi(s,e,t,{c:r,dkLen:n});return mn.encode(i).substring(1)}return ra(Hf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
8
  @noble/curves/esm/abstract/utils.js:
9
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
10
-
11
9
  @noble/curves/esm/abstract/modular.js:
12
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
13
-
14
10
  @noble/curves/esm/abstract/curve.js:
15
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
16
-
17
11
  @noble/curves/esm/abstract/edwards.js:
18
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
19
-
20
12
  @noble/curves/esm/ed25519.js:
21
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
22
-
23
13
  @noble/curves/esm/abstract/weierstrass.js:
24
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
25
-
26
14
  @noble/curves/esm/_shortw_utils.js:
27
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
28
-
29
15
  @noble/curves/esm/secp256k1.js:
30
16
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
31
17
  */
32
18
  return Libp2PCrypto}));
19
+ //# sourceMappingURL=index.min.js.map