@libp2p/crypto
Version:
Crypto primitives for libp2p
2 lines • 99.9 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PCrypto=(()=>{var kr=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var ui=Object.getOwnPropertyNames;var hi=Object.prototype.hasOwnProperty;var nt=(r,t)=>{for(var e in t)kr(r,e,{get:t[e],enumerable:!0})},li=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ui(t))!hi.call(r,o)&&o!==e&&kr(r,o,{get:()=>t[o],enumerable:!(n=fi(t,o))||n.enumerable});return r};var di=r=>li(kr({},"__esModule",{value:!0}),r);var bf={};nt(bf,{hmac:()=>nr,keys:()=>no,pbkdf2:()=>so,randomBytes:()=>Zn});var nr={};nt(nr,{create:()=>Hr});var _e=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Ce=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var po={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new rr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var ot=po;var mo={SHA1:20,SHA256:32,SHA512:64};var pi={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},mi=async(r,t)=>{let e=await ot.get().subtle.sign({name:"HMAC"},r,t);return new Uint8Array(e,0,e.byteLength)};async function Hr(r,t){let e=pi[r],n=await ot.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:e}},!1,["sign"]);return{async digest(o){return mi(n,o)},length:mo[r]}}var no={};nt(no,{generateEphemeralKeyPair:()=>Ys,generateKeyPair:()=>sf,generateKeyPairFromSeed:()=>cf,keyStretcher:()=>$s,privateKeyFromProtobuf:()=>hf,privateKeyFromRaw:()=>lf,privateKeyToProtobuf:()=>df,publicKeyFromMultihash:()=>uf,publicKeyFromProtobuf:()=>af,publicKeyFromRaw:()=>ff,publicKeyToProtobuf:()=>Fe});var q=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"}},Ke=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Mt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Fr={};nt(Fr,{base58btc:()=>it,base58flickr:()=>Ei});var Lf=new Uint8Array(0);function bo(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ct(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function yo(r){return new TextEncoder().encode(r)}function xo(r){return new TextDecoder().decode(r)}function bi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function h(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var y=0,l=0,x=0,B=g.length;x!==B&&g[x]===0;)x++,y++;for(var m=(B-x)*f+1>>>0,v=new Uint8Array(m);x!==B;){for(var _=g[x],R=0,I=m-1;(_!==0||R<l)&&I!==-1;I--,R++)_+=256*v[I]>>>0,v[I]=_%c>>>0,_=_/c>>>0;if(_!==0)throw new Error("Non-zero carry");l=R,x++}for(var T=m-l;T!==m&&v[T]===0;)T++;for(var L=a.repeat(y);T<m;++T)L+=r.charAt(v[T]);return L}function d(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var y=0;if(g[y]!==" "){for(var l=0,x=0;g[y]===a;)l++,y++;for(var B=(g.length-y)*u+1>>>0,m=new Uint8Array(B);g[y];){var v=e[g.charCodeAt(y)];if(v===255)return;for(var _=0,R=B-1;(v!==0||_<x)&&R!==-1;R--,_++)v+=c*m[R]>>>0,m[R]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");x=_,y++}if(g[y]!==" "){for(var I=B-x;I!==B&&m[I]===0;)I++;for(var T=new Uint8Array(l+(B-I)),L=l;I!==B;)T[L++]=m[I++];return T}}}function E(g){var y=d(g);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:d,decode:E}}var yi=bi,xi=yi,wo=xi;var Mr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 Eo(this,t)}},Vr=class{decoders;constructor(t){this.decoders=t}or(t){return Eo(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 Eo(r,t){return new Vr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var zr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Mr(t,e,n),this.decoder=new qr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function le({name:r,prefix:t,encode:e,decode:n}){return new zr(r,t,e,n)}function qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=wo(e,r);return le({prefix:t,name:r,encode:n,decode:s=>Ct(o(s))})}function gi(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,u=0;for(let f=0;f<s;++f){let h=o[r[f]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|h,c+=e,c>=8&&(c-=8,i[u++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function wi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return le({prefix:t,name:r,encode(o){return wi(o,n,e)},decode(o){return gi(o,n,e,r)}})}var it=qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ei=qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zr={};nt(Zr,{base32:()=>de,base32hex:()=>vi,base32hexpad:()=>Li,base32hexpadupper:()=>Ui,base32hexupper:()=>Ii,base32pad:()=>Si,base32padupper:()=>Ai,base32upper:()=>Bi,base32z:()=>Ti});var de=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bi=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Si=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ai=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),vi=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ii=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Li=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ui=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ti=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gr={};nt(Gr,{base36:()=>Ne,base36upper:()=>Ri});var Ne=qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ri=qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var _i=Ao,Bo=128,Ci=127,Ki=~Ci,Ni=Math.pow(2,31);function Ao(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ni;)t[e++]=r&255|Bo,r/=128;for(;r&Ki;)t[e++]=r&255|Bo,r>>>=7;return t[e]=r|0,Ao.bytes=e-n+1,t}var Di=jr,Pi=128,So=127;function jr(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw jr.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&So)<<o:(i&So)*Math.pow(2,o),o+=7}while(i>=Pi);return jr.bytes=s-n,e}var Oi=Math.pow(2,7),ki=Math.pow(2,14),Hi=Math.pow(2,21),Mi=Math.pow(2,28),qi=Math.pow(2,35),Vi=Math.pow(2,42),zi=Math.pow(2,49),Fi=Math.pow(2,56),Zi=Math.pow(2,63),Gi=function(r){return r<Oi?1:r<ki?2:r<Hi?3:r<Mi?4:r<qi?5:r<Vi?6:r<zi?7:r<Fi?8:r<Zi?9:10},ji={encode:_i,decode:Di,encodingLength:Gi},Wi=ji,De=Wi;function Pe(r,t=0){return[De.decode(r,t),De.decode.bytes]}function pe(r,t,e=0){return De.encode(r,t,e),t}function me(r){return De.encodingLength(r)}function gt(r,t){let e=t.byteLength,n=me(r),o=n+me(e),s=new Uint8Array(o+e);return pe(r,s,0),pe(e,s,n),s.set(t,o),new be(r,e,t,s)}function vo(r){let t=Ct(r),[e,n]=Pe(t),[o,s]=Pe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new be(e,o,i,t)}function Io(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&bo(r.bytes,e.bytes)}}var be=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Lo(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xi(e,Wr(r),t??it.encoder);default:return $i(e,Wr(r),t??de.encoder)}}var Uo=new WeakMap;function Wr(r){let t=Uo.get(r);if(t==null){let e=new Map;return Uo.set(r,e),e}return t}var It=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ji)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=gt(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Io(t.multihash,n.multihash)}toString(t){return Lo(this,t)}toJSON(){return{"/":Lo(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??To(n,o,s.bytes))}else if(e[Qi]===!0){let{version:n,multihash:o,code:s}=e,i=vo(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=To(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ke,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ct(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new be(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,d]=Pe(t.subarray(e));return e+=d,h},o=n(),s=ke;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),u=e+a,f=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,e){let[n,o]=Yi(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Wr(s).set(n,t),s}};function Yi(r,t){switch(r[0]){case"Q":{let e=t??it;return[it.prefix,e.decode(`${it.prefix}${r}`)]}case it.prefix:{let e=t??it;return[it.prefix,e.decode(r)]}case de.prefix:{let e=t??de;return[de.prefix,e.decode(r)]}case Ne.prefix:{let e=t??Ne;return[Ne.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xi(r,t,e){let{prefix:n}=e;if(n!==it.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function $i(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ke=112,Ji=18;function To(r,t,e){let n=me(r),o=n+me(t),s=new Uint8Array(o+e.byteLength);return pe(r,s,0),pe(t,s,n),s.set(e,o),s}var Qi=Symbol.for("@ipld/js-cid/CID");var Yr={};nt(Yr,{identity:()=>He});var Ro=0,tc="identity",_o=Ct;function ec(r){return gt(Ro,_o(r))}var He={code:Ro,name:tc,encode:_o,digest:ec};function pt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function ye(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function rc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function xe(r,...t){if(!rc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function sr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ye(r.outputLen),ye(r.blockLen)}function ge(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Co(r,t){xe(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function wt(r,t){return r<<32-t|r>>>t}function ir(r,t){return r<<t|r>>>32-t>>>0}function Ko(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Vt(r){return typeof r=="string"&&(r=Ko(r)),xe(r),r}function Xr(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];xe(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var we=class{clone(){return this._cloneInto()}};function No(r,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function Be(r){let t=n=>r().update(Vt(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Se(r=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(r));if(re&&typeof re.randomBytes=="function")return re.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function nc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),c=Number(e&s),a=n?4:0,u=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+u,c,n)}function cr(r,t,e){return r&t^~r&e}function ar(r,t,e){return r&t^r&e^t&e}var zt=class extends we{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ee(this.buffer)}update(t){ge(this);let{view:e,buffer:n,blockLen:o}=this;t=Vt(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Ee(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(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ge(this),Co(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;nc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Ee(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)c.setUint32(4*h,f[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var fr=BigInt(4294967295),$r=BigInt(32);function Do(r,t=!1){return t?{h:Number(r&fr),l:Number(r>>$r&fr)}:{h:Number(r>>$r&fr)|0,l:Number(r&fr)|0}}function oc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Do(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var sc=(r,t)=>BigInt(r>>>0)<<$r|BigInt(t>>>0),ic=(r,t,e)=>r>>>e,cc=(r,t,e)=>r<<32-e|t>>>e,ac=(r,t,e)=>r>>>e|t<<32-e,fc=(r,t,e)=>r<<32-e|t>>>e,uc=(r,t,e)=>r<<64-e|t>>>e-32,hc=(r,t,e)=>r>>>e-32|t<<64-e,lc=(r,t)=>t,dc=(r,t)=>r,pc=(r,t,e)=>r<<e|t>>>32-e,mc=(r,t,e)=>t<<e|r>>>32-e,bc=(r,t,e)=>t<<e-32|r>>>64-e,yc=(r,t,e)=>r<<e-32|t>>>64-e;function xc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var gc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),wc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ec=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Sc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ac=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var vc={fromBig:Do,split:oc,toBig:sc,shrSH:ic,shrSL:cc,rotrSH:ac,rotrSL:fc,rotrBH:uc,rotrBL:hc,rotr32H:lc,rotr32L:dc,rotlSH:pc,rotlSL:mc,rotlBH:bc,rotlBL:yc,add:xc,add3L:gc,add3H:wc,add4L:Ec,add4H:Bc,add5H:Ac,add5L:Sc},D=vc;var[Ic,Lc]=D.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Ft=new Uint32Array(80),Zt=new Uint32Array(80),Jr=class extends zt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:f,Fh:h,Fl:d,Gh:E,Gl:g,Hh:y,Hl:l}=this;return[t,e,n,o,s,i,c,a,u,f,h,d,E,g,y,l]}set(t,e,n,o,s,i,c,a,u,f,h,d,E,g,y,l){this.Ah=t|0,this.Al=e|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=u|0,this.El=f|0,this.Fh=h|0,this.Fl=d|0,this.Gh=E|0,this.Gl=g|0,this.Hh=y|0,this.Hl=l|0}process(t,e){for(let m=0;m<16;m++,e+=4)Ft[m]=t.getUint32(e),Zt[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let v=Ft[m-15]|0,_=Zt[m-15]|0,R=D.rotrSH(v,_,1)^D.rotrSH(v,_,8)^D.shrSH(v,_,7),I=D.rotrSL(v,_,1)^D.rotrSL(v,_,8)^D.shrSL(v,_,7),T=Ft[m-2]|0,L=Zt[m-2]|0,F=D.rotrSH(T,L,19)^D.rotrBH(T,L,61)^D.shrSH(T,L,6),H=D.rotrSL(T,L,19)^D.rotrBL(T,L,61)^D.shrSL(T,L,6),O=D.add4L(I,H,Zt[m-7],Zt[m-16]),X=D.add4H(O,R,F,Ft[m-7],Ft[m-16]);Ft[m]=X|0,Zt[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:f,Eh:h,El:d,Fh:E,Fl:g,Gh:y,Gl:l,Hh:x,Hl:B}=this;for(let m=0;m<80;m++){let v=D.rotrSH(h,d,14)^D.rotrSH(h,d,18)^D.rotrBH(h,d,41),_=D.rotrSL(h,d,14)^D.rotrSL(h,d,18)^D.rotrBL(h,d,41),R=h&E^~h&y,I=d&g^~d&l,T=D.add5L(B,_,I,Lc[m],Zt[m]),L=D.add5H(T,x,v,R,Ic[m],Ft[m]),F=T|0,H=D.rotrSH(n,o,28)^D.rotrBH(n,o,34)^D.rotrBH(n,o,39),O=D.rotrSL(n,o,28)^D.rotrBL(n,o,34)^D.rotrBL(n,o,39),X=n&s^n&c^s&c,S=o&i^o&a^i&a;x=y|0,B=l|0,y=E|0,l=g|0,E=h|0,g=d|0,{h,l:d}=D.add(u|0,f|0,L|0,F|0),u=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let U=D.add3L(F,O,S);n=D.add3H(U,L,H,X),o=U|0}({h:n,l:o}=D.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=D.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=D.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=D.add(this.Dh|0,this.Dl|0,u|0,f|0),{h,l:d}=D.add(this.Eh|0,this.El|0,h|0,d|0),{h:E,l:g}=D.add(this.Fh|0,this.Fl|0,E|0,g|0),{h:y,l}=D.add(this.Gh|0,this.Gl|0,y|0,l|0),{h:x,l:B}=D.add(this.Hh|0,this.Hl|0,x|0,B|0),this.set(n,o,s,i,c,a,u,f,h,d,E,g,y,l,x,B)}roundClean(){Ft.fill(0),Zt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ur=Be(()=>new Jr);var dr={};nt(dr,{aInRange:()=>lt,abool:()=>Et,abytes:()=>Ae,bitGet:()=>Kc,bitLen:()=>rn,bitMask:()=>qe,bitSet:()=>Nc,bytesToHex:()=>Nt,bytesToNumberBE:()=>Dt,bytesToNumberLE:()=>jt,concatBytes:()=>Pt,createHmacDrbg:()=>nn,ensureBytes:()=>j,equalBytes:()=>_c,hexToBytes:()=>oe,hexToNumber:()=>en,inRange:()=>Me,isBytes:()=>Gt,memoized:()=>ie,notImplemented:()=>Pc,numberToBytesBE:()=>Wt,numberToBytesLE:()=>se,numberToHexUnpadded:()=>ne,numberToVarBytesBE:()=>Rc,utf8ToBytes:()=>Cc,validateObject:()=>Lt});var hr=BigInt(0),lr=BigInt(1),Uc=BigInt(2);function Gt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ae(r){if(!Gt(r))throw new Error("Uint8Array expected")}function Et(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Tc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Nt(r){Ae(r);let t="";for(let e=0;e<r.length;e++)t+=Tc[r[e]];return t}function ne(r){let t=r.toString(16);return t.length&1?"0"+t:t}function en(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?hr:BigInt("0x"+r)}var Kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Po(r){if(r>=Kt._0&&r<=Kt._9)return r-Kt._0;if(r>=Kt.A&&r<=Kt.F)return r-(Kt.A-10);if(r>=Kt.a&&r<=Kt.f)return r-(Kt.a-10)}function oe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Po(r.charCodeAt(s)),c=Po(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Dt(r){return en(Nt(r))}function jt(r){return Ae(r),en(Nt(Uint8Array.from(r).reverse()))}function Wt(r,t){return oe(r.toString(16).padStart(t*2,"0"))}function se(r,t){return Wt(r,t).reverse()}function Rc(r){return oe(ne(r))}function j(r,t,e){let n;if(typeof t=="string")try{n=oe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Gt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function Pt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ae(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function _c(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function Cc(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Qr=r=>typeof r=="bigint"&&hr<=r;function Me(r,t,e){return Qr(r)&&Qr(t)&&Qr(e)&&t<=r&&r<e}function lt(r,t,e,n){if(!Me(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function rn(r){let t;for(t=0;r>hr;r>>=lr,t+=1);return t}function Kc(r,t){return r>>BigInt(t)&lr}function Nc(r,t,e){return r|(e?lr:hr)<<BigInt(t)}var qe=r=>(Uc<<BigInt(r-1))-lr,tn=r=>new Uint8Array(r),Oo=r=>Uint8Array.from(r);function nn(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=tn(r),o=tn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...h)=>e(o,n,...h),a=(h=tn())=>{o=c(Oo([0]),h),n=c(),h.length!==0&&(o=c(Oo([1]),h),n=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){n=c();let E=n.slice();d.push(E),h+=n.length}return Pt(...d)};return(h,d)=>{i(),a(h);let E;for(;!(E=d(u()));)a();return i(),E}}var Dc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Gt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Lt(r,t,e={}){let n=(o,s,i)=>{let c=Dc[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var Pc=()=>{throw new Error("not implemented")};function ie(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var $=BigInt(0),Z=BigInt(1),ce=BigInt(2),Oc=BigInt(3),on=BigInt(4),ko=BigInt(5),Ho=BigInt(8),kc=BigInt(9),Hc=BigInt(16);function V(r,t){let e=r%t;return e>=$?e:t+e}function Mc(r,t,e){if(t<$)throw new Error("invalid exponent, negatives unsupported");if(e<=$)throw new Error("invalid modulus");if(e===Z)return $;let n=Z;for(;t>$;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function G(r,t,e){let n=r;for(;t-- >$;)n*=n,n%=e;return n}function pr(r,t){if(r===$)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=$,s=Z,i=Z,c=$;for(;e!==$;){let u=n/e,f=n%e,h=o-i*u,d=s-c*u;n=e,e=f,o=i,s=c,i=h,c=d}if(n!==Z)throw new Error("invert: does not exist");return V(o,t)}function qc(r){let t=(r-Z)/ce,e,n,o;for(e=r-Z,n=0;e%ce===$;e/=ce,n++);for(o=ce;o<r&&Mc(o,t,r)!==r-Z;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/on;return function(a,u){let f=a.pow(u,i);if(!a.eql(a.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(e+Z)/ce;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let u=n,f=c.pow(c.mul(c.ONE,o),e),h=c.pow(a,s),d=c.pow(a,e);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let E=1;for(let y=c.sqr(d);E<u&&!c.eql(y,c.ONE);E++)y=c.sqr(y);let g=c.pow(f,Z<<BigInt(u-E-1));f=c.sqr(g),h=c.mul(h,g),d=c.mul(d,f),u=E}return h}}function Vc(r){if(r%on===Oc){let t=(r+Z)/on;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ho===ko){let t=(r-ko)/Ho;return function(n,o){let s=n.mul(o,ce),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,ce),i),u=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(u),o))throw new Error("Cannot find square root");return u}}return r%Hc,qc(r)}var Mo=(r,t)=>(V(r,t)&Z)===Z,zc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function sn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=zc.reduce((n,o)=>(n[o]="function",n),t);return Lt(r,e)}function Fc(r,t,e){if(e<$)throw new Error("invalid exponent, negatives unsupported");if(e===$)return r.ONE;if(e===Z)return t;let n=r.ONE,o=t;for(;e>$;)e&Z&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Z;return n}function Zc(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function cn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Yt(r,t,e=!1,n={}){if(r<=$)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=cn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:qe(o),ZERO:$,ONE:Z,create:a=>V(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return $<=a&&a<r},is0:a=>a===$,isOdd:a=>(a&Z)===Z,neg:a=>V(-a,r),eql:(a,u)=>a===u,sqr:a=>V(a*a,r),add:(a,u)=>V(a+u,r),sub:(a,u)=>V(a-u,r),mul:(a,u)=>V(a*u,r),pow:(a,u)=>Fc(c,a,u),div:(a,u)=>V(a*pr(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>pr(a,r),sqrt:n.sqrt||(a=>(i||(i=Vc(r)),i(c,a))),invertBatch:a=>Zc(c,a),cmov:(a,u,f)=>f?u:a,toBytes:a=>e?se(a,s):Wt(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?jt(a):Dt(a)}});return Object.freeze(c)}function qo(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function an(r){let t=qo(r);return t+Math.ceil(t/2)}function Vo(r,t,e=!1){let n=r.length,o=qo(t),s=an(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?jt(r):Dt(r),c=V(i,t-Z)+Z;return e?se(c,o):Wt(c,o)}var zo=BigInt(0),mr=BigInt(1);function fn(r,t){let e=t.negate();return r?e:t}function Fo(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function un(r,t){Fo(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Gc(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function jc(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var hn=new WeakMap,Zo=new WeakMap;function ln(r){return Zo.get(r)||1}function br(r,t){return{constTimeNegate:fn,hasPrecomputes(e){return ln(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>zo;)n&mr&&(o=o.add(s)),s=s.double(),n>>=mr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=un(n,t),i=[],c=e,a=c;for(let u=0;u<o;u++){a=c,i.push(a);for(let f=1;f<s;f++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=un(e,t),c=r.ZERO,a=r.BASE,u=BigInt(2**e-1),f=2**e,h=BigInt(e);for(let d=0;d<s;d++){let E=d*i,g=Number(o&u);o>>=h,g>i&&(g-=f,o+=mr);let y=E,l=E+Math.abs(g)-1,x=d%2!==0,B=g<0;g===0?a=a.add(fn(x,n[y])):c=c.add(fn(B,n[l]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:c}=un(e,t),a=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let h=0;h<i;h++){let d=h*c;if(o===zo)break;let E=Number(o&a);if(o>>=f,E>c&&(E-=u,o+=mr),E===0)continue;let g=n[d+Math.abs(E)-1];E<0&&(g=g.negate()),s=s.add(g)}return s},getPrecomputes(e,n,o){let s=hn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&hn.set(n,o(s))),s},wNAFCached(e,n,o){let s=ln(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ln(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Fo(n,t),Zo.set(e,n),hn.delete(e)}}}function yr(r,t,e,n){if(Gc(e,r),jc(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=rn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=(1<<i)-1,a=new Array(c+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let h=u;h>=0;h-=i){a.fill(o);for(let E=0;E<n.length;E++){let g=n[E],y=Number(g>>BigInt(h)&BigInt(c));a[y]=a[y].add(e[E])}let d=o;for(let E=a.length-1,g=o;E>0;E--)g=g.add(a[E]),d=d.add(g);if(f=f.add(d),h!==0)for(let E=0;E<i;E++)f=f.double()}return f}function Ve(r){return sn(r.Fp),Lt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...cn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Bt=BigInt(0),dt=BigInt(1),xr=BigInt(2),Wc=BigInt(8),Yc={zip215:!0};function Xc(r){let t=Ve(r);return Lt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Go(r){let t=Xc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,u=xr<<BigInt(c*8)-dt,f=e.create,h=Yt(t.n,t.nBitLength),d=t.uvRatio||((b,p)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(p))}}catch{return{isValid:!1,value:Bt}}}),E=t.adjustScalarBytes||(b=>b),g=t.domain||((b,p,w)=>{if(Et("phflag",w),p.length||w)throw new Error("Contexts/pre-hash are not supported");return b});function y(b,p){lt("coordinate "+b,p,Bt,u)}function l(b){if(!(b instanceof m))throw new Error("ExtendedPoint expected")}let x=ie((b,p)=>{let{ex:w,ey:A,ez:C}=b,K=b.is0();p==null&&(p=K?Wc:e.inv(C));let P=f(w*p),k=f(A*p),N=f(C*p);if(K)return{x:Bt,y:dt};if(N!==dt)throw new Error("invZ was invalid");return{x:P,y:k}}),B=ie(b=>{let{a:p,d:w}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:K,et:P}=b,k=f(A*A),N=f(C*C),M=f(K*K),z=f(M*M),Q=f(k*p),tt=f(M*f(Q+N)),rt=f(z+f(w*f(k*N)));if(tt!==rt)throw new Error("bad point: equation left != right (1)");let st=f(A*C),ht=f(K*P);if(st!==ht)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,A,C){this.ex=p,this.ey=w,this.ez=A,this.et=C,y("x",p),y("y",w),y("z",A),y("t",C),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:w,y:A}=p||{};return y("x",w),y("y",A),new m(w,A,dt,f(w*A))}static normalizeZ(p){let w=e.invertBatch(p.map(A=>A.ez));return p.map((A,C)=>A.toAffine(w[C])).map(m.fromAffine)}static msm(p,w){return yr(m,h,p,w)}_setWindowSize(p){R.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){l(p);let{ex:w,ey:A,ez:C}=this,{ex:K,ey:P,ez:k}=p,N=f(w*k),M=f(K*C),z=f(A*k),Q=f(P*C);return N===M&&z===Q}is0(){return this.equals(m.ZERO)}negate(){return new m(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:p}=t,{ex:w,ey:A,ez:C}=this,K=f(w*w),P=f(A*A),k=f(xr*f(C*C)),N=f(p*K),M=w+A,z=f(f(M*M)-K-P),Q=N+P,tt=Q-k,rt=N-P,st=f(z*tt),ht=f(Q*rt),at=f(z*rt),vt=f(tt*Q);return new m(st,ht,vt,at)}add(p){l(p);let{a:w,d:A}=t,{ex:C,ey:K,ez:P,et:k}=this,{ex:N,ey:M,ez:z,et:Q}=p;if(w===BigInt(-1)){let io=f((K-C)*(M+N)),co=f((K+C)*(M-N)),Or=f(co-io);if(Or===Bt)return this.double();let ao=f(P*xr*Q),fo=f(k*xr*z),uo=fo+ao,ho=co+io,lo=fo-ao,si=f(uo*Or),ii=f(ho*lo),ci=f(uo*lo),ai=f(Or*ho);return new m(si,ii,ai,ci)}let tt=f(C*N),rt=f(K*M),st=f(k*A*Q),ht=f(P*z),at=f((C+K)*(N+M)-tt-rt),vt=ht-st,_t=ht+st,Re=f(rt-w*tt),ei=f(at*vt),ri=f(_t*Re),ni=f(at*Re),oi=f(vt*_t);return new m(ei,ri,oi,ni)}subtract(p){return this.add(p.negate())}wNAF(p){return R.wNAFCached(this,p,m.normalizeZ)}multiply(p){let w=p;lt("scalar",w,dt,n);let{p:A,f:C}=this.wNAF(w);return m.normalizeZ([A,C])[0]}multiplyUnsafe(p,w=m.ZERO){let A=p;return lt("scalar",A,Bt,n),A===Bt?_:this.is0()||A===dt?this:R.wNAFCachedUnsafe(this,A,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(p){return x(this,p)}clearCofactor(){let{h:p}=t;return p===dt?this:this.multiplyUnsafe(p)}static fromHex(p,w=!1){let{d:A,a:C}=t,K=e.BYTES;p=j("pointHex",p,K),Et("zip215",w);let P=p.slice(),k=p[K-1];P[K-1]=k&-129;let N=jt(P),M=w?u:e.ORDER;lt("pointHex.y",N,Bt,M);let z=f(N*N),Q=f(z-dt),tt=f(A*z-C),{isValid:rt,value:st}=d(Q,tt);if(!rt)throw new Error("Point.fromHex: invalid y coordinate");let ht=(st&dt)===dt,at=(k&128)!==0;if(!w&&st===Bt&&at)throw new Error("Point.fromHex: x=0 and x_0=1");return at!==ht&&(st=f(-st)),m.fromAffine({x:st,y:N})}static fromPrivateKey(p){return L(p).point}toRawBytes(){let{x:p,y:w}=this.toAffine(),A=se(w,e.BYTES);return A[A.length-1]|=p&dt?128:0,A}toHex(){return Nt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,dt,f(t.Gx*t.Gy)),m.ZERO=new m(Bt,dt,dt,Bt);let{BASE:v,ZERO:_}=m,R=br(m,c*8);function I(b){return V(b,n)}function T(b){return I(jt(b))}function L(b){let p=e.BYTES;b=j("private key",b,p);let w=j("hashed private key",s(b),2*p),A=E(w.slice(0,p)),C=w.slice(p,2*p),K=T(A),P=v.multiply(K),k=P.toRawBytes();return{head:A,prefix:C,scalar:K,point:P,pointBytes:k}}function F(b){return L(b).pointBytes}function H(b=new Uint8Array,...p){let w=Pt(...p);return T(s(g(w,j("context",b),!!o)))}function O(b,p,w={}){b=j("message",b),o&&(b=o(b));let{prefix:A,scalar:C,pointBytes:K}=L(p),P=H(w.context,A,b),k=v.multiply(P).toRawBytes(),N=H(w.context,k,K,b),M=I(P+N*C);lt("signature.s",M,Bt,n);let z=Pt(k,se(M,e.BYTES));return j("result",z,e.BYTES*2)}let X=Yc;function S(b,p,w,A=X){let{context:C,zip215:K}=A,P=e.BYTES;b=j("signature",b,2*P),p=j("message",p),w=j("publicKey",w,P),K!==void 0&&Et("zip215",K),o&&(p=o(p));let k=jt(b.slice(P,2*P)),N,M,z;try{N=m.fromHex(w,K),M=m.fromHex(b.slice(0,P),K),z=v.multiplyUnsafe(k)}catch{return!1}if(!K&&N.isSmallOrder())return!1;let Q=H(C,M.toRawBytes(),N.toRawBytes(),p);return M.add(N.multiplyUnsafe(Q)).subtract(z).clearCofactor().equals(m.ZERO)}return v._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:O,verify:S,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,p=m.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var dn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),jo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),gu=BigInt(0),$c=BigInt(1),Wo=BigInt(2),wu=BigInt(3),Jc=BigInt(5),Qc=BigInt(8);function ta(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=dn,c=r*r%s*r%s,a=G(c,Wo,s)*c%s,u=G(a,$c,s)*r%s,f=G(u,Jc,s)*u%s,h=G(f,t,s)*f%s,d=G(h,e,s)*h%s,E=G(d,n,s)*d%s,g=G(E,o,s)*E%s,y=G(g,o,s)*E%s,l=G(y,t,s)*f%s;return{pow_p_5_8:G(l,Wo,s)*r%s,b2:c}}function ea(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function ra(r,t){let e=dn,n=V(t*t*t,e),o=V(n*n*t,e),s=ta(r*o).pow_p_5_8,i=V(r*n*s,e),c=V(t*i*i,e),a=i,u=V(i*jo,e),f=c===r,h=c===V(-r,e),d=c===V(-r*jo,e);return f&&(i=a),(h||d)&&(i=u),Mo(i,e)&&(i=V(-i,e)),{isValid:f||h,value:i}}var na=Yt(dn,void 0,!0),oa={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:na,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Qc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ur,randomBytes:Se,adjustScalarBytes:ea,uvRatio:ra},ve=Go(oa);var Ie=32,Ut=64,gr=32;function Yo(){let r=ve.utils.randomPrivateKey(),t=ve.getPublicKey(r);return{privateKey:Qo(r,t),publicKey:t}}function Xo(r){if(r.length!==gr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(r instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=r,e=ve.getPublicKey(t);return{privateKey:Qo(t,e),publicKey:e}}function $o(r,t){let e=r.subarray(0,gr);return ve.sign(t instanceof Uint8Array?t:t.subarray(),e)}function Jo(r,t,e){return ve.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function Qo(r,t){let e=new Uint8Array(Ut);for(let n=0;n<gr;n++)e[n]=r[n],e[gr+n]=t[n];return e}var ze=class{type="Ed25519";raw;constructor(t){this.raw=Le(t,Ie)}toMultihash(){return He.digest(Fe(this))}toCID(){return It.createV1(114,this.toMultihash())}toString(){return it.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e){return Jo(this.raw,e,t)}},ae=class{type="Ed25519";raw;publicKey;constructor(t,e){this.raw=Le(t,Ut),this.publicKey=new ze(e)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t){return $o(this.raw,t)}};function pn(r){if(r.length>Ut){r=Le(r,Ut+Ie);let n=r.subarray(0,Ut),o=r.subarray(Ut,r.length);return new ae(n,o)}r=Le(r,Ut);let t=r.subarray(0,Ut),e=r.subarray(Ie);return new ae(t,e)}function wr(r){return r=Le(r,Ie),new ze(r)}async function es(){let{privateKey:r,publicKey:t}=Yo();return new ae(r,t)}async function rs(r){let{privateKey:t,publicKey:e}=Xo(r);return new ae(t,e)}function Le(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Ot(r=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}var sa=Math.pow(2,7),ia=Math.pow(2,14),ca=Math.pow(2,21),ns=Math.pow(2,28),os=Math.pow(2,35),ss=Math.pow(2,42),is=Math.pow(2,49),ft=128,Xt=127;function Ze(r){if(r<sa)return 1;if(r<ia)return 2;if(r<ca)return 3;if(r<ns)return 4;if(r<os)return 5;if(r<ss)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function cs(r,t,e=0){switch(Ze(r)){case 8:t[e++]=r&255|ft,r/=128;case 7:t[e++]=r&255|ft,r/=128;case 6:t[e++]=r&255|ft,r/=128;case 5:t[e++]=r&255|ft,r/=128;case 4:t[e++]=r&255|ft,r>>>=7;case 3:t[e++]=r&255|ft,r>>>=7;case 2:t[e++]=r&255|ft,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function as(r,t){let e=r[t],n=0;if(n+=e&Xt,e<ft||(e=r[t+1],n+=(e&Xt)<<7,e<ft)||(e=r[t+2],n+=(e&Xt)<<14,e<ft)||(e=r[t+3],n+=(e&Xt)<<21,e<ft)||(e=r[t+4],n+=(e&Xt)*ns,e<ft)||(e=r[t+5],n+=(e&Xt)*os,e<ft)||(e=r[t+6],n+=(e&Xt)*ss,e<ft)||(e=r[t+7],n+=(e&Xt)*is,e<ft))return n;throw new RangeError("Could not decode varint")}var mn=new Float32Array([-0]),$t=new Uint8Array(mn.buffer);function fs(r,t,e){mn[0]=r,t[e]=$t[0],t[e+1]=$t[1],t[e+2]=$t[2],t[e+3]=$t[3]}function us(r,t){return $t[0]=r[t],$t[1]=r[t+1],$t[2]=r[t+2],$t[3]=r[t+3],mn[0]}var bn=new Float64Array([-0]),ct=new Uint8Array(bn.buffer);function hs(r,t,e){bn[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function ls(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],bn[0]}var aa=BigInt(Number.MAX_SAFE_INTEGER),fa=BigInt(Number.MIN_SAFE_INTEGER),bt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return fe;if(t<aa&&t>fa)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ds&&(o=0n,++n>ds&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new bt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var ds=4294967296n;function ps(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ms(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[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 yn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function St(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Er(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var xn=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 Er(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw St(this,4);return Er(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw St(this,4);let t=us(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw St(this,4);let t=ls(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw St(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ms(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 bt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw St(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.