@libp2p/keychain 5.0.10 → 5.0.11

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/README.md CHANGED
@@ -81,7 +81,7 @@ $ npm i @libp2p/keychain
81
81
 
82
82
  ## Browser `<script>` tag
83
83
 
84
- Loading this module through a script tag will make it's exports available as `Libp2pKeychain` in the global namespace.
84
+ Loading this module through a script tag will make its exports available as `Libp2pKeychain` in the global namespace.
85
85
 
86
86
  ```html
87
87
  <script src="https://unpkg.com/@libp2p/keychain/dist/index.min.js"></script>
package/dist/index.min.js CHANGED
@@ -1,17 +1,17 @@
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 jc=Object.create;var Gr=Object.defineProperty;var zc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Zc=Object.getPrototypeOf,Wc=Object.prototype.hasOwnProperty;var Be=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ft=(r,t)=>{for(var e in t)Gr(r,e,{get:t[e],enumerable:!0})},Go=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gc(t))!Wc.call(r,s)&&s!==e&&Gr(r,s,{get:()=>t[s],enumerable:!(n=zc(t,s))||n.enumerable});return r};var bs=(r,t,e)=>(e=r!=null?jc(Zc(r)):{},Go(t||!r||!r.__esModule?Gr(e,"default",{value:r,enumerable:!0}):e,r)),Jc=r=>Go(Gr({},"__esModule",{value:!0}),r);var Yi=Be(tr=>{"use strict";var xf="[object ArrayBuffer]",Gt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===xf}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 o=0;o<n.length;o++)if(n[o]!==s[o])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 i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},xo="string",vf=/^[0-9a-f]+$/i,Bf=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ef=/^[a-zA-Z0-9-_]+$/,bn=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=Gt.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},At=class{static toString(t,e=!1){let n=Gt.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},wn=class r{static isHex(t){return typeof t===xo&&vf.test(t)}static isBase64(t){return typeof t===xo&&Bf.test(t)}static isBase64Url(t){return typeof t===xo&&Ef.test(t)}static ToString(t,e="utf8"){let n=Gt.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 At.toString(n,!0);case"utf16":case"utf16be":return At.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 At.fromString(t,!0);case"utf16":case"utf16be":return At.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=Gt.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 bn.fromString(t);case"utf16":case"utf16be":return At.fromString(t);case"utf16le":case"usc2":return At.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 bn.toString(t);case"utf16":case"utf16be":return At.toString(t);case"utf16le":case"usc2":return At.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=Gt.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=Gt.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.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 o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return At.toString(t,e)}static FromUtf16String(t,e=!1){return At.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,"")||""}};wn.DEFAULT_UTF8_ENCODING="utf8";function Af(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function kf(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function Sf(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}tr.BufferSourceConverter=Gt;tr.Convert=wn;tr.assign=Af;tr.combine=kf;tr.isEqual=Sf});var gc=Be((lm,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 vc=Be((wc,xc)=>{"use strict";var ds=gc(),{hasOwnProperty:yc}=Object.prototype,{propertyIsEnumerable:jf}=Object,or=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),zf=wc,mc={concatArrays:!1,ignoreUndefined:!1},ps=r=>{let t=[];for(let e in r)yc.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)jf.call(r,n)&&t.push(n)}return t};function ir(r){return Array.isArray(r)?Gf(r):ds(r)?Zf(r):r}function Gf(r){let t=r.slice(0,0);return ps(r).forEach(e=>{or(t,e,ir(r[e]))}),t}function Zf(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return ps(r).forEach(e=>{or(t,e,ir(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)?or(r,s,_o(r[s],t[s],n)):or(r,s,ir(t[s])))}),r),Wf=(r,t,e)=>{let n=r.slice(0,0),s=0;return[r,t].forEach(o=>{let i=[];for(let a=0;a<o.length;a++)yc.call(o,a)&&(i.push(String(a)),o===r?or(n,s++,o[a]):or(n,s++,ir(o[a])));n=bc(n,o,ps(o).filter(a=>!i.includes(a)),e)}),n};function _o(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?Wf(r,t,e):!ds(t)||!ds(r)?ir(t):bc(r,t,ps(t),e)}xc.exports=function(...r){let t=_o(ir(mc),this!==zf&&this||{},mc),e={_:{}};for(let n of r)if(n!==void 0){if(!ds(n))throw new TypeError("`"+n+"` is not an Option Object");e=_o(e,{_:n},t)}return e._}});var kc=Be((fm,Ac)=>{"use strict";function Jf(r){return r>=55296&&r<=56319}function Yf(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,o=0,i,a,c=0;c<s;c+=1){if(i=e.charCodeAt(c),a=e[c],Jf(i)&&Yf(e.charCodeAt(c+1))&&(c+=1,a+=e[c]),o+=t(a),o===n)return e.slice(0,c+1);if(o>n)return e.slice(0,c-a.length+1)}return e}});var Ic=Be((hm,Sc)=>{"use strict";function Xf(r){return r>=55296&&r<=56319}function Qf(r){return r>=56320&&r<=57343}Sc.exports=function(t){if(typeof t!="string")throw new Error("Input must be string");for(var e=t.length,n=0,s=null,o=null,i=0;i<e;i++)s=t.charCodeAt(i),Qf(s)?o!=null&&Xf(o)?n+=1:n+=3:s<=127?n+=1:s>=128&&s<=2047?n+=2:s>=2048&&s<=65535&&(n+=3),o=s;return n}});var Cc=Be((dm,Nc)=>{"use strict";var th=kc(),eh=Ic();Nc.exports=th.bind(null,eh)});var Rc=Be((pm,Uc)=>{"use strict";var rh=Cc(),nh=/[\/\?<>\\:\*\|"]/g,sh=/[\x00-\x1f\x80-\x9f]/g,oh=/^\.+$/,ih=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,ah=/[\. ]+$/;function Tc(r,t){if(typeof r!="string")throw new Error("Input must be string");var e=r.replace(nh,t).replace(sh,t).replace(oh,t).replace(ih,t).replace(ah,t);return rh(e,255)}Uc.exports=function(r,t){var e=t&&t.replacement||"",n=Tc(r,e);return e===""?n:Tc(n,"")}});var wh={};ft(wh,{keychain:()=>bh});var hr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},dr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Zo={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var bt=Zo;var _=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},De=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},pr=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Wr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Ke=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Wo=Symbol.for("@libp2p/service-capabilities"),Ih=Symbol.for("@libp2p/service-dependencies");var Es={};ft(Es,{base58btc:()=>ot,base58flickr:()=>rl});var Yh=new Uint8Array(0);function Jo(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 Mt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Yo(r){return new TextEncoder().encode(r)}function Xo(r){return new TextDecoder().decode(r)}function Yc(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 o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var m=0,d=0,y=0,B=x.length;y!==B&&x[y]===0;)y++,m++;for(var g=(B-y)*l+1>>>0,E=new Uint8Array(g);y!==B;){for(var R=x[y],U=0,S=g-1;(R!==0||U<d)&&S!==-1;S--,U++)R+=256*E[S]>>>0,E[S]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=U,y++}for(var I=g-d;I!==g&&E[I]===0;)I++;for(var T=c.repeat(m);I<g;++I)T+=r.charAt(E[I]);return T}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var m=0;if(x[m]!==" "){for(var d=0,y=0;x[m]===c;)d++,m++;for(var B=(x.length-m)*u+1>>>0,g=new Uint8Array(B);x[m];){var E=e[x.charCodeAt(m)];if(E===255)return;for(var R=0,U=B-1;(E!==0||R<y)&&U!==-1;U--,R++)E+=a*g[U]>>>0,g[U]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");y=R,m++}if(x[m]!==" "){for(var S=B-y;S!==B&&g[S]===0;)S++;for(var I=new Uint8Array(d+(B-S)),T=d;S!==B;)I[T++]=g[S++];return I}}}function w(x){var m=h(x);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:h,decode:w}}var Xc=Yc,Qc=Xc,ti=Qc;var ws=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")}},xs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 ei(this,t)}},vs=class{decoders;constructor(t){this.decoders=t}or(t){return ei(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 ei(r,t){return new vs({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Bs=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 ws(t,e,n),this.decoder=new xs(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Me({name:r,prefix:t,encode:e,decode:n}){return new Bs(r,t,e,n)}function ne({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=ti(e,r);return Me({prefix:t,name:r,encode:n,decode:o=>Mt(s(o))})}function tl(r,t,e,n){let s={};for(let l=0;l<t.length;++l)s[t[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=s[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|f,a+=e,a>=8&&(a-=8,i[u++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function el(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Me({prefix:t,name:r,encode(s){return el(s,n,e)},decode(s){return tl(s,n,e,r)}})}var ot=ne({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rl=ne({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var As={};ft(As,{base32:()=>Pe,base32hex:()=>il,base32hexpad:()=>cl,base32hexpadupper:()=>ll,base32hexupper:()=>al,base32pad:()=>sl,base32padupper:()=>ol,base32upper:()=>nl,base32z:()=>ul});var Pe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),nl=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),sl=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ol=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),il=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),al=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cl=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ll=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ul=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ks={};ft(ks,{base36:()=>gr,base36upper:()=>fl});var gr=ne({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fl=ne({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var hl=si,ri=128,dl=127,pl=~dl,gl=Math.pow(2,31);function si(r,t,e){t=t||[],e=e||0;for(var n=e;r>=gl;)t[e++]=r&255|ri,r/=128;for(;r&pl;)t[e++]=r&255|ri,r>>>=7;return t[e]=r|0,si.bytes=e-n+1,t}var ml=Ss,yl=128,ni=127;function Ss(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw Ss.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&ni)<<s:(i&ni)*Math.pow(2,s),s+=7}while(i>=yl);return Ss.bytes=o-n,e}var bl=Math.pow(2,7),wl=Math.pow(2,14),xl=Math.pow(2,21),vl=Math.pow(2,28),Bl=Math.pow(2,35),El=Math.pow(2,42),Al=Math.pow(2,49),kl=Math.pow(2,56),Sl=Math.pow(2,63),Il=function(r){return r<bl?1:r<wl?2:r<xl?3:r<vl?4:r<Bl?5:r<El?6:r<Al?7:r<kl?8:r<Sl?9:10},Nl={encode:hl,decode:ml,encodingLength:Il},Cl=Nl,mr=Cl;function yr(r,t=0){return[mr.decode(r,t),mr.decode.bytes]}function Fe(r,t,e=0){return mr.encode(r,t,e),t}function $e(r){return mr.encodingLength(r)}function St(r,t){let e=t.byteLength,n=$e(r),s=n+$e(e),o=new Uint8Array(s+e);return Fe(r,o,0),Fe(e,o,n),o.set(t,s),new qe(r,e,t,o)}function oi(r){let t=Mt(r),[e,n]=yr(t),[s,o]=yr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new qe(e,s,i,t)}function ii(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Jo(r.bytes,e.bytes)}}var qe=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function ai(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ul(e,Is(r),t??ot.encoder);default:return Rl(e,Is(r),t??Pe.encoder)}}var ci=new WeakMap;function Is(r){let t=ci.get(r);if(t==null){let e=new Map;return ci.set(r,e),e}return t}var Lt=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!==wr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ll)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=St(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&&ii(t.multihash,n.multihash)}toString(t){return ai(this,t)}toJSON(){return{"/":ai(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:o,bytes:i}=e;return new r(n,s,o,i??li(n,s,o.bytes))}else if(e[_l]===!0){let{version:n,multihash:s,code:o}=e,i=oi(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==wr)throw new Error(`Version 0 CID must use dag-pb (code: ${wr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=li(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,wr,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=Mt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new qe(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,h]=yr(t.subarray(e));return e+=h,f},s=n(),o=wr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,s]=Tl(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Is(o).set(n,t),o}};function Tl(r,t){switch(r[0]){case"Q":{let e=t??ot;return[ot.prefix,e.decode(`${ot.prefix}${r}`)]}case ot.prefix:{let e=t??ot;return[ot.prefix,e.decode(r)]}case Pe.prefix:{let e=t??Pe;return[Pe.prefix,e.decode(r)]}case gr.prefix:{let e=t??gr;return[gr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Ul(r,t,e){let{prefix:n}=e;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function Rl(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var wr=112,Ll=18;function li(r,t,e){let n=$e(r),s=n+$e(t),o=new Uint8Array(s+e.byteLength);return Fe(r,o,0),Fe(t,o,n),o.set(e,s),o}var _l=Symbol.for("@ipld/js-cid/CID");var Ns={};ft(Ns,{identity:()=>xr});var ui=0,Hl="identity",fi=Mt;function Vl(r){return St(ui,fi(r))}var xr={code:ui,name:Hl,encode:fi,digest:Vl};function Pt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function je(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Ol(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function ze(r,...t){if(!Ol(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 Yr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");je(r.outputLen),je(r.blockLen)}function Ge(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function hi(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 Ee=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Ae=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),It=(r,t)=>r<<32-t|r>>>t,Xr=(r,t)=>r<<t|r>>>32-t>>>0,xd=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Dl=async()=>{};async function di(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let o=Date.now()-n;o>=0&&o<t||(await Dl(),n+=o)}}function pi(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function se(r){return typeof r=="string"&&(r=pi(r)),ze(r),r}function Cs(...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 o=r[n];e.set(o,s),s+=o.length}return e}var Ze=class{clone(){return this._cloneInto()}},Kl={}.toString;function gi(r,t){if(t!==void 0&&Kl.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function We(r){let t=n=>r().update(se(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Je(r=32){if(Ee&&typeof Ee.getRandomValues=="function")return Ee.getRandomValues(new Uint8Array(r));if(Ee&&typeof Ee.randomBytes=="function")return Ee.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Ml(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}var Qr=(r,t,e)=>r&t^~r&e,tn=(r,t,e)=>r&t^r&e^t&e,oe=class extends Ze{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=Ae(this.buffer)}update(t){Ge(this);let{view:e,buffer:n,blockLen:s}=this;t=se(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Ae(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ge(this),hi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let f=i;f<s;f++)e[f]=0;Ml(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=Ae(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}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:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var en=BigInt(4294967295),Ts=BigInt(32);function mi(r,t=!1){return t?{h:Number(r&en),l:Number(r>>Ts&en)}:{h:Number(r>>Ts&en)|0,l:Number(r&en)|0}}function Pl(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=mi(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Fl=(r,t)=>BigInt(r>>>0)<<Ts|BigInt(t>>>0),$l=(r,t,e)=>r>>>e,ql=(r,t,e)=>r<<32-e|t>>>e,jl=(r,t,e)=>r>>>e|t<<32-e,zl=(r,t,e)=>r<<32-e|t>>>e,Gl=(r,t,e)=>r<<64-e|t>>>e-32,Zl=(r,t,e)=>r>>>e-32|t<<64-e,Wl=(r,t)=>t,Jl=(r,t)=>r,Yl=(r,t,e)=>r<<e|t>>>32-e,Xl=(r,t,e)=>t<<e|r>>>32-e,Ql=(r,t,e)=>t<<e-32|r>>>64-e,tu=(r,t,e)=>r<<e-32|t>>>64-e;function eu(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var ru=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),nu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,su=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ou=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,iu=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),au=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var cu={fromBig:mi,split:Pl,toBig:Fl,shrSH:$l,shrSL:ql,rotrSH:jl,rotrSL:zl,rotrBH:Gl,rotrBL:Zl,rotr32H:Wl,rotr32L:Jl,rotlSH:Yl,rotlSL:Xl,rotlBH:Ql,rotlBL:tu,add:eu,add3L:ru,add3H:nu,add4L:su,add4H:ou,add5H:au,add5L:iu},V=cu;var[lu,uu]=V.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))),ie=new Uint32Array(80),ae=new Uint32Array(80),Us=class extends oe{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:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:h,Gh:w,Gl:x,Hh:m,Hl:d}=this;return[t,e,n,s,o,i,a,c,u,l,f,h,w,x,m,d]}set(t,e,n,s,o,i,a,c,u,l,f,h,w,x,m,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=h|0,this.Gh=w|0,this.Gl=x|0,this.Hh=m|0,this.Hl=d|0}process(t,e){for(let g=0;g<16;g++,e+=4)ie[g]=t.getUint32(e),ae[g]=t.getUint32(e+=4);for(let g=16;g<80;g++){let E=ie[g-15]|0,R=ae[g-15]|0,U=V.rotrSH(E,R,1)^V.rotrSH(E,R,8)^V.shrSH(E,R,7),S=V.rotrSL(E,R,1)^V.rotrSL(E,R,8)^V.shrSL(E,R,7),I=ie[g-2]|0,T=ae[g-2]|0,X=V.rotrSH(I,T,19)^V.rotrBH(I,T,61)^V.shrSH(I,T,6),F=V.rotrSL(I,T,19)^V.rotrBL(I,T,61)^V.shrSL(I,T,6),O=V.add4L(S,F,ae[g-7],ae[g-16]),Q=V.add4H(O,U,X,ie[g-7],ie[g-16]);ie[g]=Q|0,ae[g]=O|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:h,Fh:w,Fl:x,Gh:m,Gl:d,Hh:y,Hl:B}=this;for(let g=0;g<80;g++){let E=V.rotrSH(f,h,14)^V.rotrSH(f,h,18)^V.rotrBH(f,h,41),R=V.rotrSL(f,h,14)^V.rotrSL(f,h,18)^V.rotrBL(f,h,41),U=f&w^~f&m,S=h&x^~h&d,I=V.add5L(B,R,S,uu[g],ae[g]),T=V.add5H(I,y,E,U,lu[g],ie[g]),X=I|0,F=V.rotrSH(n,s,28)^V.rotrBH(n,s,34)^V.rotrBH(n,s,39),O=V.rotrSL(n,s,28)^V.rotrBL(n,s,34)^V.rotrBL(n,s,39),Q=n&o^n&a^o&a,A=s&i^s&c^i&c;y=m|0,B=d|0,m=w|0,d=x|0,w=f|0,x=h|0,{h:f,l:h}=V.add(u|0,l|0,T|0,X|0),u=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let N=V.add3L(X,O,A);n=V.add3H(N,T,F,Q),s=N|0}({h:n,l:s}=V.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=V.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=V.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=V.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:h}=V.add(this.Eh|0,this.El|0,f|0,h|0),{h:w,l:x}=V.add(this.Fh|0,this.Fl|0,w|0,x|0),{h:m,l:d}=V.add(this.Gh|0,this.Gl|0,m|0,d|0),{h:y,l:B}=V.add(this.Hh|0,this.Hl|0,y|0,B|0),this.set(n,s,o,i,a,c,u,l,f,h,w,x,m,d,y,B)}roundClean(){ie.fill(0),ae.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 ce=We(()=>new Us);var nn={};ft(nn,{aInRange:()=>wt,abool:()=>Nt,abytes:()=>Ye,bitGet:()=>mu,bitLen:()=>Vs,bitMask:()=>Br,bitSet:()=>yu,bytesToHex:()=>$t,bytesToNumberBE:()=>qt,bytesToNumberLE:()=>ue,concatBytes:()=>jt,createHmacDrbg:()=>Os,ensureBytes:()=>J,equalBytes:()=>pu,hexToBytes:()=>Se,hexToNumber:()=>Hs,inRange:()=>vr,isBytes:()=>le,memoized:()=>Ne,notImplemented:()=>wu,numberToBytesBE:()=>fe,numberToBytesLE:()=>Ie,numberToHexUnpadded:()=>ke,numberToVarBytesBE:()=>du,utf8ToBytes:()=>gu,validateObject:()=>_t});var _s=BigInt(0),rn=BigInt(1),fu=BigInt(2);function le(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ye(r){if(!le(r))throw new Error("Uint8Array expected")}function Nt(r,t){if(typeof t!="boolean")throw new Error(`${r} must be valid boolean, got "${t}".`)}var hu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function $t(r){Ye(r);let t="";for(let e=0;e<r.length;e++)t+=hu[r[e]];return t}function ke(r){let t=r.toString(16);return t.length&1?`0${t}`:t}function Hs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var Ft={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function yi(r){if(r>=Ft._0&&r<=Ft._9)return r-Ft._0;if(r>=Ft._A&&r<=Ft._F)return r-(Ft._A-10);if(r>=Ft._a&&r<=Ft._f)return r-(Ft._a-10)}function Se(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,o=0;s<e;s++,o+=2){let i=yi(r.charCodeAt(o)),a=yi(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function qt(r){return Hs($t(r))}function ue(r){return Ye(r),Hs($t(Uint8Array.from(r).reverse()))}function fe(r,t){return Se(r.toString(16).padStart(t*2,"0"))}function Ie(r,t){return fe(r,t).reverse()}function du(r){return Se(ke(r))}function J(r,t,e){let n;if(typeof t=="string")try{n=Se(t)}catch(o){throw new Error(`${r} must be valid hex string, got "${t}". Cause: ${o}`)}else if(le(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 jt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Ye(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function pu(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 gu(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Rs=r=>typeof r=="bigint"&&_s<=r;function vr(r,t,e){return Rs(r)&&Rs(t)&&Rs(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!vr(t,e,n))throw new Error(`expected valid ${r}: ${e} <= n < ${n}, got ${typeof t} ${t}`)}function Vs(r){let t;for(t=0;r>_s;r>>=rn,t+=1);return t}function mu(r,t){return r>>BigInt(t)&rn}function yu(r,t,e){return r|(e?rn:_s)<<BigInt(t)}var Br=r=>(fu<<BigInt(r-1))-rn,Ls=r=>new Uint8Array(r),bi=r=>Uint8Array.from(r);function Os(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=Ls(r),s=Ls(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...f)=>e(s,n,...f),c=(f=Ls())=>{s=a(bi([0]),f),n=a(),f.length!==0&&(s=a(bi([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<t;){n=a();let w=n.slice();h.push(w),f+=n.length}return jt(...h)};return(f,h)=>{i(),c(f);let w;for(;!(w=h(u()));)c();return i(),w}}var bu={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"||le(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 _t(r,t,e={}){let n=(s,o,i)=>{let a=bu[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(let[s,o]of Object.entries(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var wu=()=>{throw new Error("not implemented")};function Ne(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var et=BigInt(0),G=BigInt(1),Ce=BigInt(2),xu=BigInt(3),Ds=BigInt(4),wi=BigInt(5),xi=BigInt(8),vu=BigInt(9),Bu=BigInt(16);function j(r,t){let e=r%t;return e>=et?e:t+e}function Eu(r,t,e){if(e<=et||t<et)throw new Error("Expected power/modulo > 0");if(e===G)return et;let n=G;for(;t>et;)t&G&&(n=n*r%e),r=r*r%e,t>>=G;return n}function Z(r,t,e){let n=r;for(;t-- >et;)n*=n,n%=e;return n}function sn(r,t){if(r===et||t<=et)throw new Error(`invert: expected positive integers, got n=${r} mod=${t}`);let e=j(r,t),n=t,s=et,o=G,i=G,a=et;for(;e!==et;){let u=n/e,l=n%e,f=s-i*u,h=o-a*u;n=e,e=l,s=i,o=a,i=f,a=h}if(n!==G)throw new Error("invert: does not exist");return j(s,t)}function Au(r){let t=(r-G)/Ce,e,n,s;for(e=r-G,n=0;e%Ce===et;e/=Ce,n++);for(s=Ce;s<r&&Eu(s,t,r)!==r-G;s++);if(n===1){let i=(r+G)/Ds;return function(c,u){let l=c.pow(u,i);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(e+G)/Ce;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,s),e),f=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let w=1;for(let m=a.sqr(h);w<u&&!a.eql(m,a.ONE);w++)m=a.sqr(m);let x=a.pow(l,G<<BigInt(u-w-1));l=a.sqr(x),f=a.mul(f,x),h=a.mul(h,l),u=w}return f}}function ku(r){if(r%Ds===xu){let t=(r+G)/Ds;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%xi===wi){let t=(r-wi)/xi;return function(n,s){let o=n.mul(s,Ce),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Ce),i),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),s))throw new Error("Cannot find square root");return u}}return r%Bu,Au(r)}var vi=(r,t)=>(j(r,t)&G)===G,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ks(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=Su.reduce((n,s)=>(n[s]="function",n),t);return _t(r,e)}function Iu(r,t,e){if(e<et)throw new Error("Expected power > 0");if(e===et)return r.ONE;if(e===G)return t;let n=r.ONE,s=t;for(;e>et;)e&G&&(n=r.mul(n,s)),s=r.sqr(s),e>>=G;return n}function Nu(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function Ms(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function he(r,t,e=!1,n={}){if(r<=et)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:s,nByteLength:o}=Ms(r,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let i=ku(r),a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Br(s),ZERO:et,ONE:G,create:c=>j(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return et<=c&&c<r},is0:c=>c===et,isOdd:c=>(c&G)===G,neg:c=>j(-c,r),eql:(c,u)=>c===u,sqr:c=>j(c*c,r),add:(c,u)=>j(c+u,r),sub:(c,u)=>j(c-u,r),mul:(c,u)=>j(c*u,r),pow:(c,u)=>Iu(a,c,u),div:(c,u)=>j(c*sn(u,r),r),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>sn(c,r),sqrt:n.sqrt||(c=>i(a,c)),invertBatch:c=>Nu(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>e?Ie(c,o):fe(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return e?ue(c):qt(c)}});return Object.freeze(a)}function Bi(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 Ps(r){let t=Bi(r);return t+Math.ceil(t/2)}function Ei(r,t,e=!1){let n=r.length,s=Bi(t),o=Ps(t);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let i=e?qt(r):ue(r),a=j(i,t-G)+G;return e?Ie(a,s):fe(a,s)}var Tu=BigInt(0),Fs=BigInt(1),$s=new WeakMap,Ai=new WeakMap;function on(r,t){let e=(o,i)=>{let a=i.negate();return o?a:i},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>t)throw new Error(`Wrong window size=${o}, should be [1..${t}]`)},s=o=>{n(o);let i=Math.ceil(t/o)+1,a=2**(o-1);return{windows:i,windowSize:a}};return{constTimeNegate:e,unsafeLadder(o,i){let a=r.ZERO,c=o;for(;i>Tu;)i&Fs&&(a=a.add(c)),c=c.double(),i>>=Fs;return a},precomputeWindow(o,i){let{windows:a,windowSize:c}=s(i),u=[],l=o,f=l;for(let h=0;h<a;h++){f=l,u.push(f);for(let w=1;w<c;w++)f=f.add(l),u.push(f);l=f.double()}return u},wNAF(o,i,a){let{windows:c,windowSize:u}=s(o),l=r.ZERO,f=r.BASE,h=BigInt(2**o-1),w=2**o,x=BigInt(o);for(let m=0;m<c;m++){let d=m*u,y=Number(a&h);a>>=x,y>u&&(y-=w,a+=Fs);let B=d,g=d+Math.abs(y)-1,E=m%2!==0,R=y<0;y===0?f=f.add(e(E,i[B])):l=l.add(e(R,i[g]))}return{p:l,f}},wNAFCached(o,i,a){let c=Ai.get(o)||1,u=$s.get(o);return u||(u=this.precomputeWindow(o,c),c!==1&&$s.set(o,a(u))),this.wNAF(c,u,i)},setWindowSize(o,i){n(i),Ai.set(o,i),$s.delete(o)}}}function an(r,t,e,n){if(!Array.isArray(e)||!Array.isArray(n)||n.length!==e.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((l,f)=>{if(!t.isValid(l))throw new Error(`wrong scalar at index ${f}`)}),e.forEach((l,f)=>{if(!(l instanceof r))throw new Error(`wrong point at index ${f}`)});let s=Vs(BigInt(e.length)),o=s>12?s-3:s>4?s-2:s?2:1,i=(1<<o)-1,a=new Array(i+1).fill(r.ZERO),c=Math.floor((t.BITS-1)/o)*o,u=r.ZERO;for(let l=c;l>=0;l-=o){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let w=n[h],x=Number(w>>BigInt(l)&BigInt(i));a[x]=a[x].add(e[h])}let f=r.ZERO;for(let h=a.length-1,w=r.ZERO;h>0;h--)w=w.add(a[h]),f=f.add(w);if(u=u.add(f),l!==0)for(let h=0;h<o;h++)u=u.double()}return u}function Er(r){return Ks(r.Fp),_t(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ms(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ct=BigInt(0),xt=BigInt(1),cn=BigInt(2),Uu=BigInt(8),Ru={zip215:!0};function Lu(r){let t=Er(r);return _t(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ki(r){let t=Lu(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,u=cn<<BigInt(a*8)-xt,l=e.create,f=he(t.n,t.nBitLength),h=t.uvRatio||((b,p)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(p))}}catch{return{isValid:!1,value:Ct}}}),w=t.adjustScalarBytes||(b=>b),x=t.domain||((b,p,v)=>{if(Nt("phflag",v),p.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function m(b,p){wt("coordinate "+b,p,Ct,u)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let y=Ne((b,p)=>{let{ex:v,ey:C,ez:L}=b,H=b.is0();p==null&&(p=H?Uu:e.inv(L));let D=l(v*p),P=l(C*p),K=l(L*p);if(H)return{x:Ct,y:xt};if(K!==xt)throw new Error("invZ was invalid");return{x:D,y:P}}),B=Ne(b=>{let{a:p,d:v}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:C,ey:L,ez:H,et:D}=b,P=l(C*C),K=l(L*L),q=l(H*H),z=l(q*q),nt=l(P*p),st=l(q*l(nt+K)),ct=l(z+l(v*l(P*K)));if(st!==ct)throw new Error("bad point: equation left != right (1)");let pt=l(C*L),tt=l(H*D);if(pt!==tt)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(p,v,C,L){this.ex=p,this.ey=v,this.ez=C,this.et=L,m("x",p),m("y",v),m("z",C),m("t",L),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof g)throw new Error("extended point not allowed");let{x:v,y:C}=p||{};return m("x",v),m("y",C),new g(v,C,xt,l(v*C))}static normalizeZ(p){let v=e.invertBatch(p.map(C=>C.ez));return p.map((C,L)=>C.toAffine(v[L])).map(g.fromAffine)}static msm(p,v){return an(g,f,p,v)}_setWindowSize(p){U.setWindowSize(this,p)}assertValidity(){B(this)}equals(p){d(p);let{ex:v,ey:C,ez:L}=this,{ex:H,ey:D,ez:P}=p,K=l(v*P),q=l(H*L),z=l(C*P),nt=l(D*L);return K===q&&z===nt}is0(){return this.equals(g.ZERO)}negate(){return new g(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:p}=t,{ex:v,ey:C,ez:L}=this,H=l(v*v),D=l(C*C),P=l(cn*l(L*L)),K=l(p*H),q=v+C,z=l(l(q*q)-H-D),nt=K+D,st=nt-P,ct=K-D,pt=l(z*st),tt=l(nt*ct),yt=l(z*ct),Kt=l(st*nt);return new g(pt,tt,Kt,yt)}add(p){d(p);let{a:v,d:C}=t,{ex:L,ey:H,ez:D,et:P}=this,{ex:K,ey:q,ez:z,et:nt}=p;if(v===BigInt(-1)){let Mo=l((H-L)*(q+K)),Po=l((H+L)*(q-K)),ys=l(Po-Mo);if(ys===Ct)return this.double();let Fo=l(D*cn*nt),$o=l(P*cn*z),qo=$o+Fo,jo=Po+Mo,zo=$o-Fo,Pc=l(qo*ys),Fc=l(jo*zo),$c=l(qo*zo),qc=l(ys*jo);return new g(Pc,Fc,qc,$c)}let st=l(L*K),ct=l(H*q),pt=l(P*C*nt),tt=l(D*z),yt=l((L+H)*(K+q)-st-ct),Kt=tt-pt,ur=tt+pt,fr=l(ct-v*st),Oc=l(yt*Kt),Dc=l(ur*fr),Kc=l(yt*fr),Mc=l(Kt*ur);return new g(Oc,Dc,Mc,Kc)}subtract(p){return this.add(p.negate())}wNAF(p){return U.wNAFCached(this,p,g.normalizeZ)}multiply(p){let v=p;wt("scalar",v,xt,n);let{p:C,f:L}=this.wNAF(v);return g.normalizeZ([C,L])[0]}multiplyUnsafe(p){let v=p;return wt("scalar",v,Ct,n),v===Ct?R:this.equals(R)||v===xt?this:this.equals(E)?this.wNAF(v).p:U.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(p){return y(this,p)}clearCofactor(){let{h:p}=t;return p===xt?this:this.multiplyUnsafe(p)}static fromHex(p,v=!1){let{d:C,a:L}=t,H=e.BYTES;p=J("pointHex",p,H),Nt("zip215",v);let D=p.slice(),P=p[H-1];D[H-1]=P&-129;let K=ue(D),q=v?u:e.ORDER;wt("pointHex.y",K,Ct,q);let z=l(K*K),nt=l(z-xt),st=l(C*z-L),{isValid:ct,value:pt}=h(nt,st);if(!ct)throw new Error("Point.fromHex: invalid y coordinate");let tt=(pt&xt)===xt,yt=(P&128)!==0;if(!v&&pt===Ct&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==tt&&(pt=l(-pt)),g.fromAffine({x:pt,y:K})}static fromPrivateKey(p){return T(p).point}toRawBytes(){let{x:p,y:v}=this.toAffine(),C=Ie(v,e.BYTES);return C[C.length-1]|=p&xt?128:0,C}toHex(){return $t(this.toRawBytes())}}g.BASE=new g(t.Gx,t.Gy,xt,l(t.Gx*t.Gy)),g.ZERO=new g(Ct,xt,xt,Ct);let{BASE:E,ZERO:R}=g,U=on(g,a*8);function S(b){return j(b,n)}function I(b){return S(ue(b))}function T(b){let p=a;b=J("private key",b,p);let v=J("hashed private key",o(b),2*p),C=w(v.slice(0,p)),L=v.slice(p,2*p),H=I(C),D=E.multiply(H),P=D.toRawBytes();return{head:C,prefix:L,scalar:H,point:D,pointBytes:P}}function X(b){return T(b).pointBytes}function F(b=new Uint8Array,...p){let v=jt(...p);return I(o(x(v,J("context",b),!!s)))}function O(b,p,v={}){b=J("message",b),s&&(b=s(b));let{prefix:C,scalar:L,pointBytes:H}=T(p),D=F(v.context,C,b),P=E.multiply(D).toRawBytes(),K=F(v.context,P,H,b),q=S(D+K*L);wt("signature.s",q,Ct,n);let z=jt(P,Ie(q,e.BYTES));return J("result",z,a*2)}let Q=Ru;function A(b,p,v,C=Q){let{context:L,zip215:H}=C,D=e.BYTES;b=J("signature",b,2*D),p=J("message",p),H!==void 0&&Nt("zip215",H),s&&(p=s(p));let P=ue(b.slice(D,2*D)),K,q,z;try{K=g.fromHex(v,H),q=g.fromHex(b.slice(0,D),H),z=E.multiplyUnsafe(P)}catch{return!1}if(!H&&K.isSmallOrder())return!1;let nt=F(L,q.toRawBytes(),K.toRawBytes(),p);return q.add(K.multiplyUnsafe(nt)).subtract(z).clearCofactor().equals(g.ZERO)}return E._setWindowSize(8),{CURVE:t,getPublicKey:X,sign:O,verify:A,ExtendedPoint:g,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,p=g.BASE){return p._setWindowSize(b),p.multiply(BigInt(3)),p}}}}var qs=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Si=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),$d=BigInt(0),_u=BigInt(1),Ii=BigInt(2),qd=BigInt(3),Hu=BigInt(5),Vu=BigInt(8);function Ou(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=qs,a=r*r%o*r%o,c=Z(a,Ii,o)*a%o,u=Z(c,_u,o)*r%o,l=Z(u,Hu,o)*u%o,f=Z(l,t,o)*l%o,h=Z(f,e,o)*f%o,w=Z(h,n,o)*h%o,x=Z(w,s,o)*w%o,m=Z(x,s,o)*w%o,d=Z(m,t,o)*l%o;return{pow_p_5_8:Z(d,Ii,o)*r%o,b2:a}}function Du(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ku(r,t){let e=qs,n=j(t*t*t,e),s=j(n*n*t,e),o=Ou(r*s).pow_p_5_8,i=j(r*n*o,e),a=j(t*i*i,e),c=i,u=j(i*Si,e),l=a===r,f=a===j(-r,e),h=a===j(-r*Si,e);return l&&(i=c),(f||h)&&(i=u),vi(i,e)&&(i=j(-i,e)),{isValid:l||f,value:i}}var Mu=he(qs,void 0,!0),Pu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Mu,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Vu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ce,randomBytes:Je,adjustScalarBytes:Du,uvRatio:Ku},js=ki(Pu);var Ar=32,zt=64,Fu=32;function Ni(r,t){let e=r.subarray(0,Fu);return js.sign(t instanceof Uint8Array?t:t.subarray(),e)}function Ci(r,t,e){return js.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var ln=class{type="Ed25519";raw;constructor(t){this.raw=Sr(t,Ar)}toMultihash(){return xr.digest(un(this))}toCID(){return Lt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}verify(t,e){return Ci(this.raw,e,t)}},kr=class{type="Ed25519";raw;publicKey;constructor(t,e){this.raw=Sr(t,zt),this.publicKey=new ln(e)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}sign(t){return Ni(this.raw,t)}};function zs(r){if(r.length>zt){r=Sr(r,zt+Ar);let n=r.subarray(0,zt),s=r.subarray(zt,r.length);return new kr(n,s)}r=Sr(r,zt);let t=r.subarray(0,zt),e=r.subarray(Ar);return new kr(t,e)}function Sr(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Ht(r=0){return new Uint8Array(r)}var $u=Math.pow(2,7),qu=Math.pow(2,14),ju=Math.pow(2,21),Ui=Math.pow(2,28),Ri=Math.pow(2,35),Li=Math.pow(2,42),_i=Math.pow(2,49),gt=128,de=127;function Ir(r){if(r<$u)return 1;if(r<qu)return 2;if(r<ju)return 3;if(r<Ui)return 4;if(r<Ri)return 5;if(r<Li)return 6;if(r<_i)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Hi(r,t,e=0){switch(Ir(r)){case 8:t[e++]=r&255|gt,r/=128;case 7:t[e++]=r&255|gt,r/=128;case 6:t[e++]=r&255|gt,r/=128;case 5:t[e++]=r&255|gt,r/=128;case 4:t[e++]=r&255|gt,r>>>=7;case 3:t[e++]=r&255|gt,r>>>=7;case 2:t[e++]=r&255|gt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Vi(r,t){let e=r[t],n=0;if(n+=e&de,e<gt||(e=r[t+1],n+=(e&de)<<7,e<gt)||(e=r[t+2],n+=(e&de)<<14,e<gt)||(e=r[t+3],n+=(e&de)<<21,e<gt)||(e=r[t+4],n+=(e&de)*Ui,e<gt)||(e=r[t+5],n+=(e&de)*Ri,e<gt)||(e=r[t+6],n+=(e&de)*Li,e<gt)||(e=r[t+7],n+=(e&de)*_i,e<gt))return n;throw new RangeError("Could not decode varint")}var Gs=new Float32Array([-0]),pe=new Uint8Array(Gs.buffer);function Oi(r,t,e){Gs[0]=r,t[e]=pe[0],t[e+1]=pe[1],t[e+2]=pe[2],t[e+3]=pe[3]}function Di(r,t){return pe[0]=r[t],pe[1]=r[t+1],pe[2]=r[t+2],pe[3]=r[t+3],Gs[0]}var Zs=new Float64Array([-0]),ht=new Uint8Array(Zs.buffer);function Ki(r,t,e){Zs[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function Mi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],Zs[0]}var zu=BigInt(Number.MAX_SAFE_INTEGER),Gu=BigInt(Number.MIN_SAFE_INTEGER),Et=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 Te;if(t<zu&&t>Gu)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>Pi&&(s=0n,++n>Pi&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return Te;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):Te}},Te=new Et(0,0);Te.toBigInt=function(){return 0n};Te.zzEncode=Te.zzDecode=function(){return this};Te.length=function(){return 1};var Pi=4294967296n;function Fi(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 $i(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function Ws(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,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 fn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Js=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 fn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return fn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Di(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=Mi(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 $i(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 Et(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=fn(this.buf,this.pos+=4),e=fn(this.buf,this.pos+=4);return new Et(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=Vi(this.buf,this.pos);return this.pos+=Ir(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ys(r){return new Js(r instanceof Uint8Array?r:r.subarray())}function hn(r,t,e){let n=Ys(r);return t.decode(n,void 0,e)}var Xs={};ft(Xs,{base10:()=>Zu});var Zu=ne({prefix:"9",name:"base10",alphabet:"0123456789"});var Qs={};ft(Qs,{base16:()=>Wu,base16upper:()=>Ju});var Wu=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ju=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var to={};ft(to,{base2:()=>Yu});var Yu=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};ft(eo,{base256emoji:()=>rf});var ji=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}"),Xu=ji.reduce((r,t,e)=>(r[e]=t,r),[]),Qu=ji.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function tf(r){return r.reduce((t,e)=>(t+=Xu[e],t),"")}function ef(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=Qu[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var rf=Me({prefix:"\u{1F680}",name:"base256emoji",encode:tf,decode:ef});var ro={};ft(ro,{base64:()=>Ue,base64pad:()=>nf,base64url:()=>sf,base64urlpad:()=>of});var Ue=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nf=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sf=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),of=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};ft(no,{base8:()=>af});var af=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};ft(so,{identity:()=>cf});var cf=Me({prefix:"\0",name:"identity",encode:r=>Xo(r),decode:r=>Yo(r)});var k0=new TextEncoder,S0=new TextDecoder;var ao={};ft(ao,{sha256:()=>Xe,sha512:()=>ff});function io({name:r,code:t,encode:e}){return new oo(r,t,e)}var oo=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?St(this.code,e):e.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Gi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Xe=io({name:"sha2-256",code:18,encode:Gi("SHA-256")}),ff=io({name:"sha2-512",code:19,encode:Gi("SHA-512")});var co={...so,...to,...no,...Xs,...Qs,...As,...ks,...Es,...ro,...eo},D0={...ao,...Ns};function Wi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Zi=Wi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),lo=Wi("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=Ht(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),hf={utf8:Zi,"utf-8":Zi,hex:co.base16,latin1:lo,ascii:lo,binary:lo,...co},dn=hf;function $(r,t="utf8"){let e=dn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function uo(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Ht(i);s+i>t&&(n=Ht(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Re=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function fo(){}var po=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},df=uo();function pf(r){return globalThis.Buffer!=null?Ht(r):df(r)}var Cr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Re(fo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Re(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((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,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(pn,e.length(),e)}uint64Number(t){return this._push(Hi,Ir(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(pn,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(pn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ho,1,t?1:0)}fixed32(t){return this._push(Nr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Nr,4,e.lo)._push(Nr,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Nr,4,e.lo)._push(Nr,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(Oi,4,t)}double(t){return this._push(Ki,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ho,1,0):this.uint32(e)._push(mf,e,t)}string(t){let e=Fi(t);return e!==0?this.uint32(e)._push(Ws,e,t):this._push(ho,1,0)}fork(){return this.states=new po(this),this.head=this.tail=new Re(fo,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 Re(fo,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=pf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ho(r,t,e){t[e]=r&255}function gf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var go=class extends Re{next;constructor(t,e){super(gf,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 Nr(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 mf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Cr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(yf,t,r),this},Cr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(bf,t,r),this});function yf(r,t,e){t.set(r,e)}function bf(r,t,e){r.length<40?Ws(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function mo(){return new Cr}function gn(r,t){let e=mo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Qe;(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"})(Qe||(Qe={}));function mn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function yo(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return mn("enum",Qe.VARINT,e,n)}function yn(r,t){return mn("message",Qe.LENGTH_DELIMITED,r,t)}var it;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(it||(it={}));var bo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(bo||(bo={}));(function(r){r.codec=()=>yo(bo)})(it||(it={}));var ge;(function(r){let t;r.codec=()=>(t==null&&(t=yn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),it.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=it.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>gn(e,r.codec()),r.decode=(e,n)=>hn(e,r.codec(),n)})(ge||(ge={}));var Tr;(function(r){let t;r.codec=()=>(t==null&&(t=yn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),it.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=it.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>gn(e,r.codec()),r.decode=(e,n)=>hn(e,r.codec(),n)})(Tr||(Tr={}));var Kr={};ft(Kr,{MAX_RSA_KEY_SIZE:()=>is,generateRSAKeyPair:()=>ja,jwkToJWKKeyPair:()=>za,jwkToPkcs1:()=>Lf,jwkToPkix:()=>Io,jwkToRSAPrivateKey:()=>qa,pkcs1ToJwk:()=>Pa,pkcs1ToRSAPrivateKey:()=>as,pkixToJwk:()=>Fa,pkixToRSAPublicKey:()=>$a});var wf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),me=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ye=new Uint32Array(64),wo=class extends oe{constructor(){super(64,32,8,!1),this.A=me[0]|0,this.B=me[1]|0,this.C=me[2]|0,this.D=me[3]|0,this.E=me[4]|0,this.F=me[5]|0,this.G=me[6]|0,this.H=me[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)ye[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let h=ye[f-15],w=ye[f-2],x=It(h,7)^It(h,18)^h>>>3,m=It(w,17)^It(w,19)^w>>>10;ye[f]=m+ye[f-7]+x+ye[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let h=It(a,6)^It(a,11)^It(a,25),w=l+h+Qr(a,c,u)+wf[f]+ye[f]|0,m=(It(n,2)^It(n,13)^It(n,22))+tn(n,s,o)|0;l=u,u=c,c=a,a=i+w|0,i=o,o=s,s=n,n=w+m|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,s,o,i,a,c,u,l)}roundClean(){ye.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var be=We(()=>new wo);var M=bs(Yi());function Le(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,o=0,i=Math.pow(2,t);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*t);u[o-l-1]=Math.floor(s/f),s-=u[o-l-1]*f}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function xn(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function vo(){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=Le(e,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Le(o,8)-n}function Xi(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let i=e-t,a=we(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=we(t,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function Qi(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 vt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(e)}var wp=Math.log(2);function vn(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Bo(r){let t=0,e=0;for(let s=0;s<r.length;s++){let o=r[s];t+=o.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),e),e+=o.byteLength}return n.buffer}function Xt(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 Rr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Bo(this.items)}},Ur=[new Uint8Array([1])],ta="0123456789";var rr="",Ut=new ArrayBuffer(0),Eo=new Uint8Array(0),Lr="EndOfContent",ra="OCTET STRING",na="BIT STRING";function Qt(r){var t;return t=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?M.BufferSourceConverter.toUint8Array(o.valueHex):Eo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Xt(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,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",Ut)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:M.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var Zt=class{constructor({blockLength:t=0,error:e=rr,warnings:n=[],valueBeforeDecode:s=Eo}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=M.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:M.Convert.ToHex(this.valueBeforeDecodeView)}}};Zt.NAME="baseBlock";var dt=class extends Zt{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'")}};dt.NAME="valueBlock";var Bn=class extends Qt(Zt){constructor({idBlock:t={}}={}){var e,n,s,o;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?M.BufferSourceConverter.toUint8Array(t.valueHex):Eo,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!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",Ut}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=we(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=e|31,!t){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=e|31,!t){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!Xt(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let h=new Uint8Array(l);for(let w=0;w<u.length;w++)h[w]=u[w];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=u[h];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=Le(u,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}}};Bn.NAME="identificationBlock";var En=class extends Zt{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=M.BufferSourceConverter.toUint8Array(t);if(!Xt(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,e+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,e+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Le(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+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",Ut;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];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}}};En.NAME="lengthBlock";var k={},lt=class extends Zt{constructor({name:t=rr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Bn(s),this.lenBlock=new En(s),this.valueBlock=o?new o(s):new dt(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 Rr;e||sa(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 o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Ut: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():M.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${M.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 Qi(e,n)}};lt.NAME="BaseBlock";function sa(r){if(r instanceof k.Constructed)for(let t of r.valueBlock.value)sa(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var An=class extends lt{constructor({value:t=rr,...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}'`}};An.NAME="BaseStringBlock";var kn=class extends Qt(dt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};kn.NAME="PrimitiveValueBlock";var oa,Sn=class extends lt{constructor(t={}){super(t,kn),this.idBlock.isConstructed=!1}};oa=Sn;k.Primitive=oa;Sn.NAME="PRIMITIVE";function Nf(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 os(r,t=0,e=r.length){let n=t,s=new lt({},dt),o=new Zt;if(!Xt(o,r,t,e))return s.error=o.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=lt;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 u=s.idBlock.isConstructed?new k.Constructed:new k.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?k.Constructed:k.Primitive}return s=Nf(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 _e(r){if(!r.byteLength){let t=new lt({},dt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return os(M.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function Cf(r,t){return r?1:t}var Vt=class extends dt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);if(!Xt(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 o=e;for(;Cf(this.isIndefiniteForm,n)>0;){let i=os(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===Lr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Lr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new Rr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Ut:n.final()}toJSON(){let t={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let e of this.value)t.value.push(e.toJSON());return t}};Vt.NAME="ConstructedValueBlock";var ia,xe=class extends lt{constructor(t={}){super(t,Vt),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 Sl=Object.create;var nn=Object.defineProperty;var kl=Object.getOwnPropertyDescriptor;var Il=Object.getOwnPropertyNames;var Cl=Object.getPrototypeOf,Nl=Object.prototype.hasOwnProperty;var Ie=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)nn(r,e,{get:t[e],enumerable:!0})},mi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Il(t))!Nl.call(r,s)&&s!==e&&nn(r,s,{get:()=>t[s],enumerable:!(n=kl(t,s))||n.enumerable});return r};var _s=(r,t,e)=>(e=r!=null?Sl(Cl(r)):{},mi(t||!r||!r.__esModule?nn(e,"default",{value:r,enumerable:!0}):e,r)),Tl=r=>mi(nn({},"__esModule",{value:!0}),r);var Na=Ie(lr=>{"use strict";var nh="[object ArrayBuffer]",Jt=class r{static isArrayBuffer(t){return Object.prototype.toString.call(t)===nh}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 o=0;o<n.length;o++)if(n[o]!==s[o])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 i of e)n+=i.byteLength;let s=new Uint8Array(n),o=0;for(let i of e){let a=this.toUint8Array(i);s.set(a,o),o+=a.length}return t[t.length-1]instanceof Function?this.toView(s,t[t.length-1]):s.buffer}},Do="string",sh=/^[0-9a-f\s]+$/i,oh=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ih=/^[a-zA-Z0-9-_]+$/,Rn=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=Jt.toUint8Array(t),n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return decodeURIComponent(escape(n))}},St=class{static toString(t,e=!1){let n=Jt.toArrayBuffer(t),s=new DataView(n),o="";for(let i=0;i<n.byteLength;i+=2){let a=s.getUint16(i,e);o+=String.fromCharCode(a)}return o}static fromString(t,e=!1){let n=new ArrayBuffer(t.length*2),s=new DataView(n);for(let o=0;o<t.length;o++)s.setUint16(o*2,t.charCodeAt(o),e);return n}},Hn=class r{static isHex(t){return typeof t===Do&&sh.test(t)}static isBase64(t){return typeof t===Do&&oh.test(t)}static isBase64Url(t){return typeof t===Do&&ih.test(t)}static ToString(t,e="utf8"){let n=Jt.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 St.toString(n,!0);case"utf16":case"utf16be":return St.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 St.fromString(t,!0);case"utf16":case"utf16be":return St.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){let e=Jt.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 Rn.fromString(t);case"utf16":case"utf16be":return St.fromString(t);case"utf16le":case"usc2":return St.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 Rn.toString(t);case"utf16":case"utf16be":return St.toString(t);case"utf16le":case"usc2":return St.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=Jt.toUint8Array(t),n="";for(let s=0;s<e.length;s++)n+=String.fromCharCode(e[s]);return n}static ToHex(t){let e=Jt.toUint8Array(t),n="",s=e.length;for(let o=0;o<s;o++){let i=e[o];i<16&&(n+="0"),n+=i.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 o=e.slice(s,s+2);n[s/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(t,e=!1){return St.toString(t,e)}static FromUtf16String(t,e=!1){return St.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,"")||""}};Hn.DEFAULT_UTF8_ENCODING="utf8";function ah(r,...t){let e=arguments[0];for(let n=1;n<arguments.length;n++){let s=arguments[n];for(let o in s)e[o]=s[o]}return e}function ch(...r){let t=r.map(s=>s.byteLength).reduce((s,o)=>s+o),e=new Uint8Array(t),n=0;return r.map(s=>new Uint8Array(s)).forEach(s=>{for(let o of s)e[n++]=o}),e.buffer}function lh(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}lr.BufferSourceConverter=Jt;lr.Convert=Hn;lr.assign=ah;lr.combine=ch;lr.isEqual=lh});var Zc=Ie((_x,Wc)=>{"use strict";Wc.exports=r=>{if(Object.prototype.toString.call(r)!=="[object Object]")return!1;let t=Object.getPrototypeOf(r);return t===null||t===Object.prototype}});var el=Ie((Qc,tl)=>{"use strict";var Ts=Zc(),{hasOwnProperty:Yc}=Object.prototype,{propertyIsEnumerable:Qh}=Object,gr=(r,t,e)=>Object.defineProperty(r,t,{value:e,writable:!0,enumerable:!0,configurable:!0}),t0=Qc,Jc={concatArrays:!1,ignoreUndefined:!1},Us=r=>{let t=[];for(let e in r)Yc.call(r,e)&&t.push(e);if(Object.getOwnPropertySymbols){let e=Object.getOwnPropertySymbols(r);for(let n of e)Qh.call(r,n)&&t.push(n)}return t};function mr(r){return Array.isArray(r)?e0(r):Ts(r)?r0(r):r}function e0(r){let t=r.slice(0,0);return Us(r).forEach(e=>{gr(t,e,mr(r[e]))}),t}function r0(r){let t=Object.getPrototypeOf(r)===null?Object.create(null):{};return Us(r).forEach(e=>{gr(t,e,mr(r[e]))}),t}var Xc=(r,t,e,n)=>(e.forEach(s=>{typeof t[s]>"u"&&n.ignoreUndefined||(s in r&&r[s]!==Object.getPrototypeOf(r)?gr(r,s,ni(r[s],t[s],n)):gr(r,s,mr(t[s])))}),r),n0=(r,t,e)=>{let n=r.slice(0,0),s=0;return[r,t].forEach(o=>{let i=[];for(let a=0;a<o.length;a++)Yc.call(o,a)&&(i.push(String(a)),o===r?gr(n,s++,o[a]):gr(n,s++,mr(o[a])));n=Xc(n,o,Us(o).filter(a=>!i.includes(a)),e)}),n};function ni(r,t,e){return e.concatArrays&&Array.isArray(r)&&Array.isArray(t)?n0(r,t,e):!Ts(t)||!Ts(r)?mr(t):Xc(r,t,Us(t),e)}tl.exports=function(...r){let t=ni(mr(Jc),this!==t0&&this||{},Jc),e={_:{}};for(let n of r)if(n!==void 0){if(!Ts(n))throw new TypeError("`"+n+"` is not an Option Object");e=ni(e,{_:n},t)}return e._}});var ol=Ie((Vx,sl)=>{"use strict";function s0(r){return r>=55296&&r<=56319}function o0(r){return r>=56320&&r<=57343}sl.exports=function(t,e,n){if(typeof e!="string")throw new Error("Input must be string");for(var s=e.length,o=0,i,a,c=0;c<s;c+=1){if(i=e.charCodeAt(c),a=e[c],s0(i)&&o0(e.charCodeAt(c+1))&&(c+=1,a+=e[c]),o+=t(a),o===n)return e.slice(0,c+1);if(o>n)return e.slice(0,c-a.length+1)}return e}});var al=Ie((Dx,il)=>{"use strict";function i0(r){return r>=55296&&r<=56319}function a0(r){return r>=56320&&r<=57343}il.exports=function(t){if(typeof t!="string")throw new Error("Input must be string");for(var e=t.length,n=0,s=null,o=null,i=0;i<e;i++)s=t.charCodeAt(i),a0(s)?o!=null&&i0(o)?n+=1:n+=3:s<=127?n+=1:s>=128&&s<=2047?n+=2:s>=2048&&s<=65535&&(n+=3),o=s;return n}});var ll=Ie((Kx,cl)=>{"use strict";var c0=ol(),l0=al();cl.exports=c0.bind(null,l0)});var hl=Ie((Mx,fl)=>{"use strict";var u0=ll(),f0=/[\/\?<>\\:\*\|"]/g,h0=/[\x00-\x1f\x80-\x9f]/g,d0=/^\.+$/,p0=/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i,g0=/[\. ]+$/;function ul(r,t){if(typeof r!="string")throw new Error("Input must be string");var e=r.replace(f0,t).replace(h0,t).replace(d0,t).replace(p0,t).replace(g0,t);return u0(e,255)}fl.exports=function(r,t){var e=t&&t.replacement||"",n=ul(r,e);return e===""?n:ul(n,"")}});var I0={};ht(I0,{keychain:()=>k0});var vr=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},sn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var xi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new sn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var bt=xi;var _=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Er=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var on=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yi=Symbol.for("@libp2p/service-capabilities"),_0=Symbol.for("@libp2p/service-dependencies");var Ms={};ht(Ms,{base58btc:()=>ot,base58flickr:()=>Ol});var od=new Uint8Array(0);function bi(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 qt(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 wi(r){return new TextEncoder().encode(r)}function vi(r){return new TextDecoder().decode(r)}function Ul(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 o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var m=0,d=0,b=0,B=x.length;b!==B&&x[b]===0;)b++,m++;for(var p=(B-b)*u+1>>>0,E=new Uint8Array(p);b!==B;){for(var U=x[b],L=0,C=p-1;(U!==0||L<d)&&C!==-1;C--,L++)U+=256*E[C]>>>0,E[C]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");d=L,b++}for(var k=p-d;k!==p&&E[k]===0;)k++;for(var A=c.repeat(m);k<p;++k)A+=r.charAt(E[k]);return A}function h(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var m=0;if(x[m]!==" "){for(var d=0,b=0;x[m]===c;)d++,m++;for(var B=(x.length-m)*f+1>>>0,p=new Uint8Array(B);x[m];){var E=e[x.charCodeAt(m)];if(E===255)return;for(var U=0,L=B-1;(E!==0||U<b)&&L!==-1;L--,U++)E+=a*p[L]>>>0,p[L]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");b=U,m++}if(x[m]!==" "){for(var C=B-b;C!==B&&p[C]===0;)C++;for(var k=new Uint8Array(d+(B-C)),A=d;C!==B;)k[A++]=p[C++];return k}}}function g(x){var m=h(x);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:g}}var Ll=Ul,Rl=Ll,Ei=Rl;var Os=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")}},Vs=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Ai(this,t)}},Ds=class{decoders;constructor(t){this.decoders=t}or(t){return Ai(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 Ai(r,t){return new Ds({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Ks=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 Os(t,e,n),this.decoder=new Vs(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $e({name:r,prefix:t,encode:e,decode:n}){return new Ks(r,t,e,n)}function ie({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=Ei(e,r);return $e({prefix:t,name:r,encode:n,decode:o=>qt(s(o))})}function Hl(r,t,e,n){let s={};for(let u=0;u<t.length;++u)s[t[u]]=u;let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*e/8|0),a=0,c=0,f=0;for(let u=0;u<o;++u){let l=s[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,i[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function _l(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;o.length*e&7;)o+="=";return o}function Q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return $e({prefix:t,name:r,encode(s){return _l(s,n,e)},decode(s){return Hl(s,n,e,r)}})}var ot=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ol=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fs={};ht(Fs,{base32:()=>ze,base32hex:()=>Ml,base32hexpad:()=>Pl,base32hexpadupper:()=>ql,base32hexupper:()=>Fl,base32pad:()=>Dl,base32padupper:()=>Kl,base32upper:()=>Vl,base32z:()=>jl});var ze=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vl=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Dl=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kl=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ml=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fl=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pl=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ql=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jl=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ps={};ht(Ps,{base36:()=>Ar,base36upper:()=>Gl});var Ar=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gl=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $l=Ii,Si=128,zl=127,Wl=~zl,Zl=Math.pow(2,31);function Ii(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Zl;)t[e++]=r&255|Si,r/=128;for(;r&Wl;)t[e++]=r&255|Si,r>>>=7;return t[e]=r|0,Ii.bytes=e-n+1,t}var Jl=qs,Yl=128,ki=127;function qs(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw qs.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&ki)<<s:(i&ki)*Math.pow(2,s),s+=7}while(i>=Yl);return qs.bytes=o-n,e}var Xl=Math.pow(2,7),Ql=Math.pow(2,14),tu=Math.pow(2,21),eu=Math.pow(2,28),ru=Math.pow(2,35),nu=Math.pow(2,42),su=Math.pow(2,49),ou=Math.pow(2,56),iu=Math.pow(2,63),au=function(r){return r<Xl?1:r<Ql?2:r<tu?3:r<eu?4:r<ru?5:r<nu?6:r<su?7:r<ou?8:r<iu?9:10},cu={encode:$l,decode:Jl,encodingLength:au},lu=cu,Sr=lu;function kr(r,t=0){return[Sr.decode(r,t),Sr.decode.bytes]}function We(r,t,e=0){return Sr.encode(r,t,e),t}function Ze(r){return Sr.encodingLength(r)}function It(r,t){let e=t.byteLength,n=Ze(r),s=n+Ze(e),o=new Uint8Array(s+e);return We(r,o,0),We(e,o,n),o.set(t,s),new Je(r,e,t,o)}function Ci(r){let t=qt(r),[e,n]=kr(t),[s,o]=kr(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Je(e,s,i,t)}function Ni(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&bi(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}};function Ti(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return fu(e,js(r),t??ot.encoder);default:return hu(e,js(r),t??ze.encoder)}}var Ui=new WeakMap;function js(r){let t=Ui.get(r);if(t==null){let e=new Map;return Ui.set(r,e),e}return t}var Ot=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!==Cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==du)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=It(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&&Ni(t.multihash,n.multihash)}toString(t){return Ti(this,t)}toJSON(){return{"/":Ti(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:o,bytes:i}=e;return new r(n,s,o,i??Li(n,s,o.bytes))}else if(e[pu]===!0){let{version:n,multihash:s,code:o}=e,i=Ci(s);return r.create(n,o,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Cr)throw new Error(`Version 0 CID must use dag-pb (code: ${Cr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=Li(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Cr,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=qt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new Je(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,h]=kr(t.subarray(e));return e+=h,l},s=n(),o=Cr;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,s]=uu(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return js(o).set(n,t),o}};function uu(r,t){switch(r[0]){case"Q":{let e=t??ot;return[ot.prefix,e.decode(`${ot.prefix}${r}`)]}case ot.prefix:{let e=t??ot;return[ot.prefix,e.decode(r)]}case ze.prefix:{let e=t??ze;return[ze.prefix,e.decode(r)]}case Ar.prefix:{let e=t??Ar;return[Ar.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function fu(r,t,e){let{prefix:n}=e;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function hu(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Cr=112,du=18;function Li(r,t,e){let n=Ze(r),s=n+Ze(t),o=new Uint8Array(s+e.byteLength);return We(r,o,0),We(t,o,n),o.set(e,s),o}var pu=Symbol.for("@ipld/js-cid/CID");var Gs={};ht(Gs,{identity:()=>Nr});var Ri=0,gu="identity",Hi=qt;function mu(r){return It(Ri,Hi(r))}var Nr={code:Ri,name:gu,encode:Hi,digest:mu};function jt(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 _i(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function xu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ye(r,...t){if(!xu(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Oi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");_i(r.outputLen),_i(r.blockLen)}function Xe(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 Vi(r,t){Ye(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var cn=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Ct=(r,t)=>r<<32-t|r>>>t;function Di(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Tr(r){return typeof r=="string"&&(r=Di(r)),Ye(r),r}function $s(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];Ye(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}var Qe=class{clone(){return this._cloneInto()}};function ln(r){let t=n=>r().update(Tr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function un(r=32){if(Ce&&typeof Ce.getRandomValues=="function")return Ce.getRandomValues(new Uint8Array(r));if(Ce&&typeof Ce.randomBytes=="function")return Ce.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function yu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}var Ki=(r,t,e)=>r&t^~r&e,Mi=(r,t,e)=>r&t^r&e^t&e,tr=class extends Qe{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=cn(this.buffer)}update(t){Xe(this);let{view:e,buffer:n,blockLen:s}=this;t=Tr(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=cn(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Xe(this),Vi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)e[l]=0;yu(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=cn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],o)}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:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var fn=BigInt(4294967295),zs=BigInt(32);function Fi(r,t=!1){return t?{h:Number(r&fn),l:Number(r>>zs&fn)}:{h:Number(r>>zs&fn)|0,l:Number(r&fn)|0}}function bu(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Fi(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var wu=(r,t)=>BigInt(r>>>0)<<zs|BigInt(t>>>0),vu=(r,t,e)=>r>>>e,Bu=(r,t,e)=>r<<32-e|t>>>e,Eu=(r,t,e)=>r>>>e|t<<32-e,Au=(r,t,e)=>r<<32-e|t>>>e,Su=(r,t,e)=>r<<64-e|t>>>e-32,ku=(r,t,e)=>r>>>e-32|t<<64-e,Iu=(r,t)=>t,Cu=(r,t)=>r,Nu=(r,t,e)=>r<<e|t>>>32-e,Tu=(r,t,e)=>t<<e|r>>>32-e,Uu=(r,t,e)=>t<<e-32|r>>>64-e,Lu=(r,t,e)=>r<<e-32|t>>>64-e;function Ru(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Hu=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),_u=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ou=(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,Du=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Ku=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var Mu={fromBig:Fi,split:bu,toBig:wu,shrSH:vu,shrSL:Bu,rotrSH:Eu,rotrSL:Au,rotrBH:Su,rotrBL:ku,rotr32H:Iu,rotr32L:Cu,rotlSH:Nu,rotlSL:Tu,rotlBH:Uu,rotlBL:Lu,add:Ru,add3L:Hu,add3H:_u,add4L:Ou,add4H:Vu,add5H:Ku,add5L:Du},V=Mu;var[Fu,Pu]=V.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))),ae=new Uint32Array(80),ce=new Uint32Array(80),Ws=class extends tr{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:o,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:g,Gl:x,Hh:m,Hl:d}=this;return[t,e,n,s,o,i,a,c,f,u,l,h,g,x,m,d]}set(t,e,n,s,o,i,a,c,f,u,l,h,g,x,m,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=g|0,this.Gl=x|0,this.Hh=m|0,this.Hl=d|0}process(t,e){for(let p=0;p<16;p++,e+=4)ae[p]=t.getUint32(e),ce[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let E=ae[p-15]|0,U=ce[p-15]|0,L=V.rotrSH(E,U,1)^V.rotrSH(E,U,8)^V.shrSH(E,U,7),C=V.rotrSL(E,U,1)^V.rotrSL(E,U,8)^V.shrSL(E,U,7),k=ae[p-2]|0,A=ce[p-2]|0,G=V.rotrSH(k,A,19)^V.rotrBH(k,A,61)^V.shrSH(k,A,6),F=V.rotrSL(k,A,19)^V.rotrBL(k,A,61)^V.shrSL(k,A,6),K=V.add4L(C,F,ce[p-7],ce[p-16]),Y=V.add4H(K,L,G,ae[p-7],ae[p-16]);ae[p]=Y|0,ce[p]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:g,Fl:x,Gh:m,Gl:d,Hh:b,Hl:B}=this;for(let p=0;p<80;p++){let E=V.rotrSH(l,h,14)^V.rotrSH(l,h,18)^V.rotrBH(l,h,41),U=V.rotrSL(l,h,14)^V.rotrSL(l,h,18)^V.rotrBL(l,h,41),L=l&g^~l&m,C=h&x^~h&d,k=V.add5L(B,U,C,Pu[p],ce[p]),A=V.add5H(k,b,E,L,Fu[p],ae[p]),G=k|0,F=V.rotrSH(n,s,28)^V.rotrBH(n,s,34)^V.rotrBH(n,s,39),K=V.rotrSL(n,s,28)^V.rotrBL(n,s,34)^V.rotrBL(n,s,39),Y=n&o^n&a^o&a,S=s&i^s&c^i&c;b=m|0,B=d|0,m=g|0,d=x|0,g=l|0,x=h|0,{h:l,l:h}=V.add(f|0,u|0,A|0,G|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let T=V.add3L(G,K,S);n=V.add3H(T,A,F,Y),s=T|0}({h:n,l:s}=V.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=V.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=V.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=V.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=V.add(this.Eh|0,this.El|0,l|0,h|0),{h:g,l:x}=V.add(this.Fh|0,this.Fl|0,g|0,x|0),{h:m,l:d}=V.add(this.Gh|0,this.Gl|0,m|0,d|0),{h:b,l:B}=V.add(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,s,o,i,a,c,f,u,l,h,g,x,m,d,b,B)}roundClean(){ae.fill(0),ce.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 Pi=ln(()=>new Ws);var pn={};ht(pn,{aInRange:()=>wt,abool:()=>Nt,abytes:()=>er,bitGet:()=>Wu,bitLen:()=>Xs,bitMask:()=>Lr,bitSet:()=>Zu,bytesToHex:()=>$t,bytesToNumberBE:()=>zt,bytesToNumberLE:()=>ue,concatBytes:()=>Wt,createHmacDrbg:()=>Qs,ensureBytes:()=>X,equalBytes:()=>$u,hexToBytes:()=>Te,hexToNumber:()=>Ys,inRange:()=>Ur,isBytes:()=>le,memoized:()=>Le,notImplemented:()=>Yu,numberToBytesBE:()=>fe,numberToBytesLE:()=>Ue,numberToHexUnpadded:()=>Ne,numberToVarBytesBE:()=>Gu,utf8ToBytes:()=>zu,validateObject:()=>Vt});var hn=BigInt(0),dn=BigInt(1),qu=BigInt(2);function le(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function er(r){if(!le(r))throw new Error("Uint8Array expected")}function Nt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var ju=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function $t(r){er(r);let t="";for(let e=0;e<r.length;e++)t+=ju[r[e]];return t}function Ne(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ys(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?hn:BigInt("0x"+r)}var Gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function qi(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 Te(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let s=0,o=0;s<e;s++,o+=2){let i=qi(r.charCodeAt(o)),a=qi(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function zt(r){return Ys($t(r))}function ue(r){return er(r),Ys($t(Uint8Array.from(r).reverse()))}function fe(r,t){return Te(r.toString(16).padStart(t*2,"0"))}function Ue(r,t){return fe(r,t).reverse()}function Gu(r){return Te(Ne(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=Te(t)}catch(o){throw new Error(r+" must be hex string or Uint8Array, cause: "+o)}else if(le(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+" of length "+e+" expected, got "+s);return n}function Wt(...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 o=r[n];e.set(o,s),s+=o.length}return e}function $u(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 zu(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Zs=r=>typeof r=="bigint"&&hn<=r;function Ur(r,t,e){return Zs(r)&&Zs(t)&&Zs(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!Ur(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Xs(r){let t;for(t=0;r>hn;r>>=dn,t+=1);return t}function Wu(r,t){return r>>BigInt(t)&dn}function Zu(r,t,e){return r|(e?dn:hn)<<BigInt(t)}var Lr=r=>(qu<<BigInt(r-1))-dn,Js=r=>new Uint8Array(r),ji=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=Js(r),s=Js(r),o=0,i=()=>{n.fill(1),s.fill(0),o=0},a=(...l)=>e(s,n,...l),c=(l=Js())=>{s=a(ji([0]),l),n=a(),l.length!==0&&(s=a(ji([1]),l),n=a())},f=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<t;){n=a();let g=n.slice();h.push(g),l+=n.length}return Wt(...h)};return(l,h)=>{i(),c(l);let g;for(;!(g=h(f()));)c();return i(),g}}var Ju={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"||le(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 Vt(r,t,e={}){let n=(s,o,i)=>{let a=Ju[o];if(typeof a!="function")throw new Error("invalid validator function");let c=r[s];if(!(i&&c===void 0)&&!a(c,r))throw new Error("param "+String(s)+" is invalid. Expected "+o+", got "+c)};for(let[s,o]of Object.entries(t))n(s,o,!1);for(let[s,o]of Object.entries(e))n(s,o,!0);return r}var Yu=()=>{throw new Error("not implemented")};function Le(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var et=BigInt(0),Z=BigInt(1),Re=BigInt(2),Xu=BigInt(3),to=BigInt(4),Gi=BigInt(5),$i=BigInt(8),Qu=BigInt(9),tf=BigInt(16);function z(r,t){let e=r%t;return e>=et?e:t+e}function ef(r,t,e){if(t<et)throw new Error("invalid exponent, negatives unsupported");if(e<=et)throw new Error("invalid modulus");if(e===Z)return et;let n=Z;for(;t>et;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function J(r,t,e){let n=r;for(;t-- >et;)n*=n,n%=e;return n}function gn(r,t){if(r===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let e=z(r,t),n=t,s=et,o=Z,i=Z,a=et;for(;e!==et;){let f=n/e,u=n%e,l=s-i*f,h=o-a*f;n=e,e=u,s=i,o=a,i=l,a=h}if(n!==Z)throw new Error("invert: does not exist");return z(s,t)}function rf(r){let t=(r-Z)/Re,e,n,s;for(e=r-Z,n=0;e%Re===et;e/=Re,n++);for(s=Re;s<r&&ef(s,t,r)!==r-Z;s++)if(s>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/to;return function(c,f){let u=c.pow(f,i);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let o=(e+Z)/Re;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,s),e),l=a.pow(c,o),h=a.pow(c,e);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let g=1;for(let m=a.sqr(h);g<f&&!a.eql(m,a.ONE);g++)m=a.sqr(m);let x=a.pow(u,Z<<BigInt(f-g-1));u=a.sqr(x),l=a.mul(l,x),h=a.mul(h,u),f=g}return l}}function nf(r){if(r%to===Xu){let t=(r+Z)/to;return function(n,s){let o=n.pow(s,t);if(!n.eql(n.sqr(o),s))throw new Error("Cannot find square root");return o}}if(r%$i===Gi){let t=(r-Gi)/$i;return function(n,s){let o=n.mul(s,Re),i=n.pow(o,t),a=n.mul(s,i),c=n.mul(n.mul(a,Re),i),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%tf,rf(r)}var zi=(r,t)=>(z(r,t)&Z)===Z,sf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function eo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=sf.reduce((n,s)=>(n[s]="function",n),t);return Vt(r,e)}function of(r,t,e){if(e<et)throw new Error("invalid exponent, negatives unsupported");if(e===et)return r.ONE;if(e===Z)return t;let n=r.ONE,s=t;for(;e>et;)e&Z&&(n=r.mul(n,s)),s=r.sqr(s),e>>=Z;return n}function af(r,t){let e=new Array(t.length),n=t.reduce((o,i,a)=>r.is0(i)?o:(e[a]=o,r.mul(o,i)),r.ONE),s=r.inv(n);return t.reduceRight((o,i,a)=>r.is0(i)?o:(e[a]=r.mul(o,e[a]),r.mul(o,i)),s),e}function ro(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function he(r,t,e=!1,n={}){if(r<=et)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:s,nByteLength:o}=ro(r,t);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,a=Object.freeze({ORDER:r,BITS:s,BYTES:o,MASK:Lr(s),ZERO:et,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 et<=c&&c<r},is0:c=>c===et,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)=>of(a,c,f),div:(c,f)=>z(c*gn(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>gn(c,r),sqrt:n.sqrt||(c=>(i||(i=nf(r)),i(a,c))),invertBatch:c=>af(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?Ue(c,o):fe(c,o),fromBytes:c=>{if(c.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+c.length);return e?ue(c):zt(c)}});return Object.freeze(a)}function Wi(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 no(r){let t=Wi(r);return t+Math.ceil(t/2)}function Zi(r,t,e=!1){let n=r.length,s=Wi(t),o=no(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?zt(r):ue(r),a=z(i,t-Z)+Z;return e?Ue(a,s):fe(a,s)}var Ji=BigInt(0),mn=BigInt(1);function so(r,t){let e=t.negate();return r?e:t}function Yi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function oo(r,t){Yi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function lf(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function uf(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var io=new WeakMap,Xi=new WeakMap;function ao(r){return Xi.get(r)||1}function xn(r,t){return{constTimeNegate:so,hasPrecomputes(e){return ao(e)!==1},unsafeLadder(e,n,s=r.ZERO){let o=e;for(;n>Ji;)n&mn&&(s=s.add(o)),o=o.double(),n>>=mn;return s},precomputeWindow(e,n){let{windows:s,windowSize:o}=oo(n,t),i=[],a=e,c=a;for(let f=0;f<s;f++){c=a,i.push(c);for(let u=1;u<o;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,s){let{windows:o,windowSize:i}=oo(e,t),a=r.ZERO,c=r.BASE,f=BigInt(2**e-1),u=2**e,l=BigInt(e);for(let h=0;h<o;h++){let g=h*i,x=Number(s&f);s>>=l,x>i&&(x-=u,s+=mn);let m=g,d=g+Math.abs(x)-1,b=h%2!==0,B=x<0;x===0?c=c.add(so(b,n[m])):a=a.add(so(B,n[d]))}return{p:a,f:c}},wNAFUnsafe(e,n,s,o=r.ZERO){let{windows:i,windowSize:a}=oo(e,t),c=BigInt(2**e-1),f=2**e,u=BigInt(e);for(let l=0;l<i;l++){let h=l*a;if(s===Ji)break;let g=Number(s&c);if(s>>=u,g>a&&(g-=f,s+=mn),g===0)continue;let x=n[h+Math.abs(g)-1];g<0&&(x=x.negate()),o=o.add(x)}return o},getPrecomputes(e,n,s){let o=io.get(n);return o||(o=this.precomputeWindow(n,e),e!==1&&io.set(n,s(o))),o},wNAFCached(e,n,s){let o=ao(e);return this.wNAF(o,this.getPrecomputes(o,e,s),n)},wNAFCachedUnsafe(e,n,s,o){let i=ao(e);return i===1?this.unsafeLadder(e,n,o):this.wNAFUnsafe(i,this.getPrecomputes(i,e,s),n,o)},setWindowSize(e,n){Yi(n,t),Xi.set(e,n),io.delete(e)}}}function yn(r,t,e,n){if(lf(e,r),uf(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let s=r.ZERO,o=Xs(BigInt(e.length)),i=o>12?o-3:o>4?o-2:o?2:1,a=(1<<i)-1,c=new Array(a+1).fill(s),f=Math.floor((t.BITS-1)/i)*i,u=s;for(let l=f;l>=0;l-=i){c.fill(s);for(let g=0;g<n.length;g++){let x=n[g],m=Number(x>>BigInt(l)&BigInt(a));c[m]=c[m].add(e[g])}let h=s;for(let g=c.length-1,x=s;g>0;g--)x=x.add(c[g]),h=h.add(x);if(u=u.add(h),l!==0)for(let g=0;g<i;g++)u=u.double()}return u}function Rr(r){return eo(r.Fp),Vt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ro(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Tt=BigInt(0),vt=BigInt(1),bn=BigInt(2),ff=BigInt(8),hf={zip215:!0};function df(r){let t=Rr(r);return Vt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Qi(r){let t=df(r),{Fp:e,n,prehash:s,hash:o,randomBytes:i,nByteLength:a,h:c}=t,f=bn<<BigInt(a*8)-vt,u=e.create,l=he(t.n,t.nBitLength),h=t.uvRatio||((w,y)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(y))}}catch{return{isValid:!1,value:Tt}}}),g=t.adjustScalarBytes||(w=>w),x=t.domain||((w,y,v)=>{if(Nt("phflag",v),y.length||v)throw new Error("Contexts/pre-hash are not supported");return w});function m(w,y){wt("coordinate "+w,y,Tt,f)}function d(w){if(!(w instanceof p))throw new Error("ExtendedPoint expected")}let b=Le((w,y)=>{let{ex:v,ey:N,ez:R}=w,H=w.is0();y==null&&(y=H?ff:e.inv(R));let M=u(v*y),q=u(N*y),O=u(R*y);if(H)return{x:Tt,y:vt};if(O!==vt)throw new Error("invZ was invalid");return{x:M,y:q}}),B=Le(w=>{let{a:y,d:v}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:N,ey:R,ez:H,et:M}=w,q=u(N*N),O=u(R*R),$=u(H*H),W=u($*$),nt=u(q*y),st=u($*u(nt+O)),ct=u(W+u(v*u(q*O)));if(st!==ct)throw new Error("bad point: equation left != right (1)");let ft=u(N*R),yt=u(H*M);if(ft!==yt)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(y,v,N,R){this.ex=y,this.ey=v,this.ez=N,this.et=R,m("x",y),m("y",v),m("z",N),m("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof p)throw new Error("extended point not allowed");let{x:v,y:N}=y||{};return m("x",v),m("y",N),new p(v,N,vt,u(v*N))}static normalizeZ(y){let v=e.invertBatch(y.map(N=>N.ez));return y.map((N,R)=>N.toAffine(v[R])).map(p.fromAffine)}static msm(y,v){return yn(p,l,y,v)}_setWindowSize(y){L.setWindowSize(this,y)}assertValidity(){B(this)}equals(y){d(y);let{ex:v,ey:N,ez:R}=this,{ex:H,ey:M,ez:q}=y,O=u(v*q),$=u(H*R),W=u(N*q),nt=u(M*R);return O===$&&W===nt}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:y}=t,{ex:v,ey:N,ez:R}=this,H=u(v*v),M=u(N*N),q=u(bn*u(R*R)),O=u(y*H),$=v+N,W=u(u($*$)-H-M),nt=O+M,st=nt-q,ct=O-M,ft=u(W*st),yt=u(nt*ct),gt=u(W*ct),_t=u(st*nt);return new p(ft,yt,_t,gt)}add(y){d(y);let{a:v,d:N}=t,{ex:R,ey:H,ez:M,et:q}=this,{ex:O,ey:$,ez:W,et:nt}=y;if(v===BigInt(-1)){let li=u((H-R)*($+O)),ui=u((H+R)*($-O)),Hs=u(ui-li);if(Hs===Tt)return this.double();let fi=u(M*bn*nt),hi=u(q*bn*W),di=hi+fi,pi=ui+li,gi=hi-fi,vl=u(di*Hs),Bl=u(pi*gi),El=u(di*gi),Al=u(Hs*pi);return new p(vl,Bl,Al,El)}let st=u(R*O),ct=u(H*$),ft=u(q*N*nt),yt=u(M*W),gt=u((R+H)*(O+$)-st-ct),_t=yt-ft,Pt=yt+ft,wr=u(ct-v*st),xl=u(gt*_t),yl=u(Pt*wr),bl=u(gt*wr),wl=u(_t*Pt);return new p(xl,yl,wl,bl)}subtract(y){return this.add(y.negate())}wNAF(y){return L.wNAFCached(this,y,p.normalizeZ)}multiply(y){let v=y;wt("scalar",v,vt,n);let{p:N,f:R}=this.wNAF(v);return p.normalizeZ([N,R])[0]}multiplyUnsafe(y,v=p.ZERO){let N=y;return wt("scalar",N,Tt,n),N===Tt?U:this.is0()||N===vt?this:L.wNAFCachedUnsafe(this,N,p.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(y){return b(this,y)}clearCofactor(){let{h:y}=t;return y===vt?this:this.multiplyUnsafe(y)}static fromHex(y,v=!1){let{d:N,a:R}=t,H=e.BYTES;y=X("pointHex",y,H),Nt("zip215",v);let M=y.slice(),q=y[H-1];M[H-1]=q&-129;let O=ue(M),$=v?f:e.ORDER;wt("pointHex.y",O,Tt,$);let W=u(O*O),nt=u(W-vt),st=u(N*W-R),{isValid:ct,value:ft}=h(nt,st);if(!ct)throw new Error("Point.fromHex: invalid y coordinate");let yt=(ft&vt)===vt,gt=(q&128)!==0;if(!v&&ft===Tt&&gt)throw new Error("Point.fromHex: x=0 and x_0=1");return gt!==yt&&(ft=u(-ft)),p.fromAffine({x:ft,y:O})}static fromPrivateKey(y){return A(y).point}toRawBytes(){let{x:y,y:v}=this.toAffine(),N=Ue(v,e.BYTES);return N[N.length-1]|=y&vt?128:0,N}toHex(){return $t(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,vt,u(t.Gx*t.Gy)),p.ZERO=new p(Tt,vt,vt,Tt);let{BASE:E,ZERO:U}=p,L=xn(p,a*8);function C(w){return z(w,n)}function k(w){return C(ue(w))}function A(w){let y=e.BYTES;w=X("private key",w,y);let v=X("hashed private key",o(w),2*y),N=g(v.slice(0,y)),R=v.slice(y,2*y),H=k(N),M=E.multiply(H),q=M.toRawBytes();return{head:N,prefix:R,scalar:H,point:M,pointBytes:q}}function G(w){return A(w).pointBytes}function F(w=new Uint8Array,...y){let v=Wt(...y);return k(o(x(v,X("context",w),!!s)))}function K(w,y,v={}){w=X("message",w),s&&(w=s(w));let{prefix:N,scalar:R,pointBytes:H}=A(y),M=F(v.context,N,w),q=E.multiply(M).toRawBytes(),O=F(v.context,q,H,w),$=C(M+O*R);wt("signature.s",$,Tt,n);let W=Wt(q,Ue($,e.BYTES));return X("result",W,e.BYTES*2)}let Y=hf;function S(w,y,v,N=Y){let{context:R,zip215:H}=N,M=e.BYTES;w=X("signature",w,2*M),y=X("message",y),v=X("publicKey",v,M),H!==void 0&&Nt("zip215",H),s&&(y=s(y));let q=ue(w.slice(M,2*M)),O,$,W;try{O=p.fromHex(v,H),$=p.fromHex(w.slice(0,M),H),W=E.multiplyUnsafe(q)}catch{return!1}if(!H&&O.isSmallOrder())return!1;let nt=F(R,$.toRawBytes(),O.toRawBytes(),y);return $.add(O.multiplyUnsafe(nt)).subtract(W).clearCofactor().equals(p.ZERO)}return E._setWindowSize(8),{CURVE:t,getPublicKey:G,sign:K,verify:S,ExtendedPoint:p,utils:{getExtendedPublicKey:A,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,y=p.BASE){return y._setWindowSize(w),y.multiply(BigInt(3)),y}}}}var co=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ta=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Jd=BigInt(0),pf=BigInt(1),ea=BigInt(2),Yd=BigInt(3),gf=BigInt(5),mf=BigInt(8);function xf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=co,a=r*r%o*r%o,c=J(a,ea,o)*a%o,f=J(c,pf,o)*r%o,u=J(f,gf,o)*f%o,l=J(u,t,o)*u%o,h=J(l,e,o)*l%o,g=J(h,n,o)*h%o,x=J(g,s,o)*g%o,m=J(x,s,o)*g%o,d=J(m,t,o)*u%o;return{pow_p_5_8:J(d,ea,o)*r%o,b2:a}}function yf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function bf(r,t){let e=co,n=z(t*t*t,e),s=z(n*n*t,e),o=xf(r*s).pow_p_5_8,i=z(r*n*o,e),a=z(t*i*i,e),c=i,f=z(i*ta,e),u=a===r,l=a===z(-r,e),h=a===z(-r*ta,e);return u&&(i=c),(l||h)&&(i=f),zi(i,e)&&(i=z(-i,e)),{isValid:u||l,value:i}}var wf=he(co,void 0,!0),vf={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:wf,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:mf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Pi,randomBytes:un,adjustScalarBytes:yf,uvRatio:bf},lo=Qi(vf);var Hr=32,Zt=64,Bf=32;function ra(r,t){let e=r.subarray(0,Bf);return lo.sign(t instanceof Uint8Array?t:t.subarray(),e)}function na(r,t,e){return lo.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var wn=class{type="Ed25519";raw;constructor(t){this.raw=Or(t,Hr)}toMultihash(){return Nr.digest(vn(this))}toCID(){return Ot.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}verify(t,e){return na(this.raw,e,t)}},_r=class{type="Ed25519";raw;publicKey;constructor(t,e){this.raw=Or(t,Zt),this.publicKey=new wn(e)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}sign(t){return ra(this.raw,t)}};function uo(r){if(r.length>Zt){r=Or(r,Zt+Hr);let n=r.subarray(0,Zt),s=r.subarray(Zt,r.length);return new _r(n,s)}r=Or(r,Zt);let t=r.subarray(0,Zt),e=r.subarray(Hr);return new _r(t,e)}function Or(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Dt(r=0){return new Uint8Array(r)}var Ef=Math.pow(2,7),Af=Math.pow(2,14),Sf=Math.pow(2,21),oa=Math.pow(2,28),ia=Math.pow(2,35),aa=Math.pow(2,42),ca=Math.pow(2,49),mt=128,de=127;function Vr(r){if(r<Ef)return 1;if(r<Af)return 2;if(r<Sf)return 3;if(r<oa)return 4;if(r<ia)return 5;if(r<aa)return 6;if(r<ca)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function la(r,t,e=0){switch(Vr(r)){case 8:t[e++]=r&255|mt,r/=128;case 7:t[e++]=r&255|mt,r/=128;case 6:t[e++]=r&255|mt,r/=128;case 5:t[e++]=r&255|mt,r/=128;case 4:t[e++]=r&255|mt,r>>>=7;case 3:t[e++]=r&255|mt,r>>>=7;case 2:t[e++]=r&255|mt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ua(r,t){let e=r[t],n=0;if(n+=e&de,e<mt||(e=r[t+1],n+=(e&de)<<7,e<mt)||(e=r[t+2],n+=(e&de)<<14,e<mt)||(e=r[t+3],n+=(e&de)<<21,e<mt)||(e=r[t+4],n+=(e&de)*oa,e<mt)||(e=r[t+5],n+=(e&de)*ia,e<mt)||(e=r[t+6],n+=(e&de)*aa,e<mt)||(e=r[t+7],n+=(e&de)*ca,e<mt))return n;throw new RangeError("Could not decode varint")}var fo=new Float32Array([-0]),pe=new Uint8Array(fo.buffer);function fa(r,t,e){fo[0]=r,t[e]=pe[0],t[e+1]=pe[1],t[e+2]=pe[2],t[e+3]=pe[3]}function ha(r,t){return pe[0]=r[t],pe[1]=r[t+1],pe[2]=r[t+2],pe[3]=r[t+3],fo[0]}var ho=new Float64Array([-0]),dt=new Uint8Array(ho.buffer);function da(r,t,e){ho[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function pa(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],ho[0]}var kf=BigInt(Number.MAX_SAFE_INTEGER),If=BigInt(Number.MIN_SAFE_INTEGER),At=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 He;if(t<kf&&t>If)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>ga&&(s=0n,++n>ga&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return He;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):He}},He=new At(0,0);He.toBigInt=function(){return 0n};He.zzEncode=He.zzDecode=function(){return this};He.length=function(){return 1};var ga=4294967296n;function ma(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 xa(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function po(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,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 Ut(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Bn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var go=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ut(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 Ut(this,4);return Bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return Bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let t=ha(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ut(this,4);let t=pa(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 Ut(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return xa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ut(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 At(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 Ut(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 Ut(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 Ut(this,8);let t=Bn(this.buf,this.pos+=4),e=Bn(this.buf,this.pos+=4);return new At(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=ua(this.buf,this.pos);return this.pos+=Vr(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 mo(r){return new go(r instanceof Uint8Array?r:r.subarray())}function En(r,t,e){let n=mo(r);return t.decode(n,void 0,e)}var xo={};ht(xo,{base10:()=>Cf});var Cf=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var yo={};ht(yo,{base16:()=>Nf,base16upper:()=>Tf});var Nf=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tf=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bo={};ht(bo,{base2:()=>Uf});var Uf=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wo={};ht(wo,{base256emoji:()=>Of});var ba=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}"),Lf=ba.reduce((r,t,e)=>(r[e]=t,r),[]),Rf=ba.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Hf(r){return r.reduce((t,e)=>(t+=Lf[e],t),"")}function _f(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=Rf[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var Of=$e({prefix:"\u{1F680}",name:"base256emoji",encode:Hf,decode:_f});var vo={};ht(vo,{base64:()=>_e,base64pad:()=>Vf,base64url:()=>Df,base64urlpad:()=>Kf});var _e=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vf=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Df=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kf=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bo={};ht(Bo,{base8:()=>Mf});var Mf=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Eo={};ht(Eo,{identity:()=>Ff});var Ff=$e({prefix:"\0",name:"identity",encode:r=>vi(r),decode:r=>wi(r)});var Lp=new TextEncoder,Rp=new TextDecoder;var ko={};ht(ko,{sha256:()=>rr,sha512:()=>jf});function So({name:r,code:t,encode:e}){return new Ao(r,t,e)}var Ao=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?It(this.code,e):e.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function va(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var rr=So({name:"sha2-256",code:18,encode:va("SHA-256")}),jf=So({name:"sha2-512",code:19,encode:va("SHA-512")});var Io={...Eo,...bo,...Bo,...xo,...yo,...Fs,...Ps,...Ms,...vo,...wo},Gp={...ko,...Gs};function Ea(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ba=Ea("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Co=Ea("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=Dt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Gf={utf8:Ba,"utf-8":Ba,hex:Io.base16,latin1:Co,ascii:Co,binary:Co,...Io},An=Gf;function j(r,t="utf8"){let e=An[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function No(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return Dt(i);s+i>t&&(n=Dt(t),s=0);let a=n.subarray(s,s+=i);return s&7&&(s=(s|7)+1),a}}var Oe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function To(){}var Lo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},$f=No();function zf(r){return globalThis.Buffer!=null?Dt(r):$f(r)}var Kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(To,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Oe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ro((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(Sn,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=At.fromBigInt(t);return this._push(Sn,e.length(),e)}uint64Number(t){return this._push(la,Vr(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=At.fromBigInt(t).zzEncode();return this._push(Sn,e.length(),e)}sint64Number(t){let e=At.fromNumber(t).zzEncode();return this._push(Sn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Uo,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=At.fromBigInt(t);return this._push(Dr,4,e.lo)._push(Dr,4,e.hi)}fixed64Number(t){let e=At.fromNumber(t);return this._push(Dr,4,e.lo)._push(Dr,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(fa,4,t)}double(t){return this._push(da,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Uo,1,0):this.uint32(e)._push(Zf,e,t)}string(t){let e=ma(t);return e!==0?this.uint32(e)._push(po,e,t):this._push(Uo,1,0)}fork(){return this.states=new Lo(this),this.head=this.tail=new Oe(To,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 Oe(To,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=zf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Uo(r,t,e){t[e]=r&255}function Wf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ro=class extends Oe{next;constructor(t,e){super(Wf,t,e),this.next=void 0}};function Sn(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 Dr(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 Zf(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(Jf,t,r),this},Kr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Yf,t,r),this});function Jf(r,t,e){t.set(r,e)}function Yf(r,t,e){r.length<40?po(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(j(r),e)}function Ho(){return new Kr}function kn(r,t){let e=Ho();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var nr;(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"})(nr||(nr={}));function In(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function _o(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return In("enum",nr.VARINT,e,n)}function Cn(r,t){return In("message",nr.LENGTH_DELIMITED,r,t)}var it;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(it||(it={}));var Oo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Oo||(Oo={}));(function(r){r.codec=()=>_o(Oo)})(it||(it={}));var ge;(function(r){let t;r.codec=()=>(t==null&&(t=Cn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),it.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=it.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>kn(e,r.codec()),r.decode=(e,n)=>En(e,r.codec(),n)})(ge||(ge={}));var Mr;(function(r){let t;r.codec=()=>(t==null&&(t=Cn((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),it.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=it.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>kn(e,r.codec()),r.decode=(e,n)=>En(e,r.codec(),n)})(Mr||(Mr={}));var Jr={};ht(Jr,{MAX_RSA_KEY_SIZE:()=>vs,generateRSAKeyPair:()=>Ec,jwkToJWKKeyPair:()=>Ac,jwkToPkcs1:()=>mh,jwkToPkix:()=>Go,jwkToRSAPrivateKey:()=>Bc,pkcs1ToJwk:()=>bc,pkcs1ToRSAPrivateKey:()=>Bs,pkixToJwk:()=>wc,pkixToRSAPublicKey:()=>vc});function sr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Xf(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Fr(r,...t){if(!Xf(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Nn(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");sr(r.outputLen),sr(r.blockLen)}function or(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 Sa(r,t){Fr(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var Ve=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var De=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Lt=(r,t)=>r<<32-t|r>>>t,Tn=(r,t)=>r<<t|r>>>32-t>>>0;var Qf=async()=>{};async function ka(r,t,e){let n=Date.now();for(let s=0;s<r;s++){e(s);let o=Date.now()-n;o>=0&&o<t||(await Qf(),n+=o)}}function th(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function me(r){return typeof r=="string"&&(r=th(r)),Fr(r),r}var ir=class{clone(){return this._cloneInto()}};function Ia(r,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(r,t)}function ar(r){let t=n=>r().update(me(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ca(r=32){if(Ve&&typeof Ve.getRandomValues=="function")return Ve.getRandomValues(new Uint8Array(r));if(Ve&&typeof Ve.randomBytes=="function")return Ve.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function eh(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,f=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+f,a,n)}var Un=(r,t,e)=>r&t^~r&e,Ln=(r,t,e)=>r&t^r&e^t&e,xe=class extends ir{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=De(this.buffer)}update(t){or(this);let{view:e,buffer:n,blockLen:s}=this;t=me(t);let o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=De(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){or(this),Sa(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>s-i&&(this.process(n,0),i=0);for(let l=i;l<s;l++)e[l]=0;eh(n,s-8,BigInt(this.length*8),o),this.process(n,0);let a=De(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],o)}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:o,destroyed:i,pos:a}=this;return t.length=s,t.pos=a,t.finished=o,t.destroyed=i,s%e&&t.buffer.set(n),t}};var rh=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]),ye=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),be=new Uint32Array(64),Vo=class extends xe{constructor(){super(64,32,8,!1),this.A=ye[0]|0,this.B=ye[1]|0,this.C=ye[2]|0,this.D=ye[3]|0,this.E=ye[4]|0,this.F=ye[5]|0,this.G=ye[6]|0,this.H=ye[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)be[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let h=be[l-15],g=be[l-2],x=Lt(h,7)^Lt(h,18)^h>>>3,m=Lt(g,17)^Lt(g,19)^g>>>10;be[l]=m+be[l-7]+x+be[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Lt(a,6)^Lt(a,11)^Lt(a,25),g=u+h+Un(a,c,f)+rh[l]+be[l]|0,m=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Ln(n,s,o)|0;u=f,f=c,c=a,a=i+g|0,i=o,o=s,s=n,n=g+m|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var cr=ar(()=>new Vo);var P=_s(Na());function Ke(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,o=0,i=Math.pow(2,t);for(let a=1;a<8;a++){if(r<i){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let f=new Uint8Array(c);for(let u=a-1;u>=0;u--){let l=Math.pow(2,u*t);f[o-u-1]=Math.floor(s/l),s-=f[o-u-1]*l}return c}i*=Math.pow(2,t)}return new ArrayBuffer(0)}function _n(...r){let t=0,e=0;for(let o of r)t+=o.length;let n=new ArrayBuffer(t),s=new Uint8Array(n);for(let o of r)s.set(o,e),e+=o.length;return s}function Ko(){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=Ke(e,8),s=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=r[a];return o[0]&=127,Ke(o,8)-n}function Ta(r){let t=r<0?r*-1:r,e=128;for(let n=1;n<8;n++){if(t<=e){if(r<0){let i=e-t,a=we(i,8,n),c=new Uint8Array(a);return c[0]|=128,a}let s=we(t,8,n),o=new Uint8Array(s);if(o[0]&128){let i=s.slice(0),a=new Uint8Array(i);s=new ArrayBuffer(s.byteLength+1),o=new Uint8Array(s);for(let c=0;c<i.byteLength;c++)o[c+1]=a[c];o[0]=0}return s}e*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ua(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 Bt(r,t){let e=r.toString(10);if(t<e.length)return"";let n=t-e.length,s=new Array(n);for(let i=0;i<n;i++)s[i]="0";return s.join("").concat(e)}var Hg=Math.log(2);function On(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Mo(r){let t=0,e=0;for(let s=0;s<r.length;s++){let o=r[s];t+=o.byteLength}let n=new Uint8Array(t);for(let s=0;s<r.length;s++){let o=r[s];n.set(new Uint8Array(o),e),e+=o.byteLength}return n.buffer}function ee(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 qr=class{constructor(){this.items=[]}write(t){this.items.push(t)}final(){return Mo(this.items)}},Pr=[new Uint8Array([1])],La="0123456789";var fr="",Rt=new ArrayBuffer(0),Fo=new Uint8Array(0),jr="EndOfContent",Ha="OCTET STRING",_a="BIT STRING";function re(r){var t;return t=class extends r{constructor(...n){var s;super(...n);let o=n[0]||{};this.isHexOnly=(s=o.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=o.valueHex?P.BufferSourceConverter.toUint8Array(o.valueHex):Fo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,s,o){let i=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!ee(this,i,s,o))return-1;let a=s+o;return this.valueHexView=i.subarray(s,a),this.valueHexView.length?(this.blockLength=o,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",Rt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:P.Convert.ToHex(this.valueHexView)}}},t.NAME="hexBlock",t}var Yt=class{constructor({blockLength:t=0,error:e=fr,warnings:n=[],valueBeforeDecode:s=Fo}={}){this.blockLength=t,this.error=e,this.warnings=n,this.valueBeforeDecodeView=P.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:P.Convert.ToHex(this.valueBeforeDecodeView)}}};Yt.NAME="baseBlock";var pt=class extends Yt{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'")}};pt.NAME="valueBlock";var Vn=class extends re(Yt){constructor({idBlock:t={}}={}){var e,n,s,o;super(),t?(this.isHexOnly=(e=t.isHexOnly)!==null&&e!==void 0?e:!1,this.valueHexView=t.valueHex?P.BufferSourceConverter.toUint8Array(t.valueHex):Fo,this.tagClass=(n=t.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(s=t.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(o=t.isConstructed)!==null&&o!==void 0?o:!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",Rt}if(this.isConstructed&&(e|=32),this.tagNumber<31&&!this.isHexOnly){let s=new Uint8Array(1);if(!t){let o=this.tagNumber;o&=31,e|=o,s[0]=e}return s.buffer}if(!this.isHexOnly){let s=we(this.tagNumber,7),o=new Uint8Array(s),i=s.byteLength,a=new Uint8Array(i+1);if(a[0]=e|31,!t){for(let c=0;c<i-1;c++)a[c+1]=o[c]|128;a[i]=o[i-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=e|31,!t){let s=this.valueHexView;for(let o=0;o<s.length-1;o++)n[o+1]=s[o]|128;n[this.valueHexView.byteLength]=s[s.length-1]}return n.buffer}fromBER(t,e,n){let s=P.BufferSourceConverter.toUint8Array(t);if(!ee(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,f=this.valueHexView=new Uint8Array(255),u=255;for(;o[c]&128;){if(f[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let g=0;g<f.length;g++)h[g]=f[g];f=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,f[c-1]=o[c]&127;let l=new Uint8Array(c);for(let h=0;h<c;h++)l[h]=f[h];f=this.valueHexView=new Uint8Array(c),f.set(l),this.blockLength<=9?this.tagNumber=Ke(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}}};Vn.NAME="identificationBlock";var Dn=class extends Yt{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=P.BufferSourceConverter.toUint8Array(t);if(!ee(this,s,e,n))return-1;let o=s.subarray(e,e+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,e+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,e+this.blockLength;let i=o[0]&127;if(i>8)return this.error="Too big integer",-1;if(i+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=e+1,c=s.subarray(a,a+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ke(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+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",Rt;if(e=new ArrayBuffer(s.byteLength+1),t)return e;let o=new Uint8Array(s);n=new Uint8Array(e),n[0]=s.byteLength|128;for(let i=0;i<s.byteLength;i++)n[i+1]=o[i];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}}};Dn.NAME="lengthBlock";var I={},lt=class extends Yt{constructor({name:t=fr,optional:e=!1,primitiveSchema:n,...s}={},o){super(s),this.name=t,this.optional=e,n&&(this.primitiveSchema=n),this.idBlock=new Vn(s),this.lenBlock=new Dn(s),this.valueBlock=o?new o(s):new pt(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 qr;e||Oa(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 o=this.valueBlock.toBER(t);this.lenBlock.length=o.byteLength;let i=this.lenBlock.toBER(t);n.write(i),n.write(o)}return e?Rt: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():P.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${P.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 Ua(e,n)}};lt.NAME="BaseBlock";function Oa(r){if(r instanceof I.Constructed)for(let t of r.valueBlock.value)Oa(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var Kn=class extends lt{constructor({value:t=fr,...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 Mn=class extends re(pt){constructor({isHexOnly:t=!0,...e}={}){super(e),this.isHexOnly=t}};Mn.NAME="PrimitiveValueBlock";var Va,Fn=class extends lt{constructor(t={}){super(t,Mn),this.idBlock.isConstructed=!1}};Va=Fn;I.Primitive=Va;Fn.NAME="PRIMITIVE";function fh(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 ws(r,t=0,e=r.length){let n=t,s=new lt({},pt),o=new Yt;if(!ee(o,r,t,e))return s.error=o.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=lt;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=I.EndOfContent;break;case 1:c=I.Boolean;break;case 2:c=I.Integer;break;case 3:c=I.BitString;break;case 4:c=I.OctetString;break;case 5:c=I.Null;break;case 6:c=I.ObjectIdentifier;break;case 10:c=I.Enumerated;break;case 12:c=I.Utf8String;break;case 13:c=I.RelativeObjectIdentifier;break;case 14:c=I.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=I.Sequence;break;case 17:c=I.Set;break;case 18:c=I.NumericString;break;case 19:c=I.PrintableString;break;case 20:c=I.TeletexString;break;case 21:c=I.VideotexString;break;case 22:c=I.IA5String;break;case 23:c=I.UTCTime;break;case 24:c=I.GeneralizedTime;break;case 25:c=I.GraphicString;break;case 26:c=I.VisibleString;break;case 27:c=I.GeneralString;break;case 28:c=I.UniversalString;break;case 29:c=I.CharacterString;break;case 30:c=I.BmpString;break;case 31:c=I.DATE;break;case 32:c=I.TimeOfDay;break;case 33:c=I.DateTime;break;case 34:c=I.Duration;break;default:{let f=s.idBlock.isConstructed?new I.Constructed:new I.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?I.Constructed:I.Primitive}return s=fh(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 Me(r){if(!r.byteLength){let t=new lt({},pt);return t.error="Input buffer has zero length",{offset:-1,result:t}}return ws(P.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function hh(r,t){return r?1:t}var Kt=class extends pt{constructor({value:t=[],isIndefiniteForm:e=!1,...n}={}){super(n),this.value=t,this.isIndefiniteForm=e}fromBER(t,e,n){let s=P.BufferSourceConverter.toUint8Array(t);if(!ee(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 o=e;for(;hh(this.isIndefiniteForm,n)>0;){let i=ws(s,o,n);if(i.offset===-1)return this.error=i.result.error,this.warnings.concat(i.result.warnings),-1;if(o=i.offset,this.blockLength+=i.result.blockLength,n-=i.result.blockLength,this.value.push(i.result),this.isIndefiniteForm&&i.result.constructor.NAME===jr)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===jr?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(t,e){let n=e||new qr;for(let s=0;s<this.value.length;s++)this.value[s].toBER(t,n);return e?Rt: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 Da,ve=class extends lt{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
- `)}`:`${e} :`}};ia=xe;k.Constructed=ia;xe.NAME="CONSTRUCTED";var In=class extends dt{fromBER(t,e,n){return e}toBER(t){return Ut}};In.override="EndOfContentValueBlock";var aa,Nn=class extends lt{constructor(t={}){super(t,In),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};aa=Nn;k.EndOfContent=aa;Nn.NAME=Lr;var ca,Wt=class extends lt{constructor(t={}){super(t,dt),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}`}};ca=Wt;k.Null=ca;Wt.NAME="NULL";var Cn=class extends Qt(dt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.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=M.BufferSourceConverter.toUint8Array(t);return Xt(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,vo.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Cn.NAME="BooleanValueBlock";var la,Tn=class extends lt{constructor(t={}){super(t,Cn),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}`}};la=Tn;k.Boolean=la;Tn.NAME="BOOLEAN";var Un=class extends Qt(Vt){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=Vt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===Lr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==ra)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?Vt.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Un.NAME="OctetStringValueBlock";var ua,Jt=class r extends lt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Un),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 o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=os(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.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} : ${M.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 M.BufferSourceConverter.concat(t)}};ua=Jt;k.OctetString=ua;Jt.NAME=ra;var Rn=class extends Qt(Vt){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=Vt.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===Lr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==na)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}let o=M.BufferSourceConverter.toUint8Array(t);if(!Xt(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=os(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return Vt.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Ut;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}}};Rn.NAME="BitStringValueBlock";var fa,er=class extends lt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Rn),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)}`}}};fa=er;k.BitString=fa;er.NAME=na;var ha;function Tf(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u=0,l=c<i?i:c,f=0;for(let h=l;h>=0;h--,f++){switch(!0){case f<a.length:u=o[i-f]+a[c-f]+e[0];break;default:u=o[i-f]+e[0]}switch(e[0]=u/10,!0){case f>=o.length:o=xn(new Uint8Array([u%10]),o);break;default:o[i-f]=u%10}}return e[0]>0&&(o=xn(e,o)),o}function ea(r){if(r>=Ur.length)for(let t=Ur.length;t<=r;t++){let e=new Uint8Array([0]),n=Ur[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=xn(e,n)),Ur.push(n)}return Ur[r]}function Uf(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=o[i-l]-a[c-l]-e,!0){case u<0:e=1,o[i-l]=u+10;break;default:e=0,o[i-l]=u}if(e>0)for(let f=i-c+1;f>=0;f--,l++)if(u=o[i-l]-e,u<0)e=1,o[i-l]=u+10;else{e=0,o[i-l]=u;break}return o.slice()}var _r=class extends Qt(dt){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=vo.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Xi(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}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,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let u=0;u<8;u++){if((s&1)===1)switch(n){case t:e=Uf(ea(n),e),i="-";break;default:e=Tf(e,ea(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=ta.charAt(e[c]));return a===!1&&(i+=ta.charAt(0)),i}};ha=_r;_r.NAME="IntegerValueBlock";Object.defineProperty(ha.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var da,Y=class r extends lt{constructor(t={}){super(t,_r),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return vn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){vn();let e=BigInt(t),n=new Rr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${M.Convert.ToHex(a)}`)+e,l=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);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()}`}};da=Y;k.Integer=da;Y.NAME="INTEGER";var pa,Ln=class extends Y{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};pa=Ln;k.Enumerated=pa;Ln.NAME="ENUMERATED";var Hr=class extends Qt(dt){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=M.BufferSourceConverter.toUint8Array(t);if(!Xt(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[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=Le(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){vn();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,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ut;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=M.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}}};Hr.NAME="sidBlock";var _n=class extends dt{constructor({value:t=rr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Hr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}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,Ut;e.push(s)}return Bo(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,o){let i=this.value[0],a=0;switch(i.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;i.valueDec=c+a,o=!1}else{let i=new Hr;if(s>Number.MAX_SAFE_INTEGER){vn();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}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}};_n.NAME="ObjectIdentifierValueBlock";var ga,kt=class extends lt{constructor(t={}){super(t,_n),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()}}};ga=kt;k.ObjectIdentifier=ga;kt.NAME="OBJECT IDENTIFIER";var Vr=class extends Qt(Zt){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!Xt(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[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=Le(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,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Ut;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Vr.NAME="relativeSidBlock";var Hn=class extends dt{constructor({value:t=rr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Vr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Ut;n.push(o)}return Bo(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 o=new Vr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}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}};Hn.NAME="RelativeObjectIdentifierValueBlock";var ma,Vn=class extends lt{constructor(t={}){super(t,Hn),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()}}};ma=Vn;k.RelativeObjectIdentifier=ma;Vn.NAME="RelativeObjectIdentifier";var ya,rt=class extends xe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};ya=rt;k.Sequence=ya;rt.NAME="SEQUENCE";var ba,On=class extends xe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};ba=On;k.Set=ba;On.NAME="SET";var Dn=class extends Qt(dt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=rr}toJSON(){return{...super.toJSON(),value:this.value}}};Dn.NAME="StringValueBlock";var Kn=class extends Dn{};Kn.NAME="SimpleStringValueBlock";var mt=class extends An{constructor({...t}={}){super(t,Kn)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.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}};mt.NAME="SIMPLE STRING";var Mn=class extends mt{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};Mn.NAME="Utf8StringValueBlock";var wa,Yt=class extends Mn{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};wa=Yt;k.Utf8String=wa;Yt.NAME="UTF8String";var Pn=class extends mt{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};Pn.NAME="BmpStringValueBlock";var xa,Fn=class extends Pn{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};xa=Fn;k.BmpString=xa;Fn.NAME="BMPString";var $n=class extends mt{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 o=we(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};$n.NAME="UniversalStringValueBlock";var va,qn=class extends $n{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};va=qn;k.UniversalString=va;qn.NAME="UniversalString";var Ba,jn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Ba=jn;k.NumericString=Ba;jn.NAME="NumericString";var Ea,zn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Ea=zn;k.PrintableString=Ea;zn.NAME="PrintableString";var Aa,Gn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Aa=Gn;k.TeletexString=Aa;Gn.NAME="TeletexString";var ka,Zn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};ka=Zn;k.VideotexString=ka;Zn.NAME="VideotexString";var Sa,Wn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Sa=Wn;k.IA5String=Sa;Wn.NAME="IA5String";var Ia,Jn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Ia=Jn;k.GraphicString=Ia;Jn.NAME="GraphicString";var Na,Or=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Na=Or;k.VisibleString=Na;Or.NAME="VisibleString";var Ca,Yn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Ca=Yn;k.GeneralString=Ca;Yn.NAME="GeneralString";var Ta,Xn=class extends mt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Ta=Xn;k.CharacterString=Ta;Xn.NAME="CharacterString";var Ua,Dr=class extends Or{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,M.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]=vt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=vt(this.month,2),e[2]=vt(this.day,2),e[3]=vt(this.hour,2),e[4]=vt(this.minute,2),e[5]=vt(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}}};Ua=Dr;k.UTCTime=Ua;Dr.NAME="UTCTime";var Ra,Qn=class extends Dr{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="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let f=new Number(t[t.length-1]);if(isNaN(f.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 f=1,h=n.indexOf("+"),w="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(w=n.substring(h+1),n=n.substring(0,h),w.length!==2&&w.length!==4)throw new Error("Wrong input string for conversion");let x=parseInt(w.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*x,w.length===4){if(x=parseInt(w.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=f*x}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,u)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=i.exec(s);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(vt(this.year,4)),e.push(vt(this.month,2)),e.push(vt(this.day,2)),e.push(vt(this.hour,2)),e.push(vt(this.minute,2)),e.push(vt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(vt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Ra=Qn;k.GeneralizedTime=Ra;Qn.NAME="GeneralizedTime";var La,ts=class extends Yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};La=ts;k.DATE=La;ts.NAME="DATE";var _a,es=class extends Yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};_a=es;k.TimeOfDay=_a;es.NAME="TimeOfDay";var Ha,rs=class extends Yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Ha=rs;k.DateTime=Ha;rs.NAME="DateTime";var Va,ns=class extends Yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};Va=ns;k.Duration=Va;ns.NAME="Duration";var Oa,ss=class extends Yt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Oa=ss;k.TIME=Oa;ss.NAME="TIME";function Bt(r,t="utf8"){let e=dn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function He(r){if(isNaN(r)||r<=0)throw new _("random bytes length must be a Number bigger than 0");return Je(r)}async function Da(r){let t=await bt.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 Rf(t);return{privateKey:e[0],publicKey:e[1]}}async function Ka(r,t){let e=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ma(r,t,e){let n=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Rf(r){if(r.privateKey==null||r.publicKey==null)throw new _("Private and public key are required");return Promise.all([bt.get().subtle.exportKey("jwk",r.privateKey),bt.get().subtle.exportKey("jwk",r.publicKey)])}function ko(r){if(r.kty!=="RSA")throw new _("invalid key type");if(r.n==null)throw new _("invalid key modulus");return $(r.n,"base64url").length*8}var nr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Kr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return Lt.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}verify(t,e){return Ma(this._key,e,t)}},Mr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Kr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}sign(t){return Ka(this._key,t)}};var is=8192,So=18;function Pa(r){let{result:t}=_e(r),e=t.valueBlock.value;return{n:Ot(e[1]),e:Ot(e[2]),d:Ot(e[3]),p:Ot(e[4]),q:Ot(e[5]),dp:Ot(e[6]),dq:Ot(e[7]),qi:Ot(e[8]),kty:"RSA",alg:"RS256"}}function Lf(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 _("JWK was missing components");let e=new rt({value:[new Y({value:0}),Y.fromBigInt(Dt($(r.n,"base64url"))),Y.fromBigInt(Dt($(r.e,"base64url"))),Y.fromBigInt(Dt($(r.d,"base64url"))),Y.fromBigInt(Dt($(r.p,"base64url"))),Y.fromBigInt(Dt($(r.q,"base64url"))),Y.fromBigInt(Dt($(r.dp,"base64url"))),Y.fromBigInt(Dt($(r.dq,"base64url"))),Y.fromBigInt(Dt($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Fa(r){let{result:t}=_e(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Ot(e[0]),e:Ot(e[1])}}function Io(r){if(r.n==null||r.e==null)throw new _("JWK was missing components");let e=new rt({value:[new rt({value:[new kt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new er({valueHex:new rt({value:[Y.fromBigInt(Dt($(r.n,"base64url"))),Y.fromBigInt(Dt($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Ot(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Bt(t,"base64url")}function Dt(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(""))}function as(r){let t=Pa(r);return qa(t)}function $a(r){let t=Fa(r);if(ko(t)>is)throw new De("Key size is too large");let e=be(ge.encode({Type:it.RSA,Data:r})),n=St(So,e);return new nr(t,n)}function qa(r){if(ko(r)>is)throw new _("Key size is too large");let t=za(r),e=be(ge.encode({Type:it.RSA,Data:Io(t.publicKey)})),n=St(So,e);return new Mr(t.privateKey,new nr(t.publicKey,n))}async function ja(r){if(r>is)throw new _("Key size is too large");let t=await Da(r),e=be(ge.encode({Type:it.RSA,Data:Io(t.publicKey)})),n=St(So,e);return new Mr(t.privateKey,new nr(t.publicKey,n))}function za(r){if(r==null)throw new _("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var cs=class extends Ze{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Yr(t);let n=se(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,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return Ge(this),this.iHash.update(t),this}digestInto(t){Ge(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:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,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()}},Pr=(r,t,e)=>new cs(r,t).update(e).digest();Pr.create=(r,t)=>new cs(r,t);function Ga(r){r.lowS!==void 0&&Nt("lowS",r.lowS),r.prehash!==void 0&&Nt("prehash",r.prehash)}function _f(r){let t=Er(r);_t(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:Hf,hexToBytes:Vf}=nn,te={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=te;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=ke(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?ke(s.length/2|128):"";return`${ke(r)}${o}${s}${t}`},decode(r,t){let{Err:e}=te,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=te;if(r<ee)throw new t("integer: negative integers are not allowed");let e=ke(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected assertion");return e},decode(r){let{Err:t}=te;if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return Hf(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=te,s=typeof r=="string"?Vf(r):r;Ye(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l}=n.decode(2,c);if(l.length)throw new t("Invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=te,n=`${t.encode(2,e.encode(r.r))}${t.encode(2,e.encode(r.s))}`;return t.encode(48,n)}},ee=BigInt(0),at=BigInt(1),Wp=BigInt(2),Za=BigInt(3),Jp=BigInt(4);function Of(r){let t=_f(r),{Fp:e}=t,n=he(t.n,t.nBitLength),s=t.toBytes||((m,d,y)=>{let B=d.toAffine();return jt(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),o=t.fromBytes||(m=>{let d=m.subarray(1),y=e.fromBytes(d.subarray(0,e.BYTES)),B=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:y,y:B}});function i(m){let{a:d,b:y}=t,B=e.sqr(m),g=e.mul(B,m);return e.add(e.add(g,e.mul(m,d)),y)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(m){return vr(m,at,t.n)}function c(m){let{allowedPrivateKeyLengths:d,nByteLength:y,wrapPrivateKey:B,n:g}=t;if(d&&typeof m!="bigint"){if(le(m)&&(m=$t(m)),typeof m!="string"||!d.includes(m.length))throw new Error("Invalid key");m=m.padStart(y*2,"0")}let E;try{E=typeof m=="bigint"?m:qt(J("private key",m,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof m}`)}return B&&(E=j(E,g)),wt("private key",E,at,g),E}function u(m){if(!(m instanceof h))throw new Error("ProjectivePoint expected")}let l=Ne((m,d)=>{let{px:y,py:B,pz:g}=m;if(e.eql(g,e.ONE))return{x:y,y:B};let E=m.is0();d==null&&(d=E?e.ONE:e.inv(g));let R=e.mul(y,d),U=e.mul(B,d),S=e.mul(g,d);if(E)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:R,y:U}}),f=Ne(m=>{if(m.is0()){if(t.allowInfinityPoint&&!e.is0(m.py))return;throw new Error("bad point: ZERO")}let{x:d,y}=m.toAffine();if(!e.isValid(d)||!e.isValid(y))throw new Error("bad point: x or y not FE");let B=e.sqr(y),g=i(d);if(!e.eql(B,g))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,y,B){if(this.px=d,this.py=y,this.pz=B,d==null||!e.isValid(d))throw new Error("x required");if(y==null||!e.isValid(y))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:y,y:B}=d||{};if(!d||!e.isValid(y)||!e.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let g=E=>e.eql(E,e.ZERO);return g(y)&&g(B)?h.ZERO:new h(y,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let y=e.invertBatch(d.map(B=>B.pz));return d.map((B,g)=>B.toAffine(y[g])).map(h.fromAffine)}static fromHex(d){let y=h.fromAffine(o(J("pointHex",d)));return y.assertValidity(),y}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,y){return an(h,n,d,y)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){u(d);let{px:y,py:B,pz:g}=this,{px:E,py:R,pz:U}=d,S=e.eql(e.mul(y,U),e.mul(E,g)),I=e.eql(e.mul(B,U),e.mul(R,g));return S&&I}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:y}=t,B=e.mul(y,Za),{px:g,py:E,pz:R}=this,U=e.ZERO,S=e.ZERO,I=e.ZERO,T=e.mul(g,g),X=e.mul(E,E),F=e.mul(R,R),O=e.mul(g,E);return O=e.add(O,O),I=e.mul(g,R),I=e.add(I,I),U=e.mul(d,I),S=e.mul(B,F),S=e.add(U,S),U=e.sub(X,S),S=e.add(X,S),S=e.mul(U,S),U=e.mul(O,U),I=e.mul(B,I),F=e.mul(d,F),O=e.sub(T,F),O=e.mul(d,O),O=e.add(O,I),I=e.add(T,T),T=e.add(I,T),T=e.add(T,F),T=e.mul(T,O),S=e.add(S,T),F=e.mul(E,R),F=e.add(F,F),T=e.mul(F,O),U=e.sub(U,T),I=e.mul(F,X),I=e.add(I,I),I=e.add(I,I),new h(U,S,I)}add(d){u(d);let{px:y,py:B,pz:g}=this,{px:E,py:R,pz:U}=d,S=e.ZERO,I=e.ZERO,T=e.ZERO,X=t.a,F=e.mul(t.b,Za),O=e.mul(y,E),Q=e.mul(B,R),A=e.mul(g,U),N=e.add(y,B),b=e.add(E,R);N=e.mul(N,b),b=e.add(O,Q),N=e.sub(N,b),b=e.add(y,g);let p=e.add(E,U);return b=e.mul(b,p),p=e.add(O,A),b=e.sub(b,p),p=e.add(B,g),S=e.add(R,U),p=e.mul(p,S),S=e.add(Q,A),p=e.sub(p,S),T=e.mul(X,b),S=e.mul(F,A),T=e.add(S,T),S=e.sub(Q,T),T=e.add(Q,T),I=e.mul(S,T),Q=e.add(O,O),Q=e.add(Q,O),A=e.mul(X,A),b=e.mul(F,b),Q=e.add(Q,A),A=e.sub(O,A),A=e.mul(X,A),b=e.add(b,A),O=e.mul(Q,b),I=e.add(I,O),O=e.mul(p,b),S=e.mul(N,S),S=e.sub(S,O),O=e.mul(N,Q),T=e.mul(p,T),T=e.add(T,O),new h(S,I,T)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){wt("scalar",d,ee,t.n);let y=h.ZERO;if(d===ee)return y;if(d===at)return this;let{endo:B}=t;if(!B)return x.unsafeLadder(this,d);let{k1neg:g,k1:E,k2neg:R,k2:U}=B.splitScalar(d),S=y,I=y,T=this;for(;E>ee||U>ee;)E&at&&(S=S.add(T)),U&at&&(I=I.add(T)),T=T.double(),E>>=at,U>>=at;return g&&(S=S.negate()),R&&(I=I.negate()),I=new h(e.mul(I.px,B.beta),I.py,I.pz),S.add(I)}multiply(d){let{endo:y,n:B}=t;wt("scalar",d,at,B);let g,E;if(y){let{k1neg:R,k1:U,k2neg:S,k2:I}=y.splitScalar(d),{p:T,f:X}=this.wNAF(U),{p:F,f:O}=this.wNAF(I);T=x.constTimeNegate(R,T),F=x.constTimeNegate(S,F),F=new h(e.mul(F.px,y.beta),F.py,F.pz),g=T.add(F),E=X.add(O)}else{let{p:R,f:U}=this.wNAF(d);g=R,E=U}return h.normalizeZ([g,E])[0]}multiplyAndAddUnsafe(d,y,B){let g=h.BASE,E=(U,S)=>S===ee||S===at||!U.equals(g)?U.multiplyUnsafe(S):U.multiply(S),R=E(this,y).add(E(d,B));return R.is0()?void 0:R}toAffine(d){return l(this,d)}isTorsionFree(){let{h:d,isTorsionFree:y}=t;if(d===at)return!0;if(y)return y(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:y}=t;return d===at?this:y?y(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Nt("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Nt("isCompressed",d),$t(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let w=t.nBitLength,x=on(h,t.endo?Math.ceil(w/2):w);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Df(r){let t=Er(r);return _t(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Wa(r){let t=Df(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(A){return j(A,n)}function a(A){return sn(A,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Of({...t,toBytes(A,N,b){let p=N.toAffine(),v=e.toBytes(p.x),C=jt;return Nt("isCompressed",b),b?C(Uint8Array.from([N.hasEvenY()?2:3]),v):C(Uint8Array.from([4]),v,e.toBytes(p.y))},fromBytes(A){let N=A.length,b=A[0],p=A.subarray(1);if(N===s&&(b===2||b===3)){let v=qt(p);if(!vr(v,at,e.ORDER))throw new Error("Point is not on curve");let C=l(v),L;try{L=e.sqrt(C)}catch(P){let K=P instanceof Error?": "+P.message:"";throw new Error("Point is not on curve"+K)}let H=(L&at)===at;return(b&1)===1!==H&&(L=e.neg(L)),{x:v,y:L}}else if(N===o&&b===4){let v=e.fromBytes(p.subarray(0,e.BYTES)),C=e.fromBytes(p.subarray(e.BYTES,2*e.BYTES));return{x:v,y:C}}else throw new Error(`Point of length ${N} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),h=A=>$t(fe(A,t.nByteLength));function w(A){let N=n>>at;return A>N}function x(A){return w(A)?i(-A):A}let m=(A,N,b)=>qt(A.slice(N,b));class d{constructor(N,b,p){this.r=N,this.s=b,this.recovery=p,this.assertValidity()}static fromCompact(N){let b=t.nByteLength;return N=J("compactSignature",N,b*2),new d(m(N,0,b),m(N,b,2*b))}static fromDER(N){let{r:b,s:p}=te.toSig(J("DER",N));return new d(b,p)}assertValidity(){wt("r",this.r,at,n),wt("s",this.s,at,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:b,s:p,recovery:v}=this,C=U(J("msgHash",N));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let L=v===2||v===3?b+t.n:b;if(L>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let H=v&1?"03":"02",D=c.fromHex(H+h(L)),P=a(L),K=i(-C*P),q=i(p*P),z=c.BASE.multiplyAndAddUnsafe(D,K,q);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Se(this.toDERHex())}toDERHex(){return te.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Se(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let y={isValidPrivateKey(A){try{return u(A),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let A=Ps(t.n);return Ei(t.randomBytes(A),t.n)},precompute(A=8,N=c.BASE){return N._setWindowSize(A),N.multiply(BigInt(3)),N}};function B(A,N=!0){return c.fromPrivateKey(A).toRawBytes(N)}function g(A){let N=le(A),b=typeof A=="string",p=(N||b)&&A.length;return N?p===s||p===o:b?p===2*s||p===2*o:A instanceof c}function E(A,N,b=!0){if(g(A))throw new Error("first arg must be private key");if(!g(N))throw new Error("second arg must be public key");return c.fromHex(N).multiply(u(A)).toRawBytes(b)}let R=t.bits2int||function(A){let N=qt(A),b=A.length*8-t.nBitLength;return b>0?N>>BigInt(b):N},U=t.bits2int_modN||function(A){return i(R(A))},S=Br(t.nBitLength);function I(A){return wt(`num < 2^${t.nBitLength}`,A,ee,S),fe(A,t.nByteLength)}function T(A,N,b=X){if(["recovered","canonical"].some(st=>st in b))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:v}=t,{lowS:C,prehash:L,extraEntropy:H}=b;C==null&&(C=!0),A=J("msgHash",A),Ga(b),L&&(A=J("prehashed msgHash",p(A)));let D=U(A),P=u(N),K=[I(P),I(D)];if(H!=null&&H!==!1){let st=H===!0?v(e.BYTES):H;K.push(J("extraEntropy",st))}let q=jt(...K),z=D;function nt(st){let ct=R(st);if(!f(ct))return;let pt=a(ct),tt=c.BASE.multiply(ct).toAffine(),yt=i(tt.x);if(yt===ee)return;let Kt=i(pt*i(z+yt*P));if(Kt===ee)return;let ur=(tt.x===yt?0:2)|Number(tt.y&at),fr=Kt;return C&&w(Kt)&&(fr=x(Kt),ur^=1),new d(yt,fr,ur)}return{seed:q,k2sig:nt}}let X={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function O(A,N,b=X){let{seed:p,k2sig:v}=T(A,N,b),C=t;return Os(C.hash.outputLen,C.nByteLength,C.hmac)(p,v)}c.BASE._setWindowSize(8);function Q(A,N,b,p=F){let v=A;if(N=J("msgHash",N),b=J("publicKey",b),"strict"in p)throw new Error("options.strict was renamed to lowS");Ga(p);let{lowS:C,prehash:L}=p,H,D;try{if(typeof v=="string"||le(v))try{H=d.fromDER(v)}catch(tt){if(!(tt instanceof te.Err))throw tt;H=d.fromCompact(v)}else if(typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint"){let{r:tt,s:yt}=v;H=new d(tt,yt)}else throw new Error("PARSE");D=c.fromHex(b)}catch(tt){if(tt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(C&&H.hasHighS())return!1;L&&(N=t.hash(N));let{r:P,s:K}=H,q=U(N),z=a(K),nt=i(q*z),st=i(P*z),ct=c.BASE.multiplyAndAddUnsafe(D,nt,st)?.toAffine();return ct?i(ct.x)===P:!1}return{CURVE:t,getPublicKey:B,getSharedSecret:E,sign:O,verify:Q,ProjectivePoint:c,Signature:d,utils:y}}function Kf(r){return{hash:r,hmac:(t,...e)=>Pr(r,t,Cs(...e)),randomBytes:Je}}function Ja(r,t){let e=n=>Wa({...r,...Kf(n)});return Object.freeze({...e(t),create:e})}var Qa=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ya=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Mf=BigInt(1),No=BigInt(2),Xa=(r,t)=>(r+t/No)/t;function Pf(r){let t=Qa,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,h=Z(f,e,t)*l%t,w=Z(h,No,t)*u%t,x=Z(w,s,t)*w%t,m=Z(x,o,t)*x%t,d=Z(m,a,t)*m%t,y=Z(d,c,t)*d%t,B=Z(y,a,t)*m%t,g=Z(B,e,t)*l%t,E=Z(g,i,t)*x%t,R=Z(E,n,t)*u%t,U=Z(R,No,t);if(!Co.eql(Co.sqr(U),r))throw new Error("Cannot find square root");return U}var Co=he(Qa,void 0,void 0,{sqrt:Pf}),Rt=Ja({a:BigInt(0),b:BigInt(7),Fp:Co,n:Ya,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ya,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Mf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Xa(o*r,t),c=Xa(-n*r,t),u=j(r-a*e-c*s,t),l=j(-a*n-c*o,t),f=u>i,h=l>i;if(f&&(u=t-u),h&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:u,k2neg:h,k2:l}}}},be),og=BigInt(0);var ig=Rt.ProjectivePoint;function To(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Ht(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function Uo(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function tc(r,t){let e=Xe.digest(t instanceof Uint8Array?t:t.subarray());if(Uo(e))return e.then(({digest:n})=>Rt.sign(n,r).toDERRawBytes()).catch(n=>{throw new hr(String(n))});try{return Rt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new hr(String(n))}}function ec(r,t,e){let n=Xe.digest(e instanceof Uint8Array?e:e.subarray());if(Uo(n))return n.then(({digest:s})=>Rt.verify(t,s,r)).catch(s=>{throw new dr(String(s))});try{return Rt.verify(t,n.digest,r)}catch(s){throw new dr(String(s))}}var ls=class{type="secp256k1";raw;_key;constructor(t){this._key=sc(t),this.raw=rc(this._key)}toMultihash(){return xr.digest(un(this))}toCID(){return Lt.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}verify(t,e){return ec(this._key,e,t)}},us=class{type="secp256k1";raw;publicKey;constructor(t,e){this.raw=nc(t),this.publicKey=new ls(e??oc(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Pt(this.raw,t.raw)}sign(t){return tc(this.raw,t)}};function Ro(r){return new us(r)}function rc(r){return Rt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function nc(r){try{return Rt.getPublicKey(r,!0),r}catch(t){throw new pr(String(t))}}function sc(r){try{return Rt.ProjectivePoint.fromHex(r),r}catch(t){throw new De(String(t))}}function oc(r){try{return Rt.getPublicKey(r,!0)}catch(t){throw new pr(String(t))}}function un(r){return ge.encode({Type:it[r.type],Data:r.raw})}function ic(r){let t=Tr.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case it.RSA:return as(e);case it.Ed25519:return zs(e);case it.secp256k1:return Ro(e);default:throw new Ke}}function ac(r){return r.byteLength===64?zs(r):r.byteLength===32?Ro(r):as(r)}function sr(r){return Tr.encode({Type:it[r.type],Data:r.raw})}function cc(r,t,e,n){Yr(r);let s=gi({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(je(o),je(i),je(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=se(t),u=se(e),l=new Uint8Array(i),f=Pr.create(r,c),h=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:h}}function lc(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}function uc(r,t,e,n){let{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=cc(r,t,e,n),u,l=new Uint8Array(4),f=Ae(l),h=new Uint8Array(a.outputLen);for(let w=1,x=0;x<o;w++,x+=a.outputLen){let m=i.subarray(x,x+a.outputLen);f.setInt32(0,w,!1),(u=c._cloneInto(u)).update(l).digestInto(h),m.set(h.subarray(0,m.length));for(let d=1;d<s;d++){a._cloneInto(u).update(h).digestInto(h);for(let y=0;y<m.length;y++)m[y]^=h[y]}}return lc(a,c,i,u,h)}async function fs(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:u}=cc(r,t,e,n),l,f=new Uint8Array(4),h=Ae(f),w=new Uint8Array(c.outputLen);for(let x=1,m=0;m<o;x++,m+=c.outputLen){let d=a.subarray(m,m+c.outputLen);h.setInt32(0,x,!1),(l=u._cloneInto(l)).update(f).digestInto(w),d.set(w.subarray(0,d.length)),await di(s-1,i,()=>{c._cloneInto(l).update(w).digestInto(w);for(let y=0;y<d.length;y++)d[y]^=w[y]})}return lc(c,u,a,l,w)}var Fr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),ve=new Uint32Array(80),Lo=class extends oe{constructor(){super(64,20,8,!1),this.A=Fr[0]|0,this.B=Fr[1]|0,this.C=Fr[2]|0,this.D=Fr[3]|0,this.E=Fr[4]|0}get(){let{A:t,B:e,C:n,D:s,E:o}=this;return[t,e,n,s,o]}set(t,e,n,s,o){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)ve[c]=t.getUint32(e,!1);for(let c=16;c<80;c++)ve[c]=Xr(ve[c-3]^ve[c-8]^ve[c-14]^ve[c-16],1);let{A:n,B:s,C:o,D:i,E:a}=this;for(let c=0;c<80;c++){let u,l;c<20?(u=Qr(s,o,i),l=1518500249):c<40?(u=s^o^i,l=1859775393):c<60?(u=tn(s,o,i),l=2400959708):(u=s^o^i,l=3395469782);let f=Xr(n,5)+u+a+l+ve[c]|0;a=i,i=o,o=Xr(s,30),s=n,n=f}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,s,o,i,a)}roundClean(){ve.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},fc=We(()=>new Lo);var hc={sha1:fc,"sha2-256":be,"sha2-512":ce};function $r(r,t,e,n,s){if(s!=="sha1"&&s!=="sha2-256"&&s!=="sha2-512"){let a=Object.keys(hc).join(" / ");throw new _(`Hash '${s}' is unknown or not supported. Must be ${a}`)}let o=hc[s],i=uc(o,r,t,{c:e,dkLen:n});return Ue.encode(i).substring(1)}var re="/",dc=new TextEncoder().encode(re),hs=dc[0],qr=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=$(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]!==hs)throw new Error("Invalid key")}toString(t="utf8"){return Bt(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(re))}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]!==hs){let t=new Uint8Array(this._buf.byteLength+1);t.fill(hs,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===hs;)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 o=e[s],i=n[s];if(o<i)return!0;if(o>i)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(re).slice(1)}type(){return Ff(this.baseNamespace())}name(){return $f(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(re)||(t+=re),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(re):new r(t.slice(0,-1).join(re))}child(t){return this.toString()===re?t:t.toString()===re?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(),...qf(t.map(e=>e.namespaces()))])}};function Ff(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function $f(r){let t=r.split(":");return t[t.length-1]}function qf(r){return[].concat(...r)}var Bc=bs(vc(),1),Ec=Bc.default;var Vc=bs(Rc(),1);var ar={};ft(ar,{create:()=>ch,derivedEmptyPasswordKey:()=>gs});var gs={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function ch(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=bt.get();e*=8;async function c(f,h){let w=a.getRandomValues(new Uint8Array(o)),x=a.getRandomValues(new Uint8Array(n)),m={name:t,iv:x};typeof h=="string"&&(h=$(h));let d;if(h.length===0){d=await a.subtle.importKey("jwk",gs,{name:"AES-GCM"},!0,["encrypt"]);try{let B={name:"PBKDF2",salt:w,iterations:i,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(B,g,{name:t,length:e},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",gs,{name:"AES-GCM"},!0,["encrypt"])}}else{let B={name:"PBKDF2",salt:w,iterations:i,hash:{name:s}},g=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(B,g,{name:t,length:e},!0,["encrypt"])}let y=await a.subtle.encrypt(m,d,f);return To([w,m.iv,new Uint8Array(y)])}async function u(f,h){let w=f.subarray(0,o),x=f.subarray(o,o+n),m=f.subarray(o+n),d={name:t,iv:x};typeof h=="string"&&(h=$(h));let y;if(h.length===0)try{let g={name:"PBKDF2",salt:w,iterations:i,hash:{name:s}},E=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(g,E,{name:t,length:e},!0,["decrypt"])}catch{y=await a.subtle.importKey("jwk",gs,{name:"AES-GCM"},!0,["decrypt"])}else{let g={name:"PBKDF2",salt:w,iterations:i,hash:{name:s}},E=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(g,E,{name:t,length:e},!0,["decrypt"])}let B=await a.subtle.decrypt(d,y,m);return new Uint8Array(B)}return{encrypt:c,decrypt:u}}async function Ho(r,t){let n=await ar.create().encrypt(r,t);return Ue.encode(n)}async function Vo(r,t,e){if(r.type==="RSA")return fh(r,t,e);if(r.type==="Ed25519")return lh(r,t,e);if(r.type==="secp256k1")return uh(r,t,e);throw new Ke}async function lh(r,t,e="libp2p-key"){if(e==="libp2p-key")return Ho(sr(r),t);throw new _(`export format '${e}' is not supported`)}async function uh(r,t,e="libp2p-key"){if(e==="libp2p-key")return Ho(sr(r),t);throw new _("Export format is not supported")}async function fh(r,t,e="pkcs-8"){if(e==="pkcs-8")return hh(r,t);if(e==="libp2p-key")return Ho(sr(r),t);throw new _("Export format is not supported")}async function hh(r,t){let e=bt.get(),s=new rt({value:[new Y({value:0}),new rt({value:[new kt({value:"1.2.840.113549.1.1.1"}),new Wt]}),new Jt({valueHex:r.raw})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=He(16),a=await fs(ce,t,i,{c:1e4,dkLen:32}),c=He(16),u=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await e.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new rt({value:[new Jt({valueHex:i}),new Y({value:1e4}),new Y({value:32}),new rt({value:[new kt({value:"1.2.840.113549.2.11"}),new Wt]})]}),h=new rt({value:[new kt({value:"1.2.840.113549.1.5.13"}),new rt({value:[new rt({value:[new kt({value:"1.2.840.113549.1.5.12"}),f]}),new rt({value:[new kt({value:"2.16.840.1.101.3.4.1.42"}),new Jt({valueHex:c})]})]})]}),x=new rt({value:[h,new Jt({valueHex:l})]}).toBER(),m=new Uint8Array(x,0,x.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Bt(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
- `)}async function Oo(r,t){try{let e=await dh(r,t);return ic(e)}catch{}if(!r.includes("BEGIN"))throw new _("Encrypted key was not a libp2p-key or a PEM file");return ph(r,t)}async function dh(r,t){let e=Ue.decode(r);return ar.create().decrypt(e,t)}async function ph(r,t){let e=bt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=$(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=_e(o),{iv:a,salt:c,iterations:u,keySize:l,cipherText:f}=gh(i),h=await fs(ce,t,c,{c:u,dkLen:l}),w=await e.subtle.importKey("raw",h,"AES-CBC",!1,["decrypt"]),x=jr(await e.subtle.decrypt({name:"AES-CBC",iv:a},w,f)),{result:m}=_e(x);n=Hc(m)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=$(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=_e(o);n=Hc(i)}else throw new _("Could not parse private key from PEM data");let s=ac(n);if(s.type!=="RSA")throw new _("Could not parse RSA private key from PEM data");return s}function gh(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new _("Only pkcs5PBES2 encrypted private keys are supported");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 _("Only pkcs5PBKDF2 key derivation functions are supported");let o=n.valueBlock.value[1],i=jr(o.valueBlock.value[0].getValue()),a=1e4,c=32;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new _("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key");let u=t.valueBlock.value[1].valueBlock.value[1],l=u.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 _("Only AES-CBC encryption schemes are supported")}}}}let f=jr(u.valueBlock.value[1].getValue());return{cipherText:jr(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function Hc(r){return jr(r.valueBlock.value[2].getValue())}function jr(r){return new Uint8Array(r,0,r.byteLength)}var mh="/pkcs8/",Ko="/info/",zr=new WeakMap,Ve={minKeyLength:112/8,minSaltLength:128/8,minIterationCount:1e3},Do={dek:{keyLength:512/8,iterationCount:1e4,salt:"you should override this value with a crypto secure random number",hash:"sha2-512"}};function cr(r){return r==null||typeof r!="string"?!1:r===(0,Vc.default)(r.trim())&&r.length>0}async function ut(){let e=Math.random()*800+200;await new Promise(n=>setTimeout(n,e))}function Oe(r){return new qr(mh+r)}function lr(r){return new qr(Ko+r)}async function yh(r){let t=sr(r),e=await Xe.digest(t);return ot.encode(e.bytes).substring(1)}var ms=class{components;init;log;constructor(t,e){if(this.components=t,this.log=t.logger.forComponent("libp2p:keychain"),this.init=Ec(Do,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<Ve.minKeyLength)throw new Error(`dek.keyLength must be least ${Ve.minKeyLength} bytes`);if(this.init.dek?.salt?.length!=null&&this.init.dek.salt.length<Ve.minSaltLength)throw new Error(`dek.saltLength must be least ${Ve.minSaltLength} bytes`);if(this.init.dek?.iterationCount!=null&&this.init.dek.iterationCount<Ve.minIterationCount)throw new Error(`dek.iterationCount must be least ${Ve.minIterationCount}`);let n=this.init.pass!=null&&this.init.dek?.salt!=null?$r(this.init.pass,this.init.dek?.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";zr.set(this,{dek:n})}[Symbol.toStringTag]="@libp2p/keychain";[Wo]=["@libp2p/keychain"];static generateOptions(){let t=Object.assign({},Do),e=Math.ceil(Ve.minSaltLength/3)*3;return t.dek.salt=Bt(He(e),"base64"),t}static get options(){return Do}async findKeyByName(t){if(!cr(t))throw await ut(),new _(`Invalid key name '${t}'`);let e=lr(t);try{let n=await this.components.datastore.get(e);return JSON.parse(Bt(n))}catch(n){throw await ut(),this.log.error(n),new Wr(`Key '${t}' does not exist.`)}}async findKeyById(t){try{let e={prefix:Ko};for await(let n of this.components.datastore.query(e)){let s=JSON.parse(Bt(n.value));if(s.id===t)return s}throw new _(`Key with id '${t}' does not exist.`)}catch(e){throw await ut(),e}}async importKey(t,e){if(!cr(t))throw await ut(),new _(`Invalid key name '${t}'`);if(e==null)throw await ut(),new _("Key is required");let n=Oe(t);if(await this.components.datastore.has(n))throw await ut(),new _(`Key '${t}' already exists`);let o,i;try{o=await yh(e);let u=zr.get(this);if(u==null)throw new _("dek missing");let l=u.dek;i=await Vo(e,l,e.type==="RSA"?"pkcs-8":"libp2p-key")}catch(u){throw await ut(),u}let a={name:t,id:o},c=this.components.datastore.batch();return c.put(n,$(i)),c.put(lr(t),$(JSON.stringify(a))),await c.commit(),a}async exportKey(t){if(!cr(t))throw await ut(),new _(`Invalid key name '${t}'`);let e=Oe(t);try{let n=await this.components.datastore.get(e),s=Bt(n),o=zr.get(this);if(o==null)throw new _("dek missing");let i=o.dek;return await Oo(s,i)}catch(n){throw await ut(),n}}async removeKey(t){if(!cr(t)||t==="self")throw await ut(),new _(`Invalid key name '${t}'`);let e=Oe(t),n=await this.findKeyByName(t),s=this.components.datastore.batch();return s.delete(e),s.delete(lr(t)),await s.commit(),n}async listKeys(){let t={prefix:Ko},e=[];for await(let n of this.components.datastore.query(t))e.push(JSON.parse(Bt(n.value)));return e}async renameKey(t,e){if(!cr(t)||t==="self")throw await ut(),new _(`Invalid old key name '${t}'`);if(!cr(e)||e==="self")throw await ut(),new _(`Invalid new key name '${e}'`);let n=Oe(t),s=Oe(e),o=lr(t),i=lr(e);if(await this.components.datastore.has(s))throw await ut(),new _(`Key '${e}' already exists`);try{let c=await this.components.datastore.get(n),u=await this.components.datastore.get(o),l=JSON.parse(Bt(u));l.name=e;let f=this.components.datastore.batch();return f.put(s,c),f.put(i,$(JSON.stringify(l))),f.delete(n),f.delete(o),await f.commit(),l}catch(c){throw await ut(),c}}async rotateKeychainPass(t,e){if(typeof t!="string")throw await ut(),new _(`Invalid old pass type '${typeof t}'`);if(typeof e!="string")throw await ut(),new _(`Invalid new pass type '${typeof e}'`);if(e.length<20)throw await ut(),new _(`Invalid pass length ${e.length}`);this.log("recreating keychain");let n=zr.get(this);if(n==null)throw new _("dek missing");let s=n.dek;this.init.pass=e;let o=e!=null&&this.init.dek?.salt!=null?$r(e,this.init.dek.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";zr.set(this,{dek:o});let i=await this.listKeys();for(let a of i){let c=await this.components.datastore.get(Oe(a.name)),u=Bt(c),l=await Oo(u,s),f=o.toString(),h=await Vo(l,f,l.type==="RSA"?"pkcs-8":"libp2p-key"),w=this.components.datastore.batch(),x={name:a.name,id:a.id};w.put(Oe(a.name),$(h)),w.put(lr(a.name),$(JSON.stringify(x))),await w.commit()}this.log("keychain reconstructed")}};function bh(r={}){return t=>new ms(t,r)}return Jc(wh);})();
6
+ `)}`:`${e} :`}};Da=ve;I.Constructed=Da;ve.NAME="CONSTRUCTED";var Pn=class extends pt{fromBER(t,e,n){return e}toBER(t){return Rt}};Pn.override="EndOfContentValueBlock";var Ka,qn=class extends lt{constructor(t={}){super(t,Pn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Ka=qn;I.EndOfContent=Ka;qn.NAME=jr;var Ma,Xt=class extends lt{constructor(t={}){super(t,pt),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}`}};Ma=Xt;I.Null=Ma;Xt.NAME="NULL";var jn=class extends re(pt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=P.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=P.BufferSourceConverter.toUint8Array(t);return ee(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,Ko.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var Fa,Gn=class extends lt{constructor(t={}){super(t,jn),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}`}};Fa=Gn;I.Boolean=Fa;Gn.NAME="BOOLEAN";var $n=class extends re(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 o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===jr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==Ha)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}}};$n.NAME="OctetStringValueBlock";var Pa,Qt=class r extends lt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},$n),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 o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=ws(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ve.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${P.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 P.BufferSourceConverter.concat(t)}};Pa=Qt;I.OctetString=Pa;Qt.NAME=Ha;var zn=class extends re(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===jr){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==_a)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 o=P.BufferSourceConverter.toUint8Array(t);if(!ee(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=i.subarray(1);try{if(a.byteLength){let c=ws(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.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 Rt;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}}};zn.NAME="BitStringValueBlock";var qa,ur=class extends lt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},zn),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 ve.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)}`}}};qa=ur;I.BitString=qa;ur.NAME=_a;var ja;function dh(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,f=0,u=c<i?i:c,l=0;for(let h=u;h>=0;h--,l++){switch(!0){case l<a.length:f=o[i-l]+a[c-l]+e[0];break;default:f=o[i-l]+e[0]}switch(e[0]=f/10,!0){case l>=o.length:o=_n(new Uint8Array([f%10]),o);break;default:o[i-l]=f%10}}return e[0]>0&&(o=_n(e,o)),o}function Ra(r){if(r>=Pr.length)for(let t=Pr.length;t<=r;t++){let e=new Uint8Array([0]),n=Pr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=_n(e,n)),Pr.push(n)}return Pr[r]}function ph(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=o[i-u]-a[c-u]-e,!0){case f<0:e=1,o[i-u]=f+10;break;default:e=0,o[i-u]=f}if(e>0)for(let l=i-c+1;l>=0;l--,u++)if(f=o[i-u]-e,f<0)e=1,o[i-u]=f+10;else{e=0,o[i-u]=f;break}return o.slice()}var Gr=class extends re(pt){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=Ko.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ta(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}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,o=this.valueHexView,i="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let f=0;f<8;f++){if((s&1)===1)switch(n){case t:e=ph(Ra(n),e),i="-";break;default:e=dh(e,Ra(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=La.charAt(e[c]));return a===!1&&(i+=La.charAt(0)),i}};ja=Gr;Gr.NAME="IntegerValueBlock";Object.defineProperty(ja.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ga,tt=class r extends lt{constructor(t={}){super(t,Gr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return On(),BigInt(this.valueBlock.toString())}static fromBigInt(t){On();let e=BigInt(t),n=new qr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(P.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${P.Convert.ToHex(a)}`)+e,u=P.BufferSourceConverter.toUint8Array(P.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);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()}`}};Ga=tt;I.Integer=Ga;tt.NAME="INTEGER";var $a,Wn=class extends tt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};$a=Wn;I.Enumerated=$a;Wn.NAME="ENUMERATED";var $r=class extends re(pt){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=P.BufferSourceConverter.toUint8Array(t);if(!ee(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[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=Ke(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){On();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,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Rt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=P.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}}};$r.NAME="sidBlock";var Zn=class extends pt{constructor({value:t=fr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new $r;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}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,Rt;e.push(s)}return Mo(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,o){let i=this.value[0],a=0;switch(i.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;i.valueDec=c+a,o=!1}else{let i=new $r;if(s>Number.MAX_SAFE_INTEGER){On();let a=BigInt(s);i.valueBigInt=a}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}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}};Zn.NAME="ObjectIdentifierValueBlock";var za,kt=class extends lt{constructor(t={}){super(t,Zn),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()}}};za=kt;I.ObjectIdentifier=za;kt.NAME="OBJECT IDENTIFIER";var zr=class extends re(Yt){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=P.BufferSourceConverter.toUint8Array(t);if(!ee(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];return this.valueHexView=i,o[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=Ke(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,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=we(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Rt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=P.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};zr.NAME="relativeSidBlock";var Jn=class extends pt{constructor({value:t=fr,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new zr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Rt;n.push(o)}return Mo(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 o=new zr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}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}};Jn.NAME="RelativeObjectIdentifierValueBlock";var Wa,Yn=class extends lt{constructor(t={}){super(t,Jn),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()}}};Wa=Yn;I.RelativeObjectIdentifier=Wa;Yn.NAME="RelativeObjectIdentifier";var Za,rt=class extends ve{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Za=rt;I.Sequence=Za;rt.NAME="SEQUENCE";var Ja,Xn=class extends ve{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ja=Xn;I.Set=Ja;Xn.NAME="SET";var Qn=class extends re(pt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=fr}toJSON(){return{...super.toJSON(),value:this.value}}};Qn.NAME="StringValueBlock";var ts=class extends Qn{};ts.NAME="SimpleStringValueBlock";var xt=class extends Kn{constructor({...t}={}){super(t,ts)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,P.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 es=class extends xt{fromBuffer(t){this.valueBlock.valueHexView=P.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=P.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=P.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(P.Convert.FromUtf8String(t)),this.valueBlock.value=t}};es.NAME="Utf8StringValueBlock";var Ya,te=class extends es{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Ya=te;I.Utf8String=Ya;te.NAME="UTF8String";var rs=class extends xt{fromBuffer(t){this.valueBlock.value=P.Convert.ToUtf16String(t),this.valueBlock.valueHexView=P.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(P.Convert.FromUtf16String(t))}};rs.NAME="BmpStringValueBlock";var Xa,ns=class extends rs{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Xa=ns;I.BmpString=Xa;ns.NAME="BMPString";var ss=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 o=we(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};ss.NAME="UniversalStringValueBlock";var Qa,os=class extends ss{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Qa=os;I.UniversalString=Qa;os.NAME="UniversalString";var tc,is=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};tc=is;I.NumericString=tc;is.NAME="NumericString";var ec,as=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};ec=as;I.PrintableString=ec;as.NAME="PrintableString";var rc,cs=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};rc=cs;I.TeletexString=rc;cs.NAME="TeletexString";var nc,ls=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};nc=ls;I.VideotexString=nc;ls.NAME="VideotexString";var sc,us=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};sc=us;I.IA5String=sc;us.NAME="IA5String";var oc,fs=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};oc=fs;I.GraphicString=oc;fs.NAME="GraphicString";var ic,Wr=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};ic=Wr;I.VisibleString=ic;Wr.NAME="VisibleString";var ac,hs=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};ac=hs;I.GeneralString=ac;hs.NAME="GeneralString";var cc,ds=class extends xt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};cc=ds;I.CharacterString=cc;ds.NAME="CharacterString";var lc,Zr=class extends Wr{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,P.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]=Bt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Bt(this.month,2),e[2]=Bt(this.day,2),e[3]=Bt(this.hour,2),e[4]=Bt(this.minute,2),e[5]=Bt(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}}};lc=Zr;I.UTCTime=lc;Zr.NAME="UTCTime";var uc,ps=class extends Zr{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="",o=0,i,a=0,c=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let l=new Number(t[t.length-1]);if(isNaN(l.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 l=1,h=n.indexOf("+"),g="";if(h===-1&&(h=n.indexOf("-"),l=-1),h!==-1){if(g=n.substring(h+1),n=n.substring(0,h),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let x=parseInt(g.substring(0,2),10);if(isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*x,g.length===4){if(x=parseInt(g.substring(2,4),10),isNaN(x.valueOf()))throw new Error("Wrong input string for conversion");c=l*x}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");o=l.valueOf(),s=n.substring(0,f)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*o;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*o;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*o;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Bt(this.year,4)),e.push(Bt(this.month,2)),e.push(Bt(this.day,2)),e.push(Bt(this.hour,2)),e.push(Bt(this.minute,2)),e.push(Bt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Bt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};uc=ps;I.GeneralizedTime=uc;ps.NAME="GeneralizedTime";var fc,gs=class extends te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};fc=gs;I.DATE=fc;gs.NAME="DATE";var hc,ms=class extends te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};hc=ms;I.TimeOfDay=hc;ms.NAME="TimeOfDay";var dc,xs=class extends te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};dc=xs;I.DateTime=dc;xs.NAME="DateTime";var pc,ys=class extends te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};pc=ys;I.Duration=pc;ys.NAME="Duration";var gc,bs=class extends te{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};gc=bs;I.TIME=gc;bs.NAME="TIME";function Et(r,t="utf8"){let e=An[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}function Fe(r){if(isNaN(r)||r<=0)throw new _("random bytes length must be a Number bigger than 0");return Ca(r)}async function mc(r){let t=await bt.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 gh(t);return{privateKey:e[0],publicKey:e[1]}}async function xc(r,t){let e=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function yc(r,t,e){let n=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function gh(r){if(r.privateKey==null||r.publicKey==null)throw new _("Private and public key are required");return Promise.all([bt.get().subtle.exportKey("jwk",r.privateKey),bt.get().subtle.exportKey("jwk",r.publicKey)])}function qo(r){if(r.kty!=="RSA")throw new _("invalid key type");if(r.n==null)throw new _("invalid key modulus");return j(r.n,"base64url").length*8}var hr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return Ot.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}verify(t,e){return yc(this._key,e,t)}},Yr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}sign(t){return xc(this._key,t)}};var vs=8192,jo=18;function bc(r){let{result:t}=Me(r),e=t.valueBlock.value;return{n:Mt(e[1]),e:Mt(e[2]),d:Mt(e[3]),p:Mt(e[4]),q:Mt(e[5]),dp:Mt(e[6]),dq:Mt(e[7]),qi:Mt(e[8]),kty:"RSA",alg:"RS256"}}function mh(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 _("JWK was missing components");let e=new rt({value:[new tt({value:0}),tt.fromBigInt(Ft(j(r.n,"base64url"))),tt.fromBigInt(Ft(j(r.e,"base64url"))),tt.fromBigInt(Ft(j(r.d,"base64url"))),tt.fromBigInt(Ft(j(r.p,"base64url"))),tt.fromBigInt(Ft(j(r.q,"base64url"))),tt.fromBigInt(Ft(j(r.dp,"base64url"))),tt.fromBigInt(Ft(j(r.dq,"base64url"))),tt.fromBigInt(Ft(j(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function wc(r){let{result:t}=Me(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:Mt(e[0]),e:Mt(e[1])}}function Go(r){if(r.n==null||r.e==null)throw new _("JWK was missing components");let e=new rt({value:[new rt({value:[new kt({value:"1.2.840.113549.1.1.1"}),new Xt]}),new ur({valueHex:new rt({value:[tt.fromBigInt(Ft(j(r.n,"base64url"))),tt.fromBigInt(Ft(j(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Mt(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Et(t,"base64url")}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(""))}function Bs(r){let t=bc(r);return Bc(t)}function vc(r){let t=wc(r);if(qo(t)>vs)throw new je("Key size is too large");let e=cr(ge.encode({Type:it.RSA,Data:r})),n=It(jo,e);return new hr(t,n)}function Bc(r){if(qo(r)>vs)throw new _("Key size is too large");let t=Ac(r),e=cr(ge.encode({Type:it.RSA,Data:Go(t.publicKey)})),n=It(jo,e);return new Yr(t.privateKey,new hr(t.publicKey,n))}async function Ec(r){if(r>vs)throw new _("Key size is too large");let t=await mc(r),e=cr(ge.encode({Type:it.RSA,Data:Go(t.publicKey)})),n=It(jo,e);return new Yr(t.privateKey,new hr(t.publicKey,n))}function Ac(r){if(r==null)throw new _("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var xh=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]),Ee=new Uint32Array(64),$o=class extends tr{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:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)Ee[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let h=Ee[l-15],g=Ee[l-2],x=Ct(h,7)^Ct(h,18)^h>>>3,m=Ct(g,17)^Ct(g,19)^g>>>10;Ee[l]=m+Ee[l-7]+x+Ee[l-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Ct(a,6)^Ct(a,11)^Ct(a,25),g=u+h+Ki(a,c,f)+xh[l]+Ee[l]|0,m=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Mi(n,s,o)|0;u=f,f=c,c=a,a=i+g|0,i=o,o=s,s=n,n=g+m|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,f,u)}roundClean(){Ee.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Sc=ln(()=>new $o);var Es=class extends Qe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Oi(t);let n=Tr(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,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return Xe(this),this.iHash.update(t),this}digestInto(t){Xe(this),Ye(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:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,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()}},zo=(r,t,e)=>new Es(r,t).update(e).digest();zo.create=(r,t)=>new Es(r,t);function kc(r){r.lowS!==void 0&&Nt("lowS",r.lowS),r.prehash!==void 0&&Nt("prehash",r.prehash)}function yh(r){let t=Rr(r);Vt(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("invalid 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("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:bh,hexToBytes:wh}=pn,ne={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=ne;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=Ne(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?Ne(s.length/2|128):"";return Ne(r)+o+s+t},decode(r,t){let{Err:e}=ne,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ne;if(r<se)throw new t("integer: negative integers are not allowed");let e=Ne(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=ne;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return bh(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ne,s=typeof r=="string"?wh(r):r;er(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=ne,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},se=BigInt(0),at=BigInt(1),dm=BigInt(2),Ic=BigInt(3),pm=BigInt(4);function vh(r){let t=yh(r),{Fp:e}=t,n=he(t.n,t.nBitLength),s=t.toBytes||((m,d,b)=>{let B=d.toAffine();return Wt(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),o=t.fromBytes||(m=>{let d=m.subarray(1),b=e.fromBytes(d.subarray(0,e.BYTES)),B=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:b,y:B}});function i(m){let{a:d,b}=t,B=e.sqr(m),p=e.mul(B,m);return e.add(e.add(p,e.mul(m,d)),b)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function a(m){return Ur(m,at,t.n)}function c(m){let{allowedPrivateKeyLengths:d,nByteLength:b,wrapPrivateKey:B,n:p}=t;if(d&&typeof m!="bigint"){if(le(m)&&(m=$t(m)),typeof m!="string"||!d.includes(m.length))throw new Error("invalid private key");m=m.padStart(b*2,"0")}let E;try{E=typeof m=="bigint"?m:zt(X("private key",m,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof m)}return B&&(E=z(E,p)),wt("private key",E,at,p),E}function f(m){if(!(m instanceof h))throw new Error("ProjectivePoint expected")}let u=Le((m,d)=>{let{px:b,py:B,pz:p}=m;if(e.eql(p,e.ONE))return{x:b,y:B};let E=m.is0();d==null&&(d=E?e.ONE:e.inv(p));let U=e.mul(b,d),L=e.mul(B,d),C=e.mul(p,d);if(E)return{x:e.ZERO,y:e.ZERO};if(!e.eql(C,e.ONE))throw new Error("invZ was invalid");return{x:U,y:L}}),l=Le(m=>{if(m.is0()){if(t.allowInfinityPoint&&!e.is0(m.py))return;throw new Error("bad point: ZERO")}let{x:d,y:b}=m.toAffine();if(!e.isValid(d)||!e.isValid(b))throw new Error("bad point: x or y not FE");let B=e.sqr(b),p=i(d);if(!e.eql(B,p))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,b,B){if(this.px=d,this.py=b,this.pz=B,d==null||!e.isValid(d))throw new Error("x required");if(b==null||!e.isValid(b))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:b,y:B}=d||{};if(!d||!e.isValid(b)||!e.isValid(B))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let p=E=>e.eql(E,e.ZERO);return p(b)&&p(B)?h.ZERO:new h(b,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let b=e.invertBatch(d.map(B=>B.pz));return d.map((B,p)=>B.toAffine(b[p])).map(h.fromAffine)}static fromHex(d){let b=h.fromAffine(o(X("pointHex",d)));return b.assertValidity(),b}static fromPrivateKey(d){return h.BASE.multiply(c(d))}static msm(d,b){return yn(h,n,d,b)}_setWindowSize(d){x.setWindowSize(this,d)}assertValidity(){l(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){f(d);let{px:b,py:B,pz:p}=this,{px:E,py:U,pz:L}=d,C=e.eql(e.mul(b,L),e.mul(E,p)),k=e.eql(e.mul(B,L),e.mul(U,p));return C&&k}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b}=t,B=e.mul(b,Ic),{px:p,py:E,pz:U}=this,L=e.ZERO,C=e.ZERO,k=e.ZERO,A=e.mul(p,p),G=e.mul(E,E),F=e.mul(U,U),K=e.mul(p,E);return K=e.add(K,K),k=e.mul(p,U),k=e.add(k,k),L=e.mul(d,k),C=e.mul(B,F),C=e.add(L,C),L=e.sub(G,C),C=e.add(G,C),C=e.mul(L,C),L=e.mul(K,L),k=e.mul(B,k),F=e.mul(d,F),K=e.sub(A,F),K=e.mul(d,K),K=e.add(K,k),k=e.add(A,A),A=e.add(k,A),A=e.add(A,F),A=e.mul(A,K),C=e.add(C,A),F=e.mul(E,U),F=e.add(F,F),A=e.mul(F,K),L=e.sub(L,A),k=e.mul(F,G),k=e.add(k,k),k=e.add(k,k),new h(L,C,k)}add(d){f(d);let{px:b,py:B,pz:p}=this,{px:E,py:U,pz:L}=d,C=e.ZERO,k=e.ZERO,A=e.ZERO,G=t.a,F=e.mul(t.b,Ic),K=e.mul(b,E),Y=e.mul(B,U),S=e.mul(p,L),T=e.add(b,B),w=e.add(E,U);T=e.mul(T,w),w=e.add(K,Y),T=e.sub(T,w),w=e.add(b,p);let y=e.add(E,L);return w=e.mul(w,y),y=e.add(K,S),w=e.sub(w,y),y=e.add(B,p),C=e.add(U,L),y=e.mul(y,C),C=e.add(Y,S),y=e.sub(y,C),A=e.mul(G,w),C=e.mul(F,S),A=e.add(C,A),C=e.sub(Y,A),A=e.add(Y,A),k=e.mul(C,A),Y=e.add(K,K),Y=e.add(Y,K),S=e.mul(G,S),w=e.mul(F,w),Y=e.add(Y,S),S=e.sub(K,S),S=e.mul(G,S),w=e.add(w,S),K=e.mul(Y,w),k=e.add(k,K),K=e.mul(y,w),C=e.mul(T,C),C=e.sub(C,K),K=e.mul(T,Y),A=e.mul(y,A),A=e.add(A,K),new h(C,k,A)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return x.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:b,n:B}=t;wt("scalar",d,se,B);let p=h.ZERO;if(d===se)return p;if(this.is0()||d===at)return this;if(!b||x.hasPrecomputes(this))return x.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:E,k1:U,k2neg:L,k2:C}=b.splitScalar(d),k=p,A=p,G=this;for(;U>se||C>se;)U&at&&(k=k.add(G)),C&at&&(A=A.add(G)),G=G.double(),U>>=at,C>>=at;return E&&(k=k.negate()),L&&(A=A.negate()),A=new h(e.mul(A.px,b.beta),A.py,A.pz),k.add(A)}multiply(d){let{endo:b,n:B}=t;wt("scalar",d,at,B);let p,E;if(b){let{k1neg:U,k1:L,k2neg:C,k2:k}=b.splitScalar(d),{p:A,f:G}=this.wNAF(L),{p:F,f:K}=this.wNAF(k);A=x.constTimeNegate(U,A),F=x.constTimeNegate(C,F),F=new h(e.mul(F.px,b.beta),F.py,F.pz),p=A.add(F),E=G.add(K)}else{let{p:U,f:L}=this.wNAF(d);p=U,E=L}return h.normalizeZ([p,E])[0]}multiplyAndAddUnsafe(d,b,B){let p=h.BASE,E=(L,C)=>C===se||C===at||!L.equals(p)?L.multiplyUnsafe(C):L.multiply(C),U=E(this,b).add(E(d,B));return U.is0()?void 0:U}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:b}=t;if(d===at)return!0;if(b)return b(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:b}=t;return d===at?this:b?b(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Nt("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Nt("isCompressed",d),$t(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,x=xn(h,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:a}}function Bh(r){let t=Rr(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Cc(r){let t=Bh(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(S){return z(S,n)}function a(S){return gn(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=vh({...t,toBytes(S,T,w){let y=T.toAffine(),v=e.toBytes(y.x),N=Wt;return Nt("isCompressed",w),w?N(Uint8Array.from([T.hasEvenY()?2:3]),v):N(Uint8Array.from([4]),v,e.toBytes(y.y))},fromBytes(S){let T=S.length,w=S[0],y=S.subarray(1);if(T===s&&(w===2||w===3)){let v=zt(y);if(!Ur(v,at,e.ORDER))throw new Error("Point is not on curve");let N=u(v),R;try{R=e.sqrt(N)}catch(q){let O=q instanceof Error?": "+q.message:"";throw new Error("Point is not on curve"+O)}let H=(R&at)===at;return(w&1)===1!==H&&(R=e.neg(R)),{x:v,y:R}}else if(T===o&&w===4){let v=e.fromBytes(y.subarray(0,e.BYTES)),N=e.fromBytes(y.subarray(e.BYTES,2*e.BYTES));return{x:v,y:N}}else{let v=s,N=o;throw new Error("invalid Point, expected length of "+v+", or uncompressed "+N+", got "+T)}}}),h=S=>$t(fe(S,t.nByteLength));function g(S){let T=n>>at;return S>T}function x(S){return g(S)?i(-S):S}let m=(S,T,w)=>zt(S.slice(T,w));class d{constructor(T,w,y){this.r=T,this.s=w,this.recovery=y,this.assertValidity()}static fromCompact(T){let w=t.nByteLength;return T=X("compactSignature",T,w*2),new d(m(T,0,w),m(T,w,2*w))}static fromDER(T){let{r:w,s:y}=ne.toSig(X("DER",T));return new d(w,y)}assertValidity(){wt("r",this.r,at,n),wt("s",this.s,at,n)}addRecoveryBit(T){return new d(this.r,this.s,T)}recoverPublicKey(T){let{r:w,s:y,recovery:v}=this,N=L(X("msgHash",T));if(v==null||![0,1,2,3].includes(v))throw new Error("recovery id invalid");let R=v===2||v===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let H=v&1?"03":"02",M=c.fromHex(H+h(R)),q=a(R),O=i(-N*q),$=i(y*q),W=c.BASE.multiplyAndAddUnsafe(M,O,$);if(!W)throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Te(this.toDERHex())}toDERHex(){return ne.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Te(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let b={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=no(t.n);return Zi(t.randomBytes(S),t.n)},precompute(S=8,T=c.BASE){return T._setWindowSize(S),T.multiply(BigInt(3)),T}};function B(S,T=!0){return c.fromPrivateKey(S).toRawBytes(T)}function p(S){let T=le(S),w=typeof S=="string",y=(T||w)&&S.length;return T?y===s||y===o:w?y===2*s||y===2*o:S instanceof c}function E(S,T,w=!0){if(p(S))throw new Error("first arg must be private key");if(!p(T))throw new Error("second arg must be public key");return c.fromHex(T).multiply(f(S)).toRawBytes(w)}let U=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let T=zt(S),w=S.length*8-t.nBitLength;return w>0?T>>BigInt(w):T},L=t.bits2int_modN||function(S){return i(U(S))},C=Lr(t.nBitLength);function k(S){return wt("num < 2^"+t.nBitLength,S,se,C),fe(S,t.nByteLength)}function A(S,T,w=G){if(["recovered","canonical"].some(st=>st in w))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:v}=t,{lowS:N,prehash:R,extraEntropy:H}=w;N==null&&(N=!0),S=X("msgHash",S),kc(w),R&&(S=X("prehashed msgHash",y(S)));let M=L(S),q=f(T),O=[k(q),k(M)];if(H!=null&&H!==!1){let st=H===!0?v(e.BYTES):H;O.push(X("extraEntropy",st))}let $=Wt(...O),W=M;function nt(st){let ct=U(st);if(!l(ct))return;let ft=a(ct),yt=c.BASE.multiply(ct).toAffine(),gt=i(yt.x);if(gt===se)return;let _t=i(ft*i(W+gt*q));if(_t===se)return;let Pt=(yt.x===gt?0:2)|Number(yt.y&at),wr=_t;return N&&g(_t)&&(wr=x(_t),Pt^=1),new d(gt,wr,Pt)}return{seed:$,k2sig:nt}}let G={lowS:t.lowS,prehash:!1},F={lowS:t.lowS,prehash:!1};function K(S,T,w=G){let{seed:y,k2sig:v}=A(S,T,w),N=t;return Qs(N.hash.outputLen,N.nByteLength,N.hmac)(y,v)}c.BASE._setWindowSize(8);function Y(S,T,w,y=F){let v=S;T=X("msgHash",T),w=X("publicKey",w);let{lowS:N,prehash:R,format:H}=y;if(kc(y),"strict"in y)throw new Error("options.strict was renamed to lowS");if(H!==void 0&&H!=="compact"&&H!=="der")throw new Error("format must be compact or der");let M=typeof v=="string"||le(v),q=!M&&!H&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!M&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,$;try{if(q&&(O=new d(v.r,v.s)),M){try{H!=="compact"&&(O=d.fromDER(v))}catch(Pt){if(!(Pt instanceof ne.Err))throw Pt}!O&&H!=="der"&&(O=d.fromCompact(v))}$=c.fromHex(w)}catch{return!1}if(!O||N&&O.hasHighS())return!1;R&&(T=t.hash(T));let{r:W,s:nt}=O,st=L(T),ct=a(nt),ft=i(st*ct),yt=i(W*ct),gt=c.BASE.multiplyAndAddUnsafe($,ft,yt)?.toAffine();return gt?i(gt.x)===W:!1}return{CURVE:t,getPublicKey:B,getSharedSecret:E,sign:K,verify:Y,ProjectivePoint:c,Signature:d,utils:b}}function Eh(r){return{hash:r,hmac:(t,...e)=>zo(r,t,$s(...e)),randomBytes:un}}function Nc(r,t){let e=n=>Cc({...r,...Eh(n)});return Object.freeze({...e(t),create:e})}var Lc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Tc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ah=BigInt(1),Wo=BigInt(2),Uc=(r,t)=>(r+t/Wo)/t;function Sh(r){let t=Lc,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=J(u,e,t)*u%t,h=J(l,e,t)*u%t,g=J(h,Wo,t)*f%t,x=J(g,s,t)*g%t,m=J(x,o,t)*x%t,d=J(m,a,t)*m%t,b=J(d,c,t)*d%t,B=J(b,a,t)*m%t,p=J(B,e,t)*u%t,E=J(p,i,t)*x%t,U=J(E,n,t)*f%t,L=J(U,Wo,t);if(!Zo.eql(Zo.sqr(L),r))throw new Error("Cannot find square root");return L}var Zo=he(Lc,void 0,void 0,{sqrt:Sh}),Ht=Nc({a:BigInt(0),b:BigInt(7),Fp:Zo,n:Tc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Tc,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ah*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Uc(o*r,t),c=Uc(-n*r,t),f=z(r-a*e-c*s,t),u=z(-a*n-c*o,t),l=f>i,h=u>i;if(l&&(f=t-f),h&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:h,k2:u}}}},Sc),Em=BigInt(0);var Am=Ht.ProjectivePoint;function Jo(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Dt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function Yo(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Rc(r,t){let e=rr.digest(t instanceof Uint8Array?t:t.subarray());if(Yo(e))return e.then(({digest:n})=>Ht.sign(n,r).toDERRawBytes()).catch(n=>{throw new vr(String(n))});try{return Ht.sign(e.digest,r).toDERRawBytes()}catch(n){throw new vr(String(n))}}function Hc(r,t,e){let n=rr.digest(e instanceof Uint8Array?e:e.subarray());if(Yo(n))return n.then(({digest:s})=>Ht.verify(t,s,r)).catch(s=>{throw new Br(String(s))});try{return Ht.verify(t,n.digest,r)}catch(s){throw new Br(String(s))}}var As=class{type="secp256k1";raw;_key;constructor(t){this._key=Vc(t),this.raw=_c(this._key)}toMultihash(){return Nr.digest(vn(this))}toCID(){return Ot.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}verify(t,e){return Hc(this._key,e,t)}},Ss=class{type="secp256k1";raw;publicKey;constructor(t,e){this.raw=Oc(t),this.publicKey=new As(e??Dc(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:jt(this.raw,t.raw)}sign(t){return Rc(this.raw,t)}};function Xo(r){return new Ss(r)}function _c(r){return Ht.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Oc(r){try{return Ht.getPublicKey(r,!0),r}catch(t){throw new Er(String(t))}}function Vc(r){try{return Ht.ProjectivePoint.fromHex(r),r}catch(t){throw new je(String(t))}}function Dc(r){try{return Ht.getPublicKey(r,!0)}catch(t){throw new Er(String(t))}}function vn(r){return ge.encode({Type:it[r.type],Data:r.raw})}function Kc(r){let t=Mr.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case it.RSA:return Bs(e);case it.Ed25519:return uo(e);case it.secp256k1:return Xo(e);default:throw new Ge}}function Mc(r){return r.byteLength===64?uo(r):r.byteLength===32?Xo(r):Bs(r)}function dr(r){return Mr.encode({Type:it[r.type],Data:r.raw})}var ks=class extends ir{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Nn(t);let n=me(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,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return or(this),this.iHash.update(t),this}digestInto(t){or(this),Fr(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:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,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()}},Qo=(r,t,e)=>new ks(r,t).update(e).digest();Qo.create=(r,t)=>new ks(r,t);function Fc(r,t,e,n){Nn(r);let s=Ia({dkLen:32,asyncTick:10},n),{c:o,dkLen:i,asyncTick:a}=s;if(sr(o),sr(i),sr(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=me(t),f=me(e),u=new Uint8Array(i),l=Qo.create(r,c),h=l._cloneInto().update(f);return{c:o,dkLen:i,asyncTick:a,DK:u,PRF:l,PRFSalt:h}}function Pc(r,t,e,n,s){return r.destroy(),t.destroy(),n&&n.destroy(),s.fill(0),e}function qc(r,t,e,n){let{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=Fc(r,t,e,n),f,u=new Uint8Array(4),l=De(u),h=new Uint8Array(a.outputLen);for(let g=1,x=0;x<o;g++,x+=a.outputLen){let m=i.subarray(x,x+a.outputLen);l.setInt32(0,g,!1),(f=c._cloneInto(f)).update(u).digestInto(h),m.set(h.subarray(0,m.length));for(let d=1;d<s;d++){a._cloneInto(f).update(h).digestInto(h);for(let b=0;b<m.length;b++)m[b]^=h[b]}}return Pc(a,c,i,f,h)}async function Is(r,t,e,n){let{c:s,dkLen:o,asyncTick:i,DK:a,PRF:c,PRFSalt:f}=Fc(r,t,e,n),u,l=new Uint8Array(4),h=De(l),g=new Uint8Array(c.outputLen);for(let x=1,m=0;m<o;x++,m+=c.outputLen){let d=a.subarray(m,m+c.outputLen);h.setInt32(0,x,!1),(u=f._cloneInto(u)).update(l).digestInto(g),d.set(g.subarray(0,d.length)),await ka(s-1,i,()=>{c._cloneInto(u).update(g).digestInto(g);for(let b=0;b<d.length;b++)d[b]^=g[b]})}return Pc(c,f,a,u,g)}var Xr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Ae=new Uint32Array(80),ti=class extends xe{constructor(){super(64,20,8,!1),this.A=Xr[0]|0,this.B=Xr[1]|0,this.C=Xr[2]|0,this.D=Xr[3]|0,this.E=Xr[4]|0}get(){let{A:t,B:e,C:n,D:s,E:o}=this;return[t,e,n,s,o]}set(t,e,n,s,o){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)Ae[c]=t.getUint32(e,!1);for(let c=16;c<80;c++)Ae[c]=Tn(Ae[c-3]^Ae[c-8]^Ae[c-14]^Ae[c-16],1);let{A:n,B:s,C:o,D:i,E:a}=this;for(let c=0;c<80;c++){let f,u;c<20?(f=Un(s,o,i),u=1518500249):c<40?(f=s^o^i,u=1859775393):c<60?(f=Ln(s,o,i),u=2400959708):(f=s^o^i,u=3395469782);let l=Tn(n,5)+f+a+u+Ae[c]|0;a=i,i=o,o=Tn(s,30),s=n,n=l}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,s,o,i,a)}roundClean(){Ae.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}},jc=ar(()=>new ti);var Cs=BigInt(4294967295),ei=BigInt(32);function Gc(r,t=!1){return t?{h:Number(r&Cs),l:Number(r>>ei&Cs)}:{h:Number(r>>ei&Cs)|0,l:Number(r&Cs)|0}}function kh(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let s=0;s<r.length;s++){let{h:o,l:i}=Gc(r[s],t);[e[s],n[s]]=[o,i]}return[e,n]}var Ih=(r,t)=>BigInt(r>>>0)<<ei|BigInt(t>>>0),Ch=(r,t,e)=>r>>>e,Nh=(r,t,e)=>r<<32-e|t>>>e,Th=(r,t,e)=>r>>>e|t<<32-e,Uh=(r,t,e)=>r<<32-e|t>>>e,Lh=(r,t,e)=>r<<64-e|t>>>e-32,Rh=(r,t,e)=>r>>>e-32|t<<64-e,Hh=(r,t)=>t,_h=(r,t)=>r,Oh=(r,t,e)=>r<<e|t>>>32-e,Vh=(r,t,e)=>t<<e|r>>>32-e,Dh=(r,t,e)=>t<<e-32|r>>>64-e,Kh=(r,t,e)=>r<<e-32|t>>>64-e;function Mh(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Fh=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ph=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,qh=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),jh=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Gh=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),$h=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var zh={fromBig:Gc,split:kh,toBig:Ih,shrSH:Ch,shrSL:Nh,rotrSH:Th,rotrSL:Uh,rotrBH:Lh,rotrBL:Rh,rotr32H:Hh,rotr32L:_h,rotlSH:Oh,rotlSL:Vh,rotlBH:Dh,rotlBL:Kh,add:Mh,add3L:Fh,add3H:Ph,add4L:qh,add4H:jh,add5H:$h,add5L:Gh},D=zh;var[Wh,Zh]=D.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Se=new Uint32Array(80),ke=new Uint32Array(80),ri=class extends xe{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:o,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:g,Gl:x,Hh:m,Hl:d}=this;return[t,e,n,s,o,i,a,c,f,u,l,h,g,x,m,d]}set(t,e,n,s,o,i,a,c,f,u,l,h,g,x,m,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=g|0,this.Gl=x|0,this.Hh=m|0,this.Hl=d|0}process(t,e){for(let p=0;p<16;p++,e+=4)Se[p]=t.getUint32(e),ke[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let E=Se[p-15]|0,U=ke[p-15]|0,L=D.rotrSH(E,U,1)^D.rotrSH(E,U,8)^D.shrSH(E,U,7),C=D.rotrSL(E,U,1)^D.rotrSL(E,U,8)^D.shrSL(E,U,7),k=Se[p-2]|0,A=ke[p-2]|0,G=D.rotrSH(k,A,19)^D.rotrBH(k,A,61)^D.shrSH(k,A,6),F=D.rotrSL(k,A,19)^D.rotrBL(k,A,61)^D.shrSL(k,A,6),K=D.add4L(C,F,ke[p-7],ke[p-16]),Y=D.add4H(K,L,G,Se[p-7],Se[p-16]);Se[p]=Y|0,ke[p]=K|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:g,Fl:x,Gh:m,Gl:d,Hh:b,Hl:B}=this;for(let p=0;p<80;p++){let E=D.rotrSH(l,h,14)^D.rotrSH(l,h,18)^D.rotrBH(l,h,41),U=D.rotrSL(l,h,14)^D.rotrSL(l,h,18)^D.rotrBL(l,h,41),L=l&g^~l&m,C=h&x^~h&d,k=D.add5L(B,U,C,Zh[p],ke[p]),A=D.add5H(k,b,E,L,Wh[p],Se[p]),G=k|0,F=D.rotrSH(n,s,28)^D.rotrBH(n,s,34)^D.rotrBH(n,s,39),K=D.rotrSL(n,s,28)^D.rotrBL(n,s,34)^D.rotrBL(n,s,39),Y=n&o^n&a^o&a,S=s&i^s&c^i&c;b=m|0,B=d|0,m=g|0,d=x|0,g=l|0,x=h|0,{h:l,l:h}=D.add(f|0,u|0,A|0,G|0),f=a|0,u=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let T=D.add3L(G,K,S);n=D.add3H(T,A,F,Y),s=T|0}({h:n,l:s}=D.add(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=D.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=D.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=D.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=D.add(this.Eh|0,this.El|0,l|0,h|0),{h:g,l:x}=D.add(this.Fh|0,this.Fl|0,g|0,x|0),{h:m,l:d}=D.add(this.Gh|0,this.Gl|0,m|0,d|0),{h:b,l:B}=D.add(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,s,o,i,a,c,f,u,l,h,g,x,m,d,b,B)}roundClean(){Se.fill(0),ke.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 pr=ar(()=>new ri);var $c={sha1:jc,"sha2-256":cr,"sha2-512":pr};function Qr(r,t,e,n,s){if(s!=="sha1"&&s!=="sha2-256"&&s!=="sha2-512"){let a=Object.keys($c).join(" / ");throw new _(`Hash '${s}' is unknown or not supported. Must be ${a}`)}let o=$c[s],i=qc(o,r,t,{c:e,dkLen:n});return _e.encode(i).substring(1)}var oe="/",zc=new TextEncoder().encode(oe),Ns=zc[0],tn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=j(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]!==Ns)throw new Error("Invalid key")}toString(t="utf8"){return Et(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=zc),this._buf[0]!==Ns){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Ns,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ns;)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 o=e[s],i=n[s];if(o<i)return!0;if(o>i)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 Jh(this.baseNamespace())}name(){return Yh(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(),...Xh(t.map(e=>e.namespaces()))])}};function Jh(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Yh(r){let t=r.split(":");return t[t.length-1]}function Xh(r){return[].concat(...r)}var rl=_s(el(),1),nl=rl.default;var ml=_s(hl(),1);var xr={};ht(xr,{create:()=>m0,derivedEmptyPasswordKey:()=>Ls});var Ls={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function m0(r){let t=r?.algorithm??"AES-GCM",e=r?.keyLength??16,n=r?.nonceLength??12,s=r?.digest??"SHA-256",o=r?.saltLength??16,i=r?.iterations??32767,a=bt.get();e*=8;async function c(l,h){let g=a.getRandomValues(new Uint8Array(o)),x=a.getRandomValues(new Uint8Array(n)),m={name:t,iv:x};typeof h=="string"&&(h=j(h));let d;if(h.length===0){d=await a.subtle.importKey("jwk",Ls,{name:"AES-GCM"},!0,["encrypt"]);try{let B={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},p=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(B,p,{name:t,length:e},!0,["encrypt"])}catch{d=await a.subtle.importKey("jwk",Ls,{name:"AES-GCM"},!0,["encrypt"])}}else{let B={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},p=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);d=await a.subtle.deriveKey(B,p,{name:t,length:e},!0,["encrypt"])}let b=await a.subtle.encrypt(m,d,l);return Jo([g,m.iv,new Uint8Array(b)])}async function f(l,h){let g=l.subarray(0,o),x=l.subarray(o,o+n),m=l.subarray(o+n),d={name:t,iv:x};typeof h=="string"&&(h=j(h));let b;if(h.length===0)try{let p={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},E=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(p,E,{name:t,length:e},!0,["decrypt"])}catch{b=await a.subtle.importKey("jwk",Ls,{name:"AES-GCM"},!0,["decrypt"])}else{let p={name:"PBKDF2",salt:g,iterations:i,hash:{name:s}},E=await a.subtle.importKey("raw",h,{name:"PBKDF2"},!1,["deriveKey"]);b=await a.subtle.deriveKey(p,E,{name:t,length:e},!0,["decrypt"])}let B=await a.subtle.decrypt(d,b,m);return new Uint8Array(B)}return{encrypt:c,decrypt:f}}async function si(r,t){let n=await xr.create().encrypt(r,t);return _e.encode(n)}async function oi(r,t,e){if(r.type==="RSA")return b0(r,t,e);if(r.type==="Ed25519")return x0(r,t,e);if(r.type==="secp256k1")return y0(r,t,e);throw new Ge}async function x0(r,t,e="libp2p-key"){if(e==="libp2p-key")return si(dr(r),t);throw new _(`export format '${e}' is not supported`)}async function y0(r,t,e="libp2p-key"){if(e==="libp2p-key")return si(dr(r),t);throw new _("Export format is not supported")}async function b0(r,t,e="pkcs-8"){if(e==="pkcs-8")return w0(r,t);if(e==="libp2p-key")return si(dr(r),t);throw new _("Export format is not supported")}async function w0(r,t){let e=bt.get(),s=new rt({value:[new tt({value:0}),new rt({value:[new kt({value:"1.2.840.113549.1.1.1"}),new Xt]}),new Qt({valueHex:r.raw})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=Fe(16),a=await Is(pr,t,i,{c:1e4,dkLen:32}),c=Fe(16),f=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await e.subtle.encrypt({name:"AES-CBC",iv:c},f,o),l=new rt({value:[new Qt({valueHex:i}),new tt({value:1e4}),new tt({value:32}),new rt({value:[new kt({value:"1.2.840.113549.2.11"}),new Xt]})]}),h=new rt({value:[new kt({value:"1.2.840.113549.1.5.13"}),new rt({value:[new rt({value:[new kt({value:"1.2.840.113549.1.5.12"}),l]}),new rt({value:[new kt({value:"2.16.840.1.101.3.4.1.42"}),new Qt({valueHex:c})]})]})]}),x=new rt({value:[h,new Qt({valueHex:u})]}).toBER(),m=new Uint8Array(x,0,x.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...Et(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
7
+ `)}async function ii(r,t){try{let e=await v0(r,t);return Kc(e)}catch{}if(!r.includes("BEGIN"))throw new _("Encrypted key was not a libp2p-key or a PEM file");return B0(r,t)}async function v0(r,t){let e=_e.decode(r);return xr.create().decrypt(e,t)}async function B0(r,t){let e=bt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Me(o),{iv:a,salt:c,iterations:f,keySize:u,cipherText:l}=E0(i),h=await Is(pr,t,c,{c:f,dkLen:u}),g=await e.subtle.importKey("raw",h,"AES-CBC",!1,["decrypt"]),x=en(await e.subtle.decrypt({name:"AES-CBC",iv:a},g,l)),{result:m}=Me(x);n=gl(m)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let o=j(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:i}=Me(o);n=gl(i)}else throw new _("Could not parse private key from PEM data");let s=Mc(n);if(s.type!=="RSA")throw new _("Could not parse RSA private key from PEM data");return s}function E0(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new _("Only pkcs5PBES2 encrypted private keys are supported");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 _("Only pkcs5PBKDF2 key derivation functions are supported");let o=n.valueBlock.value[1],i=en(o.valueBlock.value[0].getValue()),a=1e4,c=32;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new _("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key");let f=t.valueBlock.value[1].valueBlock.value[1],u=f.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new _("Only AES-CBC encryption schemes are supported")}}}}let l=en(f.valueBlock.value[1].getValue());return{cipherText:en(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:l}}function gl(r){return en(r.valueBlock.value[2].getValue())}function en(r){return new Uint8Array(r,0,r.byteLength)}var A0="/pkcs8/",ci="/info/",rn=new WeakMap,Pe={minKeyLength:112/8,minSaltLength:128/8,minIterationCount:1e3},ai={dek:{keyLength:512/8,iterationCount:1e4,salt:"you should override this value with a crypto secure random number",hash:"sha2-512"}};function yr(r){return r==null||typeof r!="string"?!1:r===(0,ml.default)(r.trim())&&r.length>0}async function ut(){let e=Math.random()*800+200;await new Promise(n=>setTimeout(n,e))}function qe(r){return new tn(A0+r)}function br(r){return new tn(ci+r)}async function S0(r){let t=dr(r),e=await rr.digest(t);return ot.encode(e.bytes).substring(1)}var Rs=class{components;init;log;constructor(t,e){if(this.components=t,this.log=t.logger.forComponent("libp2p:keychain"),this.init=nl(ai,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<Pe.minKeyLength)throw new Error(`dek.keyLength must be least ${Pe.minKeyLength} bytes`);if(this.init.dek?.salt?.length!=null&&this.init.dek.salt.length<Pe.minSaltLength)throw new Error(`dek.saltLength must be least ${Pe.minSaltLength} bytes`);if(this.init.dek?.iterationCount!=null&&this.init.dek.iterationCount<Pe.minIterationCount)throw new Error(`dek.iterationCount must be least ${Pe.minIterationCount}`);let n=this.init.pass!=null&&this.init.dek?.salt!=null?Qr(this.init.pass,this.init.dek?.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";rn.set(this,{dek:n})}[Symbol.toStringTag]="@libp2p/keychain";[yi]=["@libp2p/keychain"];static generateOptions(){let t=Object.assign({},ai),e=Math.ceil(Pe.minSaltLength/3)*3;return t.dek.salt=Et(Fe(e),"base64"),t}static get options(){return ai}async findKeyByName(t){if(!yr(t))throw await ut(),new _(`Invalid key name '${t}'`);let e=br(t);try{let n=await this.components.datastore.get(e);return JSON.parse(Et(n))}catch(n){throw await ut(),this.log.error(n),new on(`Key '${t}' does not exist.`)}}async findKeyById(t){try{let e={prefix:ci};for await(let n of this.components.datastore.query(e)){let s=JSON.parse(Et(n.value));if(s.id===t)return s}throw new _(`Key with id '${t}' does not exist.`)}catch(e){throw await ut(),e}}async importKey(t,e){if(!yr(t))throw await ut(),new _(`Invalid key name '${t}'`);if(e==null)throw await ut(),new _("Key is required");let n=qe(t);if(await this.components.datastore.has(n))throw await ut(),new _(`Key '${t}' already exists`);let o,i;try{o=await S0(e);let f=rn.get(this);if(f==null)throw new _("dek missing");let u=f.dek;i=await oi(e,u,e.type==="RSA"?"pkcs-8":"libp2p-key")}catch(f){throw await ut(),f}let a={name:t,id:o},c=this.components.datastore.batch();return c.put(n,j(i)),c.put(br(t),j(JSON.stringify(a))),await c.commit(),a}async exportKey(t){if(!yr(t))throw await ut(),new _(`Invalid key name '${t}'`);let e=qe(t);try{let n=await this.components.datastore.get(e),s=Et(n),o=rn.get(this);if(o==null)throw new _("dek missing");let i=o.dek;return await ii(s,i)}catch(n){throw await ut(),n}}async removeKey(t){if(!yr(t)||t==="self")throw await ut(),new _(`Invalid key name '${t}'`);let e=qe(t),n=await this.findKeyByName(t),s=this.components.datastore.batch();return s.delete(e),s.delete(br(t)),await s.commit(),n}async listKeys(){let t={prefix:ci},e=[];for await(let n of this.components.datastore.query(t))e.push(JSON.parse(Et(n.value)));return e}async renameKey(t,e){if(!yr(t)||t==="self")throw await ut(),new _(`Invalid old key name '${t}'`);if(!yr(e)||e==="self")throw await ut(),new _(`Invalid new key name '${e}'`);let n=qe(t),s=qe(e),o=br(t),i=br(e);if(await this.components.datastore.has(s))throw await ut(),new _(`Key '${e}' already exists`);try{let c=await this.components.datastore.get(n),f=await this.components.datastore.get(o),u=JSON.parse(Et(f));u.name=e;let l=this.components.datastore.batch();return l.put(s,c),l.put(i,j(JSON.stringify(u))),l.delete(n),l.delete(o),await l.commit(),u}catch(c){throw await ut(),c}}async rotateKeychainPass(t,e){if(typeof t!="string")throw await ut(),new _(`Invalid old pass type '${typeof t}'`);if(typeof e!="string")throw await ut(),new _(`Invalid new pass type '${typeof e}'`);if(e.length<20)throw await ut(),new _(`Invalid pass length ${e.length}`);this.log("recreating keychain");let n=rn.get(this);if(n==null)throw new _("dek missing");let s=n.dek;this.init.pass=e;let o=e!=null&&this.init.dek?.salt!=null?Qr(e,this.init.dek.salt,this.init.dek?.iterationCount,this.init.dek?.keyLength,this.init.dek?.hash):"";rn.set(this,{dek:o});let i=await this.listKeys();for(let a of i){let c=await this.components.datastore.get(qe(a.name)),f=Et(c),u=await ii(f,s),l=o.toString(),h=await oi(u,l,u.type==="RSA"?"pkcs-8":"libp2p-key"),g=this.components.datastore.batch(),x={name:a.name,id:a.id};g.put(qe(a.name),j(h)),g.put(br(a.name),j(JSON.stringify(x))),await g.commit()}this.log("keychain reconstructed")}};function k0(r={}){return t=>new Rs(t,r)}return Tl(I0);})();
8
8
  /*! Bundled license information:
9
9
 
10
10
  pvtsutils/build/index.js:
11
11
  (*!
12
12
  * MIT License
13
13
  *
14
- * Copyright (c) 2017-2022 Peculiar Ventures, LLC
14
+ * Copyright (c) 2017-2024 Peculiar Ventures, LLC
15
15
  *
16
16
  * Permission is hereby granted, free of charge, to any person obtaining a copy
17
17
  * of this software and associated documentation files (the "Software"), to deal
@@ -51,6 +51,9 @@ pvtsutils/build/index.js:
51
51
  @noble/curves/esm/ed25519.js:
52
52
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
53
53
 
54
+ @noble/hashes/esm/utils.js:
55
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
56
+
54
57
  pvutils/build/utils.es.js:
55
58
  (*!
56
59
  Copyright (c) Peculiar Ventures, LLC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/keychain",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
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,20 +59,20 @@
59
59
  "test:electron-main": "aegir test -t electron-main"
60
60
  },
61
61
  "dependencies": {
62
- "@libp2p/crypto": "^5.0.7",
63
- "@libp2p/interface": "^2.2.1",
64
- "@noble/hashes": "^1.5.0",
62
+ "@libp2p/crypto": "^5.0.8",
63
+ "@libp2p/interface": "^2.3.0",
64
+ "@noble/hashes": "^1.6.1",
65
65
  "asn1js": "^3.0.5",
66
- "interface-datastore": "^8.3.0",
66
+ "interface-datastore": "^8.3.1",
67
67
  "merge-options": "^3.0.4",
68
- "multiformats": "^13.2.2",
68
+ "multiformats": "^13.3.1",
69
69
  "sanitize-filename": "^1.6.3",
70
70
  "uint8arrays": "^5.1.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@libp2p/logger": "^5.1.4",
74
- "aegir": "^44.0.1",
75
- "datastore-core": "^10.0.0"
73
+ "@libp2p/logger": "^5.1.5",
74
+ "aegir": "^45.0.5",
75
+ "datastore-core": "^10.0.2"
76
76
  },
77
77
  "sideEffects": false
78
78
  }
package/LICENSE DELETED
@@ -1,4 +0,0 @@
1
- This project is dual licensed under MIT and Apache-2.0.
2
-
3
- MIT: https://www.opensource.org/licenses/mit
4
- Apache-2.0: https://www.apache.org/licenses/license-2.0