UNPKG

@vechain/connex

Version:

Standard interface to connect DApp with VeChain and user

2 lines 222 kB
/*! For license information please see connex.min.js.LICENSE.txt */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(function(){return(()=>{var t={280:(t,e,r)=>{"use strict";r.r(e),r.d(e,{Connex:()=>ConnexClass,default:()=>Rt});var n=r(2046),i=r(747),o=r(8764).Buffer;function s(...t){const e=i.keccak_256.create();return t.forEach((t=>{o.isBuffer(t)?e.update(t):e.update(o.from(t,"utf8"))})),o.from(e.digest())}var a=r(8764).Buffer;class Coder extends n.AbiCoder{constructor(){super(((t,e)=>t.match(/^u?int/)&&!Array.isArray(e)&&"object"!=typeof e||"BigNumber"===e._ethersType?e.toString():e))}encode(t,e){try{return super.encode(t,e)}catch(t){if(t.reason)throw new Error(t.reason);throw t}}decode(t,e){try{return super.decode(t,e)}catch(t){if(t.reason)throw new Error(t.reason);throw t}}}const u=new Coder;function h(t){try{return(0,n.formatSignature)(t).replace(/\(tuple\(/g,"((").replace(/\,tuple\(/g,",(")}catch(t){if(t.reason)throw new Error(t.reason);throw t}}var l;!function(t){function e(t,e){return u.encode([t],[e])}function r(t,e){return u.decode([t],e)[0]}function n(t,e){return u.encode(t,e)}function i(t,e){const r=u.decode(t,e),n={};return t.forEach(((t,e)=>{n[e]=r[e],t.name&&(n[t.name]=r[e])})),n}t.encodeParameter=e,t.decodeParameter=r,t.encodeParameters=n,t.decodeParameters=i;t.Function=class Function{constructor(t){this.definition=t,this.canonicalName=h(t),this.signature="0x"+s(this.canonicalName).slice(0,4).toString("hex")}encode(...t){return this.signature+n(this.definition.inputs,t).slice(2)}decode(t){return i(this.definition.outputs,t)}};function o(t){return"address"===t||"bool"===t||/^(u?int)([0-9]*)$/.test(t)||/^bytes([0-9]+)$/.test(t)}t.Event=class Event{constructor(t){this.definition=t,this.canonicalName=h(t),this.signature="0x"+s(this.canonicalName).toString("hex")}encode(t){const r=[];this.definition.anonymous||r.push(this.signature);for(const n of this.definition.inputs){if(!n.indexed)continue;const i=t[n.name];if(null==i)r.push(null);else{let t;if(o(n.type))t=e(n.type,i);else if("string"===n.type)t="0x"+s(i).toString("hex");else{if("string"!=typeof i||!/^0x[0-9a-f]+$/i.test(i)||i.length%2!=0)throw new Error(`event.encode: invalid ${n.type} value`);t="0x"+s(a.from(i.slice(2),"hex")).toString("hex")}r.push(t)}}return r}decode(t,e){if(this.definition.anonymous||(e=e.slice(1)),this.definition.inputs.filter((t=>t.indexed)).length!==e.length)throw new Error("invalid topics count");const n=u.decode(this.definition.inputs.filter((t=>!t.indexed)),t),i={};return this.definition.inputs.forEach(((t,s)=>{if(t.indexed){const n=e.shift();i[s]=o(t.type)?r(t.type,n):n}else i[s]=n.shift();t.name&&(i[t.name]=i[s])})),i}}}(l||(l={}));const c="0x"+s("Error(string)").toString("hex").slice(0,8),f="0x"+s("Panic(uint256)").toString("hex").slice(0,8);function p(t){try{if(t.startsWith(c))return l.decodeParameter("string","0x"+t.slice(c.length));if(t.startsWith(f)){const e=l.decodeParameter("uint256","0x"+t.slice(f.length));return`Panic(0x${parseInt(e).toString(16).padStart(2,"0")})`}return""}catch(t){return""}}var d=r(6462);function g(t){return"string"==typeof t&&/^0x[0-9a-f]+$/i.test(t)}function m(t,e){return!("string"!=typeof t||!/^0x[0-9a-f]*$/i.test(t))&&(e?t.length===2*e+2:t.length%2==0)}function v(t,e){return!(t<0||!Number.isInteger(t))&&(!e||t<Math.pow(2,e))}class BadParameter extends Error{constructor(t){super(t)}}function y(t,e){if(!t)throw new BadParameter(e)}function w(t,e,r){try{return d.Gu(t,e,r)}catch(t){if(t instanceof d.p8)throw new BadParameter(t.message);throw t}}function b(t){return m(t)?"":"expected bytes in hex string"}function M(t){return m(t,32)?"":"expected bytes32"}function x(t){return v(t,8)?"":"expected 8-bit unsigned integer"}function E(t){return v(t,32)?"":"expected 32-bit unsigned integer"}function A(t){return v(t,64)?"":"expected 64-bit unsigned integer"}function N(t){return"boolean"==typeof t?"":"expected boolean"}function k(t){return function(t){return"string"==typeof t?"string"==typeof(e=t)&&/^[0-9]+$/.test(e)||g(t):v(t,0);var e}(t)?"":"expected unsigned integer in number or string"}function O(t){return g(t)?"":"expected integer in hex string"}function S(t){return m(t,20)?"":"expected address"}function I(t){return"string"==typeof t?"":"expected string"}BadParameter.prototype.name="BadParameter";function _(t,e,r){const n={range:{unit:"block",from:0,to:Math.pow(2,32)-1},options:{offset:0,limit:10},criteriaSet:r,order:"asc"};let i;return{range(t){return w(t,{unit:t=>"block"===t||"time"===t?"":"expected 'block' or 'time'",from:A,to:A},"arg0"),y(t.from<=t.to,"arg0.from: expected <= arg0.to"),n.range=Object.assign({},t),this},order(t){return y("asc"===t||"desc"===t,"arg0: expected 'asc' or 'desc'"),n.order=t,this},cache(t){return i=w(t,[S],"arg0").map((t=>t.toLowerCase())),this},apply:(r,o)=>(w(r,A,"arg0"),y(o>=0&&o<=256&&Number.isInteger(o),"arg1: expected unsigned integer <= 256"),n.options.offset=r,n.options.limit=o,"transfer"===e?t.then((t=>t.filterTransferLogs(n,i))):t.then((t=>t.filterEventLogs(n,i))))}}var U=r(634),R=r.n(U),T=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};function C(t){return{sign:(e,r)=>{if("tx"===e)return w(r,[L],"arg1"),B(Promise.resolve(t),r);if("cert"===e)return w(r,{purpose:t=>"agreement"===t||"identification"===t?"":"expected 'agreement' or 'identification'",payload:{type:t=>"text"===t?"":"expected 'text'",content:I}},"arg1"),function(t,e){const r={};return{signer(t){return r.signer=w(t,S,"arg0").toLowerCase(),this},link(t){return r.link=w(t,I,"arg0"),this},accepted(t){return y("function"==typeof t,"arg0: expected function"),r.onAccepted=t,this},request(){return(()=>T(this,void 0,void 0,(function*(){try{const n=yield t;return yield n.signCert(e,r)}catch(t){throw new Rejected(t.message)}})))()}}}(Promise.resolve(t),r);throw new BadParameter("arg0: expected 'tx' or 'cert'")}}}function B(t,e){const r={};return{signer(t){return r.signer=w(t,S,"arg0").toLowerCase(),this},gas(t){return r.gas=w(t,A,"arg0"),this},dependsOn(t){return r.dependsOn=w(t,M,"arg0").toLowerCase(),this},link(t){return r.link=w(t,I,"arg0"),this},comment(t){return r.comment=w(t,I,"arg0"),this},delegate(t,e){return y("string"==typeof t,"arg0: expected url string"),w(e,d.jt(S),"arg1"),r.delegator={url:t,signer:e&&e.toLowerCase()},this},accepted(t){return y("function"==typeof t,"arg0: expected function"),r.onAccepted=t,this},request(){const n=e.map((t=>Object.assign(Object.assign({},t),{value:new(R())(t.value).toString(10)})));return(()=>T(this,void 0,void 0,(function*(){try{const e=yield t;return yield e.signTx(n,r)}catch(t){throw new Rejected(t.message)}})))()}}}class Rejected extends Error{constructor(t){super(t)}}Rejected.prototype.name="Rejected";const L={to:d.AG(S),value:k,data:d.jt(b),comment:d.jt(I),abi:d.jt((t=>{if(!(t instanceof Object))return"expected object";try{return new l.Function(t).signature,""}catch(t){return`expected valid ABI (${t.message})`}}))};function P(t,e){return{get address(){return e},get:()=>t.then((t=>t.getAccount(e,t.head.id))),getCode:()=>t.then((t=>t.getCode(e,t.head.id))),getStorage:r=>(r=w(r,M,"arg0").toLowerCase(),t.then((t=>t.getStorage(e,r,t.head.id)))),method:r=>{let n;try{n=new l.Function(JSON.parse(JSON.stringify(r)))}catch(t){throw new BadParameter(`arg0: expected valid ABI (${t.message})`)}return function(t,e,r){let n=0;const i={};let o;return{value(t){return n=w(t,k,"arg0"),this},caller(t){return i.caller=w(t,S,"arg0").toLowerCase(),this},gas(t){return i.gas=w(t,A,"arg0"),this},gasPrice(t){return i.gasPrice=w(t,k,"arg0").toString().toLowerCase(),this},gasPayer(t){return i.gasPayer=w(t,S,"arg0").toLowerCase(),this},cache(t){return o=w(t,[S],"arg0").map((t=>t.toLowerCase())),this},asClause:(...t)=>{const i=(r.definition.inputs||[]).length;y(i===t.length,"args count expected "+i);try{const i=r.encode(...t);return{to:e,value:n.toString().toLowerCase(),data:i}}catch(t){throw new BadParameter(`args can not be encoded (${t.message})`)}},call(...e){const n=this.asClause(...e);return t.then((t=>t.explain(Object.assign({clauses:[n]},i),t.head.id,o))).then((t=>t[0])).then((t=>{if(t.reverted){const e=p(t.data);return Object.assign(Object.assign({},t),{revertReason:e,decoded:{}})}{const e=r.decode(t.data);return Object.assign(Object.assign({},t),{decoded:e})}}))},transact(...e){const n=this.asClause(...e);return B(t,[Object.assign(Object.assign({},n),{abi:r.definition})])}}}(t,e,n)},event:r=>{let n;try{n=new l.Event(JSON.parse(JSON.stringify(r)))}catch(t){throw new BadParameter(`arg0: expected valid ABI (${t.message})`)}return function(t,e,r){const n=t=>{const n=r.encode(t);return{address:e,topic0:n[0]||void 0,topic1:n[1]||void 0,topic2:n[2]||void 0,topic3:n[3]||void 0,topic4:n[4]||void 0}};return{asCriteria:t=>{try{return n(t)}catch(t){throw new BadParameter(`arg0: can not be encoded (${t.message})`)}},filter:e=>{w(e,[{}],"arg0"),0===e.length&&(e=[{}]);const i=e.map(((t,e)=>{try{return n(t)}catch(t){throw new BadParameter(`arg0.#${e}: can not be encoded (${t.message})`)}})),o=_(t,"event",i);return{range(t){return o.range(t),this},order(t){return o.order(t),this},cache(t){return o.cache(t),this},apply:(t,e)=>o.apply(t,e).then((t=>t.map((t=>{const e=r.decode(t.data,t.topics);return Object.assign(Object.assign({},t),{decoded:e})}))))}}}}(t,e,n)}}}var j=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};var D=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};function F(t){const e=function(t){let e=Object.assign({},t.head),r=t.genesis.id,n=[];(()=>{j(this,void 0,void 0,(function*(){for(;;)try{const i=yield t.pollHead();if(i.id!==e.id&&i.number>=e.number){if(0===e.number||(i.number+1)%180==0)try{const e=yield t.getBlock("finalized");e&&e.id!=r&&(r=e.id)}catch(t){}e=Object.assign({},i);const o=n;n=[],o.forEach((t=>t(i)))}else yield new Promise((t=>setTimeout(t,1e3)))}catch(t){break}}))})();const i=t.genesis.timestamp;return{get head(){return e},get progress(){const t=Date.now(),r=1e3*e.timestamp;if(t-r<3e4)return 1;const n=1e3*i,o=(r-n)/(t-n);return o<0?NaN:o},get finalized(){return r},ticker:()=>{let t=e.id;return{next:()=>new Promise((r=>{if(t!==e.id)return r(Object.assign({},e));n.push((t=>{r(Object.assign({},t))}))})).then((e=>(t=e.id,e)))}}}}(t),r=(()=>D(this,void 0,void 0,(function*(){return e.head.number>0||(yield e.ticker().next()),t})))(),n=JSON.parse(JSON.stringify(t.genesis));return{get genesis(){return n},get status(){return{head:e.head,progress:e.progress,finalized:e.finalized}},ticker:()=>e.ticker(),account:t=>(t=w(t,S,"arg0").toLowerCase(),P(r,t)),block:e=>(void 0===e?e=t.head.id:y("string"==typeof e?m(e,32):v(e,32),"arg0: expected bytes32 or unsigned 32-bit integer"),function(t,e){return{get revision(){return e},get:()=>t.getBlock(e)}}(t,"string"==typeof e?e.toLowerCase():e)),transaction:t=>(t=w(t,M,"arg0").toLowerCase(),function(t,e){let r=!1;return{get id(){return e},allowPending(){return r=!0,this},get:()=>t.then((t=>t.getTransaction(e,r))),getReceipt:()=>t.then((t=>t.getReceipt(e)))}}(r,t)),filter:(t,e)=>(y("event"===t||"transfer"===t,"arg0: expected 'event' or 'transfer'"),"event"===t?(w(e,[G],"arg1"),_(r,"event",e.map((t=>({address:t.address?t.address.toLowerCase():void 0,topic0:t.topic0?t.topic0.toLowerCase():void 0,topic1:t.topic1?t.topic1.toLowerCase():void 0,topic2:t.topic2?t.topic2.toLowerCase():void 0,topic3:t.topic3?t.topic3.toLowerCase():void 0,topic4:t.topic4?t.topic4.toLowerCase():void 0}))))):(w(e,[z],"arg1"),_(r,"transfer",e.map((t=>({txOrigin:t.txOrigin?t.txOrigin.toLowerCase():void 0,sender:t.sender?t.sender.toLowerCase():void 0,recipient:t.recipient?t.recipient.toLowerCase():void 0})))))),explain:t=>(w(t,[q],"arg0"),function(t,e){const r={};let n;return{caller(t){return r.caller=w(t,S,"arg0").toLowerCase(),this},gas(t){return r.gas=w(t,A,"arg0"),this},gasPrice(t){return r.gasPrice=w(t,k,"arg0").toString().toLowerCase(),this},gasPayer(t){return r.gasPayer=w(t,S,"arg0").toLowerCase(),this},cache(t){return n=w(t,[S],"arg0").map((t=>t.toLowerCase())),this},execute(){const i=e.map((t=>({to:t.to?t.to.toLowerCase():null,value:new(R())(t.value).toString(10),data:(t.data||"0x").toLowerCase()})));return t.then((t=>t.explain(Object.assign({clauses:i},r),t.head.id,n))).then((t=>t.map((t=>{if(t.reverted){const e=p(t.data);return Object.assign(Object.assign({},t),{revertReason:e})}return t}))))}}}(r,t))}}const q={to:d.AG(S),value:k,data:d.jt(b)},G={address:d.jt(S),topic0:d.jt(M),topic1:d.jt(M),topic2:d.jt(M),topic3:d.jt(M),topic4:d.jt(M)},z={sender:d.jt(S),recipient:d.jt(S),txOrigin:d.jt(S)};const V={id:M,number:E,timestamp:A,parentID:M,txsFeatures:d.jt(E),gasLimit:A},$={id:M,number:E,size:E,parentID:M,timestamp:A,gasLimit:A,beneficiary:S,gasUsed:A,totalScore:A,txsRoot:M,txsFeatures:d.jt(E),stateRoot:M,receiptsRoot:M,signer:S,com:d.jt(N),isFinalized:d.jt(N),isTrunk:N,transactions:[M]},H={id:M,chainTag:x,blockRef:function(t){return m(t,8)?"":"expected bytes8"},expiration:E,gasPriceCoef:x,gas:A,origin:S,delegator:d.AG(d.jt(S)),nonce:O,dependsOn:d.AG(M),size:E,clauses:[{to:d.AG(S),value:O,data:b}],meta:d.AG({blockID:M,blockNumber:E,blockTimestamp:A})},Z={blockID:M,blockNumber:E,blockTimestamp:A,txID:M,txOrigin:S,clauseIndex:E},W={address:S,topics:[M],data:b},J=Object.assign(Object.assign({},W),{meta:Z}),X={sender:S,recipient:S,amount:O},K=Object.assign(Object.assign({},X),{meta:Z}),Y={gasUsed:A,gasPayer:S,paid:O,reward:O,reverted:N,outputs:[{contractAddress:d.AG(S),events:[W],transfers:[X]}],meta:{blockID:M,blockNumber:E,blockTimestamp:A,txID:M,txOrigin:S}},Q={data:b,vmError:I,gasUsed:A,reverted:N,revertReason:()=>"",events:[{address:S,topics:[M],data:b}],transfers:[{sender:S,recipient:S,amount:O}]};class Framework{constructor(t){this.thor=F(t),this.vendor=C(t)}static guardDriver(t,e){return function(t,e){const r=(t,r,n)=>{try{d.Gu(t,r,n)}catch(t){e?e(t):console.warn("Connex-Driver[MALFORMED RESPONSE]: "+t.message)}return t};return{genesis:r(t.genesis,$,"genesis"),get head(){return r(t.head,V,"head")},pollHead:()=>t.pollHead().then((t=>r(t,V,"getHead()"))),getBlock:e=>t.getBlock(e).then((t=>t?r(t,$,"getBlock()"):t)),getTransaction:(e,n)=>t.getTransaction(e,n).then((t=>t?r(t,H,"getTransaction()"):t)),getReceipt:e=>t.getReceipt(e).then((t=>t?r(t,Y,"getReceipt()"):t)),getAccount:(e,n)=>t.getAccount(e,n).then((t=>r(t,{balance:O,energy:O,hasCode:N},"getAccount()"))),getCode:(e,n)=>t.getCode(e,n).then((t=>r(t,{code:b},"getCode()"))),getStorage:(e,n,i)=>t.getStorage(e,n,i).then((t=>r(t,{value:M},"getStorage()"))),explain:(e,n)=>t.explain(e,n).then((t=>r(t,[Q],"explain()"))),filterEventLogs:e=>t.filterEventLogs(e).then((t=>r(t,[J],"filterEventLogs()"))),filterTransferLogs:e=>t.filterTransferLogs(e).then((t=>r(t,[K],"filterTransferLogs()"))),signTx:(e,n)=>t.signTx(e,n).then((t=>r(t,{txid:M,signer:S},"signTx()"))),signCert:(e,n)=>t.signCert(e,n).then((t=>r(t,{annex:{domain:I,timestamp:A,signer:S},signature:t=>m(t,65)?"":"expected 65 bytes"},"signCert()")))}}(t,e)}}const tt={main:{number:0,id:"0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a",size:170,parentID:"0xffffffff53616c757465202620526573706563742c20457468657265756d2100",timestamp:1530316800,gasLimit:1e7,beneficiary:"0x0000000000000000000000000000000000000000",gasUsed:0,totalScore:0,txsRoot:"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",txsFeatures:0,stateRoot:"0x09bfdf9e24dd5cd5b63f3c1b5d58b97ff02ca0490214a021ed7d99b93867839c",receiptsRoot:"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",signer:"0x0000000000000000000000000000000000000000",isTrunk:!0,transactions:[]},test:{number:0,id:"0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127",size:170,parentID:"0xffffffff00000000000000000000000000000000000000000000000000000000",timestamp:1530014400,gasLimit:1e7,beneficiary:"0x0000000000000000000000000000000000000000",gasUsed:0,totalScore:0,txsRoot:"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",txsFeatures:0,stateRoot:"0x4ec3af0acbad1ae467ad569337d2fe8576fe303928d35b8cdd91de47e9ac84bb",receiptsRoot:"0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0",signer:"0x0000000000000000000000000000000000000000",isTrunk:!0,transactions:[]}};class PromInt{constructor(){this.rejectors=new Set}interrupt(){const t=this.rejectors;this.rejectors=new Set,t.forEach((t=>t(new InterruptedError)))}wrap(t){return new Promise(((e,r)=>{const n=this.rejectors;n.add(r),t.then(e).catch(r).then((()=>n.delete(r)))}))}}class InterruptedError extends Error{constructor(){super("promise interrupted")}}InterruptedError.prototype.name="InterruptedError";var et=r(9992),rt=r(4491),nt=r.n(rt),it=r(8764).Buffer;const ot=r(1161);function st(...t){const e=ot.blake2bInit(32,null);return t.forEach((t=>{it.isBuffer(t)?ot.blake2bUpdate(e,t):ot.blake2bUpdate(e,it.from(t,"utf8"))})),it.from(ot.blake2bFinal(e))}function at(t,e){const r=8*t.length;return{contains(n){let i=st(n).readUInt32BE(0);const o=i>>>17|i<<15>>>0;for(let n=0;n<e;n++){const e=i%r,n=1<<e%8;if(!(t[e>>>3]&n))return!1;i=i+o>>>0}return!0}}}var ut=r(8764).Buffer,ht=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};class Cache{constructor(){this.irreversible={blocks:new et(256),txs:new et(512),receipts:new et(512)},this.window=[]}handleNewBlock(t,e,r){for(;this.window.length>0;){const e=this.window[this.window.length-1];if(e.id===t.id)return;if(e.id===t.parentID)break;this.window.pop()}for(this.window.push(Object.assign(Object.assign({},t),{bloom:e?at(ut.from(e.bits.slice(2),"hex"),e.k):void 0,block:r,accounts:new Map,txs:new Map,receipts:new Map,tied:new Map}));this.window.length>12;){const t=this.window.shift();t.txs.forEach(((t,e)=>this.irreversible.txs.set(e,t))),t.receipts.forEach(((t,e)=>this.irreversible.receipts.set(e,t))),t.block&&(this.irreversible.blocks.set(t.block.id,t.block),this.irreversible.blocks.set(t.block.number,t.block))}}getBlock(t,e){return ht(this,void 0,void 0,(function*(){let r=this.irreversible.blocks.get(t)||null;if(r)return r;const{slot:n}=this.findSlot(t);return n&&n.block?n.block:(r=yield e(),r&&(n&&n.id===r.id&&(n.block=r),this.isIrreversible(r.number)&&(this.irreversible.blocks.set(r.id,r),r.isTrunk&&this.irreversible.blocks.set(r.number,r))),r)}))}getTx(t,e){return ht(this,void 0,void 0,(function*(){let r=this.irreversible.txs.get(t)||null;if(r)return r;for(const e of this.window)if(r=e.txs.get(t)||null,r)return r;if(r=yield e(),r&&r.meta){const{slot:e}=this.findSlot(r.meta.blockID);e&&e.txs.set(t,r),this.isIrreversible(r.meta.blockNumber)&&this.irreversible.txs.set(t,r)}return r}))}getReceipt(t,e){return ht(this,void 0,void 0,(function*(){let r=this.irreversible.receipts.get(t)||null;if(r)return r;for(const e of this.window)if(r=e.receipts.get(t)||null,r)return r;if(r=yield e(),r){const{slot:e}=this.findSlot(r.meta.blockID);e&&e.receipts.set(t,r),this.isIrreversible(r.meta.blockNumber)&&this.irreversible.receipts.set(t,r)}return r}))}getAccount(t,e,r){return ht(this,void 0,void 0,(function*(){const n=this.findSlot(e);for(let e=n.index;e>=0;e--){const r=this.window[e],i=r.accounts.get(t);if(i)return e!==n.index&&n.slot.accounts.set(t,i),i.snapshot(n.slot.timestamp);if(!r.bloom||lt(r.bloom,t))break}const i=yield r();return n.slot&&n.slot.accounts.set(t,new Account(i,n.slot.timestamp)),i}))}getTied(t,e,r,n){return ht(this,void 0,void 0,(function*(){const i=this.findSlot(e);for(let e=i.index;e>=0;e--){const r=this.window[e],o=r.tied.get(t);if(o)return e!==i.index&&i.slot.tied.set(t,o),o;if(!r.bloom||!n)break;if(n.some((t=>lt(r.bloom,t))))break}const o=yield r();return i.slot&&i.slot.tied.set(t,o),o}))}findSlot(t){const e=this.window.findIndex((e=>e.id===t||e.number===t));return e>=0?{slot:this.window[e],index:e}:{index:e}}isIrreversible(t){return this.window.length>0&&t<this.window[this.window.length-1].number-12}}function lt(t,e){let r=ut.from(e.slice(2),"hex");const n=r.findIndex((t=>0!==t));return r=n<0?ut.alloc(0):r.slice(n),t.contains(r)}class Account{constructor(t,e){this.obj=t,this.initTimestamp=e}snapshot(t){return Object.assign(Object.assign({},this.obj),{energy:this.energyAt(t)})}energyAt(t){return t<this.initTimestamp?this.obj.energy:"0x"+new(nt())(this.obj.balance).times(t-this.initTimestamp).times(5e9).dividedToIntegerBy(1e18).plus(this.obj.energy).toString(16)}}function ct(t){return new Promise((e=>setTimeout(e,t)))}var ft=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};class DriverNoVendor{constructor(t,e,r){this.net=t,this.genesis=e,this.headResolvers=[],this.int=new PromInt,this.cache=new Cache,this.pendingRequests={},this.head=r||{id:e.id,number:e.number,timestamp:e.timestamp,parentID:e.parentID,txsFeatures:e.txsFeatures,gasLimit:e.gasLimit},this.headTrackerLoop()}close(){this.int.interrupt()}pollHead(){return this.int.wrap(new Promise((t=>{this.headResolvers.push((()=>t(this.head)))})))}getBlock(t){return this.cache.getBlock(t,(()=>this.httpGet("blocks/"+t)))}getTransaction(t,e){return this.cache.getTx(t,(()=>{const r={head:this.head.id};return e&&(r.pending="true"),this.httpGet("transactions/"+t,r)}))}getReceipt(t){return this.cache.getReceipt(t,(()=>this.httpGet(`transactions/${t}/receipt`,{head:this.head.id})))}getAccount(t,e){return this.cache.getAccount(t,e,(()=>this.httpGet("accounts/"+t,{revision:e})))}getCode(t,e){return this.cache.getTied("code-"+t,e,(()=>this.httpGet(`accounts/${t}/code`,{revision:e})))}getStorage(t,e,r){return this.cache.getTied(`storage-${t}-${e}`,r,(()=>this.httpGet(`accounts/${t}/storage/${e}`,{revision:r})))}explain(t,e,r){const n="explain-"+st(JSON.stringify(t)).toString("hex");return this.cache.getTied(n,e,(()=>this.httpPost("accounts/*",t,{revision:e})),r)}filterEventLogs(t,e){const r="event-"+st(JSON.stringify(t)).toString("hex");return this.cache.getTied(r,this.head.id,(()=>this.httpPost("logs/event",t)),e)}filterTransferLogs(t,e){const r="transfer-"+st(JSON.stringify(t)).toString("hex");return this.cache.getTied(r,this.head.id,(()=>this.httpPost("logs/transfer",t)),e)}signTx(t,e){throw new Error("signer not implemented")}signCert(t,e){throw new Error("signer not implemented")}mergeRequest(t,...e){const r=JSON.stringify(e),n=this.pendingRequests[r];return n||(this.pendingRequests[r]=(()=>ft(this,void 0,void 0,(function*(){try{return yield t()}finally{delete this.pendingRequests[r]}})))())}httpGet(t,e){return this.mergeRequest((()=>this.net.http("GET",t,{query:e,validateResponseHeader:this.headerValidator})),t,e||"")}httpPost(t,e,r){return this.mergeRequest((()=>this.net.http("POST",t,{query:r,body:e,validateResponseHeader:this.headerValidator})),t,r||"",e||"")}get headerValidator(){return t=>{const e=t["x-genesis-id"];if(e&&e!==this.genesis.id)throw new Error("responded 'x-genesis-id' not matched")}}emitNewHead(){const t=this.headResolvers;this.headResolvers=[],t.forEach((t=>t()))}headTrackerLoop(){return ft(this,void 0,void 0,(function*(){for(;;){let t=!1;try{const e=yield this.int.wrap(this.httpGet("blocks/best"));e.id!==this.head.id&&e.number>=this.head.number&&(this.head={id:e.id,number:e.number,timestamp:e.timestamp,parentID:e.parentID,txsFeatures:e.txsFeatures,gasLimit:e.gasLimit},this.cache.handleNewBlock(this.head,void 0,e),this.emitNewHead(),Date.now()-1e3*this.head.timestamp<6e4&&(t=!0))}catch(t){if(t instanceof InterruptedError)break}if(t)try{yield this.trackWs()}catch(t){if(t instanceof InterruptedError)break}try{yield this.int.wrap(ct(8e3))}catch(t){break}}}))}trackWs(){return ft(this,void 0,void 0,(function*(){const t="subscriptions/beat2?pos="+this.head.parentID,e=this.net.openWebSocketReader(t);try{for(;;){const t=yield this.int.wrap(e.read()),r=JSON.parse(t);!r.obsolete&&r.id!==this.head.id&&r.number>=this.head.number&&(this.head={id:r.id,number:r.number,timestamp:r.timestamp,parentID:r.parentID,txsFeatures:r.txsFeatures,gasLimit:r.gasLimit},this.cache.handleNewBlock(this.head,{k:r.k,bits:r.bloom}),this.emitNewHead())}}finally{e.close()}}))}}var pt=r(8416),dt=r.n(pt),gt=r(9347);class SimpleWebSocketReader{constructor(t,e=3e4){this.timeout=e,this.callbacks=[],this.ws=new gt(t),this.ws.onmessage=t=>{try{const e=this.callbacks;this.callbacks=[],e.forEach((e=>e(t.data)))}catch(t){this.setError(t),this.ws.close()}},this.ws.onerror=t=>{this.setError(t.error),this.ws.close()},this.ws.onclose=()=>{this.setError(new Error("closed"))}}read(){return new Promise(((t,e)=>{if(this.error)return e(this.error);const r=setTimeout((()=>{e(new Error("ws read timeout"))}),this.timeout);this.callbacks.push(((n,i)=>{if(clearTimeout(r),i)return e(i);t(n)}))}))}close(){this.ws.close()}setError(t){if(!this.error){this.error=t;const e=this.callbacks;this.callbacks=[],e.forEach((e=>e(null,t)))}}}var mt=r(8575);class Agent{constructor(){}}var vt=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};class SimpleNet{constructor(t,e=3e4,r=3e4){this.baseURL=t,this.wsTimeout=r,this.axios=dt().create({httpAgent:new Agent({keepAlive:!0}),httpsAgent:new Agent({keepAlive:!0}),baseURL:t,timeout:e})}http(t,e,r){return vt(this,void 0,void 0,(function*(){r=r||{};try{const n=yield this.axios.request({method:t,url:e,data:r.body,headers:r.headers,params:r.query});return r.validateResponseHeader&&r.validateResponseHeader(n.headers),n.data}catch(r){if(r.isAxiosError)throw function(t){if(t.response){const e=t.response;if("string"==typeof e.data){let r=e.data.trim();return r.length>50&&(r=r.slice(0,50)+"..."),new Error(`${e.status} ${t.config.method} ${t.config.url}: ${r}`)}return new Error(`${e.status} ${t.config.method} ${t.config.url}`)}return new Error(`${t.config.method} ${t.config.url}: ${t.message}`)}(r);throw new Error(`${t} ${(0,mt.DB)(this.baseURL,e)}: ${r.message}`)}}))}openWebSocketReader(t){const e=(0,mt.DB)(this.baseURL,t).replace(/^http:/i,"ws:").replace(/^https:/i,"wss:");return new SimpleWebSocketReader(e,this.wsTimeout)}}var yt=r(8764).Buffer;const wt=r(1191);function bt(...t){const e=wt.blake2bInit(32,null);return t.forEach((t=>{yt.isBuffer(t)?wt.blake2bUpdate(e,t):wt.blake2bUpdate(e,yt.from(t,"utf8"))})),yt.from(wt.blake2bFinal(e))}var Mt=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};class LazyDriver{constructor(t){this.signer=t,this._driver=null}get noVendor(){if(!this._driver)throw new Error("thor driver is not ready");return this._driver}setNoVendor(t){this._driver=t}get genesis(){return this.noVendor.genesis}get head(){return this.noVendor.head}pollHead(){return this.noVendor.pollHead()}getBlock(t){return this.noVendor.getBlock(t)}getTransaction(t,e){return this.noVendor.getTransaction(t,e)}getReceipt(t){return this.noVendor.getReceipt(t)}getAccount(t,e){return this.noVendor.getAccount(t,e)}getCode(t,e){return this.noVendor.getCode(t,e)}getStorage(t,e,r){return this.noVendor.getStorage(t,e,r)}explain(t,e,r){return this.noVendor.explain(t,e,r)}filterEventLogs(t){return this.noVendor.filterEventLogs(t)}filterTransferLogs(t){return this.noVendor.filterTransferLogs(t)}signTx(t,e){return Mt(this,void 0,void 0,(function*(){return this.signer.then((r=>r.signTx(t,e)))}))}signCert(t,e){return Mt(this,void 0,void 0,(function*(){return this.signer.then((r=>r.signCert(t,e)))}))}}const xt={};function Et(t,e){const r=bt(JSON.stringify({node:t,genesis:e})).toString("hex");let n=xt[r];return n||(xt[r]=n=new DriverNoVendor(new SimpleNet(t),e)),n}const At={};var Nt=r(1798),kt=r.n(Nt),Ot=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};const St=t=>Ot(void 0,void 0,void 0,(function*(){return function(t,e){let r=At[t];if(!r){const n=document.createElement("script");At[t]=r=new Promise(((t,r)=>{n.onload=()=>t(window[e]),n.onerror=t=>r(new Error(t.toString()))})),n.src=t,document.body.appendChild(n)}return r}("https://unpkg.com/@vechain/connex-wallet-buddy@0.1","ConnexWalletBuddy").then((e=>e.create(t,(()=>kt()(16).toString("hex")),(t=>bt(t).toString("hex")))))})),It=t=>Ot(void 0,void 0,void 0,(function*(){const t=window.connex.vendor;return Promise.resolve({signTx:(e,r)=>{const n=t.sign("tx");if(r.signer&&n.signer(r.signer),r.gas&&n.gas(r.gas),r.dependsOn&&n.dependsOn(r.dependsOn),r.link&&n.link(r.link),r.comment&&n.link(r.comment),r.delegator){const t=r.delegator.url;n.delegate((e=>Ot(void 0,void 0,void 0,(function*(){return(yield fetch(t,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})).json()}))))}return r.onAccepted&&r.onAccepted(),n.request(e)},signCert:(e,r)=>{const n=t.sign("cert");return r.signer&&n.signer(r.signer),r.link&&n.link(r.link),r.onAccepted&&r.onAccepted(),n.request(e)}})}));function _t(t){if("string"==typeof(t=t||"main")){const e=tt[t];if(!e)throw new Error("invalid network");return e}return t}function Ut(t,e){switch(e.toLocaleLowerCase()){case"sync":if(!window.connex)throw new Error("Sync not found");if(window.connex.thor.genesis.id!==t)throw new Error("Network mismatch");return It;case"sync2":return St;default:throw new Error("unsupported signer")}}class ConnexClass{constructor(t){var e;const r=_t(t.network),n=Ut(r.id,null!==(e=t.signer)&&void 0!==e?e:"sync2"),i=function(t,e,r){const n=new LazyDriver(r(e.id));return n.setNoVendor(Et(t,e)),n}(t.node,r,n),o=new Framework(i);return{get thor(){return o.thor},get vendor(){return o.vendor}}}}ConnexClass.Thor=class ThorClass{constructor(t){const e=_t(t.network),r=Et(t.node,e),n=new Framework(r);return{get genesis(){return n.thor.genesis},get status(){return n.thor.status},get ticker(){return n.thor.ticker.bind(n.thor)},get account(){return n.thor.account.bind(n.thor)},get block(){return n.thor.block.bind(n.thor)},get transaction(){return n.thor.transaction.bind(n.thor)},get filter(){return n.thor.filter.bind(n.thor)},get explain(){return n.thor.explain.bind(n.thor)}}}},ConnexClass.Vendor=class VendorClass{constructor(t,e="sync2"){const r=Ut(t=function(t){if(/^0x[0-9a-f]{64}$/.test(t=t||"main"))return t;const e=tt[t];if(e)return e.id;throw new Error("invalid genesis id")}(t),e),n=C(new LazyDriver(r(t)));return{get sign(){return n.sign.bind(n)}}}};const Rt=ConnexClass},9742:(t,e)=>{"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=u(t),s=o[0],a=o[1],h=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,a)),l=0,c=a>0?s-4:s;for(r=0;r<c;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],h[l++]=e>>16&255,h[l++]=e>>8&255,h[l++]=255&e;2===a&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,h[l++]=255&e);1===a&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,h[l++]=e>>8&255,h[l++]=255&e);return h},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],s=16383,a=0,u=n-i;a<u;a+=s)o.push(h(t,a,a+s>u?u:a+s));1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,a=o.length;s<a;++s)r[s]=o[s],n[o.charCodeAt(s)]=s;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function h(t,e,n){for(var i,o,s=[],a=e;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},8442:(t,e,r)=>{const n=r(9488);function i(t,e,r){const n=t[e]+t[r];let i=t[e+1]+t[r+1];n>=4294967296&&i++,t[e]=n,t[e+1]=i}function o(t,e,r,n){let i=t[e]+r;r<0&&(i+=4294967296);let o=t[e+1]+n;i>=4294967296&&o++,t[e]=i,t[e+1]=o}function s(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function a(t,e,r,n,s,a){const u=c[s],h=c[s+1],f=c[a],p=c[a+1];i(l,t,e),o(l,t,u,h);let d=l[n]^l[t],g=l[n+1]^l[t+1];l[n]=g,l[n+1]=d,i(l,r,n),d=l[e]^l[r],g=l[e+1]^l[r+1],l[e]=d>>>24^g<<8,l[e+1]=g>>>24^d<<8,i(l,t,e),o(l,t,f,p),d=l[n]^l[t],g=l[n+1]^l[t+1],l[n]=d>>>16^g<<16,l[n+1]=g>>>16^d<<16,i(l,r,n),d=l[e]^l[r],g=l[e+1]^l[r+1],l[e]=g>>>31^d<<1,l[e+1]=d>>>31^g<<1}const u=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),h=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(t){return 2*t}))),l=new Uint32Array(32),c=new Uint32Array(32);function f(t,e){let r=0;for(r=0;r<16;r++)l[r]=t.h[r],l[r+16]=u[r];for(l[24]=l[24]^t.t,l[25]=l[25]^t.t/4294967296,e&&(l[28]=~l[28],l[29]=~l[29]),r=0;r<32;r++)c[r]=s(t.b,4*r);for(r=0;r<12;r++)a(0,8,16,24,h[16*r+0],h[16*r+1]),a(2,10,18,26,h[16*r+2],h[16*r+3]),a(4,12,20,28,h[16*r+4],h[16*r+5]),a(6,14,22,30,h[16*r+6],h[16*r+7]),a(0,10,20,30,h[16*r+8],h[16*r+9]),a(2,12,22,24,h[16*r+10],h[16*r+11]),a(4,14,16,26,h[16*r+12],h[16*r+13]),a(6,8,18,28,h[16*r+14],h[16*r+15]);for(r=0;r<16;r++)t.h[r]=t.h[r]^l[r]^l[r+16]}function p(t,e){if(0===t||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(e&&e.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");const r={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};for(let t=0;t<16;t++)r.h[t]=u[t];const n=e?e.length:0;return r.h[0]^=16842752^n<<8^t,e&&(d(r,e),r.c=128),r}function d(t,e){for(let r=0;r<e.length;r++)128===t.c&&(t.t+=t.c,f(t,!1),t.c=0),t.b[t.c++]=e[r]}function g(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;f(t,!0);const e=new Uint8Array(t.outlen);for(let r=0;r<t.outlen;r++)e[r]=t.h[r>>2]>>8*(3&r);return e}function m(t,e,r){r=r||64,t=n.normalizeInput(t);const i=p(r,e);return d(i,t),g(i)}t.exports={blake2b:m,blake2bHex:function(t,e,r){const i=m(t,e,r);return n.toHex(i)},blake2bInit:p,blake2bUpdate:d,blake2bFinal:g}},5297:(t,e,r)=>{const n=r(9488);function i(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function o(t,e,r,n,i,o){h[t]=h[t]+h[e]+i,h[n]=s(h[n]^h[t],16),h[r]=h[r]+h[n],h[e]=s(h[e]^h[r],12),h[t]=h[t]+h[e]+o,h[n]=s(h[n]^h[t],8),h[r]=h[r]+h[n],h[e]=s(h[e]^h[r],7)}function s(t,e){return t>>>e^t<<32-e}const a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),h=new Uint32Array(16),l=new Uint32Array(16);function c(t,e){let r=0;for(r=0;r<8;r++)h[r]=t.h[r],h[r+8]=a[r];for(h[12]^=t.t,h[13]^=t.t/4294967296,e&&(h[14]=~h[14]),r=0;r<16;r++)l[r]=i(t.b,4*r);for(r=0;r<10;r++)o(0,4,8,12,l[u[16*r+0]],l[u[16*r+1]]),o(1,5,9,13,l[u[16*r+2]],l[u[16*r+3]]),o(2,6,10,14,l[u[16*r+4]],l[u[16*r+5]]),o(3,7,11,15,l[u[16*r+6]],l[u[16*r+7]]),o(0,5,10,15,l[u[16*r+8]],l[u[16*r+9]]),o(1,6,11,12,l[u[16*r+10]],l[u[16*r+11]]),o(2,7,8,13,l[u[16*r+12]],l[u[16*r+13]]),o(3,4,9,14,l[u[16*r+14]],l[u[16*r+15]]);for(r=0;r<8;r++)t.h[r]^=h[r]^h[r+8]}function f(t,e){if(!(t>0&&t<=32))throw new Error("Incorrect output length, should be in [1, 32]");const r=e?e.length:0;if(e&&!(r>0&&r<=32))throw new Error("Incorrect key length, should be in [1, 32]");const n={h:new Uint32Array(a),b:new Uint8Array(64),c:0,t:0,outlen:t};return n.h[0]^=16842752^r<<8^t,r>0&&(p(n,e),n.c=64),n}function p(t,e){for(let r=0;r<e.length;r++)64===t.c&&(t.t+=t.c,c(t,!1),t.c=0),t.b[t.c++]=e[r]}function d(t){for(t.t+=t.c;t.c<64;)t.b[t.c++]=0;c(t,!0);const e=new Uint8Array(t.outlen);for(let r=0;r<t.outlen;r++)e[r]=t.h[r>>2]>>8*(3&r)&255;return e}function g(t,e,r){r=r||32,t=n.normalizeInput(t);const i=f(r,e);return p(i,t),d(i)}t.exports={blake2s:g,blake2sHex:function(t,e,r){const i=g(t,e,r);return n.toHex(i)},blake2sInit:f,blake2sUpdate:p,blake2sFinal:d}},1191:(t,e,r)=>{const n=r(8442),i=r(5297);t.exports={blake2b:n.blake2b,blake2bHex:n.blake2bHex,blake2bInit:n.blake2bInit,blake2bUpdate:n.blake2bUpdate,blake2bFinal:n.blake2bFinal,blake2s:i.blake2s,blake2sHex:i.blake2sHex,blake2sInit:i.blake2sInit,blake2sUpdate:i.blake2sUpdate,blake2sFinal:i.blake2sFinal}},9488:(t,e,r)=>{var n=r(8764).Buffer;function i(t){return(4294967296+t).toString(16).substring(1)}t.exports={normalizeInput:function(t){let e;if(t instanceof Uint8Array)e=t;else if(t instanceof n)e=new Uint8Array(t);else{if("string"!=typeof t)throw new Error("Input must be an string, Buffer or Uint8Array");e=new Uint8Array(n.from(t,"utf8"))}return e},toHex:function(t){return Array.prototype.map.call(t,(function(t){return(t<16?"0":"")+t.toString(16)})).join("")},debugPrint:function(t,e,r){let n="\n"+t+" = ";for(let o=0;o<e.length;o+=2){if(32===r)n+=i(e[o]).toUpperCase(),n+=" ",n+=i(e[o+1]).toUpperCase();else{if(64!==r)throw new Error("Invalid size "+r);n+=i(e[o+1]).toUpperCase(),n+=i(e[o]).toUpperCase()}o%6==4?n+="\n"+new Array(t.length+4).join(" "):o<e.length-2&&(n+=" ")}console.log(n)},testSpeed:function(t,e,r){let n=(new Date).getTime();const i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=t%256;const o=(new Date).getTime();console.log("Generated random input in "+(o-n)+"ms"),n=o;for(let o=0;o<r;o++){const r=t(i),o=(new Date).getTime(),s=o-n;n=o,console.log("Hashed in "+s+"ms: "+r.substring(0,20)+"..."),console.log(Math.round(e/(1<<20)/(s/1e3)*100)/100+" MB PER SECOND")}}}},8764:(t,e,r)=>{"use strict";var n=r(9742),i=r(645),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=function(t){+t!=t&&(t=0);return u.alloc(+t)},e.INSPECT_MAX_BYTES=50;var s=2147483647;function a(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return h(t,e,r)}function h(t,e,r){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|g(t,e),n=a(r),i=n.write(t,e);i!==r&&(n=n.slice(0,i));return n}(t,e);if(ArrayBuffer.isView(t))return f(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(G(t,ArrayBuffer)||t&&G(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(G(t,SharedArrayBuffer)||t&&G(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return u.from(n,e,r);var i=function(t){if(u.isBuffer(t)){var e=0|d(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}if(void 0!==t.length)return"number"!=typeof t.length||z(t.length)?a(0):f(t);if("Buffer"===t.type&&Array.isArray(t.data))return f(t.data)}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function l(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function c(t){return l(t),a(t<0?0:0|d(t))}function f(t){for(var e=t.length<0?0:0|d(t.length),r=a(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function d(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function g(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||G(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return D(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return F(t).length;default:if(i)return n?-1:D(t).length;e=(""+e).toLowerCase(),i=!0}}function m(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return O(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return _(this,e,r);case"base64":return k(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function v(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),z(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:w(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):w(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function w(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var l=-1;for(o=r;o<a;o++)if(h(t,o)===h(e,-1===l?0:o-l)){if(-1===l&&(l=o),o-l+1===u)return l*s}else-1!==l&&(o-=o-l),l=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var c=!0,f=0;f<u;f++)if(h(t,o+f)!==h(e,f)){c=!1;break}if(c)return o}return-1}function b(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(z(a))return s;t[r+s]=a}return s}function M(t,e,r,n){return q(D(e,t.length-r),t,r,n)}function x(t,e,r,n){return q(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function E(t,e,r,n){return x(t,e,r,n)}function A(t,e,r,n){return q(F(e),t,r,n)}function N(t,e,r,n){return q(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function k(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function O(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,h=t[i],l=null,c=h>239?4:h>223?3:h>191?2:1;if(i+c<=r)switch(c){case 1:h<128&&(l=h);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&h)<<6|63&o)>127&&(l=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(u=(15&h)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,c=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),i+=c}return function(t){var e=t.length;if(e<=S)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=S));return r}(n)}e.kMaxLength=s,u.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),u.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,r){return h(t,e,r)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,r){return function(t,e,r){return l(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},u.allocUnsafe=function(t){return c(t)},u.allocUnsafeSlow=function(t){return c(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(G(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),G(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=u.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(G(o,Uint8Array)&&(o=u.from(o)),!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},u.byteLength=g,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)v(this,e,e+1);return this},u.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)v(this,e,e+3),v(this,e+1,e+2);return this},u.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)v(this,e,e+7),v(this,e+1,e+6),v(this,e+2,e+5),v(this,e+3,e+4);return this},u.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?O(this,0,t):m.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},o&&(u.prototype[o]=u.prototype.inspect),u.prototype.compare=function(t,e,r,n,i){if(G(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)