From e9eb69315b75a04474a456ba3595076d98531ba5 Mon Sep 17 00:00:00 2001 From: dapiguabc Date: Fri, 16 Sep 2022 02:24:33 +0800 Subject: [PATCH 1/5] Update checkForTrasaction for v2 --- src/js/transactionBuilder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/transactionBuilder.js b/src/js/transactionBuilder.js index 1dd5ce7..9d8fccf 100644 --- a/src/js/transactionBuilder.js +++ b/src/js/transactionBuilder.js @@ -325,13 +325,13 @@ export class TransactionBuilder extends Network { return new Promise(async (resolve) => { let lastLatestBlock = this.startBlock || 0 - - + let count = this.maxBlockToCheck // Get the next 10 blocks from the blockservice starting with the block the transction was sent from const getLatestBlock = async () => { let latestBlock = await this.blockservice.getLastetBlock() if (latestBlock > lastLatestBlock){ lastLatestBlock = latestBlock + count = count - 1 checkForTrasaction() }else{ setTimeout(getLatestBlock, 5000) @@ -345,7 +345,7 @@ export class TransactionBuilder extends Network { this.txCheckResult = {...txResults, ...txResults.txInfo} resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); }else{ - if (lastLatestBlock - this.startBlock > this.maxBlockToCheck){ + if (count < 1){ this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} blocks after sending.`] this.txCheckResult.status = 2 resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); From fdcb49b2613d15f838714981741cbfc2b9df6c4b Mon Sep 17 00:00:00 2001 From: dapiguabc Date: Wed, 21 Sep 2022 21:16:41 +0800 Subject: [PATCH 2/5] Unify APIs --- src/js/blockservice-api.js | 24 +++- src/js/masternode-api.js | 13 +- src/js/network.js | 65 +++++++++ src/js/transactionBuilder.js | 5 + test/network-test.js | 262 ++++++++++++++++++++++------------- 5 files changed, 269 insertions(+), 100 deletions(-) diff --git a/src/js/blockservice-api.js b/src/js/blockservice-api.js index 43eafde..a87ee87 100644 --- a/src/js/blockservice-api.js +++ b/src/js/blockservice-api.js @@ -63,7 +63,7 @@ async pingServer() { } async getLastetBlock(callback){ - return this.send("GET", "/latest_block") + return this.send("GET", "/latest_block", {}) .then(res => res.json()) .then(json => { if (callback) callback(json.latest_block, null) @@ -136,4 +136,24 @@ async getTransaction(hash, callback) { } }) } -} \ No newline at end of file + +async getContractInfo(contractName) { + return this.send("GET", `/contracts/${contractName}`, {}) + .then(res => res.json()) + .then(json => { + if (Object.keys(json).length > 0) { + let data = json[contractName] + return { + name: contractName, + code: data['__code__'] + } + } else { + return {"error":`${contractName} does not exist`} + } + }) + .catch(err => { + return {error: err.message} + }) +} +} + diff --git a/src/js/masternode-api.js b/src/js/masternode-api.js index bb7919d..5c2bc56 100644 --- a/src/js/masternode-api.js +++ b/src/js/masternode-api.js @@ -74,7 +74,7 @@ export class LamdenMasterNode_API { try { if (res.name) return res; } catch (e) {} - return null; + return {"error":`${contractName} does not exist`}; }; let path = `/contracts/${contractName}`; return this.send("GET", path, {}, undefined, (res, err) => returnInfo(res)).then((res) => @@ -208,4 +208,15 @@ export class LamdenMasterNode_API { return res; }); } + + async getLastetBlock(){ + return this.send("GET", "/latest_block", {}) + .then(res => res.json()) + .then(json => { + return { value: json.number } + }) + .catch(err => { + return {error: err.message} + }) + } } diff --git a/src/js/network.js b/src/js/network.js index 6e8acbe..e76db33 100644 --- a/src/js/network.js +++ b/src/js/network.js @@ -91,4 +91,69 @@ export class Network { version: this.version }; } + + // Unify APIs + async pingServer() { + let res; + if (this.blockservice.host) { + res = await this.blockservice.pingServer(); + } else { + res = await this.API.pingServer(); + } + return res + } + + async getVariable(contractName, variableName, key) { + if (this.blockservice.host) { + let data = await this.blockservice.getCurrentKeyValue(contractName, variableName, key); + return data + } else { + let res = await this.API.getVariable(contractName, variableName, key); + if (res) { + return { + value: res + } + } else { + return {error: "key or variable not exists"} + } + } + } + + async getCurrencyBalance(vk) { + return await this.getVariable("currency", "balances", vk) + } + + async getContractInfo(contractName) { + if (this.blockservice.host) { + return await this.blockservice.getContractInfo(contractName); + } else { + return await this.API.getContractInfo(contractName); + } + } + + async contractExists(contractName) { + let data; + if (this.blockservice.host) { + data = await this.blockservice.getContractInfo(contractName); + } else { + data = await this.API.getContractInfo(contractName); + } + return data && data.name ? true : false + } + + async getLastetBlock() { + if (this.blockservice.host) { + let data = await this.blockservice.getLastetBlock(); + if (data.error) { + return data + } else { + return { + value: data + } + } + } else { + return await this.API.getLastetBlock(); + } + } + } diff --git a/src/js/transactionBuilder.js b/src/js/transactionBuilder.js index 9d8fccf..d063bf0 100644 --- a/src/js/transactionBuilder.js +++ b/src/js/transactionBuilder.js @@ -305,6 +305,11 @@ export class TransactionBuilder extends Network { ); }); } + + async checkTransactionResult(callback) { + await checkBlockserviceForTransactionResult(callback) + } + async checkBlockserviceForTransactionResult(callback = undefined) { if (!this.txHash) { throw new Error("No transaction hash to check.") diff --git a/test/network-test.js b/test/network-test.js index b8bbadd..df052c3 100644 --- a/test/network-test.js +++ b/test/network-test.js @@ -14,113 +14,181 @@ function copyObject(object) { } describe("Test Netowrk class", () => { - context("Constructor", () => { - it("can create an instance", () => { - let network = new Lamden.Network(goodNetwork); - expect(network).to.exist; - expect(JSON.stringify(network.hosts)).to.be(JSON.stringify(goodNetwork.hosts)); - expect(network.host).to.be(goodNetwork.hosts[0]); - expect(network.url).to.be(goodNetwork.hosts[0]); - expect(network.type).to.be(goodNetwork.type); - expect(network.name).to.be(goodNetwork.name); - expect(network.lamden).to.be(goodNetwork.lamden); - expect(network.blockExplorer).to.be(goodNetwork.blockExplorer); - expect(network.classname).to.be('Network'); - expect(network.version).to.be(1); - }); + // context("Constructor", () => { + // it("can create an instance", () => { + // let network = new Lamden.Network(goodNetwork); + // expect(network).to.exist; + // expect(JSON.stringify(network.hosts)).to.be(JSON.stringify(goodNetwork.hosts)); + // expect(network.host).to.be(goodNetwork.hosts[0]); + // expect(network.url).to.be(goodNetwork.hosts[0]); + // expect(network.type).to.be(goodNetwork.type); + // expect(network.name).to.be(goodNetwork.name); + // expect(network.lamden).to.be(goodNetwork.lamden); + // expect(network.blockExplorer).to.be(goodNetwork.blockExplorer); + // expect(network.classname).to.be('Network'); + // expect(network.version).to.be(1); + // }); - it("rejects missing hosts Array", () => { - let error; - try { - let networkInfo = copyObject(goodNetwork); - delete networkInfo.hosts; - new Lamden.Network(networkInfo); - } catch (e) { - error = e; - } - expect(error.message).to.be("HOSTS Required (Type: Array)"); - }); - it("rejects no protocol in host string", () => { - let error; - try { - let networkInfo = copyObject(goodNetwork); - networkInfo.hosts = ["missing.protocol.com"]; - new Lamden.Network(networkInfo); - } catch (e) { - error = e; - } - expect(error.message).to.be("Host String must include http:// or https://"); - }); - it("defaults missing type to custom", () => { - let networkInfo = copyObject(goodNetwork); - networkInfo.type = ""; - let network = new Lamden.Network(networkInfo); - expect(network.type).to.be("custom"); - }); - it("rejects arg not being an object", () => { - let error; - try { - new Lamden.Network("https://testnet-master-1.lamden.io:443"); - } catch (e) { - error = e; - } - expect(error.message).to.be("Expected Network Info Object and got Type: string"); - }); - it("sets network version to 2 if provided", () => { + // it("rejects missing hosts Array", () => { + // let error; + // try { + // let networkInfo = copyObject(goodNetwork); + // delete networkInfo.hosts; + // new Lamden.Network(networkInfo); + // } catch (e) { + // error = e; + // } + // expect(error.message).to.be("HOSTS Required (Type: Array)"); + // }); + // it("rejects no protocol in host string", () => { + // let error; + // try { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.hosts = ["missing.protocol.com"]; + // new Lamden.Network(networkInfo); + // } catch (e) { + // error = e; + // } + // expect(error.message).to.be("Host String must include http:// or https://"); + // }); + // it("defaults missing type to custom", () => { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.type = ""; + // let network = new Lamden.Network(networkInfo); + // expect(network.type).to.be("custom"); + // }); + // it("rejects arg not being an object", () => { + // let error; + // try { + // new Lamden.Network("https://testnet-master-1.lamden.io:443"); + // } catch (e) { + // error = e; + // } + // expect(error.message).to.be("Expected Network Info Object and got Type: string"); + // }); + // it("sets network version to 2 if provided", () => { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.version = 2 + // let network = new Lamden.Network(networkInfo); + // expect(network.version).to.be(2); + + // }) + // it("sets network version to 1 version set to anything else", () => { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.version = "a" + // let network = new Lamden.Network(networkInfo); + // expect(network.version).to.be(1); + // }) + // }); + // context("Ping Network", () => { + // it("emits online status", async () => { + // function checkResult(result) { + // expect(result).to.be(true); + // } + // let network = new Lamden.Network(goodNetwork); + // network.events.on("online", (status) => checkResult(status)); + // await network.ping(); + // }); + + // it("return value from method return", async () => { + // function checkResult(result) { + // expect(result).to.be(true); + // } + // let network = new Lamden.Network(goodNetwork); + // let status = await network.ping(); + // checkResult(status); + // }); + // it("returns online status through callback", async () => { + // function checkResult(result) { + // expect(result).to.be(true); + // } + // let network = new Lamden.Network(goodNetwork); + // await network.ping((status) => checkResult(status)); + // }); + // }); + // context("getNetworkInfo()", () => { + // it("returns proper values", async () => { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.version = 2 + // let network = new Lamden.Network(networkInfo); + + // expect(Object.keys(network.getNetworkInfo()).length).to.be(8) + // expect(network.host).to.exist + // expect(network.url).to.exist + // expect(network.type).to.exist + // expect(network.name).to.exist + // expect(network.lamden).to.exist + // expect(network.blockExplorer).to.exist + // expect(network.classname).to.exist + // expect(network.version).to.exist + // }) + // }) + + // context("pingServer()", () => { + // it("returns proper values", async () => { + // let networkInfo = copyObject(goodNetwork); + // networkInfo.version = 2 + // let network = new Lamden.Network(networkInfo); + // let res = await network.pingServer(); + // expect(res).to.be(true) + // }) + // }) + context("getCurrencyBalance()", () => { + it("returns proper values", async () => { let networkInfo = copyObject(goodNetwork); networkInfo.version = 2 - let network = new Lamden.Network(networkInfo); - expect(network.version).to.be(2); - + let network = new Lamden.Network(networkInfo); + let res = await network.getCurrencyBalance("960c002a36c30c3aec8bc670e9b8b40eebcfd545f4e9237579fd7395a21ccebb"); + expect(res.value).to.exist; }) - it("sets network version to 1 version set to anything else", () => { + it("It should return error", async () => { let networkInfo = copyObject(goodNetwork); - networkInfo.version = "a" - let network = new Lamden.Network(networkInfo); - expect(network.version).to.be(1); + networkInfo.version = 2 + let network = new Lamden.Network(networkInfo); + let res = await network.getCurrencyBalance("errorkey"); + expect(res.error).to.be('key or variable not exists'); }) - }); - context("Ping Network", () => { - it("emits online status", async () => { - function checkResult(result) { - expect(result).to.be(true); - } - let network = new Lamden.Network(goodNetwork); - network.events.on("online", (status) => checkResult(status)); - await network.ping(); - }); - - it("return value from method return", async () => { - function checkResult(result) { - expect(result).to.be(true); - } - let network = new Lamden.Network(goodNetwork); - let status = await network.ping(); - checkResult(status); - }); - it("returns online status through callback", async () => { - function checkResult(result) { - expect(result).to.be(true); - } - let network = new Lamden.Network(goodNetwork); - await network.ping((status) => checkResult(status)); - }); - }); - context("getNetworkInfo()", () => { + }) + context("getContractInfo()", () => { it("returns proper values", async () => { let networkInfo = copyObject(goodNetwork); networkInfo.version = 2 let network = new Lamden.Network(networkInfo); - - expect(Object.keys(network.getNetworkInfo()).length).to.be(8) - expect(network.host).to.exist - expect(network.url).to.exist - expect(network.type).to.exist - expect(network.name).to.exist - expect(network.lamden).to.exist - expect(network.blockExplorer).to.exist - expect(network.classname).to.exist - expect(network.version).to.exist + let res = await network.getContractInfo("currency"); + expect(res.name).to.be('currency') + expect(res.code).to.exist + }) + it("should return error", async () => { + let networkInfo = copyObject(goodNetwork); + networkInfo.version = 2 + let network = new Lamden.Network(networkInfo); + let res = await network.getContractInfo("currency-not-exists"); + expect(res.error).to.be(`currency-not-exists does not exist`) + }) + }) + context("contractExists()", () => { + it("returns true", async () => { + let networkInfo = copyObject(goodNetwork); + networkInfo.version = 2 + let network = new Lamden.Network(networkInfo); + let res = await network.contractExists("currency"); + expect(res).to.be(true) + }) + it("returns false", async () => { + let networkInfo = copyObject(goodNetwork); + networkInfo.version = 2 + let network = new Lamden.Network(networkInfo); + let res = await network.contractExists("currency-not-exists"); + expect(res).to.be(false) + }) + }) + context("getLastetBlock()", () => { + it("returns true", async () => { + let networkInfo = copyObject(goodNetwork); + networkInfo.version = 2 + let network = new Lamden.Network(networkInfo); + let res = await network.getLastetBlock(); + expect(res.value).to.exist }) }) }); From d64afc975d43447159352794026040a8b9474e0c Mon Sep 17 00:00:00 2001 From: dapiguabc Date: Wed, 21 Sep 2022 21:17:18 +0800 Subject: [PATCH 3/5] Typescript support for Unify APIs --- package.json | 1 + src/index.d.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/index.d.ts diff --git a/package.json b/package.json index af28309..4ea7af7 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "3.7.5", "description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.", "main": "dist/cjs/lamden.js", + "types": "src/index.d.ts", "module": "dist/esm/lamden.js", "scripts": { "test": "npm run build && mocha --recursive --timeout 30000", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..73b9bc8 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,53 @@ +declare module 'lamden-js' { + export class TransactionBuilder extends Network {} + + export class Network { + version: string + events: EventEmitter + hosts: string[] + currencySymbol: string + name: string + lamden: boolean + blockExplorer: string | undefined + + get host(): string + get url(): string + getNetworkVersion(): number + getNetworkInfo(): WalletMeta + pingServer(): Promise + getVariable(contractName: string, variableName: string, key: string): Promise<{ + value?: number | Float | string + error?: string + }> + getCurrencyBalance(vk: string): Promise<{ + value?: number | Float | string + error?: string + }> + contractExists(contractName: string): Promise + getLastetBlock(): Promise<{ + value?: number + error?: string + }> + } + + type WalletMeta = { + name: string, + lamden: boolean, + type: string, + hosts: string[], + blockservice_hosts: string[], + url: string, + online: boolean, + version: string + } + + type Float = { + __fixed__: string + } + + interface EventEmitter { + on(name: string, listener: Function): void + removeListener(name: string, listenerToRemove: Function): void + emit(name:string, data: object): void + } +} \ No newline at end of file From 50bb5393d7340163645e88d23be10f9de5dd2092 Mon Sep 17 00:00:00 2001 From: dapiguabc Date: Thu, 22 Sep 2022 23:42:51 +0800 Subject: [PATCH 4/5] fix test cases --- dist/cjs/lamden.js | 3657 ++++++++++++++++--------------- dist/esm/lamden.js | 2 +- package-lock.json | 1826 ++++++--------- package.json | 8 +- src/js/blockservice-api.js | 1 - src/js/transactionBuilder.js | 16 +- test/browsers/encoder-test.js | 8 +- test/masternode_api-test.js | 4 +- test/transactionBuilder-test.js | 63 +- 9 files changed, 2667 insertions(+), 2918 deletions(-) diff --git a/dist/cjs/lamden.js b/dist/cjs/lamden.js index 55c69ef..afcc175 100644 --- a/dist/cjs/lamden.js +++ b/dist/cjs/lamden.js @@ -2628,143 +2628,143 @@ var JsonFormatter$1 = jsonformatter.JsonFormatter; cryptojs.CryptoJS = CryptoJS$1; cryptojs.JsonFormatter = JsonFormatter$1; -const { CryptoJS, JsonFormatter } = cryptojs; -const { validateTypes: validateTypes$5, assertTypes: assertTypes$1 } = validators; - -/** - * Encrypt a Javascript object with a string password - * The object passed must pass JSON.stringify or the method will fail. - * - * @param {string} password A password to encrypt the object with - * @param {Object} obj A javascript object (must be JSON compatible) - * @return {string} Encrypted string - */ -function encryptObject(password, obj) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isObject(obj); - - const encrypted = CryptoJS.AES.encrypt(JSON.stringify(obj), password, { - format: JsonFormatter, - }).toString(); - return encrypted; -} - -/** - * Decrypt an Object using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} objString A javascript object as JSON string - * @return {string} Encrypted string - */ -function decryptObject(password, objString) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isStringWithValue(objString); - - try { - const decrypt = CryptoJS.AES.decrypt(objString, password, { format: JsonFormatter }); - return JSON.parse(CryptoJS.enc.Utf8.stringify(decrypt)); - } catch (e) { - return false; - } -} - -/** - * Encrypt a string using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} string A string to be password encrypted - * @return {string} Encrypted string - */ -function encryptStrHash(password, string) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isString(string); - - const encrypt = CryptoJS.AES.encrypt(string, password).toString(); - return encrypt; -} - -/** - * Decrypt a string using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} encryptedString A string to decrypt - * @return {string} Decrypted string - */ -function decryptStrHash(password, encryptedString) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isStringWithValue(encryptedString); - - try { - const decrypted = CryptoJS.AES.decrypt(encryptedString, password); - return CryptoJS.enc.Utf8.stringify(decrypted) === "" - ? false - : CryptoJS.enc.Utf8.stringify(decrypted); - } catch (e) { - return false; - } -} - -function buf2hex(buffer) { - return Array.prototype.map - .call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)) - .join(""); -} -function hex2buf(hexString) { - var bytes = new Uint8Array(Math.ceil(hexString.length / 2)); - for (var i = 0; i < bytes.length; i++) bytes[i] = parseInt(hexString.substr(i * 2, 2), 16); - return bytes; -} -function str2buf(string) { - var buf = new Buffer.from(string); - return new Uint8Array(buf); -} -function concatUint8Arrays(array1, array2) { - var arr = new Uint8Array(array1.length + array2.length); - arr.set(array1); - arr.set(array2, array1.length); - return arr; -} -function ab2str(buf) { - return String.fromCharCode.apply(null, new Uint8Array(buf)); -} -function str2ab(str) { - var buf = new ArrayBuffer(str.length); - var bufView = new Uint8Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; -} -function str2hex(str) { - var hex = ""; - for (var i = 0; i < str.length; i++) { - hex += "" + str.charCodeAt(i).toString(16); - } - return hex; -} -function hex2str(hexx) { - var hex = hexx.toString(); //force conversion - var str = ""; - for (var i = 0; i < hex.length && hex.substr(i, 2) !== "00"; i += 2) - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - return str; -} -function randomString(length) { - var text = ""; - var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (var i = 0; i < length; i++) { - text += possible.charAt(Math.floor(Math.random() * possible.length)); - } - return text; -} -function isStringHex(string = "") { - let hexRegEx = /([0-9]|[a-f])/gim; - return typeof string === "string" && (string.match(hexRegEx) || []).length === string.length; -} - -function isLamdenKey(string) { - if (validateTypes$5.isStringHex(string) && string.length === 64) return true; - return false; +const { CryptoJS, JsonFormatter } = cryptojs; +const { validateTypes: validateTypes$5, assertTypes: assertTypes$1 } = validators; + +/** + * Encrypt a Javascript object with a string password + * The object passed must pass JSON.stringify or the method will fail. + * + * @param {string} password A password to encrypt the object with + * @param {Object} obj A javascript object (must be JSON compatible) + * @return {string} Encrypted string + */ +function encryptObject(password, obj) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isObject(obj); + + const encrypted = CryptoJS.AES.encrypt(JSON.stringify(obj), password, { + format: JsonFormatter, + }).toString(); + return encrypted; +} + +/** + * Decrypt an Object using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} objString A javascript object as JSON string + * @return {string} Encrypted string + */ +function decryptObject(password, objString) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isStringWithValue(objString); + + try { + const decrypt = CryptoJS.AES.decrypt(objString, password, { format: JsonFormatter }); + return JSON.parse(CryptoJS.enc.Utf8.stringify(decrypt)); + } catch (e) { + return false; + } +} + +/** + * Encrypt a string using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} string A string to be password encrypted + * @return {string} Encrypted string + */ +function encryptStrHash(password, string) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isString(string); + + const encrypt = CryptoJS.AES.encrypt(string, password).toString(); + return encrypt; +} + +/** + * Decrypt a string using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} encryptedString A string to decrypt + * @return {string} Decrypted string + */ +function decryptStrHash(password, encryptedString) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isStringWithValue(encryptedString); + + try { + const decrypted = CryptoJS.AES.decrypt(encryptedString, password); + return CryptoJS.enc.Utf8.stringify(decrypted) === "" + ? false + : CryptoJS.enc.Utf8.stringify(decrypted); + } catch (e) { + return false; + } +} + +function buf2hex(buffer) { + return Array.prototype.map + .call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); +} +function hex2buf(hexString) { + var bytes = new Uint8Array(Math.ceil(hexString.length / 2)); + for (var i = 0; i < bytes.length; i++) bytes[i] = parseInt(hexString.substr(i * 2, 2), 16); + return bytes; +} +function str2buf(string) { + var buf = new Buffer.from(string); + return new Uint8Array(buf); +} +function concatUint8Arrays(array1, array2) { + var arr = new Uint8Array(array1.length + array2.length); + arr.set(array1); + arr.set(array2, array1.length); + return arr; +} +function ab2str(buf) { + return String.fromCharCode.apply(null, new Uint8Array(buf)); +} +function str2ab(str) { + var buf = new ArrayBuffer(str.length); + var bufView = new Uint8Array(buf); + for (var i = 0, strLen = str.length; i < strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; +} +function str2hex(str) { + var hex = ""; + for (var i = 0; i < str.length; i++) { + hex += "" + str.charCodeAt(i).toString(16); + } + return hex; +} +function hex2str(hexx) { + var hex = hexx.toString(); //force conversion + var str = ""; + for (var i = 0; i < hex.length && hex.substr(i, 2) !== "00"; i += 2) + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + return str; +} +function randomString(length) { + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + for (var i = 0; i < length; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + return text; +} +function isStringHex(string = "") { + let hexRegEx = /([0-9]|[a-f])/gim; + return typeof string === "string" && (string.match(hexRegEx) || []).length === string.length; +} + +function isLamdenKey(string) { + if (validateTypes$5.isStringHex(string) && string.length === 64) return true; + return false; } var utils$1 = /*#__PURE__*/Object.freeze({ @@ -2786,228 +2786,228 @@ var utils$1 = /*#__PURE__*/Object.freeze({ isLamdenKey: isLamdenKey }); -/** - * Create a wallet object for signing and verifying messages - * - * @param {Object} [args={}] Args Object - * @param {string} [args.sk=undefined] A 32 character long hex representation of a signing key (private key) to create wallet from - * @param {Uint8Array(length: 32)} [args.seed=null] A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be avoided by everyday users - * @param {boolean} [args.keepPrivate=false] No direct access to the sk. Will still allow the wallet to sign messages - * @return {Object} Wallet Object with sign and verify methods - */ -let create_wallet = (args = {}) => { - let { sk = undefined, keepPrivate = false, seed = null } = args; - - let vk; - - if (sk) { - vk = get_vk(sk); - } else { - let keyPair = new_wallet(seed); - vk = keyPair.vk; - sk = keyPair.sk; - } - - const wallet = () => { - return { - sign: (msg) => sign$1(sk, msg), - verify: (msg, sig) => verify(vk, msg, sig), - vk, - sk: !keepPrivate ? sk : undefined, - }; - }; - - return wallet(); -}; - -/** - * @param Uint8Array(length: 32) seed - * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be - * avoided by everyday users - * - * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - */ -function generate_keys(seed = null) { - var kp = null; - if (seed == null) { - kp = nacl__default["default"].sign.keyPair(); - } else { - kp = nacl__default["default"].sign.keyPair.fromSeed(seed); - } - // In the JS implementation of the NaCL library the sk is the first 32 bytes of the secretKey - // and the vk is the last 32 bytes of the secretKey as well as the publicKey - // { - // 'publicKey': , - // 'secretKey': - // } - return { - sk: new Uint8Array(kp["secretKey"].slice(0, 32)), - vk: new Uint8Array(kp["secretKey"].slice(32, 64)), - }; -} -/** - * @param String sk - * sk: A 64 character long hex representation of a signing key (private key) - * - * @return String vk - * vk: A 64 character long hex representation of a verify key (public key) - */ -function get_vk(sk) { - var kp = format_to_keys(sk); - var kpf = keys_to_format(kp); - return kpf.vk; -} -/** - * @param String sk - * sk: A 64 character long hex representation of a signing key (private key) - * - * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - */ -function format_to_keys(sk) { - var skf = hex2buf(sk); - var kp = generate_keys(skf); - return kp; -} -/** - * @param Object kp - * kp: Object containing the properties sk and vk - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - * - * @return {string, string} { sk, vk } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - */ -function keys_to_format(kp) { - return { - vk: buf2hex(kp.vk), - sk: buf2hex(kp.sk), - }; -} -/** - * @param Uint8Array(length: 32) seed - * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be - * avoided by everyday users - * - * @return {string, string} { sk, vk } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - */ -function new_wallet(seed = null) { - const keys = generate_keys(seed); - return keys_to_format(keys); -} - -/** - * - * @param seed Bip39 seed phrase (128 characters in hex) - * @param derivationIndex bip32 derivation key index - * @returns {{derivationIndex: number, vk: string, sk: string, mnemonic: string}} - * derivationIndex: bip32 derivation key index - * vk: Verify Key (VK) represented as a 64 character hex string - * sk: Signing Key (SK) represented as a 64 character hex string - * seed: Bip39 seed phrase (128 characters in hex) - * mnemonic: Bip39 24 words mnemonic - */ -function generate_keys_bip39(seed = undefined, derivationIndex = 0) { - let finalSeed; - let finalMnemonic; - - if (seed !== undefined){ - finalSeed = seed; - }else { - finalMnemonic = bip39__namespace.generateMnemonic(256); - finalSeed = bip39__namespace.mnemonicToSeedSync(finalMnemonic).toString('hex'); - } - - const derivationPath = "m/44'/789'/" + derivationIndex + "'/0'/0'"; - const { key, chainCode } = bip32__default["default"].derivePath(derivationPath, finalSeed, 0x80000000); - - const privateKey = key.toString("hex"); - const publicKey = bip32__default["default"].getPublicKey(key, false).toString("hex"); - - if (publicKey !== get_vk(privateKey)) { - throw Error("Bip32 public key does not match with Lamden public key!"); - } - - return { - sk: privateKey, - vk: publicKey, - derivationIndex: derivationIndex, - seed: seed !== undefined ? null : finalSeed, - mnemonic: seed !== undefined ? null : finalMnemonic, - } -} - -/** - * @param seed Bip39 seed phrase (128 characters in hex) - * @param derivationIndex bip32 derivation key index - * - * @return {{derivationIndex: number, vk: string, sk: string, mnemonic: (string|undefined)}} { sk, vk, derivationIndex, mnemonic } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - * derivationIndex: Bip32 derivation index - * seed: Bip39 seed phrase (128 characters in hex) - * mnemonic: Bip39 24 words mnemonic - */ -function new_wallet_bip39(seed = undefined, derivationIndex = 0) { - return generate_keys_bip39(seed, derivationIndex); -} - -/** - * @param String sk - * @param Uint8Array msg - * sk: A 64 character long hex representation of a signing key (private key) - * msg: A Uint8Array of bytes representing the message you would like to sign - * - * @return String sig - * sig: A 128 character long hex string representing the message's signature - */ -function sign$1(sk, msg) { - var kp = format_to_keys(sk); - // This is required due to the secretKey required to sign a transaction - // in the js implementation of NaCL being the combination of the sk and - // vk for some stupid reason. That being said, we still want the sk and - // vk objects to exist in 32-byte string format (same as cilantro's - // python implementation) when presented to the user. - var jsnacl_sk = concatUint8Arrays(kp.sk, kp.vk); - return buf2hex(nacl__default["default"].sign.detached(msg, jsnacl_sk)); -} -/** - * @param String vk - * @param Uint8Array msg - * @param String sig - * vk: A 64 character long hex representation of a verify key (public key) - * msg: A Uint8Array (bytes) representation of a message that has been signed - * sig: A 128 character long hex representation of a nacl signature - * - * @return Bool result - * result: true if verify checked out, false if not - */ -function verify(vk, msg, sig) { - var vkb = hex2buf(vk); - var sigb = hex2buf(sig); - try { - return nacl__default["default"].sign.detached.verify(msg, sigb, vkb); - } catch (_a) { - return false; - } -} -/** - * @param string mnemonic - * @param string[] wordList - * mnemonic: Bip39 24 words mnemonic - * wordList: An array of string(Optional) - * - * @return Boolen res - * res: A boolen value - */ -function validateMnemonic(mnemonic, wordList) { - return bip39__namespace.validateMnemonic(mnemonic, wordList); +/** + * Create a wallet object for signing and verifying messages + * + * @param {Object} [args={}] Args Object + * @param {string} [args.sk=undefined] A 32 character long hex representation of a signing key (private key) to create wallet from + * @param {Uint8Array(length: 32)} [args.seed=null] A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be avoided by everyday users + * @param {boolean} [args.keepPrivate=false] No direct access to the sk. Will still allow the wallet to sign messages + * @return {Object} Wallet Object with sign and verify methods + */ +let create_wallet = (args = {}) => { + let { sk = undefined, keepPrivate = false, seed = null } = args; + + let vk; + + if (sk) { + vk = get_vk(sk); + } else { + let keyPair = new_wallet(seed); + vk = keyPair.vk; + sk = keyPair.sk; + } + + const wallet = () => { + return { + sign: (msg) => sign$1(sk, msg), + verify: (msg, sig) => verify(vk, msg, sig), + vk, + sk: !keepPrivate ? sk : undefined, + }; + }; + + return wallet(); +}; + +/** + * @param Uint8Array(length: 32) seed + * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be + * avoided by everyday users + * + * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + */ +function generate_keys(seed = null) { + var kp = null; + if (seed == null) { + kp = nacl__default["default"].sign.keyPair(); + } else { + kp = nacl__default["default"].sign.keyPair.fromSeed(seed); + } + // In the JS implementation of the NaCL library the sk is the first 32 bytes of the secretKey + // and the vk is the last 32 bytes of the secretKey as well as the publicKey + // { + // 'publicKey': , + // 'secretKey': + // } + return { + sk: new Uint8Array(kp["secretKey"].slice(0, 32)), + vk: new Uint8Array(kp["secretKey"].slice(32, 64)), + }; +} +/** + * @param String sk + * sk: A 64 character long hex representation of a signing key (private key) + * + * @return String vk + * vk: A 64 character long hex representation of a verify key (public key) + */ +function get_vk(sk) { + var kp = format_to_keys(sk); + var kpf = keys_to_format(kp); + return kpf.vk; +} +/** + * @param String sk + * sk: A 64 character long hex representation of a signing key (private key) + * + * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + */ +function format_to_keys(sk) { + var skf = hex2buf(sk); + var kp = generate_keys(skf); + return kp; +} +/** + * @param Object kp + * kp: Object containing the properties sk and vk + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + * + * @return {string, string} { sk, vk } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + */ +function keys_to_format(kp) { + return { + vk: buf2hex(kp.vk), + sk: buf2hex(kp.sk), + }; +} +/** + * @param Uint8Array(length: 32) seed + * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be + * avoided by everyday users + * + * @return {string, string} { sk, vk } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + */ +function new_wallet(seed = null) { + const keys = generate_keys(seed); + return keys_to_format(keys); +} + +/** + * + * @param seed Bip39 seed phrase (128 characters in hex) + * @param derivationIndex bip32 derivation key index + * @returns {{derivationIndex: number, vk: string, sk: string, mnemonic: string}} + * derivationIndex: bip32 derivation key index + * vk: Verify Key (VK) represented as a 64 character hex string + * sk: Signing Key (SK) represented as a 64 character hex string + * seed: Bip39 seed phrase (128 characters in hex) + * mnemonic: Bip39 24 words mnemonic + */ +function generate_keys_bip39(seed = undefined, derivationIndex = 0) { + let finalSeed; + let finalMnemonic; + + if (seed !== undefined){ + finalSeed = seed; + }else { + finalMnemonic = bip39__namespace.generateMnemonic(256); + finalSeed = bip39__namespace.mnemonicToSeedSync(finalMnemonic).toString('hex'); + } + + const derivationPath = "m/44'/789'/" + derivationIndex + "'/0'/0'"; + const { key, chainCode } = bip32__default["default"].derivePath(derivationPath, finalSeed, 0x80000000); + + const privateKey = key.toString("hex"); + const publicKey = bip32__default["default"].getPublicKey(key, false).toString("hex"); + + if (publicKey !== get_vk(privateKey)) { + throw Error("Bip32 public key does not match with Lamden public key!"); + } + + return { + sk: privateKey, + vk: publicKey, + derivationIndex: derivationIndex, + seed: seed !== undefined ? null : finalSeed, + mnemonic: seed !== undefined ? null : finalMnemonic, + } +} + +/** + * @param seed Bip39 seed phrase (128 characters in hex) + * @param derivationIndex bip32 derivation key index + * + * @return {{derivationIndex: number, vk: string, sk: string, mnemonic: (string|undefined)}} { sk, vk, derivationIndex, mnemonic } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + * derivationIndex: Bip32 derivation index + * seed: Bip39 seed phrase (128 characters in hex) + * mnemonic: Bip39 24 words mnemonic + */ +function new_wallet_bip39(seed = undefined, derivationIndex = 0) { + return generate_keys_bip39(seed, derivationIndex); +} + +/** + * @param String sk + * @param Uint8Array msg + * sk: A 64 character long hex representation of a signing key (private key) + * msg: A Uint8Array of bytes representing the message you would like to sign + * + * @return String sig + * sig: A 128 character long hex string representing the message's signature + */ +function sign$1(sk, msg) { + var kp = format_to_keys(sk); + // This is required due to the secretKey required to sign a transaction + // in the js implementation of NaCL being the combination of the sk and + // vk for some stupid reason. That being said, we still want the sk and + // vk objects to exist in 32-byte string format (same as cilantro's + // python implementation) when presented to the user. + var jsnacl_sk = concatUint8Arrays(kp.sk, kp.vk); + return buf2hex(nacl__default["default"].sign.detached(msg, jsnacl_sk)); +} +/** + * @param String vk + * @param Uint8Array msg + * @param String sig + * vk: A 64 character long hex representation of a verify key (public key) + * msg: A Uint8Array (bytes) representation of a message that has been signed + * sig: A 128 character long hex representation of a nacl signature + * + * @return Bool result + * result: true if verify checked out, false if not + */ +function verify(vk, msg, sig) { + var vkb = hex2buf(vk); + var sigb = hex2buf(sig); + try { + return nacl__default["default"].sign.detached.verify(msg, sigb, vkb); + } catch (_a) { + return false; + } +} +/** + * @param string mnemonic + * @param string[] wordList + * mnemonic: Bip39 24 words mnemonic + * wordList: An array of string(Optional) + * + * @return Boolen res + * res: A boolen value + */ +function validateMnemonic(mnemonic, wordList) { + return bip39__namespace.validateMnemonic(mnemonic, wordList); } var wallet = /*#__PURE__*/Object.freeze({ @@ -3024,37 +3024,37 @@ var wallet = /*#__PURE__*/Object.freeze({ validateMnemonic: validateMnemonic }); -class EventEmitter { - constructor() { - this._events = {}; - } - - on(name, listener) { - if (!this._events[name]) { - this._events[name] = []; - } - - this._events[name].push(listener); - } - - removeListener(name, listenerToRemove) { - if (!this._events[name]) { - throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`); - } - - const filterListeners = (listener) => listener !== listenerToRemove; - this._events[name] = this._events[name].filter(filterListeners); - } - - emit(name, data) { - if (!this._events[name]) return - - const fireCallbacks = (callback) => { - callback(data); - }; - - this._events[name].forEach(fireCallbacks); - } +class EventEmitter { + constructor() { + this._events = {}; + } + + on(name, listener) { + if (!this._events[name]) { + this._events[name] = []; + } + + this._events[name].push(listener); + } + + removeListener(name, listenerToRemove) { + if (!this._events[name]) { + throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`); + } + + const filterListeners = (listener) => listener !== listenerToRemove; + this._events[name] = this._events[name].filter(filterListeners); + } + + emit(name, data) { + if (!this._events[name]) return + + const fireCallbacks = (callback) => { + callback(data); + }; + + this._events[name].forEach(fireCallbacks); + } } var publicApi = {}; @@ -87389,1407 +87389,1510 @@ function toFixedPoint(str, e, z) { var BigNumber = clone(); -BigNumber.config({ RANGE: [-30, 30], EXPONENTIAL_AT: 1e9 }); -BigNumber.set({ DECIMAL_PLACES: 30, ROUNDING_MODE: BigNumber.ROUND_DOWN }); // equivalent - -function Encoder(type, value) { - const throwError = (val) => { - throw new Error(`Error encoding ${val} to ${type}`); - }; - const countDecimals = (n) => { - if (Math.floor(n) === n) return 0; - try { - return n.toString().split(".")[1].length; - } catch (e) { - return 0; - } - }; - const isString = (val) => typeof val === "string" || val instanceof String; - const isArray = (val) => val && typeof val === "object" && val.constructor === Array; - const isObject = (val) => val && typeof val === "object" && val.constructor === Object; - const isDate = (val) => val instanceof Date; - const isBoolean = (val) => typeof val === "boolean"; - - const isNumber = (val) => { - if (isArray(val)) return false; - return !isNaN(encodeBigNumber(val).toNumber()); - }; - - const isInteger = (val) => { - if (!isNumber(val)) return false; - if (countDecimals(val) === 0) return true; - return false; - }; - const encodeInt = (val) => { - if (!isNumber(val)) throwError(val); - else return parseInt(val); - }; - const isFloat = (val) => { - if (!isNumber(val)) return false; - if (countDecimals(val) === 0) return false; - return true; - }; - const encodeFloat = (val) => { - if (!isNumber(val)) throwError(val); - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - - return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; - }; - const encodeNumber = (val) => { - if (!isNumber(val)) throwError(val); - if (isFloat(val)) { - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; - } - if (isInteger(val)) return parseInt(val); - }; - const encodeBigNumber = (val) => { - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - return val; - }; - - const encodeBool = (val) => { - if (isBoolean(val)) return val; - if (val === "true" || val === 1) return true; - if (val === "false" || val === 0) return false; - throwError(val); - }; - const encodeStr = (val) => { - if (isString(val)) return val; - if (isDate(val)) return val.toISOString(); - return JSON.stringify(val); - }; - const encodeDateTime = (val) => { - val = !isDate(val) ? new Date(val) : val; - if (!isDate(val)) throwError(val); - return { - __time__: [ - val.getUTCFullYear(), - val.getUTCMonth(), - val.getUTCDate(), - val.getUTCHours(), - val.getUTCMinutes(), - val.getUTCSeconds(), - val.getUTCMilliseconds(), - ], - }; - }; - const encodeTimeDelta = (val) => { - const time = isDate(val) ? val.getTime() : new Date(val).getTime(); - const days = parseInt(time / 1000 / 60 / 60 / 24); - const seconds = (time - days * 24 * 60 * 60 * 1000) / 1000; - return { __delta__: [days, seconds] }; - }; - - const encodeList = (val) => { - if (isArray(val)) return parseObject(val); - try { - val = JSON.parse(val); - } catch (e) { - throwError(val); - } - if (isArray(val)) return parseObject(val); - throwError(val); - }; - - const encodeDict = (val) => { - if (isObject(val)) return parseObject(val); - try { - val = JSON.parse(val); - } catch (e) { - throwError(val); - } - if (isObject(val)) return parseObject(val); - throwError(val); - }; - - const encodeObject = (val) => { - try { - return encodeList(val); - } catch (e) { - return encodeDict(val); - } - }; - - function parseObject(obj) { - const encode = (k, v) => { - if (k === "datetime" || k === "datetime.datetime") return Encoder("datetime.datetime", v); - if (k === "timedelta" || k === "datetime.timedelta") return Encoder("datetime.timedelta", v); - if (k !== "__fixed__" && isFloat(v)) return encodeFloat(v); - return v; - }; - - const fixDatetime = (k, v) => { - const isDatetimeObject = (val) => { - let datetimeTypes = ["datetime.datetime", "datetime", "datetime.timedelta", "timedelta"]; - return ( - Object.keys(val).length === 1 && - datetimeTypes.filter((f) => f === Object.keys(val)[0]).length > 0 - ); - }; - - if (v.constructor === Array) { - v.map((val) => { - if (Object.keys(val).length === 1 && isDatetimeObject(v)) return val[Object.keys(val)[0]]; - //if (isFloat(val)) return encodeFloat(val) - return val; - }); - } - if (v.constructor === Object) { - if (Object.keys(v).length === 1 && isDatetimeObject(v)) return v[Object.keys(v)[0]]; - } - - //if (isFloat(v)) return encodeFloat(v) - - return v; - }; - - let encodeValues = JSON.stringify(obj, encode); - return JSON.parse(encodeValues, fixDatetime); - } - - const encoder = { - str: encodeStr, - string: encodeStr, - float: encodeFloat, - int: encodeInt, - bool: encodeBool, - boolean: encodeBool, - dict: encodeDict, - list: encodeList, - Any: () => value, - "datetime.timedelta": encodeTimeDelta, - "datetime.datetime": encodeDateTime, - timedelta: encodeTimeDelta, - datetime: encodeDateTime, - number: encodeNumber, - object: encodeObject, - bigNumber: encodeBigNumber, - }; - - if (Object.keys(encoder).includes(type)) return encoder[type](value); - else throw new Error(`Error: ${type} is not a valid encoder type.`); -} - +BigNumber.config({ RANGE: [-30, 30], EXPONENTIAL_AT: 1e9 }); +BigNumber.set({ DECIMAL_PLACES: 30, ROUNDING_MODE: BigNumber.ROUND_DOWN }); // equivalent + +function Encoder(type, value) { + const throwError = (val) => { + throw new Error(`Error encoding ${val} to ${type}`); + }; + const countDecimals = (n) => { + if (Math.floor(n) === n) return 0; + try { + return n.toString().split(".")[1].length; + } catch (e) { + return 0; + } + }; + const isString = (val) => typeof val === "string" || val instanceof String; + const isArray = (val) => val && typeof val === "object" && val.constructor === Array; + const isObject = (val) => val && typeof val === "object" && val.constructor === Object; + const isDate = (val) => val instanceof Date; + const isBoolean = (val) => typeof val === "boolean"; + + const isNumber = (val) => { + if (isArray(val)) return false; + return !isNaN(encodeBigNumber(val).toNumber()); + }; + + const isInteger = (val) => { + if (!isNumber(val)) return false; + if (countDecimals(val) === 0) return true; + return false; + }; + const encodeInt = (val) => { + if (!isNumber(val)) throwError(val); + else return parseInt(val); + }; + const isFloat = (val) => { + if (!isNumber(val)) return false; + if (countDecimals(val) === 0) return false; + return true; + }; + const encodeFloat = (val) => { + if (!isNumber(val)) throwError(val); + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + + return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; + }; + const encodeNumber = (val) => { + if (!isNumber(val)) throwError(val); + if (isFloat(val)) { + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; + } + if (isInteger(val)) return parseInt(val); + }; + const encodeBigNumber = (val) => { + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + return val; + }; + + const encodeBool = (val) => { + if (isBoolean(val)) return val; + if (val === "true" || val === 1) return true; + if (val === "false" || val === 0) return false; + throwError(val); + }; + const encodeStr = (val) => { + if (isString(val)) return val; + if (isDate(val)) return val.toISOString(); + return JSON.stringify(val); + }; + const encodeDateTime = (val) => { + val = !isDate(val) ? new Date(val) : val; + if (!isDate(val)) throwError(val); + return { + __time__: [ + val.getUTCFullYear(), + val.getUTCMonth(), + val.getUTCDate(), + val.getUTCHours(), + val.getUTCMinutes(), + val.getUTCSeconds(), + val.getUTCMilliseconds(), + ], + }; + }; + const encodeTimeDelta = (val) => { + const time = isDate(val) ? val.getTime() : new Date(val).getTime(); + const days = parseInt(time / 1000 / 60 / 60 / 24); + const seconds = (time - days * 24 * 60 * 60 * 1000) / 1000; + return { __delta__: [days, seconds] }; + }; + + const encodeList = (val) => { + if (isArray(val)) return parseObject(val); + try { + val = JSON.parse(val); + } catch (e) { + throwError(val); + } + if (isArray(val)) return parseObject(val); + throwError(val); + }; + + const encodeDict = (val) => { + if (isObject(val)) return parseObject(val); + try { + val = JSON.parse(val); + } catch (e) { + throwError(val); + } + if (isObject(val)) return parseObject(val); + throwError(val); + }; + + const encodeObject = (val) => { + try { + return encodeList(val); + } catch (e) { + return encodeDict(val); + } + }; + + function parseObject(obj) { + const encode = (k, v) => { + if (k === "datetime" || k === "datetime.datetime") return Encoder("datetime.datetime", v); + if (k === "timedelta" || k === "datetime.timedelta") return Encoder("datetime.timedelta", v); + if (k !== "__fixed__" && isFloat(v)) return encodeFloat(v); + return v; + }; + + const fixDatetime = (k, v) => { + const isDatetimeObject = (val) => { + let datetimeTypes = ["datetime.datetime", "datetime", "datetime.timedelta", "timedelta"]; + return ( + Object.keys(val).length === 1 && + datetimeTypes.filter((f) => f === Object.keys(val)[0]).length > 0 + ); + }; + + if (v.constructor === Array) { + v.map((val) => { + if (Object.keys(val).length === 1 && isDatetimeObject(v)) return val[Object.keys(val)[0]]; + //if (isFloat(val)) return encodeFloat(val) + return val; + }); + } + if (v.constructor === Object) { + if (Object.keys(v).length === 1 && isDatetimeObject(v)) return v[Object.keys(v)[0]]; + } + + //if (isFloat(v)) return encodeFloat(v) + + return v; + }; + + let encodeValues = JSON.stringify(obj, encode); + return JSON.parse(encodeValues, fixDatetime); + } + + const encoder = { + str: encodeStr, + string: encodeStr, + float: encodeFloat, + int: encodeInt, + bool: encodeBool, + boolean: encodeBool, + dict: encodeDict, + list: encodeList, + Any: () => value, + "datetime.timedelta": encodeTimeDelta, + "datetime.datetime": encodeDateTime, + timedelta: encodeTimeDelta, + datetime: encodeDateTime, + number: encodeNumber, + object: encodeObject, + bigNumber: encodeBigNumber, + }; + + if (Object.keys(encoder).includes(type)) return encoder[type](value); + else throw new Error(`Error: ${type} is not a valid encoder type.`); +} + Encoder.BigNumber = BigNumber; -const { validateTypes: validateTypes$4 } = validators; - -class LamdenMasterNode_API { - constructor(networkInfoObj) { - if (!validateTypes$4.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Object and got Type: ${typeof networkInfoObj}`); - if (!validateTypes$4.isArrayWithValues(networkInfoObj.hosts)) - throw new Error(`HOSTS Required (Type: Array)`); - - this.hosts = this.validateHosts(networkInfoObj.hosts); - } - //This will throw an error if the protocol wasn't included in the host string - vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Host String must include http:// or https://"); - } - validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); - } - - get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; - } - get url() { - return this.host; - } - - send(method, path, data, overrideURL, callback) { - let parms = ""; - if (Object.keys(data).includes("parms")) { - parms = this.createParms(data.parms); - } - - let options = {}; - if (method === "POST") { - let headers = { "Content-Type": "application/json" }; - options.method = method; - options.headers = headers; - options.body = data; - } - - return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) - .then(async (res) => { - if (res.status === 200) { - let json = await res.json(); - callback(json, undefined); - return json; - } else { - let error = validateTypes$4.isStringWithValue(res.statusText) ? res.statusText : false; - callback(undefined, error); - return error; - } - }) - .catch((err) => { - return callback(undefined, err.toString()); - }); - } - - createParms(parms) { - if (Object.keys(parms).length === 0) return ""; - let parmString = "?"; - Object.keys(parms).forEach((key) => { - parmString = `${parmString}${key}=${parms[key]}&`; - }); - return parmString.slice(0, -1); - } - - async getContractInfo(contractName) { - const returnInfo = (res) => { - try { - if (res.name) return res; - } catch (e) {} - return null; - }; - let path = `/contracts/${contractName}`; - return this.send("GET", path, {}, undefined, (res, err) => returnInfo(res)).then((res) => - returnInfo(res) - ); - } - - async getVariable(contract, variable, key = "") { - let parms = {}; - if (validateTypes$4.isStringWithValue(key)) parms.key = key; - - let path = `/contracts/${contract}/${variable}/`; - - const returnValue = (res) => { - try { - if (res.value) return res.value; - } catch (e) {} - return null; - }; - return this.send("GET", path, { parms }, undefined, (res, err) => returnValue(res)).then( - (res) => returnValue(res) - ); - } - - async getContractMethods(contract) { - const getMethods = (res) => { - try { - if (res.methods) return res.methods; - } catch (e) {} - return []; - }; - let path = `/contracts/${contract}/methods`; - return this.send("GET", path, {}, undefined, (res, err) => getMethods(res)).then((res) => - getMethods(res) - ); - } - - async getContractVariables(contract) { - const getVariables = (res) => { - try { - if (res.variables) return res; - } catch (e) {} - return {}; - }; - let path = `/contracts/${contract}/variables`; - return this.send("GET", path, {}, undefined, (res, err) => getVariables(res)).then((res) => - getVariables(res) - ); - } - - async pingServer() { - const getStatus = (res) => { - try { - if (res.status) return true; - } catch (e) {} - return false; - }; - let response = await this.send("GET", "/ping", {}, undefined, (res, err) => getStatus(res)); - return getStatus(response); - } - - async getCurrencyBalance(vk) { - let balanceRes = await this.getVariable("currency", "balances", vk); - if (!balanceRes) return Encoder("bigNumber", 0); - if (balanceRes.__fixed__) return Encoder("bigNumber", balanceRes.__fixed__); - return Encoder("bigNumber", balanceRes.toString()); - } - - async contractExists(contractName) { - const exists = (res) => { - try { - if (res.name) return true; - } catch (e) {} - return false; - }; - let path = `/contracts/${contractName}`; - return this.send("GET", path, {}, undefined, (res, err) => exists(res)).then((res) => - exists(res) - ); - } - - async sendTransaction(data, url = undefined, callback) { - return this.send("POST", "/", JSON.stringify(data), url, (res, err) => { - if (err) { - if (callback) { - callback(undefined, err); - return; - } else return err; - } - if (callback) { - callback(res, undefined); - return; - } - return res; - }); - } - - async getNonce(sender, callback) { - if (!validateTypes$4.isStringHex(sender)) return `${sender} is not a hex string.`; - let path = `/nonce/${sender}`; - let url = this.host; - return this.send("GET", path, {}, url, (res, err) => { - if (err) { - if (callback) { - callback(undefined, `Unable to get nonce for ${sender} on network ${url}`); - return; - } - return `Unable to get nonce for ${sender} on network ${url}`; - } - res.masternode = url; - if (callback) { - callback(res, undefined); - return; - } else return res; - }); - } - - checkTransaction(hash, callback) { - const parms = { hash }; - return this.send("GET", "/tx", { parms }, undefined, (res, err) => { - if (err) { - if (callback) { - callback(undefined, err); - return; - } else return err; - } - if (callback) { - callback(res, undefined); - return; - } - return res; - }); - } -} - -const { validateTypes: validateTypes$3 } = validators; - -class LamdenBlockservice_API { -constructor(networkInfoObj) { - if (!validateTypes$3.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Network to be Object and got Type: ${typeof networkInfoObj}`); - if (validateTypes$3.isArrayWithValues(networkInfoObj.blockservice_hosts)){ - this.hosts = this.validateHosts(networkInfoObj.blockservice_hosts); - }else { - this.hosts = []; - } -} -//This will throw an error if the protocol wasn't included in the host string -vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Blockservice host value must include http:// or https://"); -} -validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); -} - -get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; -} -get url() { - return this.host; -} - -send(method, path, data = {}, overrideURL) { - let parms = ""; - if (Object.keys(data).includes("parms")) { - parms = this.createParms(data.parms); - } - - let options = {}; - if (method === "POST") { - let headers = { "Content-Type": "application/json" }; - options.method = method; - options.headers = headers; - options.body = data; - } - - return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) -} - -createParms(parms) { - if (Object.keys(parms).length === 0) return ""; - let parmString = "?"; - Object.keys(parms).forEach((key) => { - parmString = `${parmString}${key}=${parms[key]}&`; - }); - return parmString.slice(0, -1); -} - -async pingServer() { - return this.send("GET", "/ping", {}) - .then(res => res.text()) - .then(text => text === "pong") - .catch(() => false) -} - -async getLastetBlock(callback){ - return this.send("GET", "/latest_block") - .then(res => res.json()) - .then(json => { - if (callback) callback(json.latest_block, null); - return json.latest_block - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getBlocks(start_block, limit = 10, callback){ - const parms = { start_block, limit }; - return this.send("GET", "/blocks", { parms }) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getCurrentKeyValue(contractName, variableName, key, callback){ - return this.send("GET", `/current/one/${contractName}/${variableName}/${key}`) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getCurrentKeysValues(keys, callback){ - try{ - let endpont = 'current/keys'; - let data = await this.send('POST', `/${endpont}`, JSON.stringify(keys)) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }); - return data - }catch(err){ - if (callback) callback(null, err.message); - return {error: err.message} - } +const { validateTypes: validateTypes$4 } = validators; + +class LamdenMasterNode_API { + constructor(networkInfoObj) { + if (!validateTypes$4.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Object and got Type: ${typeof networkInfoObj}`); + if (!validateTypes$4.isArrayWithValues(networkInfoObj.hosts)) + throw new Error(`HOSTS Required (Type: Array)`); + + this.hosts = this.validateHosts(networkInfoObj.hosts); + } + //This will throw an error if the protocol wasn't included in the host string + vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Host String must include http:// or https://"); + } + validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); + } + + get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; + } + get url() { + return this.host; + } + + send(method, path, data, overrideURL, callback) { + let parms = ""; + if (Object.keys(data).includes("parms")) { + parms = this.createParms(data.parms); + } + + let options = {}; + if (method === "POST") { + let headers = { "Content-Type": "application/json" }; + options.method = method; + options.headers = headers; + options.body = data; + } + + return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) + .then(async (res) => { + if (res.status === 200) { + let json = await res.json(); + callback(json, undefined); + return json; + } else { + let error = validateTypes$4.isStringWithValue(res.statusText) ? res.statusText : false; + callback(undefined, error); + return error; + } + }) + .catch((err) => { + return callback(undefined, err.toString()); + }); + } + + createParms(parms) { + if (Object.keys(parms).length === 0) return ""; + let parmString = "?"; + Object.keys(parms).forEach((key) => { + parmString = `${parmString}${key}=${parms[key]}&`; + }); + return parmString.slice(0, -1); + } + + async getContractInfo(contractName) { + const returnInfo = (res) => { + try { + if (res.name) return res; + } catch (e) {} + return {"error":`${contractName} does not exist`}; + }; + let path = `/contracts/${contractName}`; + return this.send("GET", path, {}, undefined, (res, err) => returnInfo(res)).then((res) => + returnInfo(res) + ); + } + + async getVariable(contract, variable, key = "") { + let parms = {}; + if (validateTypes$4.isStringWithValue(key)) parms.key = key; + + let path = `/contracts/${contract}/${variable}/`; + + const returnValue = (res) => { + try { + if (res.value) return res.value; + } catch (e) {} + return null; + }; + return this.send("GET", path, { parms }, undefined, (res, err) => returnValue(res)).then( + (res) => returnValue(res) + ); + } + + async getContractMethods(contract) { + const getMethods = (res) => { + try { + if (res.methods) return res.methods; + } catch (e) {} + return []; + }; + let path = `/contracts/${contract}/methods`; + return this.send("GET", path, {}, undefined, (res, err) => getMethods(res)).then((res) => + getMethods(res) + ); + } + + async getContractVariables(contract) { + const getVariables = (res) => { + try { + if (res.variables) return res; + } catch (e) {} + return {}; + }; + let path = `/contracts/${contract}/variables`; + return this.send("GET", path, {}, undefined, (res, err) => getVariables(res)).then((res) => + getVariables(res) + ); + } + + async pingServer() { + const getStatus = (res) => { + try { + if (res.status) return true; + } catch (e) {} + return false; + }; + let response = await this.send("GET", "/ping", {}, undefined, (res, err) => getStatus(res)); + return getStatus(response); + } + + async getCurrencyBalance(vk) { + let balanceRes = await this.getVariable("currency", "balances", vk); + if (!balanceRes) return Encoder("bigNumber", 0); + if (balanceRes.__fixed__) return Encoder("bigNumber", balanceRes.__fixed__); + return Encoder("bigNumber", balanceRes.toString()); + } + + async contractExists(contractName) { + const exists = (res) => { + try { + if (res.name) return true; + } catch (e) {} + return false; + }; + let path = `/contracts/${contractName}`; + return this.send("GET", path, {}, undefined, (res, err) => exists(res)).then((res) => + exists(res) + ); + } + + async sendTransaction(data, url = undefined, callback) { + return this.send("POST", "/", JSON.stringify(data), url, (res, err) => { + if (err) { + if (callback) { + callback(undefined, err); + return; + } else return err; + } + if (callback) { + callback(res, undefined); + return; + } + return res; + }); + } + + async getNonce(sender, callback) { + if (!validateTypes$4.isStringHex(sender)) return `${sender} is not a hex string.`; + let path = `/nonce/${sender}`; + let url = this.host; + return this.send("GET", path, {}, url, (res, err) => { + if (err) { + if (callback) { + callback(undefined, `Unable to get nonce for ${sender} on network ${url}`); + return; + } + return `Unable to get nonce for ${sender} on network ${url}`; + } + res.masternode = url; + if (callback) { + callback(res, undefined); + return; + } else return res; + }); + } + + checkTransaction(hash, callback) { + const parms = { hash }; + return this.send("GET", "/tx", { parms }, undefined, (res, err) => { + if (err) { + if (callback) { + callback(undefined, err); + return; + } else return err; + } + if (callback) { + callback(res, undefined); + return; + } + return res; + }); + } + + async getLastetBlock(){ + return this.send("GET", "/latest_block", {}) + .then(res => res.json()) + .then(json => { + return { value: json.number } + }) + .catch(err => { + return {error: err.message} + }) + } } -async getTransaction(hash, callback) { - const parms = { hash }; - return this.send("GET", "/tx", { parms }) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (err.message.includes("invalid json response body")) { - if (callback) callback(null, null); - return null - }else { - if (callback) callback(null, err.message); - return {error: err.message} - } - }) - } +const { validateTypes: validateTypes$3 } = validators; + +class LamdenBlockservice_API { +constructor(networkInfoObj) { + if (!validateTypes$3.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Network to be Object and got Type: ${typeof networkInfoObj}`); + if (validateTypes$3.isArrayWithValues(networkInfoObj.blockservice_hosts)){ + this.hosts = this.validateHosts(networkInfoObj.blockservice_hosts); + }else { + this.hosts = []; + } +} +//This will throw an error if the protocol wasn't included in the host string +vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Blockservice host value must include http:// or https://"); +} +validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); +} + +get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; +} +get url() { + return this.host; +} + +send(method, path, data = {}, overrideURL) { + let parms = ""; + if (Object.keys(data).includes("parms")) { + parms = this.createParms(data.parms); + } + + let options = {}; + if (method === "POST") { + let headers = { "Content-Type": "application/json" }; + options.method = method; + options.headers = headers; + options.body = data; + } + return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) +} + +createParms(parms) { + if (Object.keys(parms).length === 0) return ""; + let parmString = "?"; + Object.keys(parms).forEach((key) => { + parmString = `${parmString}${key}=${parms[key]}&`; + }); + return parmString.slice(0, -1); +} + +async pingServer() { + return this.send("GET", "/ping", {}) + .then(res => res.text()) + .then(text => text === "pong") + .catch(() => false) +} + +async getLastetBlock(callback){ + return this.send("GET", "/latest_block", {}) + .then(res => res.json()) + .then(json => { + if (callback) callback(json.latest_block, null); + return json.latest_block + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) +} + +async getBlocks(start_block, limit = 10, callback){ + const parms = { start_block, limit }; + return this.send("GET", "/blocks", { parms }) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) +} + +async getCurrentKeyValue(contractName, variableName, key, callback){ + return this.send("GET", `/current/one/${contractName}/${variableName}/${key}`) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) +} + +async getCurrentKeysValues(keys, callback){ + try{ + let endpont = 'current/keys'; + let data = await this.send('POST', `/${endpont}`, JSON.stringify(keys)) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }); + return data + }catch(err){ + if (callback) callback(null, err.message); + return {error: err.message} + } +} + +async getTransaction(hash, callback) { + const parms = { hash }; + return this.send("GET", "/tx", { parms }) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (err.message.includes("invalid json response body")) { + if (callback) callback(null, null); + return null + }else { + if (callback) callback(null, err.message); + return {error: err.message} + } + }) + } + +async getContractInfo(contractName) { + return this.send("GET", `/contracts/${contractName}`, {}) + .then(res => res.json()) + .then(json => { + if (Object.keys(json).length > 0) { + let data = json[contractName]; + return { + name: contractName, + code: data['__code__'] + } + } else { + return {"error":`${contractName} does not exist`} + } + }) + .catch(err => { + return {error: err.message} + }) +} } -const { validateTypes: validateTypes$2 } = validators; - -const NETWORK_VERSIONS = [1, 2]; - -class Network { - // Constructor needs an Object with the following information to build Class. - // - // networkInfo: { - // hosts: list of masternode hostname/ip urls, - // type: "testnet", "mainnet" or "custom", - // version : 1 (default) or 2 - // }, - constructor(networkInfoObj) { - //Reject undefined or missing info - if (!validateTypes$2.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Network Info Object and got Type: ${typeof networkInfoObj}`); - if (!validateTypes$2.isArrayWithValues(networkInfoObj.hosts)) - throw new Error(`HOSTS Required (Type: Array)`); - this.classname = 'Network'; - this.type = validateTypes$2.isStringWithValue(networkInfoObj.type) - ? networkInfoObj.type.toLowerCase() - : "custom"; - this.version = this.getNetworkVersion(networkInfoObj.version); - this.events = new EventEmitter(); - this.hosts = this.validateHosts(networkInfoObj.hosts); - this.currencySymbol = validateTypes$2.isStringWithValue(networkInfoObj.currencySymbol) - ? networkInfoObj.currencySymbol - : "TAU"; - this.name = validateTypes$2.isStringWithValue(networkInfoObj.name) - ? networkInfoObj.name - : "lamden network"; - this.lamden = validateTypes$2.isBoolean(networkInfoObj.lamden) ? networkInfoObj.lamden : false; - this.blockExplorer = validateTypes$2.isStringWithValue(networkInfoObj.blockExplorer) - ? networkInfoObj.blockExplorer - : undefined; - - this.online = false; - try { - this.API = new LamdenMasterNode_API(networkInfoObj); - } catch (e) { - throw new Error(e); - } - try { - this.blockservice = new LamdenBlockservice_API(networkInfoObj); - } catch (e) { - throw new Error(e); - } - } - //This will throw an error if the protocol wasn't included in the host string - vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Host String must include http:// or https://"); - } - validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); - } - getNetworkVersion(version){ - if (!validateTypes$2.isInteger(version)) return 1 - if (NETWORK_VERSIONS.includes(version)) return version - else return 1 - } - //Check if the network is online - //Emits boolean as 'online' event - //Also returns status as well as passes status to a callback - async ping(callback = undefined) { - this.online = await this.API.pingServer(); - this.events.emit("online", this.online); - if (validateTypes$2.isFunction(callback)) callback(this.online); - return this.online; - } - get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; - } - get url() { - return this.host; - } - getNetworkInfo() { - return { - name: this.name, - lamden: this.lamden, - type: this.type, - hosts: this.hosts, - blockservice_hosts: this.blockservice.hosts, - url: this.url, - online: this.online, - version: this.version - }; - } +const { validateTypes: validateTypes$2 } = validators; + +const NETWORK_VERSIONS = [1, 2]; + +class Network { + // Constructor needs an Object with the following information to build Class. + // + // networkInfo: { + // hosts: list of masternode hostname/ip urls, + // type: "testnet", "mainnet" or "custom", + // version : 1 (default) or 2 + // }, + constructor(networkInfoObj) { + //Reject undefined or missing info + if (!validateTypes$2.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Network Info Object and got Type: ${typeof networkInfoObj}`); + if (!validateTypes$2.isArrayWithValues(networkInfoObj.hosts)) + throw new Error(`HOSTS Required (Type: Array)`); + this.classname = 'Network'; + this.type = validateTypes$2.isStringWithValue(networkInfoObj.type) + ? networkInfoObj.type.toLowerCase() + : "custom"; + this.version = this.getNetworkVersion(networkInfoObj.version); + this.events = new EventEmitter(); + this.hosts = this.validateHosts(networkInfoObj.hosts); + this.currencySymbol = validateTypes$2.isStringWithValue(networkInfoObj.currencySymbol) + ? networkInfoObj.currencySymbol + : "TAU"; + this.name = validateTypes$2.isStringWithValue(networkInfoObj.name) + ? networkInfoObj.name + : "lamden network"; + this.lamden = validateTypes$2.isBoolean(networkInfoObj.lamden) ? networkInfoObj.lamden : false; + this.blockExplorer = validateTypes$2.isStringWithValue(networkInfoObj.blockExplorer) + ? networkInfoObj.blockExplorer + : undefined; + + this.online = false; + try { + this.API = new LamdenMasterNode_API(networkInfoObj); + } catch (e) { + throw new Error(e); + } + try { + this.blockservice = new LamdenBlockservice_API(networkInfoObj); + } catch (e) { + throw new Error(e); + } + } + //This will throw an error if the protocol wasn't included in the host string + vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Host String must include http:// or https://"); + } + validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); + } + getNetworkVersion(version){ + if (!validateTypes$2.isInteger(version)) return 1 + if (NETWORK_VERSIONS.includes(version)) return version + else return 1 + } + //Check if the network is online + //Emits boolean as 'online' event + //Also returns status as well as passes status to a callback + async ping(callback = undefined) { + this.online = await this.API.pingServer(); + this.events.emit("online", this.online); + if (validateTypes$2.isFunction(callback)) callback(this.online); + return this.online; + } + get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; + } + get url() { + return this.host; + } + getNetworkInfo() { + return { + name: this.name, + lamden: this.lamden, + type: this.type, + hosts: this.hosts, + blockservice_hosts: this.blockservice.hosts, + url: this.url, + online: this.online, + version: this.version + }; + } + + // Unify APIs + async pingServer() { + let res; + if (this.blockservice.host) { + res = await this.blockservice.pingServer(); + } else { + res = await this.API.pingServer(); + } + return res + } + + async getVariable(contractName, variableName, key) { + if (this.blockservice.host) { + let data = await this.blockservice.getCurrentKeyValue(contractName, variableName, key); + return data + } else { + let res = await this.API.getVariable(contractName, variableName, key); + if (res) { + return { + value: res + } + } else { + return {error: "key or variable not exists"} + } + } + } + + async getCurrencyBalance(vk) { + return await this.getVariable("currency", "balances", vk) + } + + async getContractInfo(contractName) { + if (this.blockservice.host) { + return await this.blockservice.getContractInfo(contractName); + } else { + return await this.API.getContractInfo(contractName); + } + } + + async contractExists(contractName) { + let data; + if (this.blockservice.host) { + data = await this.blockservice.getContractInfo(contractName); + } else { + data = await this.API.getContractInfo(contractName); + } + return data && data.name ? true : false + } + + async getLastetBlock() { + if (this.blockservice.host) { + let data = await this.blockservice.getLastetBlock(); + if (data.error) { + return data + } else { + return { + value: data + } + } + } else { + return await this.API.getLastetBlock(); + } + } + } -const { validateTypes: validateTypes$1 } = validators; - -class TransactionBuilder extends Network { - // Constructor needs an Object with the following information to build Class. - // - // arg[0] (networkInfo): { //Can also accpet a Lamden "Network Class" - // host: masternode webserver hostname/ip, - // type: "testnet", "mainnet" or "mockchain" - // } - // arg[1] (txInfo): { - // uid: [Optional] unique ID for tracking purposes, - // senderVk: public key of the transaction sender, - // contractName: name of lamden smart contract, - // methodName: name of method to call in contractName, - // kwargs: key/values of args to pass to methodName - // example: kwargs.to = "270add00fc708791c97aeb5255107c770434bd2ab71c2e103fbee75e202aa15e" - // kwargs.amount = 1000 - // stampLimit: the max amount of stamps the tx should use. tx could use less. if tx needs more the tx will fail. - // nonce: [Optional] send() will attempt to retrieve this info automatically - // processor [Optional] send() will attempt to retrieve this info automatically - // } - // arg[2] (txData): [Optional] state hydrating data - constructor(networkInfo, txInfo, txData) { - if (networkInfo && networkInfo.classname === "Network") super(networkInfo.getNetworkInfo()); - else super(networkInfo); - - //Validate arguments - if (!validateTypes$1.isObjectWithKeys(txInfo)) throw new Error(`txInfo object not found`); - if (!validateTypes$1.isStringHex(txInfo.senderVk)) - throw new Error(`Sender Public Key Required (Type: Hex String)`); - if (!validateTypes$1.isStringWithValue(txInfo.contractName)) - throw new Error(`Contract Name Required (Type: String)`); - if (!validateTypes$1.isStringWithValue(txInfo.methodName)) - throw new Error(`Method Required (Type: String)`); - if (!validateTypes$1.isInteger(txInfo.stampLimit)) - throw new Error(`Stamps Limit Required (Type: Integer)`); - - //Store variables in self for reference - this.uid = validateTypes$1.isStringWithValue(txInfo.uid) ? txInfo.uid : undefined; - this.sender = txInfo.senderVk; - this.contract = txInfo.contractName; - this.method = txInfo.methodName; - this.kwargs = {}; - if (validateTypes$1.isObject(txInfo.kwargs)) this.kwargs = txInfo.kwargs; - this.stampLimit = txInfo.stampLimit; - - //validate and set nonce and processor if user provided them - if (typeof txInfo.nonce !== "undefined") { - if (!validateTypes$1.isInteger(txInfo.nonce)) - throw new Error( - `arg[6] Nonce is required to be an Integer, type ${typeof txInfo.none} was given` - ); - this.nonce = txInfo.nonce; - } - if (typeof txInfo.processor !== "undefined") { - if (!validateTypes$1.isStringWithValue(txInfo.processor)) - throw new Error( - `arg[7] Processor is required to be a String, type ${typeof txInfo.processor} was given` - ); - this.processor = txInfo.processor; - } - - this.signature; - this.transactionSigned = false; - - //Transaction result information - this.nonceResult = {}; - this.txSendResult = { errors: [] }; - this.txBlockResult = {}; - this.txHash; - this.txCheckResult = {}; - this.txCheckAttempts = 0; - this.txCheckLimit = 10; - this.maxBlockToCheck = 30; - this.startBlock = null; - - //Hydrate other items if passed - if (txData) { - if (txData.uid) this.uid = txData.uid; - if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) - this.txSendResult = txData.txSendResult; - if (validateTypes$1.isObjectWithKeys(txData.nonceResult)) { - this.nonceResult = txData.nonceResult; - if (validateTypes$1.isInteger(this.nonceResult.nonce)) this.nonce = this.nonceResult.nonce; - if (validateTypes$1.isStringWithValue(this.nonceResult.processor)) - this.processor = this.nonceResult.processor; - } - if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) { - this.txSendResult = txData.txSendResult; - if (this.txSendResult.hash) this.txHash = this.txSendResult.hash; - } - if (validateTypes$1.isObjectWithKeys(txData.txBlockResult)) - this.txBlockResult = txData.txBlockResult; - if (validateTypes$1.isObjectWithKeys(txData.resultInfo)) this.resultInfo = txData.resultInfo; - } - //Create Capnp messages and transactionMessages - this.makePayload(); - } - makePayload() { - this.payload = { - contract: this.contract, - function: this.method, - kwargs: this.kwargs, - nonce: this.nonce, - processor: this.processor, - sender: this.sender, - stamps_supplied: this.stampLimit, - }; - this.sortedPayload = this.sortObject(this.payload); - } - makeTransaction() { - if (this.version === 1){ - this.tx = { - metadata: { - signature: this.signature, - timestamp: parseInt(+new Date() / 1000), - }, - payload: this.sortedPayload.orderedObj, - }; - } - if (this.version === 2){ - this.tx = { - metadata: { - signature: this.signature - }, - payload: this.sortedPayload.orderedObj, - }; - } - } - verifySignature() { - //Verify the signature is correct - if (!this.transactionSigned) - throw new Error( - "Transaction has not be been signed. Use the sign() method first." - ); - const stringBuffer = Buffer.from(this.sortedPayload.json); - const stringArray = new Uint8Array(stringBuffer); - return verify(this.sender, stringArray, this.signature); - } - sign(sk = undefined, userWallet = undefined) { - const stringBuffer = Buffer.from(this.sortedPayload.json); - const stringArray = new Uint8Array(stringBuffer); - if (userWallet) this.signature = userWallet.sign(stringArray); - else this.signature = sign$1(sk, stringArray); - this.transactionSigned = true; - } - sortObject(object) { - const processObj = (obj) => { - const getType = (value) => { - return Object.prototype.toString.call(value); - }; - const isArray = (value) => { - if (getType(value) === "[object Array]") return true; - return false; - }; - const isObject = (value) => { - if (getType(value) === "[object Object]") return true; - return false; - }; - - const sortObjKeys = (unsorted) => { - const sorted = {}; - Object.keys(unsorted) - .sort() - .forEach((key) => (sorted[key] = unsorted[key])); - return sorted; - }; - - const formatKeys = (unformatted) => { - Object.keys(unformatted).forEach((key) => { - if (isArray(unformatted[key])) - unformatted[key] = unformatted[key].map((item) => { - if (isObject(item)) return formatKeys(item); - return item; - }); - if (isObject(unformatted[key])) unformatted[key] = formatKeys(unformatted[key]); - }); - return sortObjKeys(unformatted); - }; - - if (!isObject(obj)) throw new TypeError("Not a valid Object"); - try { - obj = JSON.parse(JSON.stringify(obj)); - } catch (e) { - throw new TypeError("Not a valid JSON Object"); - } - return formatKeys(obj); - }; - const orderedObj = processObj(object); - return { - orderedObj, - json: JSON.stringify(orderedObj), - }; - } - async getNonce(callback = undefined) { - let timestamp = new Date().toUTCString(); - this.nonceResult = await this.API.getNonce(this.sender); - if (typeof this.nonceResult.nonce === "undefined") { - throw new Error(this.nonceResult); - } - this.nonceResult.timestamp = timestamp; - this.nonce = this.nonceResult.nonce; - this.processor = this.nonceResult.processor; - this.nonceMasternode = this.nonceResult.masternode; - //Create payload object - this.makePayload(); - - if (!callback) return this.nonceResult; - return callback(this.nonceResult); - } - async send(sk = undefined, callback = undefined, masternode = undefined) { - //Error if transaction is not signed and no sk provided to the send method to sign it before sending - if (!validateTypes$1.isStringWithValue(sk) && !this.transactionSigned) { - throw new Error( - `Transation Not Signed: Private key needed or call sign() first` - ); - } - - if (this.blockservice.url){ - if (await this.blockservice.pingServer()) this.startBlock = await this.blockservice.getLastetBlock(); - } - - let timestamp = new Date().toUTCString(); - - try { - //If the nonce isn't set attempt to get it - if (isNaN(this.nonce) || !validateTypes$1.isStringWithValue(this.processor)) - await this.getNonce(); - //if the sk is provided then sign the transaction - if (validateTypes$1.isStringWithValue(sk)) this.sign(sk); - //Serialize transaction - this.makeTransaction(); - //Send transaction to the masternode - let masternodeURL = masternode; - if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode; - let response = await this.API.sendTransaction(this.tx, masternodeURL); - //Set error if txSendResult doesn't exist - if (!response || validateTypes$1.isStringWithValue(response)) { - this.txSendResult.errors = [response || "Unknown Transaction Error"]; - } else { - if (response.error) this.txSendResult.errors = [response.error]; - else this.txSendResult = response; - } - } catch (e) { - this.txSendResult.errors = [e.message]; - } - this.txSendResult.timestamp = timestamp; - return this.handleMasterNodeResponse(this.txSendResult, callback); - } - checkForTransactionResult(callback = undefined) { - return new Promise((resolve) => { - let timerId = setTimeout( - async function checkTx() { - this.txCheckAttempts = this.txCheckAttempts + 1; - let res = await this.API.checkTransaction(this.txHash); - let checkAgain = false; - let timestamp = new Date().toUTCString(); - if (typeof res === "string" || !res) { - if (this.txCheckAttempts < this.txCheckLimit) { - checkAgain = true; - } else { - this.txCheckResult.errors = [ - `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, - res, - ]; - this.txCheckResult.status = 2; - } - } else { - if (res.error) { - if (res.error === "Transaction not found.") { - if (this.txCheckAttempts < this.txCheckLimit) { - checkAgain = true; - } else { - this.txCheckResult.errors = [ - res.error, - `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, - ]; - this.txCheckResult.status = 2; - } - } else { - this.txCheckResult.errors = [res.error]; - } - } else { - this.txCheckResult = res; - } - } - if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000); - else { - if (validateTypes$1.isNumber(this.txCheckResult.status)) { - if (this.txCheckResult.status > 0) { - if (!validateTypes$1.isArray(this.txCheckResult.errors)) - this.txCheckResult.errors = []; - this.txCheckResult.errors.push("This transaction returned a non-zero status code"); - } - } - this.txCheckResult.timestamp = timestamp; - clearTimeout(timerId); - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - } - }.bind(this), - 1000 - ); - }); - } - async checkBlockserviceForTransactionResult(callback = undefined) { - if (!this.txHash) { - throw new Error("No transaction hash to check.") - } - - // Check if the blockservice is up - let serverAvailable = await this.blockservice.pingServer(); - - //If it's not then fail over to checking from the masternode - if (!serverAvailable) { - console.log("Blockservice not available, failing back to masternode."); - return this.checkForTransactionResult(callback).then( - (res) => { - return {txinfo: res, ...res} - } - ) - } - - return new Promise(async (resolve) => { - let lastLatestBlock = this.startBlock || 0; - - - // Get the next 10 blocks from the blockservice starting with the block the transction was sent from - const getLatestBlock = async () => { - let latestBlock = await this.blockservice.getLastetBlock(); - if (latestBlock > lastLatestBlock){ - lastLatestBlock = latestBlock; - checkForTrasaction(); - }else { - setTimeout(getLatestBlock, 5000); - } - }; - - // Check all the transaction in these blocks for our transction hash - const checkForTrasaction = async () => { - let txResults = await this.blockservice.getTransaction(this.txHash); - if (txResults){ - this.txCheckResult = {...txResults, ...txResults.txInfo}; - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - }else { - if (lastLatestBlock - this.startBlock > this.maxBlockToCheck){ - this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} blocks after sending.`]; - this.txCheckResult.status = 2; - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - }else { - setTimeout(getLatestBlock, 5000); - } - } - }; - - getLatestBlock(); - }); - } - handleMasterNodeResponse(result, callback = undefined) { - //Check to see if this is a successful transacation submission - if ( - validateTypes$1.isStringWithValue(result.hash) && - validateTypes$1.isStringWithValue(result.success) - ) { - this.txHash = result.hash; - this.setPendingBlockInfo(); - } else { - this.setBlockResultInfo(result); - this.txBlockResult = result; - } - this.events.emit("response", result, this.resultInfo.subtitle); - if (validateTypes$1.isFunction(callback)) callback(result); - return result; - } - setPendingBlockInfo() { - this.resultInfo = { - title: "Transaction Pending", - subtitle: "Your transaction was submitted and is being processed", - message: `Tx Hash: ${this.txHash}`, - type: "success", - }; - return this.resultInfo; - } - setBlockResultInfo(result) { - let erroredTx = false; - let errorText = `returned an error and `; - let statusCode = validateTypes$1.isNumber(result.status) ? result.status : undefined; - let stamps = result.stampsUsed || result.stamps_used || 0; - let message = ""; - if (validateTypes$1.isArrayWithValues(result.errors)) { - erroredTx = true; - message = `This transaction returned ${result.errors.length} errors.`; - if (result.result) { - if (result.result.includes("AssertionError")) result.errors.push(result.result); - } - } - if (statusCode && erroredTx) errorText = `returned status code ${statusCode} and `; - - this.resultInfo = { - title: `Transaction ${erroredTx ? "Failed" : "Successful"}`, - subtitle: `Your transaction ${erroredTx ? `${errorText} ` : ""}used ${stamps} stamps`, - message, - type: `${erroredTx ? "error" : "success"}`, - errorInfo: erroredTx ? result.errors : undefined, - returnResult: result.result || "", - stampsUsed: stamps, - statusCode, - }; - return this.resultInfo; - } - getResultInfo() { - return this.resultInfo; - } - getTxInfo() { - return { - senderVk: this.sender, - contractName: this.contract, - methodName: this.method, - kwargs: this.kwargs, - stampLimit: this.stampLimit, - }; - } - getAllInfo() { - return { - uid: this.uid, - txHash: this.txHash, - signed: this.transactionSigned, - tx: this.tx, - signature: this.signature, - networkInfo: this.getNetworkInfo(), - txInfo: this.getTxInfo(), - txSendResult: this.txSendResult, - txBlockResult: this.txBlockResult, - resultInfo: this.getResultInfo(), - nonceResult: this.nonceResult, - }; - } +const { validateTypes: validateTypes$1 } = validators; + +class TransactionBuilder extends Network { + // Constructor needs an Object with the following information to build Class. + // + // arg[0] (networkInfo): { //Can also accpet a Lamden "Network Class" + // host: masternode webserver hostname/ip, + // type: "testnet", "mainnet" or "mockchain" + // } + // arg[1] (txInfo): { + // uid: [Optional] unique ID for tracking purposes, + // senderVk: public key of the transaction sender, + // contractName: name of lamden smart contract, + // methodName: name of method to call in contractName, + // kwargs: key/values of args to pass to methodName + // example: kwargs.to = "270add00fc708791c97aeb5255107c770434bd2ab71c2e103fbee75e202aa15e" + // kwargs.amount = 1000 + // stampLimit: the max amount of stamps the tx should use. tx could use less. if tx needs more the tx will fail. + // nonce: [Optional] send() will attempt to retrieve this info automatically + // processor [Optional] send() will attempt to retrieve this info automatically + // } + // arg[2] (txData): [Optional] state hydrating data + constructor(networkInfo, txInfo, txData) { + if (networkInfo && networkInfo.classname === "Network") super(networkInfo.getNetworkInfo()); + else super(networkInfo); + + //Validate arguments + if (!validateTypes$1.isObjectWithKeys(txInfo)) throw new Error(`txInfo object not found`); + if (!validateTypes$1.isStringHex(txInfo.senderVk)) + throw new Error(`Sender Public Key Required (Type: Hex String)`); + if (!validateTypes$1.isStringWithValue(txInfo.contractName)) + throw new Error(`Contract Name Required (Type: String)`); + if (!validateTypes$1.isStringWithValue(txInfo.methodName)) + throw new Error(`Method Required (Type: String)`); + if (!validateTypes$1.isInteger(txInfo.stampLimit)) + throw new Error(`Stamps Limit Required (Type: Integer)`); + + //Store variables in self for reference + this.uid = validateTypes$1.isStringWithValue(txInfo.uid) ? txInfo.uid : undefined; + this.sender = txInfo.senderVk; + this.contract = txInfo.contractName; + this.method = txInfo.methodName; + this.kwargs = {}; + if (validateTypes$1.isObject(txInfo.kwargs)) this.kwargs = txInfo.kwargs; + this.stampLimit = txInfo.stampLimit; + + //validate and set nonce and processor if user provided them + if (typeof txInfo.nonce !== "undefined") { + if (!validateTypes$1.isInteger(txInfo.nonce)) + throw new Error( + `arg[6] Nonce is required to be an Integer, type ${typeof txInfo.none} was given` + ); + this.nonce = txInfo.nonce; + } + if (typeof txInfo.processor !== "undefined") { + if (!validateTypes$1.isStringWithValue(txInfo.processor)) + throw new Error( + `arg[7] Processor is required to be a String, type ${typeof txInfo.processor} was given` + ); + this.processor = txInfo.processor; + } + + this.signature; + this.transactionSigned = false; + + //Transaction result information + this.nonceResult = {}; + this.txSendResult = { errors: [] }; + this.txBlockResult = {}; + this.txHash; + this.txCheckResult = {}; + this.txCheckAttempts = 0; + this.txCheckLimit = 10; + this.maxBlockToCheck = 15; + this.startBlock = null; + + //Hydrate other items if passed + if (txData) { + if (txData.uid) this.uid = txData.uid; + if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) + this.txSendResult = txData.txSendResult; + if (validateTypes$1.isObjectWithKeys(txData.nonceResult)) { + this.nonceResult = txData.nonceResult; + if (validateTypes$1.isInteger(this.nonceResult.nonce)) this.nonce = this.nonceResult.nonce; + if (validateTypes$1.isStringWithValue(this.nonceResult.processor)) + this.processor = this.nonceResult.processor; + } + if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) { + this.txSendResult = txData.txSendResult; + if (this.txSendResult.hash) this.txHash = this.txSendResult.hash; + } + if (validateTypes$1.isObjectWithKeys(txData.txBlockResult)) + this.txBlockResult = txData.txBlockResult; + if (validateTypes$1.isObjectWithKeys(txData.resultInfo)) this.resultInfo = txData.resultInfo; + } + //Create Capnp messages and transactionMessages + this.makePayload(); + } + makePayload() { + this.payload = { + contract: this.contract, + function: this.method, + kwargs: this.kwargs, + nonce: this.nonce, + processor: this.processor, + sender: this.sender, + stamps_supplied: this.stampLimit, + }; + this.sortedPayload = this.sortObject(this.payload); + } + makeTransaction() { + if (this.version === 1){ + this.tx = { + metadata: { + signature: this.signature, + timestamp: parseInt(+new Date() / 1000), + }, + payload: this.sortedPayload.orderedObj, + }; + } + if (this.version === 2){ + this.tx = { + metadata: { + signature: this.signature + }, + payload: this.sortedPayload.orderedObj, + }; + } + } + verifySignature() { + //Verify the signature is correct + if (!this.transactionSigned) + throw new Error( + "Transaction has not be been signed. Use the sign() method first." + ); + const stringBuffer = Buffer.from(this.sortedPayload.json); + const stringArray = new Uint8Array(stringBuffer); + return verify(this.sender, stringArray, this.signature); + } + sign(sk = undefined, userWallet = undefined) { + const stringBuffer = Buffer.from(this.sortedPayload.json); + const stringArray = new Uint8Array(stringBuffer); + if (userWallet) this.signature = userWallet.sign(stringArray); + else this.signature = sign$1(sk, stringArray); + this.transactionSigned = true; + } + sortObject(object) { + const processObj = (obj) => { + const getType = (value) => { + return Object.prototype.toString.call(value); + }; + const isArray = (value) => { + if (getType(value) === "[object Array]") return true; + return false; + }; + const isObject = (value) => { + if (getType(value) === "[object Object]") return true; + return false; + }; + + const sortObjKeys = (unsorted) => { + const sorted = {}; + Object.keys(unsorted) + .sort() + .forEach((key) => (sorted[key] = unsorted[key])); + return sorted; + }; + + const formatKeys = (unformatted) => { + Object.keys(unformatted).forEach((key) => { + if (isArray(unformatted[key])) + unformatted[key] = unformatted[key].map((item) => { + if (isObject(item)) return formatKeys(item); + return item; + }); + if (isObject(unformatted[key])) unformatted[key] = formatKeys(unformatted[key]); + }); + return sortObjKeys(unformatted); + }; + + if (!isObject(obj)) throw new TypeError("Not a valid Object"); + try { + obj = JSON.parse(JSON.stringify(obj)); + } catch (e) { + throw new TypeError("Not a valid JSON Object"); + } + return formatKeys(obj); + }; + const orderedObj = processObj(object); + return { + orderedObj, + json: JSON.stringify(orderedObj), + }; + } + async getNonce(callback = undefined) { + let timestamp = new Date().toUTCString(); + this.nonceResult = await this.API.getNonce(this.sender); + if (typeof this.nonceResult.nonce === "undefined") { + throw new Error(this.nonceResult); + } + this.nonceResult.timestamp = timestamp; + this.nonce = this.nonceResult.nonce; + this.processor = this.nonceResult.processor; + this.nonceMasternode = this.nonceResult.masternode; + //Create payload object + this.makePayload(); + + if (!callback) return this.nonceResult; + return callback(this.nonceResult); + } + async send(sk = undefined, callback = undefined, masternode = undefined) { + //Error if transaction is not signed and no sk provided to the send method to sign it before sending + if (!validateTypes$1.isStringWithValue(sk) && !this.transactionSigned) { + throw new Error( + `Transation Not Signed: Private key needed or call sign() first` + ); + } + + if (this.blockservice.url){ + if (await this.blockservice.pingServer()) this.startBlock = await this.blockservice.getLastetBlock(); + } + + let timestamp = new Date().toUTCString(); + + try { + //If the nonce isn't set attempt to get it + if (isNaN(this.nonce) || !validateTypes$1.isStringWithValue(this.processor)) + await this.getNonce(); + //if the sk is provided then sign the transaction + if (validateTypes$1.isStringWithValue(sk)) this.sign(sk); + //Serialize transaction + this.makeTransaction(); + //Send transaction to the masternode + let masternodeURL = masternode; + if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode; + let response = await this.API.sendTransaction(this.tx, masternodeURL); + //Set error if txSendResult doesn't exist + if (!response || validateTypes$1.isStringWithValue(response)) { + this.txSendResult.errors = [response || "Unknown Transaction Error"]; + } else { + if (response.error) this.txSendResult.errors = [response.error]; + else this.txSendResult = response; + } + } catch (e) { + this.txSendResult.errors = [e.message]; + } + this.txSendResult.timestamp = timestamp; + return this.handleMasterNodeResponse(this.txSendResult, callback); + } + checkForTransactionResult(callback = undefined) { + return new Promise((resolve) => { + let timerId = setTimeout( + async function checkTx() { + this.txCheckAttempts = this.txCheckAttempts + 1; + let res = await this.API.checkTransaction(this.txHash); + let checkAgain = false; + let timestamp = new Date().toUTCString(); + if (typeof res === "string" || !res) { + if (this.txCheckAttempts < this.txCheckLimit) { + checkAgain = true; + } else { + this.txCheckResult.errors = [ + `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, + res, + ]; + this.txCheckResult.status = 2; + } + } else { + if (res.error) { + if (res.error === "Transaction not found.") { + if (this.txCheckAttempts < this.txCheckLimit) { + checkAgain = true; + } else { + this.txCheckResult.errors = [ + res.error, + `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, + ]; + this.txCheckResult.status = 2; + } + } else { + this.txCheckResult.errors = [res.error]; + } + } else { + this.txCheckResult = res; + } + } + if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000); + else { + if (validateTypes$1.isNumber(this.txCheckResult.status)) { + if (this.txCheckResult.status > 0) { + if (!validateTypes$1.isArray(this.txCheckResult.errors)) + this.txCheckResult.errors = []; + this.txCheckResult.errors.push("This transaction returned a non-zero status code"); + } + } + this.txCheckResult.timestamp = timestamp; + clearTimeout(timerId); + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + } + }.bind(this), + 1000 + ); + }); + } + + async checkTransactionResult(callback) { + await checkBlockserviceForTransactionResult(callback); + } + + async checkBlockserviceForTransactionResult(callback = undefined) { + if (!this.txHash) { + throw new Error("No transaction hash to check.") + } + + // Check if the blockservice is up + let serverAvailable = await this.blockservice.pingServer(); + //If it's not then fail over to checking from the masternode + if (!serverAvailable) { + console.log("Blockservice not available, failing back to masternode."); + return this.checkForTransactionResult(callback).then( + (res) => { + return {txinfo: res, ...res} + } + ) + } + + let count = this.maxBlockToCheck; + return new Promise(async (resolve) => { + let lastLatestBlock = this.startBlock || 0; + // Get the next 10 blocks from the blockservice starting with the block the transction was sent from + const getLatestBlock = async () => { + if (count < 1) { + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; + this.txCheckResult.status = 2; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + } + count = count - 1; + let latestBlock = await this.blockservice.getLastetBlock(); + if (latestBlock !== lastLatestBlock){ + lastLatestBlock = latestBlock; + checkForTrasaction(); + }else { + setTimeout(getLatestBlock, 5000); + } + }; + + // Check all the transaction in these blocks for our transction hash + const checkForTrasaction = async () => { + let txResults = await this.blockservice.getTransaction(this.txHash); + if (txResults){ + this.txCheckResult = {...txResults, ...txResults.txInfo}; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + }else { + if (count < 1){ + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; + this.txCheckResult.status = 2; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + }else { + setTimeout(getLatestBlock, 5000); + } + } + }; + + getLatestBlock(); + }); + } + handleMasterNodeResponse(result, callback = undefined) { + //Check to see if this is a successful transacation submission + if ( + validateTypes$1.isStringWithValue(result.hash) && + validateTypes$1.isStringWithValue(result.success) + ) { + this.txHash = result.hash; + this.setPendingBlockInfo(); + } else { + this.setBlockResultInfo(result); + this.txBlockResult = result; + } + this.events.emit("response", result, this.resultInfo.subtitle); + if (validateTypes$1.isFunction(callback)) callback(result); + return result; + } + setPendingBlockInfo() { + this.resultInfo = { + title: "Transaction Pending", + subtitle: "Your transaction was submitted and is being processed", + message: `Tx Hash: ${this.txHash}`, + type: "success", + }; + return this.resultInfo; + } + setBlockResultInfo(result) { + let erroredTx = false; + let errorText = `returned an error and `; + let statusCode = validateTypes$1.isNumber(result.status) ? result.status : undefined; + let stamps = result.stampsUsed || result.stamps_used || 0; + let message = ""; + if (validateTypes$1.isArrayWithValues(result.errors)) { + erroredTx = true; + message = `This transaction returned ${result.errors.length} errors.`; + if (result.result) { + if (result.result.includes("AssertionError")) result.errors.push(result.result); + } + } + if (statusCode && erroredTx) errorText = `returned status code ${statusCode} and `; + + this.resultInfo = { + title: `Transaction ${erroredTx ? "Failed" : "Successful"}`, + subtitle: `Your transaction ${erroredTx ? `${errorText} ` : ""}used ${stamps} stamps`, + message, + type: `${erroredTx ? "error" : "success"}`, + errorInfo: erroredTx ? result.errors : undefined, + returnResult: result.result || "", + stampsUsed: stamps, + statusCode, + }; + return this.resultInfo; + } + getResultInfo() { + return this.resultInfo; + } + getTxInfo() { + return { + senderVk: this.sender, + contractName: this.contract, + methodName: this.method, + kwargs: this.kwargs, + stampLimit: this.stampLimit, + }; + } + getAllInfo() { + return { + uid: this.uid, + txHash: this.txHash, + signed: this.transactionSigned, + tx: this.tx, + signature: this.signature, + networkInfo: this.getNetworkInfo(), + txInfo: this.getTxInfo(), + txSendResult: this.txSendResult, + txBlockResult: this.txBlockResult, + resultInfo: this.getResultInfo(), + nonceResult: this.nonceResult, + }; + } } -class TransactionBatcher extends Network { - constructor(networkInfo) { - if (networkInfo && networkInfo.classname === "Network") - super(networkInfo.getNetworkInfo()); - else super(networkInfo); - - this.txBatches = {}; - this.overflow = []; - this.nonceResults = {}; - this.running = false; - } - addTransaction(txInfo){ - if (this.running) { - this.overflow.push(txInfo); - return - } - this.validateTransactionInfo(txInfo); - if (!this.txBatches[txInfo.senderVk]) this.txBatches[txInfo.senderVk] = []; - this.txBatches[txInfo.senderVk].push(txInfo); - } - addTransactionList(txList){ - txList.forEach(txInfo => this.addTransaction(txInfo)); - } - processOverflow(){ - const overflow = this.overflow; - this.overflow = []; - overflow.forEach(txInfo => this.addTransaction(txInfo)); - } - hasTransactions(){ - let test = Object.keys(this.txBatches).map(senderVk => this.txBatches[senderVk].length); - test.filter(f => f === 0); - if (test.length > 0 ) return true - return false - } - validateTransactionInfo(txInfo){ - try{ - new TransactionBuilder(txInfo); - }catch(e){ - return false - } - return true - } - async getStartingNonce(senderVk, callback = undefined){ - let timestamp = new Date().toUTCString(); - let response = await this.API.getNonce(senderVk); - if (typeof response.nonce === 'undefined'){ - throw new Error(response) - } - response.timestamp = timestamp; - this.nonceResults[senderVk] = response; - - if (callback) callback(response); - return response; - } - async sendAllBatches(keyDict){ - if (this.running) return - let sentTransactions = []; - this.running = true; - - await Promise.all(Object.keys(this.txBatches).map((senderVk) => { - const senderBatch = this.txBatches[senderVk].splice(0,15); - if (senderBatch.length <= 15) delete this.txBatches[senderVk]; - - return new Promise(async (resolver) => { - if (senderBatch.length === 0 ) resolver(); - - if (!keyDict[senderVk]) throw new Error(`Cannot sign batch for ${senderVk}. No signing key provided.`) - let nonceResponse = await this.getStartingNonce(senderVk); - let txBatch = this.setBatchNonces(nonceResponse, senderBatch); - this.signBatch(txBatch, keyDict[senderVk]); - this.sendBatch(txBatch).then(sentList => { - sentTransactions = [...sentTransactions, ...sentList]; - resolver(); - }); - }) - })); - - try{ - return Promise.all(sentTransactions) - }catch (e){} - finally{ - this.running = false; - this.processOverflow(); - } - } - setBatchNonces(nonceResult, txList){ - return txList.map((txInfo, index) => { - txInfo.nonce = nonceResult.nonce + index; - txInfo.processor = nonceResult.processor; - return new TransactionBuilder({hosts: [nonceResult.masternode]}, txInfo) - }).sort((a, b) => a.nonce - b.nonce) - } - signBatch(txBatch, key){ - txBatch.forEach(txBuilder => txBuilder.sign(key)); - } - sendBatch(txBatch){ - let resolvedTransactions = []; - return new Promise(resolver => { - const resolve = (index) => { - if ((index + 1) === txBatch.length) resolver(resolvedTransactions); - }; - txBatch.forEach((txBuilder, index) => { - const delayedSend = () => { - resolvedTransactions[index] = txBuilder.send().then(() => {return txBuilder}); - resolve(index); - }; - setTimeout(delayedSend, 1200 * index); - }); - }) - } +class TransactionBatcher extends Network { + constructor(networkInfo) { + if (networkInfo && networkInfo.classname === "Network") + super(networkInfo.getNetworkInfo()); + else super(networkInfo); + + this.txBatches = {}; + this.overflow = []; + this.nonceResults = {}; + this.running = false; + } + addTransaction(txInfo){ + if (this.running) { + this.overflow.push(txInfo); + return + } + this.validateTransactionInfo(txInfo); + if (!this.txBatches[txInfo.senderVk]) this.txBatches[txInfo.senderVk] = []; + this.txBatches[txInfo.senderVk].push(txInfo); + } + addTransactionList(txList){ + txList.forEach(txInfo => this.addTransaction(txInfo)); + } + processOverflow(){ + const overflow = this.overflow; + this.overflow = []; + overflow.forEach(txInfo => this.addTransaction(txInfo)); + } + hasTransactions(){ + let test = Object.keys(this.txBatches).map(senderVk => this.txBatches[senderVk].length); + test.filter(f => f === 0); + if (test.length > 0 ) return true + return false + } + validateTransactionInfo(txInfo){ + try{ + new TransactionBuilder(txInfo); + }catch(e){ + return false + } + return true + } + async getStartingNonce(senderVk, callback = undefined){ + let timestamp = new Date().toUTCString(); + let response = await this.API.getNonce(senderVk); + if (typeof response.nonce === 'undefined'){ + throw new Error(response) + } + response.timestamp = timestamp; + this.nonceResults[senderVk] = response; + + if (callback) callback(response); + return response; + } + async sendAllBatches(keyDict){ + if (this.running) return + let sentTransactions = []; + this.running = true; + + await Promise.all(Object.keys(this.txBatches).map((senderVk) => { + const senderBatch = this.txBatches[senderVk].splice(0,15); + if (senderBatch.length <= 15) delete this.txBatches[senderVk]; + + return new Promise(async (resolver) => { + if (senderBatch.length === 0 ) resolver(); + + if (!keyDict[senderVk]) throw new Error(`Cannot sign batch for ${senderVk}. No signing key provided.`) + let nonceResponse = await this.getStartingNonce(senderVk); + let txBatch = this.setBatchNonces(nonceResponse, senderBatch); + this.signBatch(txBatch, keyDict[senderVk]); + this.sendBatch(txBatch).then(sentList => { + sentTransactions = [...sentTransactions, ...sentList]; + resolver(); + }); + }) + })); + + try{ + return Promise.all(sentTransactions) + }catch (e){} + finally{ + this.running = false; + this.processOverflow(); + } + } + setBatchNonces(nonceResult, txList){ + return txList.map((txInfo, index) => { + txInfo.nonce = nonceResult.nonce + index; + txInfo.processor = nonceResult.processor; + return new TransactionBuilder({hosts: [nonceResult.masternode]}, txInfo) + }).sort((a, b) => a.nonce - b.nonce) + } + signBatch(txBatch, key){ + txBatch.forEach(txBuilder => txBuilder.sign(key)); + } + sendBatch(txBatch){ + let resolvedTransactions = []; + return new Promise(resolver => { + const resolve = (index) => { + if ((index + 1) === txBatch.length) resolver(resolvedTransactions); + }; + txBatch.forEach((txBuilder, index) => { + const delayedSend = () => { + resolvedTransactions[index] = txBuilder.send().then(() => {return txBuilder}); + resolve(index); + }; + setTimeout(delayedSend, 1200 * index); + }); + }) + } } -const { validateTypes, assertTypes } = validators; - -class Keystore { - /** - * Lamden Keystores - * - * This Class will create a lamden keystore instance - * - * @param {Object|undefined} arg constructor argument - * @param {String|undefined} arg.key Create an instance and load it with one private key - * @param {String|undefined} arg.keyList Create an instance and load it with an array of private keys - * @param {String|undefined} arg.keystoreData Create an instance from an existing keystore file data - * @return {Keystore} - */ - constructor(arg = undefined) { - this.KEYSTORE_VERSION = "1.0"; - this.password = null; - this.encryptedData = null; - - this.keyList = (() => { - let keyList = []; - let outerClass = this; - let wallets = []; - - const addKey = (key) => { - keyList.push(key); - createWallets(); - }; - const deleteKey = (position) => { - keyList.splice(position, 1); - createWallets(); - }; - const clearKeys = () => { - keyList = []; - createWallets(); - }; - const numOfKeys = () => keyList.length; - const createWallets = () => { - wallets = []; - keyList.forEach(keyInfo => { - let newWallet = create_wallet({sk: keyInfo.sk, keepPrivate: true}); - newWallet = {...newWallet, ...keyInfo}; - delete newWallet.sk; - wallets.push(newWallet); - }); - }; - const createKeystore = (password, hint = undefined) => { - return JSON.stringify({ - data: encryptObject(password, {version: outerClass.KEYSTORE_VERSION, keyList}), - w: !hint ? "" : encryptStrHash('n1ahcKc0lb', hint), - }); - }; - const decryptKeystore = (password, data) => { - let decrypted = decryptObject(password, data); - if (decrypted) { - assertTypes.isArray(decrypted.keyList); - decrypted.keyList.forEach(keyInfo => assertTypes.isStringWithValue(keyInfo.sk)); - decrypted.keyList.forEach(keyInfo => addKey(keyInfo)); - outerClass.version = decrypted.version; - } else { - throw new Error("Incorrect Keystore Password.") - } - }; - - return { - getWallets: () => wallets, - getWallet: (vk) => wallets.find(wallet => wallet.vk === vk), - addKey, - clearKeys, - numOfKeys, - deleteKey, - createKeystore, - decryptKeystore - } - })(); - - if (arg){ - if (arg.key) this.addKey(arg.key); - if (arg.keyList) this.addKeys(arg.keyList); - if (arg.keystoreData) this.addKeystoreData(arg.keystoreData); - } - } - /** - * Add a list of keys to add to the keystore - * @typedef {Object} keyinfo - * @property {string} sk - The private key. - * @property {string} nickname - The key nickname. - * @property {string} name - The key name. - * @property {string} network - Network name. - * @property {string} symbol - The token symbol. - * @param {Array.} keyList An array of keyinfo Object - */ - addKeys(keyList){ - assertTypes.isArray(keyList); - keyList.forEach(key => this.addKey(key)); - } - /** - * Add a key to the keystore - * @typedef {Object} keyinfo - * @property {string} sk - The private key. - * @property {string} nickname - The key nickname. - * @property {string} name - The key name. - * @property {string} network - Network name. - * @property {string} symbol - The token symbol. - * @param {keyinfo} keyInfo A keyinfo Object - */ - addKey(keyInfo){ - assertTypes.isObjectWithKeys(keyInfo); - assertTypes.isStringWithValue(keyInfo.sk); - if (validateTypes.isStringWithValue(keyInfo.vk)) delete keyInfo.vk; - this.keyList.addKey(keyInfo); - } - /** - * Load the keystore with the data from an existing keystore - * @param {string} keystoreData The contents of an existing encrypted keystore file - */ - addKeystoreData(keystoreData){ - if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); - if(this.validateKeyStore(keystoreData)){ - this.encryptedData = keystoreData; - } - } - /** - * Returns the password hint in a keystore file - * @param {String|undefined} keystoreData The contents of an existing encrypted keystore file if one wasn't supplied to the constructor - */ - getPasswordHint(keystoreData = undefined){ - if (!this.encryptedData && !keystoreData) throw new Error("No keystore data found.") - - if (keystoreData) { - if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); - } - else keystoreData = this.encryptedData; - - if (keystoreData.w) return decryptStrHash('n1ahcKc0lb', keystoreData.w); - else return "" - } - /** - * Removes a specific key from the keyList - * @param {Number} keyIndex The index of the key you want to remove - */ - deleteKey(keyIndex){ - assertTypes.isInteger(keyIndex); - if (this.keyList.numOfKeys() === 0) return - if (keyIndex < 0 || keyIndex >= this.keyList.numOfKeys()) throw new Error("Key index out of range.") - this.keyList.deleteKey(keyIndex); - } - /** - * Clears all keys from the keystore - */ - clearKeys(){ - this.keyList.clearKeys(); - } - /** - * Clears all keys from the keystore - * @return {Array.} An array of wallet objects - */ - get wallets() { - return this.keyList.getWallets() - } - /** - * Load the keystore with the data from an existing keystore - * @param {String} vk A 32 character long Lamden public key - * @return {Object} A wallet object - */ - getWallet(vk) { - return this.keyList.getWallet(vk) - } - /** - * Used to validate that a keystore is the proper Lamden Format (does not decrypt data) - * @param {String} keystoreData The contents of an existing encrypted keystore file - * @return {Boolean} valid - * @throws {Error} This is not a valid keystore file. - */ - validateKeyStore(keystoreData){ - assertTypes.isObjectWithKeys(keystoreData); - try{ - let encryptedData = JSON.parse(keystoreData.data); - if (!encryptedData.ct || !encryptedData.iv || !encryptedData.s){ - throw new Error("This is not a valid keystore file.") - } - } catch (e) { - throw new Error("This is not a valid keystore file.") - } - return true; - } - /** - * Create a Keystore text string from the keys contained in the Keystore instance - * @param {String} password A password to encrypt the data - * @param {String|undefined} hint An optional password hint. Not stored in clear text (obsured) but not encrypted with the password. - * @return {String} A JSON stringified object containing the encrypted data - * @throws {Error} Any errors from the encyption process - */ - createKeystore(password, hint = undefined) { - assertTypes.isStringWithValue(password); - if (hint){ - assertTypes.isStringWithValue(hint); - } - return this.keyList.createKeystore(password, hint) - } - /** - * Decrypt a keystore into a useable array of wallets. Any decrypted keys will be added to existing keys in the keystore. - * @param {String} password A password to encrypt the data - * @param {String|undefined} keystoreData The encrypted contents from a keystore file if not passed into the constructor. - * @throws {Error} Any errors from the encyption process - */ - decryptKeystore(password, keystoreData = undefined){ - if (keystoreData) this.addKeystoreData(keystoreData); - if (!this.encryptedData) throw new Error ("No keystoreData to decrypt.") - try{ - this.keyList.decryptKeystore(password, this.encryptedData.data); - }catch (e){ - throw new Error("Incorrect Keystore Password.") - } - } +const { validateTypes, assertTypes } = validators; + +class Keystore { + /** + * Lamden Keystores + * + * This Class will create a lamden keystore instance + * + * @param {Object|undefined} arg constructor argument + * @param {String|undefined} arg.key Create an instance and load it with one private key + * @param {String|undefined} arg.keyList Create an instance and load it with an array of private keys + * @param {String|undefined} arg.keystoreData Create an instance from an existing keystore file data + * @return {Keystore} + */ + constructor(arg = undefined) { + this.KEYSTORE_VERSION = "1.0"; + this.password = null; + this.encryptedData = null; + + this.keyList = (() => { + let keyList = []; + let outerClass = this; + let wallets = []; + + const addKey = (key) => { + keyList.push(key); + createWallets(); + }; + const deleteKey = (position) => { + keyList.splice(position, 1); + createWallets(); + }; + const clearKeys = () => { + keyList = []; + createWallets(); + }; + const numOfKeys = () => keyList.length; + const createWallets = () => { + wallets = []; + keyList.forEach(keyInfo => { + let newWallet = create_wallet({sk: keyInfo.sk, keepPrivate: true}); + newWallet = {...newWallet, ...keyInfo}; + delete newWallet.sk; + wallets.push(newWallet); + }); + }; + const createKeystore = (password, hint = undefined) => { + return JSON.stringify({ + data: encryptObject(password, {version: outerClass.KEYSTORE_VERSION, keyList}), + w: !hint ? "" : encryptStrHash('n1ahcKc0lb', hint), + }); + }; + const decryptKeystore = (password, data) => { + let decrypted = decryptObject(password, data); + if (decrypted) { + assertTypes.isArray(decrypted.keyList); + decrypted.keyList.forEach(keyInfo => assertTypes.isStringWithValue(keyInfo.sk)); + decrypted.keyList.forEach(keyInfo => addKey(keyInfo)); + outerClass.version = decrypted.version; + } else { + throw new Error("Incorrect Keystore Password.") + } + }; + + return { + getWallets: () => wallets, + getWallet: (vk) => wallets.find(wallet => wallet.vk === vk), + addKey, + clearKeys, + numOfKeys, + deleteKey, + createKeystore, + decryptKeystore + } + })(); + + if (arg){ + if (arg.key) this.addKey(arg.key); + if (arg.keyList) this.addKeys(arg.keyList); + if (arg.keystoreData) this.addKeystoreData(arg.keystoreData); + } + } + /** + * Add a list of keys to add to the keystore + * @typedef {Object} keyinfo + * @property {string} sk - The private key. + * @property {string} nickname - The key nickname. + * @property {string} name - The key name. + * @property {string} network - Network name. + * @property {string} symbol - The token symbol. + * @param {Array.} keyList An array of keyinfo Object + */ + addKeys(keyList){ + assertTypes.isArray(keyList); + keyList.forEach(key => this.addKey(key)); + } + /** + * Add a key to the keystore + * @typedef {Object} keyinfo + * @property {string} sk - The private key. + * @property {string} nickname - The key nickname. + * @property {string} name - The key name. + * @property {string} network - Network name. + * @property {string} symbol - The token symbol. + * @param {keyinfo} keyInfo A keyinfo Object + */ + addKey(keyInfo){ + assertTypes.isObjectWithKeys(keyInfo); + assertTypes.isStringWithValue(keyInfo.sk); + if (validateTypes.isStringWithValue(keyInfo.vk)) delete keyInfo.vk; + this.keyList.addKey(keyInfo); + } + /** + * Load the keystore with the data from an existing keystore + * @param {string} keystoreData The contents of an existing encrypted keystore file + */ + addKeystoreData(keystoreData){ + if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); + if(this.validateKeyStore(keystoreData)){ + this.encryptedData = keystoreData; + } + } + /** + * Returns the password hint in a keystore file + * @param {String|undefined} keystoreData The contents of an existing encrypted keystore file if one wasn't supplied to the constructor + */ + getPasswordHint(keystoreData = undefined){ + if (!this.encryptedData && !keystoreData) throw new Error("No keystore data found.") + + if (keystoreData) { + if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); + } + else keystoreData = this.encryptedData; + + if (keystoreData.w) return decryptStrHash('n1ahcKc0lb', keystoreData.w); + else return "" + } + /** + * Removes a specific key from the keyList + * @param {Number} keyIndex The index of the key you want to remove + */ + deleteKey(keyIndex){ + assertTypes.isInteger(keyIndex); + if (this.keyList.numOfKeys() === 0) return + if (keyIndex < 0 || keyIndex >= this.keyList.numOfKeys()) throw new Error("Key index out of range.") + this.keyList.deleteKey(keyIndex); + } + /** + * Clears all keys from the keystore + */ + clearKeys(){ + this.keyList.clearKeys(); + } + /** + * Clears all keys from the keystore + * @return {Array.} An array of wallet objects + */ + get wallets() { + return this.keyList.getWallets() + } + /** + * Load the keystore with the data from an existing keystore + * @param {String} vk A 32 character long Lamden public key + * @return {Object} A wallet object + */ + getWallet(vk) { + return this.keyList.getWallet(vk) + } + /** + * Used to validate that a keystore is the proper Lamden Format (does not decrypt data) + * @param {String} keystoreData The contents of an existing encrypted keystore file + * @return {Boolean} valid + * @throws {Error} This is not a valid keystore file. + */ + validateKeyStore(keystoreData){ + assertTypes.isObjectWithKeys(keystoreData); + try{ + let encryptedData = JSON.parse(keystoreData.data); + if (!encryptedData.ct || !encryptedData.iv || !encryptedData.s){ + throw new Error("This is not a valid keystore file.") + } + } catch (e) { + throw new Error("This is not a valid keystore file.") + } + return true; + } + /** + * Create a Keystore text string from the keys contained in the Keystore instance + * @param {String} password A password to encrypt the data + * @param {String|undefined} hint An optional password hint. Not stored in clear text (obsured) but not encrypted with the password. + * @return {String} A JSON stringified object containing the encrypted data + * @throws {Error} Any errors from the encyption process + */ + createKeystore(password, hint = undefined) { + assertTypes.isStringWithValue(password); + if (hint){ + assertTypes.isStringWithValue(hint); + } + return this.keyList.createKeystore(password, hint) + } + /** + * Decrypt a keystore into a useable array of wallets. Any decrypted keys will be added to existing keys in the keystore. + * @param {String} password A password to encrypt the data + * @param {String|undefined} keystoreData The encrypted contents from a keystore file if not passed into the constructor. + * @throws {Error} Any errors from the encyption process + */ + decryptKeystore(password, keystoreData = undefined){ + if (keystoreData) this.addKeystoreData(keystoreData); + if (!this.encryptedData) throw new Error ("No keystoreData to decrypt.") + try{ + this.keyList.decryptKeystore(password, this.encryptedData.data); + }catch (e){ + throw new Error("Incorrect Keystore Password.") + } + } } -globalThis.Buffer = buffer.Buffer; - -var index = { - TransactionBuilder, - TransactionBatcher, - Masternode_API: LamdenMasterNode_API, - Blockservice_API: LamdenBlockservice_API, - Network, - wallet, - Keystore, - Encoder, - utils: utils$1, +globalThis.Buffer = buffer.Buffer; + +var index = { + TransactionBuilder, + TransactionBatcher, + Masternode_API: LamdenMasterNode_API, + Blockservice_API: LamdenBlockservice_API, + Network, + wallet, + Keystore, + Encoder, + utils: utils$1, }; module.exports = index; diff --git a/dist/esm/lamden.js b/dist/esm/lamden.js index 92d560a..b40160a 100644 --- a/dist/esm/lamden.js +++ b/dist/esm/lamden.js @@ -19,4 +19,4 @@ var n=e("buffer"),i=n.Buffer;function o(e,t){for(var r in e)t[r]=e[r]}function a */ function(e){const t=Pe,r=$e,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=function(e){+e!=e&&(e=0);return a.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function o(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,a.prototype),t}function a(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return h(e)}return s(e,t,r)}function s(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|d(e,t);let n=o(r);const i=n.write(e,t);i!==r&&(n=n.slice(0,i));return n}(e,t);if(ArrayBuffer.isView(e))return function(e){if($(e,Uint8Array)){const t=new Uint8Array(e);return f(t.buffer,t.byteOffset,t.byteLength)}return l(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if($(e,ArrayBuffer)||e&&$(e.buffer,ArrayBuffer))return f(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&($(e,SharedArrayBuffer)||e&&$(e.buffer,SharedArrayBuffer)))return f(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return a.from(n,t,r);const i=function(e){if(a.isBuffer(e)){const t=0|c(e.length),r=o(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||V(e.length)?o(0):l(e);if("Buffer"===e.type&&Array.isArray(e.data))return l(e.data)}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return a.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function u(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function h(e){return u(e),o(e<0?0:0|c(e))}function l(e){const t=e.length<0?0:0|c(e.length),r=o(t);for(let n=0;n=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function d(e,t){if(a.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||$(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return K(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Y(e).length;default:if(i)return n?-1:K(e).length;t=(""+t).toLowerCase(),i=!0}}function p(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,r);case"utf8":case"utf-8":return k(this,t,r);case"ascii":return R(this,t,r);case"latin1":case"binary":return A(this,t,r);case"base64":return S(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),V(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=a.from(t,n)),a.isBuffer(t))return 0===t.length?-1:b(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):b(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(e,t,r,n,i){let o,a=1,s=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,s/=2,u/=2,r/=2}function h(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(i){let n=-1;for(o=r;os&&(r=s-u),o=r;o>=0;o--){let r=!0;for(let n=0;ni&&(n=i):n=i;const o=t.length;let a;for(n>o/2&&(n=o/2),a=0;a>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function S(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function k(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i239?4:t>223?3:t>191?2:1;if(i+a<=r){let r,n,s,u;switch(a){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[i+1],n=e[i+2],s=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&s)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&s,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=a}return function(e){const t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);let r="",n=0;for(;nn.length?(a.isBuffer(t)||(t=a.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!a.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},a.byteLength=d,a.prototype._isBuffer=!0,a.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;tr&&(t+=" ... "),""},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(e,t,r,n,i){if($(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0);const u=Math.min(o,s),h=this.slice(n,i),l=e.slice(t,r);for(let e=0;e>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return m(this,e,t,r);case"utf8":case"utf-8":return v(this,e,t,r);case"ascii":case"latin1":case"binary":return w(this,e,t,r);case"base64":return _(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const x=4096;function R(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;in)&&(r=n);let i="";for(let n=t;nr)throw new RangeError("Trying to access beyond buffer length")}function M(e,t,r,n,i,o){if(!a.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function j(e,t,r,n,i){z(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=a,a>>=8,e[r++]=a,a>>=8,e[r++]=a,a>>=8,e[r++]=a,r}function L(e,t,r,n,i){z(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=a,a>>=8,e[r+2]=a,a>>=8,e[r+1]=a,a>>=8,e[r]=a,r+8}function U(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function I(e,t,n,i,o){return t=+t,n>>>=0,o||U(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function C(e,t,n,i,o){return t=+t,n>>>=0,o||U(e,0,n,8),r.write(e,t,n,i,52,8),n+8}a.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e],i=1,o=0;for(;++o>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=J((function(e){q(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e],i=1,o=0;for(;++o=i&&(n-=Math.pow(2,8*t)),n},a.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||O(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},a.prototype.readInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},a.prototype.readInt16LE=function(e,t){e>>>=0,t||O(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(e,t){e>>>=0,t||O(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=J((function(e){q(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<>>=0,t||O(e,4,this.length),r.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e>>>=0,t||O(e,4,this.length),r.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e>>>=0,t||O(e,8,this.length),r.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e>>>=0,t||O(e,8,this.length),r.read(this,e,!1,52,8)},a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){M(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o>>=0,r>>>=0,!n){M(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,255,0),this[t]=255&e,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeBigUInt64LE=J((function(e,t=0){return j(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),a.prototype.writeBigUInt64BE=J((function(e,t=0){return L(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),a.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);M(this,e,t,r,n-1,-n)}let i=0,o=1,a=0;for(this[t]=255&e;++i>0)-a&255;return t+r},a.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);M(this,e,t,r,n-1,-n)}let i=r-1,o=1,a=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/o>>0)-a&255;return t+r},a.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},a.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeBigInt64LE=J((function(e,t=0){return j(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),a.prototype.writeBigInt64BE=J((function(e,t=0){return L(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),a.prototype.writeFloatLE=function(e,t,r){return I(this,e,t,!0,r)},a.prototype.writeFloatBE=function(e,t,r){return I(this,e,t,!1,r)},a.prototype.writeDoubleLE=function(e,t,r){return C(this,e,t,!0,r)},a.prototype.writeDoubleBE=function(e,t,r){return C(this,e,t,!1,r)},a.prototype.copy=function(e,t,r,n){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function z(e,t,r,n,i,o){if(e>r||e3?0===t||t===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** ${8*(o+1)-1}${n}`:`>= ${t}${n} and <= ${r}${n}`,new N.ERR_OUT_OF_RANGE("value",i,e)}!function(e,t,r){q(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||W(t,e.length-(r+1))}(n,i,o)}function q(e,t){if("number"!=typeof e)throw new N.ERR_INVALID_ARG_TYPE(t,"number",e)}function W(e,t,r){if(Math.floor(e)!==e)throw q(e,r),new N.ERR_OUT_OF_RANGE(r||"offset","an integer",e);if(t<0)throw new N.ERR_BUFFER_OUT_OF_BOUNDS;throw new N.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}P("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),P("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),P("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=D(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=D(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n}),RangeError);const F=/[^+/0-9A-Za-z-_]/g;function K(e,t){let r;t=t||1/0;const n=e.length;let i=null;const o=[];for(let a=0;a55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Y(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(F,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function H(e,t,r,n){let i;for(i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function $(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function V(e){return e!=e}const G=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}}(Ne),function(e,t){var r=Ne,n=r.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o),i(n,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=n(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(Ce,Ce.exports),Ve.prototype=Object.create(null),Ge.EventEmitter=Ge,Ge.usingDomains=!1,Ge.prototype.domain=void 0,Ge.prototype._events=void 0,Ge.prototype._maxListeners=void 0,Ge.defaultMaxListeners=10,Ge.init=function(){this.domain=null,Ge.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Ve,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Ge.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},Ge.prototype.getMaxListeners=function(){return Je(this)},Ge.prototype.emit=function(e){var t,r,n,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.error;else if(!u)return!1;if(s=this.domain,u){if(t=arguments[1],!s){if(t instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=s,t.domainThrown=!1,s.emit("error",t),!1}if(!(r=a[e]))return!1;var l="function"==typeof r;switch(n=arguments.length){case 1:Xe(r,l,this);break;case 2:Ze(r,l,this,arguments[1]);break;case 3:Qe(r,l,this,arguments[1],arguments[2]);break;case 4:et(r,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(n-1),o=1;o0;)if(r[o]===t||r[o].listener&&r[o].listener===t){a=r[o].listener,i=o;break}if(i<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new Ve,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,i=e.length;n0?Reflect.ownKeys(this._events):[]};var at=Object.freeze({__proto__:null,default:Ge,EventEmitter:Ge});function st(){throw new Error("setTimeout has not been defined")}function ut(){throw new Error("clearTimeout has not been defined")}var ht=st,lt=ut;function ft(e){if(ht===setTimeout)return setTimeout(e,0);if((ht===st||!ht)&&setTimeout)return ht=setTimeout,setTimeout(e,0);try{return ht(e,0)}catch(t){try{return ht.call(null,e,0)}catch(t){return ht.call(this,e,0)}}}"function"==typeof N.setTimeout&&(ht=setTimeout),"function"==typeof N.clearTimeout&&(lt=clearTimeout);var ct,dt=[],pt=!1,gt=-1;function yt(){pt&&ct&&(pt=!1,ct.length?dt=ct.concat(dt):gt=-1,dt.length&&bt())}function bt(){if(!pt){var e=ft(yt);pt=!0;for(var t=dt.length;t;){for(ct=dt,dt=[];++gt1)for(var r=1;r=a)return e;switch(e){case"%s":return String(i[n++]);case"%d":return Number(i[n++]);case"%j":try{return JSON.stringify(i[n++])}catch(e){return"[Circular]"}default:return e}})),u=i[n];n=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),c(r)?n.showHidden=r:r&&t._extend(n,r),y(n.showHidden)&&(n.showHidden=!1),y(n.depth)&&(n.depth=2),y(n.colors)&&(n.colors=!1),y(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=a),u(n,e,n.depth)}function a(e,t){var r=o.styles[t];return r?"["+o.colors[r][0]+"m"+e+"["+o.colors[r][1]+"m":e}function s(e,t){return e}function u(e,r,n){if(e.customInspect&&r&&_(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,e);return g(i)||(i=u(e,i,n)),i}var o=function(e,t){if(y(t))return e.stylize("undefined","undefined");if(g(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(p(t))return e.stylize(""+t,"number");if(c(t))return e.stylize(""+t,"boolean");if(d(t))return e.stylize("null","null")}(e,r);if(o)return o;var a=Object.keys(r),s=function(e){var t={};return e.forEach((function(e,r){t[e]=!0})),t}(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(r)),w(r)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return h(r);if(0===a.length){if(_(r)){var m=r.name?": "+r.name:"";return e.stylize("[Function"+m+"]","special")}if(b(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(v(r))return e.stylize(Date.prototype.toString.call(r),"date");if(w(r))return h(r)}var E,S="",k=!1,x=["{","}"];(f(r)&&(k=!0,x=["[","]"]),_(r))&&(S=" [Function"+(r.name?": "+r.name:"")+"]");return b(r)&&(S=" "+RegExp.prototype.toString.call(r)),v(r)&&(S=" "+Date.prototype.toUTCString.call(r)),w(r)&&(S=" "+h(r)),0!==a.length||k&&0!=r.length?n<0?b(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special"):(e.seen.push(r),E=k?function(e,t,r,n,i){for(var o=[],a=0,s=t.length;a60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(E,S,x)):x[0]+S+x[1]}function h(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,r,n,i,o){var a,s,h;if((h=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?s=h.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):h.set&&(s=e.stylize("[Setter]","special")),R(n,i)||(a="["+i+"]"),s||(e.seen.indexOf(h.value)<0?(s=d(r)?u(e,h.value,null):u(e,h.value,r-1)).indexOf("\n")>-1&&(s=o?s.split("\n").map((function(e){return" "+e})).join("\n").substr(2):"\n"+s.split("\n").map((function(e){return" "+e})).join("\n")):s=e.stylize("[Circular]","special")),y(a)){if(o&&i.match(/^\d+$/))return s;(a=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(a=a.substr(1,a.length-2),a=e.stylize(a,"name")):(a=a.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),a=e.stylize(a,"string"))}return a+": "+s}function f(e){return Array.isArray(e)}function c(e){return"boolean"==typeof e}function d(e){return null===e}function p(e){return"number"==typeof e}function g(e){return"string"==typeof e}function y(e){return void 0===e}function b(e){return m(e)&&"[object RegExp]"===E(e)}function m(e){return"object"==typeof e&&null!==e}function v(e){return m(e)&&"[object Date]"===E(e)}function w(e){return m(e)&&("[object Error]"===E(e)||e instanceof Error)}function _(e){return"function"==typeof e}function E(e){return Object.prototype.toString.call(e)}function S(e){return e<10?"0"+e.toString(10):e.toString(10)}t.debuglog=function(e){if(y(n)&&(n=Mt.env.NODE_DEBUG||""),e=e.toUpperCase(),!i[e])if(new RegExp("\\b"+e+"\\b","i").test(n)){var r=Mt.pid;i[e]=function(){var n=t.format.apply(t,arguments);console.error("%s %d: %s",e,r,n)}}else i[e]=function(){};return i[e]},t.inspect=o,o.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},o.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=f,t.isBoolean=c,t.isNull=d,t.isNullOrUndefined=function(e){return null==e},t.isNumber=p,t.isString=g,t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=y,t.isRegExp=b,t.isObject=m,t.isDate=v,t.isError=w,t.isFunction=_,t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=Lt;var k=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function x(){var e=new Date,t=[S(e.getHours()),S(e.getMinutes()),S(e.getSeconds())].join(":");return[e.getDate(),k[e.getMonth()],t].join(" ")}function R(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.log=function(){console.log("%s - %s",x(),t.format.apply(t,arguments))},t.inherits=Ie.exports,t._extend=function(e,t){if(!t||!m(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}}(jt),Ut.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Ut.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},Ut.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Ut.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ut.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},Ut.prototype.concat=function(e){if(0===this.length)return Ne.Buffer.alloc(0);if(1===this.length)return this.head.data;for(var t=Ne.Buffer.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var It={},Ct=Ce.exports.Buffer,Nt=Ct.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};var Pt=It.StringDecoder=Dt;function Dt(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(Ct.isEncoding===Nt||!Nt(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=Wt,this.end=Ft,t=4;break;case"utf8":this.fillLast=qt,t=4;break;case"base64":this.text=Kt,this.end=Yt,t=3;break;default:return this.write=Ht,void(this.end=$t)}this.lastNeed=0,this.lastTotal=0,this.lastChar=Ct.allocUnsafe(t)}function zt(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function qt(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function Wt(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function Ft(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function Kt(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function Yt(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function Ht(e){return e.toString(this.encoding)}function $t(e){return e&&e.length?this.write(e):""}Dt.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r=0)return i>0&&(e.lastNeed=i-1),i;if(--n=0)return i>0&&(e.lastNeed=i-2),i;if(--n=0)return i>0&&(2===i?i=0:e.lastNeed=i-3),i;return 0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)},Dt.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length},Jt.ReadableState=Gt;var Vt=jt.debuglog("stream");function Gt(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof Sr&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new Ut,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new Pt(e.encoding),this.encoding=e.encoding)}function Jt(e){if(!(this instanceof Jt))return new Jt(e);this._readableState=new Gt(e,this),this.readable=!0,e&&"function"==typeof e.read&&(this._read=e.read),Ge.call(this)}function Xt(e,t,r,n,i){var o=function(e,t){var r=null;X.isBuffer(t)||"string"==typeof t||null==t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk"));return r}(t,r);if(o)e.emit("error",o);else if(null===r)t.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,Qt(e)}(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{var u;!t.decoder||i||n||(r=t.decoder.write(r),u=!t.objectMode&&0===r.length),i||(t.reading=!1),u||(t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&Qt(e))),function(e,t){t.readingMore||(t.readingMore=!0,mt(tr,e,t))}(e,t)}else i||(t.reading=!1);return function(e){return!e.ended&&(e.needReadable||e.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=8388608?e=8388608:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function Qt(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(Vt("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?mt(er,e):er(e))}function er(e){Vt("emit readable"),e.emit("readable"),ir(e)}function tr(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=function(e,t,r){var n;eo.length?o.length:e;if(a===o.length?i+=o:i+=o.slice(0,e),0===(e-=a)){a===o.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(a));break}++n}return t.length-=n,i}(e,t):function(e,t){var r=X.allocUnsafe(e),n=t.head,i=1;n.data.copy(r),e-=n.data.length;for(;n=n.next;){var o=n.data,a=e>o.length?o.length:e;if(o.copy(r,r.length-e,0,a),0===(e-=a)){a===o.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(a));break}++i}return t.length-=i,r}(e,t);return n}(e,t.buffer,t.decoder),r);var r}function ar(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,mt(sr,t,e))}function sr(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function ur(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return Vt("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?ar(this):Qt(this),null;if(0===(e=Zt(e,t))&&t.ended)return 0===t.length&&ar(this),null;var n,i=t.needReadable;return Vt("need readable",i),(0===t.length||t.length-e0?or(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&ar(this)),null!==n&&this.emit("data",n),n},Jt.prototype._read=function(e){this.emit("error",new Error("not implemented"))},Jt.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e)}n.pipesCount+=1,Vt("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||!1!==t.end?a:h;function o(e){Vt("onunpipe"),e===r&&h()}function a(){Vt("onend"),e.end()}n.endEmitted?mt(i):r.once("end",i),e.on("unpipe",o);var s=function(e){return function(){var t=e._readableState;Vt("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&e.listeners("data").length&&(t.flowing=!0,ir(e))}}(r);e.on("drain",s);var u=!1;function h(){Vt("cleanup"),e.removeListener("close",d),e.removeListener("finish",p),e.removeListener("drain",s),e.removeListener("error",c),e.removeListener("unpipe",o),r.removeListener("end",a),r.removeListener("end",h),r.removeListener("data",f),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||s()}var l=!1;function f(t){Vt("ondata"),l=!1,!1!==e.write(t)||l||((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==ur(n.pipes,e))&&!u&&(Vt("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,l=!0),r.pause())}function c(t){var r;Vt("onerror",t),g(),e.removeListener("error",c),0===(r="error",e.listeners(r).length)&&e.emit("error",t)}function d(){e.removeListener("finish",p),g()}function p(){Vt("onfinish"),e.removeListener("close",d),g()}function g(){Vt("unpipe"),r.unpipe(e)}return r.on("data",f),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",c),e.once("close",d),e.once("finish",p),e.emit("pipe",r),n.flowing||(Vt("pipe resume"),r.resume()),e},Jt.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this)),this;if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},cr.prototype._write=function(e,t,r){r(new Error("not implemented"))},cr.prototype._writev=null,cr.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!=e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||function(e,t,r){t.ending=!0,mr(e,t),r&&(t.finished?mt(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r)},jt.inherits(Sr,Jt);for(var wr=Object.keys(cr.prototype),_r=0;_r64?t=e(t):t.length<64&&(t=Pr.concat([t,zr],64));for(var r=this._ipad=Pr.allocUnsafe(64),n=this._opad=Pr.allocUnsafe(64),i=0;i<64;i++)r[i]=54^t[i],n[i]=92^t[i];this._hash=[r]}Nr(qr,Dr),qr.prototype._update=function(e){this._hash.push(e)},qr.prototype._final=function(){var e=this._alg(Pr.concat(this._hash));return this._alg(Pr.concat([this._opad,e]))};var Wr=qr,Fr={exports:{}}; /*! safe-buffer. MIT License. Feross Aboukhadijeh */ -!function(e,t){var r=Ne,n=r.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o),o.prototype=Object.create(n.prototype),i(n,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=n(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(Fr,Fr.exports);var Kr={exports:{}},Yr=r(at),Hr=Yr.EventEmitter;function $r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Vr(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Gr(e,t){for(var r=0;r0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r}},{key:"concat",value:function(e){if(0===this.length)return Jr.alloc(0);for(var t,r,n,i=Jr.allocUnsafe(e>>>0),o=this.head,a=0;o;)t=o.data,r=i,n=a,Jr.prototype.copy.call(t,r,n),a+=o.data.length,o=o.next;return i}},{key:"consume",value:function(e,t){var r;return ei.length?i.length:e;if(o===i.length?n+=i:n+=i.slice(0,e),0==(e-=o)){o===i.length?(++r,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++r}return this.length-=r,n}},{key:"_getBuffer",value:function(e){var t=Jr.allocUnsafe(e),r=this.head,n=1;for(r.data.copy(t),e-=r.data.length;r=r.next;){var i=r.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++n,r.next?this.head=r.next:this.head=this.tail=null):(this.head=r,r.data=i.slice(o));break}++n}return this.length-=n,t}},{key:Zr,value:function(e,t){return Xr(this,function(e){for(var t=1;t2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:2===r?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}sn("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),sn("ERR_INVALID_ARG_TYPE",(function(e,t,r){var n,i,o,a;if("string"==typeof t&&(i="not ",t.substr(!o||o<0?0:+o,i.length)===i)?(n="must not be",t=t.replace(/^not /,"")):n="must be",function(e,t,r){return(void 0===r||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}(e," argument"))a="The ".concat(e," ").concat(n," ").concat(un(t,"type"));else{var s=function(e,t,r){return"number"!=typeof r&&(r=0),!(r+t.length>e.length)&&-1!==e.indexOf(t,r)}(e,".")?"property":"argument";a='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(un(t,"type"))}return a+=". Received type ".concat(typeof r)}),TypeError),sn("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),sn("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),sn("ERR_STREAM_PREMATURE_CLOSE","Premature close"),sn("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),sn("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),sn("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),sn("ERR_STREAM_WRITE_AFTER_END","write after end"),sn("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),sn("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),sn("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),on.codes=an;var hn=on.codes.ERR_INVALID_OPT_VALUE;var ln={getHighWaterMark:function(e,t,r,n){var i=function(e,t,r){return null!=e.highWaterMark?e.highWaterMark:t?e[r]:null}(t,n,r);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new hn(n?r:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384}},fn={exports:{}};"function"==typeof Object.create?fn.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:fn.exports=function(e,t){if(t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}};var cn=function(e,t){if(dn("noDeprecation"))return e;var r=!1;return function(){if(!r){if(dn("throwDeprecation"))throw new Error(t);dn("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}};function dn(t){try{if(!e.localStorage)return!1}catch(e){return!1}var r=e.localStorage[t];return null!=r&&"true"===String(r).toLowerCase()}var pn,gn=Cn;function yn(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,r){var n=e.entry;e.entry=null;for(;n;){var i=n.callback;t.pendingcb--,i(r),n=n.next}t.corkedRequestsFree.next=e}(t,e)}}Cn.WritableState=In;var bn={deprecate:cn},mn=Hr,vn=Ne.Buffer,wn=e.Uint8Array||function(){};var _n,En=nn,Sn=ln.getHighWaterMark,kn=on.codes,xn=kn.ERR_INVALID_ARG_TYPE,Rn=kn.ERR_METHOD_NOT_IMPLEMENTED,An=kn.ERR_MULTIPLE_CALLBACK,Tn=kn.ERR_STREAM_CANNOT_PIPE,Bn=kn.ERR_STREAM_DESTROYED,On=kn.ERR_STREAM_NULL_VALUES,Mn=kn.ERR_STREAM_WRITE_AFTER_END,jn=kn.ERR_UNKNOWN_ENCODING,Ln=En.errorOrDestroy;function Un(){}function In(e,t,r){pn=pn||Kn,e=e||{},"boolean"!=typeof r&&(r=t instanceof pn),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=Sn(this,e,"writableHighWaterMark",r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var n=!1===e.decodeStrings;this.decodeStrings=!n,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if("function"!=typeof i)throw new An;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(r),t)!function(e,t,r,n,i){--t.pendingcb,r?(Mt.nextTick(i,n),Mt.nextTick(Wn,e,t),e._writableState.errorEmitted=!0,Ln(e,n)):(i(n),e._writableState.errorEmitted=!0,Ln(e,n),Wn(e,t))}(e,r,n,t,i);else{var o=zn(r)||e.destroyed;o||r.corked||r.bufferProcessing||!r.bufferedRequest||Dn(e,r),n?Mt.nextTick(Pn,e,r,o,i):Pn(e,r,o,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new yn(this)}function Cn(e){var t=this instanceof(pn=pn||Kn);if(!t&&!_n.call(Cn,this))return new Cn(e);this._writableState=new In(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),mn.call(this)}function Nn(e,t,r,n,i,o,a){t.writelen=n,t.writecb=a,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new Bn("write")):r?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function Pn(e,t,r,n){r||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,n(),Wn(e,t)}function Dn(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),o=t.corkedRequestsFree;o.entry=r;for(var a=0,s=!0;r;)i[a]=r,r.isBuf||(s=!1),r=r.next,a+=1;i.allBuffers=s,Nn(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new yn(t),t.bufferedRequestCount=0}else{for(;r;){var u=r.chunk,h=r.encoding,l=r.callback;if(Nn(e,t,!1,t.objectMode?1:u.length,u,h,l),r=r.next,t.bufferedRequestCount--,t.writing)break}null===r&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}function zn(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function qn(e,t){e._final((function(r){t.pendingcb--,r&&Ln(e,r),t.prefinished=!0,e.emit("prefinish"),Wn(e,t)}))}function Wn(e,t){var r=zn(t);if(r&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,Mt.nextTick(qn,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var n=e._readableState;(!n||n.autoDestroy&&n.endEmitted)&&e.destroy()}return r}fn.exports(Cn,mn),In.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(In.prototype,"buffer",{get:bn.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(_n=Function.prototype[Symbol.hasInstance],Object.defineProperty(Cn,Symbol.hasInstance,{value:function(e){return!!_n.call(this,e)||this===Cn&&(e&&e._writableState instanceof In)}})):_n=function(e){return e instanceof this},Cn.prototype.pipe=function(){Ln(this,new Tn)},Cn.prototype.write=function(e,t,r){var n,i=this._writableState,o=!1,a=!i.objectMode&&(n=e,vn.isBuffer(n)||n instanceof wn);return a&&!vn.isBuffer(e)&&(e=function(e){return vn.from(e)}(e)),"function"==typeof t&&(r=t,t=null),a?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof r&&(r=Un),i.ending?function(e,t){var r=new Mn;Ln(e,r),Mt.nextTick(t,r)}(this,r):(a||function(e,t,r,n){var i;return null===r?i=new On:"string"==typeof r||t.objectMode||(i=new xn("chunk",["string","Buffer"],r)),!i||(Ln(e,i),Mt.nextTick(n,i),!1)}(this,i,e,r))&&(i.pendingcb++,o=function(e,t,r,n,i,o){if(!r){var a=function(e,t,r){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=vn.from(t,r));return t}(t,n,i);n!==a&&(r=!0,i="buffer",n=a)}var s=t.objectMode?1:n.length;t.length+=s;var u=t.length-1))throw new jn(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(Cn.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(Cn.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Cn.prototype._write=function(e,t,r){r(new Rn("_write()"))},Cn.prototype._writev=null,Cn.prototype.end=function(e,t,r){var n=this._writableState;return"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!=e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||function(e,t,r){t.ending=!0,Wn(e,t),r&&(t.finished?Mt.nextTick(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r),this},Object.defineProperty(Cn.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(Cn.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),Cn.prototype.destroy=En.destroy,Cn.prototype._undestroy=En.undestroy,Cn.prototype._destroy=function(e,t){t(e)};var Fn=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t},Kn=Jn,Yn=wi,Hn=gn;fn.exports(Jn,Yn);for(var $n=Fn(Hn.prototype),Vn=0;Vn<$n.length;Vn++){var Gn=$n[Vn];Jn.prototype[Gn]||(Jn.prototype[Gn]=Hn.prototype[Gn])}function Jn(e){if(!(this instanceof Jn))return new Jn(e);Yn.call(this,e),Hn.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",Xn)))}function Xn(){this._writableState.ended||Mt.nextTick(Zn,this)}function Zn(e){e.end()}Object.defineProperty(Jn.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(Jn.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(Jn.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(Jn.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}});var Qn=on.codes.ERR_STREAM_PREMATURE_CLOSE;function ei(){}var ti,ri=function e(t,r,n){if("function"==typeof r)return e(t,null,r);r||(r={}),n=function(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i0)if("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===Si.prototype||(t=function(e){return Si.from(e)}(t)),n)a.endEmitted?Pi(e,new Ni):Fi(e,a,t,!0);else if(a.ended)Pi(e,new Ii);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!r?(t=a.decoder.write(t),a.objectMode||0!==t.length?Fi(e,a,t,!1):$i(e,a)):Fi(e,a,t,!1)}else n||(a.reading=!1,$i(e,a));return!a.ended&&(a.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function Yi(e){var t=e._readableState;xi("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(xi("emitReadable",t.flowing),t.emittedReadable=!0,Mt.nextTick(Hi,e))}function Hi(e){var t=e._readableState;xi("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,Zi(e)}function $i(e,t){t.readingMore||(t.readingMore=!0,Mt.nextTick(Vi,e,t))}function Vi(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function Ji(e){xi("readable nexttick read 0"),e.read(0)}function Xi(e,t){xi("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),Zi(e),t.flowing&&!t.reading&&e.read(0)}function Zi(e){var t=e._readableState;for(xi("flow",t.flowing);t.flowing&&null!==e.read(););}function Qi(e,t){return 0===t.length?null:(t.objectMode?r=t.buffer.shift():!e||e>=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):r=t.buffer.consume(e,t.decoder),r);var r}function eo(e){var t=e._readableState;xi("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,Mt.nextTick(to,t,e))}function to(e,t){if(xi("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var r=t._writableState;(!r||r.autoDestroy&&r.finished)&&t.destroy()}}function ro(e,t){for(var r=0,n=e.length;r=t.highWaterMark:t.length>0)||t.ended))return xi("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?eo(this):Yi(this),null;if(0===(e=Ki(e,t))&&t.ended)return 0===t.length&&eo(this),null;var n,i=t.needReadable;return xi("need readable",i),(0===t.length||t.length-e0?Qi(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&eo(this)),null!==n&&this.emit("data",n),n},qi.prototype._read=function(e){Pi(this,new Ci("_read()"))},qi.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e)}n.pipesCount+=1,xi("pipe count=%d opts=%j",n.pipesCount,t);var i=(!t||!1!==t.end)&&e!==Mt.stdout&&e!==Mt.stderr?a:d;function o(t,i){xi("onunpipe"),t===r&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,xi("cleanup"),e.removeListener("close",f),e.removeListener("finish",c),e.removeListener("drain",s),e.removeListener("error",l),e.removeListener("unpipe",o),r.removeListener("end",a),r.removeListener("end",d),r.removeListener("data",h),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||s())}function a(){xi("onend"),e.end()}n.endEmitted?Mt.nextTick(i):r.once("end",i),e.on("unpipe",o);var s=function(e){return function(){var t=e._readableState;xi("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&_i(e,"data")&&(t.flowing=!0,Zi(e))}}(r);e.on("drain",s);var u=!1;function h(t){xi("ondata");var i=e.write(t);xi("dest.write",i),!1===i&&((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==ro(n.pipes,e))&&!u&&(xi("false write response, pause",n.awaitDrain),n.awaitDrain++),r.pause())}function l(t){xi("onerror",t),d(),e.removeListener("error",l),0===_i(e,"error")&&Pi(e,t)}function f(){e.removeListener("finish",c),d()}function c(){xi("onfinish"),e.removeListener("close",f),d()}function d(){xi("unpipe"),r.unpipe(e)}return r.on("data",h),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",l),e.once("close",f),e.once("finish",c),e.emit("pipe",r),n.flowing||(xi("pipe resume"),r.resume()),e},qi.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r)),this;if(!e){var n=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o0,!1!==n.flowing&&this.resume()):"readable"===e&&(n.endEmitted||n.readableListening||(n.readableListening=n.needReadable=!0,n.flowing=!1,n.emittedReadable=!1,xi("on readable",n.length,n.reading),n.length?Yi(this):n.reading||Mt.nextTick(Ji,this))),r},qi.prototype.addListener=qi.prototype.on,qi.prototype.removeListener=function(e,t){var r=Ei.prototype.removeListener.call(this,e,t);return"readable"===e&&Mt.nextTick(Gi,this),r},qi.prototype.removeAllListeners=function(e){var t=Ei.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||Mt.nextTick(Gi,this),t},qi.prototype.resume=function(){var e=this._readableState;return e.flowing||(xi("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,Mt.nextTick(Xi,e,t))}(this,e)),e.paused=!1,this},qi.prototype.pause=function(){return xi("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(xi("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},qi.prototype.wrap=function(e){var t=this,r=this._readableState,n=!1;for(var i in e.on("end",(function(){if(xi("wrapped end"),r.decoder&&!r.ended){var e=r.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(xi("wrapped data"),r.decoder&&(i=r.decoder.write(i)),r.objectMode&&null==i)||(r.objectMode||i&&i.length)&&(t.push(i)||(n=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o0,(function(e){n||(n=e),e&&o.forEach(ko),a||(o.forEach(ko),i(n))}))}));return t.reduce(xo)};!function(e,t){(t=Kr.exports=wi).Stream=t,t.Readable=t,t.Writable=gn,t.Duplex=Kn,t.Transform=no,t.PassThrough=yo,t.finished=ri,t.pipeline=Ao}(0,Kr.exports);var To=Fr.exports.Buffer,Bo=Kr.exports.Transform;function Oo(e){Bo.call(this),this._block=To.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}(0,fn.exports)(Oo,Bo),Oo.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(e){n=e}r(n)},Oo.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},Oo.prototype.update=function(e,t){if(function(e,t){if(!To.isBuffer(e)&&"string"!=typeof e)throw new TypeError(t+" must be a string or a buffer")}(e,"Data"),this._finalized)throw new Error("Digest already called");To.isBuffer(e)||(e=To.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i0;++o)this._length[o]+=a,(a=this._length[o]/4294967296|0)>0&&(this._length[o]-=4294967296*a);return this},Oo.prototype._update=function(){throw new Error("_update is not implemented")},Oo.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t},Oo.prototype._digest=function(){throw new Error("_digest is not implemented")};var Mo=Oo,jo=Ie.exports,Lo=Mo,Uo=Ce.exports.Buffer,Io=new Array(16);function Co(){Lo.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}function No(e,t){return e<>>32-t}function Po(e,t,r,n,i,o,a){return No(e+(t&r|~t&n)+i+o|0,a)+t|0}function Do(e,t,r,n,i,o,a){return No(e+(t&n|r&~n)+i+o|0,a)+t|0}function zo(e,t,r,n,i,o,a){return No(e+(t^r^n)+i+o|0,a)+t|0}function qo(e,t,r,n,i,o,a){return No(e+(r^(t|~n))+i+o|0,a)+t|0}jo(Co,Lo),Co.prototype._update=function(){for(var e=Io,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var r=this._a,n=this._b,i=this._c,o=this._d;r=Po(r,n,i,o,e[0],3614090360,7),o=Po(o,r,n,i,e[1],3905402710,12),i=Po(i,o,r,n,e[2],606105819,17),n=Po(n,i,o,r,e[3],3250441966,22),r=Po(r,n,i,o,e[4],4118548399,7),o=Po(o,r,n,i,e[5],1200080426,12),i=Po(i,o,r,n,e[6],2821735955,17),n=Po(n,i,o,r,e[7],4249261313,22),r=Po(r,n,i,o,e[8],1770035416,7),o=Po(o,r,n,i,e[9],2336552879,12),i=Po(i,o,r,n,e[10],4294925233,17),n=Po(n,i,o,r,e[11],2304563134,22),r=Po(r,n,i,o,e[12],1804603682,7),o=Po(o,r,n,i,e[13],4254626195,12),i=Po(i,o,r,n,e[14],2792965006,17),r=Do(r,n=Po(n,i,o,r,e[15],1236535329,22),i,o,e[1],4129170786,5),o=Do(o,r,n,i,e[6],3225465664,9),i=Do(i,o,r,n,e[11],643717713,14),n=Do(n,i,o,r,e[0],3921069994,20),r=Do(r,n,i,o,e[5],3593408605,5),o=Do(o,r,n,i,e[10],38016083,9),i=Do(i,o,r,n,e[15],3634488961,14),n=Do(n,i,o,r,e[4],3889429448,20),r=Do(r,n,i,o,e[9],568446438,5),o=Do(o,r,n,i,e[14],3275163606,9),i=Do(i,o,r,n,e[3],4107603335,14),n=Do(n,i,o,r,e[8],1163531501,20),r=Do(r,n,i,o,e[13],2850285829,5),o=Do(o,r,n,i,e[2],4243563512,9),i=Do(i,o,r,n,e[7],1735328473,14),r=zo(r,n=Do(n,i,o,r,e[12],2368359562,20),i,o,e[5],4294588738,4),o=zo(o,r,n,i,e[8],2272392833,11),i=zo(i,o,r,n,e[11],1839030562,16),n=zo(n,i,o,r,e[14],4259657740,23),r=zo(r,n,i,o,e[1],2763975236,4),o=zo(o,r,n,i,e[4],1272893353,11),i=zo(i,o,r,n,e[7],4139469664,16),n=zo(n,i,o,r,e[10],3200236656,23),r=zo(r,n,i,o,e[13],681279174,4),o=zo(o,r,n,i,e[0],3936430074,11),i=zo(i,o,r,n,e[3],3572445317,16),n=zo(n,i,o,r,e[6],76029189,23),r=zo(r,n,i,o,e[9],3654602809,4),o=zo(o,r,n,i,e[12],3873151461,11),i=zo(i,o,r,n,e[15],530742520,16),r=qo(r,n=zo(n,i,o,r,e[2],3299628645,23),i,o,e[0],4096336452,6),o=qo(o,r,n,i,e[7],1126891415,10),i=qo(i,o,r,n,e[14],2878612391,15),n=qo(n,i,o,r,e[5],4237533241,21),r=qo(r,n,i,o,e[12],1700485571,6),o=qo(o,r,n,i,e[3],2399980690,10),i=qo(i,o,r,n,e[10],4293915773,15),n=qo(n,i,o,r,e[1],2240044497,21),r=qo(r,n,i,o,e[8],1873313359,6),o=qo(o,r,n,i,e[15],4264355552,10),i=qo(i,o,r,n,e[6],2734768916,15),n=qo(n,i,o,r,e[13],1309151649,21),r=qo(r,n,i,o,e[4],4149444226,6),o=qo(o,r,n,i,e[11],3174756917,10),i=qo(i,o,r,n,e[2],718787259,15),n=qo(n,i,o,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+o|0},Co.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Uo.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};var Wo=Co,Fo=Ne.Buffer,Ko=Ie.exports,Yo=Mo,Ho=new Array(16),$o=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],Vo=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Go=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],Jo=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],Xo=[0,1518500249,1859775393,2400959708,2840853838],Zo=[1352829926,1548603684,1836072691,2053994217,0];function Qo(){Yo.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function ea(e,t){return e<>>32-t}function ta(e,t,r,n,i,o,a,s){return ea(e+(t^r^n)+o+a|0,s)+i|0}function ra(e,t,r,n,i,o,a,s){return ea(e+(t&r|~t&n)+o+a|0,s)+i|0}function na(e,t,r,n,i,o,a,s){return ea(e+((t|~r)^n)+o+a|0,s)+i|0}function ia(e,t,r,n,i,o,a,s){return ea(e+(t&n|r&~n)+o+a|0,s)+i|0}function oa(e,t,r,n,i,o,a,s){return ea(e+(t^(r|~n))+o+a|0,s)+i|0}Ko(Qo,Yo),Qo.prototype._update=function(){for(var e=Ho,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);for(var r=0|this._a,n=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._a,u=0|this._b,h=0|this._c,l=0|this._d,f=0|this._e,c=0;c<80;c+=1){var d,p;c<16?(d=ta(r,n,i,o,a,e[$o[c]],Xo[0],Go[c]),p=oa(s,u,h,l,f,e[Vo[c]],Zo[0],Jo[c])):c<32?(d=ra(r,n,i,o,a,e[$o[c]],Xo[1],Go[c]),p=ia(s,u,h,l,f,e[Vo[c]],Zo[1],Jo[c])):c<48?(d=na(r,n,i,o,a,e[$o[c]],Xo[2],Go[c]),p=na(s,u,h,l,f,e[Vo[c]],Zo[2],Jo[c])):c<64?(d=ia(r,n,i,o,a,e[$o[c]],Xo[3],Go[c]),p=ra(s,u,h,l,f,e[Vo[c]],Zo[3],Jo[c])):(d=oa(r,n,i,o,a,e[$o[c]],Xo[4],Go[c]),p=ta(s,u,h,l,f,e[Vo[c]],Zo[4],Jo[c])),r=a,a=o,o=ea(i,10),i=n,n=d,s=f,f=l,l=ea(h,10),h=u,u=p}var g=this._b+i+l|0;this._b=this._c+o+f|0,this._c=this._d+a+s|0,this._d=this._e+r+u|0,this._e=this._a+n+h|0,this._a=g},Qo.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Fo.alloc?Fo.alloc(20):new Fo(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};var aa=Qo,sa={exports:{}},ua=Ce.exports.Buffer;function ha(e,t){this._block=ua.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}ha.prototype.update=function(e,t){"string"==typeof e&&(t=t||"utf8",e=ua.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,a=0;a=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=8*this._len;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(4294967295&r)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},ha.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var la=ha,fa=Ie.exports,ca=la,da=Ce.exports.Buffer,pa=[1518500249,1859775393,-1894007588,-899497514],ga=new Array(80);function ya(){this.init(),this._w=ga,ca.call(this,64,56)}function ba(e){return e<<30|e>>>2}function ma(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}fa(ya,ca),ya.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},ya.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=r[u-3]^r[u-8]^r[u-14]^r[u-16];for(var h=0;h<80;++h){var l=~~(h/20),f=0|((t=n)<<5|t>>>27)+ma(l,i,o,a)+s+r[h]+pa[l];s=a,a=o,o=ba(i),i=n,n=f}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},ya.prototype._hash=function(){var e=da.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var va=ya,wa=Ie.exports,_a=la,Ea=Ce.exports.Buffer,Sa=[1518500249,1859775393,-1894007588,-899497514],ka=new Array(80);function xa(){this.init(),this._w=ka,_a.call(this,64,56)}function Ra(e){return e<<5|e>>>27}function Aa(e){return e<<30|e>>>2}function Ta(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}wa(xa,_a),xa.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},xa.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=(t=r[u-3]^r[u-8]^r[u-14]^r[u-16])<<1|t>>>31;for(var h=0;h<80;++h){var l=~~(h/20),f=Ra(n)+Ta(l,i,o,a)+s+r[h]+Sa[l]|0;s=a,a=o,o=Aa(i),i=n,n=f}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},xa.prototype._hash=function(){var e=Ea.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var Ba=xa,Oa=Ie.exports,Ma=la,ja=Ce.exports.Buffer,La=[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],Ua=new Array(64);function Ia(){this.init(),this._w=Ua,Ma.call(this,64,56)}function Ca(e,t,r){return r^e&(t^r)}function Na(e,t,r){return e&t|r&(e|t)}function Pa(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function Da(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function za(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}Oa(Ia,Ma),Ia.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},Ia.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0|this._f,h=0|this._g,l=0|this._h,f=0;f<16;++f)r[f]=e.readInt32BE(4*f);for(;f<64;++f)r[f]=0|(((t=r[f-2])>>>17|t<<15)^(t>>>19|t<<13)^t>>>10)+r[f-7]+za(r[f-15])+r[f-16];for(var c=0;c<64;++c){var d=l+Da(s)+Ca(s,u,h)+La[c]+r[c]|0,p=Pa(n)+Na(n,i,o)|0;l=h,h=u,u=s,s=a+d|0,a=o,o=i,i=n,n=d+p|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0,this._f=u+this._f|0,this._g=h+this._g|0,this._h=l+this._h|0},Ia.prototype._hash=function(){var e=ja.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var qa=Ia,Wa=Ie.exports,Fa=qa,Ka=la,Ya=Ce.exports.Buffer,Ha=new Array(64);function $a(){this.init(),this._w=Ha,Ka.call(this,64,56)}Wa($a,Fa),$a.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},$a.prototype._hash=function(){var e=Ya.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var Va=$a,Ga=Ie.exports,Ja=la,Xa=Ce.exports.Buffer,Za=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],Qa=new Array(160);function es(){this.init(),this._w=Qa,Ja.call(this,128,112)}function ts(e,t,r){return r^e&(t^r)}function rs(e,t,r){return e&t|r&(e|t)}function ns(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function is(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function os(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function as(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function ss(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function us(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function hs(e,t){return e>>>0>>0?1:0}Ga(es,Ja),es.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},es.prototype._update=function(e){for(var t=this._w,r=0|this._ah,n=0|this._bh,i=0|this._ch,o=0|this._dh,a=0|this._eh,s=0|this._fh,u=0|this._gh,h=0|this._hh,l=0|this._al,f=0|this._bl,c=0|this._cl,d=0|this._dl,p=0|this._el,g=0|this._fl,y=0|this._gl,b=0|this._hl,m=0;m<32;m+=2)t[m]=e.readInt32BE(4*m),t[m+1]=e.readInt32BE(4*m+4);for(;m<160;m+=2){var v=t[m-30],w=t[m-30+1],_=os(v,w),E=as(w,v),S=ss(v=t[m-4],w=t[m-4+1]),k=us(w,v),x=t[m-14],R=t[m-14+1],A=t[m-32],T=t[m-32+1],B=E+R|0,O=_+x+hs(B,E)|0;O=(O=O+S+hs(B=B+k|0,k)|0)+A+hs(B=B+T|0,T)|0,t[m]=O,t[m+1]=B}for(var M=0;M<160;M+=2){O=t[M],B=t[M+1];var j=rs(r,n,i),L=rs(l,f,c),U=ns(r,l),I=ns(l,r),C=is(a,p),N=is(p,a),P=Za[M],D=Za[M+1],z=ts(a,s,u),q=ts(p,g,y),W=b+N|0,F=h+C+hs(W,b)|0;F=(F=(F=F+z+hs(W=W+q|0,q)|0)+P+hs(W=W+D|0,D)|0)+O+hs(W=W+B|0,B)|0;var K=I+L|0,Y=U+j+hs(K,I)|0;h=u,b=y,u=s,y=g,s=a,g=p,a=o+F+hs(p=d+W|0,d)|0,o=i,d=c,i=n,c=f,n=r,f=l,r=F+Y+hs(l=W+K|0,W)|0}this._al=this._al+l|0,this._bl=this._bl+f|0,this._cl=this._cl+c|0,this._dl=this._dl+d|0,this._el=this._el+p|0,this._fl=this._fl+g|0,this._gl=this._gl+y|0,this._hl=this._hl+b|0,this._ah=this._ah+r+hs(this._al,l)|0,this._bh=this._bh+n+hs(this._bl,f)|0,this._ch=this._ch+i+hs(this._cl,c)|0,this._dh=this._dh+o+hs(this._dl,d)|0,this._eh=this._eh+a+hs(this._el,p)|0,this._fh=this._fh+s+hs(this._fl,g)|0,this._gh=this._gh+u+hs(this._gl,y)|0,this._hh=this._hh+h+hs(this._hl,b)|0},es.prototype._hash=function(){var e=Xa.allocUnsafe(64);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var ls=es,fs=Ie.exports,cs=ls,ds=la,ps=Ce.exports.Buffer,gs=new Array(160);function ys(){this.init(),this._w=gs,ds.call(this,128,112)}fs(ys,cs),ys.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},ys.prototype._hash=function(){var e=ps.allocUnsafe(48);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var bs=ys,ms=sa.exports=function(e){e=e.toLowerCase();var t=ms[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t};ms.sha=va,ms.sha1=Ba,ms.sha224=Va,ms.sha256=qa,ms.sha384=bs,ms.sha512=ls;var vs=Ie.exports,ws=Wr,_s=Cr,Es=Ce.exports.Buffer,Ss=function(e){return(new Wo).update(e).digest()},ks=aa,xs=sa.exports,Rs=Es.alloc(128);function As(e,t){_s.call(this,"digest"),"string"==typeof t&&(t=Es.from(t));var r="sha512"===e||"sha384"===e?128:64;(this._alg=e,this._key=t,t.length>r)?t=("rmd160"===e?new ks:xs(e)).update(t).digest():t.length>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r,e[t+4]=n>>24&255,e[t+5]=n>>16&255,e[t+6]=n>>8&255,e[t+7]=255&n}function p(e,t,r,n,i){var o,a=0;for(o=0;o>>8)-1}function g(e,t,r,n){return p(e,t,r,n,16)}function y(e,t,r,n){return p(e,t,r,n,32)}function b(e,t,r,n){!function(e,t,r,n){for(var i,o=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,h=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,c=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,d=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,g=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,y=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,b=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,m=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,v=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,w=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,_=o,E=a,S=s,k=u,x=h,R=l,A=f,T=c,B=d,O=p,M=g,j=y,L=b,U=m,I=v,C=w,N=0;N<20;N+=2)_^=(i=(L^=(i=(B^=(i=(x^=(i=_+L|0)<<7|i>>>25)+_|0)<<9|i>>>23)+x|0)<<13|i>>>19)+B|0)<<18|i>>>14,R^=(i=(E^=(i=(U^=(i=(O^=(i=R+E|0)<<7|i>>>25)+R|0)<<9|i>>>23)+O|0)<<13|i>>>19)+U|0)<<18|i>>>14,M^=(i=(A^=(i=(S^=(i=(I^=(i=M+A|0)<<7|i>>>25)+M|0)<<9|i>>>23)+I|0)<<13|i>>>19)+S|0)<<18|i>>>14,C^=(i=(j^=(i=(T^=(i=(k^=(i=C+j|0)<<7|i>>>25)+C|0)<<9|i>>>23)+k|0)<<13|i>>>19)+T|0)<<18|i>>>14,_^=(i=(k^=(i=(S^=(i=(E^=(i=_+k|0)<<7|i>>>25)+_|0)<<9|i>>>23)+E|0)<<13|i>>>19)+S|0)<<18|i>>>14,R^=(i=(x^=(i=(T^=(i=(A^=(i=R+x|0)<<7|i>>>25)+R|0)<<9|i>>>23)+A|0)<<13|i>>>19)+T|0)<<18|i>>>14,M^=(i=(O^=(i=(B^=(i=(j^=(i=M+O|0)<<7|i>>>25)+M|0)<<9|i>>>23)+j|0)<<13|i>>>19)+B|0)<<18|i>>>14,C^=(i=(I^=(i=(U^=(i=(L^=(i=C+I|0)<<7|i>>>25)+C|0)<<9|i>>>23)+L|0)<<13|i>>>19)+U|0)<<18|i>>>14;_=_+o|0,E=E+a|0,S=S+s|0,k=k+u|0,x=x+h|0,R=R+l|0,A=A+f|0,T=T+c|0,B=B+d|0,O=O+p|0,M=M+g|0,j=j+y|0,L=L+b|0,U=U+m|0,I=I+v|0,C=C+w|0,e[0]=_>>>0&255,e[1]=_>>>8&255,e[2]=_>>>16&255,e[3]=_>>>24&255,e[4]=E>>>0&255,e[5]=E>>>8&255,e[6]=E>>>16&255,e[7]=E>>>24&255,e[8]=S>>>0&255,e[9]=S>>>8&255,e[10]=S>>>16&255,e[11]=S>>>24&255,e[12]=k>>>0&255,e[13]=k>>>8&255,e[14]=k>>>16&255,e[15]=k>>>24&255,e[16]=x>>>0&255,e[17]=x>>>8&255,e[18]=x>>>16&255,e[19]=x>>>24&255,e[20]=R>>>0&255,e[21]=R>>>8&255,e[22]=R>>>16&255,e[23]=R>>>24&255,e[24]=A>>>0&255,e[25]=A>>>8&255,e[26]=A>>>16&255,e[27]=A>>>24&255,e[28]=T>>>0&255,e[29]=T>>>8&255,e[30]=T>>>16&255,e[31]=T>>>24&255,e[32]=B>>>0&255,e[33]=B>>>8&255,e[34]=B>>>16&255,e[35]=B>>>24&255,e[36]=O>>>0&255,e[37]=O>>>8&255,e[38]=O>>>16&255,e[39]=O>>>24&255,e[40]=M>>>0&255,e[41]=M>>>8&255,e[42]=M>>>16&255,e[43]=M>>>24&255,e[44]=j>>>0&255,e[45]=j>>>8&255,e[46]=j>>>16&255,e[47]=j>>>24&255,e[48]=L>>>0&255,e[49]=L>>>8&255,e[50]=L>>>16&255,e[51]=L>>>24&255,e[52]=U>>>0&255,e[53]=U>>>8&255,e[54]=U>>>16&255,e[55]=U>>>24&255,e[56]=I>>>0&255,e[57]=I>>>8&255,e[58]=I>>>16&255,e[59]=I>>>24&255,e[60]=C>>>0&255,e[61]=C>>>8&255,e[62]=C>>>16&255,e[63]=C>>>24&255}(e,t,r,n)}function m(e,t,r,n){!function(e,t,r,n){for(var i,o=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,h=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,c=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,d=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,g=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,y=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,b=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,m=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,v=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,w=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,_=0;_<20;_+=2)o^=(i=(b^=(i=(d^=(i=(h^=(i=o+b|0)<<7|i>>>25)+o|0)<<9|i>>>23)+h|0)<<13|i>>>19)+d|0)<<18|i>>>14,l^=(i=(a^=(i=(m^=(i=(p^=(i=l+a|0)<<7|i>>>25)+l|0)<<9|i>>>23)+p|0)<<13|i>>>19)+m|0)<<18|i>>>14,g^=(i=(f^=(i=(s^=(i=(v^=(i=g+f|0)<<7|i>>>25)+g|0)<<9|i>>>23)+v|0)<<13|i>>>19)+s|0)<<18|i>>>14,w^=(i=(y^=(i=(c^=(i=(u^=(i=w+y|0)<<7|i>>>25)+w|0)<<9|i>>>23)+u|0)<<13|i>>>19)+c|0)<<18|i>>>14,o^=(i=(u^=(i=(s^=(i=(a^=(i=o+u|0)<<7|i>>>25)+o|0)<<9|i>>>23)+a|0)<<13|i>>>19)+s|0)<<18|i>>>14,l^=(i=(h^=(i=(c^=(i=(f^=(i=l+h|0)<<7|i>>>25)+l|0)<<9|i>>>23)+f|0)<<13|i>>>19)+c|0)<<18|i>>>14,g^=(i=(p^=(i=(d^=(i=(y^=(i=g+p|0)<<7|i>>>25)+g|0)<<9|i>>>23)+y|0)<<13|i>>>19)+d|0)<<18|i>>>14,w^=(i=(v^=(i=(m^=(i=(b^=(i=w+v|0)<<7|i>>>25)+w|0)<<9|i>>>23)+b|0)<<13|i>>>19)+m|0)<<18|i>>>14;e[0]=o>>>0&255,e[1]=o>>>8&255,e[2]=o>>>16&255,e[3]=o>>>24&255,e[4]=l>>>0&255,e[5]=l>>>8&255,e[6]=l>>>16&255,e[7]=l>>>24&255,e[8]=g>>>0&255,e[9]=g>>>8&255,e[10]=g>>>16&255,e[11]=g>>>24&255,e[12]=w>>>0&255,e[13]=w>>>8&255,e[14]=w>>>16&255,e[15]=w>>>24&255,e[16]=f>>>0&255,e[17]=f>>>8&255,e[18]=f>>>16&255,e[19]=f>>>24&255,e[20]=c>>>0&255,e[21]=c>>>8&255,e[22]=c>>>16&255,e[23]=c>>>24&255,e[24]=d>>>0&255,e[25]=d>>>8&255,e[26]=d>>>16&255,e[27]=d>>>24&255,e[28]=p>>>0&255,e[29]=p>>>8&255,e[30]=p>>>16&255,e[31]=p>>>24&255}(e,t,r,n)}var v=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(e,t,r,n,i,o,a){var s,u,h=new Uint8Array(16),l=new Uint8Array(64);for(u=0;u<16;u++)h[u]=0;for(u=0;u<8;u++)h[u]=o[u];for(;i>=64;){for(b(l,h,a,v),u=0;u<64;u++)e[t+u]=r[n+u]^l[u];for(s=1,u=8;u<16;u++)s=s+(255&h[u])|0,h[u]=255&s,s>>>=8;i-=64,t+=64,n+=64}if(i>0)for(b(l,h,a,v),u=0;u=64;){for(b(u,s,i,v),a=0;a<64;a++)e[t+a]=u[a];for(o=1,a=8;a<16;a++)o=o+(255&s[a])|0,s[a]=255&o,o>>>=8;r-=64,t+=64}if(r>0)for(b(u,s,i,v),a=0;a>>13|r<<3),n=255&e[4]|(255&e[5])<<8,this.r[2]=7939&(r>>>10|n<<6),i=255&e[6]|(255&e[7])<<8,this.r[3]=8191&(n>>>7|i<<9),o=255&e[8]|(255&e[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,a=255&e[10]|(255&e[11])<<8,this.r[6]=8191&(o>>>14|a<<2),s=255&e[12]|(255&e[13])<<8,this.r[7]=8065&(a>>>11|s<<5),u=255&e[14]|(255&e[15])<<8,this.r[8]=8191&(s>>>8|u<<8),this.r[9]=u>>>5&127,this.pad[0]=255&e[16]|(255&e[17])<<8,this.pad[1]=255&e[18]|(255&e[19])<<8,this.pad[2]=255&e[20]|(255&e[21])<<8,this.pad[3]=255&e[22]|(255&e[23])<<8,this.pad[4]=255&e[24]|(255&e[25])<<8,this.pad[5]=255&e[26]|(255&e[27])<<8,this.pad[6]=255&e[28]|(255&e[29])<<8,this.pad[7]=255&e[30]|(255&e[31])<<8};function x(e,t,r,n,i,o){var a=new k(o);return a.update(r,n,i),a.finish(e,t),0}function R(e,t,r,n,i,o){var a=new Uint8Array(16);return x(a,0,r,n,i,o),g(e,t,a,0)}function A(e,t,r,n,i){var o;if(r<32)return-1;for(S(e,0,t,0,r,n,i),x(e,16,e,32,r-32,e),o=0;o<16;o++)e[o]=0;return 0}function T(e,t,r,n,i){var o,a=new Uint8Array(32);if(r<32)return-1;if(E(a,0,32,n,i),0!==R(t,16,t,32,r-32,a))return-1;for(S(e,0,t,0,r,n,i),o=0;o<32;o++)e[o]=0;return 0}function B(e,t){var r;for(r=0;r<16;r++)e[r]=0|t[r]}function O(e){var t,r,n=1;for(t=0;t<16;t++)r=e[t]+n+65535,n=Math.floor(r/65536),e[t]=r-65536*n;e[0]+=n-1+37*(n-1)}function M(e,t,r){for(var n,i=~(r-1),o=0;o<16;o++)n=i&(e[o]^t[o]),e[o]^=n,t[o]^=n}function j(e,r){var n,i,o,a=t(),s=t();for(n=0;n<16;n++)s[n]=r[n];for(O(s),O(s),O(s),i=0;i<2;i++){for(a[0]=s[0]-65517,n=1;n<15;n++)a[n]=s[n]-65535-(a[n-1]>>16&1),a[n-1]&=65535;a[15]=s[15]-32767-(a[14]>>16&1),o=a[15]>>16&1,a[14]&=65535,M(s,a,1-o)}for(n=0;n<16;n++)e[2*n]=255&s[n],e[2*n+1]=s[n]>>8}function L(e,t){var r=new Uint8Array(32),n=new Uint8Array(32);return j(r,e),j(n,t),y(r,0,n,0)}function I(e){var t=new Uint8Array(32);return j(t,e),1&t[0]}function C(e,t){var r;for(r=0;r<16;r++)e[r]=t[2*r]+(t[2*r+1]<<8);e[15]&=32767}function N(e,t,r){for(var n=0;n<16;n++)e[n]=t[n]+r[n]}function P(e,t,r){for(var n=0;n<16;n++)e[n]=t[n]-r[n]}function D(e,t,r){var n,i,o=0,a=0,s=0,u=0,h=0,l=0,f=0,c=0,d=0,p=0,g=0,y=0,b=0,m=0,v=0,w=0,_=0,E=0,S=0,k=0,x=0,R=0,A=0,T=0,B=0,O=0,M=0,j=0,L=0,U=0,I=0,C=r[0],N=r[1],P=r[2],D=r[3],z=r[4],q=r[5],W=r[6],F=r[7],K=r[8],Y=r[9],H=r[10],$=r[11],V=r[12],G=r[13],J=r[14],X=r[15];o+=(n=t[0])*C,a+=n*N,s+=n*P,u+=n*D,h+=n*z,l+=n*q,f+=n*W,c+=n*F,d+=n*K,p+=n*Y,g+=n*H,y+=n*$,b+=n*V,m+=n*G,v+=n*J,w+=n*X,a+=(n=t[1])*C,s+=n*N,u+=n*P,h+=n*D,l+=n*z,f+=n*q,c+=n*W,d+=n*F,p+=n*K,g+=n*Y,y+=n*H,b+=n*$,m+=n*V,v+=n*G,w+=n*J,_+=n*X,s+=(n=t[2])*C,u+=n*N,h+=n*P,l+=n*D,f+=n*z,c+=n*q,d+=n*W,p+=n*F,g+=n*K,y+=n*Y,b+=n*H,m+=n*$,v+=n*V,w+=n*G,_+=n*J,E+=n*X,u+=(n=t[3])*C,h+=n*N,l+=n*P,f+=n*D,c+=n*z,d+=n*q,p+=n*W,g+=n*F,y+=n*K,b+=n*Y,m+=n*H,v+=n*$,w+=n*V,_+=n*G,E+=n*J,S+=n*X,h+=(n=t[4])*C,l+=n*N,f+=n*P,c+=n*D,d+=n*z,p+=n*q,g+=n*W,y+=n*F,b+=n*K,m+=n*Y,v+=n*H,w+=n*$,_+=n*V,E+=n*G,S+=n*J,k+=n*X,l+=(n=t[5])*C,f+=n*N,c+=n*P,d+=n*D,p+=n*z,g+=n*q,y+=n*W,b+=n*F,m+=n*K,v+=n*Y,w+=n*H,_+=n*$,E+=n*V,S+=n*G,k+=n*J,x+=n*X,f+=(n=t[6])*C,c+=n*N,d+=n*P,p+=n*D,g+=n*z,y+=n*q,b+=n*W,m+=n*F,v+=n*K,w+=n*Y,_+=n*H,E+=n*$,S+=n*V,k+=n*G,x+=n*J,R+=n*X,c+=(n=t[7])*C,d+=n*N,p+=n*P,g+=n*D,y+=n*z,b+=n*q,m+=n*W,v+=n*F,w+=n*K,_+=n*Y,E+=n*H,S+=n*$,k+=n*V,x+=n*G,R+=n*J,A+=n*X,d+=(n=t[8])*C,p+=n*N,g+=n*P,y+=n*D,b+=n*z,m+=n*q,v+=n*W,w+=n*F,_+=n*K,E+=n*Y,S+=n*H,k+=n*$,x+=n*V,R+=n*G,A+=n*J,T+=n*X,p+=(n=t[9])*C,g+=n*N,y+=n*P,b+=n*D,m+=n*z,v+=n*q,w+=n*W,_+=n*F,E+=n*K,S+=n*Y,k+=n*H,x+=n*$,R+=n*V,A+=n*G,T+=n*J,B+=n*X,g+=(n=t[10])*C,y+=n*N,b+=n*P,m+=n*D,v+=n*z,w+=n*q,_+=n*W,E+=n*F,S+=n*K,k+=n*Y,x+=n*H,R+=n*$,A+=n*V,T+=n*G,B+=n*J,O+=n*X,y+=(n=t[11])*C,b+=n*N,m+=n*P,v+=n*D,w+=n*z,_+=n*q,E+=n*W,S+=n*F,k+=n*K,x+=n*Y,R+=n*H,A+=n*$,T+=n*V,B+=n*G,O+=n*J,M+=n*X,b+=(n=t[12])*C,m+=n*N,v+=n*P,w+=n*D,_+=n*z,E+=n*q,S+=n*W,k+=n*F,x+=n*K,R+=n*Y,A+=n*H,T+=n*$,B+=n*V,O+=n*G,M+=n*J,j+=n*X,m+=(n=t[13])*C,v+=n*N,w+=n*P,_+=n*D,E+=n*z,S+=n*q,k+=n*W,x+=n*F,R+=n*K,A+=n*Y,T+=n*H,B+=n*$,O+=n*V,M+=n*G,j+=n*J,L+=n*X,v+=(n=t[14])*C,w+=n*N,_+=n*P,E+=n*D,S+=n*z,k+=n*q,x+=n*W,R+=n*F,A+=n*K,T+=n*Y,B+=n*H,O+=n*$,M+=n*V,j+=n*G,L+=n*J,U+=n*X,w+=(n=t[15])*C,a+=38*(E+=n*P),s+=38*(S+=n*D),u+=38*(k+=n*z),h+=38*(x+=n*q),l+=38*(R+=n*W),f+=38*(A+=n*F),c+=38*(T+=n*K),d+=38*(B+=n*Y),p+=38*(O+=n*H),g+=38*(M+=n*$),y+=38*(j+=n*V),b+=38*(L+=n*G),m+=38*(U+=n*J),v+=38*(I+=n*X),o=(n=(o+=38*(_+=n*N))+(i=1)+65535)-65536*(i=Math.floor(n/65536)),a=(n=a+i+65535)-65536*(i=Math.floor(n/65536)),s=(n=s+i+65535)-65536*(i=Math.floor(n/65536)),u=(n=u+i+65535)-65536*(i=Math.floor(n/65536)),h=(n=h+i+65535)-65536*(i=Math.floor(n/65536)),l=(n=l+i+65535)-65536*(i=Math.floor(n/65536)),f=(n=f+i+65535)-65536*(i=Math.floor(n/65536)),c=(n=c+i+65535)-65536*(i=Math.floor(n/65536)),d=(n=d+i+65535)-65536*(i=Math.floor(n/65536)),p=(n=p+i+65535)-65536*(i=Math.floor(n/65536)),g=(n=g+i+65535)-65536*(i=Math.floor(n/65536)),y=(n=y+i+65535)-65536*(i=Math.floor(n/65536)),b=(n=b+i+65535)-65536*(i=Math.floor(n/65536)),m=(n=m+i+65535)-65536*(i=Math.floor(n/65536)),v=(n=v+i+65535)-65536*(i=Math.floor(n/65536)),w=(n=w+i+65535)-65536*(i=Math.floor(n/65536)),o=(n=(o+=i-1+37*(i-1))+(i=1)+65535)-65536*(i=Math.floor(n/65536)),a=(n=a+i+65535)-65536*(i=Math.floor(n/65536)),s=(n=s+i+65535)-65536*(i=Math.floor(n/65536)),u=(n=u+i+65535)-65536*(i=Math.floor(n/65536)),h=(n=h+i+65535)-65536*(i=Math.floor(n/65536)),l=(n=l+i+65535)-65536*(i=Math.floor(n/65536)),f=(n=f+i+65535)-65536*(i=Math.floor(n/65536)),c=(n=c+i+65535)-65536*(i=Math.floor(n/65536)),d=(n=d+i+65535)-65536*(i=Math.floor(n/65536)),p=(n=p+i+65535)-65536*(i=Math.floor(n/65536)),g=(n=g+i+65535)-65536*(i=Math.floor(n/65536)),y=(n=y+i+65535)-65536*(i=Math.floor(n/65536)),b=(n=b+i+65535)-65536*(i=Math.floor(n/65536)),m=(n=m+i+65535)-65536*(i=Math.floor(n/65536)),v=(n=v+i+65535)-65536*(i=Math.floor(n/65536)),w=(n=w+i+65535)-65536*(i=Math.floor(n/65536)),o+=i-1+37*(i-1),e[0]=o,e[1]=a,e[2]=s,e[3]=u,e[4]=h,e[5]=l,e[6]=f,e[7]=c,e[8]=d,e[9]=p,e[10]=g,e[11]=y,e[12]=b,e[13]=m,e[14]=v,e[15]=w}function z(e,t){D(e,t,t)}function q(e,r){var n,i=t();for(n=0;n<16;n++)i[n]=r[n];for(n=253;n>=0;n--)z(i,i),2!==n&&4!==n&&D(i,i,r);for(n=0;n<16;n++)e[n]=i[n]}function W(e,r){var n,i=t();for(n=0;n<16;n++)i[n]=r[n];for(n=250;n>=0;n--)z(i,i),1!==n&&D(i,i,r);for(n=0;n<16;n++)e[n]=i[n]}function F(e,r,n){var i,o,a=new Uint8Array(32),u=new Float64Array(80),h=t(),l=t(),f=t(),c=t(),d=t(),p=t();for(o=0;o<31;o++)a[o]=r[o];for(a[31]=127&r[31]|64,a[0]&=248,C(u,n),o=0;o<16;o++)l[o]=u[o],c[o]=h[o]=f[o]=0;for(h[0]=c[0]=1,o=254;o>=0;--o)M(h,l,i=a[o>>>3]>>>(7&o)&1),M(f,c,i),N(d,h,f),P(h,h,f),N(f,l,c),P(l,l,c),z(c,d),z(p,h),D(h,f,h),D(f,l,d),N(d,h,f),P(h,h,f),z(l,h),P(f,c,p),D(h,f,s),N(h,h,c),D(f,f,h),D(h,c,p),D(c,l,u),z(l,d),M(h,l,i),M(f,c,i);for(o=0;o<16;o++)u[o+16]=h[o],u[o+32]=f[o],u[o+48]=l[o],u[o+64]=c[o];var g=u.subarray(32),y=u.subarray(16);return q(g,g),D(y,y,g),j(e,y),0}function K(e,t){return F(e,t,i)}function Y(e,t){return r(t,32),K(e,t)}function H(e,t,r){var i=new Uint8Array(32);return F(i,r,t),m(e,n,i,v)}k.prototype.blocks=function(e,t,r){for(var n,i,o,a,s,u,h,l,f,c,d,p,g,y,b,m,v,w,_,E=this.fin?0:2048,S=this.h[0],k=this.h[1],x=this.h[2],R=this.h[3],A=this.h[4],T=this.h[5],B=this.h[6],O=this.h[7],M=this.h[8],j=this.h[9],L=this.r[0],U=this.r[1],I=this.r[2],C=this.r[3],N=this.r[4],P=this.r[5],D=this.r[6],z=this.r[7],q=this.r[8],W=this.r[9];r>=16;)c=f=0,c+=(S+=8191&(n=255&e[t+0]|(255&e[t+1])<<8))*L,c+=(k+=8191&(n>>>13|(i=255&e[t+2]|(255&e[t+3])<<8)<<3))*(5*W),c+=(x+=8191&(i>>>10|(o=255&e[t+4]|(255&e[t+5])<<8)<<6))*(5*q),c+=(R+=8191&(o>>>7|(a=255&e[t+6]|(255&e[t+7])<<8)<<9))*(5*z),f=(c+=(A+=8191&(a>>>4|(s=255&e[t+8]|(255&e[t+9])<<8)<<12))*(5*D))>>>13,c&=8191,c+=(T+=s>>>1&8191)*(5*P),c+=(B+=8191&(s>>>14|(u=255&e[t+10]|(255&e[t+11])<<8)<<2))*(5*N),c+=(O+=8191&(u>>>11|(h=255&e[t+12]|(255&e[t+13])<<8)<<5))*(5*C),c+=(M+=8191&(h>>>8|(l=255&e[t+14]|(255&e[t+15])<<8)<<8))*(5*I),d=f+=(c+=(j+=l>>>5|E)*(5*U))>>>13,d+=S*U,d+=k*L,d+=x*(5*W),d+=R*(5*q),f=(d+=A*(5*z))>>>13,d&=8191,d+=T*(5*D),d+=B*(5*P),d+=O*(5*N),d+=M*(5*C),f+=(d+=j*(5*I))>>>13,d&=8191,p=f,p+=S*I,p+=k*U,p+=x*L,p+=R*(5*W),f=(p+=A*(5*q))>>>13,p&=8191,p+=T*(5*z),p+=B*(5*D),p+=O*(5*P),p+=M*(5*N),g=f+=(p+=j*(5*C))>>>13,g+=S*C,g+=k*I,g+=x*U,g+=R*L,f=(g+=A*(5*W))>>>13,g&=8191,g+=T*(5*q),g+=B*(5*z),g+=O*(5*D),g+=M*(5*P),y=f+=(g+=j*(5*N))>>>13,y+=S*N,y+=k*C,y+=x*I,y+=R*U,f=(y+=A*L)>>>13,y&=8191,y+=T*(5*W),y+=B*(5*q),y+=O*(5*z),y+=M*(5*D),b=f+=(y+=j*(5*P))>>>13,b+=S*P,b+=k*N,b+=x*C,b+=R*I,f=(b+=A*U)>>>13,b&=8191,b+=T*L,b+=B*(5*W),b+=O*(5*q),b+=M*(5*z),m=f+=(b+=j*(5*D))>>>13,m+=S*D,m+=k*P,m+=x*N,m+=R*C,f=(m+=A*I)>>>13,m&=8191,m+=T*U,m+=B*L,m+=O*(5*W),m+=M*(5*q),v=f+=(m+=j*(5*z))>>>13,v+=S*z,v+=k*D,v+=x*P,v+=R*N,f=(v+=A*C)>>>13,v&=8191,v+=T*I,v+=B*U,v+=O*L,v+=M*(5*W),w=f+=(v+=j*(5*q))>>>13,w+=S*q,w+=k*z,w+=x*D,w+=R*P,f=(w+=A*N)>>>13,w&=8191,w+=T*C,w+=B*I,w+=O*U,w+=M*L,_=f+=(w+=j*(5*W))>>>13,_+=S*W,_+=k*q,_+=x*z,_+=R*D,f=(_+=A*P)>>>13,_&=8191,_+=T*N,_+=B*C,_+=O*I,_+=M*U,S=c=8191&(f=(f=((f+=(_+=j*L)>>>13)<<2)+f|0)+(c&=8191)|0),k=d+=f>>>=13,x=p&=8191,R=g&=8191,A=y&=8191,T=b&=8191,B=m&=8191,O=v&=8191,M=w&=8191,j=_&=8191,t+=16,r-=16;this.h[0]=S,this.h[1]=k,this.h[2]=x,this.h[3]=R,this.h[4]=A,this.h[5]=T,this.h[6]=B,this.h[7]=O,this.h[8]=M,this.h[9]=j},k.prototype.finish=function(e,t){var r,n,i,o,a=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=r,r=this.h[o]>>>13,this.h[o]&=8191;for(this.h[0]+=5*r,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,a[0]=this.h[0]+5,r=a[0]>>>13,a[0]&=8191,o=1;o<10;o++)a[o]=this.h[o]+r,r=a[o]>>>13,a[o]&=8191;for(a[9]-=8192,n=(1^r)-1,o=0;o<10;o++)a[o]&=n;for(n=~n,o=0;o<10;o++)this.h[o]=this.h[o]&n|a[o];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;e[t+0]=this.h[0]>>>0&255,e[t+1]=this.h[0]>>>8&255,e[t+2]=this.h[1]>>>0&255,e[t+3]=this.h[1]>>>8&255,e[t+4]=this.h[2]>>>0&255,e[t+5]=this.h[2]>>>8&255,e[t+6]=this.h[3]>>>0&255,e[t+7]=this.h[3]>>>8&255,e[t+8]=this.h[4]>>>0&255,e[t+9]=this.h[4]>>>8&255,e[t+10]=this.h[5]>>>0&255,e[t+11]=this.h[5]>>>8&255,e[t+12]=this.h[6]>>>0&255,e[t+13]=this.h[6]>>>8&255,e[t+14]=this.h[7]>>>0&255,e[t+15]=this.h[7]>>>8&255},k.prototype.update=function(e,t,r){var n,i;if(this.leftover){for((i=16-this.leftover)>r&&(i=r),n=0;n=16&&(i=r-r%16,this.blocks(e,t,i),t+=i,r-=i),r){for(n=0;n=128;){for(E=0;E<16;E++)S=8*E+V,O[E]=r[S+0]<<24|r[S+1]<<16|r[S+2]<<8|r[S+3],M[E]=r[S+4]<<24|r[S+5]<<16|r[S+6]<<8|r[S+7];for(E=0;E<80;E++)if(i=j,o=L,a=U,s=I,u=C,h=N,l=P,c=z,d=q,p=W,g=F,y=K,b=Y,m=H,R=65535&(x=$),A=x>>>16,T=65535&(k=D),B=k>>>16,R+=65535&(x=(K>>>14|C<<18)^(K>>>18|C<<14)^(C>>>9|K<<23)),A+=x>>>16,T+=65535&(k=(C>>>14|K<<18)^(C>>>18|K<<14)^(K>>>9|C<<23)),B+=k>>>16,R+=65535&(x=K&Y^~K&H),A+=x>>>16,T+=65535&(k=C&N^~C&P),B+=k>>>16,R+=65535&(x=G[2*E+1]),A+=x>>>16,T+=65535&(k=G[2*E]),B+=k>>>16,k=O[E%16],A+=(x=M[E%16])>>>16,T+=65535&k,B+=k>>>16,T+=(A+=(R+=65535&x)>>>16)>>>16,R=65535&(x=_=65535&R|A<<16),A=x>>>16,T=65535&(k=w=65535&T|(B+=T>>>16)<<16),B=k>>>16,R+=65535&(x=(z>>>28|j<<4)^(j>>>2|z<<30)^(j>>>7|z<<25)),A+=x>>>16,T+=65535&(k=(j>>>28|z<<4)^(z>>>2|j<<30)^(z>>>7|j<<25)),B+=k>>>16,A+=(x=z&q^z&W^q&W)>>>16,T+=65535&(k=j&L^j&U^L&U),B+=k>>>16,f=65535&(T+=(A+=(R+=65535&x)>>>16)>>>16)|(B+=T>>>16)<<16,v=65535&R|A<<16,R=65535&(x=g),A=x>>>16,T=65535&(k=s),B=k>>>16,A+=(x=_)>>>16,T+=65535&(k=w),B+=k>>>16,L=i,U=o,I=a,C=s=65535&(T+=(A+=(R+=65535&x)>>>16)>>>16)|(B+=T>>>16)<<16,N=u,P=h,D=l,j=f,q=c,W=d,F=p,K=g=65535&R|A<<16,Y=y,H=b,$=m,z=v,E%16==15)for(S=0;S<16;S++)k=O[S],R=65535&(x=M[S]),A=x>>>16,T=65535&k,B=k>>>16,k=O[(S+9)%16],R+=65535&(x=M[(S+9)%16]),A+=x>>>16,T+=65535&k,B+=k>>>16,w=O[(S+1)%16],R+=65535&(x=((_=M[(S+1)%16])>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25)),A+=x>>>16,T+=65535&(k=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7),B+=k>>>16,w=O[(S+14)%16],A+=(x=((_=M[(S+14)%16])>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26))>>>16,T+=65535&(k=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6),B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,O[S]=65535&T|B<<16,M[S]=65535&R|A<<16;R=65535&(x=z),A=x>>>16,T=65535&(k=j),B=k>>>16,k=e[0],A+=(x=t[0])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[0]=j=65535&T|B<<16,t[0]=z=65535&R|A<<16,R=65535&(x=q),A=x>>>16,T=65535&(k=L),B=k>>>16,k=e[1],A+=(x=t[1])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[1]=L=65535&T|B<<16,t[1]=q=65535&R|A<<16,R=65535&(x=W),A=x>>>16,T=65535&(k=U),B=k>>>16,k=e[2],A+=(x=t[2])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[2]=U=65535&T|B<<16,t[2]=W=65535&R|A<<16,R=65535&(x=F),A=x>>>16,T=65535&(k=I),B=k>>>16,k=e[3],A+=(x=t[3])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[3]=I=65535&T|B<<16,t[3]=F=65535&R|A<<16,R=65535&(x=K),A=x>>>16,T=65535&(k=C),B=k>>>16,k=e[4],A+=(x=t[4])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[4]=C=65535&T|B<<16,t[4]=K=65535&R|A<<16,R=65535&(x=Y),A=x>>>16,T=65535&(k=N),B=k>>>16,k=e[5],A+=(x=t[5])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[5]=N=65535&T|B<<16,t[5]=Y=65535&R|A<<16,R=65535&(x=H),A=x>>>16,T=65535&(k=P),B=k>>>16,k=e[6],A+=(x=t[6])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[6]=P=65535&T|B<<16,t[6]=H=65535&R|A<<16,R=65535&(x=$),A=x>>>16,T=65535&(k=D),B=k>>>16,k=e[7],A+=(x=t[7])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[7]=D=65535&T|B<<16,t[7]=$=65535&R|A<<16,V+=128,n-=128}return n}function X(e,t,r){var n,i=new Int32Array(8),o=new Int32Array(8),a=new Uint8Array(256),s=r;for(i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225,o[0]=4089235720,o[1]=2227873595,o[2]=4271175723,o[3]=1595750129,o[4]=2917565137,o[5]=725511199,o[6]=4215389547,o[7]=327033209,J(i,o,t,r),r%=128,n=0;n=0;--i)Q(e,t,n=r[i/8|0]>>(7&i)&1),Z(t,e),Z(e,e),Q(e,t,n)}function re(e,r){var n=[t(),t(),t(),t()];B(n[0],l),B(n[1],f),B(n[2],a),D(n[3],l,f),te(e,n,r)}function ne(e,n,i){var o,a=new Uint8Array(64),s=[t(),t(),t(),t()];for(i||r(n,32),X(a,n,32),a[0]&=248,a[31]&=127,a[31]|=64,re(s,a),ee(e,s),o=0;o<32;o++)n[o+32]=e[o];return 0}var ie=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function oe(e,t){var r,n,i,o;for(n=63;n>=32;--n){for(r=0,i=n-32,o=n-12;i>4)*ie[i],r=t[i]>>8,t[i]&=255;for(i=0;i<32;i++)t[i]-=r*ie[i];for(n=0;n<32;n++)t[n+1]+=t[n]>>8,e[n]=255&t[n]}function ae(e){var t,r=new Float64Array(64);for(t=0;t<64;t++)r[t]=e[t];for(t=0;t<64;t++)e[t]=0;oe(e,r)}function se(e,r,n,i){var o,a,s=new Uint8Array(64),u=new Uint8Array(64),h=new Uint8Array(64),l=new Float64Array(64),f=[t(),t(),t(),t()];X(s,i,32),s[0]&=248,s[31]&=127,s[31]|=64;var c=n+64;for(o=0;o>7&&P(e[0],o,e[0]),D(e[3],e[0],e[1]),0)}(d,i))return-1;for(s=0;s=0},e.sign.keyPair=function(){var e=new Uint8Array(fe),t=new Uint8Array(ce);return ne(e,t),{publicKey:e,secretKey:t}},e.sign.keyPair.fromSecretKey=function(e){if(pe(e),e.length!==ce)throw new Error("bad secret key size");for(var t=new Uint8Array(fe),r=0;re.replace("'",""),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.derivePath=e.isValidPath=e.getPublicKey=e.getMasterKeyFromSeed=void 0;const t=Ts,r=Bs.exports,n=Os;e.getMasterKeyFromSeed=e=>{const r=t("sha512","ed25519 seed").update(X.from(e,"hex")).digest();return{key:r.slice(0,32),chainCode:r.slice(32)}};e.getPublicKey=(e,t=!0)=>{const n=r.sign.keyPair.fromSeed(e).secretKey.subarray(32),i=X.alloc(1,0);return t?X.concat([i,X.from(n)]):X.from(n)},e.isValidPath=e=>!!n.pathRegex.test(e)&&!e.split("/").slice(1).map(n.replaceDerive).some(isNaN),e.derivePath=(r,i,o=2147483648)=>{if(!e.isValidPath(r))throw new Error("Invalid derivation path");const{key:a,chainCode:s}=e.getMasterKeyFromSeed(i);return r.split("/").slice(1).map(n.replaceDerive).map((e=>parseInt(e,10))).reduce(((e,r)=>(({key:e,chainCode:r},n)=>{const i=X.allocUnsafe(4);i.writeUInt32BE(n,0);const o=X.concat([X.alloc(1,0),e,i]),a=t("sha512",r).update(o).digest();return{key:a.slice(0,32),chainCode:a.slice(32)}})(e,r+o)),{key:a,chainCode:s})}}(Ue);var Ms=t(Ue);let js=(e={})=>{let t,{sk:r,keepPrivate:n=!1,seed:i=null}=e;if(r)t=Us(r);else{let e=Ns(i);t=e.vk,r=e.sk}return{sign:e=>Ps(r,e),verify:(e,r)=>Ds(t,e,r),vk:t,sk:n?void 0:r}};function Ls(e=null){var t=null;return t=null==e?I.sign.keyPair():I.sign.keyPair.fromSeed(e),{sk:new Uint8Array(t.secretKey.slice(0,32)),vk:new Uint8Array(t.secretKey.slice(32,64))}}function Us(e){return Cs(Is(e)).vk}function Is(e){return Ls(O(e))}function Cs(e){return{vk:B(e.vk),sk:B(e.sk)}}function Ns(e=null){return Cs(Ls(e))}function Ps(e,t){var r=Is(e),n=M(r.sk,r.vk);return B(I.sign.detached(t,n))}function Ds(e,t,r){var n=O(e),i=O(r);try{return I.sign.detached.verify(t,i,n)}catch(e){return!1}}var zs=Object.freeze({__proto__:null,create_wallet:js,generate_keys:Ls,get_vk:Us,format_to_keys:Is,keys_to_format:Cs,new_wallet:Ns,new_wallet_bip39:function(e,t=0){return function(e,t=0){let r,n;void 0!==e?r=e:(n=C.exports.generateMnemonic(256),r=C.exports.mnemonicToSeedSync(n).toString("hex"));const i="m/44'/789'/"+t+"'/0'/0'",{key:o,chainCode:a}=Ms.derivePath(i,r,2147483648),s=o.toString("hex"),u=Ms.getPublicKey(o,!1).toString("hex");if(u!==Us(s))throw Error("Bip32 public key does not match with Lamden public key!");return{sk:s,vk:u,derivationIndex:t,seed:void 0!==e?null:r,mnemonic:void 0!==e?null:n}}(e,t)},sign:Ps,verify:Ds,validateMnemonic:function(e,t){return C.exports.validateMnemonic(e,t)}});class qs{constructor(){this._events={}}on(e,t){this._events[e]||(this._events[e]=[]),this._events[e].push(t)}removeListener(e,t){if(!this._events[e])throw new Error(`Can't remove a listener. Event "${e}" doesn't exits.`);this._events[e]=this._events[e].filter((e=>e!==t))}emit(e,t){if(!this._events[e])return;this._events[e].forEach((e=>{e(t)}))}}var Ws={exports:{}};!function(e,t){var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,r.fetch&&(t.default=r.fetch.bind(r)),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response}(Ws,Ws.exports);var Fs,Ks=Ws.exports,Ys={exports:{}};Fs=Ys,function(e){var t,r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,o="[BigNumber Error] ",a=o+"Number primitive has more than 15 significant digits: ",s=1e14,u=14,h=9007199254740991,l=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],f=1e7,c=1e9;function d(e){var t=0|e;return e>0||e===t?t:t-1}function p(e){for(var t,r,n=1,i=e.length,o=e[0]+"";nh^r?1:-1;for(s=(u=i.length)<(h=o.length)?u:h,a=0;ao[a]^r?1:-1;return u==h?0:u>h^r?1:-1}function y(e,t,r,n){if(er||e!==i(e))throw Error(o+(n||"Argument")+("number"==typeof e?er?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function b(e){var t=e.c.length-1;return d(e.e/u)==t&&e.c[t]%2!=0}function m(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function v(e,t,r){var n,i;if(t<0){for(i=r+".";++t;i+=r);e=i+e}else if(++t>(n=e.length)){for(i=r,t-=n;--t;i+=r);e+=i}else tN?g.c=g.e=null:e.e=10;f/=10,l++);return void(l>N?g.c=g.e=null:(g.e=l,g.c=[e]))}p=String(e)}else{if(!r.test(p=String(e)))return E(g,p,c);g.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(l=p.indexOf("."))>-1&&(p=p.replace(".","")),(f=p.search(/e/i))>0?(l<0&&(l=f),l+=+p.slice(f+1),p=p.substring(0,f)):l<0&&(l=p.length)}else{if(y(t,2,W.length,"Base"),10==t)return $(g=new F(e),j+g.e+1,L);if(p=String(e),c="number"==typeof e){if(0*e!=0)return E(g,p,c,t);if(g.s=1/e<0?(p=p.slice(1),-1):1,F.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(a+e)}else g.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=W.slice(0,t),l=f=0,d=p.length;fl){l=d;continue}}else if(!s&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){s=!0,f=-1,l=0;continue}return E(g,String(e),c,t)}c=!1,(l=(p=_(p,t,10,g.s)).indexOf("."))>-1?p=p.replace(".",""):l=p.length}for(f=0;48===p.charCodeAt(f);f++);for(d=p.length;48===p.charCodeAt(--d););if(p=p.slice(f,++d)){if(d-=f,c&&F.DEBUG&&d>15&&(e>h||e!==i(e)))throw Error(a+g.s*e);if((l=l-f-1)>N)g.c=g.e=null;else if(l=I)?m(u,a):v(u,a,"0");else if(o=(e=$(new F(e),t,r)).e,s=(u=p(e.c)).length,1==n||2==n&&(t<=o||o<=U)){for(;ss){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=o-s)>0)for(o+1==s&&(u+=".");t--;u+="0");return e.s<0&&i?"-"+u:u}function Y(e,t){for(var r,n=1,i=new F(e[0]);n=10;i/=10,n++);return(r=n+r*u-1)>N?e.c=e.e=null:r=10;c/=10,a++);if((h=t-a)<0)h+=u,f=t,g=(d=y[p=0])/b[a-f-1]%10|0;else if((p=n((h+1)/u))>=y.length){if(!o)break e;for(;y.length<=p;y.push(0));d=g=0,a=1,f=(h%=u)-u+1}else{for(d=c=y[p],a=1;c>=10;c/=10,a++);g=(f=(h%=u)-u+a)<0?0:d/b[a-f-1]%10|0}if(o=o||t<0||null!=y[p+1]||(f<0?d:d%b[a-f-1]),o=r<4?(g||o)&&(0==r||r==(e.s<0?3:2)):g>5||5==g&&(4==r||o||6==r&&(h>0?f>0?d/b[a-f]:0:y[p-1])%10&1||r==(e.s<0?8:7)),t<1||!y[0])return y.length=0,o?(t-=e.e+1,y[0]=b[(u-t%u)%u],e.e=-t||0):y[0]=e.e=0,e;if(0==h?(y.length=p,c=1,p--):(y.length=p+1,c=b[u-h],y[p]=f>0?i(d/b[a-f]%b[f])*c:0),o)for(;;){if(0==p){for(h=1,f=y[0];f>=10;f/=10,h++);for(f=y[0]+=c,c=1;f>=10;f/=10,c++);h!=c&&(e.e++,y[0]==s&&(y[0]=1));break}if(y[p]+=c,y[p]!=s)break;y[p--]=0,c=1}for(h=y.length;0===y[--h];y.pop());}e.e>N?e.c=e.e=null:e.e=I?m(t,r):v(t,r,"0"),e.s<0?"-"+t:t)}return F.clone=e,F.ROUND_UP=0,F.ROUND_DOWN=1,F.ROUND_CEIL=2,F.ROUND_FLOOR=3,F.ROUND_HALF_UP=4,F.ROUND_HALF_DOWN=5,F.ROUND_HALF_EVEN=6,F.ROUND_HALF_CEIL=7,F.ROUND_HALF_FLOOR=8,F.EUCLID=9,F.config=F.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(o+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(y(r=e[t],0,c,t),j=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(y(r=e[t],0,8,t),L=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(y(r[0],-c,0,t),y(r[1],0,c,t),U=r[0],I=r[1]):(y(r,-c,c,t),U=-(I=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)y(r[0],-c,-1,t),y(r[1],1,c,t),C=r[0],N=r[1];else{if(y(r,-c,c,t),!r)throw Error(o+t+" cannot be zero: "+r);C=-(N=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(o+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw P=!r,Error(o+"crypto unavailable");P=r}else P=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(y(r=e[t],0,9,t),D=r),e.hasOwnProperty(t="POW_PRECISION")&&(y(r=e[t],0,c,t),z=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(o+t+" not an object: "+r);q=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.$|[+-.\s]|(.).*\1/.test(r))throw Error(o+t+" invalid: "+r);W=r}}return{DECIMAL_PLACES:j,ROUNDING_MODE:L,EXPONENTIAL_AT:[U,I],RANGE:[C,N],CRYPTO:P,MODULO_MODE:D,POW_PRECISION:z,FORMAT:q,ALPHABET:W}},F.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!F.DEBUG)return!0;var t,r,n=e.c,a=e.e,h=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===h||-1===h)&&a>=-c&&a<=c&&a===i(a)){if(0===n[0]){if(0===a&&1===n.length)return!0;break e}if((t=(a+1)%u)<1&&(t+=u),String(n[0]).length==t){for(t=0;t=s||r!==i(r))break e;if(0!==r)return!0}}}else if(null===n&&null===a&&(null===h||1===h||-1===h))return!0;throw Error(o+"Invalid BigNumber: "+e)},F.maximum=F.max=function(){return Y(arguments,O.lt)},F.minimum=F.min=function(){return Y(arguments,O.gt)},F.random=(S=9007199254740992,k=Math.random()*S&2097151?function(){return i(Math.random()*S)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,a,s,h,f=0,d=[],p=new F(M);if(null==e?e=j:y(e,0,c),s=n(e/u),P)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(s*=2));f>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[f]=r[0],t[f+1]=r[1]):(d.push(h%1e14),f+=2);f=s/2}else{if(!crypto.randomBytes)throw P=!1,Error(o+"crypto unavailable");for(t=crypto.randomBytes(s*=7);f=9e15?crypto.randomBytes(7).copy(t,f):(d.push(h%1e14),f+=7);f=s/7}if(!P)for(;f=10;h/=10,f++);fr-1&&(null==a[i+1]&&(a[i+1]=0),a[i+1]+=a[i]/r|0,a[i]%=r)}return a.reverse()}return function(r,n,i,o,a){var s,u,h,l,f,c,d,g,y=r.indexOf("."),b=j,m=L;for(y>=0&&(l=z,z=0,r=r.replace(".",""),c=(g=new F(n)).pow(r.length-y),z=l,g.c=t(v(p(c.c),c.e,"0"),10,i,e),g.e=g.c.length),h=l=(d=t(r,n,i,a?(s=W,e):(s=e,W))).length;0==d[--l];d.pop());if(!d[0])return s.charAt(0);if(y<0?--h:(c.c=d,c.e=h,c.s=o,d=(c=w(c,g,b,m,i)).c,f=c.r,h=c.e),y=d[u=h+b+1],l=i/2,f=f||u<0||null!=d[u+1],f=m<4?(null!=y||f)&&(0==m||m==(c.s<0?3:2)):y>l||y==l&&(4==m||f||6==m&&1&d[u-1]||m==(c.s<0?8:7)),u<1||!d[0])r=f?v(s.charAt(1),-b,s.charAt(0)):s.charAt(0);else{if(d.length=u,f)for(--i;++d[--u]>i;)d[u]=0,u||(++h,d=[1].concat(d));for(l=d.length;!d[--l];);for(y=0,r="";y<=l;r+=s.charAt(d[y++]));r=v(r,h,s.charAt(0))}return r}}(),w=function(){function e(e,t,r){var n,i,o,a,s=0,u=e.length,h=t%f,l=t/f|0;for(e=e.slice();u--;)s=((i=h*(o=e[u]%f)+(n=l*o+(a=e[u]/f|0)*h)%f*f+s)/r|0)+(n/f|0)+l*a,e[u]=i%r;return s&&(e=[s].concat(e)),e}function t(e,t,r,n){var i,o;if(r!=n)o=r>n?1:-1;else for(i=o=0;it[i]?1:-1;break}return o}function r(e,t,r,n){for(var i=0;r--;)e[r]-=i,i=e[r]1;e.splice(0,1));}return function(n,o,a,h,l){var f,c,p,g,y,b,m,v,w,_,E,S,k,x,R,A,T,B=n.s==o.s?1:-1,O=n.c,M=o.c;if(!(O&&O[0]&&M&&M[0]))return new F(n.s&&o.s&&(O?!M||O[0]!=M[0]:M)?O&&0==O[0]||!M?0*B:B/0:NaN);for(w=(v=new F(B)).c=[],B=a+(c=n.e-o.e)+1,l||(l=s,c=d(n.e/u)-d(o.e/u),B=B/u|0),p=0;M[p]==(O[p]||0);p++);if(M[p]>(O[p]||0)&&c--,B<0)w.push(1),g=!0;else{for(x=O.length,A=M.length,p=0,B+=2,(y=i(l/(M[0]+1)))>1&&(M=e(M,y,l),O=e(O,y,l),A=M.length,x=O.length),k=A,E=(_=O.slice(0,A)).length;E=l/2&&R++;do{if(y=0,(f=t(M,_,A,E))<0){if(S=_[0],A!=E&&(S=S*l+(_[1]||0)),(y=i(S/R))>1)for(y>=l&&(y=l-1),m=(b=e(M,y,l)).length,E=_.length;1==t(b,_,m,E);)y--,r(b,A=10;B/=10,p++);$(v,a+(v.e=p+c*u-1)+1,h,g)}else v.e=c,v.r=+g;return v}}(),x=/^(-?)0([xbo])(?=\w[\w.]*$)/i,R=/^([^.]+)\.$/,A=/^\.([^.]+)$/,T=/^-?(Infinity|NaN)$/,B=/^\s*\+(?=[\w.])|^\s+|\s+$/g,E=function(e,t,r,n){var i,a=r?t:t.replace(B,"");if(T.test(a))e.s=isNaN(a)?null:a<0?-1:1;else{if(!r&&(a=a.replace(x,(function(e,t,r){return i="x"==(r=r.toLowerCase())?16:"b"==r?2:8,n&&n!=i?e:t})),n&&(i=n,a=a.replace(R,"$1").replace(A,"0.$1")),t!=a))return new F(a,i);if(F.DEBUG)throw Error(o+"Not a"+(n?" base "+n:"")+" number: "+t);e.s=null}e.c=e.e=null},O.absoluteValue=O.abs=function(){var e=new F(this);return e.s<0&&(e.s=1),e},O.comparedTo=function(e,t){return g(this,new F(e,t))},O.decimalPlaces=O.dp=function(e,t){var r,n,i,o=this;if(null!=e)return y(e,0,c),null==t?t=L:y(t,0,8),$(new F(o),e+o.e+1,t);if(!(r=o.c))return null;if(n=((i=r.length-1)-d(this.e/u))*u,i=r[i])for(;i%10==0;i/=10,n--);return n<0&&(n=0),n},O.dividedBy=O.div=function(e,t){return w(this,new F(e,t),j,L)},O.dividedToIntegerBy=O.idiv=function(e,t){return w(this,new F(e,t),0,1)},O.exponentiatedBy=O.pow=function(e,t){var r,a,s,h,l,f,c,d,p=this;if((e=new F(e)).c&&!e.isInteger())throw Error(o+"Exponent not an integer: "+V(e));if(null!=t&&(t=new F(t)),l=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return d=new F(Math.pow(+V(p),l?2-b(e):+V(e))),t?d.mod(t):d;if(f=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new F(NaN);(a=!f&&p.isInteger()&&t.isInteger())&&(p=p.mod(t))}else{if(e.e>9&&(p.e>0||p.e<-1||(0==p.e?p.c[0]>1||l&&p.c[1]>=24e7:p.c[0]<8e13||l&&p.c[0]<=9999975e7)))return h=p.s<0&&b(e)?-0:0,p.e>-1&&(h=1/h),new F(f?1/h:h);z&&(h=n(z/u+2))}for(l?(r=new F(.5),f&&(e.s=1),c=b(e)):c=(s=Math.abs(+V(e)))%2,d=new F(M);;){if(c){if(!(d=d.times(p)).c)break;h?d.c.length>h&&(d.c.length=h):a&&(d=d.mod(t))}if(s){if(0===(s=i(s/2)))break;c=s%2}else if($(e=e.times(r),e.e+1,1),e.e>14)c=b(e);else{if(0==(s=+V(e)))break;c=s%2}p=p.times(p),h?p.c&&p.c.length>h&&(p.c.length=h):a&&(p=p.mod(t))}return a?d:(f&&(d=M.div(d)),t?d.mod(t):h?$(d,z,L,void 0):d)},O.integerValue=function(e){var t=new F(this);return null==e?e=L:y(e,0,8),$(t,t.e+1,e)},O.isEqualTo=O.eq=function(e,t){return 0===g(this,new F(e,t))},O.isFinite=function(){return!!this.c},O.isGreaterThan=O.gt=function(e,t){return g(this,new F(e,t))>0},O.isGreaterThanOrEqualTo=O.gte=function(e,t){return 1===(t=g(this,new F(e,t)))||0===t},O.isInteger=function(){return!!this.c&&d(this.e/u)>this.c.length-2},O.isLessThan=O.lt=function(e,t){return g(this,new F(e,t))<0},O.isLessThanOrEqualTo=O.lte=function(e,t){return-1===(t=g(this,new F(e,t)))||0===t},O.isNaN=function(){return!this.s},O.isNegative=function(){return this.s<0},O.isPositive=function(){return this.s>0},O.isZero=function(){return!!this.c&&0==this.c[0]},O.minus=function(e,t){var r,n,i,o,a=this,h=a.s;if(t=(e=new F(e,t)).s,!h||!t)return new F(NaN);if(h!=t)return e.s=-t,a.plus(e);var l=a.e/u,f=e.e/u,c=a.c,p=e.c;if(!l||!f){if(!c||!p)return c?(e.s=-t,e):new F(p?a:NaN);if(!c[0]||!p[0])return p[0]?(e.s=-t,e):new F(c[0]?a:3==L?-0:0)}if(l=d(l),f=d(f),c=c.slice(),h=l-f){for((o=h<0)?(h=-h,i=c):(f=l,i=p),i.reverse(),t=h;t--;i.push(0));i.reverse()}else for(n=(o=(h=c.length)<(t=p.length))?h:t,h=t=0;t0)for(;t--;c[r++]=0);for(t=s-1;n>h;){if(c[--n]=0;){for(r=0,y=S[i]%w,b=S[i]/w|0,o=i+(a=l);o>i;)r=((c=y*(c=E[--a]%w)+(h=b*c+(p=E[a]/w|0)*y)%w*w+m[o]+r)/v|0)+(h/w|0)+b*p,m[o--]=c%v;m[o]=r}return r?++n:m.splice(0,1),H(e,m,n)},O.negated=function(){var e=new F(this);return e.s=-e.s||null,e},O.plus=function(e,t){var r,n=this,i=n.s;if(t=(e=new F(e,t)).s,!i||!t)return new F(NaN);if(i!=t)return e.s=-t,n.minus(e);var o=n.e/u,a=e.e/u,h=n.c,l=e.c;if(!o||!a){if(!h||!l)return new F(i/0);if(!h[0]||!l[0])return l[0]?e:new F(h[0]?n:0*i)}if(o=d(o),a=d(a),h=h.slice(),i=o-a){for(i>0?(a=o,r=l):(i=-i,r=h),r.reverse();i--;r.push(0));r.reverse()}for((i=h.length)-(t=l.length)<0&&(r=l,l=h,h=r,t=i),i=0;t;)i=(h[--t]=h[t]+l[t]+i)/s|0,h[t]=s===h[t]?0:h[t]%s;return i&&(h=[i].concat(h),++a),H(e,h,a)},O.precision=O.sd=function(e,t){var r,n,i,o=this;if(null!=e&&e!==!!e)return y(e,1,c),null==t?t=L:y(t,0,8),$(new F(o),e,t);if(!(r=o.c))return null;if(n=(i=r.length-1)*u+1,i=r[i]){for(;i%10==0;i/=10,n--);for(i=r[0];i>=10;i/=10,n++);}return e&&o.e+1>n&&(n=o.e+1),n},O.shiftedBy=function(e){return y(e,-9007199254740991,h),this.times("1e"+e)},O.squareRoot=O.sqrt=function(){var e,t,r,n,i,o=this,a=o.c,s=o.s,u=o.e,h=j+4,l=new F("0.5");if(1!==s||!a||!a[0])return new F(!s||s<0&&(!a||a[0])?NaN:a?o:1/0);if(0==(s=Math.sqrt(+V(o)))||s==1/0?(((t=p(a)).length+u)%2==0&&(t+="0"),s=Math.sqrt(+t),u=d((u+1)/2)-(u<0||u%2),r=new F(t=s==1/0?"1e"+u:(t=s.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new F(s+""),r.c[0])for((s=(u=r.e)+h)<3&&(s=0);;)if(i=r,r=l.times(i.plus(w(o,i,h,1))),p(i.c).slice(0,s)===(t=p(r.c)).slice(0,s)){if(r.e0&&g>0){for(a=g%u||u,f=p.substr(0,a);a0&&(f+=l+p.slice(a)),d&&(f="-"+f)}n=c?f+(r.decimalSeparator||"")+((h=+r.fractionGroupSize)?c.replace(new RegExp("\\d{"+h+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):c):f}return(r.prefix||"")+n+(r.suffix||"")},O.toFraction=function(e){var t,r,n,i,a,s,h,f,c,d,g,y,b=this,m=b.c;if(null!=e&&(!(h=new F(e)).isInteger()&&(h.c||1!==h.s)||h.lt(M)))throw Error(o+"Argument "+(h.isInteger()?"out of range: ":"not an integer: ")+V(h));if(!m)return new F(b);for(t=new F(M),c=r=new F(M),n=f=new F(M),y=p(m),a=t.e=y.length-b.e-1,t.c[0]=l[(s=a%u)<0?u+s:s],e=!e||h.comparedTo(t)>0?a>0?t:c:h,s=N,N=1/0,h=new F(y),f.c[0]=0;d=w(h,t,0,1),1!=(i=r.plus(d.times(n))).comparedTo(e);)r=n,n=i,c=f.plus(d.times(i=c)),f=i,t=h.minus(d.times(i=t)),h=i;return i=w(e.minus(r),n,0,1),f=f.plus(i.times(c)),r=r.plus(i.times(n)),f.s=c.s=b.s,g=w(c,n,a*=2,L).minus(b).abs().comparedTo(w(f,r,a,L).minus(b).abs())<1?[c,n]:[f,r],N=s,g},O.toNumber=function(){return+V(this)},O.toPrecision=function(e,t){return null!=e&&y(e,1,c),K(this,e,t,2)},O.toString=function(e){var t,r=this,n=r.s,i=r.e;return null===i?n?(t="Infinity",n<0&&(t="-"+t)):t="NaN":(null==e?t=i<=U||i>=I?m(p(r.c),i):v(p(r.c),i,"0"):10===e?t=v(p((r=$(new F(r),j+i+1,L)).c),r.e,"0"):(y(e,2,W.length,"Base"),t=_(v(p(r.c),i,"0"),10,e,n,!0)),n<0&&r.c[0]&&(t="-"+t)),t},O.valueOf=O.toJSON=function(){return V(this)},O._isBigNumber=!0,null!=t&&F.set(t),F}(),t.default=t.BigNumber=t,Fs.exports?Fs.exports=t:(e||(e="undefined"!=typeof self&&self?self:window),e.BigNumber=t)}(e);var Hs=Ys.exports;function $s(e,t){const r=t=>{throw new Error(`Error encoding ${t} to ${e}`)},n=e=>{if(Math.floor(e)===e)return 0;try{return e.toString().split(".")[1].length}catch(e){return 0}},i=e=>e&&"object"==typeof e&&e.constructor===Array,o=e=>e&&"object"==typeof e&&e.constructor===Object,a=e=>e instanceof Date,s=e=>!i(e)&&!isNaN(l(e).toNumber()),u=e=>!!s(e)&&0!==n(e),h=e=>(s(e)||r(e),Hs.isBigNumber(e)||(e=new Hs(e)),{__fixed__:e.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm,"$1$2")}),l=e=>(Hs.isBigNumber(e)||(e=new Hs(e)),e),f=e=>(e=>"boolean"==typeof e)(e)?e:"true"===e||1===e||"false"!==e&&0!==e&&void r(e),c=e=>(e=>"string"==typeof e||e instanceof String)(e)?e:a(e)?e.toISOString():JSON.stringify(e),d=e=>(e=a(e)?e:new Date(e),a(e)||r(e),{__time__:[e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()]}),p=e=>{const t=a(e)?e.getTime():new Date(e).getTime(),r=parseInt(t/1e3/60/60/24);return{__delta__:[r,(t-24*r*60*60*1e3)/1e3]}},g=e=>{if(i(e))return b(e);try{e=JSON.parse(e)}catch(t){r(e)}if(i(e))return b(e);r(e)},y=e=>{if(o(e))return b(e);try{e=JSON.parse(e)}catch(t){r(e)}if(o(e))return b(e);r(e)};function b(e){let t=JSON.stringify(e,((e,t)=>"datetime"===e||"datetime.datetime"===e?$s("datetime.datetime",t):"timedelta"===e||"datetime.timedelta"===e?$s("datetime.timedelta",t):"__fixed__"!==e&&u(t)?h(t):t));return JSON.parse(t,((e,t)=>{const r=e=>1===Object.keys(e).length&&["datetime.datetime","datetime","datetime.timedelta","timedelta"].filter((t=>t===Object.keys(e)[0])).length>0;return t.constructor===Array&&t.map((e=>1===Object.keys(e).length&&r(t)?e[Object.keys(e)[0]]:e)),t.constructor===Object&&1===Object.keys(t).length&&r(t)?t[Object.keys(t)[0]]:t}))}const m={str:c,string:c,float:h,int:e=>{if(s(e))return parseInt(e);r(e)},bool:f,boolean:f,dict:y,list:g,Any:()=>t,"datetime.timedelta":p,"datetime.datetime":d,timedelta:p,datetime:d,number:e=>(s(e)||r(e),u(e)?(Hs.isBigNumber(e)||(e=new Hs(e)),{__fixed__:e.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm,"$1$2")}):(e=>!!s(e)&&0===n(e))(e)?parseInt(e):void 0),object:e=>{try{return g(e)}catch(t){return y(e)}},bigNumber:l};if(Object.keys(m).includes(e))return m[e](t);throw new Error(`Error: ${e} is not a valid encoder type.`)}Hs.config({RANGE:[-30,30],EXPONENTIAL_AT:1e9}),Hs.set({DECIMAL_PLACES:30,ROUNDING_MODE:Hs.ROUND_DOWN}),$s.BigNumber=Hs;const{validateTypes:Vs}=o;class Gs{constructor(e){if(!Vs.isObjectWithKeys(e))throw new Error("Expected Object and got Type: "+typeof e);if(!Vs.isArrayWithValues(e.hosts))throw new Error("HOSTS Required (Type: Array)");this.hosts=this.validateHosts(e.hosts)}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Host String must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}send(e,t,r,n,i){let o="";Object.keys(r).includes("parms")&&(o=this.createParms(r.parms));let a={};if("POST"===e){let t={"Content-Type":"application/json"};a.method=e,a.headers=t,a.body=r}return Ks(`${n||this.url}${t}${o}`,a).then((async e=>{if(200===e.status){let t=await e.json();return i(t,void 0),t}{let t=!!Vs.isStringWithValue(e.statusText)&&e.statusText;return i(void 0,t),t}})).catch((e=>i(void 0,e.toString())))}createParms(e){if(0===Object.keys(e).length)return"";let t="?";return Object.keys(e).forEach((r=>{t=`${t}${r}=${e[r]}&`})),t.slice(0,-1)}async getContractInfo(e){const t=e=>{try{if(e.name)return e}catch(e){}return null};let r=`/contracts/${e}`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async getVariable(e,t,r=""){let n={};Vs.isStringWithValue(r)&&(n.key=r);let i=`/contracts/${e}/${t}/`;const o=e=>{try{if(e.value)return e.value}catch(e){}return null};return this.send("GET",i,{parms:n},void 0,((e,t)=>o(e))).then((e=>o(e)))}async getContractMethods(e){const t=e=>{try{if(e.methods)return e.methods}catch(e){}return[]};let r=`/contracts/${e}/methods`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async getContractVariables(e){const t=e=>{try{if(e.variables)return e}catch(e){}return{}};let r=`/contracts/${e}/variables`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async pingServer(){const e=e=>{try{if(e.status)return!0}catch(e){}return!1};let t=await this.send("GET","/ping",{},void 0,((t,r)=>e(t)));return e(t)}async getCurrencyBalance(e){let t=await this.getVariable("currency","balances",e);return t?t.__fixed__?$s("bigNumber",t.__fixed__):$s("bigNumber",t.toString()):$s("bigNumber",0)}async contractExists(e){const t=e=>{try{if(e.name)return!0}catch(e){}return!1};let r=`/contracts/${e}`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async sendTransaction(e,t,r){return this.send("POST","/",JSON.stringify(e),t,((e,t)=>t?r?void r(void 0,t):t:r?void r(e,void 0):e))}async getNonce(e,t){if(!Vs.isStringHex(e))return`${e} is not a hex string.`;let r=`/nonce/${e}`,n=this.host;return this.send("GET",r,{},n,((r,i)=>i?t?void t(void 0,`Unable to get nonce for ${e} on network ${n}`):`Unable to get nonce for ${e} on network ${n}`:(r.masternode=n,t?void t(r,void 0):r)))}checkTransaction(e,t){const r={hash:e};return this.send("GET","/tx",{parms:r},void 0,((e,r)=>r?t?void t(void 0,r):r:t?void t(e,void 0):e))}}const{validateTypes:Js}=o;class Xs{constructor(e){if(!Js.isObjectWithKeys(e))throw new Error("Expected Network to be Object and got Type: "+typeof e);Js.isArrayWithValues(e.blockservice_hosts)?this.hosts=this.validateHosts(e.blockservice_hosts):this.hosts=[]}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Blockservice host value must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}send(e,t,r={},n){let i="";Object.keys(r).includes("parms")&&(i=this.createParms(r.parms));let o={};if("POST"===e){let t={"Content-Type":"application/json"};o.method=e,o.headers=t,o.body=r}return Ks(`${n||this.url}${t}${i}`,o)}createParms(e){if(0===Object.keys(e).length)return"";let t="?";return Object.keys(e).forEach((r=>{t=`${t}${r}=${e[r]}&`})),t.slice(0,-1)}async pingServer(){return this.send("GET","/ping",{}).then((e=>e.text())).then((e=>"pong"===e)).catch((()=>!1))}async getLastetBlock(e){return this.send("GET","/latest_block").then((e=>e.json())).then((t=>(e&&e(t.latest_block,null),t.latest_block))).catch((t=>(e&&e(null,t.message),{error:t.message})))}async getBlocks(e,t=10,r){const n={start_block:e,limit:t};return this.send("GET","/blocks",{parms:n}).then((e=>e.json())).then((e=>(r&&r(e,null),e))).catch((e=>(r&&r(null,e.message),{error:e.message})))}async getCurrentKeyValue(e,t,r,n){return this.send("GET",`/current/one/${e}/${t}/${r}`).then((e=>e.json())).then((e=>(n&&n(e,null),e))).catch((e=>(n&&n(null,e.message),{error:e.message})))}async getCurrentKeysValues(e,t){try{let r="current/keys";return await this.send("POST",`/${r}`,JSON.stringify(e)).then((e=>e.json())).then((e=>(t&&t(e,null),e)))}catch(e){return t&&t(null,e.message),{error:e.message}}}async getTransaction(e,t){const r={hash:e};return this.send("GET","/tx",{parms:r}).then((e=>e.json())).then((e=>(t&&t(e,null),e))).catch((e=>e.message.includes("invalid json response body")?(t&&t(null,null),null):(t&&t(null,e.message),{error:e.message})))}}const{validateTypes:Zs}=o,Qs=[1,2];class eu{constructor(e){if(!Zs.isObjectWithKeys(e))throw new Error("Expected Network Info Object and got Type: "+typeof e);if(!Zs.isArrayWithValues(e.hosts))throw new Error("HOSTS Required (Type: Array)");this.classname="Network",this.type=Zs.isStringWithValue(e.type)?e.type.toLowerCase():"custom",this.version=this.getNetworkVersion(e.version),this.events=new qs,this.hosts=this.validateHosts(e.hosts),this.currencySymbol=Zs.isStringWithValue(e.currencySymbol)?e.currencySymbol:"TAU",this.name=Zs.isStringWithValue(e.name)?e.name:"lamden network",this.lamden=!!Zs.isBoolean(e.lamden)&&e.lamden,this.blockExplorer=Zs.isStringWithValue(e.blockExplorer)?e.blockExplorer:void 0,this.online=!1;try{this.API=new Gs(e)}catch(e){throw new Error(e)}try{this.blockservice=new Xs(e)}catch(e){throw new Error(e)}}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Host String must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}getNetworkVersion(e){return Zs.isInteger(e)&&Qs.includes(e)?e:1}async ping(e){return this.online=await this.API.pingServer(),this.events.emit("online",this.online),Zs.isFunction(e)&&e(this.online),this.online}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}getNetworkInfo(){return{name:this.name,lamden:this.lamden,type:this.type,hosts:this.hosts,blockservice_hosts:this.blockservice.hosts,url:this.url,online:this.online,version:this.version}}}const{validateTypes:tu}=o;class ru extends eu{constructor(e,t,r){if(e&&"Network"===e.classname?super(e.getNetworkInfo()):super(e),!tu.isObjectWithKeys(t))throw new Error("txInfo object not found");if(!tu.isStringHex(t.senderVk))throw new Error("Sender Public Key Required (Type: Hex String)");if(!tu.isStringWithValue(t.contractName))throw new Error("Contract Name Required (Type: String)");if(!tu.isStringWithValue(t.methodName))throw new Error("Method Required (Type: String)");if(!tu.isInteger(t.stampLimit))throw new Error("Stamps Limit Required (Type: Integer)");if(this.uid=tu.isStringWithValue(t.uid)?t.uid:void 0,this.sender=t.senderVk,this.contract=t.contractName,this.method=t.methodName,this.kwargs={},tu.isObject(t.kwargs)&&(this.kwargs=t.kwargs),this.stampLimit=t.stampLimit,void 0!==t.nonce){if(!tu.isInteger(t.nonce))throw new Error(`arg[6] Nonce is required to be an Integer, type ${typeof t.none} was given`);this.nonce=t.nonce}if(void 0!==t.processor){if(!tu.isStringWithValue(t.processor))throw new Error(`arg[7] Processor is required to be a String, type ${typeof t.processor} was given`);this.processor=t.processor}this.signature,this.transactionSigned=!1,this.nonceResult={},this.txSendResult={errors:[]},this.txBlockResult={},this.txHash,this.txCheckResult={},this.txCheckAttempts=0,this.txCheckLimit=10,this.maxBlockToCheck=30,this.startBlock=null,r&&(r.uid&&(this.uid=r.uid),tu.isObjectWithKeys(r.txSendResult)&&(this.txSendResult=r.txSendResult),tu.isObjectWithKeys(r.nonceResult)&&(this.nonceResult=r.nonceResult,tu.isInteger(this.nonceResult.nonce)&&(this.nonce=this.nonceResult.nonce),tu.isStringWithValue(this.nonceResult.processor)&&(this.processor=this.nonceResult.processor)),tu.isObjectWithKeys(r.txSendResult)&&(this.txSendResult=r.txSendResult,this.txSendResult.hash&&(this.txHash=this.txSendResult.hash)),tu.isObjectWithKeys(r.txBlockResult)&&(this.txBlockResult=r.txBlockResult),tu.isObjectWithKeys(r.resultInfo)&&(this.resultInfo=r.resultInfo)),this.makePayload()}makePayload(){this.payload={contract:this.contract,function:this.method,kwargs:this.kwargs,nonce:this.nonce,processor:this.processor,sender:this.sender,stamps_supplied:this.stampLimit},this.sortedPayload=this.sortObject(this.payload)}makeTransaction(){1===this.version&&(this.tx={metadata:{signature:this.signature,timestamp:parseInt(+new Date/1e3)},payload:this.sortedPayload.orderedObj}),2===this.version&&(this.tx={metadata:{signature:this.signature},payload:this.sortedPayload.orderedObj})}verifySignature(){if(!this.transactionSigned)throw new Error("Transaction has not be been signed. Use the sign() method first.");const e=Buffer.from(this.sortedPayload.json),t=new Uint8Array(e);return Ds(this.sender,t,this.signature)}sign(e,t){const r=Buffer.from(this.sortedPayload.json),n=new Uint8Array(r);this.signature=t?t.sign(n):Ps(e,n),this.transactionSigned=!0}sortObject(e){const t=(e=>{const t=e=>Object.prototype.toString.call(e),r=e=>"[object Object]"===t(e),n=e=>(Object.keys(e).forEach((i=>{var o;o=e[i],"[object Array]"===t(o)&&(e[i]=e[i].map((e=>r(e)?n(e):e))),r(e[i])&&(e[i]=n(e[i]))})),(e=>{const t={};return Object.keys(e).sort().forEach((r=>t[r]=e[r])),t})(e));if(!r(e))throw new TypeError("Not a valid Object");try{e=JSON.parse(JSON.stringify(e))}catch(e){throw new TypeError("Not a valid JSON Object")}return n(e)})(e);return{orderedObj:t,json:JSON.stringify(t)}}async getNonce(e){let t=(new Date).toUTCString();if(this.nonceResult=await this.API.getNonce(this.sender),void 0===this.nonceResult.nonce)throw new Error(this.nonceResult);return this.nonceResult.timestamp=t,this.nonce=this.nonceResult.nonce,this.processor=this.nonceResult.processor,this.nonceMasternode=this.nonceResult.masternode,this.makePayload(),e?e(this.nonceResult):this.nonceResult}async send(e,t,r){if(!tu.isStringWithValue(e)&&!this.transactionSigned)throw new Error("Transation Not Signed: Private key needed or call sign() first");this.blockservice.url&&await this.blockservice.pingServer()&&(this.startBlock=await this.blockservice.getLastetBlock());let n=(new Date).toUTCString();try{!isNaN(this.nonce)&&tu.isStringWithValue(this.processor)||await this.getNonce(),tu.isStringWithValue(e)&&this.sign(e),this.makeTransaction();let t=r;!t&&this.nonceMasternode&&(t=this.nonceMasternode);let n=await this.API.sendTransaction(this.tx,t);!n||tu.isStringWithValue(n)?this.txSendResult.errors=[n||"Unknown Transaction Error"]:n.error?this.txSendResult.errors=[n.error]:this.txSendResult=n}catch(e){this.txSendResult.errors=[e.message]}return this.txSendResult.timestamp=n,this.handleMasterNodeResponse(this.txSendResult,t)}checkForTransactionResult(e){return new Promise((t=>{let r=setTimeout(async function n(){this.txCheckAttempts=this.txCheckAttempts+1;let i=await this.API.checkTransaction(this.txHash),o=!1,a=(new Date).toUTCString();"string"!=typeof i&&i?i.error?"Transaction not found."===i.error?this.txCheckAttempts0&&(tu.isArray(this.txCheckResult.errors)||(this.txCheckResult.errors=[]),this.txCheckResult.errors.push("This transaction returned a non-zero status code")),this.txCheckResult.timestamp=a,clearTimeout(r),t(this.handleMasterNodeResponse(this.txCheckResult,e)))}.bind(this),1e3)}))}async checkBlockserviceForTransactionResult(e){if(!this.txHash)throw new Error("No transaction hash to check.");return await this.blockservice.pingServer()?new Promise((async t=>{let r=this.startBlock||0;const n=async()=>{let e=await this.blockservice.getLastetBlock();e>r?(r=e,i()):setTimeout(n,5e3)},i=async()=>{let i=await this.blockservice.getTransaction(this.txHash);i?(this.txCheckResult={...i,...i.txInfo},t(this.handleMasterNodeResponse(this.txCheckResult,e))):r-this.startBlock>this.maxBlockToCheck?(this.txCheckResult.errors=[`No transaction result found within ${this.maxBlockToCheck} blocks after sending.`],this.txCheckResult.status=2,t(this.handleMasterNodeResponse(this.txCheckResult,e))):setTimeout(n,5e3)};n()})):(console.log("Blockservice not available, failing back to masternode."),this.checkForTransactionResult(e).then((e=>({txinfo:e,...e}))))}handleMasterNodeResponse(e,t){return tu.isStringWithValue(e.hash)&&tu.isStringWithValue(e.success)?(this.txHash=e.hash,this.setPendingBlockInfo()):(this.setBlockResultInfo(e),this.txBlockResult=e),this.events.emit("response",e,this.resultInfo.subtitle),tu.isFunction(t)&&t(e),e}setPendingBlockInfo(){return this.resultInfo={title:"Transaction Pending",subtitle:"Your transaction was submitted and is being processed",message:`Tx Hash: ${this.txHash}`,type:"success"},this.resultInfo}setBlockResultInfo(e){let t=!1,r="returned an error and ",n=tu.isNumber(e.status)?e.status:void 0,i=e.stampsUsed||e.stamps_used||0,o="";return tu.isArrayWithValues(e.errors)&&(t=!0,o=`This transaction returned ${e.errors.length} errors.`,e.result&&e.result.includes("AssertionError")&&e.errors.push(e.result)),n&&t&&(r=`returned status code ${n} and `),this.resultInfo={title:"Transaction "+(t?"Failed":"Successful"),subtitle:`Your transaction ${t?`${r} `:""}used ${i} stamps`,message:o,type:""+(t?"error":"success"),errorInfo:t?e.errors:void 0,returnResult:e.result||"",stampsUsed:i,statusCode:n},this.resultInfo}getResultInfo(){return this.resultInfo}getTxInfo(){return{senderVk:this.sender,contractName:this.contract,methodName:this.method,kwargs:this.kwargs,stampLimit:this.stampLimit}}getAllInfo(){return{uid:this.uid,txHash:this.txHash,signed:this.transactionSigned,tx:this.tx,signature:this.signature,networkInfo:this.getNetworkInfo(),txInfo:this.getTxInfo(),txSendResult:this.txSendResult,txBlockResult:this.txBlockResult,resultInfo:this.getResultInfo(),nonceResult:this.nonceResult}}}const{validateTypes:nu,assertTypes:iu}=o;globalThis.Buffer=Ne.Buffer;var ou={TransactionBuilder:ru,TransactionBatcher:class extends eu{constructor(e){e&&"Network"===e.classname?super(e.getNetworkInfo()):super(e),this.txBatches={},this.overflow=[],this.nonceResults={},this.running=!1}addTransaction(e){this.running?this.overflow.push(e):(this.validateTransactionInfo(e),this.txBatches[e.senderVk]||(this.txBatches[e.senderVk]=[]),this.txBatches[e.senderVk].push(e))}addTransactionList(e){e.forEach((e=>this.addTransaction(e)))}processOverflow(){const e=this.overflow;this.overflow=[],e.forEach((e=>this.addTransaction(e)))}hasTransactions(){let e=Object.keys(this.txBatches).map((e=>this.txBatches[e].length));return e.filter((e=>0===e)),e.length>0}validateTransactionInfo(e){try{new ru(e)}catch(e){return!1}return!0}async getStartingNonce(e,t){let r=(new Date).toUTCString(),n=await this.API.getNonce(e);if(void 0===n.nonce)throw new Error(n);return n.timestamp=r,this.nonceResults[e]=n,t&&t(n),n}async sendAllBatches(e){if(this.running)return;let t=[];this.running=!0,await Promise.all(Object.keys(this.txBatches).map((r=>{const n=this.txBatches[r].splice(0,15);return n.length<=15&&delete this.txBatches[r],new Promise((async i=>{if(0===n.length&&i(),!e[r])throw new Error(`Cannot sign batch for ${r}. No signing key provided.`);let o=await this.getStartingNonce(r),a=this.setBatchNonces(o,n);this.signBatch(a,e[r]),this.sendBatch(a).then((e=>{t=[...t,...e],i()}))}))})));try{return Promise.all(t)}catch(e){}finally{this.running=!1,this.processOverflow()}}setBatchNonces(e,t){return t.map(((t,r)=>(t.nonce=e.nonce+r,t.processor=e.processor,new ru({hosts:[e.masternode]},t)))).sort(((e,t)=>e.nonce-t.nonce))}signBatch(e,t){e.forEach((e=>e.sign(t)))}sendBatch(e){let t=[];return new Promise((r=>{e.forEach(((n,i)=>{setTimeout((()=>{t[i]=n.send().then((()=>n)),(n=>{n+1===e.length&&r(t)})(i)}),1200*i)}))}))}},Masternode_API:Gs,Blockservice_API:Xs,Network:eu,wallet:zs,Keystore:class{constructor(e){this.KEYSTORE_VERSION="1.0",this.password=null,this.encryptedData=null,this.keyList=(()=>{let e=[],t=this,r=[];const n=t=>{e.push(t),i()},i=()=>{r=[],e.forEach((e=>{let t=js({sk:e.sk,keepPrivate:!0});t={...t,...e},delete t.sk,r.push(t)}))};return{getWallets:()=>r,getWallet:e=>r.find((t=>t.vk===e)),addKey:n,clearKeys:()=>{e=[],i()},numOfKeys:()=>e.length,deleteKey:t=>{e.splice(t,1),i()},createKeystore:(r,n)=>JSON.stringify({data:x(r,{version:t.KEYSTORE_VERSION,keyList:e}),w:n?A("n1ahcKc0lb",n):""}),decryptKeystore:(e,r)=>{let i=R(e,r);if(!i)throw new Error("Incorrect Keystore Password.");iu.isArray(i.keyList),i.keyList.forEach((e=>iu.isStringWithValue(e.sk))),i.keyList.forEach((e=>n(e))),t.version=i.version}}})(),e&&(e.key&&this.addKey(e.key),e.keyList&&this.addKeys(e.keyList),e.keystoreData&&this.addKeystoreData(e.keystoreData))}addKeys(e){iu.isArray(e),e.forEach((e=>this.addKey(e)))}addKey(e){iu.isObjectWithKeys(e),iu.isStringWithValue(e.sk),nu.isStringWithValue(e.vk)&&delete e.vk,this.keyList.addKey(e)}addKeystoreData(e){nu.isString(e)&&(e=JSON.parse(e)),this.validateKeyStore(e)&&(this.encryptedData=e)}getPasswordHint(e){if(!this.encryptedData&&!e)throw new Error("No keystore data found.");return e?nu.isString(e)&&(e=JSON.parse(e)):e=this.encryptedData,e.w?T("n1ahcKc0lb",e.w):""}deleteKey(e){if(iu.isInteger(e),0!==this.keyList.numOfKeys()){if(e<0||e>=this.keyList.numOfKeys())throw new Error("Key index out of range.");this.keyList.deleteKey(e)}}clearKeys(){this.keyList.clearKeys()}get wallets(){return this.keyList.getWallets()}getWallet(e){return this.keyList.getWallet(e)}validateKeyStore(e){iu.isObjectWithKeys(e);try{let t=JSON.parse(e.data);if(!t.ct||!t.iv||!t.s)throw new Error("This is not a valid keystore file.")}catch(e){throw new Error("This is not a valid keystore file.")}return!0}createKeystore(e,t){return iu.isStringWithValue(e),t&&iu.isStringWithValue(t),this.keyList.createKeystore(e,t)}decryptKeystore(e,t){if(t&&this.addKeystoreData(t),!this.encryptedData)throw new Error("No keystoreData to decrypt.");try{this.keyList.decryptKeystore(e,this.encryptedData.data)}catch(e){throw new Error("Incorrect Keystore Password.")}}},Encoder:$s,utils:j};export{ou as default}; +!function(e,t){var r=Ne,n=r.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=o),o.prototype=Object.create(n.prototype),i(n,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=n(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(Fr,Fr.exports);var Kr={exports:{}},Yr=r(at),Hr=Yr.EventEmitter;function $r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Vr(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Gr(e,t){for(var r=0;r0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r}},{key:"concat",value:function(e){if(0===this.length)return Jr.alloc(0);for(var t,r,n,i=Jr.allocUnsafe(e>>>0),o=this.head,a=0;o;)t=o.data,r=i,n=a,Jr.prototype.copy.call(t,r,n),a+=o.data.length,o=o.next;return i}},{key:"consume",value:function(e,t){var r;return ei.length?i.length:e;if(o===i.length?n+=i:n+=i.slice(0,e),0==(e-=o)){o===i.length?(++r,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(o));break}++r}return this.length-=r,n}},{key:"_getBuffer",value:function(e){var t=Jr.allocUnsafe(e),r=this.head,n=1;for(r.data.copy(t),e-=r.data.length;r=r.next;){var i=r.data,o=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,o),0==(e-=o)){o===i.length?(++n,r.next?this.head=r.next:this.head=this.tail=null):(this.head=r,r.data=i.slice(o));break}++n}return this.length-=n,t}},{key:Zr,value:function(e,t){return Xr(this,function(e){for(var t=1;t2?"one of ".concat(t," ").concat(e.slice(0,r-1).join(", "),", or ")+e[r-1]:2===r?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}sn("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),sn("ERR_INVALID_ARG_TYPE",(function(e,t,r){var n,i,o,a;if("string"==typeof t&&(i="not ",t.substr(!o||o<0?0:+o,i.length)===i)?(n="must not be",t=t.replace(/^not /,"")):n="must be",function(e,t,r){return(void 0===r||r>e.length)&&(r=e.length),e.substring(r-t.length,r)===t}(e," argument"))a="The ".concat(e," ").concat(n," ").concat(un(t,"type"));else{var s=function(e,t,r){return"number"!=typeof r&&(r=0),!(r+t.length>e.length)&&-1!==e.indexOf(t,r)}(e,".")?"property":"argument";a='The "'.concat(e,'" ').concat(s," ").concat(n," ").concat(un(t,"type"))}return a+=". Received type ".concat(typeof r)}),TypeError),sn("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),sn("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),sn("ERR_STREAM_PREMATURE_CLOSE","Premature close"),sn("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),sn("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),sn("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),sn("ERR_STREAM_WRITE_AFTER_END","write after end"),sn("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),sn("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),sn("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),on.codes=an;var hn=on.codes.ERR_INVALID_OPT_VALUE;var ln={getHighWaterMark:function(e,t,r,n){var i=function(e,t,r){return null!=e.highWaterMark?e.highWaterMark:t?e[r]:null}(t,n,r);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new hn(n?r:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384}},fn={exports:{}};"function"==typeof Object.create?fn.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:fn.exports=function(e,t){if(t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}};var cn=function(e,t){if(dn("noDeprecation"))return e;var r=!1;return function(){if(!r){if(dn("throwDeprecation"))throw new Error(t);dn("traceDeprecation")?console.trace(t):console.warn(t),r=!0}return e.apply(this,arguments)}};function dn(t){try{if(!e.localStorage)return!1}catch(e){return!1}var r=e.localStorage[t];return null!=r&&"true"===String(r).toLowerCase()}var pn,gn=Cn;function yn(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,r){var n=e.entry;e.entry=null;for(;n;){var i=n.callback;t.pendingcb--,i(r),n=n.next}t.corkedRequestsFree.next=e}(t,e)}}Cn.WritableState=In;var bn={deprecate:cn},mn=Hr,vn=Ne.Buffer,wn=e.Uint8Array||function(){};var _n,En=nn,Sn=ln.getHighWaterMark,kn=on.codes,xn=kn.ERR_INVALID_ARG_TYPE,Rn=kn.ERR_METHOD_NOT_IMPLEMENTED,An=kn.ERR_MULTIPLE_CALLBACK,Tn=kn.ERR_STREAM_CANNOT_PIPE,Bn=kn.ERR_STREAM_DESTROYED,On=kn.ERR_STREAM_NULL_VALUES,Mn=kn.ERR_STREAM_WRITE_AFTER_END,jn=kn.ERR_UNKNOWN_ENCODING,Ln=En.errorOrDestroy;function Un(){}function In(e,t,r){pn=pn||Kn,e=e||{},"boolean"!=typeof r&&(r=t instanceof pn),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=Sn(this,e,"writableHighWaterMark",r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var n=!1===e.decodeStrings;this.decodeStrings=!n,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if("function"!=typeof i)throw new An;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(r),t)!function(e,t,r,n,i){--t.pendingcb,r?(Mt.nextTick(i,n),Mt.nextTick(Wn,e,t),e._writableState.errorEmitted=!0,Ln(e,n)):(i(n),e._writableState.errorEmitted=!0,Ln(e,n),Wn(e,t))}(e,r,n,t,i);else{var o=zn(r)||e.destroyed;o||r.corked||r.bufferProcessing||!r.bufferedRequest||Dn(e,r),n?Mt.nextTick(Pn,e,r,o,i):Pn(e,r,o,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new yn(this)}function Cn(e){var t=this instanceof(pn=pn||Kn);if(!t&&!_n.call(Cn,this))return new Cn(e);this._writableState=new In(e,this,t),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),mn.call(this)}function Nn(e,t,r,n,i,o,a){t.writelen=n,t.writecb=a,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new Bn("write")):r?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function Pn(e,t,r,n){r||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,n(),Wn(e,t)}function Dn(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),o=t.corkedRequestsFree;o.entry=r;for(var a=0,s=!0;r;)i[a]=r,r.isBuf||(s=!1),r=r.next,a+=1;i.allBuffers=s,Nn(e,t,!0,t.length,i,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new yn(t),t.bufferedRequestCount=0}else{for(;r;){var u=r.chunk,h=r.encoding,l=r.callback;if(Nn(e,t,!1,t.objectMode?1:u.length,u,h,l),r=r.next,t.bufferedRequestCount--,t.writing)break}null===r&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}function zn(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function qn(e,t){e._final((function(r){t.pendingcb--,r&&Ln(e,r),t.prefinished=!0,e.emit("prefinish"),Wn(e,t)}))}function Wn(e,t){var r=zn(t);if(r&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,Mt.nextTick(qn,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var n=e._readableState;(!n||n.autoDestroy&&n.endEmitted)&&e.destroy()}return r}fn.exports(Cn,mn),In.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(In.prototype,"buffer",{get:bn.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(_n=Function.prototype[Symbol.hasInstance],Object.defineProperty(Cn,Symbol.hasInstance,{value:function(e){return!!_n.call(this,e)||this===Cn&&(e&&e._writableState instanceof In)}})):_n=function(e){return e instanceof this},Cn.prototype.pipe=function(){Ln(this,new Tn)},Cn.prototype.write=function(e,t,r){var n,i=this._writableState,o=!1,a=!i.objectMode&&(n=e,vn.isBuffer(n)||n instanceof wn);return a&&!vn.isBuffer(e)&&(e=function(e){return vn.from(e)}(e)),"function"==typeof t&&(r=t,t=null),a?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof r&&(r=Un),i.ending?function(e,t){var r=new Mn;Ln(e,r),Mt.nextTick(t,r)}(this,r):(a||function(e,t,r,n){var i;return null===r?i=new On:"string"==typeof r||t.objectMode||(i=new xn("chunk",["string","Buffer"],r)),!i||(Ln(e,i),Mt.nextTick(n,i),!1)}(this,i,e,r))&&(i.pendingcb++,o=function(e,t,r,n,i,o){if(!r){var a=function(e,t,r){e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=vn.from(t,r));return t}(t,n,i);n!==a&&(r=!0,i="buffer",n=a)}var s=t.objectMode?1:n.length;t.length+=s;var u=t.length-1))throw new jn(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(Cn.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(Cn.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Cn.prototype._write=function(e,t,r){r(new Rn("_write()"))},Cn.prototype._writev=null,Cn.prototype.end=function(e,t,r){var n=this._writableState;return"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!=e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||function(e,t,r){t.ending=!0,Wn(e,t),r&&(t.finished?Mt.nextTick(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r),this},Object.defineProperty(Cn.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(Cn.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),Cn.prototype.destroy=En.destroy,Cn.prototype._undestroy=En.undestroy,Cn.prototype._destroy=function(e,t){t(e)};var Fn=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t},Kn=Jn,Yn=wi,Hn=gn;fn.exports(Jn,Yn);for(var $n=Fn(Hn.prototype),Vn=0;Vn<$n.length;Vn++){var Gn=$n[Vn];Jn.prototype[Gn]||(Jn.prototype[Gn]=Hn.prototype[Gn])}function Jn(e){if(!(this instanceof Jn))return new Jn(e);Yn.call(this,e),Hn.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",Xn)))}function Xn(){this._writableState.ended||Mt.nextTick(Zn,this)}function Zn(e){e.end()}Object.defineProperty(Jn.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(Jn.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(Jn.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(Jn.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}});var Qn=on.codes.ERR_STREAM_PREMATURE_CLOSE;function ei(){}var ti,ri=function e(t,r,n){if("function"==typeof r)return e(t,null,r);r||(r={}),n=function(e){var t=!1;return function(){if(!t){t=!0;for(var r=arguments.length,n=new Array(r),i=0;i0)if("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===Si.prototype||(t=function(e){return Si.from(e)}(t)),n)a.endEmitted?Pi(e,new Ni):Fi(e,a,t,!0);else if(a.ended)Pi(e,new Ii);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!r?(t=a.decoder.write(t),a.objectMode||0!==t.length?Fi(e,a,t,!1):$i(e,a)):Fi(e,a,t,!1)}else n||(a.reading=!1,$i(e,a));return!a.ended&&(a.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function Yi(e){var t=e._readableState;xi("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(xi("emitReadable",t.flowing),t.emittedReadable=!0,Mt.nextTick(Hi,e))}function Hi(e){var t=e._readableState;xi("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,Zi(e)}function $i(e,t){t.readingMore||(t.readingMore=!0,Mt.nextTick(Vi,e,t))}function Vi(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function Ji(e){xi("readable nexttick read 0"),e.read(0)}function Xi(e,t){xi("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),Zi(e),t.flowing&&!t.reading&&e.read(0)}function Zi(e){var t=e._readableState;for(xi("flow",t.flowing);t.flowing&&null!==e.read(););}function Qi(e,t){return 0===t.length?null:(t.objectMode?r=t.buffer.shift():!e||e>=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):r=t.buffer.consume(e,t.decoder),r);var r}function eo(e){var t=e._readableState;xi("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,Mt.nextTick(to,t,e))}function to(e,t){if(xi("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var r=t._writableState;(!r||r.autoDestroy&&r.finished)&&t.destroy()}}function ro(e,t){for(var r=0,n=e.length;r=t.highWaterMark:t.length>0)||t.ended))return xi("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?eo(this):Yi(this),null;if(0===(e=Ki(e,t))&&t.ended)return 0===t.length&&eo(this),null;var n,i=t.needReadable;return xi("need readable",i),(0===t.length||t.length-e0?Qi(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&eo(this)),null!==n&&this.emit("data",n),n},qi.prototype._read=function(e){Pi(this,new Ci("_read()"))},qi.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e)}n.pipesCount+=1,xi("pipe count=%d opts=%j",n.pipesCount,t);var i=(!t||!1!==t.end)&&e!==Mt.stdout&&e!==Mt.stderr?a:d;function o(t,i){xi("onunpipe"),t===r&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,xi("cleanup"),e.removeListener("close",f),e.removeListener("finish",c),e.removeListener("drain",s),e.removeListener("error",l),e.removeListener("unpipe",o),r.removeListener("end",a),r.removeListener("end",d),r.removeListener("data",h),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||s())}function a(){xi("onend"),e.end()}n.endEmitted?Mt.nextTick(i):r.once("end",i),e.on("unpipe",o);var s=function(e){return function(){var t=e._readableState;xi("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&_i(e,"data")&&(t.flowing=!0,Zi(e))}}(r);e.on("drain",s);var u=!1;function h(t){xi("ondata");var i=e.write(t);xi("dest.write",i),!1===i&&((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==ro(n.pipes,e))&&!u&&(xi("false write response, pause",n.awaitDrain),n.awaitDrain++),r.pause())}function l(t){xi("onerror",t),d(),e.removeListener("error",l),0===_i(e,"error")&&Pi(e,t)}function f(){e.removeListener("finish",c),d()}function c(){xi("onfinish"),e.removeListener("close",f),d()}function d(){xi("unpipe"),r.unpipe(e)}return r.on("data",h),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",l),e.once("close",f),e.once("finish",c),e.emit("pipe",r),n.flowing||(xi("pipe resume"),r.resume()),e},qi.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r)),this;if(!e){var n=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o0,!1!==n.flowing&&this.resume()):"readable"===e&&(n.endEmitted||n.readableListening||(n.readableListening=n.needReadable=!0,n.flowing=!1,n.emittedReadable=!1,xi("on readable",n.length,n.reading),n.length?Yi(this):n.reading||Mt.nextTick(Ji,this))),r},qi.prototype.addListener=qi.prototype.on,qi.prototype.removeListener=function(e,t){var r=Ei.prototype.removeListener.call(this,e,t);return"readable"===e&&Mt.nextTick(Gi,this),r},qi.prototype.removeAllListeners=function(e){var t=Ei.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||Mt.nextTick(Gi,this),t},qi.prototype.resume=function(){var e=this._readableState;return e.flowing||(xi("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,Mt.nextTick(Xi,e,t))}(this,e)),e.paused=!1,this},qi.prototype.pause=function(){return xi("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(xi("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},qi.prototype.wrap=function(e){var t=this,r=this._readableState,n=!1;for(var i in e.on("end",(function(){if(xi("wrapped end"),r.decoder&&!r.ended){var e=r.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(i){(xi("wrapped data"),r.decoder&&(i=r.decoder.write(i)),r.objectMode&&null==i)||(r.objectMode||i&&i.length)&&(t.push(i)||(n=!0,e.pause()))})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o0,(function(e){n||(n=e),e&&o.forEach(ko),a||(o.forEach(ko),i(n))}))}));return t.reduce(xo)};!function(e,t){(t=Kr.exports=wi).Stream=t,t.Readable=t,t.Writable=gn,t.Duplex=Kn,t.Transform=no,t.PassThrough=yo,t.finished=ri,t.pipeline=Ao}(0,Kr.exports);var To=Fr.exports.Buffer,Bo=Kr.exports.Transform;function Oo(e){Bo.call(this),this._block=To.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}(0,fn.exports)(Oo,Bo),Oo.prototype._transform=function(e,t,r){var n=null;try{this.update(e,t)}catch(e){n=e}r(n)},Oo.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},Oo.prototype.update=function(e,t){if(function(e,t){if(!To.isBuffer(e)&&"string"!=typeof e)throw new TypeError(t+" must be a string or a buffer")}(e,"Data"),this._finalized)throw new Error("Digest already called");To.isBuffer(e)||(e=To.from(e,t));for(var r=this._block,n=0;this._blockOffset+e.length-n>=this._blockSize;){for(var i=this._blockOffset;i0;++o)this._length[o]+=a,(a=this._length[o]/4294967296|0)>0&&(this._length[o]-=4294967296*a);return this},Oo.prototype._update=function(){throw new Error("_update is not implemented")},Oo.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return t},Oo.prototype._digest=function(){throw new Error("_digest is not implemented")};var Mo=Oo,jo=Ie.exports,Lo=Mo,Uo=Ce.exports.Buffer,Io=new Array(16);function Co(){Lo.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878}function No(e,t){return e<>>32-t}function Po(e,t,r,n,i,o,a){return No(e+(t&r|~t&n)+i+o|0,a)+t|0}function Do(e,t,r,n,i,o,a){return No(e+(t&n|r&~n)+i+o|0,a)+t|0}function zo(e,t,r,n,i,o,a){return No(e+(t^r^n)+i+o|0,a)+t|0}function qo(e,t,r,n,i,o,a){return No(e+(r^(t|~n))+i+o|0,a)+t|0}jo(Co,Lo),Co.prototype._update=function(){for(var e=Io,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var r=this._a,n=this._b,i=this._c,o=this._d;r=Po(r,n,i,o,e[0],3614090360,7),o=Po(o,r,n,i,e[1],3905402710,12),i=Po(i,o,r,n,e[2],606105819,17),n=Po(n,i,o,r,e[3],3250441966,22),r=Po(r,n,i,o,e[4],4118548399,7),o=Po(o,r,n,i,e[5],1200080426,12),i=Po(i,o,r,n,e[6],2821735955,17),n=Po(n,i,o,r,e[7],4249261313,22),r=Po(r,n,i,o,e[8],1770035416,7),o=Po(o,r,n,i,e[9],2336552879,12),i=Po(i,o,r,n,e[10],4294925233,17),n=Po(n,i,o,r,e[11],2304563134,22),r=Po(r,n,i,o,e[12],1804603682,7),o=Po(o,r,n,i,e[13],4254626195,12),i=Po(i,o,r,n,e[14],2792965006,17),r=Do(r,n=Po(n,i,o,r,e[15],1236535329,22),i,o,e[1],4129170786,5),o=Do(o,r,n,i,e[6],3225465664,9),i=Do(i,o,r,n,e[11],643717713,14),n=Do(n,i,o,r,e[0],3921069994,20),r=Do(r,n,i,o,e[5],3593408605,5),o=Do(o,r,n,i,e[10],38016083,9),i=Do(i,o,r,n,e[15],3634488961,14),n=Do(n,i,o,r,e[4],3889429448,20),r=Do(r,n,i,o,e[9],568446438,5),o=Do(o,r,n,i,e[14],3275163606,9),i=Do(i,o,r,n,e[3],4107603335,14),n=Do(n,i,o,r,e[8],1163531501,20),r=Do(r,n,i,o,e[13],2850285829,5),o=Do(o,r,n,i,e[2],4243563512,9),i=Do(i,o,r,n,e[7],1735328473,14),r=zo(r,n=Do(n,i,o,r,e[12],2368359562,20),i,o,e[5],4294588738,4),o=zo(o,r,n,i,e[8],2272392833,11),i=zo(i,o,r,n,e[11],1839030562,16),n=zo(n,i,o,r,e[14],4259657740,23),r=zo(r,n,i,o,e[1],2763975236,4),o=zo(o,r,n,i,e[4],1272893353,11),i=zo(i,o,r,n,e[7],4139469664,16),n=zo(n,i,o,r,e[10],3200236656,23),r=zo(r,n,i,o,e[13],681279174,4),o=zo(o,r,n,i,e[0],3936430074,11),i=zo(i,o,r,n,e[3],3572445317,16),n=zo(n,i,o,r,e[6],76029189,23),r=zo(r,n,i,o,e[9],3654602809,4),o=zo(o,r,n,i,e[12],3873151461,11),i=zo(i,o,r,n,e[15],530742520,16),r=qo(r,n=zo(n,i,o,r,e[2],3299628645,23),i,o,e[0],4096336452,6),o=qo(o,r,n,i,e[7],1126891415,10),i=qo(i,o,r,n,e[14],2878612391,15),n=qo(n,i,o,r,e[5],4237533241,21),r=qo(r,n,i,o,e[12],1700485571,6),o=qo(o,r,n,i,e[3],2399980690,10),i=qo(i,o,r,n,e[10],4293915773,15),n=qo(n,i,o,r,e[1],2240044497,21),r=qo(r,n,i,o,e[8],1873313359,6),o=qo(o,r,n,i,e[15],4264355552,10),i=qo(i,o,r,n,e[6],2734768916,15),n=qo(n,i,o,r,e[13],1309151649,21),r=qo(r,n,i,o,e[4],4149444226,6),o=qo(o,r,n,i,e[11],3174756917,10),i=qo(i,o,r,n,e[2],718787259,15),n=qo(n,i,o,r,e[9],3951481745,21),this._a=this._a+r|0,this._b=this._b+n|0,this._c=this._c+i|0,this._d=this._d+o|0},Co.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Uo.allocUnsafe(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e};var Wo=Co,Fo=Ne.Buffer,Ko=Ie.exports,Yo=Mo,Ho=new Array(16),$o=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],Vo=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],Go=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],Jo=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],Xo=[0,1518500249,1859775393,2400959708,2840853838],Zo=[1352829926,1548603684,1836072691,2053994217,0];function Qo(){Yo.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function ea(e,t){return e<>>32-t}function ta(e,t,r,n,i,o,a,s){return ea(e+(t^r^n)+o+a|0,s)+i|0}function ra(e,t,r,n,i,o,a,s){return ea(e+(t&r|~t&n)+o+a|0,s)+i|0}function na(e,t,r,n,i,o,a,s){return ea(e+((t|~r)^n)+o+a|0,s)+i|0}function ia(e,t,r,n,i,o,a,s){return ea(e+(t&n|r&~n)+o+a|0,s)+i|0}function oa(e,t,r,n,i,o,a,s){return ea(e+(t^(r|~n))+o+a|0,s)+i|0}Ko(Qo,Yo),Qo.prototype._update=function(){for(var e=Ho,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);for(var r=0|this._a,n=0|this._b,i=0|this._c,o=0|this._d,a=0|this._e,s=0|this._a,u=0|this._b,h=0|this._c,l=0|this._d,f=0|this._e,c=0;c<80;c+=1){var d,p;c<16?(d=ta(r,n,i,o,a,e[$o[c]],Xo[0],Go[c]),p=oa(s,u,h,l,f,e[Vo[c]],Zo[0],Jo[c])):c<32?(d=ra(r,n,i,o,a,e[$o[c]],Xo[1],Go[c]),p=ia(s,u,h,l,f,e[Vo[c]],Zo[1],Jo[c])):c<48?(d=na(r,n,i,o,a,e[$o[c]],Xo[2],Go[c]),p=na(s,u,h,l,f,e[Vo[c]],Zo[2],Jo[c])):c<64?(d=ia(r,n,i,o,a,e[$o[c]],Xo[3],Go[c]),p=ra(s,u,h,l,f,e[Vo[c]],Zo[3],Jo[c])):(d=oa(r,n,i,o,a,e[$o[c]],Xo[4],Go[c]),p=ta(s,u,h,l,f,e[Vo[c]],Zo[4],Jo[c])),r=a,a=o,o=ea(i,10),i=n,n=d,s=f,f=l,l=ea(h,10),h=u,u=p}var g=this._b+i+l|0;this._b=this._c+o+f|0,this._c=this._d+a+s|0,this._d=this._e+r+u|0,this._e=this._a+n+h|0,this._a=g},Qo.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=Fo.alloc?Fo.alloc(20):new Fo(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e};var aa=Qo,sa={exports:{}},ua=Ce.exports.Buffer;function ha(e,t){this._block=ua.alloc(e),this._finalSize=t,this._blockSize=e,this._len=0}ha.prototype.update=function(e,t){"string"==typeof e&&(t=t||"utf8",e=ua.from(e,t));for(var r=this._block,n=this._blockSize,i=e.length,o=this._len,a=0;a=this._finalSize&&(this._update(this._block),this._block.fill(0));var r=8*this._len;if(r<=4294967295)this._block.writeUInt32BE(r,this._blockSize-4);else{var n=(4294967295&r)>>>0,i=(r-n)/4294967296;this._block.writeUInt32BE(i,this._blockSize-8),this._block.writeUInt32BE(n,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},ha.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var la=ha,fa=Ie.exports,ca=la,da=Ce.exports.Buffer,pa=[1518500249,1859775393,-1894007588,-899497514],ga=new Array(80);function ya(){this.init(),this._w=ga,ca.call(this,64,56)}function ba(e){return e<<30|e>>>2}function ma(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}fa(ya,ca),ya.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},ya.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=r[u-3]^r[u-8]^r[u-14]^r[u-16];for(var h=0;h<80;++h){var l=~~(h/20),f=0|((t=n)<<5|t>>>27)+ma(l,i,o,a)+s+r[h]+pa[l];s=a,a=o,o=ba(i),i=n,n=f}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},ya.prototype._hash=function(){var e=da.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var va=ya,wa=Ie.exports,_a=la,Ea=Ce.exports.Buffer,Sa=[1518500249,1859775393,-1894007588,-899497514],ka=new Array(80);function xa(){this.init(),this._w=ka,_a.call(this,64,56)}function Ra(e){return e<<5|e>>>27}function Aa(e){return e<<30|e>>>2}function Ta(e,t,r,n){return 0===e?t&r|~t&n:2===e?t&r|t&n|r&n:t^r^n}wa(xa,_a),xa.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},xa.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0;u<16;++u)r[u]=e.readInt32BE(4*u);for(;u<80;++u)r[u]=(t=r[u-3]^r[u-8]^r[u-14]^r[u-16])<<1|t>>>31;for(var h=0;h<80;++h){var l=~~(h/20),f=Ra(n)+Ta(l,i,o,a)+s+r[h]+Sa[l]|0;s=a,a=o,o=Aa(i),i=n,n=f}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0},xa.prototype._hash=function(){var e=Ea.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e};var Ba=xa,Oa=Ie.exports,Ma=la,ja=Ce.exports.Buffer,La=[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],Ua=new Array(64);function Ia(){this.init(),this._w=Ua,Ma.call(this,64,56)}function Ca(e,t,r){return r^e&(t^r)}function Na(e,t,r){return e&t|r&(e|t)}function Pa(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function Da(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function za(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}Oa(Ia,Ma),Ia.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},Ia.prototype._update=function(e){for(var t,r=this._w,n=0|this._a,i=0|this._b,o=0|this._c,a=0|this._d,s=0|this._e,u=0|this._f,h=0|this._g,l=0|this._h,f=0;f<16;++f)r[f]=e.readInt32BE(4*f);for(;f<64;++f)r[f]=0|(((t=r[f-2])>>>17|t<<15)^(t>>>19|t<<13)^t>>>10)+r[f-7]+za(r[f-15])+r[f-16];for(var c=0;c<64;++c){var d=l+Da(s)+Ca(s,u,h)+La[c]+r[c]|0,p=Pa(n)+Na(n,i,o)|0;l=h,h=u,u=s,s=a+d|0,a=o,o=i,i=n,n=d+p|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=o+this._c|0,this._d=a+this._d|0,this._e=s+this._e|0,this._f=u+this._f|0,this._g=h+this._g|0,this._h=l+this._h|0},Ia.prototype._hash=function(){var e=ja.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e};var qa=Ia,Wa=Ie.exports,Fa=qa,Ka=la,Ya=Ce.exports.Buffer,Ha=new Array(64);function $a(){this.init(),this._w=Ha,Ka.call(this,64,56)}Wa($a,Fa),$a.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},$a.prototype._hash=function(){var e=Ya.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e};var Va=$a,Ga=Ie.exports,Ja=la,Xa=Ce.exports.Buffer,Za=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],Qa=new Array(160);function es(){this.init(),this._w=Qa,Ja.call(this,128,112)}function ts(e,t,r){return r^e&(t^r)}function rs(e,t,r){return e&t|r&(e|t)}function ns(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function is(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function os(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function as(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function ss(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function us(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function hs(e,t){return e>>>0>>0?1:0}Ga(es,Ja),es.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},es.prototype._update=function(e){for(var t=this._w,r=0|this._ah,n=0|this._bh,i=0|this._ch,o=0|this._dh,a=0|this._eh,s=0|this._fh,u=0|this._gh,h=0|this._hh,l=0|this._al,f=0|this._bl,c=0|this._cl,d=0|this._dl,p=0|this._el,g=0|this._fl,y=0|this._gl,b=0|this._hl,m=0;m<32;m+=2)t[m]=e.readInt32BE(4*m),t[m+1]=e.readInt32BE(4*m+4);for(;m<160;m+=2){var v=t[m-30],w=t[m-30+1],_=os(v,w),E=as(w,v),S=ss(v=t[m-4],w=t[m-4+1]),k=us(w,v),x=t[m-14],R=t[m-14+1],A=t[m-32],T=t[m-32+1],B=E+R|0,O=_+x+hs(B,E)|0;O=(O=O+S+hs(B=B+k|0,k)|0)+A+hs(B=B+T|0,T)|0,t[m]=O,t[m+1]=B}for(var M=0;M<160;M+=2){O=t[M],B=t[M+1];var j=rs(r,n,i),L=rs(l,f,c),U=ns(r,l),I=ns(l,r),C=is(a,p),N=is(p,a),P=Za[M],D=Za[M+1],z=ts(a,s,u),q=ts(p,g,y),W=b+N|0,F=h+C+hs(W,b)|0;F=(F=(F=F+z+hs(W=W+q|0,q)|0)+P+hs(W=W+D|0,D)|0)+O+hs(W=W+B|0,B)|0;var K=I+L|0,Y=U+j+hs(K,I)|0;h=u,b=y,u=s,y=g,s=a,g=p,a=o+F+hs(p=d+W|0,d)|0,o=i,d=c,i=n,c=f,n=r,f=l,r=F+Y+hs(l=W+K|0,W)|0}this._al=this._al+l|0,this._bl=this._bl+f|0,this._cl=this._cl+c|0,this._dl=this._dl+d|0,this._el=this._el+p|0,this._fl=this._fl+g|0,this._gl=this._gl+y|0,this._hl=this._hl+b|0,this._ah=this._ah+r+hs(this._al,l)|0,this._bh=this._bh+n+hs(this._bl,f)|0,this._ch=this._ch+i+hs(this._cl,c)|0,this._dh=this._dh+o+hs(this._dl,d)|0,this._eh=this._eh+a+hs(this._el,p)|0,this._fh=this._fh+s+hs(this._fl,g)|0,this._gh=this._gh+u+hs(this._gl,y)|0,this._hh=this._hh+h+hs(this._hl,b)|0},es.prototype._hash=function(){var e=Xa.allocUnsafe(64);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),t(this._gh,this._gl,48),t(this._hh,this._hl,56),e};var ls=es,fs=Ie.exports,cs=ls,ds=la,ps=Ce.exports.Buffer,gs=new Array(160);function ys(){this.init(),this._w=gs,ds.call(this,128,112)}fs(ys,cs),ys.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},ys.prototype._hash=function(){var e=ps.allocUnsafe(48);function t(t,r,n){e.writeInt32BE(t,n),e.writeInt32BE(r,n+4)}return t(this._ah,this._al,0),t(this._bh,this._bl,8),t(this._ch,this._cl,16),t(this._dh,this._dl,24),t(this._eh,this._el,32),t(this._fh,this._fl,40),e};var bs=ys,ms=sa.exports=function(e){e=e.toLowerCase();var t=ms[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t};ms.sha=va,ms.sha1=Ba,ms.sha224=Va,ms.sha256=qa,ms.sha384=bs,ms.sha512=ls;var vs=Ie.exports,ws=Wr,_s=Cr,Es=Ce.exports.Buffer,Ss=function(e){return(new Wo).update(e).digest()},ks=aa,xs=sa.exports,Rs=Es.alloc(128);function As(e,t){_s.call(this,"digest"),"string"==typeof t&&(t=Es.from(t));var r="sha512"===e||"sha384"===e?128:64;(this._alg=e,this._key=t,t.length>r)?t=("rmd160"===e?new ks:xs(e)).update(t).digest():t.length>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r,e[t+4]=n>>24&255,e[t+5]=n>>16&255,e[t+6]=n>>8&255,e[t+7]=255&n}function p(e,t,r,n,i){var o,a=0;for(o=0;o>>8)-1}function g(e,t,r,n){return p(e,t,r,n,16)}function y(e,t,r,n){return p(e,t,r,n,32)}function b(e,t,r,n){!function(e,t,r,n){for(var i,o=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,h=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,c=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,d=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,g=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,y=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,b=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,m=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,v=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,w=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,_=o,E=a,S=s,k=u,x=h,R=l,A=f,T=c,B=d,O=p,M=g,j=y,L=b,U=m,I=v,C=w,N=0;N<20;N+=2)_^=(i=(L^=(i=(B^=(i=(x^=(i=_+L|0)<<7|i>>>25)+_|0)<<9|i>>>23)+x|0)<<13|i>>>19)+B|0)<<18|i>>>14,R^=(i=(E^=(i=(U^=(i=(O^=(i=R+E|0)<<7|i>>>25)+R|0)<<9|i>>>23)+O|0)<<13|i>>>19)+U|0)<<18|i>>>14,M^=(i=(A^=(i=(S^=(i=(I^=(i=M+A|0)<<7|i>>>25)+M|0)<<9|i>>>23)+I|0)<<13|i>>>19)+S|0)<<18|i>>>14,C^=(i=(j^=(i=(T^=(i=(k^=(i=C+j|0)<<7|i>>>25)+C|0)<<9|i>>>23)+k|0)<<13|i>>>19)+T|0)<<18|i>>>14,_^=(i=(k^=(i=(S^=(i=(E^=(i=_+k|0)<<7|i>>>25)+_|0)<<9|i>>>23)+E|0)<<13|i>>>19)+S|0)<<18|i>>>14,R^=(i=(x^=(i=(T^=(i=(A^=(i=R+x|0)<<7|i>>>25)+R|0)<<9|i>>>23)+A|0)<<13|i>>>19)+T|0)<<18|i>>>14,M^=(i=(O^=(i=(B^=(i=(j^=(i=M+O|0)<<7|i>>>25)+M|0)<<9|i>>>23)+j|0)<<13|i>>>19)+B|0)<<18|i>>>14,C^=(i=(I^=(i=(U^=(i=(L^=(i=C+I|0)<<7|i>>>25)+C|0)<<9|i>>>23)+L|0)<<13|i>>>19)+U|0)<<18|i>>>14;_=_+o|0,E=E+a|0,S=S+s|0,k=k+u|0,x=x+h|0,R=R+l|0,A=A+f|0,T=T+c|0,B=B+d|0,O=O+p|0,M=M+g|0,j=j+y|0,L=L+b|0,U=U+m|0,I=I+v|0,C=C+w|0,e[0]=_>>>0&255,e[1]=_>>>8&255,e[2]=_>>>16&255,e[3]=_>>>24&255,e[4]=E>>>0&255,e[5]=E>>>8&255,e[6]=E>>>16&255,e[7]=E>>>24&255,e[8]=S>>>0&255,e[9]=S>>>8&255,e[10]=S>>>16&255,e[11]=S>>>24&255,e[12]=k>>>0&255,e[13]=k>>>8&255,e[14]=k>>>16&255,e[15]=k>>>24&255,e[16]=x>>>0&255,e[17]=x>>>8&255,e[18]=x>>>16&255,e[19]=x>>>24&255,e[20]=R>>>0&255,e[21]=R>>>8&255,e[22]=R>>>16&255,e[23]=R>>>24&255,e[24]=A>>>0&255,e[25]=A>>>8&255,e[26]=A>>>16&255,e[27]=A>>>24&255,e[28]=T>>>0&255,e[29]=T>>>8&255,e[30]=T>>>16&255,e[31]=T>>>24&255,e[32]=B>>>0&255,e[33]=B>>>8&255,e[34]=B>>>16&255,e[35]=B>>>24&255,e[36]=O>>>0&255,e[37]=O>>>8&255,e[38]=O>>>16&255,e[39]=O>>>24&255,e[40]=M>>>0&255,e[41]=M>>>8&255,e[42]=M>>>16&255,e[43]=M>>>24&255,e[44]=j>>>0&255,e[45]=j>>>8&255,e[46]=j>>>16&255,e[47]=j>>>24&255,e[48]=L>>>0&255,e[49]=L>>>8&255,e[50]=L>>>16&255,e[51]=L>>>24&255,e[52]=U>>>0&255,e[53]=U>>>8&255,e[54]=U>>>16&255,e[55]=U>>>24&255,e[56]=I>>>0&255,e[57]=I>>>8&255,e[58]=I>>>16&255,e[59]=I>>>24&255,e[60]=C>>>0&255,e[61]=C>>>8&255,e[62]=C>>>16&255,e[63]=C>>>24&255}(e,t,r,n)}function m(e,t,r,n){!function(e,t,r,n){for(var i,o=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,h=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,c=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,d=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,g=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,y=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,b=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,m=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,v=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,w=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,_=0;_<20;_+=2)o^=(i=(b^=(i=(d^=(i=(h^=(i=o+b|0)<<7|i>>>25)+o|0)<<9|i>>>23)+h|0)<<13|i>>>19)+d|0)<<18|i>>>14,l^=(i=(a^=(i=(m^=(i=(p^=(i=l+a|0)<<7|i>>>25)+l|0)<<9|i>>>23)+p|0)<<13|i>>>19)+m|0)<<18|i>>>14,g^=(i=(f^=(i=(s^=(i=(v^=(i=g+f|0)<<7|i>>>25)+g|0)<<9|i>>>23)+v|0)<<13|i>>>19)+s|0)<<18|i>>>14,w^=(i=(y^=(i=(c^=(i=(u^=(i=w+y|0)<<7|i>>>25)+w|0)<<9|i>>>23)+u|0)<<13|i>>>19)+c|0)<<18|i>>>14,o^=(i=(u^=(i=(s^=(i=(a^=(i=o+u|0)<<7|i>>>25)+o|0)<<9|i>>>23)+a|0)<<13|i>>>19)+s|0)<<18|i>>>14,l^=(i=(h^=(i=(c^=(i=(f^=(i=l+h|0)<<7|i>>>25)+l|0)<<9|i>>>23)+f|0)<<13|i>>>19)+c|0)<<18|i>>>14,g^=(i=(p^=(i=(d^=(i=(y^=(i=g+p|0)<<7|i>>>25)+g|0)<<9|i>>>23)+y|0)<<13|i>>>19)+d|0)<<18|i>>>14,w^=(i=(v^=(i=(m^=(i=(b^=(i=w+v|0)<<7|i>>>25)+w|0)<<9|i>>>23)+b|0)<<13|i>>>19)+m|0)<<18|i>>>14;e[0]=o>>>0&255,e[1]=o>>>8&255,e[2]=o>>>16&255,e[3]=o>>>24&255,e[4]=l>>>0&255,e[5]=l>>>8&255,e[6]=l>>>16&255,e[7]=l>>>24&255,e[8]=g>>>0&255,e[9]=g>>>8&255,e[10]=g>>>16&255,e[11]=g>>>24&255,e[12]=w>>>0&255,e[13]=w>>>8&255,e[14]=w>>>16&255,e[15]=w>>>24&255,e[16]=f>>>0&255,e[17]=f>>>8&255,e[18]=f>>>16&255,e[19]=f>>>24&255,e[20]=c>>>0&255,e[21]=c>>>8&255,e[22]=c>>>16&255,e[23]=c>>>24&255,e[24]=d>>>0&255,e[25]=d>>>8&255,e[26]=d>>>16&255,e[27]=d>>>24&255,e[28]=p>>>0&255,e[29]=p>>>8&255,e[30]=p>>>16&255,e[31]=p>>>24&255}(e,t,r,n)}var v=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(e,t,r,n,i,o,a){var s,u,h=new Uint8Array(16),l=new Uint8Array(64);for(u=0;u<16;u++)h[u]=0;for(u=0;u<8;u++)h[u]=o[u];for(;i>=64;){for(b(l,h,a,v),u=0;u<64;u++)e[t+u]=r[n+u]^l[u];for(s=1,u=8;u<16;u++)s=s+(255&h[u])|0,h[u]=255&s,s>>>=8;i-=64,t+=64,n+=64}if(i>0)for(b(l,h,a,v),u=0;u=64;){for(b(u,s,i,v),a=0;a<64;a++)e[t+a]=u[a];for(o=1,a=8;a<16;a++)o=o+(255&s[a])|0,s[a]=255&o,o>>>=8;r-=64,t+=64}if(r>0)for(b(u,s,i,v),a=0;a>>13|r<<3),n=255&e[4]|(255&e[5])<<8,this.r[2]=7939&(r>>>10|n<<6),i=255&e[6]|(255&e[7])<<8,this.r[3]=8191&(n>>>7|i<<9),o=255&e[8]|(255&e[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,a=255&e[10]|(255&e[11])<<8,this.r[6]=8191&(o>>>14|a<<2),s=255&e[12]|(255&e[13])<<8,this.r[7]=8065&(a>>>11|s<<5),u=255&e[14]|(255&e[15])<<8,this.r[8]=8191&(s>>>8|u<<8),this.r[9]=u>>>5&127,this.pad[0]=255&e[16]|(255&e[17])<<8,this.pad[1]=255&e[18]|(255&e[19])<<8,this.pad[2]=255&e[20]|(255&e[21])<<8,this.pad[3]=255&e[22]|(255&e[23])<<8,this.pad[4]=255&e[24]|(255&e[25])<<8,this.pad[5]=255&e[26]|(255&e[27])<<8,this.pad[6]=255&e[28]|(255&e[29])<<8,this.pad[7]=255&e[30]|(255&e[31])<<8};function x(e,t,r,n,i,o){var a=new k(o);return a.update(r,n,i),a.finish(e,t),0}function R(e,t,r,n,i,o){var a=new Uint8Array(16);return x(a,0,r,n,i,o),g(e,t,a,0)}function A(e,t,r,n,i){var o;if(r<32)return-1;for(S(e,0,t,0,r,n,i),x(e,16,e,32,r-32,e),o=0;o<16;o++)e[o]=0;return 0}function T(e,t,r,n,i){var o,a=new Uint8Array(32);if(r<32)return-1;if(E(a,0,32,n,i),0!==R(t,16,t,32,r-32,a))return-1;for(S(e,0,t,0,r,n,i),o=0;o<32;o++)e[o]=0;return 0}function B(e,t){var r;for(r=0;r<16;r++)e[r]=0|t[r]}function O(e){var t,r,n=1;for(t=0;t<16;t++)r=e[t]+n+65535,n=Math.floor(r/65536),e[t]=r-65536*n;e[0]+=n-1+37*(n-1)}function M(e,t,r){for(var n,i=~(r-1),o=0;o<16;o++)n=i&(e[o]^t[o]),e[o]^=n,t[o]^=n}function j(e,r){var n,i,o,a=t(),s=t();for(n=0;n<16;n++)s[n]=r[n];for(O(s),O(s),O(s),i=0;i<2;i++){for(a[0]=s[0]-65517,n=1;n<15;n++)a[n]=s[n]-65535-(a[n-1]>>16&1),a[n-1]&=65535;a[15]=s[15]-32767-(a[14]>>16&1),o=a[15]>>16&1,a[14]&=65535,M(s,a,1-o)}for(n=0;n<16;n++)e[2*n]=255&s[n],e[2*n+1]=s[n]>>8}function L(e,t){var r=new Uint8Array(32),n=new Uint8Array(32);return j(r,e),j(n,t),y(r,0,n,0)}function I(e){var t=new Uint8Array(32);return j(t,e),1&t[0]}function C(e,t){var r;for(r=0;r<16;r++)e[r]=t[2*r]+(t[2*r+1]<<8);e[15]&=32767}function N(e,t,r){for(var n=0;n<16;n++)e[n]=t[n]+r[n]}function P(e,t,r){for(var n=0;n<16;n++)e[n]=t[n]-r[n]}function D(e,t,r){var n,i,o=0,a=0,s=0,u=0,h=0,l=0,f=0,c=0,d=0,p=0,g=0,y=0,b=0,m=0,v=0,w=0,_=0,E=0,S=0,k=0,x=0,R=0,A=0,T=0,B=0,O=0,M=0,j=0,L=0,U=0,I=0,C=r[0],N=r[1],P=r[2],D=r[3],z=r[4],q=r[5],W=r[6],F=r[7],K=r[8],Y=r[9],H=r[10],$=r[11],V=r[12],G=r[13],J=r[14],X=r[15];o+=(n=t[0])*C,a+=n*N,s+=n*P,u+=n*D,h+=n*z,l+=n*q,f+=n*W,c+=n*F,d+=n*K,p+=n*Y,g+=n*H,y+=n*$,b+=n*V,m+=n*G,v+=n*J,w+=n*X,a+=(n=t[1])*C,s+=n*N,u+=n*P,h+=n*D,l+=n*z,f+=n*q,c+=n*W,d+=n*F,p+=n*K,g+=n*Y,y+=n*H,b+=n*$,m+=n*V,v+=n*G,w+=n*J,_+=n*X,s+=(n=t[2])*C,u+=n*N,h+=n*P,l+=n*D,f+=n*z,c+=n*q,d+=n*W,p+=n*F,g+=n*K,y+=n*Y,b+=n*H,m+=n*$,v+=n*V,w+=n*G,_+=n*J,E+=n*X,u+=(n=t[3])*C,h+=n*N,l+=n*P,f+=n*D,c+=n*z,d+=n*q,p+=n*W,g+=n*F,y+=n*K,b+=n*Y,m+=n*H,v+=n*$,w+=n*V,_+=n*G,E+=n*J,S+=n*X,h+=(n=t[4])*C,l+=n*N,f+=n*P,c+=n*D,d+=n*z,p+=n*q,g+=n*W,y+=n*F,b+=n*K,m+=n*Y,v+=n*H,w+=n*$,_+=n*V,E+=n*G,S+=n*J,k+=n*X,l+=(n=t[5])*C,f+=n*N,c+=n*P,d+=n*D,p+=n*z,g+=n*q,y+=n*W,b+=n*F,m+=n*K,v+=n*Y,w+=n*H,_+=n*$,E+=n*V,S+=n*G,k+=n*J,x+=n*X,f+=(n=t[6])*C,c+=n*N,d+=n*P,p+=n*D,g+=n*z,y+=n*q,b+=n*W,m+=n*F,v+=n*K,w+=n*Y,_+=n*H,E+=n*$,S+=n*V,k+=n*G,x+=n*J,R+=n*X,c+=(n=t[7])*C,d+=n*N,p+=n*P,g+=n*D,y+=n*z,b+=n*q,m+=n*W,v+=n*F,w+=n*K,_+=n*Y,E+=n*H,S+=n*$,k+=n*V,x+=n*G,R+=n*J,A+=n*X,d+=(n=t[8])*C,p+=n*N,g+=n*P,y+=n*D,b+=n*z,m+=n*q,v+=n*W,w+=n*F,_+=n*K,E+=n*Y,S+=n*H,k+=n*$,x+=n*V,R+=n*G,A+=n*J,T+=n*X,p+=(n=t[9])*C,g+=n*N,y+=n*P,b+=n*D,m+=n*z,v+=n*q,w+=n*W,_+=n*F,E+=n*K,S+=n*Y,k+=n*H,x+=n*$,R+=n*V,A+=n*G,T+=n*J,B+=n*X,g+=(n=t[10])*C,y+=n*N,b+=n*P,m+=n*D,v+=n*z,w+=n*q,_+=n*W,E+=n*F,S+=n*K,k+=n*Y,x+=n*H,R+=n*$,A+=n*V,T+=n*G,B+=n*J,O+=n*X,y+=(n=t[11])*C,b+=n*N,m+=n*P,v+=n*D,w+=n*z,_+=n*q,E+=n*W,S+=n*F,k+=n*K,x+=n*Y,R+=n*H,A+=n*$,T+=n*V,B+=n*G,O+=n*J,M+=n*X,b+=(n=t[12])*C,m+=n*N,v+=n*P,w+=n*D,_+=n*z,E+=n*q,S+=n*W,k+=n*F,x+=n*K,R+=n*Y,A+=n*H,T+=n*$,B+=n*V,O+=n*G,M+=n*J,j+=n*X,m+=(n=t[13])*C,v+=n*N,w+=n*P,_+=n*D,E+=n*z,S+=n*q,k+=n*W,x+=n*F,R+=n*K,A+=n*Y,T+=n*H,B+=n*$,O+=n*V,M+=n*G,j+=n*J,L+=n*X,v+=(n=t[14])*C,w+=n*N,_+=n*P,E+=n*D,S+=n*z,k+=n*q,x+=n*W,R+=n*F,A+=n*K,T+=n*Y,B+=n*H,O+=n*$,M+=n*V,j+=n*G,L+=n*J,U+=n*X,w+=(n=t[15])*C,a+=38*(E+=n*P),s+=38*(S+=n*D),u+=38*(k+=n*z),h+=38*(x+=n*q),l+=38*(R+=n*W),f+=38*(A+=n*F),c+=38*(T+=n*K),d+=38*(B+=n*Y),p+=38*(O+=n*H),g+=38*(M+=n*$),y+=38*(j+=n*V),b+=38*(L+=n*G),m+=38*(U+=n*J),v+=38*(I+=n*X),o=(n=(o+=38*(_+=n*N))+(i=1)+65535)-65536*(i=Math.floor(n/65536)),a=(n=a+i+65535)-65536*(i=Math.floor(n/65536)),s=(n=s+i+65535)-65536*(i=Math.floor(n/65536)),u=(n=u+i+65535)-65536*(i=Math.floor(n/65536)),h=(n=h+i+65535)-65536*(i=Math.floor(n/65536)),l=(n=l+i+65535)-65536*(i=Math.floor(n/65536)),f=(n=f+i+65535)-65536*(i=Math.floor(n/65536)),c=(n=c+i+65535)-65536*(i=Math.floor(n/65536)),d=(n=d+i+65535)-65536*(i=Math.floor(n/65536)),p=(n=p+i+65535)-65536*(i=Math.floor(n/65536)),g=(n=g+i+65535)-65536*(i=Math.floor(n/65536)),y=(n=y+i+65535)-65536*(i=Math.floor(n/65536)),b=(n=b+i+65535)-65536*(i=Math.floor(n/65536)),m=(n=m+i+65535)-65536*(i=Math.floor(n/65536)),v=(n=v+i+65535)-65536*(i=Math.floor(n/65536)),w=(n=w+i+65535)-65536*(i=Math.floor(n/65536)),o=(n=(o+=i-1+37*(i-1))+(i=1)+65535)-65536*(i=Math.floor(n/65536)),a=(n=a+i+65535)-65536*(i=Math.floor(n/65536)),s=(n=s+i+65535)-65536*(i=Math.floor(n/65536)),u=(n=u+i+65535)-65536*(i=Math.floor(n/65536)),h=(n=h+i+65535)-65536*(i=Math.floor(n/65536)),l=(n=l+i+65535)-65536*(i=Math.floor(n/65536)),f=(n=f+i+65535)-65536*(i=Math.floor(n/65536)),c=(n=c+i+65535)-65536*(i=Math.floor(n/65536)),d=(n=d+i+65535)-65536*(i=Math.floor(n/65536)),p=(n=p+i+65535)-65536*(i=Math.floor(n/65536)),g=(n=g+i+65535)-65536*(i=Math.floor(n/65536)),y=(n=y+i+65535)-65536*(i=Math.floor(n/65536)),b=(n=b+i+65535)-65536*(i=Math.floor(n/65536)),m=(n=m+i+65535)-65536*(i=Math.floor(n/65536)),v=(n=v+i+65535)-65536*(i=Math.floor(n/65536)),w=(n=w+i+65535)-65536*(i=Math.floor(n/65536)),o+=i-1+37*(i-1),e[0]=o,e[1]=a,e[2]=s,e[3]=u,e[4]=h,e[5]=l,e[6]=f,e[7]=c,e[8]=d,e[9]=p,e[10]=g,e[11]=y,e[12]=b,e[13]=m,e[14]=v,e[15]=w}function z(e,t){D(e,t,t)}function q(e,r){var n,i=t();for(n=0;n<16;n++)i[n]=r[n];for(n=253;n>=0;n--)z(i,i),2!==n&&4!==n&&D(i,i,r);for(n=0;n<16;n++)e[n]=i[n]}function W(e,r){var n,i=t();for(n=0;n<16;n++)i[n]=r[n];for(n=250;n>=0;n--)z(i,i),1!==n&&D(i,i,r);for(n=0;n<16;n++)e[n]=i[n]}function F(e,r,n){var i,o,a=new Uint8Array(32),u=new Float64Array(80),h=t(),l=t(),f=t(),c=t(),d=t(),p=t();for(o=0;o<31;o++)a[o]=r[o];for(a[31]=127&r[31]|64,a[0]&=248,C(u,n),o=0;o<16;o++)l[o]=u[o],c[o]=h[o]=f[o]=0;for(h[0]=c[0]=1,o=254;o>=0;--o)M(h,l,i=a[o>>>3]>>>(7&o)&1),M(f,c,i),N(d,h,f),P(h,h,f),N(f,l,c),P(l,l,c),z(c,d),z(p,h),D(h,f,h),D(f,l,d),N(d,h,f),P(h,h,f),z(l,h),P(f,c,p),D(h,f,s),N(h,h,c),D(f,f,h),D(h,c,p),D(c,l,u),z(l,d),M(h,l,i),M(f,c,i);for(o=0;o<16;o++)u[o+16]=h[o],u[o+32]=f[o],u[o+48]=l[o],u[o+64]=c[o];var g=u.subarray(32),y=u.subarray(16);return q(g,g),D(y,y,g),j(e,y),0}function K(e,t){return F(e,t,i)}function Y(e,t){return r(t,32),K(e,t)}function H(e,t,r){var i=new Uint8Array(32);return F(i,r,t),m(e,n,i,v)}k.prototype.blocks=function(e,t,r){for(var n,i,o,a,s,u,h,l,f,c,d,p,g,y,b,m,v,w,_,E=this.fin?0:2048,S=this.h[0],k=this.h[1],x=this.h[2],R=this.h[3],A=this.h[4],T=this.h[5],B=this.h[6],O=this.h[7],M=this.h[8],j=this.h[9],L=this.r[0],U=this.r[1],I=this.r[2],C=this.r[3],N=this.r[4],P=this.r[5],D=this.r[6],z=this.r[7],q=this.r[8],W=this.r[9];r>=16;)c=f=0,c+=(S+=8191&(n=255&e[t+0]|(255&e[t+1])<<8))*L,c+=(k+=8191&(n>>>13|(i=255&e[t+2]|(255&e[t+3])<<8)<<3))*(5*W),c+=(x+=8191&(i>>>10|(o=255&e[t+4]|(255&e[t+5])<<8)<<6))*(5*q),c+=(R+=8191&(o>>>7|(a=255&e[t+6]|(255&e[t+7])<<8)<<9))*(5*z),f=(c+=(A+=8191&(a>>>4|(s=255&e[t+8]|(255&e[t+9])<<8)<<12))*(5*D))>>>13,c&=8191,c+=(T+=s>>>1&8191)*(5*P),c+=(B+=8191&(s>>>14|(u=255&e[t+10]|(255&e[t+11])<<8)<<2))*(5*N),c+=(O+=8191&(u>>>11|(h=255&e[t+12]|(255&e[t+13])<<8)<<5))*(5*C),c+=(M+=8191&(h>>>8|(l=255&e[t+14]|(255&e[t+15])<<8)<<8))*(5*I),d=f+=(c+=(j+=l>>>5|E)*(5*U))>>>13,d+=S*U,d+=k*L,d+=x*(5*W),d+=R*(5*q),f=(d+=A*(5*z))>>>13,d&=8191,d+=T*(5*D),d+=B*(5*P),d+=O*(5*N),d+=M*(5*C),f+=(d+=j*(5*I))>>>13,d&=8191,p=f,p+=S*I,p+=k*U,p+=x*L,p+=R*(5*W),f=(p+=A*(5*q))>>>13,p&=8191,p+=T*(5*z),p+=B*(5*D),p+=O*(5*P),p+=M*(5*N),g=f+=(p+=j*(5*C))>>>13,g+=S*C,g+=k*I,g+=x*U,g+=R*L,f=(g+=A*(5*W))>>>13,g&=8191,g+=T*(5*q),g+=B*(5*z),g+=O*(5*D),g+=M*(5*P),y=f+=(g+=j*(5*N))>>>13,y+=S*N,y+=k*C,y+=x*I,y+=R*U,f=(y+=A*L)>>>13,y&=8191,y+=T*(5*W),y+=B*(5*q),y+=O*(5*z),y+=M*(5*D),b=f+=(y+=j*(5*P))>>>13,b+=S*P,b+=k*N,b+=x*C,b+=R*I,f=(b+=A*U)>>>13,b&=8191,b+=T*L,b+=B*(5*W),b+=O*(5*q),b+=M*(5*z),m=f+=(b+=j*(5*D))>>>13,m+=S*D,m+=k*P,m+=x*N,m+=R*C,f=(m+=A*I)>>>13,m&=8191,m+=T*U,m+=B*L,m+=O*(5*W),m+=M*(5*q),v=f+=(m+=j*(5*z))>>>13,v+=S*z,v+=k*D,v+=x*P,v+=R*N,f=(v+=A*C)>>>13,v&=8191,v+=T*I,v+=B*U,v+=O*L,v+=M*(5*W),w=f+=(v+=j*(5*q))>>>13,w+=S*q,w+=k*z,w+=x*D,w+=R*P,f=(w+=A*N)>>>13,w&=8191,w+=T*C,w+=B*I,w+=O*U,w+=M*L,_=f+=(w+=j*(5*W))>>>13,_+=S*W,_+=k*q,_+=x*z,_+=R*D,f=(_+=A*P)>>>13,_&=8191,_+=T*N,_+=B*C,_+=O*I,_+=M*U,S=c=8191&(f=(f=((f+=(_+=j*L)>>>13)<<2)+f|0)+(c&=8191)|0),k=d+=f>>>=13,x=p&=8191,R=g&=8191,A=y&=8191,T=b&=8191,B=m&=8191,O=v&=8191,M=w&=8191,j=_&=8191,t+=16,r-=16;this.h[0]=S,this.h[1]=k,this.h[2]=x,this.h[3]=R,this.h[4]=A,this.h[5]=T,this.h[6]=B,this.h[7]=O,this.h[8]=M,this.h[9]=j},k.prototype.finish=function(e,t){var r,n,i,o,a=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=r,r=this.h[o]>>>13,this.h[o]&=8191;for(this.h[0]+=5*r,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,a[0]=this.h[0]+5,r=a[0]>>>13,a[0]&=8191,o=1;o<10;o++)a[o]=this.h[o]+r,r=a[o]>>>13,a[o]&=8191;for(a[9]-=8192,n=(1^r)-1,o=0;o<10;o++)a[o]&=n;for(n=~n,o=0;o<10;o++)this.h[o]=this.h[o]&n|a[o];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;e[t+0]=this.h[0]>>>0&255,e[t+1]=this.h[0]>>>8&255,e[t+2]=this.h[1]>>>0&255,e[t+3]=this.h[1]>>>8&255,e[t+4]=this.h[2]>>>0&255,e[t+5]=this.h[2]>>>8&255,e[t+6]=this.h[3]>>>0&255,e[t+7]=this.h[3]>>>8&255,e[t+8]=this.h[4]>>>0&255,e[t+9]=this.h[4]>>>8&255,e[t+10]=this.h[5]>>>0&255,e[t+11]=this.h[5]>>>8&255,e[t+12]=this.h[6]>>>0&255,e[t+13]=this.h[6]>>>8&255,e[t+14]=this.h[7]>>>0&255,e[t+15]=this.h[7]>>>8&255},k.prototype.update=function(e,t,r){var n,i;if(this.leftover){for((i=16-this.leftover)>r&&(i=r),n=0;n=16&&(i=r-r%16,this.blocks(e,t,i),t+=i,r-=i),r){for(n=0;n=128;){for(E=0;E<16;E++)S=8*E+V,O[E]=r[S+0]<<24|r[S+1]<<16|r[S+2]<<8|r[S+3],M[E]=r[S+4]<<24|r[S+5]<<16|r[S+6]<<8|r[S+7];for(E=0;E<80;E++)if(i=j,o=L,a=U,s=I,u=C,h=N,l=P,c=z,d=q,p=W,g=F,y=K,b=Y,m=H,R=65535&(x=$),A=x>>>16,T=65535&(k=D),B=k>>>16,R+=65535&(x=(K>>>14|C<<18)^(K>>>18|C<<14)^(C>>>9|K<<23)),A+=x>>>16,T+=65535&(k=(C>>>14|K<<18)^(C>>>18|K<<14)^(K>>>9|C<<23)),B+=k>>>16,R+=65535&(x=K&Y^~K&H),A+=x>>>16,T+=65535&(k=C&N^~C&P),B+=k>>>16,R+=65535&(x=G[2*E+1]),A+=x>>>16,T+=65535&(k=G[2*E]),B+=k>>>16,k=O[E%16],A+=(x=M[E%16])>>>16,T+=65535&k,B+=k>>>16,T+=(A+=(R+=65535&x)>>>16)>>>16,R=65535&(x=_=65535&R|A<<16),A=x>>>16,T=65535&(k=w=65535&T|(B+=T>>>16)<<16),B=k>>>16,R+=65535&(x=(z>>>28|j<<4)^(j>>>2|z<<30)^(j>>>7|z<<25)),A+=x>>>16,T+=65535&(k=(j>>>28|z<<4)^(z>>>2|j<<30)^(z>>>7|j<<25)),B+=k>>>16,A+=(x=z&q^z&W^q&W)>>>16,T+=65535&(k=j&L^j&U^L&U),B+=k>>>16,f=65535&(T+=(A+=(R+=65535&x)>>>16)>>>16)|(B+=T>>>16)<<16,v=65535&R|A<<16,R=65535&(x=g),A=x>>>16,T=65535&(k=s),B=k>>>16,A+=(x=_)>>>16,T+=65535&(k=w),B+=k>>>16,L=i,U=o,I=a,C=s=65535&(T+=(A+=(R+=65535&x)>>>16)>>>16)|(B+=T>>>16)<<16,N=u,P=h,D=l,j=f,q=c,W=d,F=p,K=g=65535&R|A<<16,Y=y,H=b,$=m,z=v,E%16==15)for(S=0;S<16;S++)k=O[S],R=65535&(x=M[S]),A=x>>>16,T=65535&k,B=k>>>16,k=O[(S+9)%16],R+=65535&(x=M[(S+9)%16]),A+=x>>>16,T+=65535&k,B+=k>>>16,w=O[(S+1)%16],R+=65535&(x=((_=M[(S+1)%16])>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25)),A+=x>>>16,T+=65535&(k=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7),B+=k>>>16,w=O[(S+14)%16],A+=(x=((_=M[(S+14)%16])>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26))>>>16,T+=65535&(k=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6),B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,O[S]=65535&T|B<<16,M[S]=65535&R|A<<16;R=65535&(x=z),A=x>>>16,T=65535&(k=j),B=k>>>16,k=e[0],A+=(x=t[0])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[0]=j=65535&T|B<<16,t[0]=z=65535&R|A<<16,R=65535&(x=q),A=x>>>16,T=65535&(k=L),B=k>>>16,k=e[1],A+=(x=t[1])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[1]=L=65535&T|B<<16,t[1]=q=65535&R|A<<16,R=65535&(x=W),A=x>>>16,T=65535&(k=U),B=k>>>16,k=e[2],A+=(x=t[2])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[2]=U=65535&T|B<<16,t[2]=W=65535&R|A<<16,R=65535&(x=F),A=x>>>16,T=65535&(k=I),B=k>>>16,k=e[3],A+=(x=t[3])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[3]=I=65535&T|B<<16,t[3]=F=65535&R|A<<16,R=65535&(x=K),A=x>>>16,T=65535&(k=C),B=k>>>16,k=e[4],A+=(x=t[4])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[4]=C=65535&T|B<<16,t[4]=K=65535&R|A<<16,R=65535&(x=Y),A=x>>>16,T=65535&(k=N),B=k>>>16,k=e[5],A+=(x=t[5])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[5]=N=65535&T|B<<16,t[5]=Y=65535&R|A<<16,R=65535&(x=H),A=x>>>16,T=65535&(k=P),B=k>>>16,k=e[6],A+=(x=t[6])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[6]=P=65535&T|B<<16,t[6]=H=65535&R|A<<16,R=65535&(x=$),A=x>>>16,T=65535&(k=D),B=k>>>16,k=e[7],A+=(x=t[7])>>>16,T+=65535&k,B+=k>>>16,B+=(T+=(A+=(R+=65535&x)>>>16)>>>16)>>>16,e[7]=D=65535&T|B<<16,t[7]=$=65535&R|A<<16,V+=128,n-=128}return n}function X(e,t,r){var n,i=new Int32Array(8),o=new Int32Array(8),a=new Uint8Array(256),s=r;for(i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225,o[0]=4089235720,o[1]=2227873595,o[2]=4271175723,o[3]=1595750129,o[4]=2917565137,o[5]=725511199,o[6]=4215389547,o[7]=327033209,J(i,o,t,r),r%=128,n=0;n=0;--i)Q(e,t,n=r[i/8|0]>>(7&i)&1),Z(t,e),Z(e,e),Q(e,t,n)}function re(e,r){var n=[t(),t(),t(),t()];B(n[0],l),B(n[1],f),B(n[2],a),D(n[3],l,f),te(e,n,r)}function ne(e,n,i){var o,a=new Uint8Array(64),s=[t(),t(),t(),t()];for(i||r(n,32),X(a,n,32),a[0]&=248,a[31]&=127,a[31]|=64,re(s,a),ee(e,s),o=0;o<32;o++)n[o+32]=e[o];return 0}var ie=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function oe(e,t){var r,n,i,o;for(n=63;n>=32;--n){for(r=0,i=n-32,o=n-12;i>4)*ie[i],r=t[i]>>8,t[i]&=255;for(i=0;i<32;i++)t[i]-=r*ie[i];for(n=0;n<32;n++)t[n+1]+=t[n]>>8,e[n]=255&t[n]}function ae(e){var t,r=new Float64Array(64);for(t=0;t<64;t++)r[t]=e[t];for(t=0;t<64;t++)e[t]=0;oe(e,r)}function se(e,r,n,i){var o,a,s=new Uint8Array(64),u=new Uint8Array(64),h=new Uint8Array(64),l=new Float64Array(64),f=[t(),t(),t(),t()];X(s,i,32),s[0]&=248,s[31]&=127,s[31]|=64;var c=n+64;for(o=0;o>7&&P(e[0],o,e[0]),D(e[3],e[0],e[1]),0)}(d,i))return-1;for(s=0;s=0},e.sign.keyPair=function(){var e=new Uint8Array(fe),t=new Uint8Array(ce);return ne(e,t),{publicKey:e,secretKey:t}},e.sign.keyPair.fromSecretKey=function(e){if(pe(e),e.length!==ce)throw new Error("bad secret key size");for(var t=new Uint8Array(fe),r=0;re.replace("'",""),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.derivePath=e.isValidPath=e.getPublicKey=e.getMasterKeyFromSeed=void 0;const t=Ts,r=Bs.exports,n=Os;e.getMasterKeyFromSeed=e=>{const r=t("sha512","ed25519 seed").update(X.from(e,"hex")).digest();return{key:r.slice(0,32),chainCode:r.slice(32)}};e.getPublicKey=(e,t=!0)=>{const n=r.sign.keyPair.fromSeed(e).secretKey.subarray(32),i=X.alloc(1,0);return t?X.concat([i,X.from(n)]):X.from(n)},e.isValidPath=e=>!!n.pathRegex.test(e)&&!e.split("/").slice(1).map(n.replaceDerive).some(isNaN),e.derivePath=(r,i,o=2147483648)=>{if(!e.isValidPath(r))throw new Error("Invalid derivation path");const{key:a,chainCode:s}=e.getMasterKeyFromSeed(i);return r.split("/").slice(1).map(n.replaceDerive).map((e=>parseInt(e,10))).reduce(((e,r)=>(({key:e,chainCode:r},n)=>{const i=X.allocUnsafe(4);i.writeUInt32BE(n,0);const o=X.concat([X.alloc(1,0),e,i]),a=t("sha512",r).update(o).digest();return{key:a.slice(0,32),chainCode:a.slice(32)}})(e,r+o)),{key:a,chainCode:s})}}(Ue);var Ms=t(Ue);let js=(e={})=>{let t,{sk:r,keepPrivate:n=!1,seed:i=null}=e;if(r)t=Us(r);else{let e=Ns(i);t=e.vk,r=e.sk}return{sign:e=>Ps(r,e),verify:(e,r)=>Ds(t,e,r),vk:t,sk:n?void 0:r}};function Ls(e=null){var t=null;return t=null==e?I.sign.keyPair():I.sign.keyPair.fromSeed(e),{sk:new Uint8Array(t.secretKey.slice(0,32)),vk:new Uint8Array(t.secretKey.slice(32,64))}}function Us(e){return Cs(Is(e)).vk}function Is(e){return Ls(O(e))}function Cs(e){return{vk:B(e.vk),sk:B(e.sk)}}function Ns(e=null){return Cs(Ls(e))}function Ps(e,t){var r=Is(e),n=M(r.sk,r.vk);return B(I.sign.detached(t,n))}function Ds(e,t,r){var n=O(e),i=O(r);try{return I.sign.detached.verify(t,i,n)}catch(e){return!1}}var zs=Object.freeze({__proto__:null,create_wallet:js,generate_keys:Ls,get_vk:Us,format_to_keys:Is,keys_to_format:Cs,new_wallet:Ns,new_wallet_bip39:function(e,t=0){return function(e,t=0){let r,n;void 0!==e?r=e:(n=C.exports.generateMnemonic(256),r=C.exports.mnemonicToSeedSync(n).toString("hex"));const i="m/44'/789'/"+t+"'/0'/0'",{key:o,chainCode:a}=Ms.derivePath(i,r,2147483648),s=o.toString("hex"),u=Ms.getPublicKey(o,!1).toString("hex");if(u!==Us(s))throw Error("Bip32 public key does not match with Lamden public key!");return{sk:s,vk:u,derivationIndex:t,seed:void 0!==e?null:r,mnemonic:void 0!==e?null:n}}(e,t)},sign:Ps,verify:Ds,validateMnemonic:function(e,t){return C.exports.validateMnemonic(e,t)}});class qs{constructor(){this._events={}}on(e,t){this._events[e]||(this._events[e]=[]),this._events[e].push(t)}removeListener(e,t){if(!this._events[e])throw new Error(`Can't remove a listener. Event "${e}" doesn't exits.`);this._events[e]=this._events[e].filter((e=>e!==t))}emit(e,t){if(!this._events[e])return;this._events[e].forEach((e=>{e(t)}))}}var Ws={exports:{}};!function(e,t){var r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r)return r;throw new Error("unable to locate global object")}();e.exports=t=r.fetch,r.fetch&&(t.default=r.fetch.bind(r)),t.Headers=r.Headers,t.Request=r.Request,t.Response=r.Response}(Ws,Ws.exports);var Fs,Ks=Ws.exports,Ys={exports:{}};Fs=Ys,function(e){var t,r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,o="[BigNumber Error] ",a=o+"Number primitive has more than 15 significant digits: ",s=1e14,u=14,h=9007199254740991,l=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],f=1e7,c=1e9;function d(e){var t=0|e;return e>0||e===t?t:t-1}function p(e){for(var t,r,n=1,i=e.length,o=e[0]+"";nh^r?1:-1;for(s=(u=i.length)<(h=o.length)?u:h,a=0;ao[a]^r?1:-1;return u==h?0:u>h^r?1:-1}function y(e,t,r,n){if(er||e!==i(e))throw Error(o+(n||"Argument")+("number"==typeof e?er?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function b(e){var t=e.c.length-1;return d(e.e/u)==t&&e.c[t]%2!=0}function m(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function v(e,t,r){var n,i;if(t<0){for(i=r+".";++t;i+=r);e=i+e}else if(++t>(n=e.length)){for(i=r,t-=n;--t;i+=r);e+=i}else tN?g.c=g.e=null:e.e=10;f/=10,l++);return void(l>N?g.c=g.e=null:(g.e=l,g.c=[e]))}p=String(e)}else{if(!r.test(p=String(e)))return E(g,p,c);g.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(l=p.indexOf("."))>-1&&(p=p.replace(".","")),(f=p.search(/e/i))>0?(l<0&&(l=f),l+=+p.slice(f+1),p=p.substring(0,f)):l<0&&(l=p.length)}else{if(y(t,2,W.length,"Base"),10==t)return $(g=new F(e),j+g.e+1,L);if(p=String(e),c="number"==typeof e){if(0*e!=0)return E(g,p,c,t);if(g.s=1/e<0?(p=p.slice(1),-1):1,F.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(a+e)}else g.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=W.slice(0,t),l=f=0,d=p.length;fl){l=d;continue}}else if(!s&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){s=!0,f=-1,l=0;continue}return E(g,String(e),c,t)}c=!1,(l=(p=_(p,t,10,g.s)).indexOf("."))>-1?p=p.replace(".",""):l=p.length}for(f=0;48===p.charCodeAt(f);f++);for(d=p.length;48===p.charCodeAt(--d););if(p=p.slice(f,++d)){if(d-=f,c&&F.DEBUG&&d>15&&(e>h||e!==i(e)))throw Error(a+g.s*e);if((l=l-f-1)>N)g.c=g.e=null;else if(l=I)?m(u,a):v(u,a,"0");else if(o=(e=$(new F(e),t,r)).e,s=(u=p(e.c)).length,1==n||2==n&&(t<=o||o<=U)){for(;ss){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=o-s)>0)for(o+1==s&&(u+=".");t--;u+="0");return e.s<0&&i?"-"+u:u}function Y(e,t){for(var r,n=1,i=new F(e[0]);n=10;i/=10,n++);return(r=n+r*u-1)>N?e.c=e.e=null:r=10;c/=10,a++);if((h=t-a)<0)h+=u,f=t,g=(d=y[p=0])/b[a-f-1]%10|0;else if((p=n((h+1)/u))>=y.length){if(!o)break e;for(;y.length<=p;y.push(0));d=g=0,a=1,f=(h%=u)-u+1}else{for(d=c=y[p],a=1;c>=10;c/=10,a++);g=(f=(h%=u)-u+a)<0?0:d/b[a-f-1]%10|0}if(o=o||t<0||null!=y[p+1]||(f<0?d:d%b[a-f-1]),o=r<4?(g||o)&&(0==r||r==(e.s<0?3:2)):g>5||5==g&&(4==r||o||6==r&&(h>0?f>0?d/b[a-f]:0:y[p-1])%10&1||r==(e.s<0?8:7)),t<1||!y[0])return y.length=0,o?(t-=e.e+1,y[0]=b[(u-t%u)%u],e.e=-t||0):y[0]=e.e=0,e;if(0==h?(y.length=p,c=1,p--):(y.length=p+1,c=b[u-h],y[p]=f>0?i(d/b[a-f]%b[f])*c:0),o)for(;;){if(0==p){for(h=1,f=y[0];f>=10;f/=10,h++);for(f=y[0]+=c,c=1;f>=10;f/=10,c++);h!=c&&(e.e++,y[0]==s&&(y[0]=1));break}if(y[p]+=c,y[p]!=s)break;y[p--]=0,c=1}for(h=y.length;0===y[--h];y.pop());}e.e>N?e.c=e.e=null:e.e=I?m(t,r):v(t,r,"0"),e.s<0?"-"+t:t)}return F.clone=e,F.ROUND_UP=0,F.ROUND_DOWN=1,F.ROUND_CEIL=2,F.ROUND_FLOOR=3,F.ROUND_HALF_UP=4,F.ROUND_HALF_DOWN=5,F.ROUND_HALF_EVEN=6,F.ROUND_HALF_CEIL=7,F.ROUND_HALF_FLOOR=8,F.EUCLID=9,F.config=F.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(o+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(y(r=e[t],0,c,t),j=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(y(r=e[t],0,8,t),L=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(y(r[0],-c,0,t),y(r[1],0,c,t),U=r[0],I=r[1]):(y(r,-c,c,t),U=-(I=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)y(r[0],-c,-1,t),y(r[1],1,c,t),C=r[0],N=r[1];else{if(y(r,-c,c,t),!r)throw Error(o+t+" cannot be zero: "+r);C=-(N=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(o+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw P=!r,Error(o+"crypto unavailable");P=r}else P=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(y(r=e[t],0,9,t),D=r),e.hasOwnProperty(t="POW_PRECISION")&&(y(r=e[t],0,c,t),z=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(o+t+" not an object: "+r);q=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.$|[+-.\s]|(.).*\1/.test(r))throw Error(o+t+" invalid: "+r);W=r}}return{DECIMAL_PLACES:j,ROUNDING_MODE:L,EXPONENTIAL_AT:[U,I],RANGE:[C,N],CRYPTO:P,MODULO_MODE:D,POW_PRECISION:z,FORMAT:q,ALPHABET:W}},F.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!F.DEBUG)return!0;var t,r,n=e.c,a=e.e,h=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===h||-1===h)&&a>=-c&&a<=c&&a===i(a)){if(0===n[0]){if(0===a&&1===n.length)return!0;break e}if((t=(a+1)%u)<1&&(t+=u),String(n[0]).length==t){for(t=0;t=s||r!==i(r))break e;if(0!==r)return!0}}}else if(null===n&&null===a&&(null===h||1===h||-1===h))return!0;throw Error(o+"Invalid BigNumber: "+e)},F.maximum=F.max=function(){return Y(arguments,O.lt)},F.minimum=F.min=function(){return Y(arguments,O.gt)},F.random=(S=9007199254740992,k=Math.random()*S&2097151?function(){return i(Math.random()*S)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,a,s,h,f=0,d=[],p=new F(M);if(null==e?e=j:y(e,0,c),s=n(e/u),P)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(s*=2));f>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[f]=r[0],t[f+1]=r[1]):(d.push(h%1e14),f+=2);f=s/2}else{if(!crypto.randomBytes)throw P=!1,Error(o+"crypto unavailable");for(t=crypto.randomBytes(s*=7);f=9e15?crypto.randomBytes(7).copy(t,f):(d.push(h%1e14),f+=7);f=s/7}if(!P)for(;f=10;h/=10,f++);fr-1&&(null==a[i+1]&&(a[i+1]=0),a[i+1]+=a[i]/r|0,a[i]%=r)}return a.reverse()}return function(r,n,i,o,a){var s,u,h,l,f,c,d,g,y=r.indexOf("."),b=j,m=L;for(y>=0&&(l=z,z=0,r=r.replace(".",""),c=(g=new F(n)).pow(r.length-y),z=l,g.c=t(v(p(c.c),c.e,"0"),10,i,e),g.e=g.c.length),h=l=(d=t(r,n,i,a?(s=W,e):(s=e,W))).length;0==d[--l];d.pop());if(!d[0])return s.charAt(0);if(y<0?--h:(c.c=d,c.e=h,c.s=o,d=(c=w(c,g,b,m,i)).c,f=c.r,h=c.e),y=d[u=h+b+1],l=i/2,f=f||u<0||null!=d[u+1],f=m<4?(null!=y||f)&&(0==m||m==(c.s<0?3:2)):y>l||y==l&&(4==m||f||6==m&&1&d[u-1]||m==(c.s<0?8:7)),u<1||!d[0])r=f?v(s.charAt(1),-b,s.charAt(0)):s.charAt(0);else{if(d.length=u,f)for(--i;++d[--u]>i;)d[u]=0,u||(++h,d=[1].concat(d));for(l=d.length;!d[--l];);for(y=0,r="";y<=l;r+=s.charAt(d[y++]));r=v(r,h,s.charAt(0))}return r}}(),w=function(){function e(e,t,r){var n,i,o,a,s=0,u=e.length,h=t%f,l=t/f|0;for(e=e.slice();u--;)s=((i=h*(o=e[u]%f)+(n=l*o+(a=e[u]/f|0)*h)%f*f+s)/r|0)+(n/f|0)+l*a,e[u]=i%r;return s&&(e=[s].concat(e)),e}function t(e,t,r,n){var i,o;if(r!=n)o=r>n?1:-1;else for(i=o=0;it[i]?1:-1;break}return o}function r(e,t,r,n){for(var i=0;r--;)e[r]-=i,i=e[r]1;e.splice(0,1));}return function(n,o,a,h,l){var f,c,p,g,y,b,m,v,w,_,E,S,k,x,R,A,T,B=n.s==o.s?1:-1,O=n.c,M=o.c;if(!(O&&O[0]&&M&&M[0]))return new F(n.s&&o.s&&(O?!M||O[0]!=M[0]:M)?O&&0==O[0]||!M?0*B:B/0:NaN);for(w=(v=new F(B)).c=[],B=a+(c=n.e-o.e)+1,l||(l=s,c=d(n.e/u)-d(o.e/u),B=B/u|0),p=0;M[p]==(O[p]||0);p++);if(M[p]>(O[p]||0)&&c--,B<0)w.push(1),g=!0;else{for(x=O.length,A=M.length,p=0,B+=2,(y=i(l/(M[0]+1)))>1&&(M=e(M,y,l),O=e(O,y,l),A=M.length,x=O.length),k=A,E=(_=O.slice(0,A)).length;E=l/2&&R++;do{if(y=0,(f=t(M,_,A,E))<0){if(S=_[0],A!=E&&(S=S*l+(_[1]||0)),(y=i(S/R))>1)for(y>=l&&(y=l-1),m=(b=e(M,y,l)).length,E=_.length;1==t(b,_,m,E);)y--,r(b,A=10;B/=10,p++);$(v,a+(v.e=p+c*u-1)+1,h,g)}else v.e=c,v.r=+g;return v}}(),x=/^(-?)0([xbo])(?=\w[\w.]*$)/i,R=/^([^.]+)\.$/,A=/^\.([^.]+)$/,T=/^-?(Infinity|NaN)$/,B=/^\s*\+(?=[\w.])|^\s+|\s+$/g,E=function(e,t,r,n){var i,a=r?t:t.replace(B,"");if(T.test(a))e.s=isNaN(a)?null:a<0?-1:1;else{if(!r&&(a=a.replace(x,(function(e,t,r){return i="x"==(r=r.toLowerCase())?16:"b"==r?2:8,n&&n!=i?e:t})),n&&(i=n,a=a.replace(R,"$1").replace(A,"0.$1")),t!=a))return new F(a,i);if(F.DEBUG)throw Error(o+"Not a"+(n?" base "+n:"")+" number: "+t);e.s=null}e.c=e.e=null},O.absoluteValue=O.abs=function(){var e=new F(this);return e.s<0&&(e.s=1),e},O.comparedTo=function(e,t){return g(this,new F(e,t))},O.decimalPlaces=O.dp=function(e,t){var r,n,i,o=this;if(null!=e)return y(e,0,c),null==t?t=L:y(t,0,8),$(new F(o),e+o.e+1,t);if(!(r=o.c))return null;if(n=((i=r.length-1)-d(this.e/u))*u,i=r[i])for(;i%10==0;i/=10,n--);return n<0&&(n=0),n},O.dividedBy=O.div=function(e,t){return w(this,new F(e,t),j,L)},O.dividedToIntegerBy=O.idiv=function(e,t){return w(this,new F(e,t),0,1)},O.exponentiatedBy=O.pow=function(e,t){var r,a,s,h,l,f,c,d,p=this;if((e=new F(e)).c&&!e.isInteger())throw Error(o+"Exponent not an integer: "+V(e));if(null!=t&&(t=new F(t)),l=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return d=new F(Math.pow(+V(p),l?2-b(e):+V(e))),t?d.mod(t):d;if(f=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new F(NaN);(a=!f&&p.isInteger()&&t.isInteger())&&(p=p.mod(t))}else{if(e.e>9&&(p.e>0||p.e<-1||(0==p.e?p.c[0]>1||l&&p.c[1]>=24e7:p.c[0]<8e13||l&&p.c[0]<=9999975e7)))return h=p.s<0&&b(e)?-0:0,p.e>-1&&(h=1/h),new F(f?1/h:h);z&&(h=n(z/u+2))}for(l?(r=new F(.5),f&&(e.s=1),c=b(e)):c=(s=Math.abs(+V(e)))%2,d=new F(M);;){if(c){if(!(d=d.times(p)).c)break;h?d.c.length>h&&(d.c.length=h):a&&(d=d.mod(t))}if(s){if(0===(s=i(s/2)))break;c=s%2}else if($(e=e.times(r),e.e+1,1),e.e>14)c=b(e);else{if(0==(s=+V(e)))break;c=s%2}p=p.times(p),h?p.c&&p.c.length>h&&(p.c.length=h):a&&(p=p.mod(t))}return a?d:(f&&(d=M.div(d)),t?d.mod(t):h?$(d,z,L,void 0):d)},O.integerValue=function(e){var t=new F(this);return null==e?e=L:y(e,0,8),$(t,t.e+1,e)},O.isEqualTo=O.eq=function(e,t){return 0===g(this,new F(e,t))},O.isFinite=function(){return!!this.c},O.isGreaterThan=O.gt=function(e,t){return g(this,new F(e,t))>0},O.isGreaterThanOrEqualTo=O.gte=function(e,t){return 1===(t=g(this,new F(e,t)))||0===t},O.isInteger=function(){return!!this.c&&d(this.e/u)>this.c.length-2},O.isLessThan=O.lt=function(e,t){return g(this,new F(e,t))<0},O.isLessThanOrEqualTo=O.lte=function(e,t){return-1===(t=g(this,new F(e,t)))||0===t},O.isNaN=function(){return!this.s},O.isNegative=function(){return this.s<0},O.isPositive=function(){return this.s>0},O.isZero=function(){return!!this.c&&0==this.c[0]},O.minus=function(e,t){var r,n,i,o,a=this,h=a.s;if(t=(e=new F(e,t)).s,!h||!t)return new F(NaN);if(h!=t)return e.s=-t,a.plus(e);var l=a.e/u,f=e.e/u,c=a.c,p=e.c;if(!l||!f){if(!c||!p)return c?(e.s=-t,e):new F(p?a:NaN);if(!c[0]||!p[0])return p[0]?(e.s=-t,e):new F(c[0]?a:3==L?-0:0)}if(l=d(l),f=d(f),c=c.slice(),h=l-f){for((o=h<0)?(h=-h,i=c):(f=l,i=p),i.reverse(),t=h;t--;i.push(0));i.reverse()}else for(n=(o=(h=c.length)<(t=p.length))?h:t,h=t=0;t0)for(;t--;c[r++]=0);for(t=s-1;n>h;){if(c[--n]=0;){for(r=0,y=S[i]%w,b=S[i]/w|0,o=i+(a=l);o>i;)r=((c=y*(c=E[--a]%w)+(h=b*c+(p=E[a]/w|0)*y)%w*w+m[o]+r)/v|0)+(h/w|0)+b*p,m[o--]=c%v;m[o]=r}return r?++n:m.splice(0,1),H(e,m,n)},O.negated=function(){var e=new F(this);return e.s=-e.s||null,e},O.plus=function(e,t){var r,n=this,i=n.s;if(t=(e=new F(e,t)).s,!i||!t)return new F(NaN);if(i!=t)return e.s=-t,n.minus(e);var o=n.e/u,a=e.e/u,h=n.c,l=e.c;if(!o||!a){if(!h||!l)return new F(i/0);if(!h[0]||!l[0])return l[0]?e:new F(h[0]?n:0*i)}if(o=d(o),a=d(a),h=h.slice(),i=o-a){for(i>0?(a=o,r=l):(i=-i,r=h),r.reverse();i--;r.push(0));r.reverse()}for((i=h.length)-(t=l.length)<0&&(r=l,l=h,h=r,t=i),i=0;t;)i=(h[--t]=h[t]+l[t]+i)/s|0,h[t]=s===h[t]?0:h[t]%s;return i&&(h=[i].concat(h),++a),H(e,h,a)},O.precision=O.sd=function(e,t){var r,n,i,o=this;if(null!=e&&e!==!!e)return y(e,1,c),null==t?t=L:y(t,0,8),$(new F(o),e,t);if(!(r=o.c))return null;if(n=(i=r.length-1)*u+1,i=r[i]){for(;i%10==0;i/=10,n--);for(i=r[0];i>=10;i/=10,n++);}return e&&o.e+1>n&&(n=o.e+1),n},O.shiftedBy=function(e){return y(e,-9007199254740991,h),this.times("1e"+e)},O.squareRoot=O.sqrt=function(){var e,t,r,n,i,o=this,a=o.c,s=o.s,u=o.e,h=j+4,l=new F("0.5");if(1!==s||!a||!a[0])return new F(!s||s<0&&(!a||a[0])?NaN:a?o:1/0);if(0==(s=Math.sqrt(+V(o)))||s==1/0?(((t=p(a)).length+u)%2==0&&(t+="0"),s=Math.sqrt(+t),u=d((u+1)/2)-(u<0||u%2),r=new F(t=s==1/0?"1e"+u:(t=s.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new F(s+""),r.c[0])for((s=(u=r.e)+h)<3&&(s=0);;)if(i=r,r=l.times(i.plus(w(o,i,h,1))),p(i.c).slice(0,s)===(t=p(r.c)).slice(0,s)){if(r.e0&&g>0){for(a=g%u||u,f=p.substr(0,a);a0&&(f+=l+p.slice(a)),d&&(f="-"+f)}n=c?f+(r.decimalSeparator||"")+((h=+r.fractionGroupSize)?c.replace(new RegExp("\\d{"+h+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):c):f}return(r.prefix||"")+n+(r.suffix||"")},O.toFraction=function(e){var t,r,n,i,a,s,h,f,c,d,g,y,b=this,m=b.c;if(null!=e&&(!(h=new F(e)).isInteger()&&(h.c||1!==h.s)||h.lt(M)))throw Error(o+"Argument "+(h.isInteger()?"out of range: ":"not an integer: ")+V(h));if(!m)return new F(b);for(t=new F(M),c=r=new F(M),n=f=new F(M),y=p(m),a=t.e=y.length-b.e-1,t.c[0]=l[(s=a%u)<0?u+s:s],e=!e||h.comparedTo(t)>0?a>0?t:c:h,s=N,N=1/0,h=new F(y),f.c[0]=0;d=w(h,t,0,1),1!=(i=r.plus(d.times(n))).comparedTo(e);)r=n,n=i,c=f.plus(d.times(i=c)),f=i,t=h.minus(d.times(i=t)),h=i;return i=w(e.minus(r),n,0,1),f=f.plus(i.times(c)),r=r.plus(i.times(n)),f.s=c.s=b.s,g=w(c,n,a*=2,L).minus(b).abs().comparedTo(w(f,r,a,L).minus(b).abs())<1?[c,n]:[f,r],N=s,g},O.toNumber=function(){return+V(this)},O.toPrecision=function(e,t){return null!=e&&y(e,1,c),K(this,e,t,2)},O.toString=function(e){var t,r=this,n=r.s,i=r.e;return null===i?n?(t="Infinity",n<0&&(t="-"+t)):t="NaN":(null==e?t=i<=U||i>=I?m(p(r.c),i):v(p(r.c),i,"0"):10===e?t=v(p((r=$(new F(r),j+i+1,L)).c),r.e,"0"):(y(e,2,W.length,"Base"),t=_(v(p(r.c),i,"0"),10,e,n,!0)),n<0&&r.c[0]&&(t="-"+t)),t},O.valueOf=O.toJSON=function(){return V(this)},O._isBigNumber=!0,null!=t&&F.set(t),F}(),t.default=t.BigNumber=t,Fs.exports?Fs.exports=t:(e||(e="undefined"!=typeof self&&self?self:window),e.BigNumber=t)}(e);var Hs=Ys.exports;function $s(e,t){const r=t=>{throw new Error(`Error encoding ${t} to ${e}`)},n=e=>{if(Math.floor(e)===e)return 0;try{return e.toString().split(".")[1].length}catch(e){return 0}},i=e=>e&&"object"==typeof e&&e.constructor===Array,o=e=>e&&"object"==typeof e&&e.constructor===Object,a=e=>e instanceof Date,s=e=>!i(e)&&!isNaN(l(e).toNumber()),u=e=>!!s(e)&&0!==n(e),h=e=>(s(e)||r(e),Hs.isBigNumber(e)||(e=new Hs(e)),{__fixed__:e.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm,"$1$2")}),l=e=>(Hs.isBigNumber(e)||(e=new Hs(e)),e),f=e=>(e=>"boolean"==typeof e)(e)?e:"true"===e||1===e||"false"!==e&&0!==e&&void r(e),c=e=>(e=>"string"==typeof e||e instanceof String)(e)?e:a(e)?e.toISOString():JSON.stringify(e),d=e=>(e=a(e)?e:new Date(e),a(e)||r(e),{__time__:[e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()]}),p=e=>{const t=a(e)?e.getTime():new Date(e).getTime(),r=parseInt(t/1e3/60/60/24);return{__delta__:[r,(t-24*r*60*60*1e3)/1e3]}},g=e=>{if(i(e))return b(e);try{e=JSON.parse(e)}catch(t){r(e)}if(i(e))return b(e);r(e)},y=e=>{if(o(e))return b(e);try{e=JSON.parse(e)}catch(t){r(e)}if(o(e))return b(e);r(e)};function b(e){let t=JSON.stringify(e,((e,t)=>"datetime"===e||"datetime.datetime"===e?$s("datetime.datetime",t):"timedelta"===e||"datetime.timedelta"===e?$s("datetime.timedelta",t):"__fixed__"!==e&&u(t)?h(t):t));return JSON.parse(t,((e,t)=>{const r=e=>1===Object.keys(e).length&&["datetime.datetime","datetime","datetime.timedelta","timedelta"].filter((t=>t===Object.keys(e)[0])).length>0;return t.constructor===Array&&t.map((e=>1===Object.keys(e).length&&r(t)?e[Object.keys(e)[0]]:e)),t.constructor===Object&&1===Object.keys(t).length&&r(t)?t[Object.keys(t)[0]]:t}))}const m={str:c,string:c,float:h,int:e=>{if(s(e))return parseInt(e);r(e)},bool:f,boolean:f,dict:y,list:g,Any:()=>t,"datetime.timedelta":p,"datetime.datetime":d,timedelta:p,datetime:d,number:e=>(s(e)||r(e),u(e)?(Hs.isBigNumber(e)||(e=new Hs(e)),{__fixed__:e.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm,"$1$2")}):(e=>!!s(e)&&0===n(e))(e)?parseInt(e):void 0),object:e=>{try{return g(e)}catch(t){return y(e)}},bigNumber:l};if(Object.keys(m).includes(e))return m[e](t);throw new Error(`Error: ${e} is not a valid encoder type.`)}Hs.config({RANGE:[-30,30],EXPONENTIAL_AT:1e9}),Hs.set({DECIMAL_PLACES:30,ROUNDING_MODE:Hs.ROUND_DOWN}),$s.BigNumber=Hs;const{validateTypes:Vs}=o;class Gs{constructor(e){if(!Vs.isObjectWithKeys(e))throw new Error("Expected Object and got Type: "+typeof e);if(!Vs.isArrayWithValues(e.hosts))throw new Error("HOSTS Required (Type: Array)");this.hosts=this.validateHosts(e.hosts)}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Host String must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}send(e,t,r,n,i){let o="";Object.keys(r).includes("parms")&&(o=this.createParms(r.parms));let a={};if("POST"===e){let t={"Content-Type":"application/json"};a.method=e,a.headers=t,a.body=r}return Ks(`${n||this.url}${t}${o}`,a).then((async e=>{if(200===e.status){let t=await e.json();return i(t,void 0),t}{let t=!!Vs.isStringWithValue(e.statusText)&&e.statusText;return i(void 0,t),t}})).catch((e=>i(void 0,e.toString())))}createParms(e){if(0===Object.keys(e).length)return"";let t="?";return Object.keys(e).forEach((r=>{t=`${t}${r}=${e[r]}&`})),t.slice(0,-1)}async getContractInfo(e){const t=t=>{try{if(t.name)return t}catch(e){}return{error:`${e} does not exist`}};let r=`/contracts/${e}`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async getVariable(e,t,r=""){let n={};Vs.isStringWithValue(r)&&(n.key=r);let i=`/contracts/${e}/${t}/`;const o=e=>{try{if(e.value)return e.value}catch(e){}return null};return this.send("GET",i,{parms:n},void 0,((e,t)=>o(e))).then((e=>o(e)))}async getContractMethods(e){const t=e=>{try{if(e.methods)return e.methods}catch(e){}return[]};let r=`/contracts/${e}/methods`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async getContractVariables(e){const t=e=>{try{if(e.variables)return e}catch(e){}return{}};let r=`/contracts/${e}/variables`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async pingServer(){const e=e=>{try{if(e.status)return!0}catch(e){}return!1};let t=await this.send("GET","/ping",{},void 0,((t,r)=>e(t)));return e(t)}async getCurrencyBalance(e){let t=await this.getVariable("currency","balances",e);return t?t.__fixed__?$s("bigNumber",t.__fixed__):$s("bigNumber",t.toString()):$s("bigNumber",0)}async contractExists(e){const t=e=>{try{if(e.name)return!0}catch(e){}return!1};let r=`/contracts/${e}`;return this.send("GET",r,{},void 0,((e,r)=>t(e))).then((e=>t(e)))}async sendTransaction(e,t,r){return this.send("POST","/",JSON.stringify(e),t,((e,t)=>t?r?void r(void 0,t):t:r?void r(e,void 0):e))}async getNonce(e,t){if(!Vs.isStringHex(e))return`${e} is not a hex string.`;let r=`/nonce/${e}`,n=this.host;return this.send("GET",r,{},n,((r,i)=>i?t?void t(void 0,`Unable to get nonce for ${e} on network ${n}`):`Unable to get nonce for ${e} on network ${n}`:(r.masternode=n,t?void t(r,void 0):r)))}checkTransaction(e,t){const r={hash:e};return this.send("GET","/tx",{parms:r},void 0,((e,r)=>r?t?void t(void 0,r):r:t?void t(e,void 0):e))}async getLastetBlock(){return this.send("GET","/latest_block",{}).then((e=>e.json())).then((e=>({value:e.number}))).catch((e=>({error:e.message})))}}const{validateTypes:Js}=o;class Xs{constructor(e){if(!Js.isObjectWithKeys(e))throw new Error("Expected Network to be Object and got Type: "+typeof e);Js.isArrayWithValues(e.blockservice_hosts)?this.hosts=this.validateHosts(e.blockservice_hosts):this.hosts=[]}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Blockservice host value must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}send(e,t,r={},n){let i="";Object.keys(r).includes("parms")&&(i=this.createParms(r.parms));let o={};if("POST"===e){let t={"Content-Type":"application/json"};o.method=e,o.headers=t,o.body=r}return Ks(`${n||this.url}${t}${i}`,o)}createParms(e){if(0===Object.keys(e).length)return"";let t="?";return Object.keys(e).forEach((r=>{t=`${t}${r}=${e[r]}&`})),t.slice(0,-1)}async pingServer(){return this.send("GET","/ping",{}).then((e=>e.text())).then((e=>"pong"===e)).catch((()=>!1))}async getLastetBlock(e){return this.send("GET","/latest_block",{}).then((e=>e.json())).then((t=>(e&&e(t.latest_block,null),t.latest_block))).catch((t=>(e&&e(null,t.message),{error:t.message})))}async getBlocks(e,t=10,r){const n={start_block:e,limit:t};return this.send("GET","/blocks",{parms:n}).then((e=>e.json())).then((e=>(r&&r(e,null),e))).catch((e=>(r&&r(null,e.message),{error:e.message})))}async getCurrentKeyValue(e,t,r,n){return this.send("GET",`/current/one/${e}/${t}/${r}`).then((e=>e.json())).then((e=>(n&&n(e,null),e))).catch((e=>(n&&n(null,e.message),{error:e.message})))}async getCurrentKeysValues(e,t){try{let r="current/keys";return await this.send("POST",`/${r}`,JSON.stringify(e)).then((e=>e.json())).then((e=>(t&&t(e,null),e)))}catch(e){return t&&t(null,e.message),{error:e.message}}}async getTransaction(e,t){const r={hash:e};return this.send("GET","/tx",{parms:r}).then((e=>e.json())).then((e=>(t&&t(e,null),e))).catch((e=>e.message.includes("invalid json response body")?(t&&t(null,null),null):(t&&t(null,e.message),{error:e.message})))}async getContractInfo(e){return this.send("GET",`/contracts/${e}`,{}).then((e=>e.json())).then((t=>{if(Object.keys(t).length>0){let r=t[e];return{name:e,code:r.__code__}}return{error:`${e} does not exist`}})).catch((e=>({error:e.message})))}}const{validateTypes:Zs}=o,Qs=[1,2];class eu{constructor(e){if(!Zs.isObjectWithKeys(e))throw new Error("Expected Network Info Object and got Type: "+typeof e);if(!Zs.isArrayWithValues(e.hosts))throw new Error("HOSTS Required (Type: Array)");this.classname="Network",this.type=Zs.isStringWithValue(e.type)?e.type.toLowerCase():"custom",this.version=this.getNetworkVersion(e.version),this.events=new qs,this.hosts=this.validateHosts(e.hosts),this.currencySymbol=Zs.isStringWithValue(e.currencySymbol)?e.currencySymbol:"TAU",this.name=Zs.isStringWithValue(e.name)?e.name:"lamden network",this.lamden=!!Zs.isBoolean(e.lamden)&&e.lamden,this.blockExplorer=Zs.isStringWithValue(e.blockExplorer)?e.blockExplorer:void 0,this.online=!1;try{this.API=new Gs(e)}catch(e){throw new Error(e)}try{this.blockservice=new Xs(e)}catch(e){throw new Error(e)}}vaidateProtocol(e){if(["https://","http://"].map((t=>e.includes(t))).includes(!0))return e;throw new Error("Host String must include http:// or https://")}validateHosts(e){return e.map((e=>this.vaidateProtocol(e.toLowerCase())))}getNetworkVersion(e){return Zs.isInteger(e)&&Qs.includes(e)?e:1}async ping(e){return this.online=await this.API.pingServer(),this.events.emit("online",this.online),Zs.isFunction(e)&&e(this.online),this.online}get host(){return this.hosts[Math.floor(Math.random()*this.hosts.length)]}get url(){return this.host}getNetworkInfo(){return{name:this.name,lamden:this.lamden,type:this.type,hosts:this.hosts,blockservice_hosts:this.blockservice.hosts,url:this.url,online:this.online,version:this.version}}async pingServer(){let e;return e=this.blockservice.host?await this.blockservice.pingServer():await this.API.pingServer(),e}async getVariable(e,t,r){if(this.blockservice.host){return await this.blockservice.getCurrentKeyValue(e,t,r)}{let n=await this.API.getVariable(e,t,r);return n?{value:n}:{error:"key or variable not exists"}}}async getCurrencyBalance(e){return await this.getVariable("currency","balances",e)}async getContractInfo(e){return this.blockservice.host?await this.blockservice.getContractInfo(e):await this.API.getContractInfo(e)}async contractExists(e){let t;return t=this.blockservice.host?await this.blockservice.getContractInfo(e):await this.API.getContractInfo(e),!(!t||!t.name)}async getLastetBlock(){if(this.blockservice.host){let e=await this.blockservice.getLastetBlock();return e.error?e:{value:e}}return await this.API.getLastetBlock()}}const{validateTypes:tu}=o;class ru extends eu{constructor(e,t,r){if(e&&"Network"===e.classname?super(e.getNetworkInfo()):super(e),!tu.isObjectWithKeys(t))throw new Error("txInfo object not found");if(!tu.isStringHex(t.senderVk))throw new Error("Sender Public Key Required (Type: Hex String)");if(!tu.isStringWithValue(t.contractName))throw new Error("Contract Name Required (Type: String)");if(!tu.isStringWithValue(t.methodName))throw new Error("Method Required (Type: String)");if(!tu.isInteger(t.stampLimit))throw new Error("Stamps Limit Required (Type: Integer)");if(this.uid=tu.isStringWithValue(t.uid)?t.uid:void 0,this.sender=t.senderVk,this.contract=t.contractName,this.method=t.methodName,this.kwargs={},tu.isObject(t.kwargs)&&(this.kwargs=t.kwargs),this.stampLimit=t.stampLimit,void 0!==t.nonce){if(!tu.isInteger(t.nonce))throw new Error(`arg[6] Nonce is required to be an Integer, type ${typeof t.none} was given`);this.nonce=t.nonce}if(void 0!==t.processor){if(!tu.isStringWithValue(t.processor))throw new Error(`arg[7] Processor is required to be a String, type ${typeof t.processor} was given`);this.processor=t.processor}this.signature,this.transactionSigned=!1,this.nonceResult={},this.txSendResult={errors:[]},this.txBlockResult={},this.txHash,this.txCheckResult={},this.txCheckAttempts=0,this.txCheckLimit=10,this.maxBlockToCheck=15,this.startBlock=null,r&&(r.uid&&(this.uid=r.uid),tu.isObjectWithKeys(r.txSendResult)&&(this.txSendResult=r.txSendResult),tu.isObjectWithKeys(r.nonceResult)&&(this.nonceResult=r.nonceResult,tu.isInteger(this.nonceResult.nonce)&&(this.nonce=this.nonceResult.nonce),tu.isStringWithValue(this.nonceResult.processor)&&(this.processor=this.nonceResult.processor)),tu.isObjectWithKeys(r.txSendResult)&&(this.txSendResult=r.txSendResult,this.txSendResult.hash&&(this.txHash=this.txSendResult.hash)),tu.isObjectWithKeys(r.txBlockResult)&&(this.txBlockResult=r.txBlockResult),tu.isObjectWithKeys(r.resultInfo)&&(this.resultInfo=r.resultInfo)),this.makePayload()}makePayload(){this.payload={contract:this.contract,function:this.method,kwargs:this.kwargs,nonce:this.nonce,processor:this.processor,sender:this.sender,stamps_supplied:this.stampLimit},this.sortedPayload=this.sortObject(this.payload)}makeTransaction(){1===this.version&&(this.tx={metadata:{signature:this.signature,timestamp:parseInt(+new Date/1e3)},payload:this.sortedPayload.orderedObj}),2===this.version&&(this.tx={metadata:{signature:this.signature},payload:this.sortedPayload.orderedObj})}verifySignature(){if(!this.transactionSigned)throw new Error("Transaction has not be been signed. Use the sign() method first.");const e=Buffer.from(this.sortedPayload.json),t=new Uint8Array(e);return Ds(this.sender,t,this.signature)}sign(e,t){const r=Buffer.from(this.sortedPayload.json),n=new Uint8Array(r);this.signature=t?t.sign(n):Ps(e,n),this.transactionSigned=!0}sortObject(e){const t=(e=>{const t=e=>Object.prototype.toString.call(e),r=e=>"[object Object]"===t(e),n=e=>(Object.keys(e).forEach((i=>{var o;o=e[i],"[object Array]"===t(o)&&(e[i]=e[i].map((e=>r(e)?n(e):e))),r(e[i])&&(e[i]=n(e[i]))})),(e=>{const t={};return Object.keys(e).sort().forEach((r=>t[r]=e[r])),t})(e));if(!r(e))throw new TypeError("Not a valid Object");try{e=JSON.parse(JSON.stringify(e))}catch(e){throw new TypeError("Not a valid JSON Object")}return n(e)})(e);return{orderedObj:t,json:JSON.stringify(t)}}async getNonce(e){let t=(new Date).toUTCString();if(this.nonceResult=await this.API.getNonce(this.sender),void 0===this.nonceResult.nonce)throw new Error(this.nonceResult);return this.nonceResult.timestamp=t,this.nonce=this.nonceResult.nonce,this.processor=this.nonceResult.processor,this.nonceMasternode=this.nonceResult.masternode,this.makePayload(),e?e(this.nonceResult):this.nonceResult}async send(e,t,r){if(!tu.isStringWithValue(e)&&!this.transactionSigned)throw new Error("Transation Not Signed: Private key needed or call sign() first");this.blockservice.url&&await this.blockservice.pingServer()&&(this.startBlock=await this.blockservice.getLastetBlock());let n=(new Date).toUTCString();try{!isNaN(this.nonce)&&tu.isStringWithValue(this.processor)||await this.getNonce(),tu.isStringWithValue(e)&&this.sign(e),this.makeTransaction();let t=r;!t&&this.nonceMasternode&&(t=this.nonceMasternode);let n=await this.API.sendTransaction(this.tx,t);!n||tu.isStringWithValue(n)?this.txSendResult.errors=[n||"Unknown Transaction Error"]:n.error?this.txSendResult.errors=[n.error]:this.txSendResult=n}catch(e){this.txSendResult.errors=[e.message]}return this.txSendResult.timestamp=n,this.handleMasterNodeResponse(this.txSendResult,t)}checkForTransactionResult(e){return new Promise((t=>{let r=setTimeout(async function n(){this.txCheckAttempts=this.txCheckAttempts+1;let i=await this.API.checkTransaction(this.txHash),o=!1,a=(new Date).toUTCString();"string"!=typeof i&&i?i.error?"Transaction not found."===i.error?this.txCheckAttempts0&&(tu.isArray(this.txCheckResult.errors)||(this.txCheckResult.errors=[]),this.txCheckResult.errors.push("This transaction returned a non-zero status code")),this.txCheckResult.timestamp=a,clearTimeout(r),t(this.handleMasterNodeResponse(this.txCheckResult,e)))}.bind(this),1e3)}))}async checkTransactionResult(e){await checkBlockserviceForTransactionResult(e)}async checkBlockserviceForTransactionResult(e){if(!this.txHash)throw new Error("No transaction hash to check.");if(!await this.blockservice.pingServer())return console.log("Blockservice not available, failing back to masternode."),this.checkForTransactionResult(e).then((e=>({txinfo:e,...e})));let t=this.maxBlockToCheck;return new Promise((async r=>{let n=this.startBlock||0;const i=async()=>{t<1&&(this.txCheckResult.errors=[`No transaction result found within ${this.maxBlockToCheck} attempts.`],this.txCheckResult.status=2,r(this.handleMasterNodeResponse(this.txCheckResult,e))),t-=1;let a=await this.blockservice.getLastetBlock();a!==n?(n=a,o()):setTimeout(i,5e3)},o=async()=>{let n=await this.blockservice.getTransaction(this.txHash);n?(this.txCheckResult={...n,...n.txInfo},r(this.handleMasterNodeResponse(this.txCheckResult,e))):t<1?(this.txCheckResult.errors=[`No transaction result found within ${this.maxBlockToCheck} attempts.`],this.txCheckResult.status=2,r(this.handleMasterNodeResponse(this.txCheckResult,e))):setTimeout(i,5e3)};i()}))}handleMasterNodeResponse(e,t){return tu.isStringWithValue(e.hash)&&tu.isStringWithValue(e.success)?(this.txHash=e.hash,this.setPendingBlockInfo()):(this.setBlockResultInfo(e),this.txBlockResult=e),this.events.emit("response",e,this.resultInfo.subtitle),tu.isFunction(t)&&t(e),e}setPendingBlockInfo(){return this.resultInfo={title:"Transaction Pending",subtitle:"Your transaction was submitted and is being processed",message:`Tx Hash: ${this.txHash}`,type:"success"},this.resultInfo}setBlockResultInfo(e){let t=!1,r="returned an error and ",n=tu.isNumber(e.status)?e.status:void 0,i=e.stampsUsed||e.stamps_used||0,o="";return tu.isArrayWithValues(e.errors)&&(t=!0,o=`This transaction returned ${e.errors.length} errors.`,e.result&&e.result.includes("AssertionError")&&e.errors.push(e.result)),n&&t&&(r=`returned status code ${n} and `),this.resultInfo={title:"Transaction "+(t?"Failed":"Successful"),subtitle:`Your transaction ${t?`${r} `:""}used ${i} stamps`,message:o,type:""+(t?"error":"success"),errorInfo:t?e.errors:void 0,returnResult:e.result||"",stampsUsed:i,statusCode:n},this.resultInfo}getResultInfo(){return this.resultInfo}getTxInfo(){return{senderVk:this.sender,contractName:this.contract,methodName:this.method,kwargs:this.kwargs,stampLimit:this.stampLimit}}getAllInfo(){return{uid:this.uid,txHash:this.txHash,signed:this.transactionSigned,tx:this.tx,signature:this.signature,networkInfo:this.getNetworkInfo(),txInfo:this.getTxInfo(),txSendResult:this.txSendResult,txBlockResult:this.txBlockResult,resultInfo:this.getResultInfo(),nonceResult:this.nonceResult}}}const{validateTypes:nu,assertTypes:iu}=o;globalThis.Buffer=Ne.Buffer;var ou={TransactionBuilder:ru,TransactionBatcher:class extends eu{constructor(e){e&&"Network"===e.classname?super(e.getNetworkInfo()):super(e),this.txBatches={},this.overflow=[],this.nonceResults={},this.running=!1}addTransaction(e){this.running?this.overflow.push(e):(this.validateTransactionInfo(e),this.txBatches[e.senderVk]||(this.txBatches[e.senderVk]=[]),this.txBatches[e.senderVk].push(e))}addTransactionList(e){e.forEach((e=>this.addTransaction(e)))}processOverflow(){const e=this.overflow;this.overflow=[],e.forEach((e=>this.addTransaction(e)))}hasTransactions(){let e=Object.keys(this.txBatches).map((e=>this.txBatches[e].length));return e.filter((e=>0===e)),e.length>0}validateTransactionInfo(e){try{new ru(e)}catch(e){return!1}return!0}async getStartingNonce(e,t){let r=(new Date).toUTCString(),n=await this.API.getNonce(e);if(void 0===n.nonce)throw new Error(n);return n.timestamp=r,this.nonceResults[e]=n,t&&t(n),n}async sendAllBatches(e){if(this.running)return;let t=[];this.running=!0,await Promise.all(Object.keys(this.txBatches).map((r=>{const n=this.txBatches[r].splice(0,15);return n.length<=15&&delete this.txBatches[r],new Promise((async i=>{if(0===n.length&&i(),!e[r])throw new Error(`Cannot sign batch for ${r}. No signing key provided.`);let o=await this.getStartingNonce(r),a=this.setBatchNonces(o,n);this.signBatch(a,e[r]),this.sendBatch(a).then((e=>{t=[...t,...e],i()}))}))})));try{return Promise.all(t)}catch(e){}finally{this.running=!1,this.processOverflow()}}setBatchNonces(e,t){return t.map(((t,r)=>(t.nonce=e.nonce+r,t.processor=e.processor,new ru({hosts:[e.masternode]},t)))).sort(((e,t)=>e.nonce-t.nonce))}signBatch(e,t){e.forEach((e=>e.sign(t)))}sendBatch(e){let t=[];return new Promise((r=>{e.forEach(((n,i)=>{setTimeout((()=>{t[i]=n.send().then((()=>n)),(n=>{n+1===e.length&&r(t)})(i)}),1200*i)}))}))}},Masternode_API:Gs,Blockservice_API:Xs,Network:eu,wallet:zs,Keystore:class{constructor(e){this.KEYSTORE_VERSION="1.0",this.password=null,this.encryptedData=null,this.keyList=(()=>{let e=[],t=this,r=[];const n=t=>{e.push(t),i()},i=()=>{r=[],e.forEach((e=>{let t=js({sk:e.sk,keepPrivate:!0});t={...t,...e},delete t.sk,r.push(t)}))};return{getWallets:()=>r,getWallet:e=>r.find((t=>t.vk===e)),addKey:n,clearKeys:()=>{e=[],i()},numOfKeys:()=>e.length,deleteKey:t=>{e.splice(t,1),i()},createKeystore:(r,n)=>JSON.stringify({data:x(r,{version:t.KEYSTORE_VERSION,keyList:e}),w:n?A("n1ahcKc0lb",n):""}),decryptKeystore:(e,r)=>{let i=R(e,r);if(!i)throw new Error("Incorrect Keystore Password.");iu.isArray(i.keyList),i.keyList.forEach((e=>iu.isStringWithValue(e.sk))),i.keyList.forEach((e=>n(e))),t.version=i.version}}})(),e&&(e.key&&this.addKey(e.key),e.keyList&&this.addKeys(e.keyList),e.keystoreData&&this.addKeystoreData(e.keystoreData))}addKeys(e){iu.isArray(e),e.forEach((e=>this.addKey(e)))}addKey(e){iu.isObjectWithKeys(e),iu.isStringWithValue(e.sk),nu.isStringWithValue(e.vk)&&delete e.vk,this.keyList.addKey(e)}addKeystoreData(e){nu.isString(e)&&(e=JSON.parse(e)),this.validateKeyStore(e)&&(this.encryptedData=e)}getPasswordHint(e){if(!this.encryptedData&&!e)throw new Error("No keystore data found.");return e?nu.isString(e)&&(e=JSON.parse(e)):e=this.encryptedData,e.w?T("n1ahcKc0lb",e.w):""}deleteKey(e){if(iu.isInteger(e),0!==this.keyList.numOfKeys()){if(e<0||e>=this.keyList.numOfKeys())throw new Error("Key index out of range.");this.keyList.deleteKey(e)}}clearKeys(){this.keyList.clearKeys()}get wallets(){return this.keyList.getWallets()}getWallet(e){return this.keyList.getWallet(e)}validateKeyStore(e){iu.isObjectWithKeys(e);try{let t=JSON.parse(e.data);if(!t.ct||!t.iv||!t.s)throw new Error("This is not a valid keystore file.")}catch(e){throw new Error("This is not a valid keystore file.")}return!0}createKeystore(e,t){return iu.isStringWithValue(e),t&&iu.isStringWithValue(t),this.keyList.createKeystore(e,t)}decryptKeystore(e,t){if(t&&this.addKeystoreData(t),!this.encryptedData)throw new Error("No keystoreData to decrypt.");try{this.keyList.decryptKeystore(e,this.encryptedData.data)}catch(e){throw new Error("Incorrect Keystore Password.")}}},Encoder:$s,utils:j};export{ou as default}; diff --git a/package-lock.json b/package-lock.json index b434d39..cef3807 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lamden-js", - "version": "3.7.0", + "version": "3.7.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "lamden-js", - "version": "3.7.0", + "version": "3.7.5", "license": "MIT", "dependencies": { "assert": "1.4.1", @@ -30,7 +30,7 @@ "expect.js": "^0.3.1", "koa": "^2.13.4", "koa-static": "^5.0.0", - "mocha": "^7.2.0", + "mocha": "^10.0.0", "rollup": "^2.60.0", "rollup-plugin-polyfill-node": "^0.7.0", "rollup-plugin-terser": "^7.0.2", @@ -416,23 +416,6 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, - "node_modules/@rollup/plugin-commonjs/node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - } - }, "node_modules/@rollup/plugin-commonjs/node_modules/is-reference": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", @@ -583,6 +566,12 @@ "@types/node": "*" } }, + "node_modules/@ungap/promise-all-settled": { + "version": "1.1.2", + "resolved": "https://registry.npmmirror.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", + "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", + "dev": true + }, "node_modules/accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -657,21 +646,21 @@ } }, "node_modules/ansi-colors": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", - "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", + "version": "4.1.1", + "resolved": "https://registry.npmmirror.com/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/ansi-styles": { @@ -687,9 +676,9 @@ } }, "node_modules/anymatch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", - "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "version": "3.1.2", + "resolved": "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", "dev": true, "dependencies": { "normalize-path": "^3.0.0", @@ -700,13 +689,10 @@ } }, "node_modules/argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "dependencies": { - "sprintf-js": "~1.0.2" - } + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true }, "node_modules/array-union": { "version": "2.1.0", @@ -762,9 +748,9 @@ } }, "node_modules/binary-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", - "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", + "version": "2.2.0", + "resolved": "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true, "engines": { "node": ">=8" @@ -810,7 +796,7 @@ }, "node_modules/browser-stdout": { "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "resolved": "https://registry.npmmirror.com/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, @@ -862,12 +848,12 @@ } }, "node_modules/camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "version": "6.3.0", + "resolved": "https://registry.npmmirror.com/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/chalk": { @@ -897,24 +883,24 @@ } }, "node_modules/chokidar": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.0.tgz", - "integrity": "sha512-dGmKLDdT3Gdl7fBUe8XK+gAtGmzy5Fn0XkkWQuYxGIgWVPPse2CxFA5mtrlD0TOHaHjEUqkWNyP1XdHoJES/4A==", + "version": "3.5.3", + "resolved": "https://registry.npmmirror.com/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, "dependencies": { - "anymatch": "~3.1.1", + "anymatch": "~3.1.2", "braces": "~3.0.2", - "glob-parent": "~5.1.0", + "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", - "readdirp": "~3.2.0" + "readdirp": "~3.6.0" }, "engines": { "node": ">= 8.10.0" }, "optionalDependencies": { - "fsevents": "~2.1.1" + "fsevents": "~2.3.2" } }, "node_modules/chromedriver": { @@ -958,49 +944,14 @@ } }, "node_modules/cliui": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", - "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", - "dev": true, - "dependencies": { - "string-width": "^3.1.0", - "strip-ansi": "^5.2.0", - "wrap-ansi": "^5.1.0" - } - }, - "node_modules/cliui/node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/cliui/node_modules/string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "version": "7.0.4", + "resolved": "https://registry.npmmirror.com/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", "dev": true, "dependencies": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/cliui/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dev": true, - "dependencies": { - "ansi-regex": "^4.1.0" - }, - "engines": { - "node": ">=6" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" } }, "node_modules/co": { @@ -1142,12 +1093,12 @@ } }, "node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true, "engines": { - "node": ">=0.10.0" + "node": ">=10" } }, "node_modules/deep-equal": { @@ -1171,18 +1122,6 @@ "node": ">=0.10.0" } }, - "node_modules/define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, - "dependencies": { - "object-keys": "^1.0.12" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/del": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/del/-/del-6.0.0.tgz", @@ -1251,9 +1190,9 @@ "dev": true }, "node_modules/diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true, "engines": { "node": ">=0.3.1" @@ -1318,9 +1257,9 @@ "dev": true }, "node_modules/emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "version": "8.0.0", + "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, "node_modules/encodeurl": { @@ -1341,40 +1280,13 @@ "once": "^1.4.0" } }, - "node_modules/es-abstract": { - "version": "1.17.5", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", - "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", - "dev": true, - "dependencies": { - "es-to-primitive": "^1.2.1", - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.1", - "is-callable": "^1.1.5", - "is-regex": "^1.0.5", - "object-inspect": "^1.7.0", - "object-keys": "^1.1.1", - "object.assign": "^4.1.0", - "string.prototype.trimleft": "^2.1.1", - "string.prototype.trimright": "^2.1.1" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-to-primitive": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", - "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "node_modules/escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmmirror.com/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", "dev": true, - "dependencies": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" - }, "engines": { - "node": ">= 0.4" + "node": ">=6" } }, "node_modules/escape-html": { @@ -1392,19 +1304,6 @@ "node": ">=0.8.0" } }, - "node_modules/esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true, - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -1510,25 +1409,23 @@ } }, "node_modules/find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "dependencies": { - "locate-path": "^3.0.0" + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/flat": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", - "integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==", + "version": "5.0.2", + "resolved": "https://registry.npmmirror.com/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, - "dependencies": { - "is-buffer": "~2.0.3" - }, "bin": { "flat": "cli.js" } @@ -1583,10 +1480,11 @@ "dev": true }, "node_modules/fsevents": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", - "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "version": "2.3.2", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, + "hasInstallScript": true, "optional": true, "os": [ "darwin" @@ -1612,7 +1510,7 @@ }, "node_modules/get-caller-file": { "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "resolved": "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true, "engines": { @@ -1635,9 +1533,9 @@ } }, "node_modules/glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -1698,15 +1596,6 @@ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", "dev": true }, - "node_modules/growl": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", - "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", - "dev": true, - "engines": { - "node": ">=4.x" - } - }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -1793,7 +1682,7 @@ }, "node_modules/he": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "resolved": "https://registry.npmmirror.com/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, "bin": { @@ -1936,7 +1825,7 @@ }, "node_modules/is-binary-path": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "resolved": "https://registry.npmmirror.com/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, "dependencies": { @@ -1946,24 +1835,6 @@ "node": ">=8" } }, - "node_modules/is-buffer": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", - "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/is-callable": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", - "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", - "dev": true, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/is-core-module": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.0.tgz", @@ -1973,15 +1844,6 @@ "has": "^1.0.3" } }, - "node_modules/is-date-object": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", - "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", - "dev": true, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -1992,12 +1854,12 @@ } }, "node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/is-generator-function": { @@ -2060,28 +1922,22 @@ "node": ">=8" } }, - "node_modules/is-regex": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", - "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, - "dependencies": { - "has-symbols": "^1.0.1" - }, "engines": { - "node": ">= 0.4" + "node": ">=8" } }, - "node_modules/is-symbol": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", - "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmmirror.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true, - "dependencies": { - "has-symbols": "^1.0.1" - }, "engines": { - "node": ">= 0.4" + "node": ">=10" } }, "node_modules/is-url": { @@ -2110,12 +1966,6 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, "node_modules/jest-worker": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", @@ -2158,13 +2008,12 @@ "dev": true }, "node_modules/js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "dependencies": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" + "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" @@ -2358,16 +2207,15 @@ } }, "node_modules/locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "dependencies": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" + "p-locate": "^5.0.0" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/lodash": { @@ -2377,12 +2225,77 @@ "dev": true }, "node_modules/log-symbols": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-3.0.0.tgz", - "integrity": "sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==", + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/log-symbols/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/log-symbols/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/log-symbols/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/log-symbols/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/log-symbols/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/log-symbols/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "dependencies": { - "chalk": "^2.4.2" + "has-flag": "^4.0.0" }, "engines": { "node": ">=8" @@ -2474,55 +2387,109 @@ "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, - "node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "node_modules/mocha": { + "version": "10.0.0", + "resolved": "https://registry.npmmirror.com/mocha/-/mocha-10.0.0.tgz", + "integrity": "sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA==", "dev": true, "dependencies": { - "minimist": "^1.2.5" + "@ungap/promise-all-settled": "1.1.2", + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" }, "bin": { - "mkdirp": "bin/cmd.js" + "_mocha": "bin/_mocha", + "mocha": "bin/mocha.js" + }, + "engines": { + "node": ">= 14.0.0" } }, - "node_modules/mocha": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-7.2.0.tgz", - "integrity": "sha512-O9CIypScywTVpNaRrCAgoUnJgozpIofjKUYmJhiCIJMiuYnLI6otcb1/kpW9/n/tJODHGZ7i8aLQoDVsMtOKQQ==", + "node_modules/mocha/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "dev": true, "dependencies": { - "ansi-colors": "3.2.3", - "browser-stdout": "1.3.1", - "chokidar": "3.3.0", - "debug": "3.2.6", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "find-up": "3.0.0", - "glob": "7.1.3", - "growl": "1.10.5", - "he": "1.2.0", - "js-yaml": "3.13.1", - "log-symbols": "3.0.0", - "minimatch": "3.0.4", - "mkdirp": "0.5.5", - "ms": "2.1.1", - "node-environment-flags": "1.0.6", - "object.assign": "4.1.0", - "strip-json-comments": "2.0.1", - "supports-color": "6.0.0", - "which": "1.3.1", - "wide-align": "1.1.3", - "yargs": "13.3.2", - "yargs-parser": "13.1.2", - "yargs-unparser": "1.6.0" + "balanced-match": "^1.0.0" + } + }, + "node_modules/mocha/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" }, - "bin": { - "_mocha": "bin/_mocha", - "mocha": "bin/mocha" + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/mocha/node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/mocha/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/mocha/node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" }, "engines": { - "node": ">= 8.10.0" + "node": ">=10" + } + }, + "node_modules/mocha/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "node_modules/mocha/node_modules/serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" } }, "node_modules/ms": { @@ -2531,6 +2498,18 @@ "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "dev": true }, + "node_modules/nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", @@ -2548,16 +2527,6 @@ "node": "*" } }, - "node_modules/node-environment-flags": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz", - "integrity": "sha512-5Evy2epuL+6TM0lCQGpFIj6KwiEsGh1SrHUhTbNX+sLbBtjidPZFAnVK9y5yU1+h//RitLbRHTIMyxQPtxMdHw==", - "dev": true, - "dependencies": { - "object.getownpropertydescriptors": "^2.0.3", - "semver": "^5.7.0" - } - }, "node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -2579,56 +2548,13 @@ }, "node_modules/normalize-path": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "resolved": "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/object-inspect": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", - "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==", - "dev": true - }, - "node_modules/object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/object.assign": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", - "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", - "dev": true, - "dependencies": { - "define-properties": "^1.1.2", - "function-bind": "^1.1.1", - "has-symbols": "^1.0.0", - "object-keys": "^1.0.11" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/object.getownpropertydescriptors": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", - "integrity": "sha512-Z53Oah9A3TdLoblT7VKJaTDdXdT+lQO+cNpKVnya5JDe9uLvzu1YyY1yFDFrcxrlRgWrEFH0jJtD/IbuwjcEVg==", - "dev": true, - "dependencies": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.0-next.1" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -2666,27 +2592,27 @@ } }, "node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "version": "3.1.0", + "resolved": "https://registry.npmmirror.com/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "dependencies": { - "p-try": "^2.0.0" + "yocto-queue": "^0.1.0" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "dependencies": { - "p-limit": "^2.0.0" + "p-limit": "^3.0.2" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/p-map": { @@ -2704,15 +2630,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", @@ -2729,12 +2646,12 @@ } }, "node_modules/path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/path-is-absolute": { @@ -2866,32 +2783,26 @@ "dev": true }, "node_modules/readdirp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz", - "integrity": "sha512-crk4Qu3pmXwgxdSgGhgA/eXiJAPQiX4GMOZZMXnqKxHX7TaoL+3gQVo/WeuAiogr07DpnfjIMpXXa+PAIvwPGQ==", + "version": "3.6.0", + "resolved": "https://registry.npmmirror.com/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "dependencies": { - "picomatch": "^2.0.4" + "picomatch": "^2.2.1" }, "engines": { - "node": ">= 8" + "node": ">=8.10.0" } }, "node_modules/require-directory": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "resolved": "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "dev": true - }, "node_modules/resolve": { "version": "1.15.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz", @@ -3043,19 +2954,6 @@ "node": ">=6.9.0" } }, - "node_modules/rollup/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -3124,12 +3022,6 @@ "randombytes": "^2.1.0" } }, - "node_modules/set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true - }, "node_modules/set-immediate-shim": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", @@ -3200,12 +3092,6 @@ "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", "dev": true }, - "node_modules/sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -3224,97 +3110,59 @@ } }, "node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" }, "engines": { - "node": ">=4" - } - }, - "node_modules/string.prototype.trimend": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", - "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", - "dev": true, - "dependencies": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" + "node": ">=8" } }, - "node_modules/string.prototype.trimleft": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz", - "integrity": "sha512-gCA0tza1JBvqr3bfAIFJGqfdRTyPae82+KTnm3coDXkZN9wnuW3HjGgN386D7hfv5CHQYCI022/rJPVlqXyHSw==", + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, "dependencies": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5", - "string.prototype.trimstart": "^1.0.0" + "ansi-regex": "^5.0.1" }, "engines": { - "node": ">= 0.4" + "node": ">=8" } }, - "node_modules/string.prototype.trimright": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.2.tgz", - "integrity": "sha512-ZNRQ7sY3KroTaYjRS6EbNiiHrOkjihL9aQE/8gfQ4DtAC/aEBRHFJa44OmoWxGGqXuJlfKkZW4WcXErGr+9ZFg==", + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmmirror.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true, - "dependencies": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5", - "string.prototype.trimend": "^1.0.0" - }, "engines": { - "node": ">= 0.4" - } - }, - "node_modules/string.prototype.trimstart": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", - "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", - "dev": true, - "dependencies": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" + "node": ">=8" } }, - "node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "dependencies": { - "ansi-regex": "^3.0.0" + "has-flag": "^4.0.0" }, "engines": { - "node": ">=4" - } - }, - "node_modules/strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true, - "engines": { - "node": ">=0.10.0" + "node": ">=10" } }, - "node_modules/supports-color": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", - "integrity": "sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg==", + "node_modules/supports-color/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, "engines": { - "node": ">=6" + "node": ">=8" } }, "node_modules/tcp-port-used": { @@ -3483,82 +3331,56 @@ "webidl-conversions": "^3.0.0" } }, - "node_modules/which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "which": "bin/which" - } - }, - "node_modules/which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "node_modules/workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmmirror.com/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", "dev": true }, - "node_modules/wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "dev": true, - "dependencies": { - "string-width": "^1.0.2 || 2" - } - }, "node_modules/wrap-ansi": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", - "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "version": "7.0.0", + "resolved": "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "dependencies": { - "ansi-styles": "^3.2.0", - "string-width": "^3.0.0", - "strip-ansi": "^5.0.0" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=6" - } - }, - "node_modules/wrap-ansi/node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true, - "engines": { - "node": ">=6" + "node": ">=10" } }, - "node_modules/wrap-ansi/node_modules/string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "dependencies": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" + "color-convert": "^2.0.1" }, "engines": { - "node": ">=6" + "node": ">=8" } }, - "node_modules/wrap-ansi/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "node_modules/wrap-ansi/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "dependencies": { - "ansi-regex": "^4.1.0" + "color-name": "~1.1.4" }, "engines": { - "node": ">=6" + "node": ">=7.0.0" } }, + "node_modules/wrap-ansi/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -3588,86 +3410,54 @@ } }, "node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", - "dev": true - }, - "node_modules/yargs": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", - "integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==", + "version": "5.0.8", + "resolved": "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true, - "dependencies": { - "cliui": "^5.0.0", - "find-up": "^3.0.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^3.0.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^13.1.2" - } - }, - "node_modules/yargs-parser": { - "version": "13.1.2", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", - "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", - "dev": true, - "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" + "engines": { + "node": ">=10" } }, - "node_modules/yargs-unparser": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.6.0.tgz", - "integrity": "sha512-W9tKgmSn0DpSatfri0nx52Joq5hVXgeLiqR/5G0sZNDoLZFOr/xjBUDcShCOGNsBnEMNo1KAMBkTej1Hm62HTw==", + "node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmmirror.com/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "dependencies": { - "flat": "^4.1.0", - "lodash": "^4.17.15", - "yargs": "^13.3.0" + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" }, "engines": { - "node": ">=6" - } - }, - "node_modules/yargs/node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true, - "engines": { - "node": ">=6" + "node": ">=10" } }, - "node_modules/yargs/node_modules/string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "node_modules/yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true, - "dependencies": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - }, "engines": { - "node": ">=6" + "node": ">=10" } }, - "node_modules/yargs/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "dependencies": { - "ansi-regex": "^4.1.0" + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/yauzl": { @@ -3688,6 +3478,15 @@ "engines": { "node": ">= 4.0.0" } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmmirror.com/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + } } }, "dependencies": { @@ -4028,20 +3827,6 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, - "glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, "is-reference": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", @@ -4191,6 +3976,12 @@ "@types/node": "*" } }, + "@ungap/promise-all-settled": { + "version": "1.1.2", + "resolved": "https://registry.npmmirror.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", + "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", + "dev": true + }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -4244,15 +4035,15 @@ } }, "ansi-colors": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", - "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", + "version": "4.1.1", + "resolved": "https://registry.npmmirror.com/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true }, "ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, "ansi-styles": { @@ -4265,9 +4056,9 @@ } }, "anymatch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", - "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "version": "3.1.2", + "resolved": "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", "dev": true, "requires": { "normalize-path": "^3.0.0", @@ -4275,13 +4066,10 @@ } }, "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "requires": { - "sprintf-js": "~1.0.2" - } + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true }, "array-union": { "version": "2.1.0", @@ -4331,9 +4119,9 @@ "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" }, "binary-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", - "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", + "version": "2.2.0", + "resolved": "https://registry.npmmirror.com/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, "bip39": { @@ -4375,7 +4163,7 @@ }, "browser-stdout": { "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "resolved": "https://registry.npmmirror.com/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, @@ -4418,9 +4206,9 @@ } }, "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "version": "6.3.0", + "resolved": "https://registry.npmmirror.com/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true }, "chalk": { @@ -4446,19 +4234,19 @@ } }, "chokidar": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.0.tgz", - "integrity": "sha512-dGmKLDdT3Gdl7fBUe8XK+gAtGmzy5Fn0XkkWQuYxGIgWVPPse2CxFA5mtrlD0TOHaHjEUqkWNyP1XdHoJES/4A==", + "version": "3.5.3", + "resolved": "https://registry.npmmirror.com/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, "requires": { - "anymatch": "~3.1.1", + "anymatch": "~3.1.2", "braces": "~3.0.2", - "fsevents": "~2.1.1", - "glob-parent": "~5.1.0", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", - "readdirp": "~3.2.0" + "readdirp": "~3.6.0" } }, "chromedriver": { @@ -4492,42 +4280,14 @@ "dev": true }, "cliui": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", - "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "version": "7.0.4", + "resolved": "https://registry.npmmirror.com/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", "dev": true, "requires": { - "string-width": "^3.1.0", - "strip-ansi": "^5.2.0", - "wrap-ansi": "^5.1.0" - }, - "dependencies": { - "ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true - }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "dev": true, - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - } - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dev": true, - "requires": { - "ansi-regex": "^4.1.0" - } - } + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" } }, "co": { @@ -4653,9 +4413,9 @@ } }, "decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true }, "deep-equal": { @@ -4676,15 +4436,6 @@ "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", "dev": true }, - "define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, - "requires": { - "object-keys": "^1.0.12" - } - }, "del": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/del/-/del-6.0.0.tgz", @@ -4737,9 +4488,9 @@ "dev": true }, "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true }, "dir-glob": { @@ -4797,9 +4548,9 @@ "dev": true }, "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "version": "8.0.0", + "resolved": "https://registry.npmmirror.com/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, "encodeurl": { @@ -4817,35 +4568,11 @@ "once": "^1.4.0" } }, - "es-abstract": { - "version": "1.17.5", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", - "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", - "dev": true, - "requires": { - "es-to-primitive": "^1.2.1", - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.1", - "is-callable": "^1.1.5", - "is-regex": "^1.0.5", - "object-inspect": "^1.7.0", - "object-keys": "^1.1.1", - "object.assign": "^4.1.0", - "string.prototype.trimleft": "^2.1.1", - "string.prototype.trimright": "^2.1.1" - } - }, - "es-to-primitive": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", - "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", - "dev": true, - "requires": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" - } + "escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmmirror.com/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true }, "escape-html": { "version": "1.0.3", @@ -4859,12 +4586,6 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true - }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -4947,22 +4668,20 @@ } }, "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "requires": { - "locate-path": "^3.0.0" + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" } }, "flat": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", - "integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==", - "dev": true, - "requires": { - "is-buffer": "~2.0.3" - } + "version": "5.0.2", + "resolved": "https://registry.npmmirror.com/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true }, "follow-redirects": { "version": "1.15.1", @@ -4994,9 +4713,9 @@ "dev": true }, "fsevents": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", - "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "version": "2.3.2", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "optional": true }, @@ -5014,7 +4733,7 @@ }, "get-caller-file": { "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "resolved": "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, @@ -5028,9 +4747,9 @@ } }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -5076,12 +4795,6 @@ "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", "dev": true }, - "growl": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", - "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", - "dev": true - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -5146,7 +4859,7 @@ }, "he": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "resolved": "https://registry.npmmirror.com/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, @@ -5261,25 +4974,13 @@ }, "is-binary-path": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "resolved": "https://registry.npmmirror.com/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, "requires": { "binary-extensions": "^2.0.0" } }, - "is-buffer": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", - "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==", - "dev": true - }, - "is-callable": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", - "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", - "dev": true - }, "is-core-module": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.0.tgz", @@ -5289,12 +4990,6 @@ "has": "^1.0.3" } }, - "is-date-object": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", - "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", - "dev": true - }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -5302,9 +4997,9 @@ "dev": true }, "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, "is-generator-function": { @@ -5349,23 +5044,17 @@ "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true }, - "is-regex": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", - "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", - "dev": true, - "requires": { - "has-symbols": "^1.0.1" - } + "is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmmirror.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true }, - "is-symbol": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", - "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", - "dev": true, - "requires": { - "has-symbols": "^1.0.1" - } + "is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmmirror.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true }, "is-url": { "version": "1.2.4", @@ -5390,12 +5079,6 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, "jest-worker": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", @@ -5431,13 +5114,12 @@ "dev": true }, "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" + "argparse": "^2.0.1" } }, "jsesc": { @@ -5588,13 +5270,12 @@ } }, "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" + "p-locate": "^5.0.0" } }, "lodash": { @@ -5604,12 +5285,64 @@ "dev": true }, "log-symbols": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-3.0.0.tgz", - "integrity": "sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==", + "version": "4.1.0", + "resolved": "https://registry.npmmirror.com/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, "requires": { - "chalk": "^2.4.2" + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, "md5.js": { @@ -5680,45 +5413,92 @@ "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - }, "mocha": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-7.2.0.tgz", - "integrity": "sha512-O9CIypScywTVpNaRrCAgoUnJgozpIofjKUYmJhiCIJMiuYnLI6otcb1/kpW9/n/tJODHGZ7i8aLQoDVsMtOKQQ==", + "version": "10.0.0", + "resolved": "https://registry.npmmirror.com/mocha/-/mocha-10.0.0.tgz", + "integrity": "sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA==", "dev": true, "requires": { - "ansi-colors": "3.2.3", + "@ungap/promise-all-settled": "1.1.2", + "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "chokidar": "3.3.0", - "debug": "3.2.6", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "find-up": "3.0.0", - "glob": "7.1.3", - "growl": "1.10.5", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", "he": "1.2.0", - "js-yaml": "3.13.1", - "log-symbols": "3.0.0", - "minimatch": "3.0.4", - "mkdirp": "0.5.5", - "ms": "2.1.1", - "node-environment-flags": "1.0.6", - "object.assign": "4.1.0", - "strip-json-comments": "2.0.1", - "supports-color": "6.0.0", - "which": "1.3.1", - "wide-align": "1.1.3", - "yargs": "13.3.2", - "yargs-parser": "13.1.2", - "yargs-unparser": "1.6.0" + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0" + } + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + }, + "dependencies": { + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmmirror.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } + } } }, "ms": { @@ -5727,6 +5507,12 @@ "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "dev": true }, + "nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true + }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", @@ -5738,16 +5524,6 @@ "resolved": "https://registry.npmjs.org/node-cryptojs-aes/-/node-cryptojs-aes-0.4.0.tgz", "integrity": "sha1-ZM+6gMH7yfrDR8jrLCwSrb06igc=" }, - "node-environment-flags": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz", - "integrity": "sha512-5Evy2epuL+6TM0lCQGpFIj6KwiEsGh1SrHUhTbNX+sLbBtjidPZFAnVK9y5yU1+h//RitLbRHTIMyxQPtxMdHw==", - "dev": true, - "requires": { - "object.getownpropertydescriptors": "^2.0.3", - "semver": "^5.7.0" - } - }, "node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -5758,44 +5534,10 @@ }, "normalize-path": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "resolved": "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, - "object-inspect": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", - "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==", - "dev": true - }, - "object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true - }, - "object.assign": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", - "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", - "dev": true, - "requires": { - "define-properties": "^1.1.2", - "function-bind": "^1.1.1", - "has-symbols": "^1.0.0", - "object-keys": "^1.0.11" - } - }, - "object.getownpropertydescriptors": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", - "integrity": "sha512-Z53Oah9A3TdLoblT7VKJaTDdXdT+lQO+cNpKVnya5JDe9uLvzu1YyY1yFDFrcxrlRgWrEFH0jJtD/IbuwjcEVg==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.0-next.1" - } - }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -5827,21 +5569,21 @@ "dev": true }, "p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "version": "3.1.0", + "resolved": "https://registry.npmmirror.com/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "requires": { - "p-try": "^2.0.0" + "yocto-queue": "^0.1.0" } }, "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "requires": { - "p-limit": "^2.0.0" + "p-limit": "^3.0.2" } }, "p-map": { @@ -5853,12 +5595,6 @@ "aggregate-error": "^3.0.0" } }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true - }, "pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", @@ -5872,9 +5608,9 @@ "dev": true }, "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, "path-is-absolute": { @@ -5979,24 +5715,18 @@ } }, "readdirp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.2.0.tgz", - "integrity": "sha512-crk4Qu3pmXwgxdSgGhgA/eXiJAPQiX4GMOZZMXnqKxHX7TaoL+3gQVo/WeuAiogr07DpnfjIMpXXa+PAIvwPGQ==", + "version": "3.6.0", + "resolved": "https://registry.npmmirror.com/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "requires": { - "picomatch": "^2.0.4" + "picomatch": "^2.2.1" } }, "require-directory": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true - }, - "require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "resolved": "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, "resolve": { @@ -6081,15 +5811,6 @@ "dev": true, "requires": { "fsevents": "~2.3.2" - }, - "dependencies": { - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - } } }, "rollup-plugin-polyfill-node": { @@ -6182,12 +5903,6 @@ "randombytes": "^2.1.0" } }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true - }, "set-immediate-shim": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", @@ -6245,12 +5960,6 @@ "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", "dev": true }, - "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", @@ -6266,79 +5975,46 @@ } }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "string.prototype.trimend": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", - "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" - } - }, - "string.prototype.trimleft": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz", - "integrity": "sha512-gCA0tza1JBvqr3bfAIFJGqfdRTyPae82+KTnm3coDXkZN9wnuW3HjGgN386D7hfv5CHQYCI022/rJPVlqXyHSw==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5", - "string.prototype.trimstart": "^1.0.0" - } - }, - "string.prototype.trimright": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.2.tgz", - "integrity": "sha512-ZNRQ7sY3KroTaYjRS6EbNiiHrOkjihL9aQE/8gfQ4DtAC/aEBRHFJa44OmoWxGGqXuJlfKkZW4WcXErGr+9ZFg==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5", - "string.prototype.trimend": "^1.0.0" - } - }, - "string.prototype.trimstart": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", - "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", - "dev": true, - "requires": { - "define-properties": "^1.1.3", - "es-abstract": "^1.17.5" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" } }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "ansi-regex": "^5.0.1" } }, "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "version": "3.1.1", + "resolved": "https://registry.npmmirror.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, "supports-color": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", - "integrity": "sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg==", + "version": "8.1.1", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" + }, + "dependencies": { + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + } } }, "tcp-port-used": { @@ -6474,66 +6150,46 @@ "webidl-conversions": "^3.0.0" } }, - "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } - }, - "which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmmirror.com/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", "dev": true }, - "wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "dev": true, - "requires": { - "string-width": "^1.0.2 || 2" - } - }, "wrap-ansi": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", - "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "version": "7.0.0", + "resolved": "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "requires": { - "ansi-styles": "^3.2.0", - "string-width": "^3.0.0", - "strip-ansi": "^5.0.0" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "dependencies": { - "ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true - }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" + "color-convert": "^2.0.1" } }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "requires": { - "ansi-regex": "^4.1.0" + "color-name": "~1.1.4" } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true } } }, @@ -6560,76 +6216,42 @@ "dev": true }, "y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "version": "5.0.8", + "resolved": "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true }, "yargs": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", - "integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==", + "version": "16.2.0", + "resolved": "https://registry.npmmirror.com/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "requires": { - "cliui": "^5.0.0", - "find-up": "^3.0.0", - "get-caller-file": "^2.0.1", + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^3.0.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^13.1.2" - }, - "dependencies": { - "ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true - }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "dev": true, - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - } - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dev": true, - "requires": { - "ansi-regex": "^4.1.0" - } - } + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" } }, "yargs-parser": { - "version": "13.1.2", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", - "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } + "version": "20.2.4", + "resolved": "https://registry.npmmirror.com/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true }, "yargs-unparser": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.6.0.tgz", - "integrity": "sha512-W9tKgmSn0DpSatfri0nx52Joq5hVXgeLiqR/5G0sZNDoLZFOr/xjBUDcShCOGNsBnEMNo1KAMBkTej1Hm62HTw==", + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "requires": { - "flat": "^4.1.0", - "lodash": "^4.17.15", - "yargs": "^13.3.0" + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" } }, "yauzl": { @@ -6647,6 +6269,12 @@ "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.2.1.tgz", "integrity": "sha512-faQrqNMzcPCHGVC2aaOINk13K+aaBDUPjGWl0teOXywElLjyVAB6Oe2jj62jHYtwsU49jXhScYbvPENK+6zAvQ==", "dev": true + }, + "yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmmirror.com/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true } } } diff --git a/package.json b/package.json index 4ea7af7..d73b118 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "types": "src/index.d.ts", "module": "dist/esm/lamden.js", "scripts": { - "test": "npm run build && mocha --recursive --timeout 30000", + "test": "npm run build && mocha --recursive --timeout 30000 --exit", "tests": "npm run test", "test-network": "npm run build && mocha test/network-test.js --timeout 10000", - "test-masternode-api": "npm run build && mocha test/masternode_api-test.js --timeout 10000", + "test-masternode-api": "npm run build && mocha test/masternode_api-test.js --timeout 30000 --exit", "test-blockservice-api": "npm run build && mocha test/blockservice_api-test.js --timeout 10000", - "test-transaction-builder": "npm run build && mocha test/transactionBuilder-test.js --timeout 30000", + "test-transaction-builder": "npm run build && mocha test/transactionBuilder-test.js --timeout 30000 --exit", "test-transaction-batcher": "npm run build && mocha test/transactionBatcher-test.js --timeout 60000", "test-wallet": "npm run build && mocha test/wallet-test.js", "test-encoder": "npm run build && mocha test/encoder-test.js", @@ -64,7 +64,7 @@ "expect.js": "^0.3.1", "koa": "^2.13.4", "koa-static": "^5.0.0", - "mocha": "^7.2.0", + "mocha": "^10.0.0", "rollup": "^2.60.0", "rollup-plugin-polyfill-node": "^0.7.0", "rollup-plugin-terser": "^7.0.2", diff --git a/src/js/blockservice-api.js b/src/js/blockservice-api.js index a87ee87..71f82f4 100644 --- a/src/js/blockservice-api.js +++ b/src/js/blockservice-api.js @@ -42,7 +42,6 @@ send(method, path, data = {}, overrideURL) { options.headers = headers; options.body = data; } - return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) } diff --git a/src/js/transactionBuilder.js b/src/js/transactionBuilder.js index d063bf0..668873e 100644 --- a/src/js/transactionBuilder.js +++ b/src/js/transactionBuilder.js @@ -74,7 +74,7 @@ export class TransactionBuilder extends Network { this.txCheckResult = {}; this.txCheckAttempts = 0; this.txCheckLimit = 10; - this.maxBlockToCheck = 30; + this.maxBlockToCheck = 15; this.startBlock = null; //Hydrate other items if passed @@ -317,7 +317,6 @@ export class TransactionBuilder extends Network { // Check if the blockservice is up let serverAvailable = await this.blockservice.pingServer() - //If it's not then fail over to checking from the masternode if (!serverAvailable) { console.log("Blockservice not available, failing back to masternode.") @@ -328,15 +327,20 @@ export class TransactionBuilder extends Network { ) } + let count = this.maxBlockToCheck return new Promise(async (resolve) => { let lastLatestBlock = this.startBlock || 0 - let count = this.maxBlockToCheck // Get the next 10 blocks from the blockservice starting with the block the transction was sent from const getLatestBlock = async () => { + if (count < 1) { + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`] + this.txCheckResult.status = 2 + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + } + count = count - 1 let latestBlock = await this.blockservice.getLastetBlock() - if (latestBlock > lastLatestBlock){ + if (latestBlock !== lastLatestBlock){ lastLatestBlock = latestBlock - count = count - 1 checkForTrasaction() }else{ setTimeout(getLatestBlock, 5000) @@ -351,7 +355,7 @@ export class TransactionBuilder extends Network { resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); }else{ if (count < 1){ - this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} blocks after sending.`] + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`] this.txCheckResult.status = 2 resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); }else{ diff --git a/test/browsers/encoder-test.js b/test/browsers/encoder-test.js index 29ef924..418b4bd 100644 --- a/test/browsers/encoder-test.js +++ b/test/browsers/encoder-test.js @@ -12,7 +12,12 @@ caps.setLoggingPrefs(prefs); const dateString = "2020-07-28T19:16:35.059Z"; const millisecondsDelta = 475200000; - +const typeValidAssertMiddleware = async (ctx, next) => { + if (ctx.request.url.indexOf("types-validate-assert") >= 0 && ctx.request.url.indexOf(".js") === -1) { + ctx.redirect(`${ctx.request.url}.js`); + } + await next(); + } describe('Browsers Tests: Test Type Encoder', function () { let driver; let server; @@ -21,6 +26,7 @@ describe('Browsers Tests: Test Type Encoder', function () { before(async function() { // Start a http server + app.use(typeValidAssertMiddleware) app.use(KoaStatic(path.join(__dirname,'../../'))); server = app.listen(port, () => console.log(`\n\x1B[32mKoa Server running at http://127.0.0.1:${port}/\x1B[0m`)) diff --git a/test/masternode_api-test.js b/test/masternode_api-test.js index dfb3750..a837030 100644 --- a/test/masternode_api-test.js +++ b/test/masternode_api-test.js @@ -117,6 +117,7 @@ describe("Test Masternode API returns", () => { context("Masternode_API.getContractMethods()", () => { it("returns an array if a contract exists on the blockchain", async () => { let response = await goodNetwork_api.getContractMethods("currency"); + console.log(response) expect(Array.isArray(response)).to.be(true); expect(response.length > 0).to.be(true); }); @@ -162,6 +163,7 @@ describe("Test Masternode API returns", () => { it("returns undefined if the key does not exist in the variable", async () => { let key = wallet.new_wallet().vk; let response = await goodNetwork_api.getVariable("currency", "balances", key); + console.log(response) expect(response).to.be(null); }); it("returns undefined if the contract does not exist", async () => { @@ -189,7 +191,7 @@ describe("Test Masternode API returns", () => { }); it("returns undefined if provided network is unresponsive", async () => { let response = await badNetwork_api.getContractInfo("currency"); - expect(response).to.be(null); + expect(response.error).to.be('currency does not exist'); }); }); diff --git a/test/transactionBuilder-test.js b/test/transactionBuilder-test.js index da09d91..47bf9fd 100644 --- a/test/transactionBuilder-test.js +++ b/test/transactionBuilder-test.js @@ -76,6 +76,14 @@ let txInfo_withNonce = { processor, }; +function sleep(milliseconds) { + const date = Date.now(); + let currentDate = null; + do { + currentDate = Date.now(); + } while (currentDate - date < milliseconds); +} + describe("Test TransactionBuilder class", () => { context("new TransactionBuilder", () => { it("can create an instance without nonce or processor", () => { @@ -390,7 +398,7 @@ describe("Test TransactionBuilder class", () => { newTx1.txHash = "b9f9d598c56ae579b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46b" let res = await newTx1.checkForTransactionResult() expect(res.hash).to.exist - expect(res.status).to.equal(0) + expect(res.status.__fixed__).to.equal('0') }); it("Returns error and status code 2 if txHash could not be found after X tries.", async function () { let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); @@ -410,7 +418,7 @@ describe("Test TransactionBuilder class", () => { newTx1.checkForTransactionResult((res) => { expect(res.hash).to.exist - expect(res.status).to.equal(0) + expect(res.status.__fixed__).to.equal('0') resolver() }); }) @@ -452,13 +460,15 @@ describe("Test TransactionBuilder class", () => { expect(res.state_changes_obj).to.exist }); it("Returns error and status code 2 if txHash could not be found within X number of blocks.", async function () { + this.timeout(50000) let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); + newTx1.maxBlockToCheck = 2 newTx1.txHash = "b9f9d598c56ae59b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46b" newTx1.startBlock = 62880 let res = await newTx1.checkBlockserviceForTransactionResult() expect(res.errors.length).to.be.greaterThan(0) expect(res.status).to.equal(2) - expect(res.errors[0]).to.equal(`No transaction result found within ${newTx1.maxBlockToCheck} blocks after sending.`) + expect(res.errors[0]).to.equal(`No transaction result found within ${newTx1.maxBlockToCheck} attempts.`) }); it("Fails back to masternode checker if blockservice is not available.", async function () { let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); @@ -498,32 +508,29 @@ describe("Test TransactionBuilder class", () => { }); }) }); - it("Returns error and status code 2 if txHash could not be found within X number of blocks.", async function () { - return new Promise(resolver => { - let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); - newTx1.txHash = "b9f9d598c56ae59b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46b" - newTx1.startBlock = 62880 - newTx1.checkBlockserviceForTransactionResult((res) => { - expect(res.errors.length).to.be.greaterThan(0) - expect(res.status).to.equal(2) - expect(res.errors[0]).to.equal(`No transaction result found within ${newTx1.maxBlockToCheck} blocks after sending.`) - resolver() - }); - }) + it("Returns error and status code 2 if txHash could not be found within X number of blocks.", function () { + this.timeout(50000) + let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); + newTx1.txHash = "b9f9d598c56ae59b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46b" + newTx1.startBlock = 62880 + newTx1.maxBlockToCheck = 2 + newTx1.checkBlockserviceForTransactionResult((res) => { + expect(res.errors.length).to.be.greaterThan(0) + expect(res.status).to.equal(2) + expect(res.errors[0]).to.equal(`No transaction result found within ${newTx1.maxBlockToCheck} attempts.`) + }); }); - it("Fails back to masternode checker if blockservice is not available.", async function () { - return new Promise(resolver => { - let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); - newTx1.blockservice.hosts = [] - newTx1.txHash = "b9f9d598c56ae59b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46" - newTx1.txCheckLimit = 2; - newTx1.checkBlockserviceForTransactionResult((res) => { - expect(res.errors.length).to.be.greaterThan(0) - expect(res.status).to.equal(2) - expect(res.errors.includes("Retry Attempts 2 hit while checking for Tx Result.")).to.equal(true) - resolver() - }); - }) + it("Fails back to masternode checker if blockservice is not available.", function (done) { + let newTx1 = new Lamden.TransactionBuilder(goodNetwork, txInfo_noNonce); + newTx1.blockservice.hosts = [] + newTx1.txHash = "b9f9d598c56ae59b8392651a9a463335b68bdf4d6fd60391fca19a7b1fdb46" + newTx1.txCheckLimit = 2; + newTx1.checkBlockserviceForTransactionResult((res) => { + expect(res.errors.length).to.be.greaterThan(0) + expect(res.status).to.equal(2) + expect(res.errors.includes("Retry Attempts 2 hit while checking for Tx Result.")).to.equal(true) + done() + }); }); }) }) From 55ae79533926c60f3358dd56e99b43b969c8f111 Mon Sep 17 00:00:00 2001 From: JeffWScott Date: Wed, 28 Sep 2022 15:49:05 -0400 Subject: [PATCH 5/5] update version --- dist/cjs/lamden.js | 3760 ++++++++++++++++++++++---------------------- package-lock.json | 288 ++-- package.json | 4 +- 3 files changed, 1978 insertions(+), 2074 deletions(-) diff --git a/dist/cjs/lamden.js b/dist/cjs/lamden.js index afcc175..24d871d 100644 --- a/dist/cjs/lamden.js +++ b/dist/cjs/lamden.js @@ -2628,143 +2628,143 @@ var JsonFormatter$1 = jsonformatter.JsonFormatter; cryptojs.CryptoJS = CryptoJS$1; cryptojs.JsonFormatter = JsonFormatter$1; -const { CryptoJS, JsonFormatter } = cryptojs; -const { validateTypes: validateTypes$5, assertTypes: assertTypes$1 } = validators; - -/** - * Encrypt a Javascript object with a string password - * The object passed must pass JSON.stringify or the method will fail. - * - * @param {string} password A password to encrypt the object with - * @param {Object} obj A javascript object (must be JSON compatible) - * @return {string} Encrypted string - */ -function encryptObject(password, obj) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isObject(obj); - - const encrypted = CryptoJS.AES.encrypt(JSON.stringify(obj), password, { - format: JsonFormatter, - }).toString(); - return encrypted; -} - -/** - * Decrypt an Object using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} objString A javascript object as JSON string - * @return {string} Encrypted string - */ -function decryptObject(password, objString) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isStringWithValue(objString); - - try { - const decrypt = CryptoJS.AES.decrypt(objString, password, { format: JsonFormatter }); - return JSON.parse(CryptoJS.enc.Utf8.stringify(decrypt)); - } catch (e) { - return false; - } -} - -/** - * Encrypt a string using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} string A string to be password encrypted - * @return {string} Encrypted string - */ -function encryptStrHash(password, string) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isString(string); - - const encrypt = CryptoJS.AES.encrypt(string, password).toString(); - return encrypt; -} - -/** - * Decrypt a string using a password string - * - * @param {string} password A password to encrypt the object with - * @param {string} encryptedString A string to decrypt - * @return {string} Decrypted string - */ -function decryptStrHash(password, encryptedString) { - assertTypes$1.isStringWithValue(password); - assertTypes$1.isStringWithValue(encryptedString); - - try { - const decrypted = CryptoJS.AES.decrypt(encryptedString, password); - return CryptoJS.enc.Utf8.stringify(decrypted) === "" - ? false - : CryptoJS.enc.Utf8.stringify(decrypted); - } catch (e) { - return false; - } -} - -function buf2hex(buffer) { - return Array.prototype.map - .call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)) - .join(""); -} -function hex2buf(hexString) { - var bytes = new Uint8Array(Math.ceil(hexString.length / 2)); - for (var i = 0; i < bytes.length; i++) bytes[i] = parseInt(hexString.substr(i * 2, 2), 16); - return bytes; -} -function str2buf(string) { - var buf = new Buffer.from(string); - return new Uint8Array(buf); -} -function concatUint8Arrays(array1, array2) { - var arr = new Uint8Array(array1.length + array2.length); - arr.set(array1); - arr.set(array2, array1.length); - return arr; -} -function ab2str(buf) { - return String.fromCharCode.apply(null, new Uint8Array(buf)); -} -function str2ab(str) { - var buf = new ArrayBuffer(str.length); - var bufView = new Uint8Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; -} -function str2hex(str) { - var hex = ""; - for (var i = 0; i < str.length; i++) { - hex += "" + str.charCodeAt(i).toString(16); - } - return hex; -} -function hex2str(hexx) { - var hex = hexx.toString(); //force conversion - var str = ""; - for (var i = 0; i < hex.length && hex.substr(i, 2) !== "00"; i += 2) - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - return str; -} -function randomString(length) { - var text = ""; - var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (var i = 0; i < length; i++) { - text += possible.charAt(Math.floor(Math.random() * possible.length)); - } - return text; -} -function isStringHex(string = "") { - let hexRegEx = /([0-9]|[a-f])/gim; - return typeof string === "string" && (string.match(hexRegEx) || []).length === string.length; -} - -function isLamdenKey(string) { - if (validateTypes$5.isStringHex(string) && string.length === 64) return true; - return false; +const { CryptoJS, JsonFormatter } = cryptojs; +const { validateTypes: validateTypes$5, assertTypes: assertTypes$1 } = validators; + +/** + * Encrypt a Javascript object with a string password + * The object passed must pass JSON.stringify or the method will fail. + * + * @param {string} password A password to encrypt the object with + * @param {Object} obj A javascript object (must be JSON compatible) + * @return {string} Encrypted string + */ +function encryptObject(password, obj) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isObject(obj); + + const encrypted = CryptoJS.AES.encrypt(JSON.stringify(obj), password, { + format: JsonFormatter, + }).toString(); + return encrypted; +} + +/** + * Decrypt an Object using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} objString A javascript object as JSON string + * @return {string} Encrypted string + */ +function decryptObject(password, objString) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isStringWithValue(objString); + + try { + const decrypt = CryptoJS.AES.decrypt(objString, password, { format: JsonFormatter }); + return JSON.parse(CryptoJS.enc.Utf8.stringify(decrypt)); + } catch (e) { + return false; + } +} + +/** + * Encrypt a string using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} string A string to be password encrypted + * @return {string} Encrypted string + */ +function encryptStrHash(password, string) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isString(string); + + const encrypt = CryptoJS.AES.encrypt(string, password).toString(); + return encrypt; +} + +/** + * Decrypt a string using a password string + * + * @param {string} password A password to encrypt the object with + * @param {string} encryptedString A string to decrypt + * @return {string} Decrypted string + */ +function decryptStrHash(password, encryptedString) { + assertTypes$1.isStringWithValue(password); + assertTypes$1.isStringWithValue(encryptedString); + + try { + const decrypted = CryptoJS.AES.decrypt(encryptedString, password); + return CryptoJS.enc.Utf8.stringify(decrypted) === "" + ? false + : CryptoJS.enc.Utf8.stringify(decrypted); + } catch (e) { + return false; + } +} + +function buf2hex(buffer) { + return Array.prototype.map + .call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); +} +function hex2buf(hexString) { + var bytes = new Uint8Array(Math.ceil(hexString.length / 2)); + for (var i = 0; i < bytes.length; i++) bytes[i] = parseInt(hexString.substr(i * 2, 2), 16); + return bytes; +} +function str2buf(string) { + var buf = new Buffer.from(string); + return new Uint8Array(buf); +} +function concatUint8Arrays(array1, array2) { + var arr = new Uint8Array(array1.length + array2.length); + arr.set(array1); + arr.set(array2, array1.length); + return arr; +} +function ab2str(buf) { + return String.fromCharCode.apply(null, new Uint8Array(buf)); +} +function str2ab(str) { + var buf = new ArrayBuffer(str.length); + var bufView = new Uint8Array(buf); + for (var i = 0, strLen = str.length; i < strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; +} +function str2hex(str) { + var hex = ""; + for (var i = 0; i < str.length; i++) { + hex += "" + str.charCodeAt(i).toString(16); + } + return hex; +} +function hex2str(hexx) { + var hex = hexx.toString(); //force conversion + var str = ""; + for (var i = 0; i < hex.length && hex.substr(i, 2) !== "00"; i += 2) + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + return str; +} +function randomString(length) { + var text = ""; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + for (var i = 0; i < length; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + return text; +} +function isStringHex(string = "") { + let hexRegEx = /([0-9]|[a-f])/gim; + return typeof string === "string" && (string.match(hexRegEx) || []).length === string.length; +} + +function isLamdenKey(string) { + if (validateTypes$5.isStringHex(string) && string.length === 64) return true; + return false; } var utils$1 = /*#__PURE__*/Object.freeze({ @@ -2786,228 +2786,228 @@ var utils$1 = /*#__PURE__*/Object.freeze({ isLamdenKey: isLamdenKey }); -/** - * Create a wallet object for signing and verifying messages - * - * @param {Object} [args={}] Args Object - * @param {string} [args.sk=undefined] A 32 character long hex representation of a signing key (private key) to create wallet from - * @param {Uint8Array(length: 32)} [args.seed=null] A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be avoided by everyday users - * @param {boolean} [args.keepPrivate=false] No direct access to the sk. Will still allow the wallet to sign messages - * @return {Object} Wallet Object with sign and verify methods - */ -let create_wallet = (args = {}) => { - let { sk = undefined, keepPrivate = false, seed = null } = args; - - let vk; - - if (sk) { - vk = get_vk(sk); - } else { - let keyPair = new_wallet(seed); - vk = keyPair.vk; - sk = keyPair.sk; - } - - const wallet = () => { - return { - sign: (msg) => sign$1(sk, msg), - verify: (msg, sig) => verify(vk, msg, sig), - vk, - sk: !keepPrivate ? sk : undefined, - }; - }; - - return wallet(); -}; - -/** - * @param Uint8Array(length: 32) seed - * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be - * avoided by everyday users - * - * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - */ -function generate_keys(seed = null) { - var kp = null; - if (seed == null) { - kp = nacl__default["default"].sign.keyPair(); - } else { - kp = nacl__default["default"].sign.keyPair.fromSeed(seed); - } - // In the JS implementation of the NaCL library the sk is the first 32 bytes of the secretKey - // and the vk is the last 32 bytes of the secretKey as well as the publicKey - // { - // 'publicKey': , - // 'secretKey': - // } - return { - sk: new Uint8Array(kp["secretKey"].slice(0, 32)), - vk: new Uint8Array(kp["secretKey"].slice(32, 64)), - }; -} -/** - * @param String sk - * sk: A 64 character long hex representation of a signing key (private key) - * - * @return String vk - * vk: A 64 character long hex representation of a verify key (public key) - */ -function get_vk(sk) { - var kp = format_to_keys(sk); - var kpf = keys_to_format(kp); - return kpf.vk; -} -/** - * @param String sk - * sk: A 64 character long hex representation of a signing key (private key) - * - * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - */ -function format_to_keys(sk) { - var skf = hex2buf(sk); - var kp = generate_keys(skf); - return kp; -} -/** - * @param Object kp - * kp: Object containing the properties sk and vk - * sk: Signing Key (SK) represents 32 byte signing key - * vk: Verify Key (VK) represents a 32 byte verify key - * - * @return {string, string} { sk, vk } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - */ -function keys_to_format(kp) { - return { - vk: buf2hex(kp.vk), - sk: buf2hex(kp.sk), - }; -} -/** - * @param Uint8Array(length: 32) seed - * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be - * avoided by everyday users - * - * @return {string, string} { sk, vk } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - */ -function new_wallet(seed = null) { - const keys = generate_keys(seed); - return keys_to_format(keys); -} - -/** - * - * @param seed Bip39 seed phrase (128 characters in hex) - * @param derivationIndex bip32 derivation key index - * @returns {{derivationIndex: number, vk: string, sk: string, mnemonic: string}} - * derivationIndex: bip32 derivation key index - * vk: Verify Key (VK) represented as a 64 character hex string - * sk: Signing Key (SK) represented as a 64 character hex string - * seed: Bip39 seed phrase (128 characters in hex) - * mnemonic: Bip39 24 words mnemonic - */ -function generate_keys_bip39(seed = undefined, derivationIndex = 0) { - let finalSeed; - let finalMnemonic; - - if (seed !== undefined){ - finalSeed = seed; - }else { - finalMnemonic = bip39__namespace.generateMnemonic(256); - finalSeed = bip39__namespace.mnemonicToSeedSync(finalMnemonic).toString('hex'); - } - - const derivationPath = "m/44'/789'/" + derivationIndex + "'/0'/0'"; - const { key, chainCode } = bip32__default["default"].derivePath(derivationPath, finalSeed, 0x80000000); - - const privateKey = key.toString("hex"); - const publicKey = bip32__default["default"].getPublicKey(key, false).toString("hex"); - - if (publicKey !== get_vk(privateKey)) { - throw Error("Bip32 public key does not match with Lamden public key!"); - } - - return { - sk: privateKey, - vk: publicKey, - derivationIndex: derivationIndex, - seed: seed !== undefined ? null : finalSeed, - mnemonic: seed !== undefined ? null : finalMnemonic, - } -} - -/** - * @param seed Bip39 seed phrase (128 characters in hex) - * @param derivationIndex bip32 derivation key index - * - * @return {{derivationIndex: number, vk: string, sk: string, mnemonic: (string|undefined)}} { sk, vk, derivationIndex, mnemonic } - * sk: Signing Key (SK) represented as a 64 character hex string - * vk: Verify Key (VK) represented as a 64 character hex string - * derivationIndex: Bip32 derivation index - * seed: Bip39 seed phrase (128 characters in hex) - * mnemonic: Bip39 24 words mnemonic - */ -function new_wallet_bip39(seed = undefined, derivationIndex = 0) { - return generate_keys_bip39(seed, derivationIndex); -} - -/** - * @param String sk - * @param Uint8Array msg - * sk: A 64 character long hex representation of a signing key (private key) - * msg: A Uint8Array of bytes representing the message you would like to sign - * - * @return String sig - * sig: A 128 character long hex string representing the message's signature - */ -function sign$1(sk, msg) { - var kp = format_to_keys(sk); - // This is required due to the secretKey required to sign a transaction - // in the js implementation of NaCL being the combination of the sk and - // vk for some stupid reason. That being said, we still want the sk and - // vk objects to exist in 32-byte string format (same as cilantro's - // python implementation) when presented to the user. - var jsnacl_sk = concatUint8Arrays(kp.sk, kp.vk); - return buf2hex(nacl__default["default"].sign.detached(msg, jsnacl_sk)); -} -/** - * @param String vk - * @param Uint8Array msg - * @param String sig - * vk: A 64 character long hex representation of a verify key (public key) - * msg: A Uint8Array (bytes) representation of a message that has been signed - * sig: A 128 character long hex representation of a nacl signature - * - * @return Bool result - * result: true if verify checked out, false if not - */ -function verify(vk, msg, sig) { - var vkb = hex2buf(vk); - var sigb = hex2buf(sig); - try { - return nacl__default["default"].sign.detached.verify(msg, sigb, vkb); - } catch (_a) { - return false; - } -} -/** - * @param string mnemonic - * @param string[] wordList - * mnemonic: Bip39 24 words mnemonic - * wordList: An array of string(Optional) - * - * @return Boolen res - * res: A boolen value - */ -function validateMnemonic(mnemonic, wordList) { - return bip39__namespace.validateMnemonic(mnemonic, wordList); +/** + * Create a wallet object for signing and verifying messages + * + * @param {Object} [args={}] Args Object + * @param {string} [args.sk=undefined] A 32 character long hex representation of a signing key (private key) to create wallet from + * @param {Uint8Array(length: 32)} [args.seed=null] A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be avoided by everyday users + * @param {boolean} [args.keepPrivate=false] No direct access to the sk. Will still allow the wallet to sign messages + * @return {Object} Wallet Object with sign and verify methods + */ +let create_wallet = (args = {}) => { + let { sk = undefined, keepPrivate = false, seed = null } = args; + + let vk; + + if (sk) { + vk = get_vk(sk); + } else { + let keyPair = new_wallet(seed); + vk = keyPair.vk; + sk = keyPair.sk; + } + + const wallet = () => { + return { + sign: (msg) => sign$1(sk, msg), + verify: (msg, sig) => verify(vk, msg, sig), + vk, + sk: !keepPrivate ? sk : undefined, + }; + }; + + return wallet(); +}; + +/** + * @param Uint8Array(length: 32) seed + * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be + * avoided by everyday users + * + * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + */ +function generate_keys(seed = null) { + var kp = null; + if (seed == null) { + kp = nacl__default["default"].sign.keyPair(); + } else { + kp = nacl__default["default"].sign.keyPair.fromSeed(seed); + } + // In the JS implementation of the NaCL library the sk is the first 32 bytes of the secretKey + // and the vk is the last 32 bytes of the secretKey as well as the publicKey + // { + // 'publicKey': , + // 'secretKey': + // } + return { + sk: new Uint8Array(kp["secretKey"].slice(0, 32)), + vk: new Uint8Array(kp["secretKey"].slice(32, 64)), + }; +} +/** + * @param String sk + * sk: A 64 character long hex representation of a signing key (private key) + * + * @return String vk + * vk: A 64 character long hex representation of a verify key (public key) + */ +function get_vk(sk) { + var kp = format_to_keys(sk); + var kpf = keys_to_format(kp); + return kpf.vk; +} +/** + * @param String sk + * sk: A 64 character long hex representation of a signing key (private key) + * + * @return {Uint8Array(length: 32), Uint8Array(length: 32)} { vk, sk } + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + */ +function format_to_keys(sk) { + var skf = hex2buf(sk); + var kp = generate_keys(skf); + return kp; +} +/** + * @param Object kp + * kp: Object containing the properties sk and vk + * sk: Signing Key (SK) represents 32 byte signing key + * vk: Verify Key (VK) represents a 32 byte verify key + * + * @return {string, string} { sk, vk } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + */ +function keys_to_format(kp) { + return { + vk: buf2hex(kp.vk), + sk: buf2hex(kp.sk), + }; +} +/** + * @param Uint8Array(length: 32) seed + * seed: A Uint8Array with a length of 32 to seed the keyPair with. This is advanced behavior and should be + * avoided by everyday users + * + * @return {string, string} { sk, vk } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + */ +function new_wallet(seed = null) { + const keys = generate_keys(seed); + return keys_to_format(keys); +} + +/** + * + * @param seed Bip39 seed phrase (128 characters in hex) + * @param derivationIndex bip32 derivation key index + * @returns {{derivationIndex: number, vk: string, sk: string, mnemonic: string}} + * derivationIndex: bip32 derivation key index + * vk: Verify Key (VK) represented as a 64 character hex string + * sk: Signing Key (SK) represented as a 64 character hex string + * seed: Bip39 seed phrase (128 characters in hex) + * mnemonic: Bip39 24 words mnemonic + */ +function generate_keys_bip39(seed = undefined, derivationIndex = 0) { + let finalSeed; + let finalMnemonic; + + if (seed !== undefined){ + finalSeed = seed; + }else { + finalMnemonic = bip39__namespace.generateMnemonic(256); + finalSeed = bip39__namespace.mnemonicToSeedSync(finalMnemonic).toString('hex'); + } + + const derivationPath = "m/44'/789'/" + derivationIndex + "'/0'/0'"; + const { key, chainCode } = bip32__default["default"].derivePath(derivationPath, finalSeed, 0x80000000); + + const privateKey = key.toString("hex"); + const publicKey = bip32__default["default"].getPublicKey(key, false).toString("hex"); + + if (publicKey !== get_vk(privateKey)) { + throw Error("Bip32 public key does not match with Lamden public key!"); + } + + return { + sk: privateKey, + vk: publicKey, + derivationIndex: derivationIndex, + seed: seed !== undefined ? null : finalSeed, + mnemonic: seed !== undefined ? null : finalMnemonic, + } +} + +/** + * @param seed Bip39 seed phrase (128 characters in hex) + * @param derivationIndex bip32 derivation key index + * + * @return {{derivationIndex: number, vk: string, sk: string, mnemonic: (string|undefined)}} { sk, vk, derivationIndex, mnemonic } + * sk: Signing Key (SK) represented as a 64 character hex string + * vk: Verify Key (VK) represented as a 64 character hex string + * derivationIndex: Bip32 derivation index + * seed: Bip39 seed phrase (128 characters in hex) + * mnemonic: Bip39 24 words mnemonic + */ +function new_wallet_bip39(seed = undefined, derivationIndex = 0) { + return generate_keys_bip39(seed, derivationIndex); +} + +/** + * @param String sk + * @param Uint8Array msg + * sk: A 64 character long hex representation of a signing key (private key) + * msg: A Uint8Array of bytes representing the message you would like to sign + * + * @return String sig + * sig: A 128 character long hex string representing the message's signature + */ +function sign$1(sk, msg) { + var kp = format_to_keys(sk); + // This is required due to the secretKey required to sign a transaction + // in the js implementation of NaCL being the combination of the sk and + // vk for some stupid reason. That being said, we still want the sk and + // vk objects to exist in 32-byte string format (same as cilantro's + // python implementation) when presented to the user. + var jsnacl_sk = concatUint8Arrays(kp.sk, kp.vk); + return buf2hex(nacl__default["default"].sign.detached(msg, jsnacl_sk)); +} +/** + * @param String vk + * @param Uint8Array msg + * @param String sig + * vk: A 64 character long hex representation of a verify key (public key) + * msg: A Uint8Array (bytes) representation of a message that has been signed + * sig: A 128 character long hex representation of a nacl signature + * + * @return Bool result + * result: true if verify checked out, false if not + */ +function verify(vk, msg, sig) { + var vkb = hex2buf(vk); + var sigb = hex2buf(sig); + try { + return nacl__default["default"].sign.detached.verify(msg, sigb, vkb); + } catch (_a) { + return false; + } +} +/** + * @param string mnemonic + * @param string[] wordList + * mnemonic: Bip39 24 words mnemonic + * wordList: An array of string(Optional) + * + * @return Boolen res + * res: A boolen value + */ +function validateMnemonic(mnemonic, wordList) { + return bip39__namespace.validateMnemonic(mnemonic, wordList); } var wallet = /*#__PURE__*/Object.freeze({ @@ -3024,37 +3024,37 @@ var wallet = /*#__PURE__*/Object.freeze({ validateMnemonic: validateMnemonic }); -class EventEmitter { - constructor() { - this._events = {}; - } - - on(name, listener) { - if (!this._events[name]) { - this._events[name] = []; - } - - this._events[name].push(listener); - } - - removeListener(name, listenerToRemove) { - if (!this._events[name]) { - throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`); - } - - const filterListeners = (listener) => listener !== listenerToRemove; - this._events[name] = this._events[name].filter(filterListeners); - } - - emit(name, data) { - if (!this._events[name]) return - - const fireCallbacks = (callback) => { - callback(data); - }; - - this._events[name].forEach(fireCallbacks); - } +class EventEmitter { + constructor() { + this._events = {}; + } + + on(name, listener) { + if (!this._events[name]) { + this._events[name] = []; + } + + this._events[name].push(listener); + } + + removeListener(name, listenerToRemove) { + if (!this._events[name]) { + throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`); + } + + const filterListeners = (listener) => listener !== listenerToRemove; + this._events[name] = this._events[name].filter(filterListeners); + } + + emit(name, data) { + if (!this._events[name]) return + + const fireCallbacks = (callback) => { + callback(data); + }; + + this._events[name].forEach(fireCallbacks); + } } var publicApi = {}; @@ -87389,1510 +87389,1510 @@ function toFixedPoint(str, e, z) { var BigNumber = clone(); -BigNumber.config({ RANGE: [-30, 30], EXPONENTIAL_AT: 1e9 }); -BigNumber.set({ DECIMAL_PLACES: 30, ROUNDING_MODE: BigNumber.ROUND_DOWN }); // equivalent - -function Encoder(type, value) { - const throwError = (val) => { - throw new Error(`Error encoding ${val} to ${type}`); - }; - const countDecimals = (n) => { - if (Math.floor(n) === n) return 0; - try { - return n.toString().split(".")[1].length; - } catch (e) { - return 0; - } - }; - const isString = (val) => typeof val === "string" || val instanceof String; - const isArray = (val) => val && typeof val === "object" && val.constructor === Array; - const isObject = (val) => val && typeof val === "object" && val.constructor === Object; - const isDate = (val) => val instanceof Date; - const isBoolean = (val) => typeof val === "boolean"; - - const isNumber = (val) => { - if (isArray(val)) return false; - return !isNaN(encodeBigNumber(val).toNumber()); - }; - - const isInteger = (val) => { - if (!isNumber(val)) return false; - if (countDecimals(val) === 0) return true; - return false; - }; - const encodeInt = (val) => { - if (!isNumber(val)) throwError(val); - else return parseInt(val); - }; - const isFloat = (val) => { - if (!isNumber(val)) return false; - if (countDecimals(val) === 0) return false; - return true; - }; - const encodeFloat = (val) => { - if (!isNumber(val)) throwError(val); - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - - return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; - }; - const encodeNumber = (val) => { - if (!isNumber(val)) throwError(val); - if (isFloat(val)) { - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; - } - if (isInteger(val)) return parseInt(val); - }; - const encodeBigNumber = (val) => { - if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); - return val; - }; - - const encodeBool = (val) => { - if (isBoolean(val)) return val; - if (val === "true" || val === 1) return true; - if (val === "false" || val === 0) return false; - throwError(val); - }; - const encodeStr = (val) => { - if (isString(val)) return val; - if (isDate(val)) return val.toISOString(); - return JSON.stringify(val); - }; - const encodeDateTime = (val) => { - val = !isDate(val) ? new Date(val) : val; - if (!isDate(val)) throwError(val); - return { - __time__: [ - val.getUTCFullYear(), - val.getUTCMonth(), - val.getUTCDate(), - val.getUTCHours(), - val.getUTCMinutes(), - val.getUTCSeconds(), - val.getUTCMilliseconds(), - ], - }; - }; - const encodeTimeDelta = (val) => { - const time = isDate(val) ? val.getTime() : new Date(val).getTime(); - const days = parseInt(time / 1000 / 60 / 60 / 24); - const seconds = (time - days * 24 * 60 * 60 * 1000) / 1000; - return { __delta__: [days, seconds] }; - }; - - const encodeList = (val) => { - if (isArray(val)) return parseObject(val); - try { - val = JSON.parse(val); - } catch (e) { - throwError(val); - } - if (isArray(val)) return parseObject(val); - throwError(val); - }; - - const encodeDict = (val) => { - if (isObject(val)) return parseObject(val); - try { - val = JSON.parse(val); - } catch (e) { - throwError(val); - } - if (isObject(val)) return parseObject(val); - throwError(val); - }; - - const encodeObject = (val) => { - try { - return encodeList(val); - } catch (e) { - return encodeDict(val); - } - }; - - function parseObject(obj) { - const encode = (k, v) => { - if (k === "datetime" || k === "datetime.datetime") return Encoder("datetime.datetime", v); - if (k === "timedelta" || k === "datetime.timedelta") return Encoder("datetime.timedelta", v); - if (k !== "__fixed__" && isFloat(v)) return encodeFloat(v); - return v; - }; - - const fixDatetime = (k, v) => { - const isDatetimeObject = (val) => { - let datetimeTypes = ["datetime.datetime", "datetime", "datetime.timedelta", "timedelta"]; - return ( - Object.keys(val).length === 1 && - datetimeTypes.filter((f) => f === Object.keys(val)[0]).length > 0 - ); - }; - - if (v.constructor === Array) { - v.map((val) => { - if (Object.keys(val).length === 1 && isDatetimeObject(v)) return val[Object.keys(val)[0]]; - //if (isFloat(val)) return encodeFloat(val) - return val; - }); - } - if (v.constructor === Object) { - if (Object.keys(v).length === 1 && isDatetimeObject(v)) return v[Object.keys(v)[0]]; - } - - //if (isFloat(v)) return encodeFloat(v) - - return v; - }; - - let encodeValues = JSON.stringify(obj, encode); - return JSON.parse(encodeValues, fixDatetime); - } - - const encoder = { - str: encodeStr, - string: encodeStr, - float: encodeFloat, - int: encodeInt, - bool: encodeBool, - boolean: encodeBool, - dict: encodeDict, - list: encodeList, - Any: () => value, - "datetime.timedelta": encodeTimeDelta, - "datetime.datetime": encodeDateTime, - timedelta: encodeTimeDelta, - datetime: encodeDateTime, - number: encodeNumber, - object: encodeObject, - bigNumber: encodeBigNumber, - }; - - if (Object.keys(encoder).includes(type)) return encoder[type](value); - else throw new Error(`Error: ${type} is not a valid encoder type.`); -} - +BigNumber.config({ RANGE: [-30, 30], EXPONENTIAL_AT: 1e9 }); +BigNumber.set({ DECIMAL_PLACES: 30, ROUNDING_MODE: BigNumber.ROUND_DOWN }); // equivalent + +function Encoder(type, value) { + const throwError = (val) => { + throw new Error(`Error encoding ${val} to ${type}`); + }; + const countDecimals = (n) => { + if (Math.floor(n) === n) return 0; + try { + return n.toString().split(".")[1].length; + } catch (e) { + return 0; + } + }; + const isString = (val) => typeof val === "string" || val instanceof String; + const isArray = (val) => val && typeof val === "object" && val.constructor === Array; + const isObject = (val) => val && typeof val === "object" && val.constructor === Object; + const isDate = (val) => val instanceof Date; + const isBoolean = (val) => typeof val === "boolean"; + + const isNumber = (val) => { + if (isArray(val)) return false; + return !isNaN(encodeBigNumber(val).toNumber()); + }; + + const isInteger = (val) => { + if (!isNumber(val)) return false; + if (countDecimals(val) === 0) return true; + return false; + }; + const encodeInt = (val) => { + if (!isNumber(val)) throwError(val); + else return parseInt(val); + }; + const isFloat = (val) => { + if (!isNumber(val)) return false; + if (countDecimals(val) === 0) return false; + return true; + }; + const encodeFloat = (val) => { + if (!isNumber(val)) throwError(val); + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + + return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; + }; + const encodeNumber = (val) => { + if (!isNumber(val)) throwError(val); + if (isFloat(val)) { + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + return { __fixed__: val.toFixed(30).replace(/^0+(\d)|(\d)0+$/gm, "$1$2") }; + } + if (isInteger(val)) return parseInt(val); + }; + const encodeBigNumber = (val) => { + if (!BigNumber.isBigNumber(val)) val = new BigNumber(val); + return val; + }; + + const encodeBool = (val) => { + if (isBoolean(val)) return val; + if (val === "true" || val === 1) return true; + if (val === "false" || val === 0) return false; + throwError(val); + }; + const encodeStr = (val) => { + if (isString(val)) return val; + if (isDate(val)) return val.toISOString(); + return JSON.stringify(val); + }; + const encodeDateTime = (val) => { + val = !isDate(val) ? new Date(val) : val; + if (!isDate(val)) throwError(val); + return { + __time__: [ + val.getUTCFullYear(), + val.getUTCMonth(), + val.getUTCDate(), + val.getUTCHours(), + val.getUTCMinutes(), + val.getUTCSeconds(), + val.getUTCMilliseconds(), + ], + }; + }; + const encodeTimeDelta = (val) => { + const time = isDate(val) ? val.getTime() : new Date(val).getTime(); + const days = parseInt(time / 1000 / 60 / 60 / 24); + const seconds = (time - days * 24 * 60 * 60 * 1000) / 1000; + return { __delta__: [days, seconds] }; + }; + + const encodeList = (val) => { + if (isArray(val)) return parseObject(val); + try { + val = JSON.parse(val); + } catch (e) { + throwError(val); + } + if (isArray(val)) return parseObject(val); + throwError(val); + }; + + const encodeDict = (val) => { + if (isObject(val)) return parseObject(val); + try { + val = JSON.parse(val); + } catch (e) { + throwError(val); + } + if (isObject(val)) return parseObject(val); + throwError(val); + }; + + const encodeObject = (val) => { + try { + return encodeList(val); + } catch (e) { + return encodeDict(val); + } + }; + + function parseObject(obj) { + const encode = (k, v) => { + if (k === "datetime" || k === "datetime.datetime") return Encoder("datetime.datetime", v); + if (k === "timedelta" || k === "datetime.timedelta") return Encoder("datetime.timedelta", v); + if (k !== "__fixed__" && isFloat(v)) return encodeFloat(v); + return v; + }; + + const fixDatetime = (k, v) => { + const isDatetimeObject = (val) => { + let datetimeTypes = ["datetime.datetime", "datetime", "datetime.timedelta", "timedelta"]; + return ( + Object.keys(val).length === 1 && + datetimeTypes.filter((f) => f === Object.keys(val)[0]).length > 0 + ); + }; + + if (v.constructor === Array) { + v.map((val) => { + if (Object.keys(val).length === 1 && isDatetimeObject(v)) return val[Object.keys(val)[0]]; + //if (isFloat(val)) return encodeFloat(val) + return val; + }); + } + if (v.constructor === Object) { + if (Object.keys(v).length === 1 && isDatetimeObject(v)) return v[Object.keys(v)[0]]; + } + + //if (isFloat(v)) return encodeFloat(v) + + return v; + }; + + let encodeValues = JSON.stringify(obj, encode); + return JSON.parse(encodeValues, fixDatetime); + } + + const encoder = { + str: encodeStr, + string: encodeStr, + float: encodeFloat, + int: encodeInt, + bool: encodeBool, + boolean: encodeBool, + dict: encodeDict, + list: encodeList, + Any: () => value, + "datetime.timedelta": encodeTimeDelta, + "datetime.datetime": encodeDateTime, + timedelta: encodeTimeDelta, + datetime: encodeDateTime, + number: encodeNumber, + object: encodeObject, + bigNumber: encodeBigNumber, + }; + + if (Object.keys(encoder).includes(type)) return encoder[type](value); + else throw new Error(`Error: ${type} is not a valid encoder type.`); +} + Encoder.BigNumber = BigNumber; -const { validateTypes: validateTypes$4 } = validators; - -class LamdenMasterNode_API { - constructor(networkInfoObj) { - if (!validateTypes$4.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Object and got Type: ${typeof networkInfoObj}`); - if (!validateTypes$4.isArrayWithValues(networkInfoObj.hosts)) - throw new Error(`HOSTS Required (Type: Array)`); - - this.hosts = this.validateHosts(networkInfoObj.hosts); - } - //This will throw an error if the protocol wasn't included in the host string - vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Host String must include http:// or https://"); - } - validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); - } - - get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; - } - get url() { - return this.host; - } - - send(method, path, data, overrideURL, callback) { - let parms = ""; - if (Object.keys(data).includes("parms")) { - parms = this.createParms(data.parms); - } - - let options = {}; - if (method === "POST") { - let headers = { "Content-Type": "application/json" }; - options.method = method; - options.headers = headers; - options.body = data; - } - - return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) - .then(async (res) => { - if (res.status === 200) { - let json = await res.json(); - callback(json, undefined); - return json; - } else { - let error = validateTypes$4.isStringWithValue(res.statusText) ? res.statusText : false; - callback(undefined, error); - return error; - } - }) - .catch((err) => { - return callback(undefined, err.toString()); - }); - } - - createParms(parms) { - if (Object.keys(parms).length === 0) return ""; - let parmString = "?"; - Object.keys(parms).forEach((key) => { - parmString = `${parmString}${key}=${parms[key]}&`; - }); - return parmString.slice(0, -1); - } - - async getContractInfo(contractName) { - const returnInfo = (res) => { - try { - if (res.name) return res; - } catch (e) {} - return {"error":`${contractName} does not exist`}; - }; - let path = `/contracts/${contractName}`; - return this.send("GET", path, {}, undefined, (res, err) => returnInfo(res)).then((res) => - returnInfo(res) - ); - } - - async getVariable(contract, variable, key = "") { - let parms = {}; - if (validateTypes$4.isStringWithValue(key)) parms.key = key; - - let path = `/contracts/${contract}/${variable}/`; - - const returnValue = (res) => { - try { - if (res.value) return res.value; - } catch (e) {} - return null; - }; - return this.send("GET", path, { parms }, undefined, (res, err) => returnValue(res)).then( - (res) => returnValue(res) - ); - } - - async getContractMethods(contract) { - const getMethods = (res) => { - try { - if (res.methods) return res.methods; - } catch (e) {} - return []; - }; - let path = `/contracts/${contract}/methods`; - return this.send("GET", path, {}, undefined, (res, err) => getMethods(res)).then((res) => - getMethods(res) - ); - } - - async getContractVariables(contract) { - const getVariables = (res) => { - try { - if (res.variables) return res; - } catch (e) {} - return {}; - }; - let path = `/contracts/${contract}/variables`; - return this.send("GET", path, {}, undefined, (res, err) => getVariables(res)).then((res) => - getVariables(res) - ); - } - - async pingServer() { - const getStatus = (res) => { - try { - if (res.status) return true; - } catch (e) {} - return false; - }; - let response = await this.send("GET", "/ping", {}, undefined, (res, err) => getStatus(res)); - return getStatus(response); - } - - async getCurrencyBalance(vk) { - let balanceRes = await this.getVariable("currency", "balances", vk); - if (!balanceRes) return Encoder("bigNumber", 0); - if (balanceRes.__fixed__) return Encoder("bigNumber", balanceRes.__fixed__); - return Encoder("bigNumber", balanceRes.toString()); - } - - async contractExists(contractName) { - const exists = (res) => { - try { - if (res.name) return true; - } catch (e) {} - return false; - }; - let path = `/contracts/${contractName}`; - return this.send("GET", path, {}, undefined, (res, err) => exists(res)).then((res) => - exists(res) - ); - } - - async sendTransaction(data, url = undefined, callback) { - return this.send("POST", "/", JSON.stringify(data), url, (res, err) => { - if (err) { - if (callback) { - callback(undefined, err); - return; - } else return err; - } - if (callback) { - callback(res, undefined); - return; - } - return res; - }); - } - - async getNonce(sender, callback) { - if (!validateTypes$4.isStringHex(sender)) return `${sender} is not a hex string.`; - let path = `/nonce/${sender}`; - let url = this.host; - return this.send("GET", path, {}, url, (res, err) => { - if (err) { - if (callback) { - callback(undefined, `Unable to get nonce for ${sender} on network ${url}`); - return; - } - return `Unable to get nonce for ${sender} on network ${url}`; - } - res.masternode = url; - if (callback) { - callback(res, undefined); - return; - } else return res; - }); - } - - checkTransaction(hash, callback) { - const parms = { hash }; - return this.send("GET", "/tx", { parms }, undefined, (res, err) => { - if (err) { - if (callback) { - callback(undefined, err); - return; - } else return err; - } - if (callback) { - callback(res, undefined); - return; - } - return res; - }); - } - - async getLastetBlock(){ - return this.send("GET", "/latest_block", {}) - .then(res => res.json()) - .then(json => { - return { value: json.number } - }) - .catch(err => { - return {error: err.message} - }) - } +const { validateTypes: validateTypes$4 } = validators; + +class LamdenMasterNode_API { + constructor(networkInfoObj) { + if (!validateTypes$4.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Object and got Type: ${typeof networkInfoObj}`); + if (!validateTypes$4.isArrayWithValues(networkInfoObj.hosts)) + throw new Error(`HOSTS Required (Type: Array)`); + + this.hosts = this.validateHosts(networkInfoObj.hosts); + } + //This will throw an error if the protocol wasn't included in the host string + vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Host String must include http:// or https://"); + } + validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); + } + + get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; + } + get url() { + return this.host; + } + + send(method, path, data, overrideURL, callback) { + let parms = ""; + if (Object.keys(data).includes("parms")) { + parms = this.createParms(data.parms); + } + + let options = {}; + if (method === "POST") { + let headers = { "Content-Type": "application/json" }; + options.method = method; + options.headers = headers; + options.body = data; + } + + return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) + .then(async (res) => { + if (res.status === 200) { + let json = await res.json(); + callback(json, undefined); + return json; + } else { + let error = validateTypes$4.isStringWithValue(res.statusText) ? res.statusText : false; + callback(undefined, error); + return error; + } + }) + .catch((err) => { + return callback(undefined, err.toString()); + }); + } + + createParms(parms) { + if (Object.keys(parms).length === 0) return ""; + let parmString = "?"; + Object.keys(parms).forEach((key) => { + parmString = `${parmString}${key}=${parms[key]}&`; + }); + return parmString.slice(0, -1); + } + + async getContractInfo(contractName) { + const returnInfo = (res) => { + try { + if (res.name) return res; + } catch (e) {} + return {"error":`${contractName} does not exist`}; + }; + let path = `/contracts/${contractName}`; + return this.send("GET", path, {}, undefined, (res, err) => returnInfo(res)).then((res) => + returnInfo(res) + ); + } + + async getVariable(contract, variable, key = "") { + let parms = {}; + if (validateTypes$4.isStringWithValue(key)) parms.key = key; + + let path = `/contracts/${contract}/${variable}/`; + + const returnValue = (res) => { + try { + if (res.value) return res.value; + } catch (e) {} + return null; + }; + return this.send("GET", path, { parms }, undefined, (res, err) => returnValue(res)).then( + (res) => returnValue(res) + ); + } + + async getContractMethods(contract) { + const getMethods = (res) => { + try { + if (res.methods) return res.methods; + } catch (e) {} + return []; + }; + let path = `/contracts/${contract}/methods`; + return this.send("GET", path, {}, undefined, (res, err) => getMethods(res)).then((res) => + getMethods(res) + ); + } + + async getContractVariables(contract) { + const getVariables = (res) => { + try { + if (res.variables) return res; + } catch (e) {} + return {}; + }; + let path = `/contracts/${contract}/variables`; + return this.send("GET", path, {}, undefined, (res, err) => getVariables(res)).then((res) => + getVariables(res) + ); + } + + async pingServer() { + const getStatus = (res) => { + try { + if (res.status) return true; + } catch (e) {} + return false; + }; + let response = await this.send("GET", "/ping", {}, undefined, (res, err) => getStatus(res)); + return getStatus(response); + } + + async getCurrencyBalance(vk) { + let balanceRes = await this.getVariable("currency", "balances", vk); + if (!balanceRes) return Encoder("bigNumber", 0); + if (balanceRes.__fixed__) return Encoder("bigNumber", balanceRes.__fixed__); + return Encoder("bigNumber", balanceRes.toString()); + } + + async contractExists(contractName) { + const exists = (res) => { + try { + if (res.name) return true; + } catch (e) {} + return false; + }; + let path = `/contracts/${contractName}`; + return this.send("GET", path, {}, undefined, (res, err) => exists(res)).then((res) => + exists(res) + ); + } + + async sendTransaction(data, url = undefined, callback) { + return this.send("POST", "/", JSON.stringify(data), url, (res, err) => { + if (err) { + if (callback) { + callback(undefined, err); + return; + } else return err; + } + if (callback) { + callback(res, undefined); + return; + } + return res; + }); + } + + async getNonce(sender, callback) { + if (!validateTypes$4.isStringHex(sender)) return `${sender} is not a hex string.`; + let path = `/nonce/${sender}`; + let url = this.host; + return this.send("GET", path, {}, url, (res, err) => { + if (err) { + if (callback) { + callback(undefined, `Unable to get nonce for ${sender} on network ${url}`); + return; + } + return `Unable to get nonce for ${sender} on network ${url}`; + } + res.masternode = url; + if (callback) { + callback(res, undefined); + return; + } else return res; + }); + } + + checkTransaction(hash, callback) { + const parms = { hash }; + return this.send("GET", "/tx", { parms }, undefined, (res, err) => { + if (err) { + if (callback) { + callback(undefined, err); + return; + } else return err; + } + if (callback) { + callback(res, undefined); + return; + } + return res; + }); + } + + async getLastetBlock(){ + return this.send("GET", "/latest_block", {}) + .then(res => res.json()) + .then(json => { + return { value: json.number } + }) + .catch(err => { + return {error: err.message} + }) + } } -const { validateTypes: validateTypes$3 } = validators; - -class LamdenBlockservice_API { -constructor(networkInfoObj) { - if (!validateTypes$3.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Network to be Object and got Type: ${typeof networkInfoObj}`); - if (validateTypes$3.isArrayWithValues(networkInfoObj.blockservice_hosts)){ - this.hosts = this.validateHosts(networkInfoObj.blockservice_hosts); - }else { - this.hosts = []; - } -} -//This will throw an error if the protocol wasn't included in the host string -vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Blockservice host value must include http:// or https://"); -} -validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); -} - -get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; -} -get url() { - return this.host; -} - -send(method, path, data = {}, overrideURL) { - let parms = ""; - if (Object.keys(data).includes("parms")) { - parms = this.createParms(data.parms); - } - - let options = {}; - if (method === "POST") { - let headers = { "Content-Type": "application/json" }; - options.method = method; - options.headers = headers; - options.body = data; - } - return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) -} - -createParms(parms) { - if (Object.keys(parms).length === 0) return ""; - let parmString = "?"; - Object.keys(parms).forEach((key) => { - parmString = `${parmString}${key}=${parms[key]}&`; - }); - return parmString.slice(0, -1); -} - -async pingServer() { - return this.send("GET", "/ping", {}) - .then(res => res.text()) - .then(text => text === "pong") - .catch(() => false) -} - -async getLastetBlock(callback){ - return this.send("GET", "/latest_block", {}) - .then(res => res.json()) - .then(json => { - if (callback) callback(json.latest_block, null); - return json.latest_block - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getBlocks(start_block, limit = 10, callback){ - const parms = { start_block, limit }; - return this.send("GET", "/blocks", { parms }) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getCurrentKeyValue(contractName, variableName, key, callback){ - return this.send("GET", `/current/one/${contractName}/${variableName}/${key}`) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (callback) callback(null, err.message); - return {error: err.message} - }) -} - -async getCurrentKeysValues(keys, callback){ - try{ - let endpont = 'current/keys'; - let data = await this.send('POST', `/${endpont}`, JSON.stringify(keys)) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }); - return data - }catch(err){ - if (callback) callback(null, err.message); - return {error: err.message} - } -} - -async getTransaction(hash, callback) { - const parms = { hash }; - return this.send("GET", "/tx", { parms }) - .then(res => res.json()) - .then(json => { - if (callback) callback(json, null); - return json - }) - .catch(err => { - if (err.message.includes("invalid json response body")) { - if (callback) callback(null, null); - return null - }else { - if (callback) callback(null, err.message); - return {error: err.message} - } - }) - } - -async getContractInfo(contractName) { - return this.send("GET", `/contracts/${contractName}`, {}) - .then(res => res.json()) - .then(json => { - if (Object.keys(json).length > 0) { - let data = json[contractName]; - return { - name: contractName, - code: data['__code__'] - } - } else { - return {"error":`${contractName} does not exist`} - } - }) - .catch(err => { - return {error: err.message} - }) -} +const { validateTypes: validateTypes$3 } = validators; + +class LamdenBlockservice_API { +constructor(networkInfoObj) { + if (!validateTypes$3.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Network to be Object and got Type: ${typeof networkInfoObj}`); + if (validateTypes$3.isArrayWithValues(networkInfoObj.blockservice_hosts)){ + this.hosts = this.validateHosts(networkInfoObj.blockservice_hosts); + }else { + this.hosts = []; + } +} +//This will throw an error if the protocol wasn't included in the host string +vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Blockservice host value must include http:// or https://"); +} +validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); } -const { validateTypes: validateTypes$2 } = validators; - -const NETWORK_VERSIONS = [1, 2]; - -class Network { - // Constructor needs an Object with the following information to build Class. - // - // networkInfo: { - // hosts: list of masternode hostname/ip urls, - // type: "testnet", "mainnet" or "custom", - // version : 1 (default) or 2 - // }, - constructor(networkInfoObj) { - //Reject undefined or missing info - if (!validateTypes$2.isObjectWithKeys(networkInfoObj)) - throw new Error(`Expected Network Info Object and got Type: ${typeof networkInfoObj}`); - if (!validateTypes$2.isArrayWithValues(networkInfoObj.hosts)) - throw new Error(`HOSTS Required (Type: Array)`); - this.classname = 'Network'; - this.type = validateTypes$2.isStringWithValue(networkInfoObj.type) - ? networkInfoObj.type.toLowerCase() - : "custom"; - this.version = this.getNetworkVersion(networkInfoObj.version); - this.events = new EventEmitter(); - this.hosts = this.validateHosts(networkInfoObj.hosts); - this.currencySymbol = validateTypes$2.isStringWithValue(networkInfoObj.currencySymbol) - ? networkInfoObj.currencySymbol - : "TAU"; - this.name = validateTypes$2.isStringWithValue(networkInfoObj.name) - ? networkInfoObj.name - : "lamden network"; - this.lamden = validateTypes$2.isBoolean(networkInfoObj.lamden) ? networkInfoObj.lamden : false; - this.blockExplorer = validateTypes$2.isStringWithValue(networkInfoObj.blockExplorer) - ? networkInfoObj.blockExplorer - : undefined; - - this.online = false; - try { - this.API = new LamdenMasterNode_API(networkInfoObj); - } catch (e) { - throw new Error(e); - } - try { - this.blockservice = new LamdenBlockservice_API(networkInfoObj); - } catch (e) { - throw new Error(e); - } - } - //This will throw an error if the protocol wasn't included in the host string - vaidateProtocol(host) { - let protocols = ["https://", "http://"]; - if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; - throw new Error("Host String must include http:// or https://"); - } - validateHosts(hosts) { - return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); - } - getNetworkVersion(version){ - if (!validateTypes$2.isInteger(version)) return 1 - if (NETWORK_VERSIONS.includes(version)) return version - else return 1 - } - //Check if the network is online - //Emits boolean as 'online' event - //Also returns status as well as passes status to a callback - async ping(callback = undefined) { - this.online = await this.API.pingServer(); - this.events.emit("online", this.online); - if (validateTypes$2.isFunction(callback)) callback(this.online); - return this.online; - } - get host() { - return this.hosts[Math.floor(Math.random() * this.hosts.length)]; - } - get url() { - return this.host; - } - getNetworkInfo() { - return { - name: this.name, - lamden: this.lamden, - type: this.type, - hosts: this.hosts, - blockservice_hosts: this.blockservice.hosts, - url: this.url, - online: this.online, - version: this.version - }; - } - - // Unify APIs - async pingServer() { - let res; - if (this.blockservice.host) { - res = await this.blockservice.pingServer(); - } else { - res = await this.API.pingServer(); - } - return res - } - - async getVariable(contractName, variableName, key) { - if (this.blockservice.host) { - let data = await this.blockservice.getCurrentKeyValue(contractName, variableName, key); - return data - } else { - let res = await this.API.getVariable(contractName, variableName, key); - if (res) { - return { - value: res - } - } else { - return {error: "key or variable not exists"} - } - } - } - - async getCurrencyBalance(vk) { - return await this.getVariable("currency", "balances", vk) - } - - async getContractInfo(contractName) { - if (this.blockservice.host) { - return await this.blockservice.getContractInfo(contractName); - } else { - return await this.API.getContractInfo(contractName); - } - } - - async contractExists(contractName) { - let data; - if (this.blockservice.host) { - data = await this.blockservice.getContractInfo(contractName); - } else { - data = await this.API.getContractInfo(contractName); - } - return data && data.name ? true : false - } - - async getLastetBlock() { - if (this.blockservice.host) { - let data = await this.blockservice.getLastetBlock(); - if (data.error) { - return data - } else { - return { - value: data - } - } - } else { - return await this.API.getLastetBlock(); - } - } - +get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; +} +get url() { + return this.host; } -const { validateTypes: validateTypes$1 } = validators; - -class TransactionBuilder extends Network { - // Constructor needs an Object with the following information to build Class. - // - // arg[0] (networkInfo): { //Can also accpet a Lamden "Network Class" - // host: masternode webserver hostname/ip, - // type: "testnet", "mainnet" or "mockchain" - // } - // arg[1] (txInfo): { - // uid: [Optional] unique ID for tracking purposes, - // senderVk: public key of the transaction sender, - // contractName: name of lamden smart contract, - // methodName: name of method to call in contractName, - // kwargs: key/values of args to pass to methodName - // example: kwargs.to = "270add00fc708791c97aeb5255107c770434bd2ab71c2e103fbee75e202aa15e" - // kwargs.amount = 1000 - // stampLimit: the max amount of stamps the tx should use. tx could use less. if tx needs more the tx will fail. - // nonce: [Optional] send() will attempt to retrieve this info automatically - // processor [Optional] send() will attempt to retrieve this info automatically - // } - // arg[2] (txData): [Optional] state hydrating data - constructor(networkInfo, txInfo, txData) { - if (networkInfo && networkInfo.classname === "Network") super(networkInfo.getNetworkInfo()); - else super(networkInfo); - - //Validate arguments - if (!validateTypes$1.isObjectWithKeys(txInfo)) throw new Error(`txInfo object not found`); - if (!validateTypes$1.isStringHex(txInfo.senderVk)) - throw new Error(`Sender Public Key Required (Type: Hex String)`); - if (!validateTypes$1.isStringWithValue(txInfo.contractName)) - throw new Error(`Contract Name Required (Type: String)`); - if (!validateTypes$1.isStringWithValue(txInfo.methodName)) - throw new Error(`Method Required (Type: String)`); - if (!validateTypes$1.isInteger(txInfo.stampLimit)) - throw new Error(`Stamps Limit Required (Type: Integer)`); - - //Store variables in self for reference - this.uid = validateTypes$1.isStringWithValue(txInfo.uid) ? txInfo.uid : undefined; - this.sender = txInfo.senderVk; - this.contract = txInfo.contractName; - this.method = txInfo.methodName; - this.kwargs = {}; - if (validateTypes$1.isObject(txInfo.kwargs)) this.kwargs = txInfo.kwargs; - this.stampLimit = txInfo.stampLimit; - - //validate and set nonce and processor if user provided them - if (typeof txInfo.nonce !== "undefined") { - if (!validateTypes$1.isInteger(txInfo.nonce)) - throw new Error( - `arg[6] Nonce is required to be an Integer, type ${typeof txInfo.none} was given` - ); - this.nonce = txInfo.nonce; - } - if (typeof txInfo.processor !== "undefined") { - if (!validateTypes$1.isStringWithValue(txInfo.processor)) - throw new Error( - `arg[7] Processor is required to be a String, type ${typeof txInfo.processor} was given` - ); - this.processor = txInfo.processor; - } - - this.signature; - this.transactionSigned = false; - - //Transaction result information - this.nonceResult = {}; - this.txSendResult = { errors: [] }; - this.txBlockResult = {}; - this.txHash; - this.txCheckResult = {}; - this.txCheckAttempts = 0; - this.txCheckLimit = 10; - this.maxBlockToCheck = 15; - this.startBlock = null; - - //Hydrate other items if passed - if (txData) { - if (txData.uid) this.uid = txData.uid; - if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) - this.txSendResult = txData.txSendResult; - if (validateTypes$1.isObjectWithKeys(txData.nonceResult)) { - this.nonceResult = txData.nonceResult; - if (validateTypes$1.isInteger(this.nonceResult.nonce)) this.nonce = this.nonceResult.nonce; - if (validateTypes$1.isStringWithValue(this.nonceResult.processor)) - this.processor = this.nonceResult.processor; - } - if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) { - this.txSendResult = txData.txSendResult; - if (this.txSendResult.hash) this.txHash = this.txSendResult.hash; - } - if (validateTypes$1.isObjectWithKeys(txData.txBlockResult)) - this.txBlockResult = txData.txBlockResult; - if (validateTypes$1.isObjectWithKeys(txData.resultInfo)) this.resultInfo = txData.resultInfo; - } - //Create Capnp messages and transactionMessages - this.makePayload(); - } - makePayload() { - this.payload = { - contract: this.contract, - function: this.method, - kwargs: this.kwargs, - nonce: this.nonce, - processor: this.processor, - sender: this.sender, - stamps_supplied: this.stampLimit, - }; - this.sortedPayload = this.sortObject(this.payload); - } - makeTransaction() { - if (this.version === 1){ - this.tx = { - metadata: { - signature: this.signature, - timestamp: parseInt(+new Date() / 1000), - }, - payload: this.sortedPayload.orderedObj, - }; - } - if (this.version === 2){ - this.tx = { - metadata: { - signature: this.signature - }, - payload: this.sortedPayload.orderedObj, - }; - } - } - verifySignature() { - //Verify the signature is correct - if (!this.transactionSigned) - throw new Error( - "Transaction has not be been signed. Use the sign() method first." - ); - const stringBuffer = Buffer.from(this.sortedPayload.json); - const stringArray = new Uint8Array(stringBuffer); - return verify(this.sender, stringArray, this.signature); - } - sign(sk = undefined, userWallet = undefined) { - const stringBuffer = Buffer.from(this.sortedPayload.json); - const stringArray = new Uint8Array(stringBuffer); - if (userWallet) this.signature = userWallet.sign(stringArray); - else this.signature = sign$1(sk, stringArray); - this.transactionSigned = true; - } - sortObject(object) { - const processObj = (obj) => { - const getType = (value) => { - return Object.prototype.toString.call(value); - }; - const isArray = (value) => { - if (getType(value) === "[object Array]") return true; - return false; - }; - const isObject = (value) => { - if (getType(value) === "[object Object]") return true; - return false; - }; - - const sortObjKeys = (unsorted) => { - const sorted = {}; - Object.keys(unsorted) - .sort() - .forEach((key) => (sorted[key] = unsorted[key])); - return sorted; - }; - - const formatKeys = (unformatted) => { - Object.keys(unformatted).forEach((key) => { - if (isArray(unformatted[key])) - unformatted[key] = unformatted[key].map((item) => { - if (isObject(item)) return formatKeys(item); - return item; - }); - if (isObject(unformatted[key])) unformatted[key] = formatKeys(unformatted[key]); - }); - return sortObjKeys(unformatted); - }; - - if (!isObject(obj)) throw new TypeError("Not a valid Object"); - try { - obj = JSON.parse(JSON.stringify(obj)); - } catch (e) { - throw new TypeError("Not a valid JSON Object"); - } - return formatKeys(obj); - }; - const orderedObj = processObj(object); - return { - orderedObj, - json: JSON.stringify(orderedObj), - }; - } - async getNonce(callback = undefined) { - let timestamp = new Date().toUTCString(); - this.nonceResult = await this.API.getNonce(this.sender); - if (typeof this.nonceResult.nonce === "undefined") { - throw new Error(this.nonceResult); - } - this.nonceResult.timestamp = timestamp; - this.nonce = this.nonceResult.nonce; - this.processor = this.nonceResult.processor; - this.nonceMasternode = this.nonceResult.masternode; - //Create payload object - this.makePayload(); - - if (!callback) return this.nonceResult; - return callback(this.nonceResult); - } - async send(sk = undefined, callback = undefined, masternode = undefined) { - //Error if transaction is not signed and no sk provided to the send method to sign it before sending - if (!validateTypes$1.isStringWithValue(sk) && !this.transactionSigned) { - throw new Error( - `Transation Not Signed: Private key needed or call sign() first` - ); - } - - if (this.blockservice.url){ - if (await this.blockservice.pingServer()) this.startBlock = await this.blockservice.getLastetBlock(); - } - - let timestamp = new Date().toUTCString(); - - try { - //If the nonce isn't set attempt to get it - if (isNaN(this.nonce) || !validateTypes$1.isStringWithValue(this.processor)) - await this.getNonce(); - //if the sk is provided then sign the transaction - if (validateTypes$1.isStringWithValue(sk)) this.sign(sk); - //Serialize transaction - this.makeTransaction(); - //Send transaction to the masternode - let masternodeURL = masternode; - if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode; - let response = await this.API.sendTransaction(this.tx, masternodeURL); - //Set error if txSendResult doesn't exist - if (!response || validateTypes$1.isStringWithValue(response)) { - this.txSendResult.errors = [response || "Unknown Transaction Error"]; - } else { - if (response.error) this.txSendResult.errors = [response.error]; - else this.txSendResult = response; - } - } catch (e) { - this.txSendResult.errors = [e.message]; - } - this.txSendResult.timestamp = timestamp; - return this.handleMasterNodeResponse(this.txSendResult, callback); - } - checkForTransactionResult(callback = undefined) { - return new Promise((resolve) => { - let timerId = setTimeout( - async function checkTx() { - this.txCheckAttempts = this.txCheckAttempts + 1; - let res = await this.API.checkTransaction(this.txHash); - let checkAgain = false; - let timestamp = new Date().toUTCString(); - if (typeof res === "string" || !res) { - if (this.txCheckAttempts < this.txCheckLimit) { - checkAgain = true; - } else { - this.txCheckResult.errors = [ - `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, - res, - ]; - this.txCheckResult.status = 2; - } - } else { - if (res.error) { - if (res.error === "Transaction not found.") { - if (this.txCheckAttempts < this.txCheckLimit) { - checkAgain = true; - } else { - this.txCheckResult.errors = [ - res.error, - `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, - ]; - this.txCheckResult.status = 2; - } - } else { - this.txCheckResult.errors = [res.error]; - } - } else { - this.txCheckResult = res; - } - } - if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000); - else { - if (validateTypes$1.isNumber(this.txCheckResult.status)) { - if (this.txCheckResult.status > 0) { - if (!validateTypes$1.isArray(this.txCheckResult.errors)) - this.txCheckResult.errors = []; - this.txCheckResult.errors.push("This transaction returned a non-zero status code"); - } - } - this.txCheckResult.timestamp = timestamp; - clearTimeout(timerId); - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - } - }.bind(this), - 1000 - ); - }); - } - - async checkTransactionResult(callback) { - await checkBlockserviceForTransactionResult(callback); - } - - async checkBlockserviceForTransactionResult(callback = undefined) { - if (!this.txHash) { - throw new Error("No transaction hash to check.") - } - - // Check if the blockservice is up - let serverAvailable = await this.blockservice.pingServer(); - //If it's not then fail over to checking from the masternode - if (!serverAvailable) { - console.log("Blockservice not available, failing back to masternode."); - return this.checkForTransactionResult(callback).then( - (res) => { - return {txinfo: res, ...res} - } - ) - } - - let count = this.maxBlockToCheck; - return new Promise(async (resolve) => { - let lastLatestBlock = this.startBlock || 0; - // Get the next 10 blocks from the blockservice starting with the block the transction was sent from - const getLatestBlock = async () => { - if (count < 1) { - this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; - this.txCheckResult.status = 2; - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - } - count = count - 1; - let latestBlock = await this.blockservice.getLastetBlock(); - if (latestBlock !== lastLatestBlock){ - lastLatestBlock = latestBlock; - checkForTrasaction(); - }else { - setTimeout(getLatestBlock, 5000); - } - }; - - // Check all the transaction in these blocks for our transction hash - const checkForTrasaction = async () => { - let txResults = await this.blockservice.getTransaction(this.txHash); - if (txResults){ - this.txCheckResult = {...txResults, ...txResults.txInfo}; - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - }else { - if (count < 1){ - this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; - this.txCheckResult.status = 2; - resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); - }else { - setTimeout(getLatestBlock, 5000); - } - } - }; - - getLatestBlock(); - }); - } - handleMasterNodeResponse(result, callback = undefined) { - //Check to see if this is a successful transacation submission - if ( - validateTypes$1.isStringWithValue(result.hash) && - validateTypes$1.isStringWithValue(result.success) - ) { - this.txHash = result.hash; - this.setPendingBlockInfo(); - } else { - this.setBlockResultInfo(result); - this.txBlockResult = result; - } - this.events.emit("response", result, this.resultInfo.subtitle); - if (validateTypes$1.isFunction(callback)) callback(result); - return result; - } - setPendingBlockInfo() { - this.resultInfo = { - title: "Transaction Pending", - subtitle: "Your transaction was submitted and is being processed", - message: `Tx Hash: ${this.txHash}`, - type: "success", - }; - return this.resultInfo; - } - setBlockResultInfo(result) { - let erroredTx = false; - let errorText = `returned an error and `; - let statusCode = validateTypes$1.isNumber(result.status) ? result.status : undefined; - let stamps = result.stampsUsed || result.stamps_used || 0; - let message = ""; - if (validateTypes$1.isArrayWithValues(result.errors)) { - erroredTx = true; - message = `This transaction returned ${result.errors.length} errors.`; - if (result.result) { - if (result.result.includes("AssertionError")) result.errors.push(result.result); - } - } - if (statusCode && erroredTx) errorText = `returned status code ${statusCode} and `; - - this.resultInfo = { - title: `Transaction ${erroredTx ? "Failed" : "Successful"}`, - subtitle: `Your transaction ${erroredTx ? `${errorText} ` : ""}used ${stamps} stamps`, - message, - type: `${erroredTx ? "error" : "success"}`, - errorInfo: erroredTx ? result.errors : undefined, - returnResult: result.result || "", - stampsUsed: stamps, - statusCode, - }; - return this.resultInfo; - } - getResultInfo() { - return this.resultInfo; - } - getTxInfo() { - return { - senderVk: this.sender, - contractName: this.contract, - methodName: this.method, - kwargs: this.kwargs, - stampLimit: this.stampLimit, - }; - } - getAllInfo() { - return { - uid: this.uid, - txHash: this.txHash, - signed: this.transactionSigned, - tx: this.tx, - signature: this.signature, - networkInfo: this.getNetworkInfo(), - txInfo: this.getTxInfo(), - txSendResult: this.txSendResult, - txBlockResult: this.txBlockResult, - resultInfo: this.getResultInfo(), - nonceResult: this.nonceResult, - }; - } +send(method, path, data = {}, overrideURL) { + let parms = ""; + if (Object.keys(data).includes("parms")) { + parms = this.createParms(data.parms); + } + + let options = {}; + if (method === "POST") { + let headers = { "Content-Type": "application/json" }; + options.method = method; + options.headers = headers; + options.body = data; + } + return fetch(`${overrideURL ? overrideURL : this.url}${path}${parms}`, options) } -class TransactionBatcher extends Network { - constructor(networkInfo) { - if (networkInfo && networkInfo.classname === "Network") - super(networkInfo.getNetworkInfo()); - else super(networkInfo); - - this.txBatches = {}; - this.overflow = []; - this.nonceResults = {}; - this.running = false; - } - addTransaction(txInfo){ - if (this.running) { - this.overflow.push(txInfo); - return - } - this.validateTransactionInfo(txInfo); - if (!this.txBatches[txInfo.senderVk]) this.txBatches[txInfo.senderVk] = []; - this.txBatches[txInfo.senderVk].push(txInfo); - } - addTransactionList(txList){ - txList.forEach(txInfo => this.addTransaction(txInfo)); - } - processOverflow(){ - const overflow = this.overflow; - this.overflow = []; - overflow.forEach(txInfo => this.addTransaction(txInfo)); - } - hasTransactions(){ - let test = Object.keys(this.txBatches).map(senderVk => this.txBatches[senderVk].length); - test.filter(f => f === 0); - if (test.length > 0 ) return true - return false - } - validateTransactionInfo(txInfo){ - try{ - new TransactionBuilder(txInfo); - }catch(e){ - return false - } - return true - } - async getStartingNonce(senderVk, callback = undefined){ - let timestamp = new Date().toUTCString(); - let response = await this.API.getNonce(senderVk); - if (typeof response.nonce === 'undefined'){ - throw new Error(response) - } - response.timestamp = timestamp; - this.nonceResults[senderVk] = response; - - if (callback) callback(response); - return response; - } - async sendAllBatches(keyDict){ - if (this.running) return - let sentTransactions = []; - this.running = true; - - await Promise.all(Object.keys(this.txBatches).map((senderVk) => { - const senderBatch = this.txBatches[senderVk].splice(0,15); - if (senderBatch.length <= 15) delete this.txBatches[senderVk]; - - return new Promise(async (resolver) => { - if (senderBatch.length === 0 ) resolver(); - - if (!keyDict[senderVk]) throw new Error(`Cannot sign batch for ${senderVk}. No signing key provided.`) - let nonceResponse = await this.getStartingNonce(senderVk); - let txBatch = this.setBatchNonces(nonceResponse, senderBatch); - this.signBatch(txBatch, keyDict[senderVk]); - this.sendBatch(txBatch).then(sentList => { - sentTransactions = [...sentTransactions, ...sentList]; - resolver(); - }); - }) - })); - - try{ - return Promise.all(sentTransactions) - }catch (e){} - finally{ - this.running = false; - this.processOverflow(); - } - } - setBatchNonces(nonceResult, txList){ - return txList.map((txInfo, index) => { - txInfo.nonce = nonceResult.nonce + index; - txInfo.processor = nonceResult.processor; - return new TransactionBuilder({hosts: [nonceResult.masternode]}, txInfo) - }).sort((a, b) => a.nonce - b.nonce) - } - signBatch(txBatch, key){ - txBatch.forEach(txBuilder => txBuilder.sign(key)); - } - sendBatch(txBatch){ - let resolvedTransactions = []; - return new Promise(resolver => { - const resolve = (index) => { - if ((index + 1) === txBatch.length) resolver(resolvedTransactions); - }; - txBatch.forEach((txBuilder, index) => { - const delayedSend = () => { - resolvedTransactions[index] = txBuilder.send().then(() => {return txBuilder}); - resolve(index); - }; - setTimeout(delayedSend, 1200 * index); - }); - }) - } +createParms(parms) { + if (Object.keys(parms).length === 0) return ""; + let parmString = "?"; + Object.keys(parms).forEach((key) => { + parmString = `${parmString}${key}=${parms[key]}&`; + }); + return parmString.slice(0, -1); } -const { validateTypes, assertTypes } = validators; - -class Keystore { - /** - * Lamden Keystores - * - * This Class will create a lamden keystore instance - * - * @param {Object|undefined} arg constructor argument - * @param {String|undefined} arg.key Create an instance and load it with one private key - * @param {String|undefined} arg.keyList Create an instance and load it with an array of private keys - * @param {String|undefined} arg.keystoreData Create an instance from an existing keystore file data - * @return {Keystore} - */ - constructor(arg = undefined) { - this.KEYSTORE_VERSION = "1.0"; - this.password = null; - this.encryptedData = null; - - this.keyList = (() => { - let keyList = []; - let outerClass = this; - let wallets = []; - - const addKey = (key) => { - keyList.push(key); - createWallets(); - }; - const deleteKey = (position) => { - keyList.splice(position, 1); - createWallets(); - }; - const clearKeys = () => { - keyList = []; - createWallets(); - }; - const numOfKeys = () => keyList.length; - const createWallets = () => { - wallets = []; - keyList.forEach(keyInfo => { - let newWallet = create_wallet({sk: keyInfo.sk, keepPrivate: true}); - newWallet = {...newWallet, ...keyInfo}; - delete newWallet.sk; - wallets.push(newWallet); - }); - }; - const createKeystore = (password, hint = undefined) => { - return JSON.stringify({ - data: encryptObject(password, {version: outerClass.KEYSTORE_VERSION, keyList}), - w: !hint ? "" : encryptStrHash('n1ahcKc0lb', hint), - }); - }; - const decryptKeystore = (password, data) => { - let decrypted = decryptObject(password, data); - if (decrypted) { - assertTypes.isArray(decrypted.keyList); - decrypted.keyList.forEach(keyInfo => assertTypes.isStringWithValue(keyInfo.sk)); - decrypted.keyList.forEach(keyInfo => addKey(keyInfo)); - outerClass.version = decrypted.version; - } else { - throw new Error("Incorrect Keystore Password.") - } - }; - - return { - getWallets: () => wallets, - getWallet: (vk) => wallets.find(wallet => wallet.vk === vk), - addKey, - clearKeys, - numOfKeys, - deleteKey, - createKeystore, - decryptKeystore - } - })(); - - if (arg){ - if (arg.key) this.addKey(arg.key); - if (arg.keyList) this.addKeys(arg.keyList); - if (arg.keystoreData) this.addKeystoreData(arg.keystoreData); - } - } - /** - * Add a list of keys to add to the keystore - * @typedef {Object} keyinfo - * @property {string} sk - The private key. - * @property {string} nickname - The key nickname. - * @property {string} name - The key name. - * @property {string} network - Network name. - * @property {string} symbol - The token symbol. - * @param {Array.} keyList An array of keyinfo Object - */ - addKeys(keyList){ - assertTypes.isArray(keyList); - keyList.forEach(key => this.addKey(key)); - } - /** - * Add a key to the keystore - * @typedef {Object} keyinfo - * @property {string} sk - The private key. - * @property {string} nickname - The key nickname. - * @property {string} name - The key name. - * @property {string} network - Network name. - * @property {string} symbol - The token symbol. - * @param {keyinfo} keyInfo A keyinfo Object - */ - addKey(keyInfo){ - assertTypes.isObjectWithKeys(keyInfo); - assertTypes.isStringWithValue(keyInfo.sk); - if (validateTypes.isStringWithValue(keyInfo.vk)) delete keyInfo.vk; - this.keyList.addKey(keyInfo); - } - /** - * Load the keystore with the data from an existing keystore - * @param {string} keystoreData The contents of an existing encrypted keystore file - */ - addKeystoreData(keystoreData){ - if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); - if(this.validateKeyStore(keystoreData)){ - this.encryptedData = keystoreData; - } - } - /** - * Returns the password hint in a keystore file - * @param {String|undefined} keystoreData The contents of an existing encrypted keystore file if one wasn't supplied to the constructor - */ - getPasswordHint(keystoreData = undefined){ - if (!this.encryptedData && !keystoreData) throw new Error("No keystore data found.") - - if (keystoreData) { - if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); - } - else keystoreData = this.encryptedData; - - if (keystoreData.w) return decryptStrHash('n1ahcKc0lb', keystoreData.w); - else return "" - } - /** - * Removes a specific key from the keyList - * @param {Number} keyIndex The index of the key you want to remove - */ - deleteKey(keyIndex){ - assertTypes.isInteger(keyIndex); - if (this.keyList.numOfKeys() === 0) return - if (keyIndex < 0 || keyIndex >= this.keyList.numOfKeys()) throw new Error("Key index out of range.") - this.keyList.deleteKey(keyIndex); - } - /** - * Clears all keys from the keystore - */ - clearKeys(){ - this.keyList.clearKeys(); - } - /** - * Clears all keys from the keystore - * @return {Array.} An array of wallet objects - */ - get wallets() { - return this.keyList.getWallets() - } - /** - * Load the keystore with the data from an existing keystore - * @param {String} vk A 32 character long Lamden public key - * @return {Object} A wallet object - */ - getWallet(vk) { - return this.keyList.getWallet(vk) - } - /** - * Used to validate that a keystore is the proper Lamden Format (does not decrypt data) - * @param {String} keystoreData The contents of an existing encrypted keystore file - * @return {Boolean} valid - * @throws {Error} This is not a valid keystore file. - */ - validateKeyStore(keystoreData){ - assertTypes.isObjectWithKeys(keystoreData); - try{ - let encryptedData = JSON.parse(keystoreData.data); - if (!encryptedData.ct || !encryptedData.iv || !encryptedData.s){ - throw new Error("This is not a valid keystore file.") - } - } catch (e) { - throw new Error("This is not a valid keystore file.") - } - return true; - } - /** - * Create a Keystore text string from the keys contained in the Keystore instance - * @param {String} password A password to encrypt the data - * @param {String|undefined} hint An optional password hint. Not stored in clear text (obsured) but not encrypted with the password. - * @return {String} A JSON stringified object containing the encrypted data - * @throws {Error} Any errors from the encyption process - */ - createKeystore(password, hint = undefined) { - assertTypes.isStringWithValue(password); - if (hint){ - assertTypes.isStringWithValue(hint); - } - return this.keyList.createKeystore(password, hint) - } - /** - * Decrypt a keystore into a useable array of wallets. Any decrypted keys will be added to existing keys in the keystore. - * @param {String} password A password to encrypt the data - * @param {String|undefined} keystoreData The encrypted contents from a keystore file if not passed into the constructor. - * @throws {Error} Any errors from the encyption process - */ - decryptKeystore(password, keystoreData = undefined){ - if (keystoreData) this.addKeystoreData(keystoreData); - if (!this.encryptedData) throw new Error ("No keystoreData to decrypt.") - try{ - this.keyList.decryptKeystore(password, this.encryptedData.data); - }catch (e){ - throw new Error("Incorrect Keystore Password.") - } - } +async pingServer() { + return this.send("GET", "/ping", {}) + .then(res => res.text()) + .then(text => text === "pong") + .catch(() => false) +} + +async getLastetBlock(callback){ + return this.send("GET", "/latest_block", {}) + .then(res => res.json()) + .then(json => { + if (callback) callback(json.latest_block, null); + return json.latest_block + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) } -globalThis.Buffer = buffer.Buffer; - -var index = { - TransactionBuilder, - TransactionBatcher, - Masternode_API: LamdenMasterNode_API, - Blockservice_API: LamdenBlockservice_API, - Network, - wallet, - Keystore, - Encoder, - utils: utils$1, +async getBlocks(start_block, limit = 10, callback){ + const parms = { start_block, limit }; + return this.send("GET", "/blocks", { parms }) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) +} + +async getCurrentKeyValue(contractName, variableName, key, callback){ + return this.send("GET", `/current/one/${contractName}/${variableName}/${key}`) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (callback) callback(null, err.message); + return {error: err.message} + }) +} + +async getCurrentKeysValues(keys, callback){ + try{ + let endpont = 'current/keys'; + let data = await this.send('POST', `/${endpont}`, JSON.stringify(keys)) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }); + return data + }catch(err){ + if (callback) callback(null, err.message); + return {error: err.message} + } +} + +async getTransaction(hash, callback) { + const parms = { hash }; + return this.send("GET", "/tx", { parms }) + .then(res => res.json()) + .then(json => { + if (callback) callback(json, null); + return json + }) + .catch(err => { + if (err.message.includes("invalid json response body")) { + if (callback) callback(null, null); + return null + }else { + if (callback) callback(null, err.message); + return {error: err.message} + } + }) + } + +async getContractInfo(contractName) { + return this.send("GET", `/contracts/${contractName}`, {}) + .then(res => res.json()) + .then(json => { + if (Object.keys(json).length > 0) { + let data = json[contractName]; + return { + name: contractName, + code: data['__code__'] + } + } else { + return {"error":`${contractName} does not exist`} + } + }) + .catch(err => { + return {error: err.message} + }) +} +} + +const { validateTypes: validateTypes$2 } = validators; + +const NETWORK_VERSIONS = [1, 2]; + +class Network { + // Constructor needs an Object with the following information to build Class. + // + // networkInfo: { + // hosts: list of masternode hostname/ip urls, + // type: "testnet", "mainnet" or "custom", + // version : 1 (default) or 2 + // }, + constructor(networkInfoObj) { + //Reject undefined or missing info + if (!validateTypes$2.isObjectWithKeys(networkInfoObj)) + throw new Error(`Expected Network Info Object and got Type: ${typeof networkInfoObj}`); + if (!validateTypes$2.isArrayWithValues(networkInfoObj.hosts)) + throw new Error(`HOSTS Required (Type: Array)`); + this.classname = 'Network'; + this.type = validateTypes$2.isStringWithValue(networkInfoObj.type) + ? networkInfoObj.type.toLowerCase() + : "custom"; + this.version = this.getNetworkVersion(networkInfoObj.version); + this.events = new EventEmitter(); + this.hosts = this.validateHosts(networkInfoObj.hosts); + this.currencySymbol = validateTypes$2.isStringWithValue(networkInfoObj.currencySymbol) + ? networkInfoObj.currencySymbol + : "TAU"; + this.name = validateTypes$2.isStringWithValue(networkInfoObj.name) + ? networkInfoObj.name + : "lamden network"; + this.lamden = validateTypes$2.isBoolean(networkInfoObj.lamden) ? networkInfoObj.lamden : false; + this.blockExplorer = validateTypes$2.isStringWithValue(networkInfoObj.blockExplorer) + ? networkInfoObj.blockExplorer + : undefined; + + this.online = false; + try { + this.API = new LamdenMasterNode_API(networkInfoObj); + } catch (e) { + throw new Error(e); + } + try { + this.blockservice = new LamdenBlockservice_API(networkInfoObj); + } catch (e) { + throw new Error(e); + } + } + //This will throw an error if the protocol wasn't included in the host string + vaidateProtocol(host) { + let protocols = ["https://", "http://"]; + if (protocols.map((protocol) => host.includes(protocol)).includes(true)) return host; + throw new Error("Host String must include http:// or https://"); + } + validateHosts(hosts) { + return hosts.map((host) => this.vaidateProtocol(host.toLowerCase())); + } + getNetworkVersion(version){ + if (!validateTypes$2.isInteger(version)) return 1 + if (NETWORK_VERSIONS.includes(version)) return version + else return 1 + } + //Check if the network is online + //Emits boolean as 'online' event + //Also returns status as well as passes status to a callback + async ping(callback = undefined) { + this.online = await this.API.pingServer(); + this.events.emit("online", this.online); + if (validateTypes$2.isFunction(callback)) callback(this.online); + return this.online; + } + get host() { + return this.hosts[Math.floor(Math.random() * this.hosts.length)]; + } + get url() { + return this.host; + } + getNetworkInfo() { + return { + name: this.name, + lamden: this.lamden, + type: this.type, + hosts: this.hosts, + blockservice_hosts: this.blockservice.hosts, + url: this.url, + online: this.online, + version: this.version + }; + } + + // Unify APIs + async pingServer() { + let res; + if (this.blockservice.host) { + res = await this.blockservice.pingServer(); + } else { + res = await this.API.pingServer(); + } + return res + } + + async getVariable(contractName, variableName, key) { + if (this.blockservice.host) { + let data = await this.blockservice.getCurrentKeyValue(contractName, variableName, key); + return data + } else { + let res = await this.API.getVariable(contractName, variableName, key); + if (res) { + return { + value: res + } + } else { + return {error: "key or variable not exists"} + } + } + } + + async getCurrencyBalance(vk) { + return await this.getVariable("currency", "balances", vk) + } + + async getContractInfo(contractName) { + if (this.blockservice.host) { + return await this.blockservice.getContractInfo(contractName); + } else { + return await this.API.getContractInfo(contractName); + } + } + + async contractExists(contractName) { + let data; + if (this.blockservice.host) { + data = await this.blockservice.getContractInfo(contractName); + } else { + data = await this.API.getContractInfo(contractName); + } + return data && data.name ? true : false + } + + async getLastetBlock() { + if (this.blockservice.host) { + let data = await this.blockservice.getLastetBlock(); + if (data.error) { + return data + } else { + return { + value: data + } + } + } else { + return await this.API.getLastetBlock(); + } + } + +} + +const { validateTypes: validateTypes$1 } = validators; + +class TransactionBuilder extends Network { + // Constructor needs an Object with the following information to build Class. + // + // arg[0] (networkInfo): { //Can also accpet a Lamden "Network Class" + // host: masternode webserver hostname/ip, + // type: "testnet", "mainnet" or "mockchain" + // } + // arg[1] (txInfo): { + // uid: [Optional] unique ID for tracking purposes, + // senderVk: public key of the transaction sender, + // contractName: name of lamden smart contract, + // methodName: name of method to call in contractName, + // kwargs: key/values of args to pass to methodName + // example: kwargs.to = "270add00fc708791c97aeb5255107c770434bd2ab71c2e103fbee75e202aa15e" + // kwargs.amount = 1000 + // stampLimit: the max amount of stamps the tx should use. tx could use less. if tx needs more the tx will fail. + // nonce: [Optional] send() will attempt to retrieve this info automatically + // processor [Optional] send() will attempt to retrieve this info automatically + // } + // arg[2] (txData): [Optional] state hydrating data + constructor(networkInfo, txInfo, txData) { + if (networkInfo && networkInfo.classname === "Network") super(networkInfo.getNetworkInfo()); + else super(networkInfo); + + //Validate arguments + if (!validateTypes$1.isObjectWithKeys(txInfo)) throw new Error(`txInfo object not found`); + if (!validateTypes$1.isStringHex(txInfo.senderVk)) + throw new Error(`Sender Public Key Required (Type: Hex String)`); + if (!validateTypes$1.isStringWithValue(txInfo.contractName)) + throw new Error(`Contract Name Required (Type: String)`); + if (!validateTypes$1.isStringWithValue(txInfo.methodName)) + throw new Error(`Method Required (Type: String)`); + if (!validateTypes$1.isInteger(txInfo.stampLimit)) + throw new Error(`Stamps Limit Required (Type: Integer)`); + + //Store variables in self for reference + this.uid = validateTypes$1.isStringWithValue(txInfo.uid) ? txInfo.uid : undefined; + this.sender = txInfo.senderVk; + this.contract = txInfo.contractName; + this.method = txInfo.methodName; + this.kwargs = {}; + if (validateTypes$1.isObject(txInfo.kwargs)) this.kwargs = txInfo.kwargs; + this.stampLimit = txInfo.stampLimit; + + //validate and set nonce and processor if user provided them + if (typeof txInfo.nonce !== "undefined") { + if (!validateTypes$1.isInteger(txInfo.nonce)) + throw new Error( + `arg[6] Nonce is required to be an Integer, type ${typeof txInfo.none} was given` + ); + this.nonce = txInfo.nonce; + } + if (typeof txInfo.processor !== "undefined") { + if (!validateTypes$1.isStringWithValue(txInfo.processor)) + throw new Error( + `arg[7] Processor is required to be a String, type ${typeof txInfo.processor} was given` + ); + this.processor = txInfo.processor; + } + + this.signature; + this.transactionSigned = false; + + //Transaction result information + this.nonceResult = {}; + this.txSendResult = { errors: [] }; + this.txBlockResult = {}; + this.txHash; + this.txCheckResult = {}; + this.txCheckAttempts = 0; + this.txCheckLimit = 10; + this.maxBlockToCheck = 15; + this.startBlock = null; + + //Hydrate other items if passed + if (txData) { + if (txData.uid) this.uid = txData.uid; + if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) + this.txSendResult = txData.txSendResult; + if (validateTypes$1.isObjectWithKeys(txData.nonceResult)) { + this.nonceResult = txData.nonceResult; + if (validateTypes$1.isInteger(this.nonceResult.nonce)) this.nonce = this.nonceResult.nonce; + if (validateTypes$1.isStringWithValue(this.nonceResult.processor)) + this.processor = this.nonceResult.processor; + } + if (validateTypes$1.isObjectWithKeys(txData.txSendResult)) { + this.txSendResult = txData.txSendResult; + if (this.txSendResult.hash) this.txHash = this.txSendResult.hash; + } + if (validateTypes$1.isObjectWithKeys(txData.txBlockResult)) + this.txBlockResult = txData.txBlockResult; + if (validateTypes$1.isObjectWithKeys(txData.resultInfo)) this.resultInfo = txData.resultInfo; + } + //Create Capnp messages and transactionMessages + this.makePayload(); + } + makePayload() { + this.payload = { + contract: this.contract, + function: this.method, + kwargs: this.kwargs, + nonce: this.nonce, + processor: this.processor, + sender: this.sender, + stamps_supplied: this.stampLimit, + }; + this.sortedPayload = this.sortObject(this.payload); + } + makeTransaction() { + if (this.version === 1){ + this.tx = { + metadata: { + signature: this.signature, + timestamp: parseInt(+new Date() / 1000), + }, + payload: this.sortedPayload.orderedObj, + }; + } + if (this.version === 2){ + this.tx = { + metadata: { + signature: this.signature + }, + payload: this.sortedPayload.orderedObj, + }; + } + } + verifySignature() { + //Verify the signature is correct + if (!this.transactionSigned) + throw new Error( + "Transaction has not be been signed. Use the sign() method first." + ); + const stringBuffer = Buffer.from(this.sortedPayload.json); + const stringArray = new Uint8Array(stringBuffer); + return verify(this.sender, stringArray, this.signature); + } + sign(sk = undefined, userWallet = undefined) { + const stringBuffer = Buffer.from(this.sortedPayload.json); + const stringArray = new Uint8Array(stringBuffer); + if (userWallet) this.signature = userWallet.sign(stringArray); + else this.signature = sign$1(sk, stringArray); + this.transactionSigned = true; + } + sortObject(object) { + const processObj = (obj) => { + const getType = (value) => { + return Object.prototype.toString.call(value); + }; + const isArray = (value) => { + if (getType(value) === "[object Array]") return true; + return false; + }; + const isObject = (value) => { + if (getType(value) === "[object Object]") return true; + return false; + }; + + const sortObjKeys = (unsorted) => { + const sorted = {}; + Object.keys(unsorted) + .sort() + .forEach((key) => (sorted[key] = unsorted[key])); + return sorted; + }; + + const formatKeys = (unformatted) => { + Object.keys(unformatted).forEach((key) => { + if (isArray(unformatted[key])) + unformatted[key] = unformatted[key].map((item) => { + if (isObject(item)) return formatKeys(item); + return item; + }); + if (isObject(unformatted[key])) unformatted[key] = formatKeys(unformatted[key]); + }); + return sortObjKeys(unformatted); + }; + + if (!isObject(obj)) throw new TypeError("Not a valid Object"); + try { + obj = JSON.parse(JSON.stringify(obj)); + } catch (e) { + throw new TypeError("Not a valid JSON Object"); + } + return formatKeys(obj); + }; + const orderedObj = processObj(object); + return { + orderedObj, + json: JSON.stringify(orderedObj), + }; + } + async getNonce(callback = undefined) { + let timestamp = new Date().toUTCString(); + this.nonceResult = await this.API.getNonce(this.sender); + if (typeof this.nonceResult.nonce === "undefined") { + throw new Error(this.nonceResult); + } + this.nonceResult.timestamp = timestamp; + this.nonce = this.nonceResult.nonce; + this.processor = this.nonceResult.processor; + this.nonceMasternode = this.nonceResult.masternode; + //Create payload object + this.makePayload(); + + if (!callback) return this.nonceResult; + return callback(this.nonceResult); + } + async send(sk = undefined, callback = undefined, masternode = undefined) { + //Error if transaction is not signed and no sk provided to the send method to sign it before sending + if (!validateTypes$1.isStringWithValue(sk) && !this.transactionSigned) { + throw new Error( + `Transation Not Signed: Private key needed or call sign() first` + ); + } + + if (this.blockservice.url){ + if (await this.blockservice.pingServer()) this.startBlock = await this.blockservice.getLastetBlock(); + } + + let timestamp = new Date().toUTCString(); + + try { + //If the nonce isn't set attempt to get it + if (isNaN(this.nonce) || !validateTypes$1.isStringWithValue(this.processor)) + await this.getNonce(); + //if the sk is provided then sign the transaction + if (validateTypes$1.isStringWithValue(sk)) this.sign(sk); + //Serialize transaction + this.makeTransaction(); + //Send transaction to the masternode + let masternodeURL = masternode; + if (!masternodeURL && this.nonceMasternode) masternodeURL = this.nonceMasternode; + let response = await this.API.sendTransaction(this.tx, masternodeURL); + //Set error if txSendResult doesn't exist + if (!response || validateTypes$1.isStringWithValue(response)) { + this.txSendResult.errors = [response || "Unknown Transaction Error"]; + } else { + if (response.error) this.txSendResult.errors = [response.error]; + else this.txSendResult = response; + } + } catch (e) { + this.txSendResult.errors = [e.message]; + } + this.txSendResult.timestamp = timestamp; + return this.handleMasterNodeResponse(this.txSendResult, callback); + } + checkForTransactionResult(callback = undefined) { + return new Promise((resolve) => { + let timerId = setTimeout( + async function checkTx() { + this.txCheckAttempts = this.txCheckAttempts + 1; + let res = await this.API.checkTransaction(this.txHash); + let checkAgain = false; + let timestamp = new Date().toUTCString(); + if (typeof res === "string" || !res) { + if (this.txCheckAttempts < this.txCheckLimit) { + checkAgain = true; + } else { + this.txCheckResult.errors = [ + `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, + res, + ]; + this.txCheckResult.status = 2; + } + } else { + if (res.error) { + if (res.error === "Transaction not found.") { + if (this.txCheckAttempts < this.txCheckLimit) { + checkAgain = true; + } else { + this.txCheckResult.errors = [ + res.error, + `Retry Attempts ${this.txCheckAttempts} hit while checking for Tx Result.`, + ]; + this.txCheckResult.status = 2; + } + } else { + this.txCheckResult.errors = [res.error]; + } + } else { + this.txCheckResult = res; + } + } + if (checkAgain) timerId = setTimeout(checkTx.bind(this), 1000); + else { + if (validateTypes$1.isNumber(this.txCheckResult.status)) { + if (this.txCheckResult.status > 0) { + if (!validateTypes$1.isArray(this.txCheckResult.errors)) + this.txCheckResult.errors = []; + this.txCheckResult.errors.push("This transaction returned a non-zero status code"); + } + } + this.txCheckResult.timestamp = timestamp; + clearTimeout(timerId); + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + } + }.bind(this), + 1000 + ); + }); + } + + async checkTransactionResult(callback) { + await checkBlockserviceForTransactionResult(callback); + } + + async checkBlockserviceForTransactionResult(callback = undefined) { + if (!this.txHash) { + throw new Error("No transaction hash to check.") + } + + // Check if the blockservice is up + let serverAvailable = await this.blockservice.pingServer(); + //If it's not then fail over to checking from the masternode + if (!serverAvailable) { + console.log("Blockservice not available, failing back to masternode."); + return this.checkForTransactionResult(callback).then( + (res) => { + return {txinfo: res, ...res} + } + ) + } + + let count = this.maxBlockToCheck; + return new Promise(async (resolve) => { + let lastLatestBlock = this.startBlock || 0; + // Get the next 10 blocks from the blockservice starting with the block the transction was sent from + const getLatestBlock = async () => { + if (count < 1) { + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; + this.txCheckResult.status = 2; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + } + count = count - 1; + let latestBlock = await this.blockservice.getLastetBlock(); + if (latestBlock !== lastLatestBlock){ + lastLatestBlock = latestBlock; + checkForTrasaction(); + }else { + setTimeout(getLatestBlock, 5000); + } + }; + + // Check all the transaction in these blocks for our transction hash + const checkForTrasaction = async () => { + let txResults = await this.blockservice.getTransaction(this.txHash); + if (txResults){ + this.txCheckResult = {...txResults, ...txResults.txInfo}; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + }else { + if (count < 1){ + this.txCheckResult.errors = [`No transaction result found within ${this.maxBlockToCheck} attempts.`]; + this.txCheckResult.status = 2; + resolve(this.handleMasterNodeResponse(this.txCheckResult, callback)); + }else { + setTimeout(getLatestBlock, 5000); + } + } + }; + + getLatestBlock(); + }); + } + handleMasterNodeResponse(result, callback = undefined) { + //Check to see if this is a successful transacation submission + if ( + validateTypes$1.isStringWithValue(result.hash) && + validateTypes$1.isStringWithValue(result.success) + ) { + this.txHash = result.hash; + this.setPendingBlockInfo(); + } else { + this.setBlockResultInfo(result); + this.txBlockResult = result; + } + this.events.emit("response", result, this.resultInfo.subtitle); + if (validateTypes$1.isFunction(callback)) callback(result); + return result; + } + setPendingBlockInfo() { + this.resultInfo = { + title: "Transaction Pending", + subtitle: "Your transaction was submitted and is being processed", + message: `Tx Hash: ${this.txHash}`, + type: "success", + }; + return this.resultInfo; + } + setBlockResultInfo(result) { + let erroredTx = false; + let errorText = `returned an error and `; + let statusCode = validateTypes$1.isNumber(result.status) ? result.status : undefined; + let stamps = result.stampsUsed || result.stamps_used || 0; + let message = ""; + if (validateTypes$1.isArrayWithValues(result.errors)) { + erroredTx = true; + message = `This transaction returned ${result.errors.length} errors.`; + if (result.result) { + if (result.result.includes("AssertionError")) result.errors.push(result.result); + } + } + if (statusCode && erroredTx) errorText = `returned status code ${statusCode} and `; + + this.resultInfo = { + title: `Transaction ${erroredTx ? "Failed" : "Successful"}`, + subtitle: `Your transaction ${erroredTx ? `${errorText} ` : ""}used ${stamps} stamps`, + message, + type: `${erroredTx ? "error" : "success"}`, + errorInfo: erroredTx ? result.errors : undefined, + returnResult: result.result || "", + stampsUsed: stamps, + statusCode, + }; + return this.resultInfo; + } + getResultInfo() { + return this.resultInfo; + } + getTxInfo() { + return { + senderVk: this.sender, + contractName: this.contract, + methodName: this.method, + kwargs: this.kwargs, + stampLimit: this.stampLimit, + }; + } + getAllInfo() { + return { + uid: this.uid, + txHash: this.txHash, + signed: this.transactionSigned, + tx: this.tx, + signature: this.signature, + networkInfo: this.getNetworkInfo(), + txInfo: this.getTxInfo(), + txSendResult: this.txSendResult, + txBlockResult: this.txBlockResult, + resultInfo: this.getResultInfo(), + nonceResult: this.nonceResult, + }; + } +} + +class TransactionBatcher extends Network { + constructor(networkInfo) { + if (networkInfo && networkInfo.classname === "Network") + super(networkInfo.getNetworkInfo()); + else super(networkInfo); + + this.txBatches = {}; + this.overflow = []; + this.nonceResults = {}; + this.running = false; + } + addTransaction(txInfo){ + if (this.running) { + this.overflow.push(txInfo); + return + } + this.validateTransactionInfo(txInfo); + if (!this.txBatches[txInfo.senderVk]) this.txBatches[txInfo.senderVk] = []; + this.txBatches[txInfo.senderVk].push(txInfo); + } + addTransactionList(txList){ + txList.forEach(txInfo => this.addTransaction(txInfo)); + } + processOverflow(){ + const overflow = this.overflow; + this.overflow = []; + overflow.forEach(txInfo => this.addTransaction(txInfo)); + } + hasTransactions(){ + let test = Object.keys(this.txBatches).map(senderVk => this.txBatches[senderVk].length); + test.filter(f => f === 0); + if (test.length > 0 ) return true + return false + } + validateTransactionInfo(txInfo){ + try{ + new TransactionBuilder(txInfo); + }catch(e){ + return false + } + return true + } + async getStartingNonce(senderVk, callback = undefined){ + let timestamp = new Date().toUTCString(); + let response = await this.API.getNonce(senderVk); + if (typeof response.nonce === 'undefined'){ + throw new Error(response) + } + response.timestamp = timestamp; + this.nonceResults[senderVk] = response; + + if (callback) callback(response); + return response; + } + async sendAllBatches(keyDict){ + if (this.running) return + let sentTransactions = []; + this.running = true; + + await Promise.all(Object.keys(this.txBatches).map((senderVk) => { + const senderBatch = this.txBatches[senderVk].splice(0,15); + if (senderBatch.length <= 15) delete this.txBatches[senderVk]; + + return new Promise(async (resolver) => { + if (senderBatch.length === 0 ) resolver(); + + if (!keyDict[senderVk]) throw new Error(`Cannot sign batch for ${senderVk}. No signing key provided.`) + let nonceResponse = await this.getStartingNonce(senderVk); + let txBatch = this.setBatchNonces(nonceResponse, senderBatch); + this.signBatch(txBatch, keyDict[senderVk]); + this.sendBatch(txBatch).then(sentList => { + sentTransactions = [...sentTransactions, ...sentList]; + resolver(); + }); + }) + })); + + try{ + return Promise.all(sentTransactions) + }catch (e){} + finally{ + this.running = false; + this.processOverflow(); + } + } + setBatchNonces(nonceResult, txList){ + return txList.map((txInfo, index) => { + txInfo.nonce = nonceResult.nonce + index; + txInfo.processor = nonceResult.processor; + return new TransactionBuilder({hosts: [nonceResult.masternode]}, txInfo) + }).sort((a, b) => a.nonce - b.nonce) + } + signBatch(txBatch, key){ + txBatch.forEach(txBuilder => txBuilder.sign(key)); + } + sendBatch(txBatch){ + let resolvedTransactions = []; + return new Promise(resolver => { + const resolve = (index) => { + if ((index + 1) === txBatch.length) resolver(resolvedTransactions); + }; + txBatch.forEach((txBuilder, index) => { + const delayedSend = () => { + resolvedTransactions[index] = txBuilder.send().then(() => {return txBuilder}); + resolve(index); + }; + setTimeout(delayedSend, 1200 * index); + }); + }) + } +} + +const { validateTypes, assertTypes } = validators; + +class Keystore { + /** + * Lamden Keystores + * + * This Class will create a lamden keystore instance + * + * @param {Object|undefined} arg constructor argument + * @param {String|undefined} arg.key Create an instance and load it with one private key + * @param {String|undefined} arg.keyList Create an instance and load it with an array of private keys + * @param {String|undefined} arg.keystoreData Create an instance from an existing keystore file data + * @return {Keystore} + */ + constructor(arg = undefined) { + this.KEYSTORE_VERSION = "1.0"; + this.password = null; + this.encryptedData = null; + + this.keyList = (() => { + let keyList = []; + let outerClass = this; + let wallets = []; + + const addKey = (key) => { + keyList.push(key); + createWallets(); + }; + const deleteKey = (position) => { + keyList.splice(position, 1); + createWallets(); + }; + const clearKeys = () => { + keyList = []; + createWallets(); + }; + const numOfKeys = () => keyList.length; + const createWallets = () => { + wallets = []; + keyList.forEach(keyInfo => { + let newWallet = create_wallet({sk: keyInfo.sk, keepPrivate: true}); + newWallet = {...newWallet, ...keyInfo}; + delete newWallet.sk; + wallets.push(newWallet); + }); + }; + const createKeystore = (password, hint = undefined) => { + return JSON.stringify({ + data: encryptObject(password, {version: outerClass.KEYSTORE_VERSION, keyList}), + w: !hint ? "" : encryptStrHash('n1ahcKc0lb', hint), + }); + }; + const decryptKeystore = (password, data) => { + let decrypted = decryptObject(password, data); + if (decrypted) { + assertTypes.isArray(decrypted.keyList); + decrypted.keyList.forEach(keyInfo => assertTypes.isStringWithValue(keyInfo.sk)); + decrypted.keyList.forEach(keyInfo => addKey(keyInfo)); + outerClass.version = decrypted.version; + } else { + throw new Error("Incorrect Keystore Password.") + } + }; + + return { + getWallets: () => wallets, + getWallet: (vk) => wallets.find(wallet => wallet.vk === vk), + addKey, + clearKeys, + numOfKeys, + deleteKey, + createKeystore, + decryptKeystore + } + })(); + + if (arg){ + if (arg.key) this.addKey(arg.key); + if (arg.keyList) this.addKeys(arg.keyList); + if (arg.keystoreData) this.addKeystoreData(arg.keystoreData); + } + } + /** + * Add a list of keys to add to the keystore + * @typedef {Object} keyinfo + * @property {string} sk - The private key. + * @property {string} nickname - The key nickname. + * @property {string} name - The key name. + * @property {string} network - Network name. + * @property {string} symbol - The token symbol. + * @param {Array.} keyList An array of keyinfo Object + */ + addKeys(keyList){ + assertTypes.isArray(keyList); + keyList.forEach(key => this.addKey(key)); + } + /** + * Add a key to the keystore + * @typedef {Object} keyinfo + * @property {string} sk - The private key. + * @property {string} nickname - The key nickname. + * @property {string} name - The key name. + * @property {string} network - Network name. + * @property {string} symbol - The token symbol. + * @param {keyinfo} keyInfo A keyinfo Object + */ + addKey(keyInfo){ + assertTypes.isObjectWithKeys(keyInfo); + assertTypes.isStringWithValue(keyInfo.sk); + if (validateTypes.isStringWithValue(keyInfo.vk)) delete keyInfo.vk; + this.keyList.addKey(keyInfo); + } + /** + * Load the keystore with the data from an existing keystore + * @param {string} keystoreData The contents of an existing encrypted keystore file + */ + addKeystoreData(keystoreData){ + if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); + if(this.validateKeyStore(keystoreData)){ + this.encryptedData = keystoreData; + } + } + /** + * Returns the password hint in a keystore file + * @param {String|undefined} keystoreData The contents of an existing encrypted keystore file if one wasn't supplied to the constructor + */ + getPasswordHint(keystoreData = undefined){ + if (!this.encryptedData && !keystoreData) throw new Error("No keystore data found.") + + if (keystoreData) { + if (validateTypes.isString(keystoreData)) keystoreData = JSON.parse(keystoreData); + } + else keystoreData = this.encryptedData; + + if (keystoreData.w) return decryptStrHash('n1ahcKc0lb', keystoreData.w); + else return "" + } + /** + * Removes a specific key from the keyList + * @param {Number} keyIndex The index of the key you want to remove + */ + deleteKey(keyIndex){ + assertTypes.isInteger(keyIndex); + if (this.keyList.numOfKeys() === 0) return + if (keyIndex < 0 || keyIndex >= this.keyList.numOfKeys()) throw new Error("Key index out of range.") + this.keyList.deleteKey(keyIndex); + } + /** + * Clears all keys from the keystore + */ + clearKeys(){ + this.keyList.clearKeys(); + } + /** + * Clears all keys from the keystore + * @return {Array.} An array of wallet objects + */ + get wallets() { + return this.keyList.getWallets() + } + /** + * Load the keystore with the data from an existing keystore + * @param {String} vk A 32 character long Lamden public key + * @return {Object} A wallet object + */ + getWallet(vk) { + return this.keyList.getWallet(vk) + } + /** + * Used to validate that a keystore is the proper Lamden Format (does not decrypt data) + * @param {String} keystoreData The contents of an existing encrypted keystore file + * @return {Boolean} valid + * @throws {Error} This is not a valid keystore file. + */ + validateKeyStore(keystoreData){ + assertTypes.isObjectWithKeys(keystoreData); + try{ + let encryptedData = JSON.parse(keystoreData.data); + if (!encryptedData.ct || !encryptedData.iv || !encryptedData.s){ + throw new Error("This is not a valid keystore file.") + } + } catch (e) { + throw new Error("This is not a valid keystore file.") + } + return true; + } + /** + * Create a Keystore text string from the keys contained in the Keystore instance + * @param {String} password A password to encrypt the data + * @param {String|undefined} hint An optional password hint. Not stored in clear text (obsured) but not encrypted with the password. + * @return {String} A JSON stringified object containing the encrypted data + * @throws {Error} Any errors from the encyption process + */ + createKeystore(password, hint = undefined) { + assertTypes.isStringWithValue(password); + if (hint){ + assertTypes.isStringWithValue(hint); + } + return this.keyList.createKeystore(password, hint) + } + /** + * Decrypt a keystore into a useable array of wallets. Any decrypted keys will be added to existing keys in the keystore. + * @param {String} password A password to encrypt the data + * @param {String|undefined} keystoreData The encrypted contents from a keystore file if not passed into the constructor. + * @throws {Error} Any errors from the encyption process + */ + decryptKeystore(password, keystoreData = undefined){ + if (keystoreData) this.addKeystoreData(keystoreData); + if (!this.encryptedData) throw new Error ("No keystoreData to decrypt.") + try{ + this.keyList.decryptKeystore(password, this.encryptedData.data); + }catch (e){ + throw new Error("Incorrect Keystore Password.") + } + } +} + +globalThis.Buffer = buffer.Buffer; + +var index = { + TransactionBuilder, + TransactionBatcher, + Masternode_API: LamdenMasterNode_API, + Blockservice_API: LamdenBlockservice_API, + Network, + wallet, + Keystore, + Encoder, + utils: utils$1, }; module.exports = index; diff --git a/package-lock.json b/package-lock.json index cef3807..76790a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.0.6", "buffer": "^6.0.3", - "chromedriver": "^105.0.0", + "chromedriver": "^105.0.1", "dotenv": "^8.2.0", "expect.js": "^0.3.1", "koa": "^2.13.4", @@ -81,12 +81,6 @@ "ms": "^2.1.1" } }, - "node_modules/@babel/core/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/@babel/generator": { "version": "7.8.4", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.8.4.tgz", @@ -270,12 +264,6 @@ "ms": "^2.1.1" } }, - "node_modules/@babel/traverse/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/@babel/types": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.8.3.tgz", @@ -539,9 +527,9 @@ "dev": true }, "node_modules/@testim/chrome-version": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.2.tgz", - "integrity": "sha512-1c4ZOETSRpI0iBfIFUqU4KqwBAB2lHUAlBjZz/YqOHqwM9dTTzjV6Km0ZkiEiSCx/tLr1BtESIKyWWMww+RUqw==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.3.tgz", + "integrity": "sha512-g697J3WxV/Zytemz8aTuKjTGYtta9+02kva3C1xc7KXB8GdbfE1akGJIsZLyY/FSh2QrnE+fiB7vmWU3XNcb6A==", "dev": true }, "node_modules/@types/estree": { @@ -610,9 +598,9 @@ } }, "node_modules/agent-base/node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -626,12 +614,6 @@ } } }, - "node_modules/agent-base/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -904,17 +886,17 @@ } }, "node_modules/chromedriver": { - "version": "105.0.0", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-105.0.0.tgz", - "integrity": "sha512-BX3GOUW5m6eiW9cVVF8hw+EFxvrGqYCxbwOqnpk8PjbNFqL5xjy7yel+e6ilJPjckAYFutMKs8XJvOs/W85vvg==", + "version": "105.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-105.0.1.tgz", + "integrity": "sha512-QqylH9mvl4Ybq3mmHsym7jeq/LhEi2sPtD8ffd9ixiDFdPRlh2F4vzrzK+myj1MiXb0TYJK7+OCcMEmsB3Sm/Q==", "dev": true, "hasInstallScript": true, "dependencies": { - "@testim/chrome-version": "^1.1.2", + "@testim/chrome-version": "^1.1.3", "axios": "^0.27.2", - "del": "^6.0.0", + "del": "^6.1.1", "extract-zip": "^2.0.1", - "https-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.1", "proxy-from-env": "^1.1.0", "tcp-port-used": "^1.0.1" }, @@ -1123,9 +1105,9 @@ } }, "node_modules/del": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/del/-/del-6.0.0.tgz", - "integrity": "sha512-1shh9DQ23L16oXSZKB2JxpL7iMy2E0S9d517ptA1P8iw0alkPtQcrKH7ru31rYtKwF499HkTu+DRzq3TCKDFRQ==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz", + "integrity": "sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==", "dev": true, "dependencies": { "globby": "^11.0.1", @@ -1356,16 +1338,10 @@ } } }, - "node_modules/extract-zip/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/fast-glob": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", - "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", + "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", "dev": true, "dependencies": { "@nodelib/fs.stat": "^2.0.2", @@ -1375,7 +1351,7 @@ "micromatch": "^4.0.4" }, "engines": { - "node": ">=8" + "node": ">=8.6.0" } }, "node_modules/fastq": { @@ -1571,16 +1547,16 @@ } }, "node_modules/globby": { - "version": "11.0.4", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.4.tgz", - "integrity": "sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "dev": true, "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", - "fast-glob": "^3.1.1", - "ignore": "^5.1.4", - "merge2": "^1.3.0", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", "slash": "^3.0.0" }, "engines": { @@ -1591,9 +1567,9 @@ } }, "node_modules/graceful-fs": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", - "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", "dev": true }, "node_modules/has": { @@ -1734,9 +1710,9 @@ "dev": true }, "node_modules/https-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", - "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", "dev": true, "dependencies": { "agent-base": "6", @@ -1747,9 +1723,9 @@ } }, "node_modules/https-proxy-agent/node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -1763,12 +1739,6 @@ } } }, - "node_modules/https-proxy-agent/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -1776,9 +1746,9 @@ "dev": true }, "node_modules/ignore": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.9.tgz", - "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", "dev": true, "engines": { "node": ">= 4" @@ -2154,12 +2124,6 @@ } } }, - "node_modules/koa-send/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/koa-static": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/koa-static/-/koa-static-5.0.0.tgz", @@ -2191,12 +2155,6 @@ } } }, - "node_modules/koa/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/lie": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", @@ -2336,13 +2294,13 @@ } }, "node_modules/micromatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", - "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dev": true, "dependencies": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" + "braces": "^3.0.2", + "picomatch": "^2.3.1" }, "engines": { "node": ">=8.6" @@ -2493,9 +2451,9 @@ } }, "node_modules/ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "node_modules/nanoid": { @@ -2700,9 +2658,9 @@ "dev": true }, "node_modules/picomatch": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", - "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true, "engines": { "node": ">=8.6" @@ -3192,12 +3150,6 @@ } } }, - "node_modules/tcp-port-used/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, "node_modules/terser": { "version": "5.15.0", "resolved": "https://registry.npmjs.org/terser/-/terser-5.15.0.tgz", @@ -3530,12 +3482,6 @@ "requires": { "ms": "^2.1.1" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -3702,12 +3648,6 @@ "requires": { "ms": "^2.1.1" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -3949,9 +3889,9 @@ } }, "@testim/chrome-version": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.2.tgz", - "integrity": "sha512-1c4ZOETSRpI0iBfIFUqU4KqwBAB2lHUAlBjZz/YqOHqwM9dTTzjV6Km0ZkiEiSCx/tLr1BtESIKyWWMww+RUqw==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.3.tgz", + "integrity": "sha512-g697J3WxV/Zytemz8aTuKjTGYtta9+02kva3C1xc7KXB8GdbfE1akGJIsZLyY/FSh2QrnE+fiB7vmWU3XNcb6A==", "dev": true }, "@types/estree": { @@ -4008,19 +3948,13 @@ }, "dependencies": { "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -4250,16 +4184,16 @@ } }, "chromedriver": { - "version": "105.0.0", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-105.0.0.tgz", - "integrity": "sha512-BX3GOUW5m6eiW9cVVF8hw+EFxvrGqYCxbwOqnpk8PjbNFqL5xjy7yel+e6ilJPjckAYFutMKs8XJvOs/W85vvg==", + "version": "105.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-105.0.1.tgz", + "integrity": "sha512-QqylH9mvl4Ybq3mmHsym7jeq/LhEi2sPtD8ffd9ixiDFdPRlh2F4vzrzK+myj1MiXb0TYJK7+OCcMEmsB3Sm/Q==", "dev": true, "requires": { - "@testim/chrome-version": "^1.1.2", + "@testim/chrome-version": "^1.1.3", "axios": "^0.27.2", - "del": "^6.0.0", + "del": "^6.1.1", "extract-zip": "^2.0.1", - "https-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.1", "proxy-from-env": "^1.1.0", "tcp-port-used": "^1.0.1" } @@ -4437,9 +4371,9 @@ "dev": true }, "del": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/del/-/del-6.0.0.tgz", - "integrity": "sha512-1shh9DQ23L16oXSZKB2JxpL7iMy2E0S9d517ptA1P8iw0alkPtQcrKH7ru31rYtKwF499HkTu+DRzq3TCKDFRQ==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/del/-/del-6.1.1.tgz", + "integrity": "sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==", "dev": true, "requires": { "globby": "^11.0.1", @@ -4618,19 +4552,13 @@ "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, "fast-glob": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", - "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", + "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", @@ -4776,23 +4704,23 @@ "dev": true }, "globby": { - "version": "11.0.4", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.4.tgz", - "integrity": "sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "dev": true, "requires": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", - "fast-glob": "^3.1.1", - "ignore": "^5.1.4", - "merge2": "^1.3.0", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", "slash": "^3.0.0" } }, "graceful-fs": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz", - "integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==", + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", "dev": true }, "has": { @@ -4901,9 +4829,9 @@ } }, "https-proxy-agent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", - "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", "dev": true, "requires": { "agent-base": "6", @@ -4911,19 +4839,13 @@ }, "dependencies": { "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -4934,9 +4856,9 @@ "dev": true }, "ignore": { - "version": "5.1.9", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.9.tgz", - "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", "dev": true }, "immediate": { @@ -5197,12 +5119,6 @@ "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -5241,12 +5157,6 @@ "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, @@ -5374,13 +5284,13 @@ "dev": true }, "micromatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", - "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dev": true, "requires": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" + "braces": "^3.0.2", + "picomatch": "^2.3.1" } }, "mime-db": { @@ -5502,9 +5412,9 @@ } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "nanoid": { @@ -5650,9 +5560,9 @@ "dev": true }, "picomatch": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", - "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true }, "process-nextick-args": { @@ -6035,12 +5945,6 @@ "requires": { "ms": "2.1.2" } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true } } }, diff --git a/package.json b/package.json index d73b118..2ef4fa8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lamden-js", - "version": "3.7.5", + "version": "3.8.0", "description": "A javascript implementaion for creating wallets, submitting transactions and interacting with masternodes on the Lamden Blockchain.", "main": "dist/cjs/lamden.js", "types": "src/index.d.ts", @@ -59,7 +59,7 @@ "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.0.6", "buffer": "^6.0.3", - "chromedriver": "^105.0.0", + "chromedriver": "^105.0.1", "dotenv": "^8.2.0", "expect.js": "^0.3.1", "koa": "^2.13.4",