@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/{base.js → base.mjs} +23 -11
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +14 -11
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +69 -59
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/{index.js → index.mjs} +12 -10
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +37 -20
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +28 -8
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +133 -90
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +43 -22
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +51 -35
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/{index.js → index.mjs} +40 -28
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/encoder.d.ts +26 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/{index.js → index.mjs} +15 -12
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +17 -11
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/constants.mjs +108 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +321 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +92 -74
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +16 -172
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +106 -14
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/{crypto.js → crypto.mjs} +42 -156
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.mjs +106 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +49 -15
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +49 -58
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +16 -6
- package/src/ae/aens.js +52 -58
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +21 -154
- package/src/ae/index.js +6 -4
- package/src/ae/oracle.js +33 -14
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -65
- package/src/channel/handlers.js +30 -20
- package/src/channel/index.js +46 -16
- package/src/channel/internal.js +35 -30
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +22 -113
- package/src/contract/ga/helpers.js +10 -6
- package/src/contract/ga/index.js +31 -24
- package/src/index.js +9 -8
- package/src/node-pool/index.js +13 -10
- package/src/node.js +11 -10
- package/src/tx/builder/constants.js +100 -0
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +99 -103
- package/src/tx/builder/index.js +81 -40
- package/src/tx/builder/schema.js +44 -132
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +110 -35
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +11 -155
- package/src/utils/encoder.ts +101 -0
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +68 -45
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -308
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -356
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -242
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -56
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -318
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/index.js +0 -310
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/mptree.ts"],"names":["hash","MerkleTreeHashMismatchError","MissingNodeInTreeError","UnknownPathNibbleError","UnknownNodeLengthError","NodeType","MPTree","nodeHash","node","from","rlpEncode","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","parseInt","Leaf","includes","serialize","mptHash","value","get","searchFrom","substr"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,iBAAoC,KAApC;;;;SAESA,I;SAEPC,2B,EACAC,sB,EACAC,sB,EACAC,sB;IAGGC,Q;;WAAAA,Q;AAAAA,EAAAA,Q,CAAAA,Q;AAAAA,EAAAA,Q,CAAAA,Q;AAAAA,EAAAA,Q,CAAAA,Q;GAAAA,Q,KAAAA,Q;;AAQL,eAAe,MAAMC,MAAN,CAAa;AAIH,SAARC,QAAQ,CAAEC,IAAF,EAAuB;AAC5C,WAAO,QAAOC,IAAP,CAAYT,IAAI,CAACU,SAAS,CAACF,IAAD,CAAV,CAAhB,EAAmCG,QAAnC,CAA4C,KAA5C,CAAP;AACD;AAED;AACF;AACA;AACA;AACA;AACA;;;AACEC,EAAAA,WAAW,CAAEC,MAAF,EAAwB;AACjC,SAAKC,QAAL,GAAgBD,MAAM,CAAC,CAAD,CAAN,CAAUF,QAAV,CAAm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MAAhB,CAAN;AACA;;AACF,aAAKzB,QAAQ,CAACgC,IAAd;AACE,cAAIH,IAAI,KAAKZ,GAAb,EAAkB,OAAOH,SAAP;AAClB,iBAAOK,OAAO,CAAC,CAAD,CAAd;AAbJ;AAeD;AACF;;AAzGyB","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\nimport { encode as rlpEncode } from 'rlp'\nimport type { Input } from 'rlp'\nimport { hash } from './crypto-ts'\nimport {\n MerkleTreeHashMismatchError,\n MissingNodeInTreeError,\n UnknownPathNibbleError,\n UnknownNodeLengthError\n} from './errors'\n\nenum NodeType {\n Branch,\n Extension,\n Leaf\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>]\n\nexport default class MPTree {\n private readonly rootHash: string\n private readonly nodes: { [key: string]: Buffer[] }\n\n private static nodeHash (node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex')\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @rtype (binary: Array) => MPTree\n * @param {Array} binary - Binary\n * @return {MPTree} Merkle Patricia Tree\n */\n constructor (binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex')\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]])\n )\n\n if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\\'t find a node by root hash')\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError()\n const { type, payload } = MPTree.parseNode(node)\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter(n => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in branch node')\n }\n })\n break\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new MissingNodeInTreeError('Can\\'t find a node by hash in extension node')\n }\n }\n })\n }\n\n isEqual (tree: MPTree): boolean {\n return this.rootHash === tree.rootHash\n }\n\n private static parseNode (node: Buffer[]): { type: NodeType, payload: Buffer[], path: string | null } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null }\n case 2: {\n const path = node[0].toString('hex')\n const nibble = parseInt(path[0], 16)\n if (nibble > 3) throw new UnknownPathNibbleError(nibble)\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf\n const slice = [0, 2].includes(nibble) ? 2 : 1\n return { type, payload: [node[1]], path: path.slice(slice) }\n }\n default:\n throw new UnknownNodeLengthError(node.length)\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @rtype () => Array\n * @return {Array} Binary\n */\n serialize (): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value\n ]))\n ]\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @rtype (key: String) => Buffer\n * @param {String} key - The key of the element to retrieve\n * @return {Buffer} Value associated to the specified key\n */\n get (key: string): Buffer | undefined {\n let searchFrom = this.rootHash\n while (true) {\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom])\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16]\n searchFrom = payload[parseInt(key[0], 16)].toString('hex')\n key = key.substr(1)\n break\n case NodeType.Extension:\n if (key.substr(0, path?.length) !== path) return undefined\n searchFrom = payload[0].toString('hex')\n key = key.substr(path.length)\n break\n case NodeType.Leaf:\n if (path !== key) return undefined\n return payload[0]\n }\n }\n }\n}\n"],"file":"mptree.mjs"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { snakeToPascal, pascalToSnake } from
|
|
1
|
+
import { snakeToPascal, pascalToSnake } from "./string.mjs";
|
|
2
2
|
export const pause = async duration => await new Promise(resolve => setTimeout(resolve, duration));
|
|
3
3
|
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn));
|
|
4
4
|
export const filterObject = (object, fn) => Object.fromEntries(Object.entries(object).filter(fn));
|
|
@@ -40,4 +40,4 @@ export const snakizeKeys = traverseKeys.bind(null, pascalToSnake);
|
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
export const pascalizeKeys = traverseKeys.bind(null, snakeToPascal);
|
|
43
|
-
//# sourceMappingURL=other.
|
|
43
|
+
//# sourceMappingURL=other.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/other.ts"],"names":["snakeToPascal","pascalToSnake","pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","filterObject","filter","traverseKeys","Array","isArray","i","key","value","snakizeKeys","bind","pascalizeKeys"],"mappings":"SAASA,a,EAAeC,a;AAExB,OAAO,MAAMC,KAAK,GAAG,MAAOC,QAAP,IACnB,MAAM,IAAIC,OAAJ,CAAYC,OAAO,IAAIC,UAAU,CAACD,OAAD,EAAUF,QAAV,CAAjC,CADD;AAGP,OAAO,MAAMI,SAAS,GAAG,CACvBC,MADuB,EAEvBC,EAFuB,KAGZC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBK,GAAvB,CAA2BJ,EAA3B,CAAnB,CAHN;AAKP,OAAO,MAAMK,YAAY,GAAG,CAC1BN,MAD0B,EAE1BC,EAF0B,KAGfC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBO,MAAvB,CAA8BN,EAA9B,CAAnB,CAHN;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMO,YAAY,GAAG,CAACP,EAAD,EAAeD,MAAf,KAAoC;AAC9D,MAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,KAAK,IAA7C,EAAmD,OAAOA,MAAP;AACnD,MAAIS,KAAK,CAACC,OAAN,CAAcV,MAAd,CAAJ,EAA2B,OAAOA,MAAM,CAACK,GAAP,CAAWM,CAAC,IAAIH,YAAY,CAACP,EAAD,EAAKU,CAAL,CAA5B,CAAP;AAC3B,SAAOZ,SAAS,CAACC,MAAD,EAAS;AAAA,QAAC,CAACY,GAAD,EAAMC,KAAN,CAAD;AAAA,WAAiC,CACxDZ,EAAE,CAACW,GAAD,CADsD,EAC/CJ,YAAY,CAACP,EAAD,EAAKY,KAAL,CADmC,CAAjC;AAAA,GAAT,CAAhB;AAGD,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAGN,YAAY,CAACO,IAAb,CAAkB,IAAlB,EAAwBtB,aAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMuB,aAAa,GAAGR,YAAY,CAACO,IAAb,CAAkB,IAAlB,EAAwBvB,aAAxB,CAAtB","sourcesContent":["import { snakeToPascal, pascalToSnake } from './string'\n\nexport const pause = async (duration: number): Promise<void> =>\n await new Promise(resolve => setTimeout(resolve, duration))\n\nexport const mapObject = (\n object: object,\n fn: (value: [string, any], index: number, array: Array<[string, any]>) => Array<[string, any]>\n): object => Object.fromEntries(Object.entries(object).map(fn))\n\nexport const filterObject = (\n object: object,\n fn: (value: [string, any], index: number, array: Array<[string, any]>) => boolean\n): object => Object.fromEntries(Object.entries(object).filter(fn))\n\n/**\n * Key traversal metafunction\n * @static\n * @function\n * @rtype (fn: (s: String) => String) => (o: Object) => Object\n * @param {Function} fn - Key transformation function\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n */\nexport const traverseKeys = (fn: Function, object: any): any => {\n if (typeof object !== 'object' || object === null) return object\n if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i))\n return mapObject(object, ([key, value]: [string, any]) => [\n fn(key), traverseKeys(fn, value)\n ])\n}\n\n/**\n * snake_case key traversal\n * @static\n * @rtype (o: Object) => Object\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n * @see pascalToSnake\n */\nexport const snakizeKeys = traverseKeys.bind(null, pascalToSnake)\n\n/**\n * PascalCase key traversal\n * @static\n * @rtype (o: Object) => Object\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n * @see snakeToPascal\n */\nexport const pascalizeKeys = traverseKeys.bind(null, snakeToPascal)\n"],"file":"other.mjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/semver-satisfies.ts"],"names":["version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","pow","vNumber","geNumber","ltNumber"],"mappings":"AAAA,eAAe,UAAUA,OAAV,EAA2BC,SAA3B,EAA8CC,SAA9C,EAA0E;AACvF,QAAMC,aAAa,GAAIC,CAAD,IAAyBA,CAAC,CAC7CC,KAD4C,CACtC,MADsC,EAC9B,CAD8B,EAC3BA,KAD2B,CACrB,GADqB,EAChBC,GADgB,CACZC,CAAC,IAAI,CAACA,CADM,CAA/C;;AAGA,QAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAD,CAAvC;AACA,QAAMS,YAAY,GAAGN,aAAa,CAACF,SAAD,CAAlC;AACA,QAAMS,YAAY,GAAGP,aAAa,CAACD,SAAD,CAAlC;AAEA,QAAMS,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,GAAGL,iBAAZ,EAA+B,GAAGC,YAAlC,EAAgD,GAAGC,YAAnD,IAAmE,CAAhF;;AACA,QAAMI,kBAAkB,GAAIC,UAAD,IAAkCA,UAAU,CAACC,OAAX,GAC1DC,MAD0D,CACnD,CAACC,GAAD,EAAMC,CAAN,EAASC,GAAT,KAAiBF,GAAG,GAAGC,CAAC,GAAGP,IAAI,CAACS,GAAL,CAASV,IAAT,EAAeS,GAAf,CADwB,EACH,CADG,CAA7D;;AAGA,QAAME,OAAO,GAAGR,kBAAkB,CAACN,iBAAD,CAAlC;AACA,QAAMe,QAAQ,GAAGT,kBAAkB,CAACL,YAAD,CAAnC;AACA,QAAMe,QAAQ,GAAGV,kBAAkB,CAACJ,YAAD,CAAnC;AACA,SAAOY,OAAO,IAAIC,QAAX,IAAuBD,OAAO,GAAGE,QAAxC;AACD","sourcesContent":["export default function (version: string, geVersion: string, ltVersion: string): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map(i => +i)\n\n const versionComponents = getComponents(version)\n const geComponents = getComponents(geVersion)\n const ltComponents = getComponents(ltVersion)\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * Math.pow(base, idx), 0)\n\n const vNumber = componentsToNumber(versionComponents)\n const geNumber = componentsToNumber(geComponents)\n const ltNumber = componentsToNumber(ltComponents)\n return vNumber >= geNumber && vNumber < ltNumber\n}\n"],"file":"semver-satisfies.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/semver-satisfies.ts"],"names":["version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","pow","vNumber","geNumber","ltNumber"],"mappings":"AAAA,eAAe,UAAUA,OAAV,EAA2BC,SAA3B,EAA8CC,SAA9C,EAA0E;AACvF,QAAMC,aAAa,GAAIC,CAAD,IAAyBA,CAAC,CAC7CC,KAD4C,CACtC,MADsC,EAC9B,CAD8B,EAC3BA,KAD2B,CACrB,GADqB,EAChBC,GADgB,CACZC,CAAC,IAAI,CAACA,CADM,CAA/C;;AAGA,QAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAD,CAAvC;AACA,QAAMS,YAAY,GAAGN,aAAa,CAACF,SAAD,CAAlC;AACA,QAAMS,YAAY,GAAGP,aAAa,CAACD,SAAD,CAAlC;AAEA,QAAMS,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,GAAGL,iBAAZ,EAA+B,GAAGC,YAAlC,EAAgD,GAAGC,YAAnD,IAAmE,CAAhF;;AACA,QAAMI,kBAAkB,GAAIC,UAAD,IAAkCA,UAAU,CAACC,OAAX,GAC1DC,MAD0D,CACnD,CAACC,GAAD,EAAMC,CAAN,EAASC,GAAT,KAAiBF,GAAG,GAAGC,CAAC,GAAGP,IAAI,CAACS,GAAL,CAASV,IAAT,EAAeS,GAAf,CADwB,EACH,CADG,CAA7D;;AAGA,QAAME,OAAO,GAAGR,kBAAkB,CAACN,iBAAD,CAAlC;AACA,QAAMe,QAAQ,GAAGT,kBAAkB,CAACL,YAAD,CAAnC;AACA,QAAMe,QAAQ,GAAGV,kBAAkB,CAACJ,YAAD,CAAnC;AACA,SAAOY,OAAO,IAAIC,QAAX,IAAuBD,OAAO,GAAGE,QAAxC;AACD","sourcesContent":["export default function (version: string, geVersion: string, ltVersion: string): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map(i => +i)\n\n const versionComponents = getComponents(version)\n const geComponents = getComponents(geVersion)\n const ltComponents = getComponents(ltVersion)\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * Math.pow(base, idx), 0)\n\n const vNumber = componentsToNumber(versionComponents)\n const geNumber = componentsToNumber(geComponents)\n const ltNumber = componentsToNumber(ltComponents)\n return vNumber >= geNumber && vNumber < ltNumber\n}\n"],"file":"semver-satisfies.mjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/string.ts"],"names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAT,CAAwBC,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,KAAV,EAAiBC,KAAK,IAAIA,KAAK,CAAC,CAAD,CAAL,CAASC,WAAT,EAA1B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBJ,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,QAAV,EAAoBC,KAAK,IAAK,IAAGA,KAAK,CAACG,WAAN,EAAoB,EAArD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,CAAgBC,GAAhB,EAAsC;AAC3C,SAAOA,GAAG,CAACC,MAAJ,GAAa,CAAb,KAAmB,CAAnB,IAAwB,eAAeC,IAAf,CAAoBF,GAApB,CAA/B;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,QAAT,CAAmBH,GAAnB,EAAyC;AAC9C,MAAIA,GAAG,CAACC,MAAJ,GAAa,CAAb,GAAiB,CAAjB,IAAsB,gBAAgBC,IAAhB,CAAqBF,GAArB,CAA1B,EAAqD,OAAO,KAAP;AACrD,QAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAJ,CAAY,GAAZ,CAAd;AACA,SAAOD,KAAK,KAAK,CAAC,CAAX,IAAgB,SAASF,IAAT,CAAcF,GAAG,CAACM,KAAJ,CAAUF,KAAV,CAAd,CAAvB;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function snakeToPascal (s: string): string {\n return s.replace(/_./g, match => match[1].toUpperCase())\n}\n\n/**\n * Convert string from PascalCase to snake_case\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function pascalToSnake (s: string): string {\n return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`)\n}\n\n/**\n * Check whether a string is valid hex.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid hex, false otherwise.\n */\nexport function isHex (str: string): boolean {\n return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str)\n}\n\n/**\n * Check whether a string is valid base-64.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid base-64, false otherwise.\n */\nexport function isBase64 (str: string): boolean {\n if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false\n const index = str.indexOf('=')\n return index === -1 || /={1,2}/.test(str.slice(index))\n}\n"],"file":"string.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/string.ts"],"names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAT,CAAwBC,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,KAAV,EAAiBC,KAAK,IAAIA,KAAK,CAAC,CAAD,CAAL,CAASC,WAAT,EAA1B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBJ,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,QAAV,EAAoBC,KAAK,IAAK,IAAGA,KAAK,CAACG,WAAN,EAAoB,EAArD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,CAAgBC,GAAhB,EAAsC;AAC3C,SAAOA,GAAG,CAACC,MAAJ,GAAa,CAAb,KAAmB,CAAnB,IAAwB,eAAeC,IAAf,CAAoBF,GAApB,CAA/B;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,QAAT,CAAmBH,GAAnB,EAAyC;AAC9C,MAAIA,GAAG,CAACC,MAAJ,GAAa,CAAb,GAAiB,CAAjB,IAAsB,gBAAgBC,IAAhB,CAAqBF,GAArB,CAA1B,EAAqD,OAAO,KAAP;AACrD,QAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAJ,CAAY,GAAZ,CAAd;AACA,SAAOD,KAAK,KAAK,CAAC,CAAX,IAAgB,SAASF,IAAT,CAAcF,GAAG,CAACM,KAAJ,CAAUF,KAAV,CAAd,CAAvB;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function snakeToPascal (s: string): string {\n return s.replace(/_./g, match => match[1].toUpperCase())\n}\n\n/**\n * Convert string from PascalCase to snake_case\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function pascalToSnake (s: string): string {\n return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`)\n}\n\n/**\n * Check whether a string is valid hex.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid hex, false otherwise.\n */\nexport function isHex (str: string): boolean {\n return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str)\n}\n\n/**\n * Check whether a string is valid base-64.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid base-64, false otherwise.\n */\nexport function isBase64 (str: string): boolean {\n if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false\n const index = str.indexOf('=')\n return index === -1 || /={1,2}/.test(str.slice(index))\n}\n"],"file":"string.mjs"}
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import SwaggerClient from 'swagger-client';
|
|
24
24
|
import fetch from 'cross-fetch';
|
|
25
|
-
import JsonBig from
|
|
26
|
-
import { snakizeKeys, pascalizeKeys, mapObject, filterObject } from
|
|
25
|
+
import JsonBig from "./json-big.mjs";
|
|
26
|
+
import { snakizeKeys, pascalizeKeys, mapObject, filterObject } from "./other.mjs";
|
|
27
|
+
import { ArgumentCountMismatchError } from "./errors.mjs";
|
|
28
|
+
import { snakeToPascal } from "./string.mjs";
|
|
27
29
|
let warnedAboutInternalApiUsage = false;
|
|
28
30
|
/**
|
|
29
31
|
* Generator of Swagger client
|
|
@@ -51,18 +53,35 @@ export default (async function (specUrl) {
|
|
|
51
53
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
54
|
spec = spec || (await (await fetch(specUrl)).json());
|
|
53
55
|
const jsonImp = disableBigNumbers ? JSON : JsonBig;
|
|
54
|
-
|
|
55
|
-
if (['https://compiler.aepps.com', 'https://latest.compiler.aepps.com'].includes(new URL(specUrl).origin) || new URL(specUrl).origin.includes('https://')) {
|
|
56
|
-
spec.schemes = ['https'];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
56
|
const [external, internal] = await Promise.all([specUrl, internalUrl].map(url => {
|
|
60
57
|
if (!url) return null;
|
|
58
|
+
const pendingGetRequests = {};
|
|
61
59
|
return SwaggerClient({
|
|
62
60
|
url,
|
|
63
61
|
spec,
|
|
62
|
+
requestInterceptor: request => {
|
|
63
|
+
if (request.method !== 'GET') return;
|
|
64
|
+
return { ...request,
|
|
65
|
+
userFetch: async (url, request) => {
|
|
66
|
+
var _pendingGetRequests$k;
|
|
67
|
+
|
|
68
|
+
const key = JSON.stringify({ ...request,
|
|
69
|
+
url
|
|
70
|
+
});
|
|
71
|
+
(_pendingGetRequests$k = pendingGetRequests[key]) !== null && _pendingGetRequests$k !== void 0 ? _pendingGetRequests$k : pendingGetRequests[key] = fetch(url, request);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
return (await pendingGetRequests[key]).clone();
|
|
75
|
+
} finally {
|
|
76
|
+
delete pendingGetRequests[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
},
|
|
64
81
|
responseInterceptor: response => {
|
|
65
|
-
|
|
82
|
+
var _response$text;
|
|
83
|
+
|
|
84
|
+
if (response.text === '' || ((_response$text = response.text) === null || _response$text === void 0 ? void 0 : _response$text.size) === 0) return response;
|
|
66
85
|
const body = jsonImp.parse(response.text);
|
|
67
86
|
Object.assign(response, {
|
|
68
87
|
body: disableCaseConversion ? body : pascalizeKeys(body)
|
|
@@ -71,7 +90,7 @@ export default (async function (specUrl) {
|
|
|
71
90
|
}
|
|
72
91
|
});
|
|
73
92
|
}));
|
|
74
|
-
const combinedApi = [
|
|
93
|
+
const combinedApi = Object.assign({}, ...(external.apis.external ? [external.apis.external] : Object.values(external.apis)), mapObject((internal === null || internal === void 0 ? void 0 : internal.apis.internal) || {}, _ref => {
|
|
75
94
|
let [key, handler] = _ref;
|
|
76
95
|
return [key, function () {
|
|
77
96
|
if (!warnedAboutInternalApiUsage) {
|
|
@@ -81,15 +100,17 @@ export default (async function (specUrl) {
|
|
|
81
100
|
|
|
82
101
|
return handler(...arguments);
|
|
83
102
|
}];
|
|
84
|
-
})].reduce((acc, n) => ({ ...acc,
|
|
85
|
-
...n
|
|
86
103
|
}));
|
|
87
104
|
const opSpecs = Object.values(spec.paths).map(paths => Object.values(paths)).flat().reduce((acc, n) => ({ ...acc,
|
|
88
105
|
[n.operationId]: n
|
|
89
106
|
}), {});
|
|
107
|
+
const requestQueues = {};
|
|
90
108
|
const api = mapObject(combinedApi, _ref2 => {
|
|
91
109
|
let [opId, handler] = _ref2;
|
|
92
|
-
|
|
110
|
+
const functionName = opId.slice(0, 1).toLowerCase() + snakeToPascal(opId.slice(1));
|
|
111
|
+
return [functionName, async function () {
|
|
112
|
+
var _requestQueues$__queu;
|
|
113
|
+
|
|
93
114
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
94
115
|
args[_key] = arguments[_key];
|
|
95
116
|
}
|
|
@@ -101,12 +122,17 @@ export default (async function (specUrl) {
|
|
|
101
122
|
name: '__requestBody'
|
|
102
123
|
}] : [])];
|
|
103
124
|
const required = parameters.filter(param => param.required).map(p => p.name);
|
|
104
|
-
|
|
125
|
+
|
|
126
|
+
if (![0, 1].includes(args.length - required.length)) {
|
|
127
|
+
throw new ArgumentCountMismatchError(functionName, required.length, args.length);
|
|
128
|
+
}
|
|
129
|
+
|
|
105
130
|
const values = required.reduce((acc, req, idx) => ({ ...acc,
|
|
106
131
|
[req]: args[idx]
|
|
107
132
|
}), args[required.length] || {});
|
|
108
133
|
const {
|
|
109
134
|
__requestBody,
|
|
135
|
+
__queue,
|
|
110
136
|
...stringified
|
|
111
137
|
} = mapObject(values, _ref3 => {
|
|
112
138
|
let [param, value] = _ref3;
|
|
@@ -118,13 +144,21 @@ export default (async function (specUrl) {
|
|
|
118
144
|
});
|
|
119
145
|
return [param, jsonImp.stringify(filteredValue)];
|
|
120
146
|
});
|
|
121
|
-
|
|
147
|
+
|
|
148
|
+
const request = async () => (await handler(stringified, {
|
|
122
149
|
requestBody: __requestBody
|
|
123
150
|
})).body;
|
|
151
|
+
|
|
152
|
+
if (!__queue) return request();
|
|
153
|
+
const res = ((_requestQueues$__queu = requestQueues[__queue]) !== null && _requestQueues$__queu !== void 0 ? _requestQueues$__queu : Promise.resolve()).then(request, request); // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
|
|
154
|
+
// gap to ensure that node won't reject the nonce
|
|
155
|
+
|
|
156
|
+
requestQueues[__queue] = res.then(() => new Promise(resolve => setTimeout(resolve, 750)));
|
|
157
|
+
return res;
|
|
124
158
|
}];
|
|
125
159
|
});
|
|
126
160
|
return Object.assign(external, {
|
|
127
161
|
api
|
|
128
162
|
});
|
|
129
163
|
});
|
|
130
|
-
//# sourceMappingURL=swagger.
|
|
164
|
+
//# sourceMappingURL=swagger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/swagger.js"],"names":["SwaggerClient","fetch","JsonBig","snakizeKeys","pascalizeKeys","mapObject","filterObject","ArgumentCountMismatchError","snakeToPascal","warnedAboutInternalApiUsage","specUrl","spec","internalUrl","disableBigNumbers","disableCaseConversion","responseInterceptor","json","jsonImp","JSON","external","internal","Promise","all","map","url","pendingGetRequests","requestInterceptor","request","method","userFetch","key","stringify","clone","response","text","size","body","parse","Object","assign","combinedApi","apis","values","handler","console","warn","opSpecs","paths","flat","reduce","acc","n","operationId","requestQueues","api","opId","functionName","slice","toLowerCase","args","opSpec","parameters","requestBody","required","schema","content","name","filter","param","p","includes","length","req","idx","__requestBody","__queue","stringified","value","rootKeys","keys","find","properties","filteredValue","res","resolve","then","setTimeout"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,aAAP,MAA0B,gBAA1B;AACA,OAAOC,KAAP,MAAkB,aAAlB;OACOC,O;SACEC,W,EAAaC,a,EAAeC,S,EAAWC,Y;SACvCC,0B;SACAC,a;AAET,IAAIC,2BAA2B,GAAG,KAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,gBAAe,gBACbC,OADa,EAGV;AAAA,MADH;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,WAAR;AAAqBC,IAAAA,iBAArB;AAAwCC,IAAAA,qBAAxC;AAA+DC,IAAAA;AAA/D,GACG,uEADoF,EACpF;AACHJ,EAAAA,IAAI,GAAGA,IAAI,KAAI,MAAM,CAAC,MAAMV,KAAK,CAACS,OAAD,CAAZ,EAAuBM,IAAvB,EAAV,CAAX;AACA,QAAMC,OAAO,GAAGJ,iBAAiB,GAAGK,IAAH,GAAUhB,OAA3C;AAEA,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a,CAACsB,OAAD,CAAb,GAAyBQ,GAAG,CAACE,IAAJ,CAAS,MAAM,IAAIhE,OAAJ,CAAY+D,OAAO,IAAIE,UAAU,CAACF,OAAD,EAAU,GAAV,CAAjC,CAAf,CAAzB;AACA,aAAOD,GAAP;AACD,KAxCI,CAAP;AA0CD,GA5CoB,CAArB;AA8CA,SAAO7C,MAAM,CAACC,MAAP,CAAcpB,QAAd,EAAwB;AAAEmC,IAAAA;AAAF,GAAxB,CAAP;AACD,CA5GD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Generator of Swagger client module\n * @module @aeternity/aepp-sdk/es/utils/swagger\n * @export genSwaggerClient\n */\n\nimport SwaggerClient from 'swagger-client'\nimport fetch from 'cross-fetch'\nimport JsonBig from './json-big'\nimport { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other'\nimport { ArgumentCountMismatchError } from './errors'\nimport { snakeToPascal } from './string'\n\nlet warnedAboutInternalApiUsage = false\n\n/**\n * Generator of Swagger client\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/swagger\n * @rtype Object\n * @param {String} specUrl - Swagger specification URL on external node host\n * @param {Object} options\n * @param {String} [options.spec] - Override OpenAPI definition\n * @param {String} [options.internalUrl] - Node internal URL\n * @param {Boolean} [options.disableBigNumbers]\n * @param {Boolean} [options.disableCaseConversion]\n * @param {Function} [options.responseInterceptor]\n * @return {Object} Swagger client\n * @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')\n */\nexport default async (\n specUrl,\n { spec, internalUrl, disableBigNumbers, disableCaseConversion, responseInterceptor } = {}\n) => {\n spec = spec || await (await fetch(specUrl)).json()\n const jsonImp = disableBigNumbers ? JSON : JsonBig\n\n const [external, internal] = await Promise.all([specUrl, internalUrl].map((url) => {\n if (!url) return null\n const pendingGetRequests = {}\n return SwaggerClient({\n url,\n spec,\n requestInterceptor: request => {\n if (request.method !== 'GET') return\n return {\n ...request,\n userFetch: async (url, request) => {\n const key = JSON.stringify({ ...request, url })\n pendingGetRequests[key] ??= fetch(url, request)\n try {\n return (await pendingGetRequests[key]).clone()\n } finally {\n delete pendingGetRequests[key]\n }\n }\n }\n },\n responseInterceptor: response => {\n if (response.text === '' || response.text?.size === 0) return response\n const body = jsonImp.parse(response.text)\n Object.assign(response, {\n body: disableCaseConversion ? body : pascalizeKeys(body)\n })\n return (responseInterceptor && responseInterceptor(response)) || response\n }\n })\n }))\n\n const combinedApi = Object.assign(\n {},\n ...external.apis.external ? [external.apis.external] : Object.values(external.apis),\n mapObject(internal?.apis.internal || {}, ([key, handler]) => [key, (...args) => {\n if (!warnedAboutInternalApiUsage) {\n console.warn(\n 'SDK\\'s wrapper of aeternity node internal API is deprecated, please use external ' +\n 'equivalent (for example, \"sdk.api.protectedDryRunTxs\" instead of \"sdk.api.dryRunTxs\") ' +\n 'or create a wrapper of internal API by yourself (using \"genSwaggerClient\")'\n )\n warnedAboutInternalApiUsage = true\n }\n return handler(...args)\n }])\n )\n\n const opSpecs = Object.values(spec.paths)\n .map(paths => Object.values(paths))\n .flat()\n .reduce((acc, n) => ({ ...acc, [n.operationId]: n }), {})\n\n const requestQueues = {}\n const api = mapObject(combinedApi, ([opId, handler]) => {\n const functionName = opId.slice(0, 1).toLowerCase() + snakeToPascal(opId.slice(1))\n return [\n functionName,\n async (...args) => {\n const opSpec = opSpecs[opId]\n const parameters = [\n ...opSpec.parameters,\n ...opSpec.requestBody\n ? [{\n required: opSpec.requestBody.required,\n schema: Object.values(opSpec.requestBody.content)[0].schema,\n name: '__requestBody'\n }]\n : []\n ]\n const required = parameters.filter(param => param.required).map(p => p.name)\n if (![0, 1].includes(args.length - required.length)) {\n throw new ArgumentCountMismatchError(functionName, required.length, args.length)\n }\n const values = required.reduce(\n (acc, req, idx) => ({ ...acc, [req]: args[idx] }),\n args[required.length] || {}\n )\n const { __requestBody, __queue, ...stringified } = mapObject(values, ([param, value]) => {\n if (typeof value !== 'object') return [param, value]\n const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties)\n const filteredValue = filterObject(\n disableCaseConversion ? value : snakizeKeys(value),\n ([key]) => rootKeys.includes(key)\n )\n return [param, jsonImp.stringify(filteredValue)]\n })\n\n const request = async () => (await handler(stringified, { requestBody: __requestBody }))\n .body\n if (!__queue) return request()\n const res = (requestQueues[__queue] ?? Promise.resolve()).then(request, request)\n // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803\n // gap to ensure that node won't reject the nonce\n requestQueues[__queue] = res.then(() => new Promise(resolve => setTimeout(resolve, 750)))\n return res\n }\n ]\n })\n\n return Object.assign(external, { api })\n}\n"],"file":"swagger.mjs"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeternity/aepp-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"description": "SDK for the æternity blockchain",
|
|
5
5
|
"main": "dist/aepp-sdk.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
7
|
-
"module": "es/index.
|
|
7
|
+
"module": "es/index.mjs",
|
|
8
8
|
"browser": {
|
|
9
9
|
"dist/aepp-sdk.js": "./dist/aepp-sdk.browser.js"
|
|
10
10
|
},
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions
|
|
13
|
+
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true",
|
|
14
14
|
"build": "webpack --mode=production && npm run build:es",
|
|
15
15
|
"build:dev": "webpack --mode=development && npm run build:es",
|
|
16
16
|
"docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.js",
|
|
17
17
|
"docs:api": "node apidoc.js",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"test": "nyc
|
|
21
|
-
"
|
|
22
|
-
"test:
|
|
23
|
-
"test:integration:contract,chain": "nyc --require @babel/register --require ts-node/register mocha './test/integration/@(contract|contract-aci|chain).js' --timeout 40s",
|
|
24
|
-
"test:integration:else": "nyc --require @babel/register --require ts-node/register mocha './test/integration/!(channel|accounts|contract|chain).js' --timeout 40s",
|
|
25
|
-
"test:unit": "nyc --require @babel/register --require ts-node/register mocha './test/unit/*'",
|
|
26
|
-
"test:watch": "mocha --recursive --require @babel/register --require ts-node/register --watch --timeout 40s",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"test": "nyc mocha './test/unit/' './test/integration/'",
|
|
20
|
+
"test:integration": "nyc mocha './test/integration/'",
|
|
21
|
+
"test:unit": "nyc mocha './test/unit/'",
|
|
22
|
+
"test:watch": "mocha './test/unit/' './test/integration/' --watch",
|
|
27
23
|
"prepare": "npm run build",
|
|
28
|
-
"prepublishOnly": "npm run docs:examples
|
|
29
|
-
"release": "standard-version --skip.tag"
|
|
24
|
+
"prepublishOnly": "npm run docs:examples",
|
|
25
|
+
"release": "standard-version --skip.tag --infile docs/CHANGELOG.md"
|
|
30
26
|
},
|
|
31
27
|
"license": "ISC",
|
|
32
28
|
"keywords": [
|
|
@@ -36,33 +32,27 @@
|
|
|
36
32
|
"SDK"
|
|
37
33
|
],
|
|
38
34
|
"dependencies": {
|
|
39
|
-
"@aeternity/aepp-calldata": "^1.
|
|
40
|
-
"@aeternity/
|
|
35
|
+
"@aeternity/aepp-calldata": "^1.1.1",
|
|
36
|
+
"@aeternity/argon2-browser": "^0.1.2",
|
|
37
|
+
"@aeternity/blakejs": "^1.1.2",
|
|
41
38
|
"@aeternity/json-bigint": "^0.3.1",
|
|
42
|
-
"@
|
|
39
|
+
"@aeternity/uuid": "^0.0.1",
|
|
40
|
+
"@babel/runtime-corejs3": "^7.17.2",
|
|
43
41
|
"@stamp/it": "^1.1.0",
|
|
44
42
|
"@stamp/required": "^1.0.1",
|
|
45
43
|
"aes-js": "^3.1.2",
|
|
46
|
-
"bignumber.js": "^9.0.
|
|
44
|
+
"bignumber.js": "^9.0.2",
|
|
47
45
|
"bip32-path": "^0.4.2",
|
|
48
|
-
"
|
|
49
|
-
"bs58check": "^2.1.2",
|
|
46
|
+
"bs58": "^4.0.1",
|
|
50
47
|
"buffer": "^6.0.3",
|
|
51
|
-
"cross-fetch": "^3.1.
|
|
52
|
-
"crypto-browserify": "^3.12.0",
|
|
53
|
-
"ed2curve": "^0.3.0",
|
|
48
|
+
"cross-fetch": "^3.1.5",
|
|
54
49
|
"events": "^3.3.0",
|
|
55
|
-
"libsodium-wrappers-sumo": "^0.7.9",
|
|
56
|
-
"path-browserify": "^1.0.1",
|
|
57
50
|
"process": "^0.11.10",
|
|
58
|
-
"
|
|
59
|
-
"rlp": "^2.2.7",
|
|
51
|
+
"rlp": "^3.0.0",
|
|
60
52
|
"sha.js": "^2.4.11",
|
|
61
|
-
"
|
|
62
|
-
"swagger-client": "^3.17.0",
|
|
53
|
+
"swagger-client": "^3.18.4",
|
|
63
54
|
"tweetnacl": "^1.0.3",
|
|
64
55
|
"tweetnacl-auth": "^1.0.1",
|
|
65
|
-
"uuid": "^8.3.2",
|
|
66
56
|
"websocket": "^1.0.34"
|
|
67
57
|
},
|
|
68
58
|
"repository": {
|
|
@@ -70,47 +60,48 @@
|
|
|
70
60
|
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
71
61
|
},
|
|
72
62
|
"devDependencies": {
|
|
73
|
-
"@babel/cli": "^7.
|
|
74
|
-
"@babel/core": "^7.
|
|
75
|
-
"@babel/node": "^7.16.
|
|
76
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
77
|
-
"@babel/preset-env": "^7.16.
|
|
78
|
-
"@babel/preset-typescript": "^7.16.
|
|
79
|
-
"@babel/register": "^7.
|
|
80
|
-
"@commitlint/cli": "^
|
|
81
|
-
"@commitlint/config-conventional": "^
|
|
63
|
+
"@babel/cli": "^7.17.0",
|
|
64
|
+
"@babel/core": "^7.17.2",
|
|
65
|
+
"@babel/node": "^7.16.8",
|
|
66
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
67
|
+
"@babel/preset-env": "^7.16.11",
|
|
68
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
69
|
+
"@babel/register": "^7.17.0",
|
|
70
|
+
"@commitlint/cli": "^16.1.0",
|
|
71
|
+
"@commitlint/config-conventional": "^16.0.0",
|
|
82
72
|
"@types/bn.js": "^5.1.0",
|
|
83
|
-
"@types/
|
|
84
|
-
"@types/
|
|
85
|
-
"@types/
|
|
73
|
+
"@types/bs58": "^4.0.1",
|
|
74
|
+
"@types/chai": "^4.3.0",
|
|
75
|
+
"@types/mocha": "^9.1.0",
|
|
76
|
+
"@types/node": "^17.0.17",
|
|
77
|
+
"@types/sha.js": "^2.4.0",
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^5.11.0",
|
|
79
|
+
"@typescript-eslint/parser": "^5.11.0",
|
|
86
80
|
"babel-loader": "^8.2.3",
|
|
87
|
-
"babel-plugin-
|
|
88
|
-
"
|
|
81
|
+
"babel-plugin-add-import-extension": "^1.6.0",
|
|
82
|
+
"babel-plugin-import-globals": "^2.0.0",
|
|
83
|
+
"babel-plugin-transform-default-named-imports": "^1.2.2",
|
|
84
|
+
"chai": "^4.3.6",
|
|
89
85
|
"chai-as-promised": "^7.1.1",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
86
|
+
"eslint": "^8.8.0",
|
|
87
|
+
"eslint-config-standard": "^17.0.0-1",
|
|
88
|
+
"jsdoc-to-markdown": "^7.1.1",
|
|
89
|
+
"mocha": "^9.2.0",
|
|
93
90
|
"nyc": "^15.1.0",
|
|
94
|
-
"sinon": "^
|
|
91
|
+
"sinon": "^13.0.1",
|
|
95
92
|
"source-map": "^0.7.3",
|
|
96
93
|
"standard-version": "^9.3.2",
|
|
97
|
-
"ts-node": "^10.
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"webpack": "^5.64.1",
|
|
94
|
+
"ts-node": "^10.5.0",
|
|
95
|
+
"typescript": "^4.5.5",
|
|
96
|
+
"webpack": "^5.68.0",
|
|
101
97
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
102
|
-
"webpack-cli": "^4.9.
|
|
98
|
+
"webpack-cli": "^4.9.2"
|
|
103
99
|
},
|
|
104
100
|
"files": [
|
|
105
101
|
"dist",
|
|
106
102
|
"src",
|
|
107
103
|
"es"
|
|
108
104
|
],
|
|
109
|
-
"ts-standard": {
|
|
110
|
-
"ignore": [
|
|
111
|
-
"examples/**/*.js"
|
|
112
|
-
]
|
|
113
|
-
},
|
|
114
105
|
"browserslist": [
|
|
115
106
|
"> 1%",
|
|
116
107
|
"last 2 versions",
|
package/src/account/base.js
CHANGED
|
@@ -85,7 +85,9 @@ async function signMessage (message, opt = { returnHex: false }) {
|
|
|
85
85
|
* Verify message
|
|
86
86
|
* @instance
|
|
87
87
|
* @category async
|
|
88
|
-
* @rtype (
|
|
88
|
+
* @rtype (
|
|
89
|
+
* msg: String, signature: String, publicKey: String
|
|
90
|
+
* ) => signature: Promise[String], throws: Error
|
|
89
91
|
* @param {String} message - Message to verify
|
|
90
92
|
* @param {String} signature - Signature
|
|
91
93
|
* @param {Object} opt - Options
|
package/src/account/memory.js
CHANGED
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import AccountBase from './base'
|
|
26
|
-
import { sign,
|
|
26
|
+
import { sign, isValidKeypair } from '../utils/crypto'
|
|
27
27
|
import { isHex } from '../utils/string'
|
|
28
28
|
import { decode } from '../tx/builder/helpers'
|
|
29
|
+
import { InvalidKeypairError } from '../utils/errors'
|
|
29
30
|
|
|
30
31
|
const secrets = new WeakMap()
|
|
31
32
|
|
|
@@ -44,21 +45,25 @@ export default AccountBase.compose({
|
|
|
44
45
|
init ({ keypair, gaId }) {
|
|
45
46
|
this.isGa = !!gaId
|
|
46
47
|
if (gaId) {
|
|
47
|
-
|
|
48
|
+
decode(gaId)
|
|
48
49
|
secrets.set(this, { publicKey: gaId })
|
|
49
50
|
return
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
if (!keypair || typeof keypair !== 'object') throw new
|
|
53
|
-
if (!keypair.secretKey || !keypair.publicKey)
|
|
54
|
-
|
|
53
|
+
if (!keypair || typeof keypair !== 'object') throw new InvalidKeypairError('KeyPair must be an object')
|
|
54
|
+
if (!keypair.secretKey || !keypair.publicKey) {
|
|
55
|
+
throw new InvalidKeypairError('KeyPair must must have "secretKey", "publicKey" properties')
|
|
56
|
+
}
|
|
57
|
+
if (typeof keypair.publicKey !== 'string' || keypair.publicKey.indexOf('ak_') === -1) {
|
|
58
|
+
throw new InvalidKeypairError('Public Key must be a base58c string with "ak_" prefix')
|
|
59
|
+
}
|
|
55
60
|
if (
|
|
56
61
|
!Buffer.isBuffer(keypair.secretKey) &&
|
|
57
62
|
(typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey))
|
|
58
|
-
) throw new
|
|
63
|
+
) throw new InvalidKeypairError('Secret key must be hex string or Buffer')
|
|
59
64
|
|
|
60
65
|
const pubBuffer = Buffer.from(decode(keypair.publicKey, 'ak'))
|
|
61
|
-
if (!isValidKeypair(Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new
|
|
66
|
+
if (!isValidKeypair(Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new InvalidKeypairError('Invalid Key Pair')
|
|
62
67
|
|
|
63
68
|
secrets.set(this, {
|
|
64
69
|
secretKey: Buffer.isBuffer(keypair.secretKey) ? keypair.secretKey : Buffer.from(keypair.secretKey, 'hex'),
|
|
@@ -68,7 +73,7 @@ export default AccountBase.compose({
|
|
|
68
73
|
props: { isGa: false },
|
|
69
74
|
methods: {
|
|
70
75
|
sign (data) {
|
|
71
|
-
if (this.isGa) throw new
|
|
76
|
+
if (this.isGa) throw new InvalidKeypairError('You are trying to sign data using generalized account without keypair')
|
|
72
77
|
return Promise.resolve(sign(data, secrets.get(this).secretKey))
|
|
73
78
|
},
|
|
74
79
|
address () {
|
package/src/account/multiple.js
CHANGED
|
@@ -25,6 +25,10 @@ import AsyncInit from '../utils/async-init'
|
|
|
25
25
|
import MemoryAccount from './memory'
|
|
26
26
|
import { decode } from '../tx/builder/helpers'
|
|
27
27
|
import AccountBase, { isAccountBase } from './base'
|
|
28
|
+
import {
|
|
29
|
+
UnavailableAccountError,
|
|
30
|
+
TypeError
|
|
31
|
+
} from '../utils/errors'
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* AccountMultiple stamp
|
|
@@ -41,7 +45,9 @@ import AccountBase, { isAccountBase } from './base'
|
|
|
41
45
|
* @param {String} [options.address] - Address of account to select
|
|
42
46
|
* @return {Object} AccountMultiple instance
|
|
43
47
|
* @example
|
|
44
|
-
* const accounts = await AccountMultiple({
|
|
48
|
+
* const accounts = await AccountMultiple({
|
|
49
|
+
* accounts: [MemoryAccount({ keypair: 'keypair_object' })]
|
|
50
|
+
* })
|
|
45
51
|
* await accounts.addAccount(account, { select: true }) // Add account and make it selected
|
|
46
52
|
* accounts.removeAccount(address) // Remove account
|
|
47
53
|
* accounts.selectAccount(address) // Select account
|
|
@@ -123,28 +129,32 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
123
129
|
*/
|
|
124
130
|
selectAccount (address) {
|
|
125
131
|
decode(address, 'ak')
|
|
126
|
-
if (!this.accounts[address]) throw new
|
|
132
|
+
if (!this.accounts[address]) throw new UnavailableAccountError(address)
|
|
127
133
|
this.selectedAddress = address
|
|
128
134
|
},
|
|
129
135
|
/**
|
|
130
136
|
* Resolves an account
|
|
131
|
-
* @param account
|
|
137
|
+
* @param account account address (should exist in sdk instance), MemoryAccount or keypair
|
|
132
138
|
* @returns {AccountBase}
|
|
133
139
|
* @private
|
|
134
140
|
*/
|
|
135
141
|
_resolveAccount (account) {
|
|
136
142
|
if (account === null) {
|
|
137
|
-
throw new
|
|
143
|
+
throw new TypeError(
|
|
144
|
+
'Account should be an address (ak-prefixed string), ' +
|
|
145
|
+
'keypair, or instance of account base, got null instead')
|
|
138
146
|
} else {
|
|
139
147
|
switch (typeof account) {
|
|
140
148
|
case 'string':
|
|
141
149
|
decode(account, 'ak')
|
|
142
|
-
if (!this.accounts[account]) throw new
|
|
150
|
+
if (!this.accounts[account]) throw new UnavailableAccountError(account)
|
|
143
151
|
return this.accounts[account]
|
|
144
152
|
case 'object':
|
|
145
153
|
return isAccountBase(account) ? account : MemoryAccount({ keypair: account })
|
|
146
154
|
default:
|
|
147
|
-
throw new
|
|
155
|
+
throw new TypeError(
|
|
156
|
+
'Account should be an address (ak-prefixed string), ' +
|
|
157
|
+
`keypair, or instance of account base, got ${account} instead`)
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
}
|