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