@libp2p/crypto 5.1.0 → 5.1.1
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 +1 -1
- package/package.json +2 -2
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 Zr=Object.defineProperty;var ki=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Hi=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var r in t)Zr(e,r,{get:t[r],enumerable:!0})},Mi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Oi(t))!Hi.call(e,o)&&o!==r&&Zr(e,o,{get:()=>t[o],enumerable:!(n=ki(t,o))||n.enumerable});return e};var qi=e=>Mi(Zr({},"__esModule",{value:!0}),e);var tu={};st(tu,{hmac:()=>hr,keys:()=>Eo,pbkdf2:()=>So,randomBytes:()=>no});var hr={};st(hr,{create:()=>Yr});var Me=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},qe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},lr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _o={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new lr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var it=_o;var Uo={SHA1:20,SHA256:32,SHA512:64};var Vi={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},zi=async(e,t)=>{let r=await it.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function Yr(e,t){let r=Vi[e],n=await it.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return zi(n,o)},length:Uo[e]}}var Eo={};st(Eo,{generateEphemeralKeyPair:()=>Si,generateKeyPair:()=>Mf,generateKeyPairFromSeed:()=>qf,keyStretcher:()=>vi,privateKeyFromCryptoKeyPair:()=>$f,privateKeyFromProtobuf:()=>jf,privateKeyFromRaw:()=>Gf,privateKeyToCryptoKeyPair:()=>Xf,privateKeyToProtobuf:()=>Zf,publicKeyFromMultihash:()=>Ff,publicKeyFromProtobuf:()=>Vf,publicKeyFromRaw:()=>zf,publicKeyToProtobuf:()=>ce});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ve=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var zt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Qr={};st(Qr,{base58btc:()=>rt,base58flickr:()=>Wi});var lu=new Uint8Array(0);function Ro(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Do(e){return new TextEncoder().encode(e)}function Po(e){return new TextDecoder().decode(e)}function Fi(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var b=0,h=0,x=0,A=g.length;x!==A&&g[x]===0;)x++,b++;for(var m=(A-x)*f+1>>>0,v=new Uint8Array(m);x!==A;){for(var _=g[x],T=0,I=m-1;(_!==0||T<h)&&I!==-1;I--,T++)_+=256*v[I]>>>0,v[I]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");h=T,x++}for(var C=m-h;C!==m&&v[C]===0;)C++;for(var L=c.repeat(b);C<m;++C)L+=e.charAt(v[C]);return L}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var b=0;if(g[b]!==" "){for(var h=0,x=0;g[b]===c;)h++,b++;for(var A=(g.length-b)*u+1>>>0,m=new Uint8Array(A);g[b];){var v=r[g.charCodeAt(b)];if(v===255)return;for(var _=0,T=A-1;(v!==0||_<x)&&T!==-1;T--,_++)v+=a*m[T]>>>0,m[T]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");x=_,b++}if(g[b]!==" "){for(var I=A-x;I!==A&&m[I]===0;)I++;for(var C=new Uint8Array(h+(A-I)),L=h;I!==A;)C[L++]=m[I++];return C}}}function E(g){var b=d(g);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:E}}var ji=Fi,Gi=ji,ko=Gi;var Wr=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Oo(this,t)}},$r=class{decoders;constructor(t){this.decoders=t}or(t){return Oo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Oo(e,t){return new $r({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Jr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Wr(t,r,n),this.decoder=new Xr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:e,prefix:t,encode:r,decode:n}){return new Jr(e,t,r,n)}function Ft({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ko(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Zi(e,t,r,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),a=0,c=0,u=0;for(let f=0;f<s;++f){let l=o[e[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,a+=r,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=r||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Yi(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return ge({prefix:t,name:e,encode(o){return Yi(o,n,r)},decode(o){return Zi(o,n,r,e)}})}var rt=Ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wi=Ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tn={};st(tn,{base32:()=>we,base32hex:()=>Qi,base32hexpad:()=>ea,base32hexpadupper:()=>ra,base32hexupper:()=>ta,base32pad:()=>$i,base32padupper:()=>Ji,base32upper:()=>Xi,base32z:()=>na});var we=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xi=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$i=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ji=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qi=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ta=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ea=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ra=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),na=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var en={};st(en,{base36:()=>ze,base36upper:()=>oa});var ze=Ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oa=Ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sa=qo,Ho=128,ia=127,aa=~ia,ca=Math.pow(2,31);function qo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ca;)t[r++]=e&255|Ho,e/=128;for(;e&aa;)t[r++]=e&255|Ho,e>>>=7;return t[r]=e|0,qo.bytes=r-n+1,t}var fa=rn,ua=128,Mo=127;function rn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw rn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Mo)<<o:(i&Mo)*Math.pow(2,o),o+=7}while(i>=ua);return rn.bytes=s-n,r}var la=Math.pow(2,7),ha=Math.pow(2,14),da=Math.pow(2,21),pa=Math.pow(2,28),ma=Math.pow(2,35),ya=Math.pow(2,42),ba=Math.pow(2,49),xa=Math.pow(2,56),ga=Math.pow(2,63),wa=function(e){return e<la?1:e<ha?2:e<da?3:e<pa?4:e<ma?5:e<ya?6:e<ba?7:e<xa?8:e<ga?9:10},Ea={encode:sa,decode:fa,encodingLength:wa},Aa=Ea,Fe=Aa;function je(e,t=0){return[Fe.decode(e,t),Fe.decode.bytes]}function Ee(e,t,r=0){return Fe.encode(e,t,r),t}function Ae(e){return Fe.encodingLength(e)}function St(e,t){let r=t.byteLength,n=Ae(e),o=n+Ae(r),s=new Uint8Array(o+r);return Ee(e,s,0),Ee(r,s,n),s.set(t,o),new Se(e,r,t,s)}function Vo(e){let t=Dt(e),[r,n]=je(t),[o,s]=je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Se(r,o,i,t)}function zo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ro(e.bytes,r.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Fo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ba(r,nn(e),t??rt.encoder);default:return va(r,nn(e),t??we.encoder)}}var jo=new WeakMap;function nn(e){let t=jo.get(e);if(t==null){let r=new Map;return jo.set(e,r),r}return t}var wt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ia)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=St(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&zo(t.multihash,n.multihash)}toString(t){return Fo(this,t)}toJSON(){return{"/":Fo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Go(n,o,s.bytes))}else if(r[La]===!0){let{version:n,multihash:o,code:s}=r,i=Vo(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Go(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ze,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Se(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=je(t.subarray(r));return r+=d,l},o=n(),s=Ze;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Sa(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return nn(s).set(n,t),s}};function Sa(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case we.prefix:{let r=t??we;return[we.prefix,r.decode(e)]}case ze.prefix:{let r=t??ze;return[ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Ba(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function va(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Ze=112,Ia=18;function Go(e,t,r){let n=Ae(e),o=n+Ae(t),s=new Uint8Array(o+r.byteLength);return Ee(e,s,0),Ee(t,s,n),s.set(r,o),s}var La=Symbol.for("@ipld/js-cid/CID");var on={};st(on,{identity:()=>ie});var Zo=0,Ka="identity",Yo=Dt;function Ca(e){return St(Zo,Yo(e))}var ie={code:Zo,name:Ka,encode:Yo,digest:Ca};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Tt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Xo=Symbol.for("@achingbrain/uint8arraylist");function Wo(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function pr(e){return!!e?.[Xo]}var lt=class e{bufs;length;[Xo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(pr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(pr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Wo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Wo(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(pr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Tt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Tt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!pr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let E=this.get(l+d);if(n[d]!==E){f=Math.max(1,d-a[E]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var sn={};st(sn,{base10:()=>Ta});var Ta=Ft({prefix:"9",name:"base10",alphabet:"0123456789"});var an={};st(an,{base16:()=>_a,base16upper:()=>Ua});var _a=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ua=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cn={};st(cn,{base2:()=>Ra});var Ra=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fn={};st(fn,{base256emoji:()=>Oa});var $o=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Da=$o.reduce((e,t,r)=>(e[r]=t,e),[]),Pa=$o.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Na(e){return e.reduce((t,r)=>(t+=Da[r],t),"")}function ka(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Oa=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Na,decode:ka});var ln={};st(ln,{base64:()=>un,base64pad:()=>Ha,base64url:()=>Ma,base64urlpad:()=>qa});var un=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ha=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ma=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qa=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hn={};st(hn,{base8:()=>Va});var Va=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dn={};st(dn,{identity:()=>za});var za=ge({prefix:"\0",name:"identity",encode:e=>Po(e),decode:e=>Do(e)});var Yu=new TextEncoder,Wu=new TextDecoder;var yn={};st(yn,{sha256:()=>mr,sha512:()=>Ga});function mn({name:e,code:t,encode:r}){return new pn(e,t,r)}var pn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?St(this.code,r):r.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Qo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var mr=mn({name:"sha2-256",code:18,encode:Qo("SHA-256")}),Ga=mn({name:"sha2-512",code:19,encode:Qo("SHA-512")});var bn={...dn,...cn,...hn,...sn,...an,...tn,...en,...Qr,...ln,...fn},al={...yn,...on};function es(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ts=es("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),xn=es("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Za={utf8:ts,"utf-8":ts,hex:bn.base16,latin1:xn,ascii:xn,binary:xn,...bn},yr=Za;function G(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=yr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ya=parseInt("11111",2),gn=parseInt("10000000",2),Wa=parseInt("01111111",2),rs={0:Ye,1:Ye,2:Xa,3:Qa,4:tc,5:Ja,6:$a,16:Ye,22:Ye,48:Ye};function xt(e,t={offset:0}){let r=e[t.offset]&Ya;if(t.offset++,rs[r]!=null)return rs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&gn)===gn){let n=e[t.offset]&Wa,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ye(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=xt(e,t);if(n===null)break;r.push(n)}return r}function Xa(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function $a(e,t){let r=We(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Ja(e,t){return t.offset++,null}function Qa(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function tc(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ec(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function br(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ec(e.byteLength);return new lt(Uint8Array.from([t.byteLength|gn]),t)}function ht(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),br(t),t)}function Xe(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),br(r),r)}function ns(e){return new lt(Uint8Array.from([4]),br(e),e)}function Bt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),br(r),r)}var wn="1.2.840.10045.3.1.7",En="1.3.132.0.34",An="1.3.132.0.35";async function os(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function ss(e,t){let r=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},r,t.subarray());return new Uint8Array(n,0,n.byteLength)}async function is(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,r.subarray())}var rc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),nc=Uint8Array.from([6,5,43,129,4,0,34]),oc=Uint8Array.from([6,5,43,129,4,0,35]),as={ext:!0,kty:"EC",crv:"P-256"},cs={ext:!0,kty:"EC",crv:"P-384"},fs={ext:!0,kty:"EC",crv:"P-521"},Be=32,ve=48,Ie=66;function us(e){let t=xt(e);return Sn(t)}function Sn(e){let t=e[1],r=V(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Be)return s=V(n.subarray(o,o+Be),"base64url"),i=V(n.subarray(o+Be),"base64url"),new Nt({...as,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===ve)return s=V(n.subarray(o,o+ve),"base64url"),i=V(n.subarray(o+ve),"base64url"),new Nt({...cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=V(n.subarray(o,o+Ie),"base64url"),i=V(n.subarray(o+Ie),"base64url"),new Nt({...fs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Bn(e){let t=xt(e);return vn(t)}function vn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Be*2+1)return n=V(t.subarray(r,r+Be),"base64url"),o=V(t.subarray(r+Be),"base64url"),new ae({...as,key_ops:["verify"],x:n,y:o});if(t.byteLength===ve*2+1)return n=V(t.subarray(r,r+ve),"base64url"),o=V(t.subarray(r+ve),"base64url"),new ae({...cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=V(t.subarray(r,r+Ie),"base64url"),o=V(t.subarray(r+Ie),"base64url"),new ae({...fs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ls(e){return Bt([ht(Uint8Array.from([1])),ns(G(e.d??"","base64url")),Bt([ds(e.crv)],160),Bt([Xe(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function hs(e){return Bt([ht(Uint8Array.from([1])),Bt([ds(e.crv)],160),Bt([Xe(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function ds(e){if(e==="P-256")return rc;if(e==="P-384")return nc;if(e==="P-521")return oc;throw new N(`Invalid curve ${e}`)}async function ps(e="P-256"){let t=await os(e);return new Nt(t.privateKey)}var ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=hs(this.jwk)),this._raw}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r){return is(this.jwk,r,t)}},Nt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ae({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=ls(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async sign(t){return ss(this.jwk,t)}};function Le(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function sc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ke(e,...t){if(!sc(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function xr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Le(e.outputLen),Le(e.blockLen)}function Ce(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ms(e,t){Ke(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var fe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function _e(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}function gr(e,t){return e<<t|e>>>32-t>>>0}function ys(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function jt(e){return typeof e=="string"&&(e=ys(e)),Ke(e),e}function In(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Ke(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Te=class{clone(){return this._cloneInto()}};function bs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function Ue(e){let t=n=>e().update(jt(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Re(e=32){if(fe&&typeof fe.getRandomValues=="function")return fe.getRandomValues(new Uint8Array(e));if(fe&&typeof fe.randomBytes=="function")return fe.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function ic(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function wr(e,t,r){return e&t^~e&r}function Er(e,t,r){return e&t^e&r^t&r}var Gt=class extends Te{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=_e(this.buffer)}update(t){Ce(this);let{view:r,buffer:n,blockLen:o}=this;t=jt(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=_e(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ce(this),ms(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;ic(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=_e(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%r&&t.buffer.set(n),t}};var Ar=BigInt(4294967295),Ln=BigInt(32);function xs(e,t=!1){return t?{h:Number(e&Ar),l:Number(e>>Ln&Ar)}:{h:Number(e>>Ln&Ar)|0,l:Number(e&Ar)|0}}function ac(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:s,l:i}=xs(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}var cc=(e,t)=>BigInt(e>>>0)<<Ln|BigInt(t>>>0),fc=(e,t,r)=>e>>>r,uc=(e,t,r)=>e<<32-r|t>>>r,lc=(e,t,r)=>e>>>r|t<<32-r,hc=(e,t,r)=>e<<32-r|t>>>r,dc=(e,t,r)=>e<<64-r|t>>>r-32,pc=(e,t,r)=>e>>>r-32|t<<64-r,mc=(e,t)=>t,yc=(e,t)=>e,bc=(e,t,r)=>e<<r|t>>>32-r,xc=(e,t,r)=>t<<r|e>>>32-r,gc=(e,t,r)=>t<<r-32|e>>>64-r,wc=(e,t,r)=>e<<r-32|t>>>64-r;function Ec(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ac=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Sc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Bc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),vc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ic=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Lc=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Kc={fromBig:xs,split:ac,toBig:cc,shrSH:fc,shrSL:uc,rotrSH:lc,rotrSL:hc,rotrBH:dc,rotrBL:pc,rotr32H:mc,rotr32L:yc,rotlSH:bc,rotlSL:xc,rotlBH:gc,rotlBL:wc,add:Ec,add3L:Ac,add3H:Sc,add4L:Bc,add4H:vc,add5H:Lc,add5L:Ic},P=Kc;var[Cc,Tc]=P.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Zt=new Uint32Array(80),Yt=new Uint32Array(80),Kn=class extends Gt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:E,Gl:g,Hh:b,Hl:h}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,E,g,b,h]}set(t,r,n,o,s,i,a,c,u,f,l,d,E,g,b,h){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=b|0,this.Hl=h|0}process(t,r){for(let m=0;m<16;m++,r+=4)Zt[m]=t.getUint32(r),Yt[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let v=Zt[m-15]|0,_=Yt[m-15]|0,T=P.rotrSH(v,_,1)^P.rotrSH(v,_,8)^P.shrSH(v,_,7),I=P.rotrSL(v,_,1)^P.rotrSL(v,_,8)^P.shrSL(v,_,7),C=Zt[m-2]|0,L=Yt[m-2]|0,Z=P.rotrSH(C,L,19)^P.rotrBH(C,L,61)^P.shrSH(C,L,6),M=P.rotrSL(C,L,19)^P.rotrBL(C,L,61)^P.shrSL(C,L,6),O=P.add4L(I,M,Yt[m-7],Yt[m-16]),J=P.add4H(O,T,Z,Zt[m-7],Zt[m-16]);Zt[m]=J|0,Yt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:E,Fl:g,Gh:b,Gl:h,Hh:x,Hl:A}=this;for(let m=0;m<80;m++){let v=P.rotrSH(l,d,14)^P.rotrSH(l,d,18)^P.rotrBH(l,d,41),_=P.rotrSL(l,d,14)^P.rotrSL(l,d,18)^P.rotrBL(l,d,41),T=l&E^~l&b,I=d&g^~d&h,C=P.add5L(A,_,I,Tc[m],Yt[m]),L=P.add5H(C,x,v,T,Cc[m],Zt[m]),Z=C|0,M=P.rotrSH(n,o,28)^P.rotrBH(n,o,34)^P.rotrBH(n,o,39),O=P.rotrSL(n,o,28)^P.rotrBL(n,o,34)^P.rotrBL(n,o,39),J=n&s^n&a^s&a,S=o&i^o&c^i&c;x=b|0,A=h|0,b=E|0,h=g|0,E=l|0,g=d|0,{h:l,l:d}=P.add(u|0,f|0,L|0,Z|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let K=P.add3L(Z,O,S);n=P.add3H(K,L,M,J),o=K|0}({h:n,l:o}=P.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=P.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=P.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=P.add(this.Eh|0,this.El|0,l|0,d|0),{h:E,l:g}=P.add(this.Fh|0,this.Fl|0,E|0,g|0),{h:b,l:h}=P.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:x,l:A}=P.add(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,s,i,a,c,u,f,l,d,E,g,b,h,x,A)}roundClean(){Zt.fill(0),Yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Sr=Ue(()=>new Kn);var Ir={};st(Ir,{aInRange:()=>mt,abool:()=>It,abytes:()=>De,bitGet:()=>Nc,bitLen:()=>Un,bitMask:()=>Je,bitSet:()=>kc,bytesToHex:()=>Ot,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>Xt,concatBytes:()=>Mt,createHmacDrbg:()=>Rn,ensureBytes:()=>X,equalBytes:()=>Dc,hexToBytes:()=>le,hexToNumber:()=>_n,inRange:()=>$e,isBytes:()=>Wt,memoized:()=>de,notImplemented:()=>Hc,numberToBytesBE:()=>$t,numberToBytesLE:()=>he,numberToHexUnpadded:()=>ue,numberToVarBytesBE:()=>Rc,utf8ToBytes:()=>Pc,validateObject:()=>_t});var Br=BigInt(0),vr=BigInt(1),_c=BigInt(2);function Wt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function De(e){if(!Wt(e))throw new Error("Uint8Array expected")}function It(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}var Uc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ot(e){De(e);let t="";for(let r=0;r<e.length;r++)t+=Uc[e[r]];return t}function ue(e){let t=e.toString(16);return t.length&1?"0"+t:t}function _n(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Br:BigInt("0x"+e)}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gs(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=gs(e.charCodeAt(s)),a=gs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ht(e){return _n(Ot(e))}function Xt(e){return De(e),_n(Ot(Uint8Array.from(e).reverse()))}function $t(e,t){return le(e.toString(16).padStart(t*2,"0"))}function he(e,t){return $t(e,t).reverse()}function Rc(e){return le(ue(e))}function X(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Wt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Mt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];De(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Dc(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Pc(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}var Cn=e=>typeof e=="bigint"&&Br<=e;function $e(e,t,r){return Cn(e)&&Cn(t)&&Cn(r)&&t<=e&&e<r}function mt(e,t,r,n){if(!$e(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Un(e){let t;for(t=0;e>Br;e>>=vr,t+=1);return t}function Nc(e,t){return e>>BigInt(t)&vr}function kc(e,t,r){return e|(r?vr:Br)<<BigInt(t)}var Je=e=>(_c<<BigInt(e-1))-vr,Tn=e=>new Uint8Array(e),ws=e=>Uint8Array.from(e);function Rn(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Tn(e),o=Tn(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>r(o,n,...l),c=(l=Tn())=>{o=a(ws([0]),l),n=a(),l.length!==0&&(o=a(ws([1]),l),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let E=n.slice();d.push(E),l+=n.length}return Mt(...d)};return(l,d)=>{i(),c(l);let E;for(;!(E=d(u()));)c();return i(),E}}var Oc={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Wt(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function _t(e,t,r={}){let n=(o,s,i)=>{let a=Oc[s];if(typeof a!="function")throw new Error("invalid validator function");let c=e[o];if(!(i&&c===void 0)&&!a(c,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+c)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(r))n(o,s,!0);return e}var Hc=()=>{throw new Error("not implemented")};function de(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Q=BigInt(0),Y=BigInt(1),pe=BigInt(2),Mc=BigInt(3),Dn=BigInt(4),Es=BigInt(5),As=BigInt(8),qc=BigInt(9),Vc=BigInt(16);function z(e,t){let r=e%t;return r>=Q?r:t+r}function zc(e,t,r){if(t<Q)throw new Error("invalid exponent, negatives unsupported");if(r<=Q)throw new Error("invalid modulus");if(r===Y)return Q;let n=Y;for(;t>Q;)t&Y&&(n=n*e%r),e=e*e%r,t>>=Y;return n}function W(e,t,r){let n=e;for(;t-- >Q;)n*=n,n%=r;return n}function Lr(e,t){if(e===Q)throw new Error("invert: expected non-zero number");if(t<=Q)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=Q,s=Y,i=Y,a=Q;for(;r!==Q;){let u=n/r,f=n%r,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==Y)throw new Error("invert: does not exist");return z(o,t)}function Fc(e){let t=(e-Y)/pe,r,n,o;for(r=e-Y,n=0;r%pe===Q;r/=pe,n++);for(o=pe;o<e&&zc(o,t,e)!==e-Y;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(e+Y)/Dn;return function(c,u){let f=c.pow(u,i);if(!c.eql(c.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(r+Y)/pe;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,f=a.pow(a.mul(a.ONE,o),r),l=a.pow(c,s),d=a.pow(c,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let b=a.sqr(d);E<u&&!a.eql(b,a.ONE);E++)b=a.sqr(b);let g=a.pow(f,Y<<BigInt(u-E-1));f=a.sqr(g),l=a.mul(l,g),d=a.mul(d,f),u=E}return l}}function jc(e){if(e%Dn===Mc){let t=(e+Y)/Dn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(e%As===Es){let t=(e-Es)/As;return function(n,o){let s=n.mul(o,pe),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,pe),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return e%Vc,Fc(e)}var Ss=(e,t)=>(z(e,t)&Y)===Y,Gc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Gc.reduce((n,o)=>(n[o]="function",n),t);return _t(e,r)}function Zc(e,t,r){if(r<Q)throw new Error("invalid exponent, negatives unsupported");if(r===Q)return e.ONE;if(r===Y)return t;let n=e.ONE,o=t;for(;r>Q;)r&Y&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Y;return n}function Yc(e,t){let r=new Array(t.length),n=t.reduce((s,i,a)=>e.is0(i)?s:(r[a]=s,e.mul(s,i)),e.ONE),o=e.inv(n);return t.reduceRight((s,i,a)=>e.is0(i)?s:(r[a]=e.mul(s,r[a]),e.mul(s,i)),o),r}function Nn(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jt(e,t,r=!1,n={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:s}=Nn(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:s,MASK:Je(o),ZERO:Q,ONE:Y,create:c=>z(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Q<=c&&c<e},is0:c=>c===Q,isOdd:c=>(c&Y)===Y,neg:c=>z(-c,e),eql:(c,u)=>c===u,sqr:c=>z(c*c,e),add:(c,u)=>z(c+u,e),sub:(c,u)=>z(c-u,e),mul:(c,u)=>z(c*u,e),pow:(c,u)=>Zc(a,c,u),div:(c,u)=>z(c*Lr(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Lr(c,e),sqrt:n.sqrt||(c=>(i||(i=jc(e)),i(a,c))),invertBatch:c=>Yc(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>r?he(c,s):$t(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?Xt(c):Ht(c)}});return Object.freeze(a)}function Bs(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function kn(e){let t=Bs(e);return t+Math.ceil(t/2)}function vs(e,t,r=!1){let n=e.length,o=Bs(t),s=kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Xt(e):Ht(e),a=z(i,t-Y)+Y;return r?he(a,o):$t(a,o)}var Is=BigInt(0),Kr=BigInt(1);function On(e,t){let r=t.negate();return e?r:t}function Ls(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Hn(e,t){Ls(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function Wc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Xc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Mn=new WeakMap,Ks=new WeakMap;function qn(e){return Ks.get(e)||1}function Cr(e,t){return{constTimeNegate:On,hasPrecomputes(r){return qn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Is;)n&Kr&&(o=o.add(s)),s=s.double(),n>>=Kr;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Hn(n,t),i=[],a=r,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let{windows:s,windowSize:i}=Hn(r,t),a=e.ZERO,c=e.BASE,u=BigInt(2**r-1),f=2**r,l=BigInt(r);for(let d=0;d<s;d++){let E=d*i,g=Number(o&u);o>>=l,g>i&&(g-=f,o+=Kr);let b=E,h=E+Math.abs(g)-1,x=d%2!==0,A=g<0;g===0?c=c.add(On(x,n[b])):a=a.add(On(A,n[h]))}return{p:a,f:c}},wNAFUnsafe(r,n,o,s=e.ZERO){let{windows:i,windowSize:a}=Hn(r,t),c=BigInt(2**r-1),u=2**r,f=BigInt(r);for(let l=0;l<i;l++){let d=l*a;if(o===Is)break;let E=Number(o&c);if(o>>=f,E>a&&(E-=u,o+=Kr),E===0)continue;let g=n[d+Math.abs(E)-1];E<0&&(g=g.negate()),s=s.add(g)}return s},getPrecomputes(r,n,o){let s=Mn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Mn.set(n,o(s))),s},wNAFCached(r,n,o){let s=qn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=qn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Ls(n,t),Ks.set(r,n),Mn.delete(r)}}}function Tr(e,t,r,n){if(Wc(r,e),Xc(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,s=Un(BigInt(r.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=(1<<i)-1,c=new Array(a+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let l=u;l>=0;l-=i){c.fill(o);for(let E=0;E<n.length;E++){let g=n[E],b=Number(g>>BigInt(l)&BigInt(a));c[b]=c[b].add(r[E])}let d=o;for(let E=c.length-1,g=o;E>0;E--)g=g.add(c[E]),d=d.add(g);if(f=f.add(d),l!==0)for(let E=0;E<i;E++)f=f.double()}return f}function Qe(e){return Pn(e.Fp),_t(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Nn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Lt=BigInt(0),yt=BigInt(1),_r=BigInt(2),$c=BigInt(8),Jc={zip215:!0};function Qc(e){let t=Qe(e);return _t(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Cs(e){let t=Qc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=_r<<BigInt(a*8)-yt,f=r.create,l=Jt(t.n,t.nBitLength),d=t.uvRatio||((y,p)=>{try{return{isValid:!0,value:r.sqrt(y*r.inv(p))}}catch{return{isValid:!1,value:Lt}}}),E=t.adjustScalarBytes||(y=>y),g=t.domain||((y,p,w)=>{if(It("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,p){mt("coordinate "+y,p,Lt,u)}function h(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let x=de((y,p)=>{let{ex:w,ey:B,ez:U}=y,R=y.is0();p==null&&(p=R?$c:r.inv(U));let k=f(w*p),H=f(B*p),D=f(U*p);if(R)return{x:Lt,y:yt};if(D!==yt)throw new Error("invZ was invalid");return{x:k,y:H}}),A=de(y=>{let{a:p,d:w}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:B,ey:U,ez:R,et:k}=y,H=f(B*B),D=f(U*U),q=f(R*R),F=f(q*q),tt=f(H*p),et=f(q*f(tt+D)),ot=f(F+f(w*f(H*D)));if(et!==ot)throw new Error("bad point: equation left != right (1)");let at=f(B*U),pt=f(R*k);if(at!==pt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,B,U){this.ex=p,this.ey=w,this.ez=B,this.et=U,b("x",p),b("y",w),b("z",B),b("t",U),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:w,y:B}=p||{};return b("x",w),b("y",B),new m(w,B,yt,f(w*B))}static normalizeZ(p){let w=r.invertBatch(p.map(B=>B.ez));return p.map((B,U)=>B.toAffine(w[U])).map(m.fromAffine)}static msm(p,w){return Tr(m,l,p,w)}_setWindowSize(p){T.setWindowSize(this,p)}assertValidity(){A(this)}equals(p){h(p);let{ex:w,ey:B,ez:U}=this,{ex:R,ey:k,ez:H}=p,D=f(w*H),q=f(R*U),F=f(B*H),tt=f(k*U);return D===q&&F===tt}is0(){return this.equals(m.ZERO)}negate(){return new m(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:p}=t,{ex:w,ey:B,ez:U}=this,R=f(w*w),k=f(B*B),H=f(_r*f(U*U)),D=f(p*R),q=w+B,F=f(f(q*q)-R-k),tt=D+k,et=tt-H,ot=D-k,at=f(F*et),pt=f(tt*ot),ut=f(F*ot),Ct=f(et*tt);return new m(at,pt,Ct,ut)}add(p){h(p);let{a:w,d:B}=t,{ex:U,ey:R,ez:k,et:H}=this,{ex:D,ey:q,ez:F,et:tt}=p;if(w===BigInt(-1)){let Bo=f((R-U)*(q+D)),vo=f((R+U)*(q-D)),Gr=f(vo-Bo);if(Gr===Lt)return this.double();let Io=f(k*_r*tt),Lo=f(H*_r*F),Ko=Lo+Io,Co=vo+Bo,To=Lo-Io,Ri=f(Ko*Gr),Di=f(Co*To),Pi=f(Ko*To),Ni=f(Gr*Co);return new m(Ri,Di,Ni,Pi)}let et=f(U*D),ot=f(R*q),at=f(H*B*tt),pt=f(k*F),ut=f((U+R)*(D+q)-et-ot),Ct=pt-at,Rt=pt+at,He=f(ot-w*et),Ci=f(ut*Ct),Ti=f(Rt*He),_i=f(ut*He),Ui=f(Ct*Rt);return new m(Ci,Ti,Ui,_i)}subtract(p){return this.add(p.negate())}wNAF(p){return T.wNAFCached(this,p,m.normalizeZ)}multiply(p){let w=p;mt("scalar",w,yt,n);let{p:B,f:U}=this.wNAF(w);return m.normalizeZ([B,U])[0]}multiplyUnsafe(p,w=m.ZERO){let B=p;return mt("scalar",B,Lt,n),B===Lt?_:this.is0()||B===yt?this:T.wNAFCachedUnsafe(this,B,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===yt?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:B,a:U}=t,R=r.BYTES;p=X("pointHex",p,R),It("zip215",w);let k=p.slice(),H=p[R-1];k[R-1]=H&-129;let D=Xt(k),q=w?u:r.ORDER;mt("pointHex.y",D,Lt,q);let F=f(D*D),tt=f(F-yt),et=f(B*F-U),{isValid:ot,value:at}=d(tt,et);if(!ot)throw new Error("Point.fromHex: invalid y coordinate");let pt=(at&yt)===yt,ut=(H&128)!==0;if(!w&&at===Lt&&ut)throw new Error("Point.fromHex: x=0 and x_0=1");return ut!==pt&&(at=f(-at)),m.fromAffine({x:at,y:D})}static fromPrivateKey(p){return L(p).point}toRawBytes(){let{x:p,y:w}=this.toAffine(),B=he(w,r.BYTES);return B[B.length-1]|=p&yt?128:0,B}toHex(){return Ot(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,yt,f(t.Gx*t.Gy)),m.ZERO=new m(Lt,yt,yt,Lt);let{BASE:v,ZERO:_}=m,T=Cr(m,a*8);function I(y){return z(y,n)}function C(y){return I(Xt(y))}function L(y){let p=r.BYTES;y=X("private key",y,p);let w=X("hashed private key",s(y),2*p),B=E(w.slice(0,p)),U=w.slice(p,2*p),R=C(B),k=v.multiply(R),H=k.toRawBytes();return{head:B,prefix:U,scalar:R,point:k,pointBytes:H}}function Z(y){return L(y).pointBytes}function M(y=new Uint8Array,...p){let w=Mt(...p);return C(s(g(w,X("context",y),!!o)))}function O(y,p,w={}){y=X("message",y),o&&(y=o(y));let{prefix:B,scalar:U,pointBytes:R}=L(p),k=M(w.context,B,y),H=v.multiply(k).toRawBytes(),D=M(w.context,H,R,y),q=I(k+D*U);mt("signature.s",q,Lt,n);let F=Mt(H,he(q,r.BYTES));return X("result",F,r.BYTES*2)}let J=Jc;function S(y,p,w,B=J){let{context:U,zip215:R}=B,k=r.BYTES;y=X("signature",y,2*k),p=X("message",p),w=X("publicKey",w,k),R!==void 0&&It("zip215",R),o&&(p=o(p));let H=Xt(y.slice(k,2*k)),D,q,F;try{D=m.fromHex(w,R),q=m.fromHex(y.slice(0,k),R),F=v.multiplyUnsafe(H)}catch{return!1}if(!R&&D.isSmallOrder())return!1;let tt=M(U,q.toRawBytes(),D.toRawBytes(),p);return q.add(D.multiplyUnsafe(tt)).subtract(F).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:O,verify:S,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(r.BYTES),precompute(y=8,p=m.BASE){return p._setWindowSize(y),p.multiply(BigInt(3)),p}}}}var Vn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),ch=BigInt(0),tf=BigInt(1),_s=BigInt(2),fh=BigInt(3),ef=BigInt(5),rf=BigInt(8);function nf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Vn,a=e*e%s*e%s,c=W(a,_s,s)*a%s,u=W(c,tf,s)*e%s,f=W(u,ef,s)*u%s,l=W(f,t,s)*f%s,d=W(l,r,s)*l%s,E=W(d,n,s)*d%s,g=W(E,o,s)*E%s,b=W(g,o,s)*E%s,h=W(b,t,s)*f%s;return{pow_p_5_8:W(h,_s,s)*e%s,b2:a}}function of(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function sf(e,t){let r=Vn,n=z(t*t*t,r),o=z(n*n*t,r),s=nf(e*o).pow_p_5_8,i=z(e*n*s,r),a=z(t*i*i,r),c=i,u=z(i*Ts,r),f=a===e,l=a===z(-e,r),d=a===z(-e*Ts,r);return f&&(i=c),(l||d)&&(i=u),Ss(i,r)&&(i=z(-i,r)),{isValid:f||l,value:i}}var af=Jt(Vn,void 0,!0),cf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:af,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:rf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Sr,randomBytes:Re,adjustScalarBytes:of,uvRatio:sf},Pe=Cs(cf);var Qt=32,Et=64,Ur=32;function Us(){let e=Pe.utils.randomPrivateKey(),t=Pe.getPublicKey(e);return{privateKey:Ns(e,t),publicKey:t}}function Rs(e){if(e.length!==Ur)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Pe.getPublicKey(t);return{privateKey:Ns(t,r),publicKey:r}}function Ds(e,t){let r=e.subarray(0,Ur);return Pe.sign(t instanceof Uint8Array?t:t.subarray(),r)}function Ps(e,t,r){return Pe.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}function Ns(e,t){let r=new Uint8Array(Et);for(let n=0;n<Ur;n++)r[n]=e[n],r[Ur+n]=t[n];return r}var tr=class{type="Ed25519";raw;constructor(t){this.raw=Ne(t,Qt)}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return Ps(this.raw,r,t)}},me=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ne(t,Et),this.publicKey=new tr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return Ds(this.raw,t)}};function zn(e){if(e.length>Et){e=Ne(e,Et+Qt);let n=e.subarray(0,Et),o=e.subarray(Et,e.length);return new me(n,o)}e=Ne(e,Et);let t=e.subarray(0,Et),r=e.subarray(Qt);return new me(t,r)}function Rr(e){return e=Ne(e,Qt),new tr(e)}async function Os(){let{privateKey:e,publicKey:t}=Us();return new me(e,t)}async function Hs(e){let{privateKey:t,publicKey:r}=Rs(e);return new me(t,r)}function Ne(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ff=Math.pow(2,7),uf=Math.pow(2,14),lf=Math.pow(2,21),Ms=Math.pow(2,28),qs=Math.pow(2,35),Vs=Math.pow(2,42),zs=Math.pow(2,49),dt=128,te=127;function er(e){if(e<ff)return 1;if(e<uf)return 2;if(e<lf)return 3;if(e<Ms)return 4;if(e<qs)return 5;if(e<Vs)return 6;if(e<zs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fs(e,t,r=0){switch(er(e)){case 8:t[r++]=e&255|dt,e/=128;case 7:t[r++]=e&255|dt,e/=128;case 6:t[r++]=e&255|dt,e/=128;case 5:t[r++]=e&255|dt,e/=128;case 4:t[r++]=e&255|dt,e>>>=7;case 3:t[r++]=e&255|dt,e>>>=7;case 2:t[r++]=e&255|dt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function js(e,t){let r=e[t],n=0;if(n+=r&te,r<dt||(r=e[t+1],n+=(r&te)<<7,r<dt)||(r=e[t+2],n+=(r&te)<<14,r<dt)||(r=e[t+3],n+=(r&te)<<21,r<dt)||(r=e[t+4],n+=(r&te)*Ms,r<dt)||(r=e[t+5],n+=(r&te)*qs,r<dt)||(r=e[t+6],n+=(r&te)*Vs,r<dt)||(r=e[t+7],n+=(r&te)*zs,r<dt))return n;throw new RangeError("Could not decode varint")}var Fn=new Float32Array([-0]),ee=new Uint8Array(Fn.buffer);function Gs(e,t,r){Fn[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function Zs(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Fn[0]}var jn=new Float64Array([-0]),ft=new Uint8Array(jn.buffer);function Ys(e,t,r){jn[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Ws(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],jn[0]}var hf=BigInt(Number.MAX_SAFE_INTEGER),df=BigInt(Number.MIN_SAFE_INTEGER),gt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<hf&&t>df)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Xs&&(o=0n,++n>Xs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ye}},ye=new gt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Xs=4294967296n;function $s(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Js(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Gn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Dr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Zn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Dr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Dr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Zs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ws(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Js(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Dr(this.buf,this.pos+=4),r=Dr(this.buf,this.pos+=4);return new gt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=js(this.buf,this.pos);return this.pos+=er(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yn(e){return new Zn(e instanceof Uint8Array?e:e.subarray())}function Pr(e,t,r){let n=Yn(e);return t.decode(n,void 0,r)}function Wn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return bt(i);o+i>t&&(n=bt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var be=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Xn(){}var Jn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},pf=Wn();function mf(e){return globalThis.Buffer!=null?bt(e):pf(e)}var nr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(Xn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new be(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Nr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=gt.fromBigInt(t);return this._push(Nr,r.length(),r)}uint64Number(t){return this._push(Fs,er(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=gt.fromBigInt(t).zzEncode();return this._push(Nr,r.length(),r)}sint64Number(t){let r=gt.fromNumber(t).zzEncode();return this._push(Nr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push($n,1,t?1:0)}fixed32(t){return this._push(rr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=gt.fromBigInt(t);return this._push(rr,4,r.lo)._push(rr,4,r.hi)}fixed64Number(t){let r=gt.fromNumber(t);return this._push(rr,4,r.lo)._push(rr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Gs,4,t)}double(t){return this._push(Ys,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push($n,1,0):this.uint32(r)._push(bf,r,t)}string(t){let r=$s(t);return r!==0?this.uint32(r)._push(Gn,r,t):this._push($n,1,0)}fork(){return this.states=new Jn(this),this.head=this.tail=new be(Xn,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new be(Xn,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=mf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function $n(e,t,r){t[r]=e&255}function yf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Qn=class extends be{next;constructor(t,r){super(yf,t,r),this.next=void 0}};function Nr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function rr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function bf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(nr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(xf,t,e),this},nr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(gf,t,e),this});function xf(e,t,r){t.set(e,r)}function gf(e,t,r){e.length<40?Gn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function to(){return new nr}function kr(e,t){let r=to();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var ke;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(ke||(ke={}));function Or(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function eo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Or("enum",ke.VARINT,r,n)}function Hr(e,t){return Or("message",ke.LENGTH_DELIMITED,e,t)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var ro;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ro||(ro={}));(function(e){e.codec=()=>eo(ro)})(j||(j={}));var Ut;(function(e){let t;e.codec=()=>(t==null&&(t=Hr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>kr(r,e.codec()),e.decode=(r,n)=>Pr(r,e.codec(),n)})(Ut||(Ut={}));var or;(function(e){let t;e.codec=()=>(t==null&&(t=Hr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>kr(r,e.codec()),e.decode=(r,n)=>Pr(r,e.codec(),n)})(or||(or={}));function no(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return Re(e)}var ir={};st(ir,{MAX_RSA_KEY_SIZE:()=>so,generateRSAKeyPair:()=>ho,jwkToJWKKeyPair:()=>ni,jwkToPkcs1:()=>Bf,jwkToPkix:()=>fo,jwkToRSAPrivateKey:()=>Vr,pkcs1MessageToJwk:()=>ao,pkcs1MessageToRSAPrivateKey:()=>Mr,pkcs1ToJwk:()=>Sf,pkcs1ToRSAPrivateKey:()=>uo,pkixMessageToJwk:()=>co,pkixMessageToRSAPublicKey:()=>qr,pkixToJwk:()=>vf,pkixToRSAPublicKey:()=>lo});var wf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),re=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ne=new Uint32Array(64),oo=class extends Gt{constructor(){super(64,32,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)ne[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=ne[l-15],E=ne[l-2],g=vt(d,7)^vt(d,18)^d>>>3,b=vt(E,17)^vt(E,19)^E>>>10;ne[l]=b+ne[l-7]+g+ne[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=vt(a,6)^vt(a,11)^vt(a,25),E=f+d+wr(a,c,u)+wf[l]+ne[l]|0,b=(vt(n,2)^vt(n,13)^vt(n,22))+Er(n,o,s)|0;f=u,u=c,c=a,a=i+E|0,i=s,s=o,o=n,n=E+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){ne.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var oe=Ue(()=>new oo);var Oe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=ir.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return wt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return ri(this.jwk,r,t)}},sr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ir.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return ei(this.jwk,t)}};var so=8192,io=18,Ef=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Sf(e){let t=xt(e);return ao(t)}function ao(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function Bf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new N("JWK was missing components");return Bt([ht(Uint8Array.from([0])),ht(G(e.n,"base64url")),ht(G(e.e,"base64url")),ht(G(e.d,"base64url")),ht(G(e.p,"base64url")),ht(G(e.q,"base64url")),ht(G(e.dp,"base64url")),ht(G(e.dq,"base64url")),ht(G(e.qi,"base64url"))]).subarray()}function vf(e){let t=xt(e,{offset:0});return co(t)}function co(e){let t=xt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function fo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return Bt([Af,Xe(Bt([ht(G(e.n,"base64url")),ht(G(e.e,"base64url"))]))]).subarray()}function uo(e){let t=xt(e);return Mr(t)}function Mr(e){let t=ao(e);return Vr(t)}function lo(e,t){if(e.byteLength>=Ef)throw new xe("Key size is too large");let r=xt(e,{offset:0});return qr(r,e,t)}function qr(e,t,r){let n=co(e);if(r==null){let o=oe(Ut.encode({Type:j.RSA,Data:t}));r=St(io,o)}return new Oe(n,r)}function Vr(e){if(si(e)>so)throw new N("Key size is too large");let t=ni(e),r=oe(Ut.encode({Type:j.RSA,Data:fo(t.publicKey)})),n=St(io,r);return new sr(t.privateKey,new Oe(t.publicKey,n))}async function ho(e){if(e>so)throw new N("Key size is too large");let t=await oi(e),r=oe(Ut.encode({Type:j.RSA,Data:fo(t.publicKey)})),n=St(io,r);return new sr(t.privateKey,new Oe(t.publicKey,n))}function ni(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ii="1.2.840.113549.1.1.1";async function oi(e){let t=await it.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await If(t);return{privateKey:r[0],publicKey:r[1]}}async function ei(e,t){let r=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await it.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ri(e,t,r){let n=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return it.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function If(e){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");return Promise.all([it.get().subtle.exportKey("jwk",e.privateKey),it.get().subtle.exportKey("jwk",e.publicKey)])}function si(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return G(e.n,"base64url").length*8}var zr=class extends Te{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,xr(t);let n=jt(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ce(this),this.iHash.update(t),this}digestInto(t){Ce(this),Ke(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ar=(e,t,r)=>new zr(e,t).update(r).digest();ar.create=(e,t)=>new zr(e,t);function ai(e){e.lowS!==void 0&&It("lowS",e.lowS),e.prehash!==void 0&&It("prehash",e.prehash)}function Lf(e){let t=Qe(e);_t(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:Kf,hexToBytes:Cf}=Ir,po=class extends Error{constructor(t=""){super(t)}},qt={Err:po,_tlv:{encode:(e,t)=>{let{Err:r}=qt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=ue(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ue(o.length/2|128):"";return ue(e)+s+o+t},decode(e,t){let{Err:r}=qt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=qt;if(e<Vt)throw new t("integer: negative integers are not allowed");let r=ue(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=qt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Kf(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=qt,o=typeof e=="string"?Cf(e):e;De(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=qt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Vt=BigInt(0),nt=BigInt(1),R0=BigInt(2),ci=BigInt(3),D0=BigInt(4);function Tf(e){let t=Lf(e),{Fp:r}=t,n=Jt(t.n,t.nBitLength),o=t.toBytes||((b,h,x)=>{let A=h.toAffine();return Mt(Uint8Array.from([4]),r.toBytes(A.x),r.toBytes(A.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),x=r.fromBytes(h.subarray(0,r.BYTES)),A=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x,y:A}});function i(b){let{a:h,b:x}=t,A=r.sqr(b),m=r.mul(A,b);return r.add(r.add(m,r.mul(b,h)),x)}if(!r.eql(r.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(b){return $e(b,nt,t.n)}function c(b){let{allowedPrivateKeyLengths:h,nByteLength:x,wrapPrivateKey:A,n:m}=t;if(h&&typeof b!="bigint"){if(Wt(b)&&(b=Ot(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(x*2,"0")}let v;try{v=typeof b=="bigint"?b:Ht(X("private key",b,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof b)}return A&&(v=z(v,m)),mt("private key",v,nt,m),v}function u(b){if(!(b instanceof d))throw new Error("ProjectivePoint expected")}let f=de((b,h)=>{let{px:x,py:A,pz:m}=b;if(r.eql(m,r.ONE))return{x,y:A};let v=b.is0();h==null&&(h=v?r.ONE:r.inv(m));let _=r.mul(x,h),T=r.mul(A,h),I=r.mul(m,h);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(I,r.ONE))throw new Error("invZ was invalid");return{x:_,y:T}}),l=de(b=>{if(b.is0()){if(t.allowInfinityPoint&&!r.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:x}=b.toAffine();if(!r.isValid(h)||!r.isValid(x))throw new Error("bad point: x or y not FE");let A=r.sqr(x),m=i(h);if(!r.eql(A,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,x,A){if(this.px=h,this.py=x,this.pz=A,h==null||!r.isValid(h))throw new Error("x required");if(x==null||!r.isValid(x))throw new Error("y required");if(A==null||!r.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x,y:A}=h||{};if(!h||!r.isValid(x)||!r.isValid(A))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let m=v=>r.eql(v,r.ZERO);return m(x)&&m(A)?d.ZERO:new d(x,A,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let x=r.invertBatch(h.map(A=>A.pz));return h.map((A,m)=>A.toAffine(x[m])).map(d.fromAffine)}static fromHex(h){let x=d.fromAffine(s(X("pointHex",h)));return x.assertValidity(),x}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,x){return Tr(d,n,h,x)}_setWindowSize(h){g.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:x,py:A,pz:m}=this,{px:v,py:_,pz:T}=h,I=r.eql(r.mul(x,T),r.mul(v,m)),C=r.eql(r.mul(A,T),r.mul(_,m));return I&&C}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:x}=t,A=r.mul(x,ci),{px:m,py:v,pz:_}=this,T=r.ZERO,I=r.ZERO,C=r.ZERO,L=r.mul(m,m),Z=r.mul(v,v),M=r.mul(_,_),O=r.mul(m,v);return O=r.add(O,O),C=r.mul(m,_),C=r.add(C,C),T=r.mul(h,C),I=r.mul(A,M),I=r.add(T,I),T=r.sub(Z,I),I=r.add(Z,I),I=r.mul(T,I),T=r.mul(O,T),C=r.mul(A,C),M=r.mul(h,M),O=r.sub(L,M),O=r.mul(h,O),O=r.add(O,C),C=r.add(L,L),L=r.add(C,L),L=r.add(L,M),L=r.mul(L,O),I=r.add(I,L),M=r.mul(v,_),M=r.add(M,M),L=r.mul(M,O),T=r.sub(T,L),C=r.mul(M,Z),C=r.add(C,C),C=r.add(C,C),new d(T,I,C)}add(h){u(h);let{px:x,py:A,pz:m}=this,{px:v,py:_,pz:T}=h,I=r.ZERO,C=r.ZERO,L=r.ZERO,Z=t.a,M=r.mul(t.b,ci),O=r.mul(x,v),J=r.mul(A,_),S=r.mul(m,T),K=r.add(x,A),y=r.add(v,_);K=r.mul(K,y),y=r.add(O,J),K=r.sub(K,y),y=r.add(x,m);let p=r.add(v,T);return y=r.mul(y,p),p=r.add(O,S),y=r.sub(y,p),p=r.add(A,m),I=r.add(_,T),p=r.mul(p,I),I=r.add(J,S),p=r.sub(p,I),L=r.mul(Z,y),I=r.mul(M,S),L=r.add(I,L),I=r.sub(J,L),L=r.add(J,L),C=r.mul(I,L),J=r.add(O,O),J=r.add(J,O),S=r.mul(Z,S),y=r.mul(M,y),J=r.add(J,S),S=r.sub(O,S),S=r.mul(Z,S),y=r.add(y,S),O=r.mul(J,y),C=r.add(C,O),O=r.mul(p,y),I=r.mul(K,I),I=r.sub(I,O),O=r.mul(K,J),L=r.mul(p,L),L=r.add(L,O),new d(I,C,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return g.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:x,n:A}=t;mt("scalar",h,Vt,A);let m=d.ZERO;if(h===Vt)return m;if(this.is0()||h===nt)return this;if(!x||g.hasPrecomputes(this))return g.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:v,k1:_,k2neg:T,k2:I}=x.splitScalar(h),C=m,L=m,Z=this;for(;_>Vt||I>Vt;)_&nt&&(C=C.add(Z)),I&nt&&(L=L.add(Z)),Z=Z.double(),_>>=nt,I>>=nt;return v&&(C=C.negate()),T&&(L=L.negate()),L=new d(r.mul(L.px,x.beta),L.py,L.pz),C.add(L)}multiply(h){let{endo:x,n:A}=t;mt("scalar",h,nt,A);let m,v;if(x){let{k1neg:_,k1:T,k2neg:I,k2:C}=x.splitScalar(h),{p:L,f:Z}=this.wNAF(T),{p:M,f:O}=this.wNAF(C);L=g.constTimeNegate(_,L),M=g.constTimeNegate(I,M),M=new d(r.mul(M.px,x.beta),M.py,M.pz),m=L.add(M),v=Z.add(O)}else{let{p:_,f:T}=this.wNAF(h);m=_,v=T}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(h,x,A){let m=d.BASE,v=(T,I)=>I===Vt||I===nt||!T.equals(m)?T.multiplyUnsafe(I):T.multiply(I),_=v(this,x).add(v(h,A));return _.is0()?void 0:_}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:x}=t;if(h===nt)return!0;if(x)return x(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:x}=t;return h===nt?this:x?x(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return It("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return It("isCompressed",h),Ot(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);let E=t.nBitLength,g=Cr(d,t.endo?Math.ceil(E/2):E);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function _f(e){let t=Qe(e);return _t(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function fi(e){let t=_f(e),{Fp:r,n}=t,o=r.BYTES+1,s=2*r.BYTES+1;function i(S){return z(S,n)}function a(S){return Lr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=Tf({...t,toBytes(S,K,y){let p=K.toAffine(),w=r.toBytes(p.x),B=Mt;return It("isCompressed",y),y?B(Uint8Array.from([K.hasEvenY()?2:3]),w):B(Uint8Array.from([4]),w,r.toBytes(p.y))},fromBytes(S){let K=S.length,y=S[0],p=S.subarray(1);if(K===o&&(y===2||y===3)){let w=Ht(p);if(!$e(w,nt,r.ORDER))throw new Error("Point is not on curve");let B=f(w),U;try{U=r.sqrt(B)}catch(H){let D=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+D)}let R=(U&nt)===nt;return(y&1)===1!==R&&(U=r.neg(U)),{x:w,y:U}}else if(K===s&&y===4){let w=r.fromBytes(p.subarray(0,r.BYTES)),B=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:w,y:B}}else{let w=o,B=s;throw new Error("invalid Point, expected length of "+w+", or uncompressed "+B+", got "+K)}}}),d=S=>Ot($t(S,t.nByteLength));function E(S){let K=n>>nt;return S>K}function g(S){return E(S)?i(-S):S}let b=(S,K,y)=>Ht(S.slice(K,y));class h{constructor(K,y,p){this.r=K,this.s=y,this.recovery=p,this.assertValidity()}static fromCompact(K){let y=t.nByteLength;return K=X("compactSignature",K,y*2),new h(b(K,0,y),b(K,y,2*y))}static fromDER(K){let{r:y,s:p}=qt.toSig(X("DER",K));return new h(y,p)}assertValidity(){mt("r",this.r,nt,n),mt("s",this.s,nt,n)}addRecoveryBit(K){return new h(this.r,this.s,K)}recoverPublicKey(K){let{r:y,s:p,recovery:w}=this,B=T(X("msgHash",K));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let U=w===2||w===3?y+t.n:y;if(U>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(w&1)===0?"02":"03",k=c.fromHex(R+d(U)),H=a(U),D=i(-B*H),q=i(p*H),F=c.BASE.multiplyAndAddUnsafe(k,D,q);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return le(this.toDERHex())}toDERHex(){return qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return le(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let x={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=kn(t.n);return vs(t.randomBytes(S),t.n)},precompute(S=8,K=c.BASE){return K._setWindowSize(S),K.multiply(BigInt(3)),K}};function A(S,K=!0){return c.fromPrivateKey(S).toRawBytes(K)}function m(S){let K=Wt(S),y=typeof S=="string",p=(K||y)&&S.length;return K?p===o||p===s:y?p===2*o||p===2*s:S instanceof c}function v(S,K,y=!0){if(m(S))throw new Error("first arg must be private key");if(!m(K))throw new Error("second arg must be public key");return c.fromHex(K).multiply(u(S)).toRawBytes(y)}let _=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let K=Ht(S),y=S.length*8-t.nBitLength;return y>0?K>>BigInt(y):K},T=t.bits2int_modN||function(S){return i(_(S))},I=Je(t.nBitLength);function C(S){return mt("num < 2^"+t.nBitLength,S,Vt,I),$t(S,t.nByteLength)}function L(S,K,y=Z){if(["recovered","canonical"].some(et=>et in y))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:w}=t,{lowS:B,prehash:U,extraEntropy:R}=y;B==null&&(B=!0),S=X("msgHash",S),ai(y),U&&(S=X("prehashed msgHash",p(S)));let k=T(S),H=u(K),D=[C(H),C(k)];if(R!=null&&R!==!1){let et=R===!0?w(r.BYTES):R;D.push(X("extraEntropy",et))}let q=Mt(...D),F=k;function tt(et){let ot=_(et);if(!l(ot))return;let at=a(ot),pt=c.BASE.multiply(ot).toAffine(),ut=i(pt.x);if(ut===Vt)return;let Ct=i(at*i(F+ut*H));if(Ct===Vt)return;let Rt=(pt.x===ut?0:2)|Number(pt.y&nt),He=Ct;return B&&E(Ct)&&(He=g(Ct),Rt^=1),new h(ut,He,Rt)}return{seed:q,k2sig:tt}}let Z={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function O(S,K,y=Z){let{seed:p,k2sig:w}=L(S,K,y),B=t;return Rn(B.hash.outputLen,B.nByteLength,B.hmac)(p,w)}c.BASE._setWindowSize(8);function J(S,K,y,p=M){let w=S;K=X("msgHash",K),y=X("publicKey",y);let{lowS:B,prehash:U,format:R}=p;if(ai(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let k=typeof w=="string"||Wt(w),H=!k&&!R&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!k&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let D,q;try{if(H&&(D=new h(w.r,w.s)),k){try{R!=="compact"&&(D=h.fromDER(w))}catch(Rt){if(!(Rt instanceof qt.Err))throw Rt}!D&&R!=="der"&&(D=h.fromCompact(w))}q=c.fromHex(y)}catch{return!1}if(!D||B&&D.hasHighS())return!1;U&&(K=t.hash(K));let{r:F,s:tt}=D,et=T(K),ot=a(tt),at=i(et*ot),pt=i(F*ot),ut=c.BASE.multiplyAndAddUnsafe(q,at,pt)?.toAffine();return ut?i(ut.x)===F:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:v,sign:O,verify:J,ProjectivePoint:c,Signature:h,utils:x}}function Uf(e){return{hash:e,hmac:(t,...r)=>ar(e,t,In(...r)),randomBytes:Re}}function ui(e,t){let r=n=>fi({...e,...Uf(n)});return{...r(t),create:r}}var di=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),li=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Rf=BigInt(1),mo=BigInt(2),hi=(e,t)=>(e+t/mo)/t;function Df(e){let t=di,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=W(f,r,t)*f%t,d=W(l,r,t)*f%t,E=W(d,mo,t)*u%t,g=W(E,o,t)*E%t,b=W(g,s,t)*g%t,h=W(b,a,t)*b%t,x=W(h,c,t)*h%t,A=W(x,a,t)*b%t,m=W(A,r,t)*f%t,v=W(m,i,t)*g%t,_=W(v,n,t)*u%t,T=W(_,mo,t);if(!yo.eql(yo.sqr(T),e))throw new Error("Cannot find square root");return T}var yo=Jt(di,void 0,void 0,{sqrt:Df}),At=ui({a:BigInt(0),b:BigInt(7),Fp:yo,n:li,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=li,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Rf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=hi(s*e,t),c=hi(-n*e,t),u=z(e-a*r-c*o,t),f=z(-a*n-c*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},oe),z0=BigInt(0);var F0=At.ProjectivePoint;function bo(e,t){let r=G(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Tt([new Uint8Array(t-r.length),r])}return r}function xo(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var pi=33,mi=32;function yi(e,t){let r=mr.digest(t instanceof Uint8Array?t:t.subarray());if(xo(r))return r.then(({digest:n})=>At.sign(n,e).toDERRawBytes()).catch(n=>{throw new Me(String(n))});try{return At.sign(r.digest,e).toDERRawBytes()}catch(n){throw new Me(String(n))}}function bi(e,t,r){let n=mr.digest(r instanceof Uint8Array?r:r.subarray());if(xo(n))return n.then(({digest:o})=>At.verify(t,o,e)).catch(o=>{throw new qe(String(o))});try{return At.verify(t,n.digest,e)}catch(o){throw new qe(String(o))}}var cr=class{type="secp256k1";raw;_key;constructor(t){this._key=wi(t),this.raw=xi(this._key)}toMultihash(){return ie.digest(ce(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r){return bi(this._key,r,t)}},fr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=gi(t),this.publicKey=new cr(r??Ei(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t){return yi(this.raw,t)}};function go(e){return new fr(e)}function Fr(e){return new cr(e)}async function Ai(){let e=Pf();return new fr(e)}function xi(e){return At.ProjectivePoint.fromHex(e).toRawBytes(!0)}function gi(e){try{return At.getPublicKey(e,!0),e}catch(t){throw new Ve(String(t))}}function wi(e){try{return At.ProjectivePoint.fromHex(e),e}catch(t){throw new xe(String(t))}}function Ei(e){try{return At.getPublicKey(e,!0)}catch(t){throw new Ve(String(t))}}function Pf(){return At.utils.randomPrivateKey()}var jr={"P-256":32,"P-384":48,"P-521":66},Nf=Object.keys(jr),wo=Nf.join(" / ");async function Si(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${wo}`);let t=await it.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await it.get().subtle.importKey("jwk",Of(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let c=await it.get().subtle.importKey("jwk",Bi(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await it.get().subtle.deriveBits({name:"ECDH",public:c},a,jr[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await it.get().subtle.exportKey("jwk",t.publicKey);return{key:kf(n),genSharedKey:r}}function kf(e){if(e.crv==null||e.x==null||e.y==null)throw new N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${wo}`);let t=jr[e.crv];return Tt([Uint8Array.from([4]),bo(e.x,t),bo(e.y,t)],1+t*2)}function Bi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${wo}`);let r=jr[e];if(!ct(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:V(t.subarray(1,r+1),"base64url"),y:V(t.subarray(1+r),"base64url"),ext:!0}}var Of=(e,t)=>({...Bi(e,t.public),d:V(t.private,"base64url")});var Hf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function vi(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=Hf[e],o=n.keySize,s=n.ivSize,i=20,a=G("key expansion"),c=2*(s+o+i),u=await Yr(t,r),f=await u.digest(a),l=[],d=0;for(;d<c;){let A=await u.digest(Tt([f,a])),m=A.length;d+m>c&&(m=c-d),l.push(A),d+=m,f=await u.digest(f)}let E=c/2,g=Tt(l),b=g.subarray(0,E),h=g.subarray(E,c),x=A=>({iv:A.subarray(0,s),cipherKey:A.subarray(s,s+o),macKey:A.subarray(s+o)});return{k1:x(b),k2:x(h)}}async function Mf(e,t){if(e==="Ed25519")return Os();if(e==="secp256k1")return Ai();if(e==="RSA")return ho(Yf(t));if(e==="ECDSA")return ps(Wf(t));throw new zt}async function qf(e,t){if(e!=="Ed25519")throw new zt("Seed key derivation only supported for Ed25519 keys");return Hs(t)}function Vf(e,t){let{Type:r,Data:n}=Ut.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return lo(o,t);case j.Ed25519:return Rr(o);case j.secp256k1:return Fr(o);case j.ECDSA:return Bn(o);default:throw new zt}}function zf(e){if(e.byteLength===Qt)return Rr(e);if(e.byteLength===pi)return Fr(e);let t=xt(e),r=t[1]?.[0];if(r===wn||r===En||r===An)return vn(t);if(t[0]?.[0]===ii)return qr(t,e);throw new N("Could not extract public key from raw bytes")}function Ff(e){let{Type:t,Data:r}=Ut.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Rr(n);case j.secp256k1:return Fr(n);case j.ECDSA:return Bn(n);default:throw new zt}}function ce(e){return Ut.encode({Type:j[e.type],Data:e.raw})}function jf(e){let t=or.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return uo(r);case j.Ed25519:return zn(r);case j.secp256k1:return go(r);case j.ECDSA:return us(r);default:throw new zt}}function Gf(e){if(e.byteLength===Et)return zn(e);if(e.byteLength===mi)return go(e);let t=xt(e),r=t[2]?.[0];if(r===wn||r===En||r===An)return Sn(t);if(t.length>8)return Mr(t);throw new N("Could not extract private key from raw bytes")}function Zf(e){return or.encode({Type:j[e.type],Data:e.raw})}function Yf(e){return e==null?2048:parseInt(e,10)}function Wf(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new N("Unsupported curve, should be P-256, P-384 or P-521")}async function Xf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new N("Only RSA and ECDSA keys are supported")}async function $f(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Vr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Nt(t)}throw new N("Only RSA and ECDSA keys are supported")}function Jf(e,t,r,n){xr(e);let o=bs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Le(s),Le(i),Le(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=jt(t),u=jt(r),f=new Uint8Array(i),l=ar.create(e,c),d=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function Qf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),o.fill(0),r}function Ii(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:c}=Jf(e,t,r,n),u,f=new Uint8Array(4),l=_e(f),d=new Uint8Array(a.outputLen);for(let E=1,g=0;g<s;E++,g+=a.outputLen){let b=i.subarray(g,g+a.outputLen);l.setInt32(0,E,!1),(u=c._cloneInto(u)).update(f).digestInto(d),b.set(d.subarray(0,b.length));for(let h=1;h<o;h++){a._cloneInto(u).update(d).digestInto(d);for(let x=0;x<b.length;x++)b[x]^=d[x]}}return Qf(a,c,i,u,d)}var ur=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),se=new Uint32Array(80),Ao=class extends Gt{constructor(){super(64,20,8,!1),this.A=ur[0]|0,this.B=ur[1]|0,this.C=ur[2]|0,this.D=ur[3]|0,this.E=ur[4]|0}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let c=0;c<16;c++,r+=4)se[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)se[c]=gr(se[c-3]^se[c-8]^se[c-14]^se[c-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let c=0;c<80;c++){let u,f;c<20?(u=wr(o,s,i),f=1518500249):c<40?(u=o^s^i,f=1859775393):c<60?(u=Er(o,s,i),f=2400959708):(u=o^s^i,f=3395469782);let l=gr(n,5)+u+a+f+se[c]|0;a=i,i=s,s=gr(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){se.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},Li=Ue(()=>new Ao);var Ki={sha1:Li,"sha2-256":oe,"sha2-512":Sr};function So(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Ki).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Ki[o],i=Ii(s,e,t,{c:r,dkLen:n});return un.encode(i).substring(1)}return qi(tu);})();
|
|
2
|
+
"use strict";var Libp2PCrypto=(()=>{var qr=Object.defineProperty;var Ki=Object.getOwnPropertyDescriptor;var Ci=Object.getOwnPropertyNames;var _i=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)qr(e,r,{get:t[r],enumerable:!0})},Ui=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ci(t))!_i.call(e,o)&&o!==r&&qr(e,o,{get:()=>t[o],enumerable:!(n=Ki(t,o))||n.enumerable});return e};var Ti=e=>Ui(qr({},"__esModule",{value:!0}),e);var Rf={};ct(Rf,{hmac:()=>lr,keys:()=>yo,pbkdf2:()=>xo,randomBytes:()=>Qn});var lr={};ct(lr,{create:()=>Vr});var Oe=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},He=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},ur=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var wo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new ur("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var it=wo;var Eo={SHA1:20,SHA256:32,SHA512:64};var Di={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},Pi=async(e,t)=>{let r=await it.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function Vr(e,t){let r=Di[e],n=await it.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return Pi(n,o)},length:Eo[e]}}var yo={};ct(yo,{generateEphemeralKeyPair:()=>gi,generateKeyPair:()=>Ef,generateKeyPairFromSeed:()=>Af,keyStretcher:()=>Ei,privateKeyFromCryptoKeyPair:()=>Tf,privateKeyFromProtobuf:()=>If,privateKeyFromRaw:()=>Lf,privateKeyToCryptoKeyPair:()=>Uf,privateKeyToProtobuf:()=>Kf,publicKeyFromMultihash:()=>vf,publicKeyFromProtobuf:()=>Sf,publicKeyFromRaw:()=>Bf,publicKeyToProtobuf:()=>se});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},me=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Me=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Vt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Gr={};ct(Gr,{base58btc:()=>nt,base58flickr:()=>Mi});var Zf=new Uint8Array(0);function Ao(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function So(e){return new TextEncoder().encode(e)}function Bo(e){return new TextDecoder().decode(e)}function Ri(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var y=0,h=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],U=0,L=m-1;(T!==0||U<h)&&L!==-1;L--,U++)T+=256*v[L]>>>0,v[L]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");h=U,b++}for(var K=m-h;K!==m&&v[K]===0;)K++;for(var C=c.repeat(y);K<m;++K)C+=e.charAt(v[K]);return C}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 h=0,b=0;g[y]===c;)h++,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,U=A-1;(v!==0||T<b)&&U!==-1;U--,T++)v+=a*m[U]>>>0,m[U]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");b=T,y++}if(g[y]!==" "){for(var L=A-b;L!==A&&m[L]===0;)L++;for(var K=new Uint8Array(h+(A-L)),C=h;L!==A;)K[C++]=m[L++];return K}}}function E(g){var y=d(g);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:E}}var Ni=Ri,ki=Ni,Io=ki;var zr=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")}},Fr=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 Lo(this,t)}},jr=class{decoders;constructor(t){this.decoders=t}or(t){return Lo(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 Lo(e,t){return new jr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Zr=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 zr(t,r,n),this.decoder=new Fr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ye({name:e,prefix:t,encode:r,decode:n}){return new Zr(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Io(r,e);return ye({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Oi(e,t,r,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),a=0,c=0,u=0;for(let f=0;f<s;++f){let l=o[e[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,a+=r,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=r||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return i}function Hi(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return ye({prefix:t,name:e,encode(o){return Hi(o,n,r)},decode(o){return Oi(o,n,r,e)}})}var nt=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Mi=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wr={};ct(Wr,{base32:()=>be,base32hex:()=>Fi,base32hexpad:()=>Zi,base32hexpadupper:()=>Gi,base32hexupper:()=>ji,base32pad:()=>Vi,base32padupper:()=>zi,base32upper:()=>qi,base32z:()=>Wi});var be=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qi=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vi=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zi=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Fi=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ji=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zi=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gi=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wi=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yr={};ct(Yr,{base36:()=>qe,base36upper:()=>Yi});var qe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yi=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xi=_o,Ko=128,$i=127,Ji=~$i,Qi=Math.pow(2,31);function _o(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Qi;)t[r++]=e&255|Ko,e/=128;for(;e&Ji;)t[r++]=e&255|Ko,e>>>=7;return t[r]=e|0,_o.bytes=r-n+1,t}var ta=Xr,ea=128,Co=127;function Xr(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Xr.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Co)<<o:(i&Co)*Math.pow(2,o),o+=7}while(i>=ea);return Xr.bytes=s-n,r}var ra=Math.pow(2,7),na=Math.pow(2,14),oa=Math.pow(2,21),sa=Math.pow(2,28),ia=Math.pow(2,35),aa=Math.pow(2,42),ca=Math.pow(2,49),fa=Math.pow(2,56),ua=Math.pow(2,63),la=function(e){return e<ra?1:e<na?2:e<oa?3:e<sa?4:e<ia?5:e<aa?6:e<ca?7:e<fa?8:e<ua?9:10},ha={encode:Xi,decode:ta,encodingLength:la},da=ha,Ve=da;function ze(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function xe(e,t,r=0){return Ve.encode(e,t,r),t}function ge(e){return Ve.encodingLength(e)}function vt(e,t){let r=t.byteLength,n=ge(e),o=n+ge(r),s=new Uint8Array(o+r);return xe(e,s,0),xe(r,s,n),s.set(t,o),new we(e,r,t,s)}function Uo(e){let t=Dt(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 we(r,o,i,t)}function To(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ao(e.bytes,r.bytes)}}var we=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Do(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return ma(r,$r(e),t??nt.encoder);default:return ya(r,$r(e),t??be.encoder)}}var Po=new WeakMap;function $r(e){let t=Po.get(e);if(t==null){let r=new Map;return Po.set(e,r),r}return t}var Et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ba)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=vt(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&&To(t.multihash,n.multihash)}toString(t){return Do(this,t)}toJSON(){return{"/":Do(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??Ro(n,o,s.bytes))}else if(r[xa]===!0){let{version:n,multihash:o,code:s}=r,i=Uo(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==je)throw new Error(`Version 0 CID must use dag-pb (code: ${je}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ro(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,je,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new we(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=ze(t.subarray(r));return r+=d,l},o=n(),s=je;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),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 $r(s).set(n,t),s}};function pa(e,t){switch(e[0]){case"Q":{let r=t??nt;return[nt.prefix,r.decode(`${nt.prefix}${e}`)]}case nt.prefix:{let r=t??nt;return[nt.prefix,r.decode(e)]}case be.prefix:{let r=t??be;return[be.prefix,r.decode(e)]}case qe.prefix:{let r=t??qe;return[qe.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 ma(e,t,r){let{prefix:n}=r;if(n!==nt.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 ya(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var je=112,ba=18;function Ro(e,t,r){let n=ge(e),o=n+ge(t),s=new Uint8Array(o+r.byteLength);return xe(e,s,0),xe(t,s,n),s.set(r,o),s}var xa=Symbol.for("@ipld/js-cid/CID");var Jr={};ct(Jr,{identity:()=>ne});var No=0,ga="identity",ko=Dt;function wa(e){return vt(No,ko(e))}var ne={code:No,name:ga,encode:ko,digest:wa};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 Pt(e=0){return new Uint8Array(e)}function bt(e=0){return new Uint8Array(e)}function Ct(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ho=Symbol.for("@achingbrain/uint8arraylist");function Oo(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 dr(e){return!!e?.[Ho]}var lt=class e{bufs;length;[Ho]=!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(dr(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(dr(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=Oo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Oo(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(dr(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],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!dr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let E=this.get(l+d);if(n[d]!==E){f=Math.max(1,d-a[E]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!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 Qr={};ct(Qr,{base10:()=>Ea});var Ea=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var tn={};ct(tn,{base16:()=>Aa,base16upper:()=>Sa});var Aa=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Sa=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var en={};ct(en,{base2:()=>Ba});var Ba=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rn={};ct(rn,{base256emoji:()=>Ca});var Mo=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}"),va=Mo.reduce((e,t,r)=>(e[r]=t,e),[]),Ia=Mo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function La(e){return e.reduce((t,r)=>(t+=va[r],t),"")}function Ka(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ia[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ca=ye({prefix:"\u{1F680}",name:"base256emoji",encode:La,decode:Ka});var on={};ct(on,{base64:()=>nn,base64pad:()=>_a,base64url:()=>Ua,base64urlpad:()=>Ta});var nn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_a=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ua=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ta=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var sn={};ct(sn,{base8:()=>Da});var Da=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var an={};ct(an,{identity:()=>Pa});var Pa=ye({prefix:"\0",name:"identity",encode:e=>Bo(e),decode:e=>So(e)});var Cu=new TextEncoder,_u=new TextDecoder;var un={};ct(un,{sha256:()=>pr,sha512:()=>ka});function fn({name:e,code:t,encode:r}){return new cn(e,t,r)}var cn=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?vt(this.code,r):r.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Vo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var pr=fn({name:"sha2-256",code:18,encode:Vo("SHA-256")}),ka=fn({name:"sha2-512",code:19,encode:Vo("SHA-512")});var ln={...an,...en,...sn,...Qr,...tn,...Wr,...Yr,...Gr,...on,...rn},Vu={...un,...Jr};function Fo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var zo=Fo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),hn=Fo("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Oa={utf8:zo,"utf-8":zo,hex:ln.base16,latin1:hn,ascii:hn,binary:hn,...ln},mr=Oa;function G(e,t="utf8"){let r=mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=mr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ha=parseInt("11111",2),dn=parseInt("10000000",2),Ma=parseInt("01111111",2),jo={0:Ze,1:Ze,2:qa,3:Fa,4:ja,5:za,6:Va,16:Ze,22:Ze,48:Ze};function xt(e,t={offset:0}){let r=e[t.offset]&Ha;if(t.offset++,jo[r]!=null)return jo[r](e,t);throw new Error("No decoder for tag "+r)}function Ge(e,t){let r=0;if((e[t.offset]&dn)===dn){let n=e[t.offset]&Ma,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 Ze(e,t){Ge(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=xt(e,t);if(n===null)break;r.push(n)}return r}function qa(e,t){let r=Ge(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 Va(e,t){let r=Ge(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function za(e,t){return t.offset++,null}function Fa(e,t){let r=Ge(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 ja(e,t){let r=Ge(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Za(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function yr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Za(e.byteLength);return new lt(Uint8Array.from([t.byteLength|dn]),t)}function ht(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),yr(t),t)}function We(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),yr(r),r)}function Zo(e){return new lt(Uint8Array.from([4]),yr(e),e)}function It(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),yr(r),r)}var pn="1.2.840.10045.3.1.7",mn="1.3.132.0.34",yn="1.3.132.0.35";async function Go(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 Wo(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 Yo(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 Ga=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Wa=Uint8Array.from([6,5,43,129,4,0,34]),Ya=Uint8Array.from([6,5,43,129,4,0,35]),Xo={ext:!0,kty:"EC",crv:"P-256"},$o={ext:!0,kty:"EC",crv:"P-384"},Jo={ext:!0,kty:"EC",crv:"P-521"},Ee=32,Ae=48,Se=66;function Qo(e){let t=xt(e);return bn(t)}function bn(e){let t=e[1],r=z(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Ee)return s=z(n.subarray(o,o+Ee),"base64url"),i=z(n.subarray(o+Ee),"base64url"),new Rt({...Xo,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ae)return s=z(n.subarray(o,o+Ae),"base64url"),i=z(n.subarray(o+Ae),"base64url"),new Rt({...$o,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Se)return s=z(n.subarray(o,o+Se),"base64url"),i=z(n.subarray(o+Se),"base64url"),new Rt({...Jo,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function xn(e){let t=xt(e);return gn(t)}function gn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ee*2+1)return n=z(t.subarray(r,r+Ee),"base64url"),o=z(t.subarray(r+Ee),"base64url"),new oe({...Xo,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ae*2+1)return n=z(t.subarray(r,r+Ae),"base64url"),o=z(t.subarray(r+Ae),"base64url"),new oe({...$o,key_ops:["verify"],x:n,y:o});if(t.byteLength===Se*2+1)return n=z(t.subarray(r,r+Se),"base64url"),o=z(t.subarray(r+Se),"base64url"),new oe({...Jo,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ts(e){return It([ht(Uint8Array.from([1])),Zo(G(e.d??"","base64url")),It([rs(e.crv)],160),It([We(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function es(e){return It([ht(Uint8Array.from([1])),It([rs(e.crv)],160),It([We(new lt(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function rs(e){if(e==="P-256")return Ga;if(e==="P-384")return Wa;if(e==="P-521")return Ya;throw new N(`Invalid curve ${e}`)}async function ns(e="P-256"){let t=await Go(e);return new Rt(t.privateKey)}var oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=es(this.jwk)),this._raw}toMultihash(){return ne.digest(se(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return nt.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 Yo(this.jwk,r,t)}},Rt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new oe({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=ts(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async sign(t){return Wo(this.jwk,t)}};function Be(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Xa(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ve(e,...t){if(!Xa(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 br(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Be(e.outputLen),Be(e.blockLen)}function Ie(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 os(e,t){ve(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var ie=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ke(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}function xr(e,t){return e<<t|e>>>32-t>>>0}var wl=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function ss(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function Ft(e){return typeof e=="string"&&(e=ss(e)),ve(e),e}function wn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ve(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 Le=class{clone(){return this._cloneInto()}};function is(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function Ce(e){let t=n=>e().update(Ft(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function _e(e=32){if(ie&&typeof ie.getRandomValues=="function")return ie.getRandomValues(new Uint8Array(e));if(ie&&typeof ie.randomBytes=="function")return Uint8Array.from(ie.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function $a(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 gr(e,t,r){return e&t^~e&r}function wr(e,t,r){return e&t^e&r^t&r}var jt=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=Ke(this.buffer)}update(t){Ie(this);let{view:r,buffer:n,blockLen:o}=this;t=Ft(t);let s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ke(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){Ie(this),os(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;$a(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ke(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.length=o,t.pos=a,t.finished=s,t.destroyed=i,o%r&&t.buffer.set(n),t}};var Ja=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gt=new Uint32Array(64),En=class extends jt{constructor(t=32){super(64,t,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Gt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Gt[l-15],E=Gt[l-2],g=Lt(d,7)^Lt(d,18)^d>>>3,y=Lt(E,17)^Lt(E,19)^E>>>10;Gt[l]=y+Gt[l-7]+g+Gt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Lt(a,6)^Lt(a,11)^Lt(a,25),E=f+d+gr(a,c,u)+Ja[l]+Gt[l]|0,y=(Lt(n,2)^Lt(n,13)^Lt(n,22))+wr(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(){Gt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Nt=Ce(()=>new En);var Er=BigInt(4294967295),An=BigInt(32);function as(e,t=!1){return t?{h:Number(e&Er),l:Number(e>>An&Er)}:{h:Number(e>>An&Er)|0,l:Number(e&Er)|0}}function Qa(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:s,l:i}=as(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}var tc=(e,t)=>BigInt(e>>>0)<<An|BigInt(t>>>0),ec=(e,t,r)=>e>>>r,rc=(e,t,r)=>e<<32-r|t>>>r,nc=(e,t,r)=>e>>>r|t<<32-r,oc=(e,t,r)=>e<<32-r|t>>>r,sc=(e,t,r)=>e<<64-r|t>>>r-32,ic=(e,t,r)=>e>>>r-32|t<<64-r,ac=(e,t)=>t,cc=(e,t)=>e,fc=(e,t,r)=>e<<r|t>>>32-r,uc=(e,t,r)=>t<<r|e>>>32-r,lc=(e,t,r)=>t<<r-32|e>>>64-r,hc=(e,t,r)=>e<<r-32|t>>>64-r;function dc(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var pc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),mc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,yc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),bc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,xc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),gc=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var wc={fromBig:as,split:Qa,toBig:tc,shrSH:ec,shrSL:rc,rotrSH:nc,rotrSL:oc,rotrBH:sc,rotrBL:ic,rotr32H:ac,rotr32L:cc,rotlSH:fc,rotlSL:uc,rotlBH:lc,rotlBL:hc,add:dc,add3L:pc,add3H:mc,add4L:yc,add4H:bc,add5H:gc,add5L:xc},P=wc;var[Ec,Ac]=P.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Wt=new Uint32Array(80),Yt=new Uint32Array(80),Sn=class extends jt{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:E,Gl:g,Hh:y,Hl:h}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,E,g,y,h]}set(t,r,n,o,s,i,a,c,u,f,l,d,E,g,y,h){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=y|0,this.Hl=h|0}process(t,r){for(let m=0;m<16;m++,r+=4)Wt[m]=t.getUint32(r),Yt[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let v=Wt[m-15]|0,T=Yt[m-15]|0,U=P.rotrSH(v,T,1)^P.rotrSH(v,T,8)^P.shrSH(v,T,7),L=P.rotrSL(v,T,1)^P.rotrSL(v,T,8)^P.shrSL(v,T,7),K=Wt[m-2]|0,C=Yt[m-2]|0,j=P.rotrSH(K,C,19)^P.rotrBH(K,C,61)^P.shrSH(K,C,6),q=P.rotrSL(K,C,19)^P.rotrBL(K,C,61)^P.shrSL(K,C,6),k=P.add4L(L,q,Yt[m-7],Yt[m-16]),tt=P.add4H(k,U,j,Wt[m-7],Wt[m-16]);Wt[m]=tt|0,Yt[m]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:E,Fl:g,Gh:y,Gl:h,Hh:b,Hl:A}=this;for(let m=0;m<80;m++){let v=P.rotrSH(l,d,14)^P.rotrSH(l,d,18)^P.rotrBH(l,d,41),T=P.rotrSL(l,d,14)^P.rotrSL(l,d,18)^P.rotrBL(l,d,41),U=l&E^~l&y,L=d&g^~d&h,K=P.add5L(A,T,L,Ac[m],Yt[m]),C=P.add5H(K,b,v,U,Ec[m],Wt[m]),j=K|0,q=P.rotrSH(n,o,28)^P.rotrBH(n,o,34)^P.rotrBH(n,o,39),k=P.rotrSL(n,o,28)^P.rotrBL(n,o,34)^P.rotrBL(n,o,39),tt=n&s^n&a^s&a,S=o&i^o&c^i&c;b=y|0,A=h|0,y=E|0,h=g|0,E=l|0,g=d|0,{h:l,l:d}=P.add(u|0,f|0,C|0,j|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=P.add3L(j,k,S);n=P.add3H(I,C,q,tt),o=I|0}({h:n,l:o}=P.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=P.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=P.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=P.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=P.add(this.Eh|0,this.El|0,l|0,d|0),{h:E,l:g}=P.add(this.Fh|0,this.Fl|0,E|0,g|0),{h:y,l:h}=P.add(this.Gh|0,this.Gl|0,y|0,h|0),{h:b,l:A}=P.add(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,f,l,d,E,g,y,h,b,A)}roundClean(){Wt.fill(0),Yt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ye=Ce(()=>new Sn);var Ln=BigInt(0),In=BigInt(1);function ae(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Kn(e){if(!ae(e))throw new Error("Uint8Array expected")}function _t(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Xe(e){let t=e.toString(16);return t.length&1?"0"+t:t}function us(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Ln:BigInt("0x"+e)}var ls=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Sc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Xt(e){if(Kn(e),ls)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Sc[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function cs(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function $e(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=cs(e.charCodeAt(s)),a=cs(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 Ot(e){return us(Xt(e))}function ce(e){return Kn(e),us(Xt(Uint8Array.from(e).reverse()))}function fe(e,t){return $e(e.toString(16).padStart(t*2,"0"))}function Ue(e,t){return fe(e,t).reverse()}function X(e,t,r){let n;if(typeof t=="string")try{n=$e(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(ae(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 $t(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Kn(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 Bn=e=>typeof e=="bigint"&&Ln<=e;function Ar(e,t,r){return Bn(e)&&Bn(t)&&Bn(r)&&t<=e&&e<r}function gt(e,t,r,n){if(!Ar(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function hs(e){let t;for(t=0;e>Ln;e>>=In,t+=1);return t}var ue=e=>(In<<BigInt(e))-In,vn=e=>new Uint8Array(e),fs=e=>Uint8Array.from(e);function ds(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=vn(e),o=vn(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},a=(...l)=>r(o,n,...l),c=(l=vn(0))=>{o=a(fs([0]),l),n=a(),l.length!==0&&(o=a(fs([1]),l),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let E=n.slice();d.push(E),l+=n.length}return $t(...d)};return(l,d)=>{i(),c(l);let E;for(;!(E=d(u()));)c();return i(),E}}var Bc={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"||ae(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 Ht(e,t,r={}){let n=(o,s,i)=>{let a=Bc[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 Te(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 et=BigInt(0),W=BigInt(1),le=BigInt(2),vc=BigInt(3),Cn=BigInt(4),ps=BigInt(5),ms=BigInt(8),Ic=BigInt(9),Lc=BigInt(16);function F(e,t){let r=e%t;return r>=et?r:t+r}function Kc(e,t,r){if(t<et)throw new Error("invalid exponent, negatives unsupported");if(r<=et)throw new Error("invalid modulus");if(r===W)return et;let n=W;for(;t>et;)t&W&&(n=n*e%r),e=e*e%r,t>>=W;return n}function Y(e,t,r){let n=e;for(;t-- >et;)n*=n,n%=r;return n}function Sr(e,t){if(e===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let r=F(e,t),n=t,o=et,s=W,i=W,a=et;for(;r!==et;){let u=n/r,f=n%r,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==W)throw new Error("invert: does not exist");return F(o,t)}function Cc(e){let t=(e-W)/le,r,n,o;for(r=e-W,n=0;r%le===et;r/=le,n++);for(o=le;o<e&&Kc(o,t,e)!==e-W;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(e+W)/Cn;return function(c,u){let f=c.pow(u,i);if(!c.eql(c.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(r+W)/le;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,f=a.pow(a.mul(a.ONE,o),r),l=a.pow(c,s),d=a.pow(c,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let E=1;for(let y=a.sqr(d);E<u&&!a.eql(y,a.ONE);E++)y=a.sqr(y);let g=a.pow(f,W<<BigInt(u-E-1));f=a.sqr(g),l=a.mul(l,g),d=a.mul(d,f),u=E}return l}}function _c(e){if(e%Cn===vc){let t=(e+W)/Cn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(e%ms===ps){let t=(e-ps)/ms;return function(n,o){let s=n.mul(o,le),i=n.pow(s,t),a=n.mul(o,i),c=n.mul(n.mul(a,le),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return e%Lc,Cc(e)}var ys=(e,t)=>(F(e,t)&W)===W,Uc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _n(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Uc.reduce((n,o)=>(n[o]="function",n),t);return Ht(e,r)}function Tc(e,t,r){if(r<et)throw new Error("invalid exponent, negatives unsupported");if(r===et)return e.ONE;if(r===W)return t;let n=e.ONE,o=t;for(;r>et;)r&W&&(n=e.mul(n,o)),o=e.sqr(o),r>>=W;return n}function Dc(e,t){let r=new Array(t.length),n=t.reduce((s,i,a)=>e.is0(i)?s:(r[a]=s,e.mul(s,i)),e.ONE),o=e.inv(n);return t.reduceRight((s,i,a)=>e.is0(i)?s:(r[a]=e.mul(s,r[a]),e.mul(s,i)),o),r}function Un(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Jt(e,t,r=!1,n={}){if(e<=et)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:s}=Un(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:ue(o),ZERO:et,ONE:W,create:c=>F(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return et<=c&&c<e},is0:c=>c===et,isOdd:c=>(c&W)===W,neg:c=>F(-c,e),eql:(c,u)=>c===u,sqr:c=>F(c*c,e),add:(c,u)=>F(c+u,e),sub:(c,u)=>F(c-u,e),mul:(c,u)=>F(c*u,e),pow:(c,u)=>Tc(a,c,u),div:(c,u)=>F(c*Sr(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Sr(c,e),sqrt:n.sqrt||(c=>(i||(i=_c(e)),i(a,c))),invertBatch:c=>Dc(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>r?Ue(c,s):fe(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?ce(c):Ot(c)}});return Object.freeze(a)}function bs(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Tn(e){let t=bs(e);return t+Math.ceil(t/2)}function xs(e,t,r=!1){let n=e.length,o=bs(t),s=Tn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ce(e):Ot(e),a=F(i,t-W)+W;return r?Ue(a,o):fe(a,o)}var gs=BigInt(0),kn=BigInt(1);function Dn(e,t){let r=t.negate();return e?r:t}function Es(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Pn(e,t){Es(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ue(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ws(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+=kn);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,E=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:E,offsetF:u}}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 Rc(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 Rn=new WeakMap,As=new WeakMap;function Nn(e){return As.get(e)||1}function Br(e,t){return{constTimeNegate:Dn,hasPrecomputes(r){return Nn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>gs;)n&kn&&(o=o.add(s)),s=s.double(),n>>=kn;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Pn(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=Pn(r,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:d,isNegF:E,offsetF:g}=ws(o,c,a);o=u,l?i=i.add(Dn(E,n[g])):s=s.add(Dn(d,n[f]))}return{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Pn(r,t);for(let a=0;a<i.windows&&o!==gs;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=ws(o,a,i);if(o=c,!f){let d=n[u];s=s.add(l?d.negate():d)}}return s},getPrecomputes(r,n,o){let s=Rn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Rn.set(n,o(s))),s},wNAFCached(r,n,o){let s=Nn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Nn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Es(n,t),As.set(r,n),Rn.delete(r)}}}function vr(e,t,r,n){if(Pc(r,e),Rc(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,s=hs(BigInt(r.length)),i=s>12?s-3:s>4?s-2:s?2:1,a=ue(i),c=new Array(Number(a)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let l=u;l>=0;l-=i){c.fill(o);for(let E=0;E<n.length;E++){let g=n[E],y=Number(g>>BigInt(l)&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),l!==0)for(let E=0;E<i;E++)f=f.double()}return f}function Je(e){return _n(e.Fp),Ht(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Un(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Ut=BigInt(0),dt=BigInt(1),Ss=BigInt(2),Nc=BigInt(8),kc={zip215:!0};function Oc(e){let t=Je(e);return Ht(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Bs(e){let t=Oc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:a,h:c}=t,u=Ss<<BigInt(a*8)-dt,f=r.create,l=Jt(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:Ut}}}),E=t.adjustScalarBytes||(x=>x),g=t.domain||((x,p,w)=>{if(_t("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:Ut;gt("coordinate "+x,p,B,u)}function h(x){if(!(x instanceof m))throw new Error("ExtendedPoint expected")}let b=Te((x,p)=>{let{ex:w,ey:B,ez:D}=x,R=x.is0();p==null&&(p=R?Nc:r.inv(D));let O=f(w*p),H=f(B*p),M=f(D*p);if(R)return{x:Ut,y:dt};if(M!==dt)throw new Error("invZ was invalid");return{x:O,y:H}}),A=Te(x=>{let{a:p,d:w}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:B,ey:D,ez:R,et:O}=x,H=f(B*B),M=f(D*D),V=f(R*R),Q=f(V*V),J=f(H*p),st=f(V*f(J+M)),mt=f(Q+f(w*f(H*M)));if(st!==mt)throw new Error("bad point: equation left != right (1)");let rt=f(B*D),at=f(R*O);if(rt!==at)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=r.invertBatch(p.map(B=>B.ez));return p.map((B,D)=>B.toAffine(w[D])).map(m.fromAffine)}static msm(p,w){return vr(m,l,p,w)}_setWindowSize(p){U.setWindowSize(this,p)}assertValidity(){A(this)}equals(p){h(p);let{ex:w,ey:B,ez:D}=this,{ex:R,ey:O,ez:H}=p,M=f(w*H),V=f(R*D),Q=f(B*H),J=f(O*D);return M===V&&Q===J}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),O=f(B*B),H=f(Ss*f(D*D)),M=f(p*R),V=w+B,Q=f(f(V*V)-R-O),J=M+O,st=J-H,mt=M-O,rt=f(Q*st),at=f(J*mt),yt=f(Q*mt),Bt=f(st*J);return new m(rt,at,Bt,yt)}add(p){h(p);let{a:w,d:B}=t,{ex:D,ey:R,ez:O,et:H}=this,{ex:M,ey:V,ez:Q,et:J}=p,st=f(D*M),mt=f(R*V),rt=f(H*B*J),at=f(O*Q),yt=f((D+R)*(M+V)-st-mt),Bt=at-rt,ke=at+rt,go=f(mt-w*st),Bi=f(yt*Bt),vi=f(ke*go),Ii=f(yt*go),Li=f(Bt*ke);return new m(Bi,vi,Li,Ii)}subtract(p){return this.add(p.negate())}wNAF(p){return U.wNAFCached(this,p,m.normalizeZ)}multiply(p){let w=p;gt("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 gt("scalar",B,Ut,n),B===Ut?T:this.is0()||B===dt?this:U.wNAFCachedUnsafe(this,B,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.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=X("pointHex",p,R),_t("zip215",w);let O=p.slice(),H=p[R-1];O[R-1]=H&-129;let M=ce(O),V=w?u:r.ORDER;gt("pointHex.y",M,Ut,V);let Q=f(M*M),J=f(Q-dt),st=f(B*Q-D),{isValid:mt,value:rt}=d(J,st);if(!mt)throw new Error("Point.fromHex: invalid y coordinate");let at=(rt&dt)===dt,yt=(H&128)!==0;if(!w&&rt===Ut&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==at&&(rt=f(-rt)),m.fromAffine({x:rt,y:M})}static fromPrivateKey(p){let{scalar:w}=C(p);return v.multiply(w)}toRawBytes(){let{x:p,y:w}=this.toAffine(),B=Ue(w,r.BYTES);return B[B.length-1]|=p&dt?128:0,B}toHex(){return Xt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,dt,f(t.Gx*t.Gy)),m.ZERO=new m(Ut,dt,dt,Ut);let{BASE:v,ZERO:T}=m,U=Br(m,a*8);function L(x){return F(x,n)}function K(x){return L(ce(x))}function C(x){let p=r.BYTES;x=X("private key",x,p);let w=X("hashed private key",s(x),2*p),B=E(w.slice(0,p)),D=w.slice(p,2*p),R=K(B);return{head:B,prefix:D,scalar:R}}function j(x){let{head:p,prefix:w,scalar:B}=C(x),D=v.multiply(B),R=D.toRawBytes();return{head:p,prefix:w,scalar:B,point:D,pointBytes:R}}function q(x){return j(x).pointBytes}function k(x=new Uint8Array,...p){let w=$t(...p);return K(s(g(w,X("context",x),!!o)))}function tt(x,p,w={}){x=X("message",x),o&&(x=o(x));let{prefix:B,scalar:D,pointBytes:R}=j(p),O=k(w.context,B,x),H=v.multiply(O).toRawBytes(),M=k(w.context,H,R,x),V=L(O+M*D);gt("signature.s",V,Ut,n);let Q=$t(H,Ue(V,r.BYTES));return X("result",Q,r.BYTES*2)}let S=kc;function I(x,p,w,B=S){let{context:D,zip215:R}=B,O=r.BYTES;x=X("signature",x,2*O),p=X("message",p),w=X("publicKey",w,O),R!==void 0&&_t("zip215",R),o&&(p=o(p));let H=ce(x.slice(O,2*O)),M,V,Q;try{M=m.fromHex(w,R),V=m.fromHex(x.slice(0,O),R),Q=v.multiplyUnsafe(H)}catch{return!1}if(!R&&M.isSmallOrder())return!1;let J=k(D,V.toRawBytes(),M.toRawBytes(),p);return V.add(M.multiplyUnsafe(J)).subtract(Q).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:q,sign:tt,verify:I,ExtendedPoint:m,utils:{getExtendedPublicKey:j,randomPrivateKey:()=>i(r.BYTES),precompute(x=8,p=m.BASE){return p._setWindowSize(x),p.multiply(BigInt(3)),p}}}}var On=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),vs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),eh=BigInt(0),Hc=BigInt(1),Is=BigInt(2),rh=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=On,a=e*e%s*e%s,c=Y(a,Is,s)*a%s,u=Y(c,Hc,s)*e%s,f=Y(u,Mc,s)*u%s,l=Y(f,t,s)*f%s,d=Y(l,r,s)*l%s,E=Y(d,n,s)*d%s,g=Y(E,o,s)*E%s,y=Y(g,o,s)*E%s,h=Y(y,t,s)*f%s;return{pow_p_5_8:Y(h,Is,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=On,n=F(t*t*t,r),o=F(n*n*t,r),s=Vc(e*o).pow_p_5_8,i=F(e*n*s,r),a=F(t*i*i,r),c=i,u=F(i*vs,r),f=a===e,l=a===F(-e,r),d=a===F(-e*vs,r);return f&&(i=c),(l||d)&&(i=u),ys(i,r)&&(i=F(-i,r)),{isValid:f||l,value:i}}var Ls=Jt(On,void 0,!0),jc={a:Ls.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ls,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:qc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ye,randomBytes:_e,adjustScalarBytes:zc,uvRatio:Fc},De=Bs(jc);var Qt=32,At=64,Ir=32;function Ks(){let e=De.utils.randomPrivateKey(),t=De.getPublicKey(e);return{privateKey:Ts(e,t),publicKey:t}}function Cs(e){if(e.length!==Ir)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=De.getPublicKey(t);return{privateKey:Ts(t,r),publicKey:r}}function _s(e,t){let r=e.subarray(0,Ir);return De.sign(t instanceof Uint8Array?t:t.subarray(),r)}function Us(e,t,r){return De.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}function Ts(e,t){let r=new Uint8Array(At);for(let n=0;n<Ir;n++)r[n]=e[n],r[Ir+n]=t[n];return r}var Qe=class{type="Ed25519";raw;constructor(t){this.raw=Pe(t,Qt)}toMultihash(){return ne.digest(se(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return nt.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 Us(this.raw,r,t)}},he=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Pe(t,At),this.publicKey=new Qe(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return _s(this.raw,t)}};function Hn(e){if(e.length>At){e=Pe(e,At+Qt);let n=e.subarray(0,At),o=e.subarray(At,e.length);return new he(n,o)}e=Pe(e,At);let t=e.subarray(0,At),r=e.subarray(Qt);return new he(t,r)}function Lr(e){return e=Pe(e,Qt),new Qe(e)}async function Ps(){let{privateKey:e,publicKey:t}=Ks();return new he(e,t)}async function Rs(e){let{privateKey:t,publicKey:r}=Cs(e);return new he(t,r)}function Pe(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Zc=Math.pow(2,7),Gc=Math.pow(2,14),Wc=Math.pow(2,21),Ns=Math.pow(2,28),ks=Math.pow(2,35),Os=Math.pow(2,42),Hs=Math.pow(2,49),pt=128,te=127;function tr(e){if(e<Zc)return 1;if(e<Gc)return 2;if(e<Wc)return 3;if(e<Ns)return 4;if(e<ks)return 5;if(e<Os)return 6;if(e<Hs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ms(e,t,r=0){switch(tr(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 qs(e,t){let r=e[t],n=0;if(n+=r&te,r<pt||(r=e[t+1],n+=(r&te)<<7,r<pt)||(r=e[t+2],n+=(r&te)<<14,r<pt)||(r=e[t+3],n+=(r&te)<<21,r<pt)||(r=e[t+4],n+=(r&te)*Ns,r<pt)||(r=e[t+5],n+=(r&te)*ks,r<pt)||(r=e[t+6],n+=(r&te)*Os,r<pt)||(r=e[t+7],n+=(r&te)*Hs,r<pt))return n;throw new RangeError("Could not decode varint")}var Mn=new Float32Array([-0]),ee=new Uint8Array(Mn.buffer);function Vs(e,t,r){Mn[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function zs(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Mn[0]}var qn=new Float64Array([-0]),ut=new Uint8Array(qn.buffer);function Fs(e,t,r){qn[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 js(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],qn[0]}var Yc=BigInt(Number.MAX_SAFE_INTEGER),Xc=BigInt(Number.MIN_SAFE_INTEGER),wt=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 de;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>Zs&&(o=0n,++n>Zs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;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):de}},de=new wt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var Zs=4294967296n;function Gs(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 Ws(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 Vn(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 Kr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var zn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Kr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Kr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=zs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=js(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 Ws(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 wt(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=Kr(this.buf,this.pos+=4),r=Kr(this.buf,this.pos+=4);return new wt(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=qs(this.buf,this.pos);return this.pos+=tr(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 Fn(e){return new zn(e instanceof Uint8Array?e:e.subarray())}function Cr(e,t,r){let n=Fn(e);return t.decode(n,void 0,r)}function jn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return bt(i);o+i>t&&(n=bt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Zn(){}var Wn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$c=jn();function Jc(e){return globalThis.Buffer!=null?bt(e):$c(e)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(Zn,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new pe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Yn((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(_r,10,wt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=wt.fromBigInt(t);return this._push(_r,r.length(),r)}uint64Number(t){return this._push(Ms,tr(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=wt.fromBigInt(t).zzEncode();return this._push(_r,r.length(),r)}sint64Number(t){let r=wt.fromNumber(t).zzEncode();return this._push(_r,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Gn,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=wt.fromBigInt(t);return this._push(er,4,r.lo)._push(er,4,r.hi)}fixed64Number(t){let r=wt.fromNumber(t);return this._push(er,4,r.lo)._push(er,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(Vs,4,t)}double(t){return this._push(Fs,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Gn,1,0):this.uint32(r)._push(tf,r,t)}string(t){let r=Gs(t);return r!==0?this.uint32(r)._push(Vn,r,t):this._push(Gn,1,0)}fork(){return this.states=new Wn(this),this.head=this.tail=new pe(Zn,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 pe(Zn,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 Gn(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 Yn=class extends pe{next;constructor(t,r){super(Qc,t,r),this.next=void 0}};function _r(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 er(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&&(rr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ef,t,e),this},rr.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?Vn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function Xn(){return new rr}function Ur(e,t){let r=Xn();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Re;(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"})(Re||(Re={}));function Tr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function $n(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 Tr("enum",Re.VARINT,r,n)}function Dr(e,t){return Tr("message",Re.LENGTH_DELIMITED,e,t)}var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Jn;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Jn||(Jn={}));(function(e){e.codec=()=>$n(Jn)})(Z||(Z={}));var Tt;(function(e){let t;e.codec=()=>(t==null&&(t=Dr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Z.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=Z.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Ur(r,e.codec()),e.decode=(r,n)=>Cr(r,e.codec(),n)})(Tt||(Tt={}));var nr;(function(e){let t;e.codec=()=>(t==null&&(t=Dr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Z.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=Z.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Ur(r,e.codec()),e.decode=(r,n)=>Cr(r,e.codec(),n)})(nr||(nr={}));function Qn(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return _e(e)}var sr={};ct(sr,{MAX_RSA_KEY_SIZE:()=>to,generateRSAKeyPair:()=>ao,jwkToJWKKeyPair:()=>Qs,jwkToPkcs1:()=>af,jwkToPkix:()=>oo,jwkToRSAPrivateKey:()=>Nr,pkcs1MessageToJwk:()=>ro,pkcs1MessageToRSAPrivateKey:()=>Pr,pkcs1ToJwk:()=>sf,pkcs1ToRSAPrivateKey:()=>so,pkixMessageToJwk:()=>no,pkixMessageToRSAPublicKey:()=>Rr,pkixToJwk:()=>cf,pkixToRSAPublicKey:()=>io});var Ne=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Et.createV1(114,this._multihash)}toString(){return nt.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 Js(this.jwk,r,t)}},or=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return $s(this.jwk,t)}};var to=8192,eo=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=xt(e);return ro(t)}function ro(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(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 N("JWK was missing components");return It([ht(Uint8Array.from([0])),ht(G(e.n,"base64url")),ht(G(e.e,"base64url")),ht(G(e.d,"base64url")),ht(G(e.p,"base64url")),ht(G(e.q,"base64url")),ht(G(e.dp,"base64url")),ht(G(e.dq,"base64url")),ht(G(e.qi,"base64url"))]).subarray()}function cf(e){let t=xt(e,{offset:0});return no(t)}function no(e){let t=xt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function oo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return It([of,We(It([ht(G(e.n,"base64url")),ht(G(e.e,"base64url"))]))]).subarray()}function so(e){let t=xt(e);return Pr(t)}function Pr(e){let t=ro(e);return Nr(t)}function io(e,t){if(e.byteLength>=nf)throw new me("Key size is too large");let r=xt(e,{offset:0});return Rr(r,e,t)}function Rr(e,t,r){let n=no(e);if(r==null){let o=Nt(Tt.encode({Type:Z.RSA,Data:t}));r=vt(eo,o)}return new Ne(n,r)}function Nr(e){if(ei(e)>to)throw new N("Key size is too large");let t=Qs(e),r=Nt(Tt.encode({Type:Z.RSA,Data:oo(t.publicKey)})),n=vt(eo,r);return new or(t.privateKey,new Ne(t.publicKey,n))}async function ao(e){if(e>to)throw new N("Key size is too large");let t=await ti(e),r=Nt(Tt.encode({Type:Z.RSA,Data:oo(t.publicKey)})),n=vt(eo,r);return new or(t.privateKey,new Ne(t.publicKey,n))}function Qs(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ri="1.2.840.113549.1.1.1";async function ti(e){let t=await it.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await ff(t);return{privateKey:r[0],publicKey:r[1]}}async function $s(e,t){let r=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await it.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Js(e,t,r){let n=await it.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return it.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function ff(e){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");return Promise.all([it.get().subtle.exportKey("jwk",e.privateKey),it.get().subtle.exportKey("jwk",e.publicKey)])}function ei(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return G(e.n,"base64url").length*8}var kr=class extends Le{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,br(t);let n=Ft(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),ve(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ir=(e,t,r)=>new kr(e,t).update(r).digest();ir.create=(e,t)=>new kr(e,t);function ni(e){e.lowS!==void 0&&_t("lowS",e.lowS),e.prehash!==void 0&&_t("prehash",e.prehash)}function uf(e){let t=Je(e);Ht(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 co=class extends Error{constructor(t=""){super(t)}},Mt={Err:co,_tlv:{encode:(e,t)=>{let{Err:r}=Mt;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=Xe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Xe(o.length/2|128):"";return Xe(e)+s+o+t},decode(e,t){let{Err:r}=Mt,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}=Mt;if(e<qt)throw new t("integer: negative integers are not allowed");let r=Xe(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}=Mt;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 Ot(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Mt,o=X("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}=Mt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},qt=BigInt(0),ot=BigInt(1),S0=BigInt(2),oi=BigInt(3),B0=BigInt(4);function lf(e){let t=uf(e),{Fp:r}=t,n=Jt(t.n,t.nBitLength),o=t.toBytes||((y,h,b)=>{let A=h.toAffine();return $t(Uint8Array.from([4]),r.toBytes(A.x),r.toBytes(A.y))}),s=t.fromBytes||(y=>{let h=y.subarray(1),b=r.fromBytes(h.subarray(0,r.BYTES)),A=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x:b,y:A}});function i(y){let{a:h,b}=t,A=r.sqr(y),m=r.mul(A,y);return r.add(r.add(m,r.mul(y,h)),b)}if(!r.eql(r.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Ar(y,ot,t.n)}function c(y){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:A,n:m}=t;if(h&&typeof y!="bigint"){if(ae(y)&&(y=Xt(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(b*2,"0")}let v;try{v=typeof y=="bigint"?y:Ot(X("private key",y,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof y)}return A&&(v=F(v,m)),gt("private key",v,ot,m),v}function u(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let f=Te((y,h)=>{let{px:b,py:A,pz:m}=y;if(r.eql(m,r.ONE))return{x:b,y:A};let v=y.is0();h==null&&(h=v?r.ONE:r.inv(m));let T=r.mul(b,h),U=r.mul(A,h),L=r.mul(m,h);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:T,y:U}}),l=Te(y=>{if(y.is0()){if(t.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=y.toAffine();if(!r.isValid(h)||!r.isValid(b))throw new Error("bad point: x or y not FE");let A=r.sqr(b),m=i(h);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(h,b,A){if(h==null||!r.isValid(h))throw new Error("x required");if(b==null||!r.isValid(b))throw new Error("y required");if(A==null||!r.isValid(A))throw new Error("z required");this.px=h,this.py=b,this.pz=A,Object.freeze(this)}static fromAffine(h){let{x:b,y:A}=h||{};if(!h||!r.isValid(b)||!r.isValid(A))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let m=v=>r.eql(v,r.ZERO);return m(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(h){let b=r.invertBatch(h.map(A=>A.pz));return h.map((A,m)=>A.toAffine(b[m])).map(d.fromAffine)}static fromHex(h){let b=d.fromAffine(s(X("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,b){return vr(d,n,h,b)}_setWindowSize(h){g.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:b,py:A,pz:m}=this,{px:v,py:T,pz:U}=h,L=r.eql(r.mul(b,U),r.mul(v,m)),K=r.eql(r.mul(A,U),r.mul(T,m));return L&&K}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b}=t,A=r.mul(b,oi),{px:m,py:v,pz:T}=this,U=r.ZERO,L=r.ZERO,K=r.ZERO,C=r.mul(m,m),j=r.mul(v,v),q=r.mul(T,T),k=r.mul(m,v);return k=r.add(k,k),K=r.mul(m,T),K=r.add(K,K),U=r.mul(h,K),L=r.mul(A,q),L=r.add(U,L),U=r.sub(j,L),L=r.add(j,L),L=r.mul(U,L),U=r.mul(k,U),K=r.mul(A,K),q=r.mul(h,q),k=r.sub(C,q),k=r.mul(h,k),k=r.add(k,K),K=r.add(C,C),C=r.add(K,C),C=r.add(C,q),C=r.mul(C,k),L=r.add(L,C),q=r.mul(v,T),q=r.add(q,q),C=r.mul(q,k),U=r.sub(U,C),K=r.mul(q,j),K=r.add(K,K),K=r.add(K,K),new d(U,L,K)}add(h){u(h);let{px:b,py:A,pz:m}=this,{px:v,py:T,pz:U}=h,L=r.ZERO,K=r.ZERO,C=r.ZERO,j=t.a,q=r.mul(t.b,oi),k=r.mul(b,v),tt=r.mul(A,T),S=r.mul(m,U),I=r.add(b,A),_=r.add(v,T);I=r.mul(I,_),_=r.add(k,tt),I=r.sub(I,_),_=r.add(b,m);let x=r.add(v,U);return _=r.mul(_,x),x=r.add(k,S),_=r.sub(_,x),x=r.add(A,m),L=r.add(T,U),x=r.mul(x,L),L=r.add(tt,S),x=r.sub(x,L),C=r.mul(j,_),L=r.mul(q,S),C=r.add(L,C),L=r.sub(tt,C),C=r.add(tt,C),K=r.mul(L,C),tt=r.add(k,k),tt=r.add(tt,k),S=r.mul(j,S),_=r.mul(q,_),tt=r.add(tt,S),S=r.sub(k,S),S=r.mul(j,S),_=r.add(_,S),k=r.mul(tt,_),K=r.add(K,k),k=r.mul(x,_),L=r.mul(I,L),L=r.sub(L,k),k=r.mul(I,tt),C=r.mul(x,C),C=r.add(C,k),new d(L,K,C)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return g.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:b,n:A}=t;gt("scalar",h,qt,A);let m=d.ZERO;if(h===qt)return m;if(this.is0()||h===ot)return this;if(!b||g.hasPrecomputes(this))return g.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:v,k1:T,k2neg:U,k2:L}=b.splitScalar(h),K=m,C=m,j=this;for(;T>qt||L>qt;)T&ot&&(K=K.add(j)),L&ot&&(C=C.add(j)),j=j.double(),T>>=ot,L>>=ot;return v&&(K=K.negate()),U&&(C=C.negate()),C=new d(r.mul(C.px,b.beta),C.py,C.pz),K.add(C)}multiply(h){let{endo:b,n:A}=t;gt("scalar",h,ot,A);let m,v;if(b){let{k1neg:T,k1:U,k2neg:L,k2:K}=b.splitScalar(h),{p:C,f:j}=this.wNAF(U),{p:q,f:k}=this.wNAF(K);C=g.constTimeNegate(T,C),q=g.constTimeNegate(L,q),q=new d(r.mul(q.px,b.beta),q.py,q.pz),m=C.add(q),v=j.add(k)}else{let{p:T,f:U}=this.wNAF(h);m=T,v=U}return d.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(h,b,A){let m=d.BASE,v=(U,L)=>L===qt||L===ot||!U.equals(m)?U.multiplyUnsafe(L):U.multiply(L),T=v(this,b).add(v(h,A));return T.is0()?void 0:T}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=t;if(h===ot)return!0;if(b)return b(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=t;return h===ot?this:b?b(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return _t("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return _t("isCompressed",h),Xt(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);let E=t.nBitLength,g=Br(d,t.endo?Math.ceil(E/2):E);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function hf(e){let t=Je(e);return Ht(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function si(e){let t=hf(e),{Fp:r,n}=t,o=r.BYTES+1,s=2*r.BYTES+1;function i(S){return F(S,n)}function a(S){return Sr(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=lf({...t,toBytes(S,I,_){let x=I.toAffine(),p=r.toBytes(x.x),w=$t;return _t("isCompressed",_),_?w(Uint8Array.from([I.hasEvenY()?2:3]),p):w(Uint8Array.from([4]),p,r.toBytes(x.y))},fromBytes(S){let I=S.length,_=S[0],x=S.subarray(1);if(I===o&&(_===2||_===3)){let p=Ot(x);if(!Ar(p,ot,r.ORDER))throw new Error("Point is not on curve");let w=f(p),B;try{B=r.sqrt(w)}catch(O){let H=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+H)}let D=(B&ot)===ot;return(_&1)===1!==D&&(B=r.neg(B)),{x:p,y:B}}else if(I===s&&_===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=>Xt(fe(S,t.nByteLength));function E(S){let I=n>>ot;return S>I}function g(S){return E(S)?i(-S):S}let y=(S,I,_)=>Ot(S.slice(I,_));class h{constructor(I,_,x){gt("r",I,ot,n),gt("s",_,ot,n),this.r=I,this.s=_,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(I){let _=t.nByteLength;return I=X("compactSignature",I,_*2),new h(y(I,0,_),y(I,_,2*_))}static fromDER(I){let{r:_,s:x}=Mt.toSig(X("DER",I));return new h(_,x)}assertValidity(){}addRecoveryBit(I){return new h(this.r,this.s,I)}recoverPublicKey(I){let{r:_,s:x,recovery:p}=this,w=U(X("msgHash",I));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let B=p===2||p===3?_+t.n:_;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)),O=a(B),H=i(-w*O),M=i(x*O),V=c.BASE.multiplyAndAddUnsafe(R,H,M);if(!V)throw new Error("point at infinify");return V.assertValidity(),V}hasHighS(){return E(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return $e(this.toDERHex())}toDERHex(){return Mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return $e(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=Tn(t.n);return xs(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=ae(S),_=typeof S=="string",x=(I||_)&&S.length;return I?x===o||x===s:_?x===2*o||x===2*s:S instanceof c}function v(S,I,_=!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(_)}let T=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=Ot(S),_=S.length*8-t.nBitLength;return _>0?I>>BigInt(_):I},U=t.bits2int_modN||function(S){return i(T(S))},L=ue(t.nBitLength);function K(S){return gt("num < 2^"+t.nBitLength,S,qt,L),fe(S,t.nByteLength)}function C(S,I,_=j){if(["recovered","canonical"].some(J=>J in _))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:p}=t,{lowS:w,prehash:B,extraEntropy:D}=_;w==null&&(w=!0),S=X("msgHash",S),ni(_),B&&(S=X("prehashed msgHash",x(S)));let R=U(S),O=u(I),H=[K(O),K(R)];if(D!=null&&D!==!1){let J=D===!0?p(r.BYTES):D;H.push(X("extraEntropy",J))}let M=$t(...H),V=R;function Q(J){let st=T(J);if(!l(st))return;let mt=a(st),rt=c.BASE.multiply(st).toAffine(),at=i(rt.x);if(at===qt)return;let yt=i(mt*i(V+at*O));if(yt===qt)return;let Bt=(rt.x===at?0:2)|Number(rt.y&ot),ke=yt;return w&&E(yt)&&(ke=g(yt),Bt^=1),new h(at,ke,Bt)}return{seed:M,k2sig:Q}}let j={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function k(S,I,_=j){let{seed:x,k2sig:p}=C(S,I,_),w=t;return ds(w.hash.outputLen,w.nByteLength,w.hmac)(x,p)}c.BASE._setWindowSize(8);function tt(S,I,_,x=q){let p=S;I=X("msgHash",I),_=X("publicKey",_);let{lowS:w,prehash:B,format:D}=x;if(ni(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"||ae(p),O=!R&&!D&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!R&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let H,M;try{if(O&&(H=new h(p.r,p.s)),R){try{D!=="compact"&&(H=h.fromDER(p))}catch(Bt){if(!(Bt instanceof Mt.Err))throw Bt}!H&&D!=="der"&&(H=h.fromCompact(p))}M=c.fromHex(_)}catch{return!1}if(!H||w&&H.hasHighS())return!1;B&&(I=t.hash(I));let{r:V,s:Q}=H,J=U(I),st=a(Q),mt=i(J*st),rt=i(V*st),at=c.BASE.multiplyAndAddUnsafe(M,mt,rt)?.toAffine();return at?i(at.x)===V:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:v,sign:k,verify:tt,ProjectivePoint:c,Signature:h,utils:b}}function df(e){return{hash:e,hmac:(t,...r)=>ir(e,t,wn(...r)),randomBytes:_e}}function ii(e,t){let r=n=>si({...e,...df(n)});return{...r(t),create:r}}var fi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ai=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),pf=BigInt(1),fo=BigInt(2),ci=(e,t)=>(e+t/fo)/t;function mf(e){let t=fi,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Y(f,r,t)*f%t,d=Y(l,r,t)*f%t,E=Y(d,fo,t)*u%t,g=Y(E,o,t)*E%t,y=Y(g,s,t)*g%t,h=Y(y,a,t)*y%t,b=Y(h,c,t)*h%t,A=Y(b,a,t)*y%t,m=Y(A,r,t)*f%t,v=Y(m,i,t)*g%t,T=Y(v,n,t)*u%t,U=Y(T,fo,t);if(!uo.eql(uo.sqr(U),e))throw new Error("Cannot find square root");return U}var uo=Jt(fi,void 0,void 0,{sqrt:mf}),St=ii({a:BigInt(0),b:BigInt(7),Fp:uo,n:ai,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=ai,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-pf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=ci(s*e,t),c=ci(-n*e,t),u=F(e-a*r-c*o,t),f=F(-a*n-c*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},Nt),D0=BigInt(0);var P0=St.ProjectivePoint;function lo(e,t){let r=G(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 ho(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var ui=33,li=32;function hi(e,t){let r=pr.digest(t instanceof Uint8Array?t:t.subarray());if(ho(r))return r.then(({digest:n})=>St.sign(n,e).toDERRawBytes()).catch(n=>{throw new Oe(String(n))});try{return St.sign(r.digest,e).toDERRawBytes()}catch(n){throw new Oe(String(n))}}function di(e,t,r){let n=pr.digest(r instanceof Uint8Array?r:r.subarray());if(ho(n))return n.then(({digest:o})=>St.verify(t,o,e)).catch(o=>{throw new He(String(o))});try{return St.verify(t,n.digest,e)}catch(o){throw new He(String(o))}}var ar=class{type="secp256k1";raw;_key;constructor(t){this._key=yi(t),this.raw=pi(this._key)}toMultihash(){return ne.digest(se(this))}toCID(){return Et.createV1(114,this.toMultihash())}toString(){return nt.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 di(this._key,r,t)}},cr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=mi(t),this.publicKey=new ar(r??bi(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t){return hi(this.raw,t)}};function po(e){return new cr(e)}function Or(e){return new ar(e)}async function xi(){let e=yf();return new cr(e)}function pi(e){return St.ProjectivePoint.fromHex(e).toRawBytes(!0)}function mi(e){try{return St.getPublicKey(e,!0),e}catch(t){throw new Me(String(t))}}function yi(e){try{return St.ProjectivePoint.fromHex(e),e}catch(t){throw new me(String(t))}}function bi(e){try{return St.getPublicKey(e,!0)}catch(t){throw new Me(String(t))}}function yf(){return St.utils.randomPrivateKey()}var Hr={"P-256":32,"P-384":48,"P-521":66},bf=Object.keys(Hr),mo=bf.join(" / ");async function gi(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${mo}`);let t=await it.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await it.get().subtle.importKey("jwk",gf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let c=await it.get().subtle.importKey("jwk",wi(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await it.get().subtle.deriveBits({name:"ECDH",public:c},a,Hr[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await it.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 N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${mo}`);let t=Hr[e.crv];return Ct([Uint8Array.from([4]),lo(e.x,t),lo(e.y,t)],1+t*2)}function wi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${mo}`);let r=Hr[e];if(!ft(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:z(t.subarray(1,r+1),"base64url"),y:z(t.subarray(1+r),"base64url"),ext:!0}}var gf=(e,t)=>({...wi(e,t.public),d:z(t.private,"base64url")});var wf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Ei(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=wf[e],o=n.keySize,s=n.ivSize,i=20,a=G("key expansion"),c=2*(s+o+i),u=await Vr(t,r),f=await u.digest(a),l=[],d=0;for(;d<c;){let A=await u.digest(Ct([f,a])),m=A.length;d+m>c&&(m=c-d),l.push(A),d+=m,f=await u.digest(f)}let E=c/2,g=Ct(l),y=g.subarray(0,E),h=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(h)}}async function Ef(e,t){if(e==="Ed25519")return Ps();if(e==="secp256k1")return xi();if(e==="RSA")return ao(Cf(t));if(e==="ECDSA")return ns(_f(t));throw new Vt}async function Af(e,t){if(e!=="Ed25519")throw new Vt("Seed key derivation only supported for Ed25519 keys");return Rs(t)}function Sf(e,t){let{Type:r,Data:n}=Tt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return io(o,t);case Z.Ed25519:return Lr(o);case Z.secp256k1:return Or(o);case Z.ECDSA:return xn(o);default:throw new Vt}}function Bf(e){if(e.byteLength===Qt)return Lr(e);if(e.byteLength===ui)return Or(e);let t=xt(e),r=t[1]?.[0];if(r===pn||r===mn||r===yn)return gn(t);if(t[0]?.[0]===ri)return Rr(t,e);throw new N("Could not extract public key from raw bytes")}function vf(e){let{Type:t,Data:r}=Tt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return Lr(n);case Z.secp256k1:return Or(n);case Z.ECDSA:return xn(n);default:throw new Vt}}function se(e){return Tt.encode({Type:Z[e.type],Data:e.raw})}function If(e){let t=nr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case Z.RSA:return so(r);case Z.Ed25519:return Hn(r);case Z.secp256k1:return po(r);case Z.ECDSA:return Qo(r);default:throw new Vt}}function Lf(e){if(e.byteLength===At)return Hn(e);if(e.byteLength===li)return po(e);let t=xt(e),r=t[2]?.[0];if(r===pn||r===mn||r===yn)return bn(t);if(t.length>8)return Pr(t);throw new N("Could not extract private key from raw bytes")}function Kf(e){return nr.encode({Type:Z[e.type],Data:e.raw})}function Cf(e){return e==null?2048:parseInt(e,10)}function _f(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new N("Unsupported curve, should be P-256, P-384 or P-521")}async function Uf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new N("Only RSA and ECDSA keys are supported")}async function Tf(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Nr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Rt(t)}throw new N("Only RSA and ECDSA keys are supported")}function Df(e,t,r,n){br(e);let o=is({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Be(s),Be(i),Be(a),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Ft(t),u=Ft(r),f=new Uint8Array(i),l=ir.create(e,c),d=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function Pf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),o.fill(0),r}function Ai(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),l=Ke(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);l.setInt32(0,E,!1),(u=c._cloneInto(u)).update(f).digestInto(d),y.set(d.subarray(0,y.length));for(let h=1;h<o;h++){a._cloneInto(u).update(d).digestInto(d);for(let b=0;b<y.length;b++)y[b]^=d[b]}}return Pf(a,c,i,u,d)}var fr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),re=new Uint32Array(80),Mr=class extends jt{constructor(){super(64,20,8,!1),this.A=fr[0]|0,this.B=fr[1]|0,this.C=fr[2]|0,this.D=fr[3]|0,this.E=fr[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)re[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)re[c]=xr(re[c-3]^re[c-8]^re[c-14]^re[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=gr(o,s,i),f=1518500249):c<40?(u=o^s^i,f=1859775393):c<60?(u=wr(o,s,i),f=2400959708):(u=o^s^i,f=3395469782);let l=xr(n,5)+u+a+f+re[c]|0;a=i,i=s,s=xr(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){re.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},bo=Ce(()=>new Mr),Pd=2**32;var Si={sha1:bo,"sha2-256":Nt,"sha2-512":Ye};function xo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Si).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Si[o],i=Ai(s,e,t,{c:r,dkLen:n});return nn.encode(i).substring(1)}return Ti(Rf);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/crypto",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Crypto primitives for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/crypto#readme",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"generate": "protons ./src/keys/keys.proto"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@libp2p/interface": "^2.
|
|
95
|
+
"@libp2p/interface": "^2.9.0",
|
|
96
96
|
"@noble/curves": "^1.7.0",
|
|
97
97
|
"@noble/hashes": "^1.6.1",
|
|
98
98
|
"multiformats": "^13.3.1",
|