@libp2p/keychain 4.1.2 → 4.1.3-f30e2ee8d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +2 -2
- package/package.json +7 -7
- package/dist/typedoc-urls.json +0 -14
package/dist/index.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PKeychain = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PKeychain=(()=>{var $c=Object.create;var zr=Object.defineProperty;var qc=Object.getOwnPropertyDescriptor;var jc=Object.getOwnPropertyNames;var Yc=Object.getPrototypeOf,Gc=Object.prototype.hasOwnProperty;var Re=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ct=(r,t)=>{for(var e in t)zr(r,e,{get:t[e],enumerable:!0})},qi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of jc(t))!Gc.call(r,s)&&s!==e&&zr(r,s,{get:()=>t[s],enumerable:!(n=qc(t,s))||n.enumerable});return r};var gs=(r,t,e)=>(e=r!=null?$c(Yc(r)):{},qi(t||!r||!r.__esModule?zr(e,"default",{value:r,enumerable:!0}):e,r)),zc=r=>qi(zr({},"__esModule",{value:!0}),r);var ea=Re(ar=>{"use strict";var Ef="[object ArrayBuffer]",Qt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Ef}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let o of e)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of e){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},di="string",vf=/^[0-9a-f]+$/i,Bf=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Af=/^[a-zA-Z0-9-_]+$/,xn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=Qt.toUint8Array(t),n="";for(let i=0;i<e.length;i++)n+=String.fromCharCode(e[i]);return decodeURIComponent(escape(n))}},It=class{static toString(t,e=!1){let n=Qt.toArrayBuffer(t),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,e);i+=String.fromCharCode(a)}return i}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let i=0;i<t.length;i++)s.setUint16(i*2,t.charCodeAt(i),e);return n}},En=class r{static isHex(t){return typeof t===di&&vf.test(t)}static isBase64(t){return typeof t===di&&Bf.test(t)}static isBase64Url(t){return typeof t===di&&Af.test(t)}static ToString(t,e="utf8"){let n=Qt.toUint8Array(t);switch(e.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return It.toString(n,!0);case"utf16":case"utf16be":return It.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return It.fromString(t,!0);case"utf16":case"utf16be":return It.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=Qt.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return xn.fromString(t);case"utf16":case"utf16be":return It.fromString(t);case"utf16le":case"usc2":return It.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return xn.toString(t);case"utf16":case"utf16be":return It.toString(t);case"utf16le":case"usc2":return It.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=Qt.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=Qt.toUint8Array(t),n="",s=e.length;for(let i=0;i<s;i++){let o=e[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let i=e.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(t,e=!1){return It.toString(t,e)}static FromUtf16String(t,e=!1){return It.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};En.DEFAULT_UTF8_ENCODING="utf8";function Sf(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)e[i]=s[i]}return e}function kf(...r){let t=r.map(s=>s.byteLength).reduce((s,i)=>s+i),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)e[n++]=i}),e.buffer}function If(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}ar.BufferSourceConverter=Qt;ar.Convert=En;ar.assign=Sf;ar.combine=kf;ar.isEqual=If});var gc=Re((yy,pc)=>{"use strict";pc.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}});var Ec=Re((wc,xc)=>{"use strict";var fs=gc(),{hasOwnProperty:mc}=Object.prototype,{propertyIsEnumerable:hh}=Object,gr=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),dh=wc,yc={concatArrays:!1,ignoreUndefined:!1},hs=r=>{let t=[];for(let e in r)mc.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)hh.call(r,n)&&t.push(n)}return t};function yr(r){return Array.isArray(r)?ph(r):fs(r)?gh(r):r}function ph(r){let t=r.slice(0,0);return hs(r).forEach(e=>{gr(t,e,yr(r[e]))}),t}function gh(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return hs(r).forEach(e=>{gr(t,e,yr(r[e]))}),t}var bc=(r,t,e,n)=>(e.forEach(s=>{typeof t[s]>"u"&&n.ignoreUndefined||(s in r&&r[s]!==Object.getPrototypeOf(r)?gr(r,s,Ui(r[s],t[s],n)):gr(r,s,yr(t[s])))}),r),yh=(r,t,e)=>{let n=r.slice(0,0),s=0;return[r,t].forEach(i=>{let o=[];for(let a=0;a<i.length;a++)mc.call(i,a)&&(o.push(String(a)),i===r?gr(n,s++,i[a]):gr(n,s++,yr(i[a])));n=bc(n,i,hs(i).filter(a=>!o.includes(a)),e)}),n};function Ui(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?yh(r,t,e):!fs(t)||!fs(r)?yr(t):bc(r,t,hs(t),e)}xc.exports=function(...r){let t=Ui(yr(yc),this!==dh&&this||{},yc),e={_:{}};for(let n of r)if(n!==void 0){if(!fs(n))throw new TypeError("`"+n+"` is not an Option Object");e=Ui(e,{_:n},t)}return e._}});var Sc=Re((by,Ac)=>{"use strict";function mh(r){return r>=55296&&r<=56319}function bh(r){return r>=56320&&r<=57343}Ac.exports=function(t,e,n){if(typeof e!="string")throw new Error("Input must be string");for(var s=e.length,i=0,o,a,c=0;c<s;c+=1){if(o=e.charCodeAt(c),a=e[c],mh(o)&&bh(e.charCodeAt(c+1))&&(c+=1,a+=e[c]),i+=t(a),i===n)return e.slice(0,c+1);if(i>n)return e.slice(0,c-a.length+1)}return e}});var Ic=Re((wy,kc)=>{"use strict";function wh(r){return r>=55296&&r<=56319}function xh(r){return r>=56320&&r<=57343}kc.exports=function(t){if(typeof t!="string")throw new Error("Input must be string");for(var e=t.length,n=0,s=null,i=null,o=0;o<e;o++)s=t.charCodeAt(o),xh(s)?i!=null&&wh(i)?n+=1:n+=3:s<=127?n+=1:s>=128&&s<=2047?n+=2:s>=2048&&s<=65535&&(n+=3),i=s;return n}});var _c=Re((xy,Rc)=>{"use strict";var Eh=Sc(),vh=Ic();Rc.exports=Eh.bind(null,vh)});var Cc=Re((Ey,Tc)=>{"use strict";var Bh=_c(),Ah=/[\/\?<>\\:\*\|"]/g,Sh=/[\x00-\x1f\x80-\x9f]/g,kh=/^\.+$/,Ih=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,Rh=/[\. ]+$/;function Nc(r,t){if(typeof r!="string")throw new Error("Input must be string");var e=r.replace(Ah,t).replace(Sh,t).replace(kh,t).replace(Ih,t).replace(Rh,t);return Bh(e,255)}Tc.exports=function(r,t){var e=t&&t.replacement||"",n=Nc(r,e);return e===""?n:Nc(n,"")}});var Th={};ct(Th,{keychain:()=>Nh});var mt={get(r=globalThis){let t=r.crypto;if(t==null||t.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return t}};var ys=Symbol.for("@libp2p/peer-id");var B=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var ji=Symbol.for("@libp2p/service-capabilities"),Vh=Symbol.for("@libp2p/service-dependencies");var fi={};ct(fi,{Ed25519PrivateKey:()=>Oe,Ed25519PublicKey:()=>Ir,generateKeyPair:()=>xf,generateKeyPairFromSeed:()=>Zo,unmarshalEd25519PrivateKey:()=>bf,unmarshalEd25519PublicKey:()=>wf});var Es={};ct(Es,{base58btc:()=>bt,base58flickr:()=>tl});var od=new Uint8Array(0);function Yi(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 jt(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 Gi(r){return new TextEncoder().encode(r)}function zi(r){return new TextDecoder().decode(r)}function Wc(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,g=0,m=0,A=p.length;m!==A&&p[m]===0;)m++,h++;for(var b=(A-m)*l+1>>>0,T=new Uint8Array(b);m!==A;){for(var x=p[m],S=0,_=b-1;(x!==0||S<g)&&_!==-1;_--,S++)x+=256*T[_]>>>0,T[_]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");g=S,m++}for(var N=b-g;N!==b&&T[N]===0;)N++;for(var Y=c.repeat(h);N<b;++N)Y+=r.charAt(T[N]);return Y}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var g=0,m=0;p[h]===c;)g++,h++;for(var A=(p.length-h)*f+1>>>0,b=new Uint8Array(A);p[h];){var T=e[p.charCodeAt(h)];if(T===255)return;for(var x=0,S=A-1;(T!==0||x<m)&&S!==-1;S--,x++)T+=a*b[S]>>>0,b[S]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");m=x,h++}if(p[h]!==" "){for(var _=A-m;_!==A&&b[_]===0;)_++;for(var N=new Uint8Array(g+(A-_)),Y=g;_!==A;)N[Y++]=b[_++];return N}}}function w(p){var h=d(p);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:d,decode:w}}var Zc=Wc,Jc=Zc,Zi=Jc;var ms=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")}},bs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 Ji(this,t)}},ws=class{decoders;constructor(t){this.decoders=t}or(t){return Ji(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 Ji(r,t){return new ws({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var xs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ms(t,e,n),this.decoder=new bs(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Fe({name:r,prefix:t,encode:e,decode:n}){return new xs(r,t,e,n)}function ce({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Zi(e,r);return Fe({prefix:t,name:r,encode:n,decode:i=>jt(s(i))})}function Xc(r,t,e,n){let s={};for(let l=0;l<t.length;++l)s[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let l=0;l<i;++l){let u=s[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Qc(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;i.length*e&7;)i+="=";return i}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Fe({prefix:t,name:r,encode(s){return Qc(s,n,e)},decode(s){return Xc(s,n,e,r)}})}var bt=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tl=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bs={};ct(Bs,{identity:()=>Yt});var el=to,Xi=128,rl=127,nl=~rl,sl=Math.pow(2,31);function to(r,t,e){t=t||[],e=e||0;for(var n=e;r>=sl;)t[e++]=r&255|Xi,r/=128;for(;r&nl;)t[e++]=r&255|Xi,r>>>=7;return t[e]=r|0,to.bytes=e-n+1,t}var il=vs,ol=128,Qi=127;function vs(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw vs.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Qi)<<s:(o&Qi)*Math.pow(2,s),s+=7}while(o>=ol);return vs.bytes=i-n,e}var al=Math.pow(2,7),cl=Math.pow(2,14),ll=Math.pow(2,21),ul=Math.pow(2,28),fl=Math.pow(2,35),hl=Math.pow(2,42),dl=Math.pow(2,49),pl=Math.pow(2,56),gl=Math.pow(2,63),yl=function(r){return r<al?1:r<cl?2:r<ll?3:r<ul?4:r<fl?5:r<hl?6:r<dl?7:r<pl?8:r<gl?9:10},ml={encode:el,decode:il,encodingLength:yl},bl=ml,br=bl;function wr(r,t=0){return[br.decode(r,t),br.decode.bytes]}function $e(r,t,e=0){return br.encode(r,t,e),t}function qe(r){return br.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=qe(r),s=n+qe(e),i=new Uint8Array(s+e);return $e(r,i,0),$e(e,i,n),i.set(t,s),new je(r,e,t,i)}function xr(r){let t=jt(r),[e,n]=wr(t),[s,i]=wr(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new je(e,s,o,t)}function eo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Yi(r.bytes,e.bytes)}}var je=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var ro=0,wl="identity",no=jt;function xl(r){return Dt(ro,no(r))}var Yt={code:ro,name:wl,encode:no,digest:xl};var ks={};ct(ks,{sha256:()=>ht,sha512:()=>El});function Ss({name:r,code:t,encode:e}){return new As(r,t,e)}var As=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function io(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ht=Ss({name:"sha2-256",code:18,encode:io("SHA-256")}),El=Ss({name:"sha2-512",code:19,encode:io("SHA-512")});function St(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 Vt(r=0){return new Uint8Array(r)}function Is(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=Vt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var Rs={};ct(Rs,{base10:()=>vl});var vl=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var _s={};ct(_s,{base16:()=>Bl,base16upper:()=>Al});var Bl=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Al=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ns={};ct(Ns,{base2:()=>Sl});var Sl=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ts={};ct(Ts,{base256emoji:()=>Nl});var oo=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}"),kl=oo.reduce((r,t,e)=>(r[e]=t,r),[]),Il=oo.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Rl(r){return r.reduce((t,e)=>(t+=kl[e],t),"")}function _l(r){let t=[];for(let e of r){let n=Il[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Nl=Fe({prefix:"\u{1F680}",name:"base256emoji",encode:Rl,decode:_l});var Cs={};ct(Cs,{base32:()=>Ge,base32hex:()=>Ul,base32hexpad:()=>Vl,base32hexpadupper:()=>Ol,base32hexupper:()=>Dl,base32pad:()=>Cl,base32padupper:()=>Ll,base32upper:()=>Tl,base32z:()=>Hl});var Ge=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Tl=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Cl=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ll=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ul=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Dl=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vl=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ol=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hl=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ls={};ct(Ls,{base36:()=>Pl,base36upper:()=>Kl});var Pl=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Kl=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Us={};ct(Us,{base64:()=>_e,base64pad:()=>Ml,base64url:()=>Fl,base64urlpad:()=>$l});var _e=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ml=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fl=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$l=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ds={};ct(Ds,{base8:()=>ql});var ql=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vs={};ct(Vs,{identity:()=>jl});var jl=Fe({prefix:"\0",name:"identity",encode:r=>zi(r),decode:r=>Gi(r)});var Ud=new TextEncoder,Dd=new TextDecoder;function ao(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Wl(e,Os(r),t??bt.encoder);default:return Zl(e,Os(r),t??Ge.encoder)}}var co=new WeakMap;function Os(r){let t=co.get(r);if(t==null){let e=new Map;return co.set(r,e),e}return t}var le=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Jl)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=Dt(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&&eo(t.multihash,n.multihash)}toString(t){return ao(this,t)}toJSON(){return{"/":ao(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:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??lo(n,s,i.bytes))}else if(e[Xl]===!0){let{version:n,multihash:s,code:i}=e,o=xr(s);return r.create(n,i,o)}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!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=lo(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Er,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,s=jt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new je(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,d]=wr(t.subarray(e));return e+=d,u},s=n(),i=Er;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),f=e+c,l=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=zl(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Os(i).set(n,t),i}};function zl(r,t){switch(r[0]){case"Q":{let e=t??bt;return[bt.prefix,e.decode(`${bt.prefix}${r}`)]}case bt.prefix:{let e=t??bt;return[bt.prefix,e.decode(r)]}case Ge.prefix:{let e=t??Ge;return[Ge.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Wl(r,t,e){let{prefix:n}=e;if(n!==bt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function Zl(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Er=112,Jl=18;function lo(r,t,e){let n=qe(r),s=n+qe(t),i=new Uint8Array(s+e.byteLength);return $e(r,i,0),$e(t,i,n),i.set(e,s),i}var Xl=Symbol.for("@ipld/js-cid/CID");var ze={...Vs,...Ns,...Ds,...Rs,..._s,...Cs,...Ls,...Es,...Us,...Ts},Jd={...ks,...Bs};function fo(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var uo=fo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hs=fo("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ql={utf8:uo,"utf-8":uo,hex:ze.base16,latin1:Hs,ascii:Hs,binary:Hs,...ze},Zr=Ql;function P(r,t="utf8"){let e=Zr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function kt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function We(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function tu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ze(r,...t){if(!tu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Jr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");We(r.outputLen),We(r.blockLen)}function Je(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 ho(r,t){Ze(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Xr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Ne=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),_t=(r,t)=>r<<32-t|r>>>t,Qr=(r,t)=>r<<t|r>>>32-t>>>0,f0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var eu=async()=>{};async function po(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let i=Date.now()-n;i>=0&&i<t||(await eu(),n+=i)}}function go(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ue(r){return typeof r=="string"&&(r=go(r)),Ze(r),r}function Ps(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Ze(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}var Xe=class{clone(){return this._cloneInto()}},ru={}.toString;function yo(r,t){if(t!==void 0&&ru.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function Qe(r){let t=n=>r().update(ue(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function tr(r=32){if(Xr&&typeof Xr.getRandomValues=="function")return Xr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function nu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(e>>s&i),a=Number(e&i),c=n?4:0,f=n?0:4;r.setUint32(t+c,o,n),r.setUint32(t+f,a,n)}var tn=(r,t,e)=>r&t^~r&e,en=(r,t,e)=>r&t^r&e^t&e,fe=class extends Xe{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ne(this.buffer)}update(t){Je(this);let{view:e,buffer:n,blockLen:s}=this;t=ue(t);let i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Ne(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Je(this),ho(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let u=o;u<s;u++)e[u]=0;nu(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=Ne(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],i)}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:s,finished:i,destroyed:o,pos:a}=this;return t.length=s,t.pos=a,t.finished=i,t.destroyed=o,s%e&&t.buffer.set(n),t}};var rn=BigInt(4294967295),Ks=BigInt(32);function mo(r,t=!1){return t?{h:Number(r&rn),l:Number(r>>Ks&rn)}:{h:Number(r>>Ks&rn)|0,l:Number(r&rn)|0}}function su(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=mo(r[s],t);[e[s],n[s]]=[i,o]}return[e,n]}var iu=(r,t)=>BigInt(r>>>0)<<Ks|BigInt(t>>>0),ou=(r,t,e)=>r>>>e,au=(r,t,e)=>r<<32-e|t>>>e,cu=(r,t,e)=>r>>>e|t<<32-e,lu=(r,t,e)=>r<<32-e|t>>>e,uu=(r,t,e)=>r<<64-e|t>>>e-32,fu=(r,t,e)=>r>>>e-32|t<<64-e,hu=(r,t)=>t,du=(r,t)=>r,pu=(r,t,e)=>r<<e|t>>>32-e,gu=(r,t,e)=>t<<e|r>>>32-e,yu=(r,t,e)=>t<<e-32|r>>>64-e,mu=(r,t,e)=>r<<e-32|t>>>64-e;function bu(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var wu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),xu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Eu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vu=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Bu=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Au=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var Su={fromBig:mo,split:su,toBig:iu,shrSH:ou,shrSL:au,rotrSH:cu,rotrSL:lu,rotrBH:uu,rotrBL:fu,rotr32H:hu,rotr32L:du,rotlSH:pu,rotlSL:gu,rotlBH:yu,rotlBL:mu,add:bu,add3L:wu,add3H:xu,add4L:Eu,add4H:vu,add5H:Au,add5L:Bu},U=Su;var[ku,Iu]=U.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))),he=new Uint32Array(80),de=new Uint32Array(80),Ms=class extends fe{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:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:d,Gh:w,Gl:p,Hh:h,Hl:g}=this;return[t,e,n,s,i,o,a,c,f,l,u,d,w,p,h,g]}set(t,e,n,s,i,o,a,c,f,l,u,d,w,p,h,g){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=w|0,this.Gl=p|0,this.Hh=h|0,this.Hl=g|0}process(t,e){for(let b=0;b<16;b++,e+=4)he[b]=t.getUint32(e),de[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let T=he[b-15]|0,x=de[b-15]|0,S=U.rotrSH(T,x,1)^U.rotrSH(T,x,8)^U.shrSH(T,x,7),_=U.rotrSL(T,x,1)^U.rotrSL(T,x,8)^U.shrSL(T,x,7),N=he[b-2]|0,Y=de[b-2]|0,$=U.rotrSH(N,Y,19)^U.rotrBH(N,Y,61)^U.shrSH(N,Y,6),D=U.rotrSL(N,Y,19)^U.rotrBL(N,Y,61)^U.shrSL(N,Y,6),nt=U.add4L(_,D,de[b-7],de[b-16]),et=U.add4H(nt,S,$,he[b-7],he[b-16]);he[b]=et|0,de[b]=nt|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:d,Fh:w,Fl:p,Gh:h,Gl:g,Hh:m,Hl:A}=this;for(let b=0;b<80;b++){let T=U.rotrSH(u,d,14)^U.rotrSH(u,d,18)^U.rotrBH(u,d,41),x=U.rotrSL(u,d,14)^U.rotrSL(u,d,18)^U.rotrBL(u,d,41),S=u&w^~u&h,_=d&p^~d&g,N=U.add5L(A,x,_,Iu[b],de[b]),Y=U.add5H(N,m,T,S,ku[b],he[b]),$=N|0,D=U.rotrSH(n,s,28)^U.rotrBH(n,s,34)^U.rotrBH(n,s,39),nt=U.rotrSL(n,s,28)^U.rotrBL(n,s,34)^U.rotrBL(n,s,39),et=n&i^n&a^i&a,At=s&o^s&c^o&c;m=h|0,A=g|0,h=w|0,g=p|0,w=u|0,p=d|0,{h:u,l:d}=U.add(f|0,l|0,Y|0,$|0),f=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let E=U.add3L($,nt,At);n=U.add3H(E,Y,D,et),s=E|0}({h:n,l:s}=U.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=U.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=U.add(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:d}=U.add(this.Eh|0,this.El|0,u|0,d|0),{h:w,l:p}=U.add(this.Fh|0,this.Fl|0,w|0,p|0),{h,l:g}=U.add(this.Gh|0,this.Gl|0,h|0,g|0),{h:m,l:A}=U.add(this.Hh|0,this.Hl|0,m|0,A|0),this.set(n,s,i,o,a,c,f,l,u,d,w,p,h,g,m,A)}roundClean(){he.fill(0),de.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 Te=Qe(()=>new Ms);var sn={};ct(sn,{abytes:()=>er,bitGet:()=>Uu,bitLen:()=>Lu,bitMask:()=>vr,bitSet:()=>Du,bytesToHex:()=>zt,bytesToNumberBE:()=>Wt,bytesToNumberLE:()=>ge,concatBytes:()=>Zt,createHmacDrbg:()=>qs,ensureBytes:()=>tt,equalBytes:()=>Tu,hexToBytes:()=>Ce,hexToNumber:()=>$s,isBytes:()=>pe,numberToBytesBE:()=>ye,numberToBytesLE:()=>Le,numberToHexUnpadded:()=>Eo,numberToVarBytesBE:()=>Nu,utf8ToBytes:()=>Cu,validateObject:()=>Ot});var xo=BigInt(0),nn=BigInt(1),Ru=BigInt(2);function pe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function er(r){if(!pe(r))throw new Error("Uint8Array expected")}var _u=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function zt(r){er(r);let t="";for(let e=0;e<r.length;e++)t+=_u[r[e]];return t}function Eo(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function $s(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Gt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function bo(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt._A&&r<=Gt._F)return r-(Gt._A-10);if(r>=Gt._a&&r<=Gt._f)return r-(Gt._a-10)}function Ce(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("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,i=0;s<e;s++,i+=2){let o=bo(r.charCodeAt(i)),a=bo(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Wt(r){return $s(zt(r))}function ge(r){return er(r),$s(zt(Uint8Array.from(r).reverse()))}function ye(r,t){return Ce(r.toString(16).padStart(t*2,"0"))}function Le(r,t){return ye(r,t).reverse()}function Nu(r){return Ce(Eo(r))}function tt(r,t,e){let n;if(typeof t=="string")try{n=Ce(t)}catch(i){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${i}`)}else if(pe(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function Zt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];er(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function Tu(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 Cu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Lu(r){let t;for(t=0;r>xo;r>>=nn,t+=1);return t}function Uu(r,t){return r>>BigInt(t)&nn}function Du(r,t,e){return r|(e?nn:xo)<<BigInt(t)}var vr=r=>(Ru<<BigInt(r-1))-nn,Fs=r=>new Uint8Array(r),wo=r=>Uint8Array.from(r);function qs(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=Fs(r),s=Fs(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...u)=>e(s,n,...u),c=(u=Fs())=>{s=a(wo([0]),u),n=a(),u.length!==0&&(s=a(wo([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,d=[];for(;u<t;){n=a();let w=n.slice();d.push(w),u+=n.length}return Zt(...d)};return(u,d)=>{o(),c(u);let w;for(;!(w=d(f()));)c();return o(),w}}var Vu={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"||pe(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 Ot(r,t,e={}){let n=(s,i,o)=>{let a=Vu[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(t))n(s,i,!1);for(let[s,i]of Object.entries(e))n(s,i,!0);return r}var at=BigInt(0),Z=BigInt(1),Ue=BigInt(2),Ou=BigInt(3),js=BigInt(4),vo=BigInt(5),Bo=BigInt(8),Hu=BigInt(9),Pu=BigInt(16);function z(r,t){let e=r%t;return e>=at?e:t+e}function Ku(r,t,e){if(e<=at||t<at)throw new Error("Expected power/modulo > 0");if(e===Z)return at;let n=Z;for(;t>at;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function J(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function on(r,t){if(r===at||t<=at)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=z(r,t),n=t,s=at,i=Z,o=Z,a=at;for(;e!==at;){let f=n/e,l=n%e,u=s-o*f,d=i-a*f;n=e,e=l,s=o,i=a,o=u,a=d}if(n!==Z)throw new Error("invert: does not exist");return z(s,t)}function Mu(r){let t=(r-Z)/Ue,e,n,s;for(e=r-Z,n=0;e%Ue===at;e/=Ue,n++);for(s=Ue;s<r&&Ku(s,t,r)!==r-Z;s++);if(n===1){let o=(r+Z)/js;return function(c,f){let l=c.pow(f,o);if(!c.eql(c.sqr(l),f))throw new Error("Cannot find square root");return l}}let i=(e+Z)/Ue;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,l=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,i),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let w=1;for(let h=a.sqr(d);w<f&&!a.eql(h,a.ONE);w++)h=a.sqr(h);let p=a.pow(l,Z<<BigInt(f-w-1));l=a.sqr(p),u=a.mul(u,p),d=a.mul(d,l),f=w}return u}}function Fu(r){if(r%js===Ou){let t=(r+Z)/js;return function(n,s){let i=n.pow(s,t);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Bo===vo){let t=(r-vo)/Bo;return function(n,s){let i=n.mul(s,Ue),o=n.pow(i,t),a=n.mul(s,o),c=n.mul(n.mul(a,Ue),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%Pu,Mu(r)}var Ao=(r,t)=>(z(r,t)&Z)===Z,$u=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ys(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=$u.reduce((n,s)=>(n[s]="function",n),t);return Ot(r,e)}function qu(r,t,e){if(e<at)throw new Error("Expected power > 0");if(e===at)return r.ONE;if(e===Z)return t;let n=r.ONE,s=t;for(;e>at;)e&Z&&(n=r.mul(n,s)),s=r.sqr(s),e>>=Z;return n}function ju(r,t){let e=new Array(t.length),n=t.reduce((i,o,a)=>r.is0(o)?i:(e[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return t.reduceRight((i,o,a)=>r.is0(o)?i:(e[a]=r.mul(i,e[a]),r.mul(i,o)),s),e}function Gs(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function an(r,t,e=!1,n={}){if(r<=at)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=Gs(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Fu(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:vr(s),ZERO:at,ONE:Z,create:c=>z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&Z)===Z,neg:c=>z(-c,r),eql:(c,f)=>c===f,sqr:c=>z(c*c,r),add:(c,f)=>z(c+f,r),sub:(c,f)=>z(c-f,r),mul:(c,f)=>z(c*f,r),pow:(c,f)=>qu(a,c,f),div:(c,f)=>z(c*on(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>on(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>ju(a,c),cmov:(c,f,l)=>l?f:c,toBytes:c=>e?Le(c,i):ye(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return e?ge(c):Wt(c)}});return Object.freeze(a)}function So(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 zs(r){let t=So(r);return t+Math.ceil(t/2)}function ko(r,t,e=!1){let n=r.length,s=So(t),i=zs(t);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=e?Wt(r):ge(r),a=z(o,t-Z)+Z;return e?Le(a,s):ye(a,s)}var Gu=BigInt(0),Ws=BigInt(1);function cn(r,t){let e=(s,i)=>{let o=i.negate();return s?o:i},n=s=>{let i=Math.ceil(t/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:e,unsafeLadder(s,i){let o=r.ZERO,a=s;for(;i>Gu;)i&Ws&&(o=o.add(a)),a=a.double(),i>>=Ws;return o},precomputeWindow(s,i){let{windows:o,windowSize:a}=n(i),c=[],f=s,l=f;for(let u=0;u<o;u++){l=f,c.push(l);for(let d=1;d<a;d++)l=l.add(f),c.push(l);f=l.double()}return c},wNAF(s,i,o){let{windows:a,windowSize:c}=n(s),f=r.ZERO,l=r.BASE,u=BigInt(2**s-1),d=2**s,w=BigInt(s);for(let p=0;p<a;p++){let h=p*c,g=Number(o&u);o>>=w,g>c&&(g-=d,o+=Ws);let m=h,A=h+Math.abs(g)-1,b=p%2!==0,T=g<0;g===0?l=l.add(e(b,i[m])):f=f.add(e(T,i[A]))}return{p:f,f:l}},wNAFCached(s,i,o,a){let c=s._WINDOW_SIZE||1,f=i.get(s);return f||(f=this.precomputeWindow(s,c),c!==1&&i.set(s,a(f))),this.wNAF(c,f,o)}}}function Br(r){return Ys(r.Fp),Ot(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Gs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Nt=BigInt(0),vt=BigInt(1),ln=BigInt(2),zu=BigInt(8),Wu={zip215:!0};function Zu(r){let t=Br(r);return Ot(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Io(r){let t=Zu(r),{Fp:e,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=t,f=ln<<BigInt(a*8)-vt,l=e.create,u=t.uvRatio||((v,y)=>{try{return{isValid:!0,value:e.sqrt(v*e.inv(y))}}catch{return{isValid:!1,value:Nt}}}),d=t.adjustScalarBytes||(v=>v),w=t.domain||((v,y,I)=>{if(y.length||I)throw new Error("Contexts/pre-hash are not supported");return v}),p=v=>typeof v=="bigint"&&Nt<v,h=(v,y)=>p(v)&&p(y)&&v<y,g=v=>v===Nt||h(v,f);function m(v,y){if(h(v,y))return v;throw new Error(`Expected valid scalar < ${y}, got ${typeof v} ${v}`)}function A(v){return v===Nt?v:m(v,n)}let b=new Map;function T(v){if(!(v instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(y,I,C,L){if(this.ex=y,this.ey=I,this.ez=C,this.et=L,!g(y))throw new Error("x required");if(!g(I))throw new Error("y required");if(!g(C))throw new Error("z required");if(!g(L))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof x)throw new Error("extended point not allowed");let{x:I,y:C}=y||{};if(!g(I)||!g(C))throw new Error("invalid affine point");return new x(I,C,vt,l(I*C))}static normalizeZ(y){let I=e.invertBatch(y.map(C=>C.ez));return y.map((C,L)=>C.toAffine(I[L])).map(x.fromAffine)}_setWindowSize(y){this._WINDOW_SIZE=y,b.delete(this)}assertValidity(){let{a:y,d:I}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:C,ey:L,ez:O,et:H}=this,j=l(C*C),M=l(L*L),q=l(O*O),st=l(q*q),X=l(j*y),ut=l(q*l(X+M)),ft=l(st+l(I*l(j*M)));if(ut!==ft)throw new Error("bad point: equation left != right (1)");let ot=l(C*L),pt=l(O*H);if(ot!==pt)throw new Error("bad point: equation left != right (2)")}equals(y){T(y);let{ex:I,ey:C,ez:L}=this,{ex:O,ey:H,ez:j}=y,M=l(I*j),q=l(O*L),st=l(C*j),X=l(H*L);return M===q&&st===X}is0(){return this.equals(x.ZERO)}negate(){return new x(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:y}=t,{ex:I,ey:C,ez:L}=this,O=l(I*I),H=l(C*C),j=l(ln*l(L*L)),M=l(y*O),q=I+C,st=l(l(q*q)-O-H),X=M+H,ut=X-j,ft=M-H,ot=l(st*ut),pt=l(X*ft),qt=l(st*ft),Ie=l(ut*X);return new x(ot,pt,Ie,qt)}add(y){T(y);let{a:I,d:C}=t,{ex:L,ey:O,ez:H,et:j}=this,{ex:M,ey:q,ez:st,et:X}=y;if(I===BigInt(-1)){let Oi=l((O-L)*(q+M)),Hi=l((O+L)*(q-M)),ps=l(Hi-Oi);if(ps===Nt)return this.double();let Pi=l(H*ln*X),Ki=l(j*ln*st),Mi=Ki+Pi,Fi=Hi+Oi,$i=Ki-Pi,Pc=l(Mi*ps),Kc=l(Fi*$i),Mc=l(Mi*$i),Fc=l(ps*Fi);return new x(Pc,Kc,Fc,Mc)}let ut=l(L*M),ft=l(O*q),ot=l(j*C*X),pt=l(H*st),qt=l((L+O)*(M+q)-ut-ft),Ie=pt-ot,mr=pt+ot,Vi=l(ft-I*ut),Dc=l(qt*Ie),Vc=l(mr*Vi),Oc=l(qt*Vi),Hc=l(Ie*mr);return new x(Dc,Vc,Hc,Oc)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,b,y,x.normalizeZ)}multiply(y){let{p:I,f:C}=this.wNAF(m(y,n));return x.normalizeZ([I,C])[0]}multiplyUnsafe(y){let I=A(y);return I===Nt?_:this.equals(_)||I===vt?this:this.equals(S)?this.wNAF(I).p:N.unsafeLadder(this,I)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){let{ex:I,ey:C,ez:L}=this,O=this.is0();y==null&&(y=O?zu:e.inv(L));let H=l(I*y),j=l(C*y),M=l(L*y);if(O)return{x:Nt,y:vt};if(M!==vt)throw new Error("invZ was invalid");return{x:H,y:j}}clearCofactor(){let{h:y}=t;return y===vt?this:this.multiplyUnsafe(y)}static fromHex(y,I=!1){let{d:C,a:L}=t,O=e.BYTES;y=tt("pointHex",y,O);let H=y.slice(),j=y[O-1];H[O-1]=j&-129;let M=ge(H);M===Nt||(I?m(M,f):m(M,e.ORDER));let q=l(M*M),st=l(q-vt),X=l(C*q-L),{isValid:ut,value:ft}=u(st,X);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let ot=(ft&vt)===vt,pt=(j&128)!==0;if(!I&&ft===Nt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==ot&&(ft=l(-ft)),x.fromAffine({x:ft,y:M})}static fromPrivateKey(y){return D(y).point}toRawBytes(){let{x:y,y:I}=this.toAffine(),C=Le(I,e.BYTES);return C[C.length-1]|=y&vt?128:0,C}toHex(){return zt(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,vt,l(t.Gx*t.Gy)),x.ZERO=new x(Nt,vt,vt,Nt);let{BASE:S,ZERO:_}=x,N=cn(x,a*8);function Y(v){return z(v,n)}function $(v){return Y(ge(v))}function D(v){let y=a;v=tt("private key",v,y);let I=tt("hashed private key",i(v),2*y),C=d(I.slice(0,y)),L=I.slice(y,2*y),O=$(C),H=S.multiply(O),j=H.toRawBytes();return{head:C,prefix:L,scalar:O,point:H,pointBytes:j}}function nt(v){return D(v).pointBytes}function et(v=new Uint8Array,...y){let I=Zt(...y);return $(i(w(I,tt("context",v),!!s)))}function At(v,y,I={}){v=tt("message",v),s&&(v=s(v));let{prefix:C,scalar:L,pointBytes:O}=D(y),H=et(I.context,C,v),j=S.multiply(H).toRawBytes(),M=et(I.context,j,O,v),q=Y(H+M*L);A(q);let st=Zt(j,Le(q,e.BYTES));return tt("result",st,a*2)}let E=Wu;function R(v,y,I,C=E){let{context:L,zip215:O}=C,H=e.BYTES;v=tt("signature",v,2*H),y=tt("message",y),s&&(y=s(y));let j=ge(v.slice(H,2*H)),M,q,st;try{M=x.fromHex(I,O),q=x.fromHex(v.slice(0,H),O),st=S.multiplyUnsafe(j)}catch{return!1}if(!O&&M.isSmallOrder())return!1;let X=et(L,q.toRawBytes(),M.toRawBytes(),y);return q.add(M.multiplyUnsafe(X)).subtract(st).clearCofactor().equals(x.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:At,verify:R,ExtendedPoint:x,utils:{getExtendedPublicKey:D,randomPrivateKey:()=>o(e.BYTES),precompute(v=8,y=x.BASE){return y._setWindowSize(v),y.multiply(BigInt(3)),y}}}}var Zs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ro=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),U0=BigInt(0),Ju=BigInt(1),_o=BigInt(2),D0=BigInt(3),Xu=BigInt(5),Qu=BigInt(8);function tf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=Zs,a=r*r%i*r%i,c=J(a,_o,i)*a%i,f=J(c,Ju,i)*r%i,l=J(f,Xu,i)*f%i,u=J(l,t,i)*l%i,d=J(u,e,i)*u%i,w=J(d,n,i)*d%i,p=J(w,s,i)*w%i,h=J(p,s,i)*w%i,g=J(h,t,i)*l%i;return{pow_p_5_8:J(g,_o,i)*r%i,b2:a}}function ef(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function rf(r,t){let e=Zs,n=z(t*t*t,e),s=z(n*n*t,e),i=tf(r*s).pow_p_5_8,o=z(r*n*i,e),a=z(t*o*o,e),c=o,f=z(o*Ro,e),l=a===r,u=a===z(-r,e),d=a===z(-r*Ro,e);return l&&(o=c),(u||d)&&(o=f),Ao(o,e)&&(o=z(-o,e)),{isValid:l||u,value:o}}var nf=an(Zs,void 0,!0),sf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:nf,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Qu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Te,randomBytes:tr,adjustScalarBytes:ef,uvRatio:rf},rr=Io(sf);var nr=32,Jt=64,un=32;function No(){let r=rr.utils.randomPrivateKey(),t=rr.getPublicKey(r);return{privateKey:Uo(r,t),publicKey:t}}function To(r){if(r.length!==un)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=rr.getPublicKey(t);return{privateKey:Uo(t,e),publicKey:e}}function Co(r,t){let e=r.subarray(0,un);return rr.sign(t instanceof Uint8Array?t:t.subarray(),e)}function Lo(r,t,e){return rr.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function Uo(r,t){let e=new Uint8Array(Jt);for(let n=0;n<un;n++)e[n]=r[n],e[un+n]=t[n];return e}var Js={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function fn(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",i=r?.saltLength??16,o=r?.iterations??32767,a=mt.get();e*=8;async function c(u,d){let w=a.getRandomValues(new Uint8Array(i)),p=a.getRandomValues(new Uint8Array(n)),h={name:t,iv:p};typeof d=="string"&&(d=P(d));let g;if(d.length===0){g=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["encrypt"]);try{let A={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},b=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(A,b,{name:t,length:e},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["encrypt"])}}else{let A={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},b=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(A,b,{name:t,length:e},!0,["encrypt"])}let m=await a.subtle.encrypt(h,g,u);return Is([w,h.iv,new Uint8Array(m)])}async function f(u,d){let w=u.subarray(0,i),p=u.subarray(i,i+n),h=u.subarray(i+n),g={name:t,iv:p};typeof d=="string"&&(d=P(d));let m;if(d.length===0)try{let b={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},T=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(b,T,{name:t,length:e},!0,["decrypt"])}catch{m=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},T=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(b,T,{name:t,length:e},!0,["decrypt"])}let A=await a.subtle.decrypt(g,m,h);return new Uint8Array(A)}return{encrypt:c,decrypt:f}}async function sr(r,t){let n=await fn().encrypt(r,t);return _e.encode(n)}var af=Math.pow(2,7),cf=Math.pow(2,14),lf=Math.pow(2,21),Vo=Math.pow(2,28),Oo=Math.pow(2,35),Ho=Math.pow(2,42),Po=Math.pow(2,49),wt=128,me=127;function Ar(r){if(r<af)return 1;if(r<cf)return 2;if(r<lf)return 3;if(r<Vo)return 4;if(r<Oo)return 5;if(r<Ho)return 6;if(r<Po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ko(r,t,e=0){switch(Ar(r)){case 8:t[e++]=r&255|wt,r/=128;case 7:t[e++]=r&255|wt,r/=128;case 6:t[e++]=r&255|wt,r/=128;case 5:t[e++]=r&255|wt,r/=128;case 4:t[e++]=r&255|wt,r>>>=7;case 3:t[e++]=r&255|wt,r>>>=7;case 2:t[e++]=r&255|wt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Mo(r,t){let e=r[t],n=0;if(n+=e&me,e<wt||(e=r[t+1],n+=(e&me)<<7,e<wt)||(e=r[t+2],n+=(e&me)<<14,e<wt)||(e=r[t+3],n+=(e&me)<<21,e<wt)||(e=r[t+4],n+=(e&me)*Vo,e<wt)||(e=r[t+5],n+=(e&me)*Oo,e<wt)||(e=r[t+6],n+=(e&me)*Ho,e<wt)||(e=r[t+7],n+=(e&me)*Po,e<wt))return n;throw new RangeError("Could not decode varint")}var Xs=new Float32Array([-0]),be=new Uint8Array(Xs.buffer);function Fo(r,t,e){Xs[0]=r,t[e]=be[0],t[e+1]=be[1],t[e+2]=be[2],t[e+3]=be[3]}function $o(r,t){return be[0]=r[t],be[1]=r[t+1],be[2]=r[t+2],be[3]=r[t+3],Xs[0]}var Qs=new Float64Array([-0]),gt=new Uint8Array(Qs.buffer);function qo(r,t,e){Qs[0]=r,t[e]=gt[0],t[e+1]=gt[1],t[e+2]=gt[2],t[e+3]=gt[3],t[e+4]=gt[4],t[e+5]=gt[5],t[e+6]=gt[6],t[e+7]=gt[7]}function jo(r,t){return gt[0]=r[t],gt[1]=r[t+1],gt[2]=r[t+2],gt[3]=r[t+3],gt[4]=r[t+4],gt[5]=r[t+5],gt[6]=r[t+6],gt[7]=r[t+7],Qs[0]}var uf=BigInt(Number.MAX_SAFE_INTEGER),ff=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 De;if(t<uf&&t>ff)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Yo&&(s=0n,++n>Yo&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return De;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):De}},De=new Bt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var Yo=4294967296n;function Go(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 zo(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function ti(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function hn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ei=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,Tt(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 Tt(this,4);return hn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return hn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=$o(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=jo(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return zo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while(this.buf[this.pos++]&128);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 Tt(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.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=hn(this.buf,this.pos+=4),e=hn(this.buf,this.pos+=4);return new Bt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Mo(this.buf,this.pos);return this.pos+=Ar(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ri(r){return new ei(r instanceof Uint8Array?r:r.subarray())}function dn(r,t,e){let n=ri(r);return t.decode(n,void 0,e)}function ni(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return Vt(o);s+o>t&&(n=Vt(t),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function si(){}var oi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hf=ni();function df(r){return globalThis.Buffer!=null?Vt(r):hf(r)}var kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ve(si,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ai((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(pn,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Bt.fromBigInt(t);return this._push(pn,e.length(),e)}uint64Number(t){return this._push(Ko,Ar(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Bt.fromBigInt(t).zzEncode();return this._push(pn,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(pn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ii,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(Sr,4,e.lo)._push(Sr,4,e.hi)}fixed64Number(t){let e=Bt.fromNumber(t);return this._push(Sr,4,e.lo)._push(Sr,4,e.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(Fo,4,t)}double(t){return this._push(qo,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ii,1,0):this.uint32(e)._push(gf,e,t)}string(t){let e=Go(t);return e!==0?this.uint32(e)._push(ti,e,t):this._push(ii,1,0)}fork(){return this.states=new oi(this),this.head=this.tail=new Ve(si,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 Ve(si,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=df(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ii(r,t,e){t[e]=r&255}function pf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ai=class extends Ve{next;constructor(t,e){super(pf,t,e),this.next=void 0}};function pn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Sr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function gf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(kr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yf,t,r),this},kr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(mf,t,r),this});function yf(r,t,e){t.set(r,e)}function mf(r,t,e){r.length<40?ti(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(P(r),e)}function ci(){return new kr}function gn(r,t){let e=ci();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ir;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ir||(ir={}));function yn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function li(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return yn("enum",ir.VARINT,e,n)}function mn(r,t){return yn("message",ir.LENGTH_DELIMITED,r,t)}var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(rt||(rt={}));var ui;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(ui||(ui={}));(function(r){r.codec=()=>li(ui)})(rt||(rt={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=mn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let o=e.uint32();switch(o>>>3){case 1:s.Type=rt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(o&7);break}}return s})),t),r.encode=e=>gn(e,r.codec()),r.decode=e=>dn(e,r.codec())})(Xt||(Xt={}));var Ht;(function(r){let t;r.codec=()=>(t==null&&(t=mn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let o=e.uint32();switch(o>>>3){case 1:s.Type=rt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(o&7);break}}return s})),t),r.encode=e=>gn(e,r.codec()),r.decode=e=>dn(e,r.codec())})(Ht||(Ht={}));var Ir=class{_key;constructor(t){this._key=or(t,nr)}verify(t,e){return Lo(this._key,e,t)}marshal(){return this._key}get bytes(){return Xt.encode({Type:rt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}},Oe=class{_key;_publicKey;constructor(t,e){this._key=or(t,Jt),this._publicKey=or(e,nr)}sign(t){return Co(this._key,t)}get public(){return new Ir(this._publicKey)}marshal(){return this._key}get bytes(){return Ht.encode({Type:rt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}async hash(){let t=ht.digest(this.bytes),e;return kt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=Yt.digest(this.public.bytes);return bt.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function bf(r){if(r.length>Jt){r=or(r,Jt+nr);let n=r.subarray(0,Jt),s=r.subarray(Jt,r.length);return new Oe(n,s)}r=or(r,Jt);let t=r.subarray(0,Jt),e=r.subarray(nr);return new Oe(t,e)}function wf(r){return r=or(r,nr),new Ir(r)}async function xf(){let{privateKey:r,publicKey:t}=No();return new Oe(r,t)}async function Zo(r){let{privateKey:t,publicKey:e}=To(r);return new Oe(t,e)}function or(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new B(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function G(r,t="utf8"){let e=Zr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}async function Jo(r,t){let e=_e.decode(r);return fn().decrypt(e,t)}var vi={};ct(vi,{MAX_RSA_KEY_SIZE:()=>Pr,RsaPrivateKey:()=>fr,RsaPublicKey:()=>Hr,fromJwk:()=>qf,generateKeyPair:()=>jf,unmarshalRsaPrivateKey:()=>xi,unmarshalRsaPublicKey:()=>$f});function Pt(r){if(isNaN(r)||r<=0)throw new B("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return tr(r)}var ve={};ct(ve,{exportToPem:()=>Pf,importFromPem:()=>wi,jwkToPkcs1:()=>Df,jwkToPkix:()=>Of,pkcs1ToJwk:()=>Uf,pkixToJwk:()=>Vf});var wn=class extends Xe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Jr(t);let n=ue(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?t.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=t.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),Ze(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Rr=(r,t,e)=>new wn(r,t).update(e).digest();Rr.create=(r,t)=>new wn(r,t);function Xo(r,t,e,n){Jr(r);let s=yo({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(We(i),We(o),We(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ue(t),f=ue(e),l=new Uint8Array(o),u=Rr.create(r,c),d=u._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:l,PRF:u,PRFSalt:d}}function Qo(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}function ta(r,t,e,n){let{c:s,dkLen:i,DK:o,PRF:a,PRFSalt:c}=Xo(r,t,e,n),f,l=new Uint8Array(4),u=Ne(l),d=new Uint8Array(a.outputLen);for(let w=1,p=0;p<i;w++,p+=a.outputLen){let h=o.subarray(p,p+a.outputLen);u.setInt32(0,w,!1),(f=c._cloneInto(f)).update(l).digestInto(d),h.set(d.subarray(0,h.length));for(let g=1;g<s;g++){a._cloneInto(f).update(d).digestInto(d);for(let m=0;m<h.length;m++)h[m]^=d[m]}}return Qo(a,c,o,f,d)}async function hi(r,t,e,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Xo(r,t,e,n),l,u=new Uint8Array(4),d=Ne(u),w=new Uint8Array(c.outputLen);for(let p=1,h=0;h<i;p++,h+=c.outputLen){let g=a.subarray(h,h+c.outputLen);d.setInt32(0,p,!1),(l=f._cloneInto(l)).update(u).digestInto(w),g.set(w.subarray(0,g.length)),await po(s-1,o,()=>{c._cloneInto(l).update(w).digestInto(w);for(let m=0;m<g.length;m++)g[m]^=w[m]})}return Qo(c,f,a,l,w)}var K=gs(ea());function He(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function we(r,t,e=-1){let n=e,s=r,i=0,o=Math.pow(2,t);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let l=a-1;l>=0;l--){let u=Math.pow(2,l*t);f[i-l-1]=Math.floor(s/u),s-=f[i-l-1]*u}return c}o*=Math.pow(2,t)}return new ArrayBuffer(0)}function vn(...r){let t=0,e=0;for(let i of r)t+=i.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let i of r)s.set(i,e),e+=i.length;return s}function pi(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=He(e,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,He(i,8)-n}function ra(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let o=e-t,a=we(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=we(t,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function na(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function Et(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(e)}var jp=Math.log(2);function Bn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function gi(r){let t=0,e=0;for(let s=0;s<r.length;s++){let i=r[s];t+=i.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),e),e+=i.byteLength}return n.buffer}function ne(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Nr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return gi(this.items)}},_r=[new Uint8Array([1])],sa="0123456789";var lr="",Lt=new ArrayBuffer(0),yi=new Uint8Array(0),Tr="EndOfContent",oa="OCTET STRING",aa="BIT STRING";function se(r){var t;return t=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?K.BufferSourceConverter.toUint8Array(i.valueHex):yi}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!ne(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Lt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:K.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var te=class{constructor({blockLength:t=0,error:e=lr,warnings:n=[],valueBeforeDecode:s=yi}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=K.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:K.Convert.ToHex(this.valueBeforeDecodeView)}}};te.NAME="baseBlock";var yt=class extends te{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};yt.NAME="valueBlock";var An=class extends se(te){constructor({idBlock:t={}}={}){var e,n,s,i;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?K.BufferSourceConverter.toUint8Array(t.valueHex):yi,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=t.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Lt}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let i=this.tagNumber;i&=31,e|=i,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=we(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=e|31,!t){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=e|31,!t){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let d=new Uint8Array(l);for(let w=0;w<f.length;w++)d[w]=f[w];f=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,f[c-1]=i[c]&127;let u=new Uint8Array(c);for(let d=0;d<c;d++)u[d]=f[d];f=this.valueHexView=new Uint8Array(c),f.set(u),this.blockLength<=9?this.tagNumber=He(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};An.NAME="identificationBlock";var Sn=class extends te{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,e+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,e+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=He(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=we(this.length,8);if(s.byteLength>127)return this.error="Too big length",Lt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let i=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Sn.NAME="lengthBlock";var k={},dt=class extends te{constructor({name:t=lr,optional:e=!1,primitiveSchema:n,...s}={},i){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new An(s),this.lenBlock=new Sn(s),this.valueBlock=i?new i(s):new yt(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(t,e){let n=e||new Nr;e||ca(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(t);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(t);n.write(o),n.write(i)}return e?Lt:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return na(e,n)}};dt.NAME="BaseBlock";function ca(r){if(r instanceof k.Constructed)for(let t of r.valueBlock.value)ca(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var kn=class extends dt{constructor({value:t=lr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};kn.NAME="BaseStringBlock";var In=class extends se(yt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};In.NAME="PrimitiveValueBlock";var la,Rn=class extends dt{constructor(t={}){super(t,In),this.idBlock.isConstructed=!1}};la=Rn;k.Primitive=la;Rn.NAME="PRIMITIVE";function _f(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function as(r,t=0,e=r.length){let n=t,s=new dt({},yt),i=new te;if(!ne(i,r,t,e))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=dt;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=k.EndOfContent;break;case 1:c=k.Boolean;break;case 2:c=k.Integer;break;case 3:c=k.BitString;break;case 4:c=k.OctetString;break;case 5:c=k.Null;break;case 6:c=k.ObjectIdentifier;break;case 10:c=k.Enumerated;break;case 12:c=k.Utf8String;break;case 13:c=k.RelativeObjectIdentifier;break;case 14:c=k.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=k.Sequence;break;case 17:c=k.Set;break;case 18:c=k.NumericString;break;case 19:c=k.PrintableString;break;case 20:c=k.TeletexString;break;case 21:c=k.VideotexString;break;case 22:c=k.IA5String;break;case 23:c=k.UTCTime;break;case 24:c=k.GeneralizedTime;break;case 25:c=k.GraphicString;break;case 26:c=k.VisibleString;break;case 27:c=k.GeneralString;break;case 28:c=k.UniversalString;break;case 29:c=k.CharacterString;break;case 30:c=k.BmpString;break;case 31:c=k.DATE;break;case 32:c=k.TimeOfDay;break;case 33:c=k.DateTime;break;case 34:c=k.Duration;break;default:{let f=s.idBlock.isConstructed?new k.Constructed:new k.Primitive;f.idBlock=s.idBlock,f.lenBlock=s.lenBlock,f.warnings=s.warnings,s=f}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?k.Constructed:k.Primitive}return s=_f(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function ur(r){if(!r.byteLength){let t=new dt({},yt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return as(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Nf(r,t){return r?1:t}var Kt=class extends yt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let i=e;for(;Nf(this.isIndefiniteForm,n)>0;){let o=as(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Tr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Tr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(t,e){let n=e||new Nr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Lt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Kt.NAME="ConstructedValueBlock";var ua,xe=class extends dt{constructor(t={}){super(t,Kt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
|
|
2
|
+
"use strict";var Libp2PKeychain=(()=>{var $c=Object.create;var zr=Object.defineProperty;var qc=Object.getOwnPropertyDescriptor;var jc=Object.getOwnPropertyNames;var Yc=Object.getPrototypeOf,Gc=Object.prototype.hasOwnProperty;var Re=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ct=(r,t)=>{for(var e in t)zr(r,e,{get:t[e],enumerable:!0})},qi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of jc(t))!Gc.call(r,s)&&s!==e&&zr(r,s,{get:()=>t[s],enumerable:!(n=qc(t,s))||n.enumerable});return r};var gs=(r,t,e)=>(e=r!=null?$c(Yc(r)):{},qi(t||!r||!r.__esModule?zr(e,"default",{value:r,enumerable:!0}):e,r)),zc=r=>qi(zr({},"__esModule",{value:!0}),r);var ea=Re(ar=>{"use strict";var Ef="[object ArrayBuffer]",Qt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===Ef}static toArrayBuffer(t){return this.isArrayBuffer(t)?t:t.byteLength===t.buffer.byteLength||t.byteOffset===0&&t.byteLength===t.buffer.byteLength?t.buffer:this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e)return t;if(this.isArrayBuffer(t))return new e(t);if(this.isArrayBufferView(t))return new e(t.buffer,t.byteOffset,t.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){let n=r.toUint8Array(t),s=r.toUint8Array(e);if(n.length!==s.byteLength)return!1;for(let i=0;i<n.length;i++)if(n[i]!==s[i])return!1;return!0}static concat(...t){let e;Array.isArray(t[0])&&!(t[1]instanceof Function)||Array.isArray(t[0])&&t[1]instanceof Function?e=t[0]:t[t.length-1]instanceof Function?e=t.slice(0,t.length-1):e=t;let n=0;for(let o of e)n+=o.byteLength;let s=new Uint8Array(n),i=0;for(let o of e){let a=this.toUint8Array(o);s.set(a,i),i+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},di="string",vf=/^[0-9a-f]+$/i,Bf=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Af=/^[a-zA-Z0-9-_]+$/,xn=class{static fromString(t){let e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n.buffer}static toString(t){let e=Qt.toUint8Array(t),n="";for(let i=0;i<e.length;i++)n+=String.fromCharCode(e[i]);return decodeURIComponent(escape(n))}},It=class{static toString(t,e=!1){let n=Qt.toArrayBuffer(t),s=new DataView(n),i="";for(let o=0;o<n.byteLength;o+=2){let a=s.getUint16(o,e);i+=String.fromCharCode(a)}return i}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let i=0;i<t.length;i++)s.setUint16(i*2,t.charCodeAt(i),e);return n}},En=class r{static isHex(t){return typeof t===di&&vf.test(t)}static isBase64(t){return typeof t===di&&Bf.test(t)}static isBase64Url(t){return typeof t===di&&Af.test(t)}static ToString(t,e="utf8"){let n=Qt.toUint8Array(t);switch(e.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return It.toString(n,!0);case"utf16":case"utf16be":return It.toString(n);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t)return new ArrayBuffer(0);switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return It.fromString(t,!0);case"utf16":case"utf16be":return It.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=Qt.toUint8Array(t);if(typeof btoa<"u"){let n=this.ToString(e,"binary");return btoa(n)}else return Buffer.from(e).toString("base64")}static FromBase64(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64(e))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(e)):new Uint8Array(Buffer.from(e,"base64")).buffer}static FromBase64Url(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isBase64Url(e))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return xn.fromString(t);case"utf16":case"utf16be":return It.fromString(t);case"utf16le":case"usc2":return It.fromString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=r.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return xn.toString(t);case"utf16":case"utf16be":return It.toString(t);case"utf16le":case"usc2":return It.toString(t,!0);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){let e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return n.buffer}static ToBinary(t){let e=Qt.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=Qt.toUint8Array(t),n="",s=e.length;for(let i=0;i<s;i++){let o=e[i];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(t){let e=this.formatString(t);if(!e)return new ArrayBuffer(0);if(!r.isHex(e))throw new TypeError("Argument 'hexString' is not HEX encoded");e.length%2&&(e=`0${e}`);let n=new Uint8Array(e.length/2);for(let s=0;s<e.length;s=s+2){let i=e.slice(s,s+2);n[s/2]=parseInt(i,16)}return n.buffer}static ToUtf16String(t,e=!1){return It.toString(t,e)}static FromUtf16String(t,e=!1){return It.fromString(t,e)}static Base64Padding(t){let e=4-t.length%4;if(e<4)for(let n=0;n<e;n++)t+="=";return t}static formatString(t){return t?.replace(/[\n\r\t ]/g,"")||""}};En.DEFAULT_UTF8_ENCODING="utf8";function Sf(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let i in s)e[i]=s[i]}return e}function kf(...r){let t=r.map(s=>s.byteLength).reduce((s,i)=>s+i),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let i of s)e[n++]=i}),e.buffer}function If(r,t){if(!(r&&t)||r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<r.byteLength;s++)if(e[s]!==n[s])return!1;return!0}ar.BufferSourceConverter=Qt;ar.Convert=En;ar.assign=Sf;ar.combine=kf;ar.isEqual=If});var gc=Re((yy,pc)=>{"use strict";pc.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}});var Ec=Re((wc,xc)=>{"use strict";var fs=gc(),{hasOwnProperty:mc}=Object.prototype,{propertyIsEnumerable:hh}=Object,gr=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),dh=wc,yc={concatArrays:!1,ignoreUndefined:!1},hs=r=>{let t=[];for(let e in r)mc.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)hh.call(r,n)&&t.push(n)}return t};function yr(r){return Array.isArray(r)?ph(r):fs(r)?gh(r):r}function ph(r){let t=r.slice(0,0);return hs(r).forEach(e=>{gr(t,e,yr(r[e]))}),t}function gh(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return hs(r).forEach(e=>{gr(t,e,yr(r[e]))}),t}var bc=(r,t,e,n)=>(e.forEach(s=>{typeof t[s]>"u"&&n.ignoreUndefined||(s in r&&r[s]!==Object.getPrototypeOf(r)?gr(r,s,Ui(r[s],t[s],n)):gr(r,s,yr(t[s])))}),r),yh=(r,t,e)=>{let n=r.slice(0,0),s=0;return[r,t].forEach(i=>{let o=[];for(let a=0;a<i.length;a++)mc.call(i,a)&&(o.push(String(a)),i===r?gr(n,s++,i[a]):gr(n,s++,yr(i[a])));n=bc(n,i,hs(i).filter(a=>!o.includes(a)),e)}),n};function Ui(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?yh(r,t,e):!fs(t)||!fs(r)?yr(t):bc(r,t,hs(t),e)}xc.exports=function(...r){let t=Ui(yr(yc),this!==dh&&this||{},yc),e={_:{}};for(let n of r)if(n!==void 0){if(!fs(n))throw new TypeError("`"+n+"` is not an Option Object");e=Ui(e,{_:n},t)}return e._}});var Sc=Re((by,Ac)=>{"use strict";function mh(r){return r>=55296&&r<=56319}function bh(r){return r>=56320&&r<=57343}Ac.exports=function(t,e,n){if(typeof e!="string")throw new Error("Input must be string");for(var s=e.length,i=0,o,a,c=0;c<s;c+=1){if(o=e.charCodeAt(c),a=e[c],mh(o)&&bh(e.charCodeAt(c+1))&&(c+=1,a+=e[c]),i+=t(a),i===n)return e.slice(0,c+1);if(i>n)return e.slice(0,c-a.length+1)}return e}});var Ic=Re((wy,kc)=>{"use strict";function wh(r){return r>=55296&&r<=56319}function xh(r){return r>=56320&&r<=57343}kc.exports=function(t){if(typeof t!="string")throw new Error("Input must be string");for(var e=t.length,n=0,s=null,i=null,o=0;o<e;o++)s=t.charCodeAt(o),xh(s)?i!=null&&wh(i)?n+=1:n+=3:s<=127?n+=1:s>=128&&s<=2047?n+=2:s>=2048&&s<=65535&&(n+=3),i=s;return n}});var _c=Re((xy,Rc)=>{"use strict";var Eh=Sc(),vh=Ic();Rc.exports=Eh.bind(null,vh)});var Cc=Re((Ey,Tc)=>{"use strict";var Bh=_c(),Ah=/[\/\?<>\\:\*\|"]/g,Sh=/[\x00-\x1f\x80-\x9f]/g,kh=/^\.+$/,Ih=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,Rh=/[\. ]+$/;function Nc(r,t){if(typeof r!="string")throw new Error("Input must be string");var e=r.replace(Ah,t).replace(Sh,t).replace(kh,t).replace(Ih,t).replace(Rh,t);return Bh(e,255)}Tc.exports=function(r,t){var e=t&&t.replacement||"",n=Nc(r,e);return e===""?n:Nc(n,"")}});var Th={};ct(Th,{keychain:()=>Nh});var mt={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw Object.assign(new Error("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"),{code:"ERR_MISSING_WEB_CRYPTO"});return t}};var ys=Symbol.for("@libp2p/peer-id");var B=class extends Error{code;props;constructor(t,e,n){super(t),this.code=e,this.name=n?.name??"CodeError",this.props=n??{}}};var ji=Symbol.for("@libp2p/service-capabilities"),Vh=Symbol.for("@libp2p/service-dependencies");var fi={};ct(fi,{Ed25519PrivateKey:()=>Oe,Ed25519PublicKey:()=>Ir,generateKeyPair:()=>xf,generateKeyPairFromSeed:()=>Zo,unmarshalEd25519PrivateKey:()=>bf,unmarshalEd25519PublicKey:()=>wf});var Es={};ct(Es,{base58btc:()=>bt,base58flickr:()=>tl});var od=new Uint8Array(0);function Yi(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 jt(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 Gi(r){return new TextEncoder().encode(r)}function zi(r){return new TextDecoder().decode(r)}function Wc(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 s=0;s<r.length;s++){var i=r.charAt(s),o=i.charCodeAt(0);if(e[o]!==255)throw new TypeError(i+" is ambiguous");e[o]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,g=0,m=0,A=p.length;m!==A&&p[m]===0;)m++,h++;for(var b=(A-m)*l+1>>>0,T=new Uint8Array(b);m!==A;){for(var x=p[m],S=0,_=b-1;(x!==0||S<g)&&_!==-1;_--,S++)x+=256*T[_]>>>0,T[_]=x%a>>>0,x=x/a>>>0;if(x!==0)throw new Error("Non-zero carry");g=S,m++}for(var N=b-g;N!==b&&T[N]===0;)N++;for(var Y=c.repeat(h);N<b;++N)Y+=r.charAt(T[N]);return Y}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var g=0,m=0;p[h]===c;)g++,h++;for(var A=(p.length-h)*f+1>>>0,b=new Uint8Array(A);p[h];){var T=e[p.charCodeAt(h)];if(T===255)return;for(var x=0,S=A-1;(T!==0||x<m)&&S!==-1;S--,x++)T+=a*b[S]>>>0,b[S]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");m=x,h++}if(p[h]!==" "){for(var _=A-m;_!==A&&b[_]===0;)_++;for(var N=new Uint8Array(g+(A-_)),Y=g;_!==A;)N[Y++]=b[_++];return N}}}function w(p){var h=d(p);if(h)return h;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:d,decode:w}}var Zc=Wc,Jc=Zc,Zi=Jc;var ms=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")}},bs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 Ji(this,t)}},ws=class{decoders;constructor(t){this.decoders=t}or(t){return Ji(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 Ji(r,t){return new ws({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var xs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new ms(t,e,n),this.decoder=new bs(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Fe({name:r,prefix:t,encode:e,decode:n}){return new xs(r,t,e,n)}function ce({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Zi(e,r);return Fe({prefix:t,name:r,encode:n,decode:i=>jt(s(i))})}function Xc(r,t,e,n){let s={};for(let l=0;l<t.length;++l)s[t[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let l=0;l<i;++l){let u=s[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Qc(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,i="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<e-o]),n)for(;i.length*e&7;)i+="=";return i}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Fe({prefix:t,name:r,encode(s){return Qc(s,n,e)},decode(s){return Xc(s,n,e,r)}})}var bt=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tl=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bs={};ct(Bs,{identity:()=>Yt});var el=to,Xi=128,rl=127,nl=~rl,sl=Math.pow(2,31);function to(r,t,e){t=t||[],e=e||0;for(var n=e;r>=sl;)t[e++]=r&255|Xi,r/=128;for(;r&nl;)t[e++]=r&255|Xi,r>>>=7;return t[e]=r|0,to.bytes=e-n+1,t}var il=vs,ol=128,Qi=127;function vs(r,n){var e=0,n=n||0,s=0,i=n,o,a=r.length;do{if(i>=a)throw vs.bytes=0,new RangeError("Could not decode varint");o=r[i++],e+=s<28?(o&Qi)<<s:(o&Qi)*Math.pow(2,s),s+=7}while(o>=ol);return vs.bytes=i-n,e}var al=Math.pow(2,7),cl=Math.pow(2,14),ll=Math.pow(2,21),ul=Math.pow(2,28),fl=Math.pow(2,35),hl=Math.pow(2,42),dl=Math.pow(2,49),pl=Math.pow(2,56),gl=Math.pow(2,63),yl=function(r){return r<al?1:r<cl?2:r<ll?3:r<ul?4:r<fl?5:r<hl?6:r<dl?7:r<pl?8:r<gl?9:10},ml={encode:el,decode:il,encodingLength:yl},bl=ml,br=bl;function wr(r,t=0){return[br.decode(r,t),br.decode.bytes]}function $e(r,t,e=0){return br.encode(r,t,e),t}function qe(r){return br.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=qe(r),s=n+qe(e),i=new Uint8Array(s+e);return $e(r,i,0),$e(e,i,n),i.set(t,s),new je(r,e,t,i)}function xr(r){let t=jt(r),[e,n]=wr(t),[s,i]=wr(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new je(e,s,o,t)}function eo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Yi(r.bytes,e.bytes)}}var je=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};var ro=0,wl="identity",no=jt;function xl(r){return Dt(ro,no(r))}var Yt={code:ro,name:wl,encode:no,digest:xl};var ks={};ct(ks,{sha256:()=>ht,sha512:()=>El});function Ss({name:r,code:t,encode:e}){return new As(r,t,e)}var As=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function io(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ht=Ss({name:"sha2-256",code:18,encode:io("SHA-256")}),El=Ss({name:"sha2-512",code:19,encode:io("SHA-512")});function St(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 Vt(r=0){return new Uint8Array(r)}function Is(r,t){t==null&&(t=r.reduce((s,i)=>s+i.length,0));let e=Vt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var Rs={};ct(Rs,{base10:()=>vl});var vl=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var _s={};ct(_s,{base16:()=>Bl,base16upper:()=>Al});var Bl=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Al=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ns={};ct(Ns,{base2:()=>Sl});var Sl=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ts={};ct(Ts,{base256emoji:()=>Nl});var oo=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}"),kl=oo.reduce((r,t,e)=>(r[e]=t,r),[]),Il=oo.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Rl(r){return r.reduce((t,e)=>(t+=kl[e],t),"")}function _l(r){let t=[];for(let e of r){let n=Il[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Nl=Fe({prefix:"\u{1F680}",name:"base256emoji",encode:Rl,decode:_l});var Cs={};ct(Cs,{base32:()=>Ge,base32hex:()=>Ul,base32hexpad:()=>Vl,base32hexpadupper:()=>Ol,base32hexupper:()=>Dl,base32pad:()=>Cl,base32padupper:()=>Ll,base32upper:()=>Tl,base32z:()=>Hl});var Ge=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Tl=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Cl=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ll=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ul=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Dl=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vl=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ol=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hl=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ls={};ct(Ls,{base36:()=>Pl,base36upper:()=>Kl});var Pl=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Kl=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Us={};ct(Us,{base64:()=>_e,base64pad:()=>Ml,base64url:()=>Fl,base64urlpad:()=>$l});var _e=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ml=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fl=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$l=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ds={};ct(Ds,{base8:()=>ql});var ql=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vs={};ct(Vs,{identity:()=>jl});var jl=Fe({prefix:"\0",name:"identity",encode:r=>zi(r),decode:r=>Gi(r)});var Ud=new TextEncoder,Dd=new TextDecoder;function ao(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Wl(e,Os(r),t??bt.encoder);default:return Zl(e,Os(r),t??Ge.encoder)}}var co=new WeakMap;function Os(r){let t=co.get(r);if(t==null){let e=new Map;return co.set(r,e),e}return t}var le=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Jl)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=Dt(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&&eo(t.multihash,n.multihash)}toString(t){return ao(this,t)}toJSON(){return{"/":ao(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:s,multihash:i,bytes:o}=e;return new r(n,s,i,o??lo(n,s,i.bytes))}else if(e[Xl]===!0){let{version:n,multihash:s,code:i}=e,o=xr(s);return r.create(n,i,o)}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!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=lo(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Er,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,s=jt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=s.subarray(e.multihashSize-e.digestSize),o=new je(e.multihashCode,e.digestSize,i,s);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,d]=wr(t.subarray(e));return e+=d,u},s=n(),i=Er;if(s===18?(s=0,e=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=e,a=n(),c=n(),f=e+c,l=f-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=zl(t,e),i=r.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Os(i).set(n,t),i}};function zl(r,t){switch(r[0]){case"Q":{let e=t??bt;return[bt.prefix,e.decode(`${bt.prefix}${r}`)]}case bt.prefix:{let e=t??bt;return[bt.prefix,e.decode(r)]}case Ge.prefix:{let e=t??Ge;return[Ge.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Wl(r,t,e){let{prefix:n}=e;if(n!==bt.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return s}function Zl(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let i=e.encode(r);return t.set(n,i),i}else return s}var Er=112,Jl=18;function lo(r,t,e){let n=qe(r),s=n+qe(t),i=new Uint8Array(s+e.byteLength);return $e(r,i,0),$e(t,i,n),i.set(e,s),i}var Xl=Symbol.for("@ipld/js-cid/CID");var ze={...Vs,...Ns,...Ds,...Rs,..._s,...Cs,...Ls,...Es,...Us,...Ts},Jd={...ks,...Bs};function fo(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var uo=fo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Hs=fo("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=Vt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ql={utf8:uo,"utf-8":uo,hex:ze.base16,latin1:Hs,ascii:Hs,binary:Hs,...ze},Zr=Ql;function P(r,t="utf8"){let e=Zr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function kt(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function We(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function tu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ze(r,...t){if(!tu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function Jr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");We(r.outputLen),We(r.blockLen)}function Je(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 ho(r,t){Ze(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var Xr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Ne=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),_t=(r,t)=>r<<32-t|r>>>t,Qr=(r,t)=>r<<t|r>>>32-t>>>0,f0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var eu=async()=>{};async function po(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let i=Date.now()-n;i>=0&&i<t||(await eu(),n+=i)}}function go(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function ue(r){return typeof r=="string"&&(r=go(r)),Ze(r),r}function Ps(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Ze(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}var Xe=class{clone(){return this._cloneInto()}},ru={}.toString;function yo(r,t){if(t!==void 0&&ru.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function Qe(r){let t=n=>r().update(ue(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function tr(r=32){if(Xr&&typeof Xr.getRandomValues=="function")return Xr.getRandomValues(new Uint8Array(r));throw new Error("crypto.getRandomValues must be defined")}function nu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),i=BigInt(4294967295),o=Number(e>>s&i),a=Number(e&i),c=n?4:0,f=n?0:4;r.setUint32(t+c,o,n),r.setUint32(t+f,a,n)}var tn=(r,t,e)=>r&t^~r&e,en=(r,t,e)=>r&t^r&e^t&e,fe=class extends Xe{constructor(t,e,n,s){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ne(this.buffer)}update(t){Je(this);let{view:e,buffer:n,blockLen:s}=this;t=ue(t);let i=t.length;for(let o=0;o<i;){let a=Math.min(s-this.pos,i-o);if(a===s){let c=Ne(t);for(;s<=i-o;o+=s)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Je(this),ho(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;e[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>s-o&&(this.process(n,0),o=0);for(let u=o;u<s;u++)e[u]=0;nu(n,s-8,BigInt(this.length*8),i),this.process(n,0);let a=Ne(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],i)}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:s,finished:i,destroyed:o,pos:a}=this;return t.length=s,t.pos=a,t.finished=i,t.destroyed=o,s%e&&t.buffer.set(n),t}};var rn=BigInt(4294967295),Ks=BigInt(32);function mo(r,t=!1){return t?{h:Number(r&rn),l:Number(r>>Ks&rn)}:{h:Number(r>>Ks&rn)|0,l:Number(r&rn)|0}}function su(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:i,l:o}=mo(r[s],t);[e[s],n[s]]=[i,o]}return[e,n]}var iu=(r,t)=>BigInt(r>>>0)<<Ks|BigInt(t>>>0),ou=(r,t,e)=>r>>>e,au=(r,t,e)=>r<<32-e|t>>>e,cu=(r,t,e)=>r>>>e|t<<32-e,lu=(r,t,e)=>r<<32-e|t>>>e,uu=(r,t,e)=>r<<64-e|t>>>e-32,fu=(r,t,e)=>r>>>e-32|t<<64-e,hu=(r,t)=>t,du=(r,t)=>r,pu=(r,t,e)=>r<<e|t>>>32-e,gu=(r,t,e)=>t<<e|r>>>32-e,yu=(r,t,e)=>t<<e-32|r>>>64-e,mu=(r,t,e)=>r<<e-32|t>>>64-e;function bu(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var wu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),xu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Eu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),vu=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Bu=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Au=(r,t,e,n,s,i)=>t+e+n+s+i+(r/2**32|0)|0;var Su={fromBig:mo,split:su,toBig:iu,shrSH:ou,shrSL:au,rotrSH:cu,rotrSL:lu,rotrBH:uu,rotrBL:fu,rotr32H:hu,rotr32L:du,rotlSH:pu,rotlSL:gu,rotlBH:yu,rotlBL:mu,add:bu,add3L:wu,add3H:xu,add4L:Eu,add4H:vu,add5H:Au,add5L:Bu},U=Su;var[ku,Iu]=U.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))),he=new Uint32Array(80),de=new Uint32Array(80),Ms=class extends fe{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:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:d,Gh:w,Gl:p,Hh:h,Hl:g}=this;return[t,e,n,s,i,o,a,c,f,l,u,d,w,p,h,g]}set(t,e,n,s,i,o,a,c,f,l,u,d,w,p,h,g){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=w|0,this.Gl=p|0,this.Hh=h|0,this.Hl=g|0}process(t,e){for(let b=0;b<16;b++,e+=4)he[b]=t.getUint32(e),de[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let T=he[b-15]|0,x=de[b-15]|0,S=U.rotrSH(T,x,1)^U.rotrSH(T,x,8)^U.shrSH(T,x,7),_=U.rotrSL(T,x,1)^U.rotrSL(T,x,8)^U.shrSL(T,x,7),N=he[b-2]|0,Y=de[b-2]|0,$=U.rotrSH(N,Y,19)^U.rotrBH(N,Y,61)^U.shrSH(N,Y,6),D=U.rotrSL(N,Y,19)^U.rotrBL(N,Y,61)^U.shrSL(N,Y,6),nt=U.add4L(_,D,de[b-7],de[b-16]),et=U.add4H(nt,S,$,he[b-7],he[b-16]);he[b]=et|0,de[b]=nt|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:d,Fh:w,Fl:p,Gh:h,Gl:g,Hh:m,Hl:A}=this;for(let b=0;b<80;b++){let T=U.rotrSH(u,d,14)^U.rotrSH(u,d,18)^U.rotrBH(u,d,41),x=U.rotrSL(u,d,14)^U.rotrSL(u,d,18)^U.rotrBL(u,d,41),S=u&w^~u&h,_=d&p^~d&g,N=U.add5L(A,x,_,Iu[b],de[b]),Y=U.add5H(N,m,T,S,ku[b],he[b]),$=N|0,D=U.rotrSH(n,s,28)^U.rotrBH(n,s,34)^U.rotrBH(n,s,39),nt=U.rotrSL(n,s,28)^U.rotrBL(n,s,34)^U.rotrBL(n,s,39),et=n&i^n&a^i&a,At=s&o^s&c^o&c;m=h|0,A=g|0,h=w|0,g=p|0,w=u|0,p=d|0,{h:u,l:d}=U.add(f|0,l|0,Y|0,$|0),f=a|0,l=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let E=U.add3L($,nt,At);n=U.add3H(E,Y,D,et),s=E|0}({h:n,l:s}=U.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=U.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=U.add(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:d}=U.add(this.Eh|0,this.El|0,u|0,d|0),{h:w,l:p}=U.add(this.Fh|0,this.Fl|0,w|0,p|0),{h,l:g}=U.add(this.Gh|0,this.Gl|0,h|0,g|0),{h:m,l:A}=U.add(this.Hh|0,this.Hl|0,m|0,A|0),this.set(n,s,i,o,a,c,f,l,u,d,w,p,h,g,m,A)}roundClean(){he.fill(0),de.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 Te=Qe(()=>new Ms);var sn={};ct(sn,{abytes:()=>er,bitGet:()=>Uu,bitLen:()=>Lu,bitMask:()=>vr,bitSet:()=>Du,bytesToHex:()=>zt,bytesToNumberBE:()=>Wt,bytesToNumberLE:()=>ge,concatBytes:()=>Zt,createHmacDrbg:()=>qs,ensureBytes:()=>tt,equalBytes:()=>Tu,hexToBytes:()=>Ce,hexToNumber:()=>$s,isBytes:()=>pe,numberToBytesBE:()=>ye,numberToBytesLE:()=>Le,numberToHexUnpadded:()=>Eo,numberToVarBytesBE:()=>Nu,utf8ToBytes:()=>Cu,validateObject:()=>Ot});var xo=BigInt(0),nn=BigInt(1),Ru=BigInt(2);function pe(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function er(r){if(!pe(r))throw new Error("Uint8Array expected")}var _u=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function zt(r){er(r);let t="";for(let e=0;e<r.length;e++)t+=_u[r[e]];return t}function Eo(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function $s(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Gt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function bo(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt._A&&r<=Gt._F)return r-(Gt._A-10);if(r>=Gt._a&&r<=Gt._f)return r-(Gt._a-10)}function Ce(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("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,i=0;s<e;s++,i+=2){let o=bo(r.charCodeAt(i)),a=bo(r.charCodeAt(i+1));if(o===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Wt(r){return $s(zt(r))}function ge(r){return er(r),$s(zt(Uint8Array.from(r).reverse()))}function ye(r,t){return Ce(r.toString(16).padStart(t*2,"0"))}function Le(r,t){return ye(r,t).reverse()}function Nu(r){return Ce(Eo(r))}function tt(r,t,e){let n;if(typeof t=="string")try{n=Ce(t)}catch(i){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${i}`)}else if(pe(t))n=Uint8Array.from(t);else throw new Error(`${r} must be hex string or Uint8Array`);let s=n.length;if(typeof e=="number"&&s!==e)throw new Error(`${r} expected ${e} bytes, got ${s}`);return n}function Zt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];er(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let i=r[n];e.set(i,s),s+=i.length}return e}function Tu(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 Cu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Lu(r){let t;for(t=0;r>xo;r>>=nn,t+=1);return t}function Uu(r,t){return r>>BigInt(t)&nn}function Du(r,t,e){return r|(e?nn:xo)<<BigInt(t)}var vr=r=>(Ru<<BigInt(r-1))-nn,Fs=r=>new Uint8Array(r),wo=r=>Uint8Array.from(r);function qs(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=Fs(r),s=Fs(r),i=0,o=()=>{n.fill(1),s.fill(0),i=0},a=(...u)=>e(s,n,...u),c=(u=Fs())=>{s=a(wo([0]),u),n=a(),u.length!==0&&(s=a(wo([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,d=[];for(;u<t;){n=a();let w=n.slice();d.push(w),u+=n.length}return Zt(...d)};return(u,d)=>{o(),c(u);let w;for(;!(w=d(f()));)c();return o(),w}}var Vu={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"||pe(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 Ot(r,t,e={}){let n=(s,i,o)=>{let a=Vu[i];if(typeof a!="function")throw new Error(`Invalid validator "${i}", expected function`);let c=r[s];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${i}`)};for(let[s,i]of Object.entries(t))n(s,i,!1);for(let[s,i]of Object.entries(e))n(s,i,!0);return r}var at=BigInt(0),Z=BigInt(1),Ue=BigInt(2),Ou=BigInt(3),js=BigInt(4),vo=BigInt(5),Bo=BigInt(8),Hu=BigInt(9),Pu=BigInt(16);function z(r,t){let e=r%t;return e>=at?e:t+e}function Ku(r,t,e){if(e<=at||t<at)throw new Error("Expected power/modulo > 0");if(e===Z)return at;let n=Z;for(;t>at;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function J(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function on(r,t){if(r===at||t<=at)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=z(r,t),n=t,s=at,i=Z,o=Z,a=at;for(;e!==at;){let f=n/e,l=n%e,u=s-o*f,d=i-a*f;n=e,e=l,s=o,i=a,o=u,a=d}if(n!==Z)throw new Error("invert: does not exist");return z(s,t)}function Mu(r){let t=(r-Z)/Ue,e,n,s;for(e=r-Z,n=0;e%Ue===at;e/=Ue,n++);for(s=Ue;s<r&&Ku(s,t,r)!==r-Z;s++);if(n===1){let o=(r+Z)/js;return function(c,f){let l=c.pow(f,o);if(!c.eql(c.sqr(l),f))throw new Error("Cannot find square root");return l}}let i=(e+Z)/Ue;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,l=a.pow(a.mul(a.ONE,s),e),u=a.pow(c,i),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let w=1;for(let h=a.sqr(d);w<f&&!a.eql(h,a.ONE);w++)h=a.sqr(h);let p=a.pow(l,Z<<BigInt(f-w-1));l=a.sqr(p),u=a.mul(u,p),d=a.mul(d,l),f=w}return u}}function Fu(r){if(r%js===Ou){let t=(r+Z)/js;return function(n,s){let i=n.pow(s,t);if(!n.eql(n.sqr(i),s))throw new Error("Cannot find square root");return i}}if(r%Bo===vo){let t=(r-vo)/Bo;return function(n,s){let i=n.mul(s,Ue),o=n.pow(i,t),a=n.mul(s,o),c=n.mul(n.mul(a,Ue),o),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),s))throw new Error("Cannot find square root");return f}}return r%Pu,Mu(r)}var Ao=(r,t)=>(z(r,t)&Z)===Z,$u=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ys(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=$u.reduce((n,s)=>(n[s]="function",n),t);return Ot(r,e)}function qu(r,t,e){if(e<at)throw new Error("Expected power > 0");if(e===at)return r.ONE;if(e===Z)return t;let n=r.ONE,s=t;for(;e>at;)e&Z&&(n=r.mul(n,s)),s=r.sqr(s),e>>=Z;return n}function ju(r,t){let e=new Array(t.length),n=t.reduce((i,o,a)=>r.is0(o)?i:(e[a]=i,r.mul(i,o)),r.ONE),s=r.inv(n);return t.reduceRight((i,o,a)=>r.is0(o)?i:(e[a]=r.mul(i,e[a]),r.mul(i,o)),s),e}function Gs(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function an(r,t,e=!1,n={}){if(r<=at)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:i}=Gs(r,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Fu(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:i,MASK:vr(s),ZERO:at,ONE:Z,create:c=>z(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&Z)===Z,neg:c=>z(-c,r),eql:(c,f)=>c===f,sqr:c=>z(c*c,r),add:(c,f)=>z(c+f,r),sub:(c,f)=>z(c-f,r),mul:(c,f)=>z(c*f,r),pow:(c,f)=>qu(a,c,f),div:(c,f)=>z(c*on(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>on(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>ju(a,c),cmov:(c,f,l)=>l?f:c,toBytes:c=>e?Le(c,i):ye(c,i),fromBytes:c=>{if(c.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${c.length}`);return e?ge(c):Wt(c)}});return Object.freeze(a)}function So(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 zs(r){let t=So(r);return t+Math.ceil(t/2)}function ko(r,t,e=!1){let n=r.length,s=So(t),i=zs(t);if(n<16||n<i||n>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${n}`);let o=e?Wt(r):ge(r),a=z(o,t-Z)+Z;return e?Le(a,s):ye(a,s)}var Gu=BigInt(0),Ws=BigInt(1);function cn(r,t){let e=(s,i)=>{let o=i.negate();return s?o:i},n=s=>{let i=Math.ceil(t/s)+1,o=2**(s-1);return{windows:i,windowSize:o}};return{constTimeNegate:e,unsafeLadder(s,i){let o=r.ZERO,a=s;for(;i>Gu;)i&Ws&&(o=o.add(a)),a=a.double(),i>>=Ws;return o},precomputeWindow(s,i){let{windows:o,windowSize:a}=n(i),c=[],f=s,l=f;for(let u=0;u<o;u++){l=f,c.push(l);for(let d=1;d<a;d++)l=l.add(f),c.push(l);f=l.double()}return c},wNAF(s,i,o){let{windows:a,windowSize:c}=n(s),f=r.ZERO,l=r.BASE,u=BigInt(2**s-1),d=2**s,w=BigInt(s);for(let p=0;p<a;p++){let h=p*c,g=Number(o&u);o>>=w,g>c&&(g-=d,o+=Ws);let m=h,A=h+Math.abs(g)-1,b=p%2!==0,T=g<0;g===0?l=l.add(e(b,i[m])):f=f.add(e(T,i[A]))}return{p:f,f:l}},wNAFCached(s,i,o,a){let c=s._WINDOW_SIZE||1,f=i.get(s);return f||(f=this.precomputeWindow(s,c),c!==1&&i.set(s,a(f))),this.wNAF(c,f,o)}}}function Br(r){return Ys(r.Fp),Ot(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Gs(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Nt=BigInt(0),vt=BigInt(1),ln=BigInt(2),zu=BigInt(8),Wu={zip215:!0};function Zu(r){let t=Br(r);return Ot(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Io(r){let t=Zu(r),{Fp:e,n,prehash:s,hash:i,randomBytes:o,nByteLength:a,h:c}=t,f=ln<<BigInt(a*8)-vt,l=e.create,u=t.uvRatio||((v,y)=>{try{return{isValid:!0,value:e.sqrt(v*e.inv(y))}}catch{return{isValid:!1,value:Nt}}}),d=t.adjustScalarBytes||(v=>v),w=t.domain||((v,y,I)=>{if(y.length||I)throw new Error("Contexts/pre-hash are not supported");return v}),p=v=>typeof v=="bigint"&&Nt<v,h=(v,y)=>p(v)&&p(y)&&v<y,g=v=>v===Nt||h(v,f);function m(v,y){if(h(v,y))return v;throw new Error(`Expected valid scalar < ${y}, got ${typeof v} ${v}`)}function A(v){return v===Nt?v:m(v,n)}let b=new Map;function T(v){if(!(v instanceof x))throw new Error("ExtendedPoint expected")}class x{constructor(y,I,C,L){if(this.ex=y,this.ey=I,this.ez=C,this.et=L,!g(y))throw new Error("x required");if(!g(I))throw new Error("y required");if(!g(C))throw new Error("z required");if(!g(L))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof x)throw new Error("extended point not allowed");let{x:I,y:C}=y||{};if(!g(I)||!g(C))throw new Error("invalid affine point");return new x(I,C,vt,l(I*C))}static normalizeZ(y){let I=e.invertBatch(y.map(C=>C.ez));return y.map((C,L)=>C.toAffine(I[L])).map(x.fromAffine)}_setWindowSize(y){this._WINDOW_SIZE=y,b.delete(this)}assertValidity(){let{a:y,d:I}=t;if(this.is0())throw new Error("bad point: ZERO");let{ex:C,ey:L,ez:O,et:H}=this,j=l(C*C),M=l(L*L),q=l(O*O),st=l(q*q),X=l(j*y),ut=l(q*l(X+M)),ft=l(st+l(I*l(j*M)));if(ut!==ft)throw new Error("bad point: equation left != right (1)");let ot=l(C*L),pt=l(O*H);if(ot!==pt)throw new Error("bad point: equation left != right (2)")}equals(y){T(y);let{ex:I,ey:C,ez:L}=this,{ex:O,ey:H,ez:j}=y,M=l(I*j),q=l(O*L),st=l(C*j),X=l(H*L);return M===q&&st===X}is0(){return this.equals(x.ZERO)}negate(){return new x(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:y}=t,{ex:I,ey:C,ez:L}=this,O=l(I*I),H=l(C*C),j=l(ln*l(L*L)),M=l(y*O),q=I+C,st=l(l(q*q)-O-H),X=M+H,ut=X-j,ft=M-H,ot=l(st*ut),pt=l(X*ft),qt=l(st*ft),Ie=l(ut*X);return new x(ot,pt,Ie,qt)}add(y){T(y);let{a:I,d:C}=t,{ex:L,ey:O,ez:H,et:j}=this,{ex:M,ey:q,ez:st,et:X}=y;if(I===BigInt(-1)){let Oi=l((O-L)*(q+M)),Hi=l((O+L)*(q-M)),ps=l(Hi-Oi);if(ps===Nt)return this.double();let Pi=l(H*ln*X),Ki=l(j*ln*st),Mi=Ki+Pi,Fi=Hi+Oi,$i=Ki-Pi,Pc=l(Mi*ps),Kc=l(Fi*$i),Mc=l(Mi*$i),Fc=l(ps*Fi);return new x(Pc,Kc,Fc,Mc)}let ut=l(L*M),ft=l(O*q),ot=l(j*C*X),pt=l(H*st),qt=l((L+O)*(M+q)-ut-ft),Ie=pt-ot,mr=pt+ot,Vi=l(ft-I*ut),Dc=l(qt*Ie),Vc=l(mr*Vi),Oc=l(qt*Vi),Hc=l(Ie*mr);return new x(Dc,Vc,Hc,Oc)}subtract(y){return this.add(y.negate())}wNAF(y){return N.wNAFCached(this,b,y,x.normalizeZ)}multiply(y){let{p:I,f:C}=this.wNAF(m(y,n));return x.normalizeZ([I,C])[0]}multiplyUnsafe(y){let I=A(y);return I===Nt?_:this.equals(_)||I===vt?this:this.equals(S)?this.wNAF(I).p:N.unsafeLadder(this,I)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,n).is0()}toAffine(y){let{ex:I,ey:C,ez:L}=this,O=this.is0();y==null&&(y=O?zu:e.inv(L));let H=l(I*y),j=l(C*y),M=l(L*y);if(O)return{x:Nt,y:vt};if(M!==vt)throw new Error("invZ was invalid");return{x:H,y:j}}clearCofactor(){let{h:y}=t;return y===vt?this:this.multiplyUnsafe(y)}static fromHex(y,I=!1){let{d:C,a:L}=t,O=e.BYTES;y=tt("pointHex",y,O);let H=y.slice(),j=y[O-1];H[O-1]=j&-129;let M=ge(H);M===Nt||(I?m(M,f):m(M,e.ORDER));let q=l(M*M),st=l(q-vt),X=l(C*q-L),{isValid:ut,value:ft}=u(st,X);if(!ut)throw new Error("Point.fromHex: invalid y coordinate");let ot=(ft&vt)===vt,pt=(j&128)!==0;if(!I&&ft===Nt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==ot&&(ft=l(-ft)),x.fromAffine({x:ft,y:M})}static fromPrivateKey(y){return D(y).point}toRawBytes(){let{x:y,y:I}=this.toAffine(),C=Le(I,e.BYTES);return C[C.length-1]|=y&vt?128:0,C}toHex(){return zt(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,vt,l(t.Gx*t.Gy)),x.ZERO=new x(Nt,vt,vt,Nt);let{BASE:S,ZERO:_}=x,N=cn(x,a*8);function Y(v){return z(v,n)}function $(v){return Y(ge(v))}function D(v){let y=a;v=tt("private key",v,y);let I=tt("hashed private key",i(v),2*y),C=d(I.slice(0,y)),L=I.slice(y,2*y),O=$(C),H=S.multiply(O),j=H.toRawBytes();return{head:C,prefix:L,scalar:O,point:H,pointBytes:j}}function nt(v){return D(v).pointBytes}function et(v=new Uint8Array,...y){let I=Zt(...y);return $(i(w(I,tt("context",v),!!s)))}function At(v,y,I={}){v=tt("message",v),s&&(v=s(v));let{prefix:C,scalar:L,pointBytes:O}=D(y),H=et(I.context,C,v),j=S.multiply(H).toRawBytes(),M=et(I.context,j,O,v),q=Y(H+M*L);A(q);let st=Zt(j,Le(q,e.BYTES));return tt("result",st,a*2)}let E=Wu;function R(v,y,I,C=E){let{context:L,zip215:O}=C,H=e.BYTES;v=tt("signature",v,2*H),y=tt("message",y),s&&(y=s(y));let j=ge(v.slice(H,2*H)),M,q,st;try{M=x.fromHex(I,O),q=x.fromHex(v.slice(0,H),O),st=S.multiplyUnsafe(j)}catch{return!1}if(!O&&M.isSmallOrder())return!1;let X=et(L,q.toRawBytes(),M.toRawBytes(),y);return q.add(M.multiplyUnsafe(X)).subtract(st).clearCofactor().equals(x.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:nt,sign:At,verify:R,ExtendedPoint:x,utils:{getExtendedPublicKey:D,randomPrivateKey:()=>o(e.BYTES),precompute(v=8,y=x.BASE){return y._setWindowSize(v),y.multiply(BigInt(3)),y}}}}var Zs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ro=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),U0=BigInt(0),Ju=BigInt(1),_o=BigInt(2),D0=BigInt(3),Xu=BigInt(5),Qu=BigInt(8);function tf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),i=Zs,a=r*r%i*r%i,c=J(a,_o,i)*a%i,f=J(c,Ju,i)*r%i,l=J(f,Xu,i)*f%i,u=J(l,t,i)*l%i,d=J(u,e,i)*u%i,w=J(d,n,i)*d%i,p=J(w,s,i)*w%i,h=J(p,s,i)*w%i,g=J(h,t,i)*l%i;return{pow_p_5_8:J(g,_o,i)*r%i,b2:a}}function ef(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function rf(r,t){let e=Zs,n=z(t*t*t,e),s=z(n*n*t,e),i=tf(r*s).pow_p_5_8,o=z(r*n*i,e),a=z(t*o*o,e),c=o,f=z(o*Ro,e),l=a===r,u=a===z(-r,e),d=a===z(-r*Ro,e);return l&&(o=c),(u||d)&&(o=f),Ao(o,e)&&(o=z(-o,e)),{isValid:l||u,value:o}}var nf=an(Zs,void 0,!0),sf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:nf,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Qu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Te,randomBytes:tr,adjustScalarBytes:ef,uvRatio:rf},rr=Io(sf);var nr=32,Jt=64,un=32;function No(){let r=rr.utils.randomPrivateKey(),t=rr.getPublicKey(r);return{privateKey:Uo(r,t),publicKey:t}}function To(r){if(r.length!==un)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=rr.getPublicKey(t);return{privateKey:Uo(t,e),publicKey:e}}function Co(r,t){let e=r.subarray(0,un);return rr.sign(t instanceof Uint8Array?t:t.subarray(),e)}function Lo(r,t,e){return rr.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}function Uo(r,t){let e=new Uint8Array(Jt);for(let n=0;n<un;n++)e[n]=r[n],e[un+n]=t[n];return e}var Js={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function fn(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",i=r?.saltLength??16,o=r?.iterations??32767,a=mt.get();e*=8;async function c(u,d){let w=a.getRandomValues(new Uint8Array(i)),p=a.getRandomValues(new Uint8Array(n)),h={name:t,iv:p};typeof d=="string"&&(d=P(d));let g;if(d.length===0){g=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["encrypt"]);try{let A={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},b=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(A,b,{name:t,length:e},!0,["encrypt"])}catch{g=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["encrypt"])}}else{let A={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},b=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(A,b,{name:t,length:e},!0,["encrypt"])}let m=await a.subtle.encrypt(h,g,u);return Is([w,h.iv,new Uint8Array(m)])}async function f(u,d){let w=u.subarray(0,i),p=u.subarray(i,i+n),h=u.subarray(i+n),g={name:t,iv:p};typeof d=="string"&&(d=P(d));let m;if(d.length===0)try{let b={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},T=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(b,T,{name:t,length:e},!0,["decrypt"])}catch{m=await a.subtle.importKey("jwk",Js,{name:"AES-GCM"},!0,["decrypt"])}else{let b={name:"PBKDF2",salt:w,iterations:o,hash:{name:s}},T=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);m=await a.subtle.deriveKey(b,T,{name:t,length:e},!0,["decrypt"])}let A=await a.subtle.decrypt(g,m,h);return new Uint8Array(A)}return{encrypt:c,decrypt:f}}async function sr(r,t){let n=await fn().encrypt(r,t);return _e.encode(n)}var af=Math.pow(2,7),cf=Math.pow(2,14),lf=Math.pow(2,21),Vo=Math.pow(2,28),Oo=Math.pow(2,35),Ho=Math.pow(2,42),Po=Math.pow(2,49),wt=128,me=127;function Ar(r){if(r<af)return 1;if(r<cf)return 2;if(r<lf)return 3;if(r<Vo)return 4;if(r<Oo)return 5;if(r<Ho)return 6;if(r<Po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ko(r,t,e=0){switch(Ar(r)){case 8:t[e++]=r&255|wt,r/=128;case 7:t[e++]=r&255|wt,r/=128;case 6:t[e++]=r&255|wt,r/=128;case 5:t[e++]=r&255|wt,r/=128;case 4:t[e++]=r&255|wt,r>>>=7;case 3:t[e++]=r&255|wt,r>>>=7;case 2:t[e++]=r&255|wt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Mo(r,t){let e=r[t],n=0;if(n+=e&me,e<wt||(e=r[t+1],n+=(e&me)<<7,e<wt)||(e=r[t+2],n+=(e&me)<<14,e<wt)||(e=r[t+3],n+=(e&me)<<21,e<wt)||(e=r[t+4],n+=(e&me)*Vo,e<wt)||(e=r[t+5],n+=(e&me)*Oo,e<wt)||(e=r[t+6],n+=(e&me)*Ho,e<wt)||(e=r[t+7],n+=(e&me)*Po,e<wt))return n;throw new RangeError("Could not decode varint")}var Xs=new Float32Array([-0]),be=new Uint8Array(Xs.buffer);function Fo(r,t,e){Xs[0]=r,t[e]=be[0],t[e+1]=be[1],t[e+2]=be[2],t[e+3]=be[3]}function $o(r,t){return be[0]=r[t],be[1]=r[t+1],be[2]=r[t+2],be[3]=r[t+3],Xs[0]}var Qs=new Float64Array([-0]),gt=new Uint8Array(Qs.buffer);function qo(r,t,e){Qs[0]=r,t[e]=gt[0],t[e+1]=gt[1],t[e+2]=gt[2],t[e+3]=gt[3],t[e+4]=gt[4],t[e+5]=gt[5],t[e+6]=gt[6],t[e+7]=gt[7]}function jo(r,t){return gt[0]=r[t],gt[1]=r[t+1],gt[2]=r[t+2],gt[3]=r[t+3],gt[4]=r[t+4],gt[5]=r[t+5],gt[6]=r[t+6],gt[7]=r[t+7],Qs[0]}var uf=BigInt(Number.MAX_SAFE_INTEGER),ff=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 De;if(t<uf&&t>ff)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Yo&&(s=0n,++n>Yo&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return De;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):De}},De=new Bt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var Yo=4294967296n;function Go(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 zo(r,t,e){if(e-t<1)return"";let s,i=[],o=0,a;for(;t<e;)a=r[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function ti(r,t,e){let n=e,s,i;for(let o=0;o<r.length;++o)s=r.charCodeAt(o),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((i=r.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function hn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ei=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,Tt(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 Tt(this,4);return hn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return hn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=$o(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=jo(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return zo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while(this.buf[this.pos++]&128);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 Tt(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.pos>=this.len)throw Tt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Tt(this,8);let t=hn(this.buf,this.pos+=4),e=hn(this.buf,this.pos+=4);return new Bt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Mo(this.buf,this.pos);return this.pos+=Ar(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ri(r){return new ei(r instanceof Uint8Array?r:r.subarray())}function dn(r,t,e){let n=ri(r);return t.decode(n,void 0,e)}function ni(r){let t=r??8192,e=t>>>1,n,s=t;return function(o){if(o<1||o>e)return Vt(o);s+o>t&&(n=Vt(t),s=0);let a=n.subarray(s,s+=o);return s&7&&(s=(s|7)+1),a}}var Ve=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function si(){}var oi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hf=ni();function df(r){return globalThis.Buffer!=null?Vt(r):hf(r)}var kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ve(si,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ve(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ai((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(pn,10,Bt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Bt.fromBigInt(t);return this._push(pn,e.length(),e)}uint64Number(t){return this._push(Ko,Ar(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Bt.fromBigInt(t).zzEncode();return this._push(pn,e.length(),e)}sint64Number(t){let e=Bt.fromNumber(t).zzEncode();return this._push(pn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ii,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Bt.fromBigInt(t);return this._push(Sr,4,e.lo)._push(Sr,4,e.hi)}fixed64Number(t){let e=Bt.fromNumber(t);return this._push(Sr,4,e.lo)._push(Sr,4,e.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(Fo,4,t)}double(t){return this._push(qo,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ii,1,0):this.uint32(e)._push(gf,e,t)}string(t){let e=Go(t);return e!==0?this.uint32(e)._push(ti,e,t):this._push(ii,1,0)}fork(){return this.states=new oi(this),this.head=this.tail=new Ve(si,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 Ve(si,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=df(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ii(r,t,e){t[e]=r&255}function pf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ai=class extends Ve{next;constructor(t,e){super(pf,t,e),this.next=void 0}};function pn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Sr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function gf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(kr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yf,t,r),this},kr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(mf,t,r),this});function yf(r,t,e){t.set(r,e)}function mf(r,t,e){r.length<40?ti(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(P(r),e)}function ci(){return new kr}function gn(r,t){let e=ci();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ir;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ir||(ir={}));function yn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function li(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,o){let a=t(i);o.int32(a)},n=function(i){let o=i.int32();return t(o)};return yn("enum",ir.VARINT,e,n)}function mn(r,t){return yn("message",ir.LENGTH_DELIMITED,r,t)}var rt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1"})(rt||(rt={}));var ui;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1"})(ui||(ui={}));(function(r){r.codec=()=>li(ui)})(rt||(rt={}));var Xt;(function(r){let t;r.codec=()=>(t==null&&(t=mn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let o=e.uint32();switch(o>>>3){case 1:s.Type=rt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(o&7);break}}return s})),t),r.encode=e=>gn(e,r.codec()),r.decode=e=>dn(e,r.codec())})(Xt||(Xt={}));var Ht;(function(r){let t;r.codec=()=>(t==null&&(t=mn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),rt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let o=e.uint32();switch(o>>>3){case 1:s.Type=rt.codec().decode(e);break;case 2:s.Data=e.bytes();break;default:e.skipType(o&7);break}}return s})),t),r.encode=e=>gn(e,r.codec()),r.decode=e=>dn(e,r.codec())})(Ht||(Ht={}));var Ir=class{_key;constructor(t){this._key=or(t,nr)}verify(t,e){return Lo(this._key,e,t)}marshal(){return this._key}get bytes(){return Xt.encode({Type:rt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}},Oe=class{_key;_publicKey;constructor(t,e){this._key=or(t,Jt),this._publicKey=or(e,nr)}sign(t){return Co(this._key,t)}get public(){return new Ir(this._publicKey)}marshal(){return this._key}get bytes(){return Ht.encode({Type:rt.Ed25519,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}async hash(){let t=ht.digest(this.bytes),e;return kt(t)?{bytes:e}=await t:e=t.bytes,e}async id(){let t=Yt.digest(this.public.bytes);return bt.encode(t.bytes).substring(1)}async export(t,e="libp2p-key"){if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function bf(r){if(r.length>Jt){r=or(r,Jt+nr);let n=r.subarray(0,Jt),s=r.subarray(Jt,r.length);return new Oe(n,s)}r=or(r,Jt);let t=r.subarray(0,Jt),e=r.subarray(nr);return new Oe(t,e)}function wf(r){return r=or(r,nr),new Ir(r)}async function xf(){let{privateKey:r,publicKey:t}=No();return new Oe(r,t)}async function Zo(r){let{privateKey:t,publicKey:e}=To(r);return new Oe(t,e)}function or(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new B(`Key must be a Uint8Array of length ${t}, got ${r.length}`,"ERR_INVALID_KEY_TYPE");return r}function G(r,t="utf8"){let e=Zr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}async function Jo(r,t){let e=_e.decode(r);return fn().decrypt(e,t)}var vi={};ct(vi,{MAX_RSA_KEY_SIZE:()=>Pr,RsaPrivateKey:()=>fr,RsaPublicKey:()=>Hr,fromJwk:()=>qf,generateKeyPair:()=>jf,unmarshalRsaPrivateKey:()=>xi,unmarshalRsaPublicKey:()=>$f});function Pt(r){if(isNaN(r)||r<=0)throw new B("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return tr(r)}var ve={};ct(ve,{exportToPem:()=>Pf,importFromPem:()=>wi,jwkToPkcs1:()=>Df,jwkToPkix:()=>Of,pkcs1ToJwk:()=>Uf,pkixToJwk:()=>Vf});var wn=class extends Xe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Jr(t);let n=ue(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,i=new Uint8Array(s);i.set(n.length>s?t.create().update(n).digest():n);for(let o=0;o<i.length;o++)i[o]^=54;this.iHash.update(i),this.oHash=t.create();for(let o=0;o<i.length;o++)i[o]^=106;this.oHash.update(i),i.fill(0)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),Ze(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Rr=(r,t,e)=>new wn(r,t).update(e).digest();Rr.create=(r,t)=>new wn(r,t);function Xo(r,t,e,n){Jr(r);let s=yo({dkLen:32,asyncTick:10},n),{c:i,dkLen:o,asyncTick:a}=s;if(We(i),We(o),We(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=ue(t),f=ue(e),l=new Uint8Array(o),u=Rr.create(r,c),d=u._cloneInto().update(f);return{c:i,dkLen:o,asyncTick:a,DK:l,PRF:u,PRFSalt:d}}function Qo(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}function ta(r,t,e,n){let{c:s,dkLen:i,DK:o,PRF:a,PRFSalt:c}=Xo(r,t,e,n),f,l=new Uint8Array(4),u=Ne(l),d=new Uint8Array(a.outputLen);for(let w=1,p=0;p<i;w++,p+=a.outputLen){let h=o.subarray(p,p+a.outputLen);u.setInt32(0,w,!1),(f=c._cloneInto(f)).update(l).digestInto(d),h.set(d.subarray(0,h.length));for(let g=1;g<s;g++){a._cloneInto(f).update(d).digestInto(d);for(let m=0;m<h.length;m++)h[m]^=d[m]}}return Qo(a,c,o,f,d)}async function hi(r,t,e,n){let{c:s,dkLen:i,asyncTick:o,DK:a,PRF:c,PRFSalt:f}=Xo(r,t,e,n),l,u=new Uint8Array(4),d=Ne(u),w=new Uint8Array(c.outputLen);for(let p=1,h=0;h<i;p++,h+=c.outputLen){let g=a.subarray(h,h+c.outputLen);d.setInt32(0,p,!1),(l=f._cloneInto(l)).update(u).digestInto(w),g.set(w.subarray(0,g.length)),await po(s-1,o,()=>{c._cloneInto(l).update(w).digestInto(w);for(let m=0;m<g.length;m++)g[m]^=w[m]})}return Qo(c,f,a,l,w)}var K=gs(ea());function He(r,t){let e=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)e+=r[r.length-1-n]*Math.pow(2,t*n);return e}function we(r,t,e=-1){let n=e,s=r,i=0,o=Math.pow(2,t);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),i=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),i=n}let f=new Uint8Array(c);for(let l=a-1;l>=0;l--){let u=Math.pow(2,l*t);f[i-l-1]=Math.floor(s/u),s-=f[i-l-1]*u}return c}o*=Math.pow(2,t)}return new ArrayBuffer(0)}function vn(...r){let t=0,e=0;for(let i of r)t+=i.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let i of r)s.set(i,e),e+=i.length;return s}function pi(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let t=new ArrayBuffer(this.valueHex.byteLength),e=new Uint8Array(t);for(let a=0;a<this.valueHex.byteLength;a++)e[a]=0;e[0]=r[0]&128;let n=He(e,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=r[a];return i[0]&=127,He(i,8)-n}function ra(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let o=e-t,a=we(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=we(t,8,n),i=new Uint8Array(s);if(i[0]&128){let o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function na(r,t){if(r.byteLength!==t.byteLength)return!1;let e=new Uint8Array(r),n=new Uint8Array(t);for(let s=0;s<e.length;s++)if(e[s]!==n[s])return!1;return!0}function Et(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let o=0;o<n;o++)s[o]="0";return s.join("").concat(e)}var jp=Math.log(2);function Bn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function gi(r){let t=0,e=0;for(let s=0;s<r.length;s++){let i=r[s];t+=i.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let i=r[s];n.set(new Uint8Array(i),e),e+=i.byteLength}return n.buffer}function ne(r,t,e,n){return t instanceof Uint8Array?t.byteLength?e<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):t.byteLength-e-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Nr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return gi(this.items)}},_r=[new Uint8Array([1])],sa="0123456789";var lr="",Lt=new ArrayBuffer(0),yi=new Uint8Array(0),Tr="EndOfContent",oa="OCTET STRING",aa="BIT STRING";function se(r){var t;return t=class extends r{constructor(...n){var s;super(...n);let i=n[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?K.BufferSourceConverter.toUint8Array(i.valueHex):yi}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,i){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!ne(this,o,s,i))return-1;let a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Lt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:K.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var te=class{constructor({blockLength:t=0,error:e=lr,warnings:n=[],valueBeforeDecode:s=yi}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=K.BufferSourceConverter.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(t){this.valueBeforeDecodeView=new Uint8Array(t)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:K.Convert.ToHex(this.valueBeforeDecodeView)}}};te.NAME="baseBlock";var yt=class extends te{fromBER(t,e,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(t,e){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};yt.NAME="valueBlock";var An=class extends se(te){constructor({idBlock:t={}}={}){var e,n,s,i;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?K.BufferSourceConverter.toUint8Array(t.valueHex):yi,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=t.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(t=!1){let e=0;switch(this.tagClass){case 1:e|=0;break;case 2:e|=64;break;case 3:e|=128;break;case 4:e|=192;break;default:return this.error="Unknown tag class",Lt}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let i=this.tagNumber;i&=31,e|=i,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=we(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=e|31,!t){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=e|31,!t){let s=this.valueHexView;for(let i=0;i<s.length-1;i++)n[i+1]=s[i]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;let a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),l=255;for(;i[c]&128;){if(f[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let d=new Uint8Array(l);for(let w=0;w<f.length;w++)d[w]=f[w];f=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,f[c-1]=i[c]&127;let u=new Uint8Array(c);for(let d=0;d<c;d++)u[d]=f[d];f=this.valueHexView=new Uint8Array(c),f.set(u),this.blockLength<=9?this.tagNumber=He(f,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return e+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};An.NAME="identificationBlock";var Sn=class extends te{constructor({lenBlock:t={}}={}){var e,n,s;super(),this.isIndefiniteForm=(e=t.isIndefiniteForm)!==null&&e!==void 0?e:!1,this.longFormUsed=(n=t.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(s=t.length)!==null&&s!==void 0?s:0}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,e+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,e+this.blockLength;let o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=He(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,e+this.blockLength}toBER(t=!1){let e,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=128),e;if(this.longFormUsed){let s=we(this.length,8);if(s.byteLength>127)return this.error="Too big length",Lt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let i=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)n[o+1]=i[o];return e}return e=new ArrayBuffer(1),t===!1&&(n=new Uint8Array(e),n[0]=this.length),e}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Sn.NAME="lengthBlock";var k={},dt=class extends te{constructor({name:t=lr,optional:e=!1,primitiveSchema:n,...s}={},i){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new An(s),this.lenBlock=new Sn(s),this.valueBlock=i?new i(s):new yt(s)}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(t,e){let n=e||new Nr;e||ca(this);let s=this.idBlock.toBER(t);if(n.write(s),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(t,n),n.write(new ArrayBuffer(2));else{let i=this.valueBlock.toBER(t);this.lenBlock.length=i.byteLength;let o=this.lenBlock.toBER(t);n.write(o),n.write(i)}return e?Lt:n.final()}toJSON(){let t={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(t.primitiveSchema=this.primitiveSchema.toJSON()),t}toString(t="ascii"){return t==="ascii"?this.onAsciiEncoding():K.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${K.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(t){if(this===t)return!0;if(!(t instanceof this.constructor))return!1;let e=this.toBER(),n=t.toBER();return na(e,n)}};dt.NAME="BaseBlock";function ca(r){if(r instanceof k.Constructed)for(let t of r.valueBlock.value)ca(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var kn=class extends dt{constructor({value:t=lr,...e}={},n){super(e,n),t&&this.fromString(t)}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}fromBER(t,e,n){let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};kn.NAME="BaseStringBlock";var In=class extends se(yt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};In.NAME="PrimitiveValueBlock";var la,Rn=class extends dt{constructor(t={}){super(t,In),this.idBlock.isConstructed=!1}};la=Rn;k.Primitive=la;Rn.NAME="PRIMITIVE";function _f(r,t){if(r instanceof t)return r;let e=new t;return e.idBlock=r.idBlock,e.lenBlock=r.lenBlock,e.warnings=r.warnings,e.valueBeforeDecodeView=r.valueBeforeDecodeView,e}function as(r,t=0,e=r.length){let n=t,s=new dt({},yt),i=new te;if(!ne(i,r,t,e))return s.error=i.error,{offset:-1,result:s};if(!r.subarray(t,t+e).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(r,t,e);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=a,e-=s.idBlock.blockLength,a=s.lenBlock.fromBER(r,t,e),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=a,e-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=dt;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=k.EndOfContent;break;case 1:c=k.Boolean;break;case 2:c=k.Integer;break;case 3:c=k.BitString;break;case 4:c=k.OctetString;break;case 5:c=k.Null;break;case 6:c=k.ObjectIdentifier;break;case 10:c=k.Enumerated;break;case 12:c=k.Utf8String;break;case 13:c=k.RelativeObjectIdentifier;break;case 14:c=k.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=k.Sequence;break;case 17:c=k.Set;break;case 18:c=k.NumericString;break;case 19:c=k.PrintableString;break;case 20:c=k.TeletexString;break;case 21:c=k.VideotexString;break;case 22:c=k.IA5String;break;case 23:c=k.UTCTime;break;case 24:c=k.GeneralizedTime;break;case 25:c=k.GraphicString;break;case 26:c=k.VisibleString;break;case 27:c=k.GeneralString;break;case 28:c=k.UniversalString;break;case 29:c=k.CharacterString;break;case 30:c=k.BmpString;break;case 31:c=k.DATE;break;case 32:c=k.TimeOfDay;break;case 33:c=k.DateTime;break;case 34:c=k.Duration;break;default:{let f=s.idBlock.isConstructed?new k.Constructed:new k.Primitive;f.idBlock=s.idBlock,f.lenBlock=s.lenBlock,f.warnings=s.warnings,s=f}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?k.Constructed:k.Primitive}return s=_f(s,c),a=s.fromBER(r,t,s.lenBlock.isIndefiniteForm?e:s.lenBlock.length),s.valueBeforeDecodeView=r.subarray(n,n+s.blockLength),{offset:a,result:s}}function ur(r){if(!r.byteLength){let t=new dt({},yt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return as(K.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Nf(r,t){return r?1:t}var Kt=class extends yt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;if(this.valueBeforeDecodeView=s.subarray(e,e+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),e;let i=e;for(;Nf(this.isIndefiniteForm,n)>0;){let o=as(s,i,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Tr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Tr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(t,e){let n=e||new Nr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Lt:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Kt.NAME="ConstructedValueBlock";var ua,xe=class extends dt{constructor(t={}){super(t,Kt),this.idBlock.isConstructed=!0}fromBER(t,e,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let s=this.valueBlock.fromBER(t,e,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){let t=[];for(let n of this.valueBlock.value)t.push(n.toString("ascii").split(`
|
|
3
3
|
`).map(s=>` ${s}`).join(`
|
|
4
4
|
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
5
|
${t.join(`
|
|
6
6
|
`)}`:`${e} :`}};ua=xe;k.Constructed=ua;xe.NAME="CONSTRUCTED";var _n=class extends yt{fromBER(t,e,n){return e}toBER(t){return Lt}};_n.override="EndOfContentValueBlock";var fa,Nn=class extends dt{constructor(t={}){super(t,_n),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};fa=Nn;k.EndOfContent=fa;Nn.NAME=Tr;var ha,Ee=class extends dt{constructor(t={}){super(t,yt),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};ha=Ee;k.Null=ha;Ee.NAME="NULL";var Tn=class extends se(yt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=K.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=K.BufferSourceConverter.toUint8Array(t);return ne(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,pi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Tn.NAME="BooleanValueBlock";var da,Cn=class extends dt{constructor(t={}){super(t,Tn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};da=Cn;k.Boolean=da;Cn.NAME="BOOLEAN";var Ln=class extends se(Kt){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=Kt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let i=0;i<this.value.length;i++){let o=this.value[i].constructor.NAME;if(o===Tr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==oa)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?Kt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Ln.NAME="OctetStringValueBlock";var pa,ee=class r extends dt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Ln),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),e;if(!this.valueBlock.isConstructed){let i=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(i.byteLength){let o=as(i,0,i.byteLength);o.offset!==-1&&o.offset===n&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?xe.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${K.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return K.BufferSourceConverter.concat(t)}};pa=ee;k.OctetString=pa;ee.NAME=oa;var Un=class extends se(Kt){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=Kt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Tr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==aa)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return s}let i=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,i,e,n))return-1;let o=i.subarray(e,e+n);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=o.subarray(1);try{if(a.byteLength){let c=as(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,e+n}toBER(t,e){if(this.isConstructed)return Kt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Lt;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};Un.NAME="BitStringValueBlock";var ga,cr=class extends dt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,i;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Un),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return xe.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};ga=cr;k.BitString=ga;cr.NAME=aa;var ya;function Tf(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f=0,l=c<o?o:c,u=0;for(let d=l;d>=0;d--,u++){switch(!0){case u<a.length:f=i[o-u]+a[c-u]+e[0];break;default:f=i[o-u]+e[0]}switch(e[0]=f/10,!0){case u>=i.length:i=vn(new Uint8Array([f%10]),i);break;default:i[o-u]=f%10}}return e[0]>0&&(i=vn(e,i)),i}function ia(r){if(r>=_r.length)for(let t=_r.length;t<=r;t++){let e=new Uint8Array([0]),n=_r[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let i=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=i[0]/10,n[s]=i[0]%10}e[0]>0&&(n=vn(e,n)),_r.push(n)}return _r[r]}function Cf(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),i=n.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1,f,l=0;for(let u=c;u>=0;u--,l++)switch(f=i[o-l]-a[c-l]-e,!0){case f<0:e=1,i[o-l]=f+10;break;default:e=0,i[o-l]=f}if(e>0)for(let u=o-c+1;u>=0;u--,l++)if(f=i[o-l]-e,f<0)e=1,i[o-l]=f+10;else{e=0,i[o-l]=f;break}return i.slice()}var Cr=class extends se(yt){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=pi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ra(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let i=this.fromBER(t,e,n);if(i===-1)return i;let o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,i=this.valueHexView,o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let f=0;f<8;f++){if((s&1)===1)switch(n){case t:e=Cf(ia(n),e),o="-";break;default:e=Tf(e,ia(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(o+=sa.charAt(e[c]));return a===!1&&(o+=sa.charAt(0)),o}};ya=Cr;Cr.NAME="IntegerValueBlock";Object.defineProperty(ya.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var ma,it=class r extends dt{constructor(t={}){super(t,Cr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Bn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Bn();let e=BigInt(t),n=new Nr,s=e.toString(16).replace(/^-/,""),i=new Uint8Array(K.Convert.FromHex(s));if(e<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${K.Convert.ToHex(a)}`)+e,l=K.BufferSourceConverter.toUint8Array(K.Convert.FromHex(f.toString(16)));l[0]|=128,n.write(l)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};ma=it;k.Integer=ma;it.NAME="INTEGER";var ba,Dn=class extends it{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};ba=Dn;k.Enumerated=ba;Dn.NAME="ENUMERATED";var Lr=class extends se(yt){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=He(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Bn();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Lt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),i=e.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n}toString(){let t="";if(this.isHexOnly)t=K.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Lr.NAME="sidBlock";var Vn=class extends yt{constructor({value:t=lr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let i=new Lr;if(s=i.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Lt;e.push(s)}return gi(e)}fromString(t){this.value=[];let e=0,n=0,s="",i=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,i){let o=this.value[0],a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{let o=new Lr;if(s>Number.MAX_SAFE_INTEGER){Bn();let a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};Vn.NAME="ObjectIdentifierValueBlock";var wa,Ct=class extends dt{constructor(t={}){super(t,Vn),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};wa=Ct;k.ObjectIdentifier=wa;Ct.NAME="OBJECT IDENTIFIER";var Ur=class extends se(te){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=K.BufferSourceConverter.toUint8Array(t);if(!ne(this,s,e,n))return-1;let i=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);let o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=He(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Lt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),i=e.byteLength-1;for(let o=0;o<i;o++)n[o]=s[o]|128;n[i]=s[i]}return n.buffer}toString(){let t="";return this.isHexOnly?t=K.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Ur.NAME="relativeSidBlock";var On=class extends yt{constructor({value:t=lr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let i=new Ur;if(s=i.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let i=this.value[s].toBER(t);if(i.byteLength===0)return this.error=this.value[s].error,Lt;n.push(i)}return gi(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let i=new Ur;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};On.NAME="RelativeObjectIdentifierValueBlock";var xa,Hn=class extends dt{constructor(t={}){super(t,On),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};xa=Hn;k.RelativeObjectIdentifier=xa;Hn.NAME="RelativeObjectIdentifier";var Ea,lt=class extends xe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ea=lt;k.Sequence=Ea;lt.NAME="SEQUENCE";var va,Pn=class extends xe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};va=Pn;k.Set=va;Pn.NAME="SET";var Kn=class extends se(yt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=lr}toJSON(){return{...super.toJSON(),value:this.value}}};Kn.NAME="StringValueBlock";var Mn=class extends Kn{};Mn.NAME="SimpleStringValueBlock";var xt=class extends kn{constructor({...t}={}){super(t,Mn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};xt.NAME="SIMPLE STRING";var Fn=class extends xt{fromBuffer(t){this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=K.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=K.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf8String(t)),this.valueBlock.value=t}};Fn.NAME="Utf8StringValueBlock";var Ba,re=class extends Fn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ba=re;k.Utf8String=Ba;re.NAME="UTF8String";var $n=class extends xt{fromBuffer(t){this.valueBlock.value=K.Convert.ToUtf16String(t),this.valueBlock.valueHexView=K.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(K.Convert.FromUtf16String(t))}};$n.NAME="BmpStringValueBlock";var Aa,qn=class extends $n{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Aa=qn;k.BmpString=Aa;qn.NAME="BMPString";var jn=class extends xt{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let i=we(t.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;let a=4-o.length;for(let c=o.length-1;c>=0;c--)n[s*4+c+a]=o[c]}this.valueBlock.value=t}};jn.NAME="UniversalStringValueBlock";var Sa,Yn=class extends jn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Sa=Yn;k.UniversalString=Sa;Yn.NAME="UniversalString";var ka,Gn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};ka=Gn;k.NumericString=ka;Gn.NAME="NumericString";var Ia,zn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ia=zn;k.PrintableString=Ia;zn.NAME="PrintableString";var Ra,Wn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Ra=Wn;k.TeletexString=Ra;Wn.NAME="TeletexString";var _a,Zn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};_a=Zn;k.VideotexString=_a;Zn.NAME="VideotexString";var Na,Jn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Na=Jn;k.IA5String=Na;Jn.NAME="IA5String";var Ta,Xn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Ta=Xn;k.GraphicString=Ta;Xn.NAME="GraphicString";var Ca,Dr=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Ca=Dr;k.VisibleString=Ca;Dr.NAME="VisibleString";var La,Qn=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};La=Qn;k.GeneralString=La;Qn.NAME="GeneralString";var Ua,ts=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Ua=ts;k.CharacterString=Ua;ts.NAME="CharacterString";var Da,Vr=class extends Dr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,K.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=Et(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Et(this.month,2),e[2]=Et(this.day,2),e[3]=Et(this.hour,2),e[4]=Et(this.minute,2),e[5]=Et(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};Da=Vr;k.UTCTime=Da;Vr.NAME="UTCTime";var Va,es=class extends Vr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",i=0,o,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let u=new Number(t[t.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let u=1,d=n.indexOf("+"),w="";if(d===-1&&(d=n.indexOf("-"),u=-1),d!==-1){if(w=n.substring(d+1),n=n.substring(0,d),w.length!==2&&w.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(w.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*p,w.length===4){if(p=parseInt(w.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");c=u*p}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let u=new Number(`0${n.substring(f)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");i=u.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=60*i;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=60*i;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let u=1e3*i;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}let l=o.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let u=1;u<l.length;u++)switch(u){case 1:this.year=parseInt(l[u],10);break;case 2:this.month=parseInt(l[u],10);break;case 3:this.day=parseInt(l[u],10);break;case 4:this.hour=parseInt(l[u],10)+a;break;case 5:this.minute=parseInt(l[u],10)+c;break;case 6:this.second=parseInt(l[u],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let u=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=u.getUTCFullYear(),this.month=u.getUTCMonth(),this.day=u.getUTCDay(),this.hour=u.getUTCHours(),this.minute=u.getUTCMinutes(),this.second=u.getUTCSeconds(),this.millisecond=u.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Et(this.year,4)),e.push(Et(this.month,2)),e.push(Et(this.day,2)),e.push(Et(this.hour,2)),e.push(Et(this.minute,2)),e.push(Et(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Et(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Va=es;k.GeneralizedTime=Va;es.NAME="GeneralizedTime";var Oa,rs=class extends re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Oa=rs;k.DATE=Oa;rs.NAME="DATE";var Ha,ns=class extends re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Ha=ns;k.TimeOfDay=Ha;ns.NAME="TimeOfDay";var Pa,ss=class extends re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Pa=ss;k.DateTime=Pa;ss.NAME="DateTime";var Ka,is=class extends re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Ka=is;k.Duration=Ka;is.NAME="Duration";var Ma,os=class extends re{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Ma=os;k.TIME=Ma;os.NAME="TIME";function Uf(r){let{result:t}=ur(r),e=t.valueBlock.value;return{n:G(Mt(e[1].toBigInt()),"base64url"),e:G(Mt(e[2].toBigInt()),"base64url"),d:G(Mt(e[3].toBigInt()),"base64url"),p:G(Mt(e[4].toBigInt()),"base64url"),q:G(Mt(e[5].toBigInt()),"base64url"),dp:G(Mt(e[6].toBigInt()),"base64url"),dq:G(Mt(e[7].toBigInt()),"base64url"),qi:G(Mt(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function Df(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new B("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new lt({value:[new it({value:0}),it.fromBigInt(Ft(P(r.n,"base64url"))),it.fromBigInt(Ft(P(r.e,"base64url"))),it.fromBigInt(Ft(P(r.d,"base64url"))),it.fromBigInt(Ft(P(r.p,"base64url"))),it.fromBigInt(Ft(P(r.q,"base64url"))),it.fromBigInt(Ft(P(r.dp,"base64url"))),it.fromBigInt(Ft(P(r.dq,"base64url"))),it.fromBigInt(Ft(P(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Vf(r){let{result:t}=ur(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:G(Mt(e[0].toBigInt()),"base64url"),e:G(Mt(e[1].toBigInt()),"base64url")}}function Of(r){if(r.n==null||r.e==null)throw new B("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new lt({value:[new lt({value:[new Ct({value:"1.2.840.113549.1.1.1"}),new Ee]}),new cr({valueHex:new lt({value:[it.fromBigInt(Ft(P(r.n,"base64url"))),it.fromBigInt(Ft(P(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Mt(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,i=0;for(;s<e;)n[s]=parseInt(t.slice(i,i+2),16),s+=1,i+=2;return n}function Ft(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}var Hf=16,mi=32,bi=1e4;async function Pf(r,t){let e=mt.get(),s=new lt({value:[new it({value:0}),new lt({value:[new Ct({value:"1.2.840.113549.1.1.1"}),new Ee]}),new ee({valueHex:r.marshal()})]}).toBER(),i=new Uint8Array(s,0,s.byteLength),o=Pt(Hf),a=await hi(Te,t,o,{c:bi,dkLen:mi}),c=Pt(16),f=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await e.subtle.encrypt({name:"AES-CBC",iv:c},f,i),u=new lt({value:[new ee({valueHex:o}),new it({value:bi}),new it({value:mi}),new lt({value:[new Ct({value:"1.2.840.113549.2.11"}),new Ee]})]}),d=new lt({value:[new Ct({value:"1.2.840.113549.1.5.13"}),new lt({value:[new lt({value:[new Ct({value:"1.2.840.113549.1.5.12"}),u]}),new lt({value:[new Ct({value:"2.16.840.1.101.3.4.1.42"}),new ee({valueHex:c})]})]})]}),p=new lt({value:[d,new ee({valueHex:l})]}).toBER(),h=new Uint8Array(p,0,p.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...G(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
-
`)}async function wi(r,t){let e=mt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=P(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=ur(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:l}=Kf(i),u=await hi(Te,t,a,{c,dkLen:f}),d=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),w=Or(await e.subtle.decrypt({name:"AES-CBC",iv:o},d,l)),{result:p}=ur(w);n=Fa(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=P(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=ur(s);n=Fa(i)}else throw new B("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return xi(n)}function Kf(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new B("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new B("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],o=Or(i.valueBlock.value[0].getValue()),a=bi,c=mi;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new B("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=t.valueBlock.value[1].valueBlock.value[1],l=f.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new B("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=Or(f.valueBlock.value[1].getValue());return{cipherText:Or(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:u}}function Fa(r){return Or(r.valueBlock.value[2].getValue())}function Or(r){return new Uint8Array(r,0,r.byteLength)}async function $a(r){let t=await mt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Ya(t);return{privateKey:e[0],publicKey:e[1]}}async function Ei(r){let e=[await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Mf(r)],n=await Ya({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function qa(r,t){let e=await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await mt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ja(r,t,e){let n=await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Ya(r){if(r.privateKey==null||r.publicKey==null)throw new B("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([mt.get().subtle.exportKey("jwk",r.privateKey),mt.get().subtle.exportKey("jwk",r.publicKey)])}async function Mf(r){return mt.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function cs(r){if(r.kty!=="RSA")throw new B("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new B("invalid key modulus","ERR_INVALID_KEY_MODULUS");return P(r.n,"base64url").length*8}var Pr=8192,Hr=class{_key;constructor(t){this._key=t}verify(t,e){return ja(this._key,e,t)}marshal(){return ve.jwkToPkix(this._key)}get bytes(){return Xt.encode({Type:rt.RSA,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}},fr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return Pt(16)}sign(t){return qa(this._key,t)}get public(){if(this._publicKey==null)throw new B("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Hr(this._publicKey)}marshal(){return ve.jwkToPkcs1(this._key)}get bytes(){return Ht.encode({Type:rt.RSA,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return G(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return ve.exportToPem(this,t);if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function xi(r){let t=ve.pkcs1ToJwk(r);if(cs(t)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ei(t);return new fr(e.privateKey,e.publicKey)}function $f(r){let t=ve.pkixToJwk(r);if(cs(t)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Hr(t)}async function qf(r){if(cs(r)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ei(r);return new fr(t.privateKey,t.publicKey)}async function jf(r){if(r>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await $a(r);return new fr(t.privateKey,t.publicKey)}var Ii={};ct(Ii,{Secp256k1PrivateKey:()=>Mr,Secp256k1PublicKey:()=>Kr,generateKeyPair:()=>sh,unmarshalSecp256k1PrivateKey:()=>rh,unmarshalSecp256k1PublicKey:()=>nh});var Yf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ae=new Uint32Array(64),Bi=class extends fe{constructor(){super(64,32,8,!1),this.A=Be[0]|0,this.B=Be[1]|0,this.C=Be[2]|0,this.D=Be[3]|0,this.E=Be[4]|0,this.F=Be[5]|0,this.G=Be[6]|0,this.H=Be[7]|0}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)Ae[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let d=Ae[u-15],w=Ae[u-2],p=_t(d,7)^_t(d,18)^d>>>3,h=_t(w,17)^_t(w,19)^w>>>10;Ae[u]=h+Ae[u-7]+p+Ae[u-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let d=_t(a,6)^_t(a,11)^_t(a,25),w=l+d+tn(a,c,f)+Yf[u]+Ae[u]|0,h=(_t(n,2)^_t(n,13)^_t(n,22))+en(n,s,i)|0;l=f,f=c,c=a,a=o+w|0,o=i,i=s,s=n,n=w+h|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,f,l)}roundClean(){Ae.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ls=Qe(()=>new Bi);function Gf(r){let t=Br(r);Ot(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:zf,hexToBytes:Wf}=sn,Pe={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Pe;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:zf(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Pe,e=typeof r=="string"?Wf(r):r;er(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:i}=Pe._parseInt(e.subarray(2)),{d:o,l:a}=Pe._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(r){let t=f=>Number.parseInt(f[0],16)&8?"00"+f:f,e=f=>{let l=f.toString(16);return l.length&1?`0${l}`:l},n=t(e(r.s)),s=t(e(r.r)),i=n.length/2,o=s.length/2,a=e(i),c=e(o);return`30${e(o+i+4)}02${c}${s}02${a}${n}`}},ie=BigInt(0),Rt=BigInt(1),mg=BigInt(2),Ga=BigInt(3),bg=BigInt(4);function Zf(r){let t=Gf(r),{Fp:e}=t,n=t.toBytes||((p,h,g)=>{let m=h.toAffine();return Zt(Uint8Array.from([4]),e.toBytes(m.x),e.toBytes(m.y))}),s=t.fromBytes||(p=>{let h=p.subarray(1),g=e.fromBytes(h.subarray(0,e.BYTES)),m=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:g,y:m}});function i(p){let{a:h,b:g}=t,m=e.sqr(p),A=e.mul(m,p);return e.add(e.add(A,e.mul(p,h)),g)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function o(p){return typeof p=="bigint"&&ie<p&&p<t.n}function a(p){if(!o(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:m,n:A}=t;if(h&&typeof p!="bigint"){if(pe(p)&&(p=zt(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let b;try{b=typeof p=="bigint"?p:Wt(tt("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return m&&(b=z(b,A)),a(b),b}let f=new Map;function l(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,g,m){if(this.px=h,this.py=g,this.pz=m,h==null||!e.isValid(h))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(m==null||!e.isValid(m))throw new Error("z required")}static fromAffine(h){let{x:g,y:m}=h||{};if(!h||!e.isValid(g)||!e.isValid(m))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");let A=b=>e.eql(b,e.ZERO);return A(g)&&A(m)?u.ZERO:new u(g,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=e.invertBatch(h.map(m=>m.pz));return h.map((m,A)=>m.toAffine(g[A])).map(u.fromAffine)}static fromHex(h){let g=u.fromAffine(s(tt("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return u.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,f.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=this.toAffine();if(!e.isValid(h)||!e.isValid(g))throw new Error("bad point: x or y not FE");let m=e.sqr(g),A=i(h);if(!e.eql(m,A))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:g,py:m,pz:A}=this,{px:b,py:T,pz:x}=h,S=e.eql(e.mul(g,x),e.mul(b,A)),_=e.eql(e.mul(m,x),e.mul(T,A));return S&&_}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,m=e.mul(g,Ga),{px:A,py:b,pz:T}=this,x=e.ZERO,S=e.ZERO,_=e.ZERO,N=e.mul(A,A),Y=e.mul(b,b),$=e.mul(T,T),D=e.mul(A,b);return D=e.add(D,D),_=e.mul(A,T),_=e.add(_,_),x=e.mul(h,_),S=e.mul(m,$),S=e.add(x,S),x=e.sub(Y,S),S=e.add(Y,S),S=e.mul(x,S),x=e.mul(D,x),_=e.mul(m,_),$=e.mul(h,$),D=e.sub(N,$),D=e.mul(h,D),D=e.add(D,_),_=e.add(N,N),N=e.add(_,N),N=e.add(N,$),N=e.mul(N,D),S=e.add(S,N),$=e.mul(b,T),$=e.add($,$),N=e.mul($,D),x=e.sub(x,N),_=e.mul($,Y),_=e.add(_,_),_=e.add(_,_),new u(x,S,_)}add(h){l(h);let{px:g,py:m,pz:A}=this,{px:b,py:T,pz:x}=h,S=e.ZERO,_=e.ZERO,N=e.ZERO,Y=t.a,$=e.mul(t.b,Ga),D=e.mul(g,b),nt=e.mul(m,T),et=e.mul(A,x),At=e.add(g,m),E=e.add(b,T);At=e.mul(At,E),E=e.add(D,nt),At=e.sub(At,E),E=e.add(g,A);let R=e.add(b,x);return E=e.mul(E,R),R=e.add(D,et),E=e.sub(E,R),R=e.add(m,A),S=e.add(T,x),R=e.mul(R,S),S=e.add(nt,et),R=e.sub(R,S),N=e.mul(Y,E),S=e.mul($,et),N=e.add(S,N),S=e.sub(nt,N),N=e.add(nt,N),_=e.mul(S,N),nt=e.add(D,D),nt=e.add(nt,D),et=e.mul(Y,et),E=e.mul($,E),nt=e.add(nt,et),et=e.sub(D,et),et=e.mul(Y,et),E=e.add(E,et),D=e.mul(nt,E),_=e.add(_,D),D=e.mul(R,E),S=e.mul(At,S),S=e.sub(S,D),D=e.mul(At,nt),N=e.mul(R,N),N=e.add(N,D),new u(S,_,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return w.wNAFCached(this,f,h,g=>{let m=e.invertBatch(g.map(A=>A.pz));return g.map((A,b)=>A.toAffine(m[b])).map(u.fromAffine)})}multiplyUnsafe(h){let g=u.ZERO;if(h===ie)return g;if(a(h),h===Rt)return this;let{endo:m}=t;if(!m)return w.unsafeLadder(this,h);let{k1neg:A,k1:b,k2neg:T,k2:x}=m.splitScalar(h),S=g,_=g,N=this;for(;b>ie||x>ie;)b&Rt&&(S=S.add(N)),x&Rt&&(_=_.add(N)),N=N.double(),b>>=Rt,x>>=Rt;return A&&(S=S.negate()),T&&(_=_.negate()),_=new u(e.mul(_.px,m.beta),_.py,_.pz),S.add(_)}multiply(h){a(h);let g=h,m,A,{endo:b}=t;if(b){let{k1neg:T,k1:x,k2neg:S,k2:_}=b.splitScalar(g),{p:N,f:Y}=this.wNAF(x),{p:$,f:D}=this.wNAF(_);N=w.constTimeNegate(T,N),$=w.constTimeNegate(S,$),$=new u(e.mul($.px,b.beta),$.py,$.pz),m=N.add($),A=Y.add(D)}else{let{p:T,f:x}=this.wNAF(g);m=T,A=x}return u.normalizeZ([m,A])[0]}multiplyAndAddUnsafe(h,g,m){let A=u.BASE,b=(x,S)=>S===ie||S===Rt||!x.equals(A)?x.multiplyUnsafe(S):x.multiply(S),T=b(this,g).add(b(h,m));return T.is0()?void 0:T}toAffine(h){let{px:g,py:m,pz:A}=this,b=this.is0();h==null&&(h=b?e.ONE:e.inv(A));let T=e.mul(g,h),x=e.mul(m,h),S=e.mul(A,h);if(b)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:T,y:x}}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===Rt)return!0;if(g)return g(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===Rt?this:g?g(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(u,this,h)}toHex(h=!0){return zt(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let d=t.nBitLength,w=cn(u,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function Jf(r){let t=Br(r);return Ot(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function za(r){let t=Jf(r),{Fp:e,n}=t,s=e.BYTES+1,i=2*e.BYTES+1;function o(E){return ie<E&&E<e.ORDER}function a(E){return z(E,n)}function c(E){return on(E,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:d}=Zf({...t,toBytes(E,R,V){let v=R.toAffine(),y=e.toBytes(v.x),I=Zt;return V?I(Uint8Array.from([R.hasEvenY()?2:3]),y):I(Uint8Array.from([4]),y,e.toBytes(v.y))},fromBytes(E){let R=E.length,V=E[0],v=E.subarray(1);if(R===s&&(V===2||V===3)){let y=Wt(v);if(!o(y))throw new Error("Point is not on curve");let I=u(y),C;try{C=e.sqrt(I)}catch(H){let j=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+j)}let L=(C&Rt)===Rt;return(V&1)===1!==L&&(C=e.neg(C)),{x:y,y:C}}else if(R===i&&V===4){let y=e.fromBytes(v.subarray(0,e.BYTES)),I=e.fromBytes(v.subarray(e.BYTES,2*e.BYTES));return{x:y,y:I}}else throw new Error(`Point of length ${R} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),w=E=>zt(ye(E,t.nByteLength));function p(E){let R=n>>Rt;return E>R}function h(E){return p(E)?a(-E):E}let g=(E,R,V)=>Wt(E.slice(R,V));class m{constructor(R,V,v){this.r=R,this.s=V,this.recovery=v,this.assertValidity()}static fromCompact(R){let V=t.nByteLength;return R=tt("compactSignature",R,V*2),new m(g(R,0,V),g(R,V,2*V))}static fromDER(R){let{r:V,s:v}=Pe.toSig(tt("DER",R));return new m(V,v)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(R){return new m(this.r,this.s,R)}recoverPublicKey(R){let{r:V,s:v,recovery:y}=this,I=_(tt("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let C=y===2||y===3?V+t.n:V;if(C>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=y&1?"03":"02",O=f.fromHex(L+w(C)),H=c(C),j=a(-I*H),M=a(v*H),q=f.BASE.multiplyAndAddUnsafe(O,j,M);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ce(this.toDERHex())}toDERHex(){return Pe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ce(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}let A={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=zs(t.n);return ko(t.randomBytes(E),t.n)},precompute(E=8,R=f.BASE){return R._setWindowSize(E),R.multiply(BigInt(3)),R}};function b(E,R=!0){return f.fromPrivateKey(E).toRawBytes(R)}function T(E){let R=pe(E),V=typeof E=="string",v=(R||V)&&E.length;return R?v===s||v===i:V?v===2*s||v===2*i:E instanceof f}function x(E,R,V=!0){if(T(E))throw new Error("first arg must be private key");if(!T(R))throw new Error("second arg must be public key");return f.fromHex(R).multiply(l(E)).toRawBytes(V)}let S=t.bits2int||function(E){let R=Wt(E),V=E.length*8-t.nBitLength;return V>0?R>>BigInt(V):R},_=t.bits2int_modN||function(E){return a(S(E))},N=vr(t.nBitLength);function Y(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(ie<=E&&E<N))throw new Error(`bigint expected < 2^${t.nBitLength}`);return ye(E,t.nByteLength)}function $(E,R,V=D){if(["recovered","canonical"].some(X=>X in V))throw new Error("sign() legacy options not supported");let{hash:v,randomBytes:y}=t,{lowS:I,prehash:C,extraEntropy:L}=V;I==null&&(I=!0),E=tt("msgHash",E),C&&(E=tt("prehashed msgHash",v(E)));let O=_(E),H=l(R),j=[Y(H),Y(O)];if(L!=null&&L!==!1){let X=L===!0?y(e.BYTES):L;j.push(tt("extraEntropy",X))}let M=Zt(...j),q=O;function st(X){let ut=S(X);if(!d(ut))return;let ft=c(ut),ot=f.BASE.multiply(ut).toAffine(),pt=a(ot.x);if(pt===ie)return;let qt=a(ft*a(q+pt*H));if(qt===ie)return;let Ie=(ot.x===pt?0:2)|Number(ot.y&Rt),mr=qt;return I&&p(qt)&&(mr=h(qt),Ie^=1),new m(pt,mr,Ie)}return{seed:M,k2sig:st}}let D={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function et(E,R,V=D){let{seed:v,k2sig:y}=$(E,R,V),I=t;return qs(I.hash.outputLen,I.nByteLength,I.hmac)(v,y)}f.BASE._setWindowSize(8);function At(E,R,V,v=nt){let y=E;if(R=tt("msgHash",R),V=tt("publicKey",V),"strict"in v)throw new Error("options.strict was renamed to lowS");let{lowS:I,prehash:C}=v,L,O;try{if(typeof y=="string"||pe(y))try{L=m.fromDER(y)}catch(ot){if(!(ot instanceof Pe.Err))throw ot;L=m.fromCompact(y)}else if(typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint"){let{r:ot,s:pt}=y;L=new m(ot,pt)}else throw new Error("PARSE");O=f.fromHex(V)}catch(ot){if(ot.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(I&&L.hasHighS())return!1;C&&(R=t.hash(R));let{r:H,s:j}=L,M=_(R),q=c(j),st=a(M*q),X=a(H*q),ut=f.BASE.multiplyAndAddUnsafe(O,st,X)?.toAffine();return ut?a(ut.x)===H:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:x,sign:et,verify:At,ProjectivePoint:f,Signature:m,utils:A}}function Xf(r){return{hash:r,hmac:(t,...e)=>Rr(r,t,Ps(...e)),randomBytes:tr}}function Wa(r,t){let e=n=>za({...r,...Xf(n)});return Object.freeze({...e(t),create:e})}var Xa=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Za=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Qf=BigInt(1),Ai=BigInt(2),Ja=(r,t)=>(r+t/Ai)/t;function th(r){let t=Xa,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=J(l,e,t)*l%t,d=J(u,e,t)*l%t,w=J(d,Ai,t)*f%t,p=J(w,s,t)*w%t,h=J(p,i,t)*p%t,g=J(h,a,t)*h%t,m=J(g,c,t)*g%t,A=J(m,a,t)*h%t,b=J(A,e,t)*l%t,T=J(b,o,t)*p%t,x=J(T,n,t)*f%t,S=J(x,Ai,t);if(!Si.eql(Si.sqr(S),r))throw new Error("Cannot find square root");return S}var Si=an(Xa,void 0,void 0,{sqrt:th}),Ut=Wa({a:BigInt(0),b:BigInt(7),Fp:Si,n:Za,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Za,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Qf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,o=BigInt("0x100000000000000000000000000000000"),a=Ja(i*r,t),c=Ja(-n*r,t),f=z(r-a*e-c*s,t),l=z(-a*n-c*i,t),u=f>o,d=l>o;if(u&&(f=t-f),d&&(l=t-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:f,k2neg:d,k2:l}}}},ls),Ig=BigInt(0);var Rg=Ut.ProjectivePoint;function Qa(){return Ut.utils.randomPrivateKey()}function tc(r,t){let e=ht.digest(t instanceof Uint8Array?t:t.subarray());if(kt(e))return e.then(({digest:n})=>Ut.sign(n,r).toDERRawBytes()).catch(n=>{throw new B(String(n),"ERR_INVALID_INPUT")});try{return Ut.sign(e.digest,r).toDERRawBytes()}catch(n){throw new B(String(n),"ERR_INVALID_INPUT")}}function ec(r,t,e){let n=ht.digest(e instanceof Uint8Array?e:e.subarray());if(kt(n))return n.then(({digest:s})=>Ut.verify(t,s,r)).catch(s=>{throw new B(String(s),"ERR_INVALID_INPUT")});try{return Ut.verify(t,n.digest,r)}catch(s){throw new B(String(s),"ERR_INVALID_INPUT")}}function rc(r){return Ut.ProjectivePoint.fromHex(r).toRawBytes(!0)}function nc(r){try{Ut.getPublicKey(r,!0)}catch(t){throw new B(String(t),"ERR_INVALID_PRIVATE_KEY")}}function ki(r){try{Ut.ProjectivePoint.fromHex(r)}catch(t){throw new B(String(t),"ERR_INVALID_PUBLIC_KEY")}}function sc(r){try{return Ut.getPublicKey(r,!0)}catch(t){throw new B(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Kr=class{_key;constructor(t){ki(t),this._key=t}verify(t,e){return ec(this._key,e,t)}marshal(){return rc(this._key)}get bytes(){return Xt.encode({Type:rt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}async hash(){let t=ht.digest(this.bytes),e;return kt(t)?{bytes:e}=await t:e=t.bytes,e}},Mr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??sc(t),nc(this._key),ki(this._publicKey)}sign(t){return tc(this._key,t)}get public(){return new Kr(this._publicKey)}marshal(){return this._key}get bytes(){return Ht.encode({Type:rt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return G(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function rh(r){return new Mr(r)}function nh(r){return new Kr(r)}async function sh(){let r=Qa();return new Mr(r)}var Fr={rsa:vi,ed25519:fi,secp256k1:Ii};function ic(r){let t=Object.keys(Fr).join(" / ");return new B(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function ih(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Fr[r];throw ic(r)}async function oc(r,t){return ih(r).generateKeyPair(t??2048)}async function Ri(r){let t=Ht.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case rt.RSA:return Fr.rsa.unmarshalRsaPrivateKey(e);case rt.Ed25519:return Fr.ed25519.unmarshalEd25519PrivateKey(e);case rt.Secp256k1:return Fr.secp256k1.unmarshalSecp256k1PrivateKey(e);default:throw ic(t.Type??"RSA")}}async function $r(r,t){try{let e=await Jo(r,t);return await Ri(e)}catch{}if(!r.includes("BEGIN"))throw new B("Encrypted key was not a libp2p-key or a PEM file","ERR_INVALID_IMPORT_FORMAT");return wi(r,t)}var qr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Se=new Uint32Array(80),_i=class extends fe{constructor(){super(64,20,8,!1),this.A=qr[0]|0,this.B=qr[1]|0,this.C=qr[2]|0,this.D=qr[3]|0,this.E=qr[4]|0}get(){let{A:t,B:e,C:n,D:s,E:i}=this;return[t,e,n,s,i]}set(t,e,n,s,i){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0}process(t,e){for(let c=0;c<16;c++,e+=4)Se[c]=t.getUint32(e,!1);for(let c=16;c<80;c++)Se[c]=Qr(Se[c-3]^Se[c-8]^Se[c-14]^Se[c-16],1);let{A:n,B:s,C:i,D:o,E:a}=this;for(let c=0;c<80;c++){let f,l;c<20?(f=tn(s,i,o),l=1518500249):c<40?(f=s^i^o,l=1859775393):c<60?(f=en(s,i,o),l=2400959708):(f=s^i^o,l=3395469782);let u=Qr(n,5)+f+a+l+Se[c]|0;a=o,o=i,i=Qr(s,30),s=n,n=u}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,s,i,o,a)}roundClean(){Se.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},ac=Qe(()=>new _i);var cc={sha1:ac,"sha2-256":ls,"sha2-512":Te};function jr(r,t,e,n,s){if(s!=="sha1"&&s!=="sha2-256"&&s!=="sha2-512"){let a=Object.keys(cc).join(" / ");throw new B(`Hash '${s}' is unknown or not supported. Must be ${a}`,"ERR_UNSUPPORTED_HASH_TYPE")}let i=cc[s],o=ta(i,r,t,{c:e,dkLen:n});return _e.encode(o).substring(1)}var uc=Symbol.for("nodejs.util.inspect.custom"),lc=Object.values(ze).map(r=>r.decoder).reduce((r,t)=>r.or(t),ze.identity.decoder),fc=114,Ci=36,Li=37,Yr=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ys]=!0;toString(){return this.string==null&&(this.string=bt.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return le.createV1(fc,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return St(this.multihash.bytes,t);if(typeof t=="string")return oh(t).equals(this);if(t?.multihash?.bytes!=null)return St(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[uc](){return`PeerId(${this.toString()})`}},hr=class extends Yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},dr=class extends Yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},pr=class extends Yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Ni=2336,Ti=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Yt.digest(P(this.url))}[uc](){return`PeerId(${this.url})`}[ys]=!0;toString(){return this.toCID().toString()}toCID(){return le.createV1(Ni,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function oh(r,t){if(t=t??lc,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=xr(bt.decode(`z${r}`));return r.startsWith("12D")?new dr({multihash:e}):r.startsWith("16U")?new pr({multihash:e}):new hr({multihash:e})}return ah(lc.decode(r))}function ah(r){try{let t=xr(r);if(t.code===Yt.code){if(t.digest.length===Ci)return new dr({multihash:t});if(t.digest.length===Li)return new pr({multihash:t})}if(t.code===ht.code)return new hr({multihash:t})}catch{return ch(le.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function ch(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==fc&&r.code!==Ni)throw new Error("Supplied PeerID CID is invalid");if(r.code===Ni){let e=G(r.multihash.digest);return new Ti(new URL(e))}let t=r.multihash;if(t.code===ht.code)return new hr({multihash:r.multihash});if(t.code===Yt.code){if(t.digest.length===Ci)return new dr({multihash:r.multihash});if(t.digest.length===Li)return new pr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function hc(r,t){return r.length===Ci?new dr({multihash:Dt(Yt.code,r),privateKey:t}):r.length===Li?new pr({multihash:Dt(Yt.code,r),privateKey:t}):new hr({multihash:await ht.digest(r),publicKey:r,privateKey:t})}var oe="/",dc=new TextEncoder().encode(oe),us=dc[0],Gr=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=P(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==us)throw new Error("Invalid key")}toString(t="utf8"){return G(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(oe))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=dc),this._buf[0]!==us){let t=new Uint8Array(this._buf.byteLength+1);t.fill(us,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===us;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let s=0;s<e.length;s++){if(n.length<s+1)return!1;let i=e[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(oe).slice(1)}type(){return lh(this.baseNamespace())}name(){return uh(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(oe)||(t+=oe),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(oe):new r(t.slice(0,-1).join(oe))}child(t){return this.toString()===oe?t:t.toString()===oe?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...fh(t.map(e=>e.namespaces()))])}};function lh(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function uh(r){let t=r.split(":");return t[t.length-1]}function fh(r){return[].concat(...r)}var vc=gs(Ec(),1),Bc=vc.default;var Lc=gs(Cc(),1);var F;(function(r){r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_INVALID_KEY_NAME="ERR_INVALID_KEY_NAME",r.ERR_INVALID_KEY_TYPE="ERR_INVALID_KEY_TYPE",r.ERR_KEY_ALREADY_EXISTS="ERR_KEY_ALREADY_EXISTS",r.ERR_INVALID_KEY_SIZE="ERR_INVALID_KEY_SIZE",r.ERR_KEY_NOT_FOUND="ERR_KEY_NOT_FOUND",r.ERR_OLD_KEY_NAME_INVALID="ERR_OLD_KEY_NAME_INVALID",r.ERR_NEW_KEY_NAME_INVALID="ERR_NEW_KEY_NAME_INVALID",r.ERR_PASSWORD_REQUIRED="ERR_PASSWORD_REQUIRED",r.ERR_PEM_REQUIRED="ERR_PEM_REQUIRED",r.ERR_CANNOT_READ_KEY="ERR_CANNOT_READ_KEY",r.ERR_MISSING_PRIVATE_KEY="ERR_MISSING_PRIVATE_KEY",r.ERR_INVALID_OLD_PASS_TYPE="ERR_INVALID_OLD_PASS_TYPE",r.ERR_INVALID_NEW_PASS_TYPE="ERR_INVALID_NEW_PASS_TYPE",r.ERR_INVALID_PASS_LENGTH="ERR_INVALID_PASS_LENGTH"})(F||(F={}));var _h="/pkcs8/",Uc="/info/",Ke=new WeakMap,Me={minKeyLength:112/8,minSaltLength:128/8,minIterationCount:1e3},Di={dek:{keyLength:512/8,iterationCount:1e4,salt:"you should override this value with a crypto secure random number",hash:"sha2-512"}};function ae(r){return r==null||typeof r!="string"?!1:r===(0,Lc.default)(r.trim())&&r.length>0}async function W(){let e=Math.random()*800+200;await new Promise(n=>setTimeout(n,e))}function $t(r){return new Gr(_h+r)}function ke(r){return new Gr(Uc+r)}var ds=class{components;init;log;constructor(t,e){if(this.components=t,this.log=t.logger.forComponent("libp2p:keychain"),this.init=Bc(Di,e),this.init.pass!=null&&this.init.pass?.length<20)throw new Error("pass must be least 20 characters");if(this.init.dek?.keyLength!=null&&this.init.dek.keyLength<Me.minKeyLength)throw new Error(`dek.keyLength must be least ${Me.minKeyLength} bytes`);if(this.init.dek?.salt?.length!=null&&this.init.dek.salt.length<Me.minSaltLength)throw new Error(`dek.saltLength must be least ${Me.minSaltLength} bytes`);if(this.init.dek?.iterationCount!=null&&this.init.dek.iterationCount<Me.minIterationCount)throw new Error(`dek.iterationCount must be least ${Me.minIterationCount}`);let n=this.init.pass!=null&&this.init.dek?.salt!=null?jr(this.init.pass,this.init.dek?.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";Ke.set(this,{dek:n})}[Symbol.toStringTag]="@libp2p/keychain";[ji]=["@libp2p/keychain"];static generateOptions(){let t=Object.assign({},Di),e=Math.ceil(Me.minSaltLength/3)*3;return t.dek.salt=G(Pt(e),"base64"),t}static get options(){return Di}async createKey(t,e,n=2048){if(!ae(t)||t==="self")throw await W(),new B("Invalid key name",F.ERR_INVALID_KEY_NAME);if(typeof e!="string")throw await W(),new B("Invalid key type",F.ERR_INVALID_KEY_TYPE);let s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B("Key name already exists",F.ERR_KEY_ALREADY_EXISTS);switch(e.toLowerCase()){case"rsa":if(!Number.isSafeInteger(n)||n<2048)throw await W(),new B("Invalid RSA key size",F.ERR_INVALID_KEY_SIZE);break;default:break}let o;try{let a=await oc(e,n),c=await a.id(),f=Ke.get(this);if(f==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let l=f.dek,u=await a.export(l);o={name:t,id:c};let d=this.components.datastore.batch();d.put(s,P(u)),d.put(ke(t),P(JSON.stringify(o))),await d.commit()}catch(a){throw await W(),a}return o}async listKeys(){let t={prefix:Uc},e=[];for await(let n of this.components.datastore.query(t))e.push(JSON.parse(G(n.value)));return e}async findKeyById(t){try{let n=(await this.listKeys()).find(s=>s.id===t);if(n==null)throw new B(`Key with id '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND);return n}catch(e){throw await W(),e}}async findKeyByName(t){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);let e=ke(t);try{let n=await this.components.datastore.get(e);return JSON.parse(G(n))}catch(n){throw await W(),this.log.error(n),new B(`Key '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND)}}async removeKey(t){if(!ae(t)||t==="self")throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);let e=$t(t),n=await this.findKeyByName(t),s=this.components.datastore.batch();return s.delete(e),s.delete(ke(t)),await s.commit(),n}async renameKey(t,e){if(!ae(t)||t==="self")throw await W(),new B(`Invalid old key name '${t}'`,F.ERR_OLD_KEY_NAME_INVALID);if(!ae(e)||e==="self")throw await W(),new B(`Invalid new key name '${e}'`,F.ERR_NEW_KEY_NAME_INVALID);let n=$t(t),s=$t(e),i=ke(t),o=ke(e);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${e}' already exists`,F.ERR_KEY_ALREADY_EXISTS);try{let c=await this.components.datastore.get(n),f=await this.components.datastore.get(i),l=JSON.parse(G(f));l.name=e;let u=this.components.datastore.batch();return u.put(s,c),u.put(o,P(JSON.stringify(l))),u.delete(n),u.delete(i),await u.commit(),l}catch(c){throw await W(),c}}async exportKey(t,e){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw await W(),new B("Password is required",F.ERR_PASSWORD_REQUIRED);let n=$t(t);try{let s=await this.components.datastore.get(n),i=G(s),o=Ke.get(this);if(o==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let a=o.dek;return await(await $r(i,a)).export(e)}catch(s){throw await W(),s}}async exportPeerId(t){let e="temporary-password",n=await this.exportKey(t,e),s=await $r(n,e);return hc(s.public.bytes,s.bytes)}async importKey(t,e,n){if(!ae(t)||t==="self")throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw await W(),new B("PEM encoded key is required",F.ERR_PEM_REQUIRED);let s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${t}' already exists`,F.ERR_KEY_ALREADY_EXISTS);let o;try{o=await $r(e,n)}catch{throw await W(),new B("Cannot read the key, most likely the password is wrong",F.ERR_CANNOT_READ_KEY)}let a;try{a=await o.id();let l=Ke.get(this);if(l==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let u=l.dek;e=await o.export(u)}catch(l){throw await W(),l}let c={name:t,id:a},f=this.components.datastore.batch();return f.put(s,P(e)),f.put(ke(t),P(JSON.stringify(c))),await f.commit(),c}async importPeer(t,e){try{if(!ae(t))throw new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw new B("PeerId is required",F.ERR_MISSING_PRIVATE_KEY);if(e.privateKey==null)throw new B("PeerId.privKey is required",F.ERR_MISSING_PRIVATE_KEY);let n=await Ri(e.privateKey),s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${t}' already exists`,F.ERR_KEY_ALREADY_EXISTS);let o=Ke.get(this);if(o==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let a=o.dek,c=await n.export(a),f={name:t,id:e.toString()},l=this.components.datastore.batch();return l.put(s,P(c)),l.put(ke(t),P(JSON.stringify(f))),await l.commit(),f}catch(n){throw await W(),n}}async getPrivateKey(t){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);try{let e=$t(t),n=await this.components.datastore.get(e);return G(n)}catch(e){throw await W(),this.log.error(e),new B(`Key '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND)}}async rotateKeychainPass(t,e){if(typeof t!="string")throw await W(),new B(`Invalid old pass type '${typeof t}'`,F.ERR_INVALID_OLD_PASS_TYPE);if(typeof e!="string")throw await W(),new B(`Invalid new pass type '${typeof e}'`,F.ERR_INVALID_NEW_PASS_TYPE);if(e.length<20)throw await W(),new B(`Invalid pass length ${e.length}`,F.ERR_INVALID_PASS_LENGTH);this.log("recreating keychain");let n=Ke.get(this);if(n==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let s=n.dek;this.init.pass=e;let i=e!=null&&this.init.dek?.salt!=null?jr(e,this.init.dek.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";Ke.set(this,{dek:i});let o=await this.listKeys();for(let a of o){let c=await this.components.datastore.get($t(a.name)),f=G(c),l=await $r(f,s),u=i.toString(),d=await l.export(u),w=this.components.datastore.batch(),p={name:a.name,id:a.id};w.put($t(a.name),P(d)),w.put(ke(a.name),P(JSON.stringify(p))),await w.commit()}this.log("keychain reconstructed")}};function Nh(r={}){return t=>new ds(t,r)}return zc(Th);})();
|
|
7
|
+
`)}async function wi(r,t){let e=mt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=P(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=ur(s),{iv:o,salt:a,iterations:c,keySize:f,cipherText:l}=Kf(i),u=await hi(Te,t,a,{c,dkLen:f}),d=await e.subtle.importKey("raw",u,"AES-CBC",!1,["decrypt"]),w=Or(await e.subtle.decrypt({name:"AES-CBC",iv:o},d,l)),{result:p}=ur(w);n=Fa(p)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=P(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=ur(s);n=Fa(i)}else throw new B("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return xi(n)}function Kf(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new B("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new B("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let i=n.valueBlock.value[1],o=Or(i.valueBlock.value[0].getValue()),a=bi,c=mi;if(i.valueBlock.value.length===3)a=Number(i.valueBlock.value[1].toBigInt()),c=Number(i.valueBlock.value[2].toBigInt());else if(i.valueBlock.value.length===2)throw new B("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let f=t.valueBlock.value[1].valueBlock.value[1],l=f.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new B("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let u=Or(f.valueBlock.value[1].getValue());return{cipherText:Or(r.valueBlock.value[1].getValue()),salt:o,iterations:a,keySize:c,iv:u}}function Fa(r){return Or(r.valueBlock.value[2].getValue())}function Or(r){return new Uint8Array(r,0,r.byteLength)}async function $a(r){let t=await mt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Ya(t);return{privateKey:e[0],publicKey:e[1]}}async function Ei(r){let e=[await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Mf(r)],n=await Ya({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function qa(r,t){let e=await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await mt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ja(r,t,e){let n=await mt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return mt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Ya(r){if(r.privateKey==null||r.publicKey==null)throw new B("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([mt.get().subtle.exportKey("jwk",r.privateKey),mt.get().subtle.exportKey("jwk",r.publicKey)])}async function Mf(r){return mt.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function cs(r){if(r.kty!=="RSA")throw new B("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new B("invalid key modulus","ERR_INVALID_KEY_MODULUS");return P(r.n,"base64url").length*8}var Pr=8192,Hr=class{_key;constructor(t){this._key=t}verify(t,e){return ja(this._key,e,t)}marshal(){return ve.jwkToPkix(this._key)}get bytes(){return Xt.encode({Type:rt.RSA,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}},fr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return Pt(16)}sign(t){return qa(this._key,t)}get public(){if(this._publicKey==null)throw new B("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Hr(this._publicKey)}marshal(){return ve.jwkToPkcs1(this._key)}get bytes(){return Ht.encode({Type:rt.RSA,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return G(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return ve.exportToPem(this,t);if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function xi(r){let t=ve.pkcs1ToJwk(r);if(cs(t)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ei(t);return new fr(e.privateKey,e.publicKey)}function $f(r){let t=ve.pkixToJwk(r);if(cs(t)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Hr(t)}async function qf(r){if(cs(r)>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ei(r);return new fr(t.privateKey,t.publicKey)}async function jf(r){if(r>Pr)throw new B("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await $a(r);return new fr(t.privateKey,t.publicKey)}var Ii={};ct(Ii,{Secp256k1PrivateKey:()=>Mr,Secp256k1PublicKey:()=>Kr,generateKeyPair:()=>sh,unmarshalSecp256k1PrivateKey:()=>rh,unmarshalSecp256k1PublicKey:()=>nh});var Yf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ae=new Uint32Array(64),Bi=class extends fe{constructor(){super(64,32,8,!1),this.A=Be[0]|0,this.B=Be[1]|0,this.C=Be[2]|0,this.D=Be[3]|0,this.E=Be[4]|0,this.F=Be[5]|0,this.G=Be[6]|0,this.H=Be[7]|0}get(){let{A:t,B:e,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,e,n,s,i,o,a,c]}set(t,e,n,s,i,o,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)Ae[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let d=Ae[u-15],w=Ae[u-2],p=_t(d,7)^_t(d,18)^d>>>3,h=_t(w,17)^_t(w,19)^w>>>10;Ae[u]=h+Ae[u-7]+p+Ae[u-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let d=_t(a,6)^_t(a,11)^_t(a,25),w=l+d+tn(a,c,f)+Yf[u]+Ae[u]|0,h=(_t(n,2)^_t(n,13)^_t(n,22))+en(n,s,i)|0;l=f,f=c,c=a,a=o+w|0,o=i,i=s,s=n,n=w+h|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,i,o,a,c,f,l)}roundClean(){Ae.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ls=Qe(()=>new Bi);function Gf(r){let t=Br(r);Ot(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:zf,hexToBytes:Wf}=sn,Pe={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=Pe;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:zf(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=Pe,e=typeof r=="string"?Wf(r):r;er(e);let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:i}=Pe._parseInt(e.subarray(2)),{d:o,l:a}=Pe._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:o}},hexFromSig(r){let t=f=>Number.parseInt(f[0],16)&8?"00"+f:f,e=f=>{let l=f.toString(16);return l.length&1?`0${l}`:l},n=t(e(r.s)),s=t(e(r.r)),i=n.length/2,o=s.length/2,a=e(i),c=e(o);return`30${e(o+i+4)}02${c}${s}02${a}${n}`}},ie=BigInt(0),Rt=BigInt(1),mg=BigInt(2),Ga=BigInt(3),bg=BigInt(4);function Zf(r){let t=Gf(r),{Fp:e}=t,n=t.toBytes||((p,h,g)=>{let m=h.toAffine();return Zt(Uint8Array.from([4]),e.toBytes(m.x),e.toBytes(m.y))}),s=t.fromBytes||(p=>{let h=p.subarray(1),g=e.fromBytes(h.subarray(0,e.BYTES)),m=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:g,y:m}});function i(p){let{a:h,b:g}=t,m=e.sqr(p),A=e.mul(m,p);return e.add(e.add(A,e.mul(p,h)),g)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function o(p){return typeof p=="bigint"&&ie<p&&p<t.n}function a(p){if(!o(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(p){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:m,n:A}=t;if(h&&typeof p!="bigint"){if(pe(p)&&(p=zt(p)),typeof p!="string"||!h.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let b;try{b=typeof p=="bigint"?p:Wt(tt("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return m&&(b=z(b,A)),a(b),b}let f=new Map;function l(p){if(!(p instanceof u))throw new Error("ProjectivePoint expected")}class u{constructor(h,g,m){if(this.px=h,this.py=g,this.pz=m,h==null||!e.isValid(h))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(m==null||!e.isValid(m))throw new Error("z required")}static fromAffine(h){let{x:g,y:m}=h||{};if(!h||!e.isValid(g)||!e.isValid(m))throw new Error("invalid affine point");if(h instanceof u)throw new Error("projective point not allowed");let A=b=>e.eql(b,e.ZERO);return A(g)&&A(m)?u.ZERO:new u(g,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=e.invertBatch(h.map(m=>m.pz));return h.map((m,A)=>m.toAffine(g[A])).map(u.fromAffine)}static fromHex(h){let g=u.fromAffine(s(tt("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return u.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,f.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=this.toAffine();if(!e.isValid(h)||!e.isValid(g))throw new Error("bad point: x or y not FE");let m=e.sqr(g),A=i(h);if(!e.eql(m,A))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:g,py:m,pz:A}=this,{px:b,py:T,pz:x}=h,S=e.eql(e.mul(g,x),e.mul(b,A)),_=e.eql(e.mul(m,x),e.mul(T,A));return S&&_}negate(){return new u(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,m=e.mul(g,Ga),{px:A,py:b,pz:T}=this,x=e.ZERO,S=e.ZERO,_=e.ZERO,N=e.mul(A,A),Y=e.mul(b,b),$=e.mul(T,T),D=e.mul(A,b);return D=e.add(D,D),_=e.mul(A,T),_=e.add(_,_),x=e.mul(h,_),S=e.mul(m,$),S=e.add(x,S),x=e.sub(Y,S),S=e.add(Y,S),S=e.mul(x,S),x=e.mul(D,x),_=e.mul(m,_),$=e.mul(h,$),D=e.sub(N,$),D=e.mul(h,D),D=e.add(D,_),_=e.add(N,N),N=e.add(_,N),N=e.add(N,$),N=e.mul(N,D),S=e.add(S,N),$=e.mul(b,T),$=e.add($,$),N=e.mul($,D),x=e.sub(x,N),_=e.mul($,Y),_=e.add(_,_),_=e.add(_,_),new u(x,S,_)}add(h){l(h);let{px:g,py:m,pz:A}=this,{px:b,py:T,pz:x}=h,S=e.ZERO,_=e.ZERO,N=e.ZERO,Y=t.a,$=e.mul(t.b,Ga),D=e.mul(g,b),nt=e.mul(m,T),et=e.mul(A,x),At=e.add(g,m),E=e.add(b,T);At=e.mul(At,E),E=e.add(D,nt),At=e.sub(At,E),E=e.add(g,A);let R=e.add(b,x);return E=e.mul(E,R),R=e.add(D,et),E=e.sub(E,R),R=e.add(m,A),S=e.add(T,x),R=e.mul(R,S),S=e.add(nt,et),R=e.sub(R,S),N=e.mul(Y,E),S=e.mul($,et),N=e.add(S,N),S=e.sub(nt,N),N=e.add(nt,N),_=e.mul(S,N),nt=e.add(D,D),nt=e.add(nt,D),et=e.mul(Y,et),E=e.mul($,E),nt=e.add(nt,et),et=e.sub(D,et),et=e.mul(Y,et),E=e.add(E,et),D=e.mul(nt,E),_=e.add(_,D),D=e.mul(R,E),S=e.mul(At,S),S=e.sub(S,D),D=e.mul(At,nt),N=e.mul(R,N),N=e.add(N,D),new u(S,_,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(u.ZERO)}wNAF(h){return w.wNAFCached(this,f,h,g=>{let m=e.invertBatch(g.map(A=>A.pz));return g.map((A,b)=>A.toAffine(m[b])).map(u.fromAffine)})}multiplyUnsafe(h){let g=u.ZERO;if(h===ie)return g;if(a(h),h===Rt)return this;let{endo:m}=t;if(!m)return w.unsafeLadder(this,h);let{k1neg:A,k1:b,k2neg:T,k2:x}=m.splitScalar(h),S=g,_=g,N=this;for(;b>ie||x>ie;)b&Rt&&(S=S.add(N)),x&Rt&&(_=_.add(N)),N=N.double(),b>>=Rt,x>>=Rt;return A&&(S=S.negate()),T&&(_=_.negate()),_=new u(e.mul(_.px,m.beta),_.py,_.pz),S.add(_)}multiply(h){a(h);let g=h,m,A,{endo:b}=t;if(b){let{k1neg:T,k1:x,k2neg:S,k2:_}=b.splitScalar(g),{p:N,f:Y}=this.wNAF(x),{p:$,f:D}=this.wNAF(_);N=w.constTimeNegate(T,N),$=w.constTimeNegate(S,$),$=new u(e.mul($.px,b.beta),$.py,$.pz),m=N.add($),A=Y.add(D)}else{let{p:T,f:x}=this.wNAF(g);m=T,A=x}return u.normalizeZ([m,A])[0]}multiplyAndAddUnsafe(h,g,m){let A=u.BASE,b=(x,S)=>S===ie||S===Rt||!x.equals(A)?x.multiplyUnsafe(S):x.multiply(S),T=b(this,g).add(b(h,m));return T.is0()?void 0:T}toAffine(h){let{px:g,py:m,pz:A}=this,b=this.is0();h==null&&(h=b?e.ONE:e.inv(A));let T=e.mul(g,h),x=e.mul(m,h),S=e.mul(A,h);if(b)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:T,y:x}}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===Rt)return!0;if(g)return g(u,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===Rt?this:g?g(u,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(u,this,h)}toHex(h=!0){return zt(this.toRawBytes(h))}}u.BASE=new u(t.Gx,t.Gy,e.ONE),u.ZERO=new u(e.ZERO,e.ONE,e.ZERO);let d=t.nBitLength,w=cn(u,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:o}}function Jf(r){let t=Br(r);return Ot(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function za(r){let t=Jf(r),{Fp:e,n}=t,s=e.BYTES+1,i=2*e.BYTES+1;function o(E){return ie<E&&E<e.ORDER}function a(E){return z(E,n)}function c(E){return on(E,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:d}=Zf({...t,toBytes(E,R,V){let v=R.toAffine(),y=e.toBytes(v.x),I=Zt;return V?I(Uint8Array.from([R.hasEvenY()?2:3]),y):I(Uint8Array.from([4]),y,e.toBytes(v.y))},fromBytes(E){let R=E.length,V=E[0],v=E.subarray(1);if(R===s&&(V===2||V===3)){let y=Wt(v);if(!o(y))throw new Error("Point is not on curve");let I=u(y),C;try{C=e.sqrt(I)}catch(H){let j=H instanceof Error?": "+H.message:"";throw new Error("Point is not on curve"+j)}let L=(C&Rt)===Rt;return(V&1)===1!==L&&(C=e.neg(C)),{x:y,y:C}}else if(R===i&&V===4){let y=e.fromBytes(v.subarray(0,e.BYTES)),I=e.fromBytes(v.subarray(e.BYTES,2*e.BYTES));return{x:y,y:I}}else throw new Error(`Point of length ${R} was invalid. Expected ${s} compressed bytes or ${i} uncompressed bytes`)}}),w=E=>zt(ye(E,t.nByteLength));function p(E){let R=n>>Rt;return E>R}function h(E){return p(E)?a(-E):E}let g=(E,R,V)=>Wt(E.slice(R,V));class m{constructor(R,V,v){this.r=R,this.s=V,this.recovery=v,this.assertValidity()}static fromCompact(R){let V=t.nByteLength;return R=tt("compactSignature",R,V*2),new m(g(R,0,V),g(R,V,2*V))}static fromDER(R){let{r:V,s:v}=Pe.toSig(tt("DER",R));return new m(V,v)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(R){return new m(this.r,this.s,R)}recoverPublicKey(R){let{r:V,s:v,recovery:y}=this,I=_(tt("msgHash",R));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let C=y===2||y===3?V+t.n:V;if(C>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=y&1?"03":"02",O=f.fromHex(L+w(C)),H=c(C),j=a(-I*H),M=a(v*H),q=f.BASE.multiplyAndAddUnsafe(O,j,M);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Ce(this.toDERHex())}toDERHex(){return Pe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ce(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}let A={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=zs(t.n);return ko(t.randomBytes(E),t.n)},precompute(E=8,R=f.BASE){return R._setWindowSize(E),R.multiply(BigInt(3)),R}};function b(E,R=!0){return f.fromPrivateKey(E).toRawBytes(R)}function T(E){let R=pe(E),V=typeof E=="string",v=(R||V)&&E.length;return R?v===s||v===i:V?v===2*s||v===2*i:E instanceof f}function x(E,R,V=!0){if(T(E))throw new Error("first arg must be private key");if(!T(R))throw new Error("second arg must be public key");return f.fromHex(R).multiply(l(E)).toRawBytes(V)}let S=t.bits2int||function(E){let R=Wt(E),V=E.length*8-t.nBitLength;return V>0?R>>BigInt(V):R},_=t.bits2int_modN||function(E){return a(S(E))},N=vr(t.nBitLength);function Y(E){if(typeof E!="bigint")throw new Error("bigint expected");if(!(ie<=E&&E<N))throw new Error(`bigint expected < 2^${t.nBitLength}`);return ye(E,t.nByteLength)}function $(E,R,V=D){if(["recovered","canonical"].some(X=>X in V))throw new Error("sign() legacy options not supported");let{hash:v,randomBytes:y}=t,{lowS:I,prehash:C,extraEntropy:L}=V;I==null&&(I=!0),E=tt("msgHash",E),C&&(E=tt("prehashed msgHash",v(E)));let O=_(E),H=l(R),j=[Y(H),Y(O)];if(L!=null&&L!==!1){let X=L===!0?y(e.BYTES):L;j.push(tt("extraEntropy",X))}let M=Zt(...j),q=O;function st(X){let ut=S(X);if(!d(ut))return;let ft=c(ut),ot=f.BASE.multiply(ut).toAffine(),pt=a(ot.x);if(pt===ie)return;let qt=a(ft*a(q+pt*H));if(qt===ie)return;let Ie=(ot.x===pt?0:2)|Number(ot.y&Rt),mr=qt;return I&&p(qt)&&(mr=h(qt),Ie^=1),new m(pt,mr,Ie)}return{seed:M,k2sig:st}}let D={lowS:t.lowS,prehash:!1},nt={lowS:t.lowS,prehash:!1};function et(E,R,V=D){let{seed:v,k2sig:y}=$(E,R,V),I=t;return qs(I.hash.outputLen,I.nByteLength,I.hmac)(v,y)}f.BASE._setWindowSize(8);function At(E,R,V,v=nt){let y=E;if(R=tt("msgHash",R),V=tt("publicKey",V),"strict"in v)throw new Error("options.strict was renamed to lowS");let{lowS:I,prehash:C}=v,L,O;try{if(typeof y=="string"||pe(y))try{L=m.fromDER(y)}catch(ot){if(!(ot instanceof Pe.Err))throw ot;L=m.fromCompact(y)}else if(typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint"){let{r:ot,s:pt}=y;L=new m(ot,pt)}else throw new Error("PARSE");O=f.fromHex(V)}catch(ot){if(ot.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(I&&L.hasHighS())return!1;C&&(R=t.hash(R));let{r:H,s:j}=L,M=_(R),q=c(j),st=a(M*q),X=a(H*q),ut=f.BASE.multiplyAndAddUnsafe(O,st,X)?.toAffine();return ut?a(ut.x)===H:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:x,sign:et,verify:At,ProjectivePoint:f,Signature:m,utils:A}}function Xf(r){return{hash:r,hmac:(t,...e)=>Rr(r,t,Ps(...e)),randomBytes:tr}}function Wa(r,t){let e=n=>za({...r,...Xf(n)});return Object.freeze({...e(t),create:e})}var Xa=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Za=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Qf=BigInt(1),Ai=BigInt(2),Ja=(r,t)=>(r+t/Ai)/t;function th(r){let t=Xa,e=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=J(l,e,t)*l%t,d=J(u,e,t)*l%t,w=J(d,Ai,t)*f%t,p=J(w,s,t)*w%t,h=J(p,i,t)*p%t,g=J(h,a,t)*h%t,m=J(g,c,t)*g%t,A=J(m,a,t)*h%t,b=J(A,e,t)*l%t,T=J(b,o,t)*p%t,x=J(T,n,t)*f%t,S=J(x,Ai,t);if(!Si.eql(Si.sqr(S),r))throw new Error("Cannot find square root");return S}var Si=an(Xa,void 0,void 0,{sqrt:th}),Ut=Wa({a:BigInt(0),b:BigInt(7),Fp:Si,n:Za,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Za,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Qf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=e,o=BigInt("0x100000000000000000000000000000000"),a=Ja(i*r,t),c=Ja(-n*r,t),f=z(r-a*e-c*s,t),l=z(-a*n-c*i,t),u=f>o,d=l>o;if(u&&(f=t-f),d&&(l=t-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:u,k1:f,k2neg:d,k2:l}}}},ls),Ig=BigInt(0);var Rg=Ut.ProjectivePoint;function Qa(){return Ut.utils.randomPrivateKey()}function tc(r,t){let e=ht.digest(t instanceof Uint8Array?t:t.subarray());if(kt(e))return e.then(({digest:n})=>Ut.sign(n,r).toDERRawBytes()).catch(n=>{throw new B(String(n),"ERR_INVALID_INPUT")});try{return Ut.sign(e.digest,r).toDERRawBytes()}catch(n){throw new B(String(n),"ERR_INVALID_INPUT")}}function ec(r,t,e){let n=ht.digest(e instanceof Uint8Array?e:e.subarray());if(kt(n))return n.then(({digest:s})=>Ut.verify(t,s,r)).catch(s=>{throw new B(String(s),"ERR_INVALID_INPUT")});try{return Ut.verify(t,n.digest,r)}catch(s){throw new B(String(s),"ERR_INVALID_INPUT")}}function rc(r){return Ut.ProjectivePoint.fromHex(r).toRawBytes(!0)}function nc(r){try{Ut.getPublicKey(r,!0)}catch(t){throw new B(String(t),"ERR_INVALID_PRIVATE_KEY")}}function ki(r){try{Ut.ProjectivePoint.fromHex(r)}catch(t){throw new B(String(t),"ERR_INVALID_PUBLIC_KEY")}}function sc(r){try{return Ut.getPublicKey(r,!0)}catch(t){throw new B(String(t),"ERR_INVALID_PRIVATE_KEY")}}var Kr=class{_key;constructor(t){ki(t),this._key=t}verify(t,e){return ec(this._key,e,t)}marshal(){return rc(this._key)}get bytes(){return Xt.encode({Type:rt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}async hash(){let t=ht.digest(this.bytes),e;return kt(t)?{bytes:e}=await t:e=t.bytes,e}},Mr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??sc(t),nc(this._key),ki(this._publicKey)}sign(t){return tc(this._key,t)}get public(){return new Kr(this._publicKey)}marshal(){return this._key}get bytes(){return Ht.encode({Type:rt.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return St(this.bytes,t.bytes)}hash(){let t=ht.digest(this.bytes);return kt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return G(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return sr(this.bytes,t);throw new B(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function rh(r){return new Mr(r)}function nh(r){return new Kr(r)}async function sh(){let r=Qa();return new Mr(r)}var Fr={rsa:vi,ed25519:fi,secp256k1:Ii};function ic(r){let t=Object.keys(Fr).join(" / ");return new B(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function ih(r){if(r=r.toLowerCase(),r==="rsa"||r==="ed25519"||r==="secp256k1")return Fr[r];throw ic(r)}async function oc(r,t){return ih(r).generateKeyPair(t??2048)}async function Ri(r){let t=Ht.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case rt.RSA:return Fr.rsa.unmarshalRsaPrivateKey(e);case rt.Ed25519:return Fr.ed25519.unmarshalEd25519PrivateKey(e);case rt.Secp256k1:return Fr.secp256k1.unmarshalSecp256k1PrivateKey(e);default:throw ic(t.Type??"RSA")}}async function $r(r,t){try{let e=await Jo(r,t);return await Ri(e)}catch{}if(!r.includes("BEGIN"))throw new B("Encrypted key was not a libp2p-key or a PEM file","ERR_INVALID_IMPORT_FORMAT");return wi(r,t)}var qr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Se=new Uint32Array(80),_i=class extends fe{constructor(){super(64,20,8,!1),this.A=qr[0]|0,this.B=qr[1]|0,this.C=qr[2]|0,this.D=qr[3]|0,this.E=qr[4]|0}get(){let{A:t,B:e,C:n,D:s,E:i}=this;return[t,e,n,s,i]}set(t,e,n,s,i){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=i|0}process(t,e){for(let c=0;c<16;c++,e+=4)Se[c]=t.getUint32(e,!1);for(let c=16;c<80;c++)Se[c]=Qr(Se[c-3]^Se[c-8]^Se[c-14]^Se[c-16],1);let{A:n,B:s,C:i,D:o,E:a}=this;for(let c=0;c<80;c++){let f,l;c<20?(f=tn(s,i,o),l=1518500249):c<40?(f=s^i^o,l=1859775393):c<60?(f=en(s,i,o),l=2400959708):(f=s^i^o,l=3395469782);let u=Qr(n,5)+f+a+l+Se[c]|0;a=o,o=i,i=Qr(s,30),s=n,n=u}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,s,i,o,a)}roundClean(){Se.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},ac=Qe(()=>new _i);var cc={sha1:ac,"sha2-256":ls,"sha2-512":Te};function jr(r,t,e,n,s){if(s!=="sha1"&&s!=="sha2-256"&&s!=="sha2-512"){let a=Object.keys(cc).join(" / ");throw new B(`Hash '${s}' is unknown or not supported. Must be ${a}`,"ERR_UNSUPPORTED_HASH_TYPE")}let i=cc[s],o=ta(i,r,t,{c:e,dkLen:n});return _e.encode(o).substring(1)}var uc=Symbol.for("nodejs.util.inspect.custom"),lc=Object.values(ze).map(r=>r.decoder).reduce((r,t)=>r.or(t),ze.identity.decoder),fc=114,Ci=36,Li=37,Yr=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ys]=!0;toString(){return this.string==null&&(this.string=bt.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return le.createV1(fc,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return St(this.multihash.bytes,t);if(typeof t=="string")return oh(t).equals(this);if(t?.multihash?.bytes!=null)return St(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[uc](){return`PeerId(${this.toString()})`}},hr=class extends Yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},dr=class extends Yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},pr=class extends Yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}},Ni=2336,Ti=class{type="url";multihash;privateKey;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Yt.digest(P(this.url))}[uc](){return`PeerId(${this.url})`}[ys]=!0;toString(){return this.toCID().toString()}toCID(){return le.createV1(Ni,this.multihash)}toBytes(){return this.toCID().bytes}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function oh(r,t){if(t=t??lc,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=xr(bt.decode(`z${r}`));return r.startsWith("12D")?new dr({multihash:e}):r.startsWith("16U")?new pr({multihash:e}):new hr({multihash:e})}return ah(lc.decode(r))}function ah(r){try{let t=xr(r);if(t.code===Yt.code){if(t.digest.length===Ci)return new dr({multihash:t});if(t.digest.length===Li)return new pr({multihash:t})}if(t.code===ht.code)return new hr({multihash:t})}catch{return ch(le.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function ch(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==fc&&r.code!==Ni)throw new Error("Supplied PeerID CID is invalid");if(r.code===Ni){let e=G(r.multihash.digest);return new Ti(new URL(e))}let t=r.multihash;if(t.code===ht.code)return new hr({multihash:r.multihash});if(t.code===Yt.code){if(t.digest.length===Ci)return new dr({multihash:r.multihash});if(t.digest.length===Li)return new pr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function hc(r,t){return r.length===Ci?new dr({multihash:Dt(Yt.code,r),privateKey:t}):r.length===Li?new pr({multihash:Dt(Yt.code,r),privateKey:t}):new hr({multihash:await ht.digest(r),publicKey:r,privateKey:t})}var oe="/",dc=new TextEncoder().encode(oe),us=dc[0],Gr=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=P(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==us)throw new Error("Invalid key")}toString(t="utf8"){return G(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(oe))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=dc),this._buf[0]!==us){let t=new Uint8Array(this._buf.byteLength+1);t.fill(us,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===us;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let s=0;s<e.length;s++){if(n.length<s+1)return!1;let i=e[s],o=n[s];if(i<o)return!0;if(i>o)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(oe).slice(1)}type(){return lh(this.baseNamespace())}name(){return uh(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(oe)||(t+=oe),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(oe):new r(t.slice(0,-1).join(oe))}child(t){return this.toString()===oe?t:t.toString()===oe?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...fh(t.map(e=>e.namespaces()))])}};function lh(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function uh(r){let t=r.split(":");return t[t.length-1]}function fh(r){return[].concat(...r)}var vc=gs(Ec(),1),Bc=vc.default;var Lc=gs(Cc(),1);var F;(function(r){r.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",r.ERR_INVALID_KEY_NAME="ERR_INVALID_KEY_NAME",r.ERR_INVALID_KEY_TYPE="ERR_INVALID_KEY_TYPE",r.ERR_KEY_ALREADY_EXISTS="ERR_KEY_ALREADY_EXISTS",r.ERR_INVALID_KEY_SIZE="ERR_INVALID_KEY_SIZE",r.ERR_KEY_NOT_FOUND="ERR_KEY_NOT_FOUND",r.ERR_OLD_KEY_NAME_INVALID="ERR_OLD_KEY_NAME_INVALID",r.ERR_NEW_KEY_NAME_INVALID="ERR_NEW_KEY_NAME_INVALID",r.ERR_PASSWORD_REQUIRED="ERR_PASSWORD_REQUIRED",r.ERR_PEM_REQUIRED="ERR_PEM_REQUIRED",r.ERR_CANNOT_READ_KEY="ERR_CANNOT_READ_KEY",r.ERR_MISSING_PRIVATE_KEY="ERR_MISSING_PRIVATE_KEY",r.ERR_INVALID_OLD_PASS_TYPE="ERR_INVALID_OLD_PASS_TYPE",r.ERR_INVALID_NEW_PASS_TYPE="ERR_INVALID_NEW_PASS_TYPE",r.ERR_INVALID_PASS_LENGTH="ERR_INVALID_PASS_LENGTH"})(F||(F={}));var _h="/pkcs8/",Uc="/info/",Ke=new WeakMap,Me={minKeyLength:112/8,minSaltLength:128/8,minIterationCount:1e3},Di={dek:{keyLength:512/8,iterationCount:1e4,salt:"you should override this value with a crypto secure random number",hash:"sha2-512"}};function ae(r){return r==null||typeof r!="string"?!1:r===(0,Lc.default)(r.trim())&&r.length>0}async function W(){let e=Math.random()*800+200;await new Promise(n=>setTimeout(n,e))}function $t(r){return new Gr(_h+r)}function ke(r){return new Gr(Uc+r)}var ds=class{components;init;log;constructor(t,e){if(this.components=t,this.log=t.logger.forComponent("libp2p:keychain"),this.init=Bc(Di,e),this.init.pass!=null&&this.init.pass?.length<20)throw new Error("pass must be least 20 characters");if(this.init.dek?.keyLength!=null&&this.init.dek.keyLength<Me.minKeyLength)throw new Error(`dek.keyLength must be least ${Me.minKeyLength} bytes`);if(this.init.dek?.salt?.length!=null&&this.init.dek.salt.length<Me.minSaltLength)throw new Error(`dek.saltLength must be least ${Me.minSaltLength} bytes`);if(this.init.dek?.iterationCount!=null&&this.init.dek.iterationCount<Me.minIterationCount)throw new Error(`dek.iterationCount must be least ${Me.minIterationCount}`);let n=this.init.pass!=null&&this.init.dek?.salt!=null?jr(this.init.pass,this.init.dek?.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";Ke.set(this,{dek:n})}[Symbol.toStringTag]="@libp2p/keychain";[ji]=["@libp2p/keychain"];static generateOptions(){let t=Object.assign({},Di),e=Math.ceil(Me.minSaltLength/3)*3;return t.dek.salt=G(Pt(e),"base64"),t}static get options(){return Di}async createKey(t,e,n=2048){if(!ae(t)||t==="self")throw await W(),new B("Invalid key name",F.ERR_INVALID_KEY_NAME);if(typeof e!="string")throw await W(),new B("Invalid key type",F.ERR_INVALID_KEY_TYPE);let s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B("Key name already exists",F.ERR_KEY_ALREADY_EXISTS);switch(e.toLowerCase()){case"rsa":if(!Number.isSafeInteger(n)||n<2048)throw await W(),new B("Invalid RSA key size",F.ERR_INVALID_KEY_SIZE);break;default:break}let o;try{let a=await oc(e,n),c=await a.id(),f=Ke.get(this);if(f==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let l=f.dek,u=await a.export(l);o={name:t,id:c};let d=this.components.datastore.batch();d.put(s,P(u)),d.put(ke(t),P(JSON.stringify(o))),await d.commit()}catch(a){throw await W(),a}return o}async listKeys(){let t={prefix:Uc},e=[];for await(let n of this.components.datastore.query(t))e.push(JSON.parse(G(n.value)));return e}async findKeyById(t){try{let n=(await this.listKeys()).find(s=>s.id===t);if(n==null)throw new B(`Key with id '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND);return n}catch(e){throw await W(),e}}async findKeyByName(t){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);let e=ke(t);try{let n=await this.components.datastore.get(e);return JSON.parse(G(n))}catch(n){throw await W(),this.log.error(n),new B(`Key '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND)}}async removeKey(t){if(!ae(t)||t==="self")throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);let e=$t(t),n=await this.findKeyByName(t),s=this.components.datastore.batch();return s.delete(e),s.delete(ke(t)),await s.commit(),n}async renameKey(t,e){if(!ae(t)||t==="self")throw await W(),new B(`Invalid old key name '${t}'`,F.ERR_OLD_KEY_NAME_INVALID);if(!ae(e)||e==="self")throw await W(),new B(`Invalid new key name '${e}'`,F.ERR_NEW_KEY_NAME_INVALID);let n=$t(t),s=$t(e),i=ke(t),o=ke(e);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${e}' already exists`,F.ERR_KEY_ALREADY_EXISTS);try{let c=await this.components.datastore.get(n),f=await this.components.datastore.get(i),l=JSON.parse(G(f));l.name=e;let u=this.components.datastore.batch();return u.put(s,c),u.put(o,P(JSON.stringify(l))),u.delete(n),u.delete(i),await u.commit(),l}catch(c){throw await W(),c}}async exportKey(t,e){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw await W(),new B("Password is required",F.ERR_PASSWORD_REQUIRED);let n=$t(t);try{let s=await this.components.datastore.get(n),i=G(s),o=Ke.get(this);if(o==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let a=o.dek;return await(await $r(i,a)).export(e)}catch(s){throw await W(),s}}async exportPeerId(t){let e="temporary-password",n=await this.exportKey(t,e),s=await $r(n,e);return hc(s.public.bytes,s.bytes)}async importKey(t,e,n){if(!ae(t)||t==="self")throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw await W(),new B("PEM encoded key is required",F.ERR_PEM_REQUIRED);let s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${t}' already exists`,F.ERR_KEY_ALREADY_EXISTS);let o;try{o=await $r(e,n)}catch{throw await W(),new B("Cannot read the key, most likely the password is wrong",F.ERR_CANNOT_READ_KEY)}let a;try{a=await o.id();let l=Ke.get(this);if(l==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let u=l.dek;e=await o.export(u)}catch(l){throw await W(),l}let c={name:t,id:a},f=this.components.datastore.batch();return f.put(s,P(e)),f.put(ke(t),P(JSON.stringify(c))),await f.commit(),c}async importPeer(t,e){try{if(!ae(t))throw new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);if(e==null)throw new B("PeerId is required",F.ERR_MISSING_PRIVATE_KEY);if(e.privateKey==null)throw new B("PeerId.privKey is required",F.ERR_MISSING_PRIVATE_KEY);let n=await Ri(e.privateKey),s=$t(t);if(await this.components.datastore.has(s))throw await W(),new B(`Key '${t}' already exists`,F.ERR_KEY_ALREADY_EXISTS);let o=Ke.get(this);if(o==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let a=o.dek,c=await n.export(a),f={name:t,id:e.toString()},l=this.components.datastore.batch();return l.put(s,P(c)),l.put(ke(t),P(JSON.stringify(f))),await l.commit(),f}catch(n){throw await W(),n}}async getPrivateKey(t){if(!ae(t))throw await W(),new B(`Invalid key name '${t}'`,F.ERR_INVALID_KEY_NAME);try{let e=$t(t),n=await this.components.datastore.get(e);return G(n)}catch(e){throw await W(),this.log.error(e),new B(`Key '${t}' does not exist.`,F.ERR_KEY_NOT_FOUND)}}async rotateKeychainPass(t,e){if(typeof t!="string")throw await W(),new B(`Invalid old pass type '${typeof t}'`,F.ERR_INVALID_OLD_PASS_TYPE);if(typeof e!="string")throw await W(),new B(`Invalid new pass type '${typeof e}'`,F.ERR_INVALID_NEW_PASS_TYPE);if(e.length<20)throw await W(),new B(`Invalid pass length ${e.length}`,F.ERR_INVALID_PASS_LENGTH);this.log("recreating keychain");let n=Ke.get(this);if(n==null)throw new B("dek missing",F.ERR_INVALID_PARAMETERS);let s=n.dek;this.init.pass=e;let i=e!=null&&this.init.dek?.salt!=null?jr(e,this.init.dek.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";Ke.set(this,{dek:i});let o=await this.listKeys();for(let a of o){let c=await this.components.datastore.get($t(a.name)),f=G(c),l=await $r(f,s),u=i.toString(),d=await l.export(u),w=this.components.datastore.batch(),p={name:a.name,id:a.id};w.put($t(a.name),P(d)),w.put(ke(a.name),P(JSON.stringify(p))),await w.commit()}this.log("keychain reconstructed")}};function Nh(r={}){return t=>new ds(t,r)}return zc(Th);})();
|
|
8
8
|
/*! Bundled license information:
|
|
9
9
|
|
|
10
10
|
pvtsutils/build/index.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/keychain",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3-f30e2ee8d",
|
|
4
4
|
"description": "Key management and cryptographically protected messages",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/keychain#readme",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"test:electron-main": "aegir test -t electron-main"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@libp2p/crypto": "
|
|
63
|
-
"@libp2p/interface": "
|
|
64
|
-
"@libp2p/peer-id": "
|
|
62
|
+
"@libp2p/crypto": "4.1.7-f30e2ee8d",
|
|
63
|
+
"@libp2p/interface": "1.6.2-f30e2ee8d",
|
|
64
|
+
"@libp2p/peer-id": "4.2.2-f30e2ee8d",
|
|
65
65
|
"interface-datastore": "^8.2.11",
|
|
66
66
|
"merge-options": "^3.0.4",
|
|
67
67
|
"multiformats": "^13.1.0",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"uint8arrays": "^5.1.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@libp2p/logger": "
|
|
73
|
-
"@libp2p/peer-id-factory": "
|
|
74
|
-
"aegir": "^
|
|
72
|
+
"@libp2p/logger": "4.0.18-f30e2ee8d",
|
|
73
|
+
"@libp2p/peer-id-factory": "4.2.2-f30e2ee8d",
|
|
74
|
+
"aegir": "^44.0.1",
|
|
75
75
|
"datastore-core": "^9.2.9"
|
|
76
76
|
},
|
|
77
77
|
"sideEffects": false
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"DEKConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.DEKConfig.html",
|
|
3
|
-
".:DEKConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.DEKConfig.html",
|
|
4
|
-
"KeyInfo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeyInfo.html",
|
|
5
|
-
".:KeyInfo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeyInfo.html",
|
|
6
|
-
"Keychain": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.Keychain.html",
|
|
7
|
-
".:Keychain": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.Keychain.html",
|
|
8
|
-
"KeychainComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainComponents.html",
|
|
9
|
-
".:KeychainComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainComponents.html",
|
|
10
|
-
"KeychainInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainInit.html",
|
|
11
|
-
".:KeychainInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainInit.html",
|
|
12
|
-
"keychain": "https://libp2p.github.io/js-libp2p/functions/_libp2p_keychain.keychain-1.html",
|
|
13
|
-
".:keychain": "https://libp2p.github.io/js-libp2p/functions/_libp2p_keychain.keychain-1.html"
|
|
14
|
-
}
|