@libp2p/crypto 5.1.1-f1de46607 → 5.1.2

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,5 +1,5 @@
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 $r=Object.defineProperty;var Yi=Object.getOwnPropertyDescriptor;var Xi=Object.getOwnPropertyNames;var $i=Object.prototype.hasOwnProperty;var at=(e,t)=>{for(var r in t)$r(e,r,{get:t[r],enumerable:!0})},Ji=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xi(t))!$i.call(e,o)&&o!==r&&$r(e,o,{get:()=>t[o],enumerable:!(n=Yi(t,o))||n.enumerable});return e};var Qi=e=>Ji($r({},"__esModule",{value:!0}),e);var Pf={};at(Pf,{hmac:()=>br,keys:()=>_o,pbkdf2:()=>Lo,randomBytes:()=>uo});var br={};at(br,{create:()=>Jr});var qe=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Ve=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},yr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Uo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new yr("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 ot=Uo;var Co={SHA1:20,SHA256:32,SHA512:64};var ta={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},ea=async(e,t)=>{let r=await ot.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function Jr(e,t){let r=ta[e],n=await ot.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return ea(n,o)},length:Co[e]}}var _o={};at(_o,{generateEphemeralKeyPair:()=>ki,generateKeyPair:()=>Ef,generateKeyPairFromSeed:()=>Af,keyStretcher:()=>Oi,privateKeyFromCryptoKeyPair:()=>Tf,privateKeyFromProtobuf:()=>If,privateKeyFromRaw:()=>_f,privateKeyToCryptoKeyPair:()=>Cf,privateKeyToProtobuf:()=>Lf,publicKeyFromMultihash:()=>vf,publicKeyFromProtobuf:()=>Sf,publicKeyFromRaw:()=>Bf,publicKeyToProtobuf:()=>ie});var P=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ge=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},ze=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var nn={};at(nn,{base58btc:()=>et,base58flickr:()=>aa});var Zf=new Uint8Array(0);function To(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){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 Ro(e){return new TextDecoder().decode(e)}function ra(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(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 y=0,l=0,b=0,A=g.length;b!==A&&g[b]===0;)b++,y++;for(var m=(A-b)*f+1>>>0,v=new Uint8Array(m);b!==A;){for(var T=g[b],C=0,_=m-1;(T!==0||C<l)&&_!==-1;_--,C++)T+=256*v[_]>>>0,v[_]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");l=C,b++}for(var L=m-l;L!==m&&v[L]===0;)L++;for(var K=c.repeat(y);L<m;++L)K+=e.charAt(v[L]);return K}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var l=0,b=0;g[y]===c;)l++,y++;for(var A=(g.length-y)*u+1>>>0,m=new Uint8Array(A);g[y];){var v=r[g.charCodeAt(y)];if(v===255)return;for(var T=0,C=A-1;(v!==0||T<b)&&C!==-1;C--,T++)v+=a*m[C]>>>0,m[C]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");b=T,y++}if(g[y]!==" "){for(var _=A-b;_!==A&&m[_]===0;)_++;for(var L=new Uint8Array(l+(A-_)),K=l;_!==A;)L[K++]=m[_++];return L}}}function E(g){var y=d(g);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:d,decode:E}}var na=ra,oa=na,No=oa;var Qr=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")}},tn=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 ko(this,t)}},en=class{decoders;constructor(t){this.decoders=t}or(t){return ko(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 ko(e,t){return new en({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var rn=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 Qr(t,r,n),this.decoder=new tn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:e,prefix:t,encode:r,decode:n}){return new rn(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=No(r,e);return we({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function sa(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 h=o[e[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,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 ia(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 Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return we({prefix:t,name:e,encode(o){return ia(o,n,r)},decode(o){return sa(o,n,r,e)}})}var et=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),aa=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var on={};at(on,{base32:()=>Ee,base32hex:()=>ha,base32hexpad:()=>da,base32hexpadupper:()=>pa,base32hexupper:()=>la,base32pad:()=>fa,base32padupper:()=>ua,base32upper:()=>ca,base32z:()=>ma});var Ee=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ca=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fa=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ua=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ha=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),la=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),da=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pa=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ma=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var sn={};at(sn,{base36:()=>Fe,base36upper:()=>ya});var Fe=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ya=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ba=Mo,Ho=128,xa=127,ga=~xa,wa=Math.pow(2,31);function Mo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=wa;)t[r++]=e&255|Ho,e/=128;for(;e&ga;)t[r++]=e&255|Ho,e>>>=7;return t[r]=e|0,Mo.bytes=r-n+1,t}var Ea=an,Aa=128,Oo=127;function an(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw an.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Oo)<<o:(i&Oo)*Math.pow(2,o),o+=7}while(i>=Aa);return an.bytes=s-n,r}var Sa=Math.pow(2,7),Ba=Math.pow(2,14),va=Math.pow(2,21),Ia=Math.pow(2,28),_a=Math.pow(2,35),La=Math.pow(2,42),Ka=Math.pow(2,49),Ua=Math.pow(2,56),Ca=Math.pow(2,63),Ta=function(e){return e<Sa?1:e<Ba?2:e<va?3:e<Ia?4:e<_a?5:e<La?6:e<Ka?7:e<Ua?8:e<Ca?9:10},Da={encode:ba,decode:Ea,encodingLength:Ta},Ra=Da,je=Ra;function Ze(e,t=0){return[je.decode(e,t),je.decode.bytes]}function Ae(e,t,r=0){return je.encode(e,t,r),t}function Se(e){return je.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 Be(e,r,t,s)}function qo(e){let t=Pt(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 Be(r,o,i,t)}function Vo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&To(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function zo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Na(r,cn(e),t??et.encoder);default:return ka(r,cn(e),t??Ee.encoder)}}var Fo=new WeakMap;function cn(e){let t=Fo.get(e);if(t==null){let r=new Map;return Fo.set(e,r),r}return t}var At=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!==Ha)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&&Vo(t.multihash,n.multihash)}toString(t){return zo(this,t)}toJSON(){return{"/":zo(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??jo(n,o,s.bytes))}else if(r[Oa]===!0){let{version:n,multihash:o,code:s}=r,i=qo(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=jo(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=Pt(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 Be(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[h,d]=Ze(t.subarray(r));return r+=d,h},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,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]=Pa(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 cn(s).set(n,t),s}};function Pa(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 Fe.prefix:{let r=t??Fe;return[Fe.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 Na(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 ka(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,Ha=18;function jo(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 Oa=Symbol.for("@ipld/js-cid/CID");var fn={};at(fn,{identity:()=>oe});var Zo=0,Ma="identity",Go=Pt;function qa(e){return It(Zo,Go(e))}var oe={code:Zo,name:Ma,encode:Go,digest:qa};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 Nt(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Ut(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Yo=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 gr(e){return!!e?.[Yo]}var ut=class e{bufs;length;[Yo]=!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=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(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 Ut(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ut(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 h=t-a;n.push(i.subarray(h,h+(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(!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 h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let d=u;d>=0;d--){let E=this.get(h+d);if(n[d]!==E){f=Math.max(1,d-a[E]);break}}if(f===0)return h}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=xt(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=Nt(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=Nt(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=Nt(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=xt(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=Nt(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=Nt(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=Nt(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=Nt(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=Nt(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 un={};at(un,{base10:()=>Va});var Va=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var hn={};at(hn,{base16:()=>za,base16upper:()=>Fa});var za=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fa=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ln={};at(ln,{base2:()=>ja});var ja=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dn={};at(dn,{base256emoji:()=>Xa});var Xo=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}"),Za=Xo.reduce((e,t,r)=>(e[r]=t,e),[]),Ga=Xo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Wa(e){return e.reduce((t,r)=>(t+=Za[r],t),"")}function Ya(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ga[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Xa=we({prefix:"\u{1F680}",name:"base256emoji",encode:Wa,decode:Ya});var mn={};at(mn,{base64:()=>pn,base64pad:()=>$a,base64url:()=>Ja,base64urlpad:()=>Qa});var pn=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$a=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ja=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qa=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};at(yn,{base8:()=>tc});var tc=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};at(bn,{identity:()=>ec});var ec=we({prefix:"\0",name:"identity",encode:e=>Ro(e),decode:e=>Do(e)});var Ku=new TextEncoder,Uu=new TextDecoder;var wn={};at(wn,{sha256:()=>wr,sha512:()=>oc});function gn({name:e,code:t,encode:r}){return new xn(e,t,r)}var xn=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 Jo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var wr=gn({name:"sha2-256",code:18,encode:Jo("SHA-256")}),oc=gn({name:"sha2-512",code:19,encode:Jo("SHA-512")});var En={...bn,...ln,...yn,...un,...hn,...on,...sn,...nn,...mn,...dn},Vu={...wn,...fn};function ts(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Qo=ts("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),An=ts("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=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),sc={utf8:Qo,"utf-8":Qo,hex:En.base16,latin1:An,ascii:An,binary:An,...En},Er=sc;function Z(e,t="utf8"){let r=Er[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=Er[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ic=parseInt("11111",2),Sn=parseInt("10000000",2),ac=parseInt("01111111",2),es={0:Ye,1:Ye,2:cc,3:hc,4:lc,5:uc,6:fc,16:Ye,22:Ye,48:Ye};function gt(e,t={offset:0}){let r=e[t.offset]&ic;if(t.offset++,es[r]!=null)return es[r](e,t);throw new Error("No decoder for tag "+r)}function Xe(e,t){let r=0;if((e[t.offset]&Sn)===Sn){let n=e[t.offset]&ac,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){Xe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=gt(e,t);if(n===null)break;r.push(n)}return r}function cc(e,t){let r=Xe(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 fc(e,t){let r=Xe(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 h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function uc(e,t){return t.offset++,null}function hc(e,t){let r=Xe(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 lc(e,t){let r=Xe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function dc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Ar(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=dc(e.byteLength);return new ut(Uint8Array.from([t.byteLength|Sn]),t)}function ht(e){let t=new ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ut(Uint8Array.from([2]),Ar(t),t)}function $e(e){let t=Uint8Array.from([0]),r=new ut(t,e);return new ut(Uint8Array.from([3]),Ar(r),r)}function rs(e){return new ut(Uint8Array.from([4]),Ar(e),e)}function _t(e,t=48){let r=new ut;for(let n of e)r.append(n);return new ut(Uint8Array.from([t]),Ar(r),r)}var Bn="1.2.840.10045.3.1.7",vn="1.3.132.0.34",In="1.3.132.0.35";async function ns(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 os(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 ss(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 pc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),mc=Uint8Array.from([6,5,43,129,4,0,34]),yc=Uint8Array.from([6,5,43,129,4,0,35]),is={ext:!0,kty:"EC",crv:"P-256"},as={ext:!0,kty:"EC",crv:"P-384"},cs={ext:!0,kty:"EC",crv:"P-521"},ve=32,Ie=48,_e=66;function fs(e){let t=gt(e);return _n(t)}function _n(e){let t=e[1],r=V(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===ve)return s=V(n.subarray(o,o+ve),"base64url"),i=V(n.subarray(o+ve),"base64url"),new kt({...is,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 kt({...as,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===_e)return s=V(n.subarray(o,o+_e),"base64url"),i=V(n.subarray(o+_e),"base64url"),new kt({...cs,key_ops:["sign"],d:r,x:s,y:i});throw new P(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Ln(e){let t=gt(e);return Kn(t)}function Kn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ve*2+1)return n=V(t.subarray(r,r+ve),"base64url"),o=V(t.subarray(r+ve),"base64url"),new se({...is,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 se({...as,key_ops:["verify"],x:n,y:o});if(t.byteLength===_e*2+1)return n=V(t.subarray(r,r+_e),"base64url"),o=V(t.subarray(r+_e),"base64url"),new se({...cs,key_ops:["verify"],x:n,y:o});throw new P(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function us(e){return _t([ht(Uint8Array.from([1])),rs(Z(e.d??"","base64url")),_t([ls(e.crv)],160),_t([$e(new ut(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function hs(e){return _t([ht(Uint8Array.from([1])),_t([ls(e.crv)],160),_t([$e(new ut(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function ls(e){if(e==="P-256")return pc;if(e==="P-384")return mc;if(e==="P-521")return yc;throw new P(`Invalid curve ${e}`)}async function ds(e="P-256"){let t=await ns(e);return new kt(t.privateKey)}var se=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 oe.digest(ie(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return et.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 ss(this.jwk,r,t)}},kt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new se({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=us(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async sign(t){return os(this.jwk,t)}};var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Gt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Wt(e,...t){if(!bc(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 Sr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Gt(e.outputLen),Gt(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 ps(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 yt(...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 Un(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Je(e){return typeof e=="string"&&(e=Un(e)),Wt(e),e}function Cn(e){return typeof e=="string"&&(e=Un(e)),Wt(e),e}function Tn(...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 ms(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 Qe(e){let t=n=>e().update(Je(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ce(e=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(e));if(ae&&typeof ae.randomBytes=="function")return Uint8Array.from(ae.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function xc(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 vr(e,t,r){return e&t^~e&r}function Ir(e,t,r){return e&t^e&r^t&r}var ce=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=Je(t),Wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ue(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){Ke(this),ps(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,yt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)r[h]=0;xc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ue(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 h=0;h<u;h++)a.setUint32(4*h,f[h],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.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var _r=BigInt(4294967295),ys=BigInt(32);function gc(e,t=!1){return t?{h:Number(e&_r),l:Number(e>>ys&_r)}:{h:Number(e>>ys&_r)|0,l:Number(e&_r)|0}}function bs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=gc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Dn=(e,t,r)=>e>>>r,Rn=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,ue=(e,t,r)=>e<<32-r|t>>>r,tr=(e,t,r)=>e<<64-r|t>>>r-32,er=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var xs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),gs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ws=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Es=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,As=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ss=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Ec=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]),Yt=new Uint32Array(64),Lr=class extends ce{constructor(t=32){super(64,t,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[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 h=0;h<16;h++,r+=4)Yt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let d=Yt[h-15],E=Yt[h-2],g=Lt(d,7)^Lt(d,18)^d>>>3,y=Lt(E,17)^Lt(E,19)^E>>>10;Yt[h]=y+Yt[h-7]+g+Yt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let d=Lt(a,6)^Lt(a,11)^Lt(a,25),E=f+d+vr(a,c,u)+Ec[h]+Yt[h]|0,y=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Ir(n,o,s)|0;f=u,u=c,c=a,a=i+E|0,i=s,s=o,o=n,n=E+y|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(){yt(Yt)}destroy(){this.set(0,0,0,0,0,0,0,0),yt(this.buffer)}};var Bs=bs(["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))),Ac=Bs[0],Sc=Bs[1],Xt=new Uint32Array(80),$t=new Uint32Array(80),Kr=class extends ce{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:d,Gh:E,Gl:g,Hh:y,Hl:l}=this;return[t,r,n,o,s,i,a,c,u,f,h,d,E,g,y,l]}set(t,r,n,o,s,i,a,c,u,f,h,d,E,g,y,l){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=h|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=y|0,this.Hl=l|0}process(t,r){for(let m=0;m<16;m++,r+=4)Xt[m]=t.getUint32(r),$t[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let v=Xt[m-15]|0,T=$t[m-15]|0,C=fe(v,T,1)^fe(v,T,8)^Dn(v,T,7),_=ue(v,T,1)^ue(v,T,8)^Rn(v,T,7),L=Xt[m-2]|0,K=$t[m-2]|0,F=fe(L,K,19)^tr(L,K,61)^Dn(L,K,6),M=ue(L,K,19)^er(L,K,61)^Rn(L,K,6),N=ws(_,M,$t[m-7],$t[m-16]),J=Es(N,C,F,Xt[m-7],Xt[m-16]);Xt[m]=J|0,$t[m]=N|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:d,Fh:E,Fl:g,Gh:y,Gl:l,Hh:b,Hl:A}=this;for(let m=0;m<80;m++){let v=fe(h,d,14)^fe(h,d,18)^tr(h,d,41),T=ue(h,d,14)^ue(h,d,18)^er(h,d,41),C=h&E^~h&y,_=d&g^~d&l,L=As(A,T,_,Sc[m],$t[m]),K=Ss(L,b,v,C,Ac[m],Xt[m]),F=L|0,M=fe(n,o,28)^tr(n,o,34)^tr(n,o,39),N=ue(n,o,28)^er(n,o,34)^er(n,o,39),J=n&s^n&a^s&a,S=o&i^o&c^i&c;b=y|0,A=l|0,y=E|0,l=g|0,E=h|0,g=d|0,{h,l:d}=Ct(u|0,f|0,K|0,F|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=xs(F,N,S);n=gs(I,K,M,J),o=I|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ct(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ct(this.Dh|0,this.Dl|0,u|0,f|0),{h,l:d}=Ct(this.Eh|0,this.El|0,h|0,d|0),{h:E,l:g}=Ct(this.Fh|0,this.Fl|0,E|0,g|0),{h:y,l}=Ct(this.Gh|0,this.Gl|0,y|0,l|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,f,h,d,E,g,y,l,b,A)}roundClean(){yt(Xt,$t)}destroy(){yt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ur=Qe(()=>new Lr);var Cr=Qe(()=>new Kr);var Hn=BigInt(0),kn=BigInt(1);function he(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function On(e){if(!he(e))throw new Error("Uint8Array expected")}function Tt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function rr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function _s(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Hn:BigInt("0x"+e)}var Ls=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Bc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jt(e){if(On(e),Ls)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Bc[e[r]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function vs(e){if(e>=Ot._0&&e<=Ot._9)return e-Ot._0;if(e>=Ot.A&&e<=Ot.F)return e-(Ot.A-10);if(e>=Ot.a&&e<=Ot.f)return e-(Ot.a-10)}function nr(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ls)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=vs(e.charCodeAt(s)),a=vs(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 Mt(e){return _s(Jt(e))}function le(e){return On(e),_s(Jt(Uint8Array.from(e).reverse()))}function de(e,t){return nr(e.toString(16).padStart(t*2,"0"))}function Te(e,t){return de(e,t).reverse()}function W(e,t,r){let n;if(typeof t=="string")try{n=nr(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(he(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 Qt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];On(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 Pn=e=>typeof e=="bigint"&&Hn<=e;function Tr(e,t,r){return Pn(e)&&Pn(t)&&Pn(r)&&t<=e&&e<r}function wt(e,t,r,n){if(!Tr(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ks(e){let t;for(t=0;e>Hn;e>>=kn,t+=1);return t}var pe=e=>(kn<<BigInt(e))-kn,Nn=e=>new Uint8Array(e),Is=e=>Uint8Array.from(e);function Us(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=Nn(e),o=Nn(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...h)=>r(o,n,...h),c=(h=Nn(0))=>{o=a(Is([0]),h),n=a(),h.length!==0&&(o=a(Is([1]),h),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){n=a();let E=n.slice();d.push(E),h+=n.length}return Qt(...d)};return(h,d)=>{i(),c(h);let E;for(;!(E=d(u()));)c();return i(),E}}var vc={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"||he(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 qt(e,t,r={}){let n=(o,s,i)=>{let a=vc[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}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 lt=BigInt(0),Q=BigInt(1),me=BigInt(2),Ic=BigInt(3),Mn=BigInt(4),Cs=BigInt(5),Ts=BigInt(8),_c=BigInt(9),Lc=BigInt(16);function z(e,t){let r=e%t;return r>=lt?r:t+r}function G(e,t,r){let n=e;for(;t-- >lt;)n*=n,n%=r;return n}function Dr(e,t){if(e===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=lt,s=Q,i=Q,a=lt;for(;r!==lt;){let u=n/r,f=n%r,h=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=h,a=d}if(n!==Q)throw new Error("invert: does not exist");return z(o,t)}function Kc(e){let t=e-Q,r=0;for(;t%me===lt;)t/=me,r++;let n=me,o=Vt(e);for(;n<e&&Ds(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1){let i=(e+Q)/Mn;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=(t+Q)/me;return function(a,c){if(!Ds(a,c))throw new Error("Cannot find square root");let u=r,f=a.pow(a.mul(a.ONE,n),t),h=a.pow(c,s),d=a.pow(c,t);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let y=a.sqr(d);E<u&&!a.eql(y,a.ONE);E++)y=a.sqr(y);let g=a.pow(f,Q<<BigInt(u-E-1));f=a.sqr(g),h=a.mul(h,g),d=a.mul(d,f),u=E}return h}}function Uc(e){return e%Mn===Ic?function(r,n){let o=(e+Q)/Mn,s=r.pow(n,o);if(!r.eql(r.sqr(s),n))throw new Error("Cannot find square root");return s}:e%Ts===Cs?function(r,n){let o=r.mul(n,me),s=(e-Cs)/Ts,i=r.pow(o,s),a=r.mul(n,i),c=r.mul(r.mul(a,me),i),u=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(u),n))throw new Error("Cannot find square root");return u}:(e%Lc,Kc(e))}var Rs=(e,t)=>(z(e,t)&Q)===Q,Cc=["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=Cc.reduce((n,o)=>(n[o]="function",n),t);return qt(e,r)}function Tc(e,t,r){if(r<lt)throw new Error("invalid exponent, negatives unsupported");if(r===lt)return e.ONE;if(r===Q)return t;let n=e.ONE,o=t;for(;r>lt;)r&Q&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Q;return n}function Re(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Dc(e,t){let r=(e.ORDER-Q)/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("Cannot find square root: probably non-prime P");return o?1:s?0:-1}function Ds(e,t){let r=Dc(e,t);return r===0||r===1}function Vn(e,t){t!==void 0&&Gt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Vt(e,t,r=!1,n={}){if(e<=lt)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,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:s,MASK:pe(o),ZERO:lt,ONE:Q,create:c=>z(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return lt<=c&&c<e},is0:c=>c===lt,isOdd:c=>(c&Q)===Q,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)=>Tc(a,c,u),div:(c,u)=>z(c*Dr(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Dr(c,e),sqrt:n.sqrt||(c=>(i||(i=Uc(e)),i(a,c))),toBytes:c=>r?Te(c,s):de(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?le(c):Mt(c)},invertBatch:c=>Re(a,c),cmov:(c,u,f)=>f?u:c});return Object.freeze(a)}function Ps(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=Ps(e);return t+Math.ceil(t/2)}function Ns(e,t,r=!1){let n=e.length,o=Ps(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):Mt(e),a=z(i,t-Q)+Q;return r?Te(a,o):de(a,o)}var ks=BigInt(0),Wn=BigInt(1);function Fn(e,t){let r=t.negate();return e?r:t}function Os(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){Os(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 Hs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Wn);let u=t*n,f=u+Math.abs(a)-1,h=a===0,d=a<0,E=t%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:d,isNegF:E,offsetF:u}}function Rc(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 Pc(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 Zn=new WeakMap,Ms=new WeakMap;function Gn(e){return Ms.get(e)||1}function Rr(e,t){return{constTimeNegate:Fn,hasPrecomputes(r){return Gn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>ks;)n&Wn&&(o=o.add(s)),s=s.double(),n>>=Wn;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=jn(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 s=e.ZERO,i=e.BASE,a=jn(r,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:h,isNeg:d,isNegF:E,offsetF:g}=Hs(o,c,a);o=u,h?i=i.add(Fn(E,n[g])):s=s.add(Fn(d,n[f]))}return{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=jn(r,t);for(let a=0;a<i.windows&&o!==ks;a++){let{nextN:c,offset:u,isZero:f,isNeg:h}=Hs(o,a,i);if(o=c,!f){let d=n[u];s=s.add(h?d.negate():d)}}return s},getPrecomputes(r,n,o){let s=Zn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Zn.set(n,o(s))),s},wNAFCached(r,n,o){let s=Gn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Gn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Os(n,t),Ms.set(r,n),Zn.delete(r)}}}function Pr(e,t,r,n){if(Rc(r,e),Pc(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,s=Ks(BigInt(r.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=pe(i),c=new Array(Number(a)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let h=u;h>=0;h-=i){c.fill(o);for(let E=0;E<n.length;E++){let g=n[E],y=Number(g>>BigInt(h)&a);c[y]=c[y].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),h!==0)for(let E=0;E<i;E++)f=f.double()}return f}function or(e){return qn(e.Fp),qt(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 Dt=BigInt(0),dt=BigInt(1),qs=BigInt(2),Nc=BigInt(8),kc={zip215:!0};function Hc(e){let t=or(e);return qt(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Vs(e){let t=Hc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=qs<<BigInt(a*8)-dt,f=r.create,h=Vt(t.n,t.nBitLength),d=t.uvRatio||((x,p)=>{try{return{isValid:!0,value:r.sqrt(x*r.inv(p))}}catch{return{isValid:!1,value:Dt}}}),E=t.adjustScalarBytes||(x=>x),g=t.domain||((x,p,w)=>{if(Tt("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return x});function y(x,p,w=!1){let B=w?dt:Dt;wt("coordinate "+x,p,B,u)}function l(x){if(!(x instanceof m))throw new Error("ExtendedPoint expected")}let b=De((x,p)=>{let{ex:w,ey:B,ez:D}=x,R=x.is0();p==null&&(p=R?Nc:r.inv(D));let k=f(w*p),H=f(B*p),O=f(D*p);if(R)return{x:Dt,y:dt};if(O!==dt)throw new Error("invZ was invalid");return{x:k,y:H}}),A=De(x=>{let{a:p,d:w}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:B,ey:D,ez:R,et:k}=x,H=f(B*B),O=f(D*D),q=f(R*R),$=f(q*q),X=f(H*p),nt=f(q*f(X+O)),mt=f($+f(w*f(H*O)));if(nt!==mt)throw new Error("bad point: equation left != right (1)");let tt=f(B*D),it=f(R*k);if(tt!==it)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,B,D){y("x",p),y("y",w),y("z",B,!0),y("t",D),this.ex=p,this.ey=w,this.ez=B,this.et=D,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 y("x",w),y("y",B),new m(w,B,dt,f(w*B))}static normalizeZ(p){let w=Re(r,p.map(B=>B.ez));return p.map((B,D)=>B.toAffine(w[D])).map(m.fromAffine)}static msm(p,w){return Pr(m,h,p,w)}_setWindowSize(p){C.setWindowSize(this,p)}assertValidity(){A(this)}equals(p){l(p);let{ex:w,ey:B,ez:D}=this,{ex:R,ey:k,ez:H}=p,O=f(w*H),q=f(R*D),$=f(B*H),X=f(k*D);return O===q&&$===X}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:D}=this,R=f(w*w),k=f(B*B),H=f(qs*f(D*D)),O=f(p*R),q=w+B,$=f(f(q*q)-R-k),X=O+k,nt=X-H,mt=O-k,tt=f($*nt),it=f(X*mt),bt=f($*mt),vt=f(nt*X);return new m(tt,it,vt,bt)}add(p){l(p);let{a:w,d:B}=t,{ex:D,ey:R,ez:k,et:H}=this,{ex:O,ey:q,ez:$,et:X}=p,nt=f(D*O),mt=f(R*q),tt=f(H*B*X),it=f(k*$),bt=f((D+R)*(O+q)-nt-mt),vt=it-tt,Me=it+tt,Ko=f(mt-w*nt),ji=f(bt*vt),Zi=f(Me*Ko),Gi=f(bt*Ko),Wi=f(vt*Me);return new m(ji,Zi,Wi,Gi)}subtract(p){return this.add(p.negate())}wNAF(p){return C.wNAFCached(this,p,m.normalizeZ)}multiply(p){let w=p;wt("scalar",w,dt,n);let{p:B,f:D}=this.wNAF(w);return m.normalizeZ([B,D])[0]}multiplyUnsafe(p,w=m.ZERO){let B=p;return wt("scalar",B,Dt,n),B===Dt?T:this.is0()||B===dt?this:C.wNAFCachedUnsafe(this,B,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(p){return b(this,p)}clearCofactor(){let{h:p}=t;return p===dt?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:B,a:D}=t,R=r.BYTES;p=W("pointHex",p,R),Tt("zip215",w);let k=p.slice(),H=p[R-1];k[R-1]=H&-129;let O=le(k),q=w?u:r.ORDER;wt("pointHex.y",O,Dt,q);let $=f(O*O),X=f($-dt),nt=f(B*$-D),{isValid:mt,value:tt}=d(X,nt);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let it=(tt&dt)===dt,bt=(H&128)!==0;if(!w&&tt===Dt&&bt)throw new Error("Point.fromHex: x=0 and x_0=1");return bt!==it&&(tt=f(-tt)),m.fromAffine({x:tt,y:O})}static fromPrivateKey(p){let{scalar:w}=K(p);return v.multiply(w)}toRawBytes(){let{x:p,y:w}=this.toAffine(),B=Te(w,r.BYTES);return B[B.length-1]|=p&dt?128:0,B}toHex(){return Jt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,dt,f(t.Gx*t.Gy)),m.ZERO=new m(Dt,dt,dt,Dt);let{BASE:v,ZERO:T}=m,C=Rr(m,a*8);function _(x){return z(x,n)}function L(x){return _(le(x))}function K(x){let p=r.BYTES;x=W("private key",x,p);let w=W("hashed private key",s(x),2*p),B=E(w.slice(0,p)),D=w.slice(p,2*p),R=L(B);return{head:B,prefix:D,scalar:R}}function F(x){let{head:p,prefix:w,scalar:B}=K(x),D=v.multiply(B),R=D.toRawBytes();return{head:p,prefix:w,scalar:B,point:D,pointBytes:R}}function M(x){return F(x).pointBytes}function N(x=Uint8Array.of(),...p){let w=Qt(...p);return L(s(g(w,W("context",x),!!o)))}function J(x,p,w={}){x=W("message",x),o&&(x=o(x));let{prefix:B,scalar:D,pointBytes:R}=F(p),k=N(w.context,B,x),H=v.multiply(k).toRawBytes(),O=N(w.context,H,R,x),q=_(k+O*D);wt("signature.s",q,Dt,n);let $=Qt(H,Te(q,r.BYTES));return W("result",$,r.BYTES*2)}let S=kc;function I(x,p,w,B=S){let{context:D,zip215:R}=B,k=r.BYTES;x=W("signature",x,2*k),p=W("message",p),w=W("publicKey",w,k),R!==void 0&&Tt("zip215",R),o&&(p=o(p));let H=le(x.slice(k,2*k)),O,q,$;try{O=m.fromHex(w,R),q=m.fromHex(x.slice(0,k),R),$=v.multiplyUnsafe(H)}catch{return!1}if(!R&&O.isSmallOrder())return!1;let X=N(D,q.toRawBytes(),O.toRawBytes(),p);return q.add(O.multiplyUnsafe(X)).subtract($).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:M,sign:J,verify:I,ExtendedPoint:m,utils:{getExtendedPublicKey:F,randomPrivateKey:()=>i(r.BYTES),precompute(x=8,p=m.BASE){return p._setWindowSize(x),p.multiply(BigInt(3)),p}}}}var Yn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vh=BigInt(0),Oc=BigInt(1),Fs=BigInt(2),zh=BigInt(3),Mc=BigInt(5),qc=BigInt(8);function Vc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Yn,a=e*e%s*e%s,c=G(a,Fs,s)*a%s,u=G(c,Oc,s)*e%s,f=G(u,Mc,s)*u%s,h=G(f,t,s)*f%s,d=G(h,r,s)*h%s,E=G(d,n,s)*d%s,g=G(E,o,s)*E%s,y=G(g,o,s)*E%s,l=G(y,t,s)*f%s;return{pow_p_5_8:G(l,Fs,s)*e%s,b2:a}}function zc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Fc(e,t){let r=Yn,n=z(t*t*t,r),o=z(n*n*t,r),s=Vc(e*o).pow_p_5_8,i=z(e*n*s,r),a=z(t*i*i,r),c=i,u=z(i*zs,r),f=a===e,h=a===z(-e,r),d=a===z(-e*zs,r);return f&&(i=c),(h||d)&&(i=u),Rs(i,r)&&(i=z(-i,r)),{isValid:f||h,value:i}}var js=Vt(Yn,void 0,!0),jc={a:js.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:js,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:qc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Cr,randomBytes:Ce,adjustScalarBytes:zc,uvRatio:Fc},Pe=Vs(jc);var te=32,St=64,Nr=32;function Zs(){let e=Pe.utils.randomPrivateKey(),t=Pe.getPublicKey(e);return{privateKey:Xs(e,t),publicKey:t}}function Gs(e){if(e.length!==Nr)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:Xs(t,r),publicKey:r}}function Ws(e,t){let r=e.subarray(0,Nr);return Pe.sign(t instanceof Uint8Array?t:t.subarray(),r)}function Ys(e,t,r){return Pe.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}function Xs(e,t){let r=new Uint8Array(St);for(let n=0;n<Nr;n++)r[n]=e[n],r[Nr+n]=t[n];return r}var sr=class{type="Ed25519";raw;constructor(t){this.raw=Ne(t,te)}toMultihash(){return oe.digest(ie(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return et.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 Ys(this.raw,r,t)}},ye=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ne(t,St),this.publicKey=new sr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return Ws(this.raw,t)}};function Xn(e){if(e.length>St){e=Ne(e,St+te);let n=e.subarray(0,St),o=e.subarray(St,e.length);return new ye(n,o)}e=Ne(e,St);let t=e.subarray(0,St),r=e.subarray(te);return new ye(t,r)}function kr(e){return e=Ne(e,te),new sr(e)}async function Js(){let{privateKey:e,publicKey:t}=Zs();return new ye(e,t)}async function Qs(e){let{privateKey:t,publicKey:r}=Gs(e);return new ye(t,r)}function Ne(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new P(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Zc=Math.pow(2,7),Gc=Math.pow(2,14),Wc=Math.pow(2,21),ti=Math.pow(2,28),ei=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),pt=128,ee=127;function ir(e){if(e<Zc)return 1;if(e<Gc)return 2;if(e<Wc)return 3;if(e<ti)return 4;if(e<ei)return 5;if(e<ri)return 6;if(e<ni)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oi(e,t,r=0){switch(ir(e)){case 8:t[r++]=e&255|pt,e/=128;case 7:t[r++]=e&255|pt,e/=128;case 6:t[r++]=e&255|pt,e/=128;case 5:t[r++]=e&255|pt,e/=128;case 4:t[r++]=e&255|pt,e>>>=7;case 3:t[r++]=e&255|pt,e>>>=7;case 2:t[r++]=e&255|pt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function si(e,t){let r=e[t],n=0;if(n+=r&ee,r<pt||(r=e[t+1],n+=(r&ee)<<7,r<pt)||(r=e[t+2],n+=(r&ee)<<14,r<pt)||(r=e[t+3],n+=(r&ee)<<21,r<pt)||(r=e[t+4],n+=(r&ee)*ti,r<pt)||(r=e[t+5],n+=(r&ee)*ei,r<pt)||(r=e[t+6],n+=(r&ee)*ri,r<pt)||(r=e[t+7],n+=(r&ee)*ni,r<pt))return n;throw new RangeError("Could not decode varint")}var $n=new Float32Array([-0]),re=new Uint8Array($n.buffer);function ii(e,t,r){$n[0]=e,t[r]=re[0],t[r+1]=re[1],t[r+2]=re[2],t[r+3]=re[3]}function ai(e,t){return re[0]=e[t],re[1]=e[t+1],re[2]=e[t+2],re[3]=e[t+3],$n[0]}var Jn=new Float64Array([-0]),ft=new Uint8Array(Jn.buffer);function ci(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 fi(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 Yc=BigInt(Number.MAX_SAFE_INTEGER),Xc=BigInt(Number.MIN_SAFE_INTEGER),Et=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<Yc&&t>Xc)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>ui&&(o=0n,++n>ui&&(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 Et(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var ui=4294967296n;function hi(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 li(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 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 Hr(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 Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=ai(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=fi(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 li(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 Et(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=Hr(this.buf,this.pos+=4),r=Hr(this.buf,this.pos+=4);return new Et(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=si(this.buf,this.pos);return this.pos+=ir(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 Or(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 xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}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}},$c=ro();function Jc(e){return globalThis.Buffer!=null?xt(e):$c(e)}var cr=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(Mr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(Mr,r.length(),r)}uint64Number(t){return this._push(oi,ir(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=Et.fromBigInt(t).zzEncode();return this._push(Mr,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(Mr,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(ar,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(ar,4,r.lo)._push(ar,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(ar,4,r.lo)._push(ar,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(ii,4,t)}double(t){return this._push(ci,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(oo,1,0):this.uint32(r)._push(tf,r,t)}string(t){let r=hi(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=Jc(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 Qc(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(Qc,t,r),this.next=void 0}};function Mr(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 ar(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 tf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(cr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ef,t,e),this},cr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(rf,t,e),this});function ef(e,t,r){t.set(e,r)}function rf(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 cr}function qr(e,t){let r=ao();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 Vr(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 a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Vr("enum",ke.VARINT,r,n)}function zr(e,t){return Vr("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 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)})(j||(j={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=zr((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=>qr(r,e.codec()),e.decode=(r,n)=>Or(r,e.codec(),n)})(Rt||(Rt={}));var fr;(function(e){let t;e.codec=()=>(t==null&&(t=zr((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=>qr(r,e.codec()),e.decode=(r,n)=>Or(r,e.codec(),n)})(fr||(fr={}));function uo(e){if(isNaN(e)||e<=0)throw new P("random bytes length must be a Number bigger than 0");return Ce(e)}var hr={};at(hr,{MAX_RSA_KEY_SIZE:()=>ho,generateRSAKeyPair:()=>go,jwkToJWKKeyPair:()=>bi,jwkToPkcs1:()=>af,jwkToPkix:()=>yo,jwkToRSAPrivateKey:()=>Zr,pkcs1MessageToJwk:()=>po,pkcs1MessageToRSAPrivateKey:()=>Fr,pkcs1ToJwk:()=>sf,pkcs1ToRSAPrivateKey:()=>bo,pkixMessageToJwk:()=>mo,pkixMessageToRSAPublicKey:()=>jr,pkixToJwk:()=>cf,pkixToRSAPublicKey:()=>xo});var He=Ur;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=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return At.createV1(114,this._multihash)}toString(){return et.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 yi(this.jwk,r,t)}},ur=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return mi(this.jwk,t)}};var ho=8192,lo=18,nf=1062,of=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function sf(e){let t=gt(e);return po(t)}function po(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 af(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 P("JWK was missing components");return _t([ht(Uint8Array.from([0])),ht(Z(e.n,"base64url")),ht(Z(e.e,"base64url")),ht(Z(e.d,"base64url")),ht(Z(e.p,"base64url")),ht(Z(e.q,"base64url")),ht(Z(e.dp,"base64url")),ht(Z(e.dq,"base64url")),ht(Z(e.qi,"base64url"))]).subarray()}function cf(e){let t=gt(e,{offset:0});return mo(t)}function mo(e){let t=gt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function yo(e){if(e.n==null||e.e==null)throw new P("JWK was missing components");return _t([of,$e(_t([ht(Z(e.n,"base64url")),ht(Z(e.e,"base64url"))]))]).subarray()}function bo(e){let t=gt(e);return Fr(t)}function Fr(e){let t=po(e);return Zr(t)}function xo(e,t){if(e.byteLength>=nf)throw new ge("Key size is too large");let r=gt(e,{offset:0});return jr(r,e,t)}function jr(e,t,r){let n=mo(e);if(r==null){let o=He(Rt.encode({Type:j.RSA,Data:t}));r=It(lo,o)}return new Oe(n,r)}function Zr(e){if(gi(e)>ho)throw new P("Key size is too large");let t=bi(e),r=He(Rt.encode({Type:j.RSA,Data:yo(t.publicKey)})),n=It(lo,r);return new ur(t.privateKey,new Oe(t.publicKey,n))}async function go(e){if(e>ho)throw new P("Key size is too large");let t=await xi(e),r=He(Rt.encode({Type:j.RSA,Data:yo(t.publicKey)})),n=It(lo,r);return new ur(t.privateKey,new Oe(t.publicKey,n))}function bi(e){if(e==null)throw new P("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var wi="1.2.840.113549.1.1.1";async function xi(e){let t=await ot.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 ff(t);return{privateKey:r[0],publicKey:r[1]}}async function mi(e,t){let r=await ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ot.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function yi(e,t,r){let n=await ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ot.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function ff(e){if(e.privateKey==null||e.publicKey==null)throw new P("Private and public key are required");return Promise.all([ot.get().subtle.exportKey("jwk",e.privateKey),ot.get().subtle.exportKey("jwk",e.publicKey)])}function gi(e){if(e.kty!=="RSA")throw new P("invalid key type");if(e.n==null)throw new P("invalid key modulus");return Z(e.n,"base64url").length*8}var Gr=class extends Le{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Sr(t);let n=Je(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),yt(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: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}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},lr=(e,t,r)=>new Gr(e,t).update(r).digest();lr.create=(e,t)=>new Gr(e,t);function Ei(e){e.lowS!==void 0&&Tt("lowS",e.lowS),e.prehash!==void 0&&Tt("prehash",e.prehash)}function uf(e){let t=or(e);qt(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 wo=class extends Error{constructor(t=""){super(t)}},zt={Err:wo,_tlv:{encode:(e,t)=>{let{Err:r}=zt;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=rr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?rr(o.length/2|128):"";return rr(e)+s+o+t},decode(e,t){let{Err:r}=zt,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}=zt;if(e<Ft)throw new t("integer: negative integers are not allowed");let r=rr(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}=zt;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 Mt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=zt,o=W("signature",e),{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}=zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),rt=BigInt(1),d0=BigInt(2),Ai=BigInt(3),p0=BigInt(4);function hf(e){let t=uf(e),{Fp:r}=t,n=Vt(t.n,t.nBitLength),o=t.toBytes||((y,l,b)=>{let A=l.toAffine();return Qt(Uint8Array.from([4]),r.toBytes(A.x),r.toBytes(A.y))}),s=t.fromBytes||(y=>{let l=y.subarray(1),b=r.fromBytes(l.subarray(0,r.BYTES)),A=r.fromBytes(l.subarray(r.BYTES,2*r.BYTES));return{x:b,y:A}});function i(y){let{a:l,b}=t,A=r.sqr(y),m=r.mul(A,y);return r.add(r.add(m,r.mul(y,l)),b)}if(!r.eql(r.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Tr(y,rt,t.n)}function c(y){let{allowedPrivateKeyLengths:l,nByteLength:b,wrapPrivateKey:A,n:m}=t;if(l&&typeof y!="bigint"){if(he(y)&&(y=Jt(y)),typeof y!="string"||!l.includes(y.length))throw new Error("invalid private key");y=y.padStart(b*2,"0")}let v;try{v=typeof y=="bigint"?y:Mt(W("private key",y,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof y)}return A&&(v=z(v,m)),wt("private key",v,rt,m),v}function u(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let f=De((y,l)=>{let{px:b,py:A,pz:m}=y;if(r.eql(m,r.ONE))return{x:b,y:A};let v=y.is0();l==null&&(l=v?r.ONE:r.inv(m));let T=r.mul(b,l),C=r.mul(A,l),_=r.mul(m,l);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(_,r.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}),h=De(y=>{if(y.is0()){if(t.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:l,y:b}=y.toAffine();if(!r.isValid(l)||!r.isValid(b))throw new Error("bad point: x or y not FE");let A=r.sqr(b),m=i(l);if(!r.eql(A,m))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(l,b,A){if(l==null||!r.isValid(l))throw new Error("x required");if(b==null||!r.isValid(b)||r.is0(b))throw new Error("y required");if(A==null||!r.isValid(A))throw new Error("z required");this.px=l,this.py=b,this.pz=A,Object.freeze(this)}static fromAffine(l){let{x:b,y:A}=l||{};if(!l||!r.isValid(b)||!r.isValid(A))throw new Error("invalid affine point");if(l instanceof d)throw new Error("projective point not allowed");let m=v=>r.eql(v,r.ZERO);return m(b)&&m(A)?d.ZERO:new d(b,A,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(l){let b=Re(r,l.map(A=>A.pz));return l.map((A,m)=>A.toAffine(b[m])).map(d.fromAffine)}static fromHex(l){let b=d.fromAffine(s(W("pointHex",l)));return b.assertValidity(),b}static fromPrivateKey(l){return d.BASE.multiply(c(l))}static msm(l,b){return Pr(d,n,l,b)}_setWindowSize(l){g.setWindowSize(this,l)}assertValidity(){h(this)}hasEvenY(){let{y:l}=this.toAffine();if(r.isOdd)return!r.isOdd(l);throw new Error("Field doesn't support isOdd")}equals(l){u(l);let{px:b,py:A,pz:m}=this,{px:v,py:T,pz:C}=l,_=r.eql(r.mul(b,C),r.mul(v,m)),L=r.eql(r.mul(A,C),r.mul(T,m));return _&&L}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:l,b}=t,A=r.mul(b,Ai),{px:m,py:v,pz:T}=this,C=r.ZERO,_=r.ZERO,L=r.ZERO,K=r.mul(m,m),F=r.mul(v,v),M=r.mul(T,T),N=r.mul(m,v);return N=r.add(N,N),L=r.mul(m,T),L=r.add(L,L),C=r.mul(l,L),_=r.mul(A,M),_=r.add(C,_),C=r.sub(F,_),_=r.add(F,_),_=r.mul(C,_),C=r.mul(N,C),L=r.mul(A,L),M=r.mul(l,M),N=r.sub(K,M),N=r.mul(l,N),N=r.add(N,L),L=r.add(K,K),K=r.add(L,K),K=r.add(K,M),K=r.mul(K,N),_=r.add(_,K),M=r.mul(v,T),M=r.add(M,M),K=r.mul(M,N),C=r.sub(C,K),L=r.mul(M,F),L=r.add(L,L),L=r.add(L,L),new d(C,_,L)}add(l){u(l);let{px:b,py:A,pz:m}=this,{px:v,py:T,pz:C}=l,_=r.ZERO,L=r.ZERO,K=r.ZERO,F=t.a,M=r.mul(t.b,Ai),N=r.mul(b,v),J=r.mul(A,T),S=r.mul(m,C),I=r.add(b,A),U=r.add(v,T);I=r.mul(I,U),U=r.add(N,J),I=r.sub(I,U),U=r.add(b,m);let x=r.add(v,C);return U=r.mul(U,x),x=r.add(N,S),U=r.sub(U,x),x=r.add(A,m),_=r.add(T,C),x=r.mul(x,_),_=r.add(J,S),x=r.sub(x,_),K=r.mul(F,U),_=r.mul(M,S),K=r.add(_,K),_=r.sub(J,K),K=r.add(J,K),L=r.mul(_,K),J=r.add(N,N),J=r.add(J,N),S=r.mul(F,S),U=r.mul(M,U),J=r.add(J,S),S=r.sub(N,S),S=r.mul(F,S),U=r.add(U,S),N=r.mul(J,U),L=r.add(L,N),N=r.mul(x,U),_=r.mul(I,_),_=r.sub(_,N),N=r.mul(I,J),K=r.mul(x,K),K=r.add(K,N),new d(_,L,K)}subtract(l){return this.add(l.negate())}is0(){return this.equals(d.ZERO)}wNAF(l){return g.wNAFCached(this,l,d.normalizeZ)}multiplyUnsafe(l){let{endo:b,n:A}=t;wt("scalar",l,Ft,A);let m=d.ZERO;if(l===Ft)return m;if(this.is0()||l===rt)return this;if(!b||g.hasPrecomputes(this))return g.wNAFCachedUnsafe(this,l,d.normalizeZ);let{k1neg:v,k1:T,k2neg:C,k2:_}=b.splitScalar(l),L=m,K=m,F=this;for(;T>Ft||_>Ft;)T&rt&&(L=L.add(F)),_&rt&&(K=K.add(F)),F=F.double(),T>>=rt,_>>=rt;return v&&(L=L.negate()),C&&(K=K.negate()),K=new d(r.mul(K.px,b.beta),K.py,K.pz),L.add(K)}multiply(l){let{endo:b,n:A}=t;wt("scalar",l,rt,A);let m,v;if(b){let{k1neg:T,k1:C,k2neg:_,k2:L}=b.splitScalar(l),{p:K,f:F}=this.wNAF(C),{p:M,f:N}=this.wNAF(L);K=g.constTimeNegate(T,K),M=g.constTimeNegate(_,M),M=new d(r.mul(M.px,b.beta),M.py,M.pz),m=K.add(M),v=F.add(N)}else{let{p:T,f:C}=this.wNAF(l);m=T,v=C}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(l,b,A){let m=d.BASE,v=(C,_)=>_===Ft||_===rt||!C.equals(m)?C.multiplyUnsafe(_):C.multiply(_),T=v(this,b).add(v(l,A));return T.is0()?void 0:T}toAffine(l){return f(this,l)}isTorsionFree(){let{h:l,isTorsionFree:b}=t;if(l===rt)return!0;if(b)return b(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:l,clearCofactor:b}=t;return l===rt?this:b?b(d,this):this.multiplyUnsafe(t.h)}toRawBytes(l=!0){return Tt("isCompressed",l),this.assertValidity(),o(d,this,l)}toHex(l=!0){return Tt("isCompressed",l),Jt(this.toRawBytes(l))}}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=Rr(d,t.endo?Math.ceil(E/2):E);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function lf(e){let t=or(e);return qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Si(e){let t=lf(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 Dr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:h}=hf({...t,toBytes(S,I,U){let x=I.toAffine(),p=r.toBytes(x.x),w=Qt;return Tt("isCompressed",U),U?w(Uint8Array.from([I.hasEvenY()?2:3]),p):w(Uint8Array.from([4]),p,r.toBytes(x.y))},fromBytes(S){let I=S.length,U=S[0],x=S.subarray(1);if(I===o&&(U===2||U===3)){let p=Mt(x);if(!Tr(p,rt,r.ORDER))throw new Error("Point is not on curve");let w=f(p),B;try{B=r.sqrt(w)}catch(k){let H=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+H)}let D=(B&rt)===rt;return(U&1)===1!==D&&(B=r.neg(B)),{x:p,y:B}}else if(I===s&&U===4){let p=r.fromBytes(x.subarray(0,r.BYTES)),w=r.fromBytes(x.subarray(r.BYTES,2*r.BYTES));return{x:p,y:w}}else{let p=o,w=s;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+w+", got "+I)}}}),d=S=>Jt(de(S,t.nByteLength));function E(S){let I=n>>rt;return S>I}function g(S){return E(S)?i(-S):S}let y=(S,I,U)=>Mt(S.slice(I,U));class l{constructor(I,U,x){wt("r",I,rt,n),wt("s",U,rt,n),this.r=I,this.s=U,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(I){let U=t.nByteLength;return I=W("compactSignature",I,U*2),new l(y(I,0,U),y(I,U,2*U))}static fromDER(I){let{r:U,s:x}=zt.toSig(W("DER",I));return new l(U,x)}assertValidity(){}addRecoveryBit(I){return new l(this.r,this.s,I)}recoverPublicKey(I){let{r:U,s:x,recovery:p}=this,w=C(W("msgHash",I));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let B=p===2||p===3?U+t.n:U;if(B>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(p&1)===0?"02":"03",R=c.fromHex(D+d(B)),k=a(B),H=i(-w*k),O=i(x*k),q=c.BASE.multiplyAndAddUnsafe(R,H,O);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new l(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return nr(this.toDERHex())}toDERHex(){return zt.hexFromSig(this)}toCompactRawBytes(){return nr(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let b={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=zn(t.n);return Ns(t.randomBytes(S),t.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function A(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function m(S){let I=he(S),U=typeof S=="string",x=(I||U)&&S.length;return I?x===o||x===s:U?x===2*o||x===2*s:S instanceof c}function v(S,I,U=!0){if(m(S))throw new Error("first arg must be private key");if(!m(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(u(S)).toRawBytes(U)}let T=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=Mt(S),U=S.length*8-t.nBitLength;return U>0?I>>BigInt(U):I},C=t.bits2int_modN||function(S){return i(T(S))},_=pe(t.nBitLength);function L(S){return wt("num < 2^"+t.nBitLength,S,Ft,_),de(S,t.nByteLength)}function K(S,I,U=F){if(["recovered","canonical"].some(X=>X in U))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:p}=t,{lowS:w,prehash:B,extraEntropy:D}=U;w==null&&(w=!0),S=W("msgHash",S),Ei(U),B&&(S=W("prehashed msgHash",x(S)));let R=C(S),k=u(I),H=[L(k),L(R)];if(D!=null&&D!==!1){let X=D===!0?p(r.BYTES):D;H.push(W("extraEntropy",X))}let O=Qt(...H),q=R;function $(X){let nt=T(X);if(!h(nt))return;let mt=a(nt),tt=c.BASE.multiply(nt).toAffine(),it=i(tt.x);if(it===Ft)return;let bt=i(mt*i(q+it*k));if(bt===Ft)return;let vt=(tt.x===it?0:2)|Number(tt.y&rt),Me=bt;return w&&E(bt)&&(Me=g(bt),vt^=1),new l(it,Me,vt)}return{seed:O,k2sig:$}}let F={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function N(S,I,U=F){let{seed:x,k2sig:p}=K(S,I,U),w=t;return Us(w.hash.outputLen,w.nByteLength,w.hmac)(x,p)}c.BASE._setWindowSize(8);function J(S,I,U,x=M){let p=S;I=W("msgHash",I),U=W("publicKey",U);let{lowS:w,prehash:B,format:D}=x;if(Ei(x),"strict"in x)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let R=typeof p=="string"||he(p),k=!R&&!D&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!R&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let H,O;try{if(k&&(H=new l(p.r,p.s)),R){try{D!=="compact"&&(H=l.fromDER(p))}catch(vt){if(!(vt instanceof zt.Err))throw vt}!H&&D!=="der"&&(H=l.fromCompact(p))}O=c.fromHex(U)}catch{return!1}if(!H||w&&H.hasHighS())return!1;B&&(I=t.hash(I));let{r:q,s:$}=H,X=C(I),nt=a($),mt=i(X*nt),tt=i(q*nt),it=c.BASE.multiplyAndAddUnsafe(O,mt,tt)?.toAffine();return it?i(it.x)===q:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:v,sign:N,verify:J,ProjectivePoint:c,Signature:l,utils:b}}function df(e){return{hash:e,hmac:(t,...r)=>lr(e,t,Tn(...r)),randomBytes:Ce}}function Bi(e,t){let r=n=>Si({...e,...df(n)});return{...r(t),create:r}}var _i=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),pf=BigInt(1),Eo=BigInt(2),Ii=(e,t)=>(e+t/Eo)/t;function mf(e){let t=_i,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,h=G(f,r,t)*f%t,d=G(h,r,t)*f%t,E=G(d,Eo,t)*u%t,g=G(E,o,t)*E%t,y=G(g,s,t)*g%t,l=G(y,a,t)*y%t,b=G(l,c,t)*l%t,A=G(b,a,t)*y%t,m=G(A,r,t)*f%t,v=G(m,i,t)*g%t,T=G(v,n,t)*u%t,C=G(T,Eo,t);if(!Ao.eql(Ao.sqr(C),e))throw new Error("Cannot find square root");return C}var Ao=Vt(_i,void 0,void 0,{sqrt:mf}),Bt=Bi({a:BigInt(0),b:BigInt(7),Fp:Ao,n:vi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=vi,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-pf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=Ii(s*e,t),c=Ii(-n*e,t),u=z(e-a*r-c*o,t),f=z(-a*n-c*s,t),h=u>i,d=f>i;if(h&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:h,k1:u,k2neg:d,k2:f}}}},Ur),S0=BigInt(0);var B0=Bt.ProjectivePoint;function So(e,t){let r=Z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Ut([new Uint8Array(t-r.length),r])}return r}function Bo(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Li=33,Ki=32;function Ui(e,t){let r=wr.digest(t instanceof Uint8Array?t:t.subarray());if(Bo(r))return r.then(({digest:n})=>Bt.sign(n,e).toDERRawBytes()).catch(n=>{throw new qe(String(n))});try{return Bt.sign(r.digest,e).toDERRawBytes()}catch(n){throw new qe(String(n))}}function Ci(e,t,r){let n=wr.digest(r instanceof Uint8Array?r:r.subarray());if(Bo(n))return n.then(({digest:o})=>Bt.verify(t,o,e)).catch(o=>{throw new Ve(String(o))});try{return Bt.verify(t,n.digest,e)}catch(o){throw new Ve(String(o))}}var dr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ri(t),this.raw=Ti(this._key)}toMultihash(){return oe.digest(ie(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return et.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 Ci(this._key,r,t)}},pr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Di(t),this.publicKey=new dr(r??Pi(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return Ui(this.raw,t)}};function vo(e){return new pr(e)}function Wr(e){return new dr(e)}async function Ni(){let e=yf();return new pr(e)}function Ti(e){return Bt.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Di(e){try{return Bt.getPublicKey(e,!0),e}catch(t){throw new ze(String(t))}}function Ri(e){try{return Bt.ProjectivePoint.fromHex(e),e}catch(t){throw new ge(String(t))}}function Pi(e){try{return Bt.getPublicKey(e,!0)}catch(t){throw new ze(String(t))}}function yf(){return Bt.utils.randomPrivateKey()}var Yr={"P-256":32,"P-384":48,"P-521":66},bf=Object.keys(Yr),Io=bf.join(" / ");async function ki(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new P(`Unknown curve: ${e}. Must be ${Io}`);let t=await ot.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await ot.get().subtle.importKey("jwk",gf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let c=await ot.get().subtle.importKey("jwk",Hi(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await ot.get().subtle.deriveBits({name:"ECDH",public:c},a,Yr[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await ot.get().subtle.exportKey("jwk",t.publicKey);return{key:xf(n),genSharedKey:r}}function xf(e){if(e.crv==null||e.x==null||e.y==null)throw new P("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new P(`Unknown curve: ${e.crv}. Must be ${Io}`);let t=Yr[e.crv];return Ut([Uint8Array.from([4]),So(e.x,t),So(e.y,t)],1+t*2)}function Hi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new P(`Unknown curve: ${e}. Must be ${Io}`);let r=Yr[e];if(!ct(t.subarray(0,1),Uint8Array.from([4])))throw new P("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 gf=(e,t)=>({...Hi(e,t.public),d:V(t.private,"base64url")});var wf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Oi(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new P("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new P("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new P("Secret was missing or an incorrect type");let n=wf[e],o=n.keySize,s=n.ivSize,i=20,a=Z("key expansion"),c=2*(s+o+i),u=await Jr(t,r),f=await u.digest(a),h=[],d=0;for(;d<c;){let A=await u.digest(Ut([f,a])),m=A.length;d+m>c&&(m=c-d),h.push(A),d+=m,f=await u.digest(f)}let E=c/2,g=Ut(h),y=g.subarray(0,E),l=g.subarray(E,c),b=A=>({iv:A.subarray(0,s),cipherKey:A.subarray(s,s+o),macKey:A.subarray(s+o)});return{k1:b(y),k2:b(l)}}async function Ef(e,t){if(e==="Ed25519")return Js();if(e==="secp256k1")return Ni();if(e==="RSA")return go(Kf(t));if(e==="ECDSA")return ds(Uf(t));throw new jt}async function Af(e,t){if(e!=="Ed25519")throw new jt("Seed key derivation only supported for Ed25519 keys");return Qs(t)}function Sf(e,t){let{Type:r,Data:n}=Rt.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return xo(o,t);case j.Ed25519:return kr(o);case j.secp256k1:return Wr(o);case j.ECDSA:return Ln(o);default:throw new jt}}function Bf(e){if(e.byteLength===te)return kr(e);if(e.byteLength===Li)return Wr(e);let t=gt(e),r=t[1]?.[0];if(r===Bn||r===vn||r===In)return Kn(t);if(t[0]?.[0]===wi)return jr(t,e);throw new P("Could not extract public key from raw bytes")}function vf(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return kr(n);case j.secp256k1:return Wr(n);case j.ECDSA:return Ln(n);default:throw new jt}}function ie(e){return Rt.encode({Type:j[e.type],Data:e.raw})}function If(e){let t=fr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return bo(r);case j.Ed25519:return Xn(r);case j.secp256k1:return vo(r);case j.ECDSA:return fs(r);default:throw new jt}}function _f(e){if(e.byteLength===St)return Xn(e);if(e.byteLength===Ki)return vo(e);let t=gt(e),r=t[2]?.[0];if(r===Bn||r===vn||r===In)return _n(t);if(t.length>8)return Fr(t);throw new P("Could not extract private key from raw bytes")}function Lf(e){return fr.encode({Type:j[e.type],Data:e.raw})}function Kf(e){return e==null?2048:parseInt(e,10)}function Uf(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 P("Unsupported curve, should be P-256, P-384 or P-521")}async function Cf(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 P("Only RSA and ECDSA keys are supported")}async function Tf(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 kt(t)}throw new P("Only RSA and ECDSA keys are supported")}function Df(e,t,r,n){Sr(e);let o=ms({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Gt(s),Gt(i),Gt(a),s<1)throw new Error("iterations (c) should be >= 1");let c=Cn(t),u=Cn(r),f=new Uint8Array(i),h=lr.create(e,c),d=h._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:a,DK:f,PRF:h,PRFSalt:d}}function Rf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),yt(o),r}function Mi(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:c}=Df(e,t,r,n),u,f=new Uint8Array(4),h=Ue(f),d=new Uint8Array(a.outputLen);for(let E=1,g=0;g<s;E++,g+=a.outputLen){let y=i.subarray(g,g+a.outputLen);h.setInt32(0,E,!1),(u=c._cloneInto(u)).update(f).digestInto(d),y.set(d.subarray(0,y.length));for(let l=1;l<o;l++){a._cloneInto(u).update(d).digestInto(d);for(let b=0;b<y.length;b++)y[b]^=d[b]}}return Rf(a,c,i,u,d)}var mr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ne=new Uint32Array(80),Xr=class extends ce{constructor(){super(64,20,8,!1),this.A=mr[0]|0,this.B=mr[1]|0,this.C=mr[2]|0,this.D=mr[3]|0,this.E=mr[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)ne[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)ne[c]=Br(ne[c-3]^ne[c-8]^ne[c-14]^ne[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=vr(o,s,i),f=1518500249):c<40?(u=o^s^i,f=1859775393):c<60?(u=Ir(o,s,i),f=2400959708):(u=o^s^i,f=3395469782);let h=Br(n,5)+u+a+f+ne[c]|0;a=i,i=s,s=Br(o,30),o=n,n=h}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(){yt(ne)}destroy(){this.set(0,0,0,0,0),yt(this.buffer)}},qi=Qe(()=>new Xr);var Vi=qi;var zi=Cr;var Fi={sha1:Vi,"sha2-256":He,"sha2-512":zi};function Lo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Fi).join(" / ");throw new P(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Fi[o],i=Mi(s,e,t,{c:r,dkLen:n});return pn.encode(i).substring(1)}return Qi(Pf);})();
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:()=>br,keys:()=>Ko,pbkdf2:()=>Uo,randomBytes:()=>uo});var br={};ct(br,{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"}},xr=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 xr("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 x=S[K],v=0,B=g-1;(x!==0||v<D)&&B!==-1;B--,v++)x+=256*u[B]>>>0,u[B]=x%c>>>0,x=x/c>>>0;if(x!==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 x=0,v=O-1;(u!==0||x<K)&&v!==-1;v--,x++)u+=c*g[v]>>>0,g[v]=u%256>>>0,u=u/256>>>0;if(u!==0)throw new Error("Non-zero carry");K=x,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:()=>xa,base32hexupper:()=>ma,base32pad:()=>la,base32padupper:()=>da,base32upper:()=>ha,base32z:()=>ba});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}),xa=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ba=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 xn={};ct(xn,{base8:()=>nc});var nc=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};ct(bn,{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={...bn,...dn,...xn,...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 xc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bc=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 xc;if(e==="P-384")return bc;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 xt(...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 xs(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,xt(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),bs=BigInt(32);function Ac(e,t=!1){return t?{h:Number(e&Lr),l:Number(e>>bs&Lr)}:{h:Number(e>>bs&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(){xt(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),xt(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,x=Jt[g-15]|0,v=ue(u,x,1)^ue(u,x,8)^Rn(u,x,7),B=he(u,x,1)^he(u,x,8)^Pn(u,x,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),x=he(l,y,14)^he(l,y,18)^rr(l,y,41),v=l&I^~l&m,B=y&S^~y&D,_=vs(O,x,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(){xt($t,Jt)}destroy(){xt(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(b,d){let p=r.sqr(b),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||((b,d)=>{try{return{isValid:!0,value:r.sqrt(b*r.inv(d))}}catch{return{isValid:!1,value:Rt}}}),S=t.adjustScalarBytes||(b=>b),m=t.domain||((b,d,p)=>{if(Dt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return b});function D(b,d,p=!1){let A=p?pt:Rt;Et("coordinate "+b,d,A,h)}function K(b){if(!(b instanceof u))throw new Error("ExtendedPoint expected")}let O=Re((b,d)=>{let{ex:p,ey:A,ez:C}=b,N=b.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(b=>{let{a:d,d:p}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:N,et:M}=b,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),bt=f(Q*yt),Bt=f(ot*$);return new u(tt,at,Bt,bt)}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),bt=f((C+N)*(V+z)-ot-yt),Bt=at-tt,qe=at+tt,Co=f(yt-p*ot),Yi=f(bt*Bt),Wi=f(qe*Co),Xi=f(bt*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,bt=(q&128)!==0;if(!p&&tt===Rt&&bt)throw new Error("Point.fromHex: x=0 and x_0=1");return bt!==at&&(tt=f(-tt)),u.fromAffine({x:tt,y:V})}static fromPrivateKey(d){let{scalar:p}=k(d);return x.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:x,ZERO:v}=u,B=Pr(u,c*8);function _(b){return j(b,n)}function R(b){return _(le(b))}function k(b){let d=r.BYTES;b=Y("private key",b,d);let p=Y("hashed private key",s(b),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(b){let{head:d,prefix:p,scalar:A}=k(b),C=x.multiply(A),N=C.toRawBytes();return{head:d,prefix:p,scalar:A,point:C,pointBytes:N}}function P(b){return U(b).pointBytes}function T(b=Uint8Array.of(),...d){let p=te(...d);return R(s(m(p,Y("context",b),!!o)))}function J(b,d,p={}){b=Y("message",b),o&&(b=o(b));let{prefix:A,scalar:C,pointBytes:N}=U(d),M=T(p.context,A,b),q=x.multiply(M).toRawBytes(),V=T(p.context,q,N,b),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(b,d,p,A=E){let{context:C,zip215:N}=A,M=r.BYTES;b=Y("signature",b,2*M),d=Y("message",d),p=Y("publicKey",p,M),N!==void 0&&Dt("zip215",N),o&&(d=o(d));let q=le(b.slice(M,2*M)),V,z,Q;try{V=u.fromHex(p,N),z=u.fromHex(b.slice(0,M),N),Q=x.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 x._setWindowSize(8),{CURVE:t,getPublicKey:P,sign:J,verify:w,ExtendedPoint:u,utils:{getExtendedPublicKey:U,randomPrivateKey:()=>i(r.BYTES),precompute(b=8,d=u.BASE){return d._setWindowSize(b),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 xe;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 xe;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):xe}},xe=new At(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.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 be=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 be(no,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 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 be(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 be(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 be{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:()=>xo,pkixMessageToJwk:()=>mo,pkixMessageToRSAPublicKey:()=>Gr,pkixToJwk:()=>ff,pkixToRSAPublicKey:()=>bo});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 xo(e){let t=gt(e);return jr(t)}function jr(e){let t=po(e);return Zr(t)}function bo(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),xt(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,x)=>{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),x=r.fromBytes(u.subarray(0,r.BYTES)),v=r.fromBytes(u.subarray(r.BYTES,2*r.BYTES));return{x,y:v}});function i(g){let{a:u,b:x}=t,v=r.sqr(g),B=r.mul(v,g);return r.add(r.add(B,r.mul(g,u)),x)}function c(g,u){let x=r.sqr(u),v=i(g);return r.eql(x,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:x,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(x*2,"0")}let _;try{_=typeof g=="bigint"?g:qt(Y("private key",g,x))}catch{throw new Error("invalid private key, expected hex or "+x+" 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:x,py:v,pz:B}=g;if(r.eql(B,r.ONE))return{x,y:v};let _=g.is0();u==null&&(u=_?r.ONE:r.inv(B));let R=r.mul(x,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:x}=g.toAffine();if(!r.isValid(u)||!r.isValid(x))throw new Error("bad point: x or y not FE");if(!c(u,x))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,x,v){if(u==null||!r.isValid(u))throw new Error("x required");if(x==null||!r.isValid(x)||r.is0(x))throw new Error("y required");if(v==null||!r.isValid(v))throw new Error("z required");this.px=u,this.py=x,this.pz=v,Object.freeze(this)}static fromAffine(u){let{x,y:v}=u||{};if(!u||!r.isValid(x)||!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(x)&&B(v)?m.ZERO:new m(x,v,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(u){let x=Pe(r,u.map(v=>v.pz));return u.map((v,B)=>v.toAffine(x[B])).map(m.fromAffine)}static fromHex(u){let x=m.fromAffine(s(Y("pointHex",u)));return x.assertValidity(),x}static fromPrivateKey(u){return m.BASE.multiply(l(u))}static msm(u,x){return Nr(m,n,u,x)}_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:x,py:v,pz:B}=this,{px:_,py:R,pz:k}=u,U=r.eql(r.mul(x,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:x}=t,v=r.mul(x,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:x,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(x,_),L=r.mul(v,R),b=r.mul(B,k),d=r.add(x,v),p=r.add(_,R);d=r.mul(d,p),p=r.add(w,L),d=r.sub(d,p),p=r.add(x,B);let A=r.add(_,k);return p=r.mul(p,A),A=r.add(w,b),p=r.sub(p,A),A=r.add(v,B),U=r.add(R,k),A=r.mul(A,U),U=r.add(L,b),A=r.sub(A,U),T=r.mul(J,p),U=r.mul(E,b),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),b=r.mul(J,b),p=r.mul(E,p),L=r.add(L,b),b=r.sub(w,b),b=r.mul(J,b),p=r.add(p,b),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:x,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(!x||O.hasPrecomputes(this))return O.wNAFCachedUnsafe(this,u,m.normalizeZ);let{k1neg:_,k1:R,k2neg:k,k2:U}=x.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,x.beta),T.py,T.pz),P.add(T)}multiply(u){let{endo:x,n:v}=t;Et("scalar",u,nt,v);let B,_;if(x){let{k1neg:R,k1:k,k2neg:U,k2:P}=x.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,x.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,x,v){let B=m.BASE,_=(k,U)=>U===jt||U===nt||!k.equals(B)?k.multiplyUnsafe(U):k.multiply(U),R=_(this,x).add(_(u,v));return R.is0()?void 0:R}toAffine(u){return I(this,u)}isTorsionFree(){let{h:u,isTorsionFree:x}=t;if(u===nt)return!0;if(x)return x(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:u,clearCofactor:x}=t;return u===nt?this:x?x(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 b=w.toAffine(),d=r.toBytes(b.x),p=te;return Dt("isCompressed",L),L?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,r.toBytes(b.y))},fromBytes(E){let w=E.length,L=E[0],b=E.subarray(1);if(w===i&&(L===2||L===3)){let d=qt(b);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(b.subarray(0,r.BYTES)),p=r.fromBytes(b.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,b){Et("r",w,nt,n),Et("s",L,nt,n),this.r=w,this.s=L,b!=null&&(this.recovery=b),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:b}=Ft.toSig(Y("DER",w));return new K(L,b)}assertValidity(){}addRecoveryBit(w){return new K(this.r,this.s,w)}recoverPublicKey(w){let{r:L,s:b,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(b*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,b=r.BYTES,d=b+1,p=2*b+1;if(!(t.allowedPrivateKeyLengths||o===d))return L===d||L===p}function x(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:b,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",b(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 bt=a(yt*a(z+at*M));if(bt===jt)return;let Bt=(tt.x===at?0:2)|Number(tt.y&nt),qe=bt;return p&&S(bt)&&(qe=m(bt),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:b,k2sig:d}=k(E,w,L),p=t;return Ts(p.hash.outputLen,p.nByteLength,p.hmac)(b,d)}f.BASE._setWindowSize(8);function J(E,w,L,b=P){let d=E;w=Y("msgHash",w),L=Y("publicKey",L);let{lowS:p,prehash:A,format:C}=b;if(Bi(b),"strict"in b)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:x,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),xf=BigInt(1),So=BigInt(2),Ki=(e,t)=>(e+t/So)/t;function bf(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,x=W(u,n,t)*h%t,v=W(x,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:bf}),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=-xf*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 bo(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 xo(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=xs({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(),xt(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(){xt(oe)}destroy(){this.set(0,0,0,0,0),xt(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: