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