@aeternity/aepp-sdk 8.2.1 → 10.0.0
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/CHANGELOG.md +216 -337
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- 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 +36 -120
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +238 -465
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +328 -495
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +41 -106
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/es/contract/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import { required } from '@stamp/required';
|
|
|
36
36
|
* @return {Object} Contract instance
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const ContractBase = stampit(required({
|
|
40
40
|
methods: {
|
|
41
41
|
contractEncodeCallDataAPI: required,
|
|
42
42
|
compileContractAPI: required,
|
|
@@ -83,7 +83,9 @@ var ContractBase = stampit(required({
|
|
|
83
83
|
* @instance
|
|
84
84
|
* @abstract
|
|
85
85
|
* @category async
|
|
86
|
-
* @rtype (
|
|
86
|
+
* @rtype (
|
|
87
|
+
* source: String, fn: String, callValue: String, callResult: String, options: Array
|
|
88
|
+
* ) => decodedResult: Promise[String]
|
|
87
89
|
* @param {String} source - Contract source
|
|
88
90
|
* @param {String} fn - Fn name
|
|
89
91
|
* @param {String} callValue - result data (cb_das...)
|
|
@@ -99,7 +101,9 @@ var ContractBase = stampit(required({
|
|
|
99
101
|
* @instance
|
|
100
102
|
* @abstract
|
|
101
103
|
* @category async
|
|
102
|
-
* @rtype (
|
|
104
|
+
* @rtype (
|
|
105
|
+
* source: String, function: String, callData: String, options: Array
|
|
106
|
+
* ) => decodedResult: Promise[String]
|
|
103
107
|
* @param {String} source - contract source
|
|
104
108
|
* @param {String} function - function name
|
|
105
109
|
* @param {String} callData - Encoded contract call data
|
package/es/contract/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contract/index.js"],"names":["stampit","required","ContractBase","methods","contractEncodeCallDataAPI","compileContractAPI","contractGetACI","setCompilerUrl","getCompilerVersion","contractDecodeCallResultAPI","validateByteCodeAPI","getFateAssembler","getBytecodeCompilerVersion"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,
|
|
1
|
+
{"version":3,"sources":["../../src/contract/index.js"],"names":["stampit","required","ContractBase","methods","contractEncodeCallDataAPI","compileContractAPI","contractGetACI","setCompilerUrl","getCompilerVersion","contractDecodeCallResultAPI","validateByteCodeAPI","getFateAssembler","getBytecodeCompilerVersion"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,OAAO,CAACC,QAAQ,CAAC;AACpCE,EAAAA,OAAO,EAAE;AACPC,IAAAA,yBAAyB,EAAEH,QADpB;AAEPI,IAAAA,kBAAkB,EAAEJ,QAFb;AAGPK,IAAAA,cAAc,EAAEL,QAHT;AAIPM,IAAAA,cAAc,EAAEN,QAJT;AAKPO,IAAAA,kBAAkB,EAAEP,QALb;AAMPQ,IAAAA,2BAA2B,EAAER,QANtB;AAOPS,IAAAA,mBAAmB,EAAET,QAPd;AAQPU,IAAAA,gBAAgB,EAAEV,QARX;AASPW,IAAAA,0BAA0B,EAAEX;AATrB;AAD2B,CAAD,CAAT,CAA5B;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAeC,YAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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 * Contract Base module\n * @module @aeternity/aepp-sdk/es/contract\n * @export Contract\n * @example import ContractBase from '@aeternity/aepp-sdk/es/contract'\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\n\n/**\n * Basic Contract Stamp\n *\n * This stamp include api call's related to contract functionality.\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/contract\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} Contract instance\n */\nconst ContractBase = stampit(required({\n methods: {\n contractEncodeCallDataAPI: required,\n compileContractAPI: required,\n contractGetACI: required,\n setCompilerUrl: required,\n getCompilerVersion: required,\n contractDecodeCallResultAPI: required,\n validateByteCodeAPI: required,\n getFateAssembler: required,\n getBytecodeCompilerVersion: required\n }\n}))\n\n/**\n * Get contract ACI\n * @function contractGetACI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, options: Array) => aciObject: Promise[Object]\n * @param {String} source - Contract source code\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {Object} - Contract aci object\n */\n\n/**\n * Encode contract data\n * @function contractEncodeCallDataAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, name: String, args: Array, options: Array) => callData: Promise[String]\n * @param {String} source - Contract source code\n * @param {String} name - Function name\n * @param {Array} args - Function argument's\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Contract encoded data\n */\n\n/**\n * Decode contract call result data\n * @function contractDecodeCallResultAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (\n * source: String, fn: String, callValue: String, callResult: String, options: Array\n * ) => decodedResult: Promise[String]\n * @param {String} source - Contract source\n * @param {String} fn - Fn name\n * @param {String} callValue - result data (cb_das...)\n * @param {String} callResult - contract call result status('ok', 'revert', ...)\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Decoded contract call result\n */\n\n/**\n * Decode call data by source\n * @function contractDecodeCallDataBySourceAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (\n * source: String, function: String, callData: String, options: Array\n * ) => decodedResult: Promise[String]\n * @param {String} source - contract source\n * @param {String} function - function name\n * @param {String} callData - Encoded contract call data\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Decoded contract call data\n */\n\n/**\n * Decode call data by bytecode\n * @function contractDecodeCallDataByCodeAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (code: String, callData: String) => decodedResult: Promise[String]\n * @param {String} code - contract byte code\n * @param {String} callData - Encoded contract call data\n * @return {String} - Decoded contract call data\n */\n\n/**\n * Compile contract\n * @function compileContractAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (code: String, options?: Object) => compiledContract: Object\n * @param {String} code - Contract source code\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {Object} Object which contain bytecode of contract\n */\n\n/**\n * Set compiler url\n * @function setCompilerUrl\n * @instance\n * @abstract\n * @category async\n * @rtype (url: String) => void\n * @param {String} url - Compiler url\n * @return {void}\n */\n\n/**\n * Get Compiler Version\n * @function getCompilerVersion\n * @instance\n * @abstract\n * @category async\n * @rtype () => String\n * @return {String} Compiler version\n */\n\nexport default ContractBase\n"],"file":"index.js"}
|
package/es/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import * as Bytes from './utils/bytes';
|
|
|
20
20
|
import * as TxBuilder from './tx/builder';
|
|
21
21
|
import * as TxBuilderHelper from './tx/builder/helpers';
|
|
22
22
|
import * as SCHEMA from './tx/builder/schema';
|
|
23
|
-
import * as ACIHelpers from './contract/aci/helpers';
|
|
24
23
|
import * as ACITransformation from './contract/aci/transformation';
|
|
25
24
|
import * as AmountFormatter from './utils/amount-formatter';
|
|
26
25
|
import HdWallet from './utils/hd-wallet';
|
|
@@ -31,7 +30,7 @@ import Node from './node';
|
|
|
31
30
|
import NodePool from './node-pool';
|
|
32
31
|
import Tx from './tx';
|
|
33
32
|
import Transaction from './tx/tx';
|
|
34
|
-
import
|
|
33
|
+
import verifyTransaction from './tx/validator';
|
|
35
34
|
import AccountBase from './account/base';
|
|
36
35
|
import AccountMultiple from './account/multiple';
|
|
37
36
|
import MemoryAccount from './account/memory';
|
|
@@ -53,5 +52,6 @@ export { _AeppWalletSchema as AeppWalletSchema };
|
|
|
53
52
|
export { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector';
|
|
54
53
|
export { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime';
|
|
55
54
|
export { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message';
|
|
56
|
-
export
|
|
55
|
+
export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey;
|
|
56
|
+
export { AmountFormatter, AccountBase, AccountMultiple, Ae, Aens, Bytes, Contract, ContractCompilerAPI, ACITransformation, ChainNode, RpcAepp, RpcWallet, Channel, Crypto, Keystore, Chain, GeneralizeAccount, HdWallet, MemoryAccount, Node, NodePool, Oracle, genSwaggerClient, Transaction, verifyTransaction, Tx, TxBuilder, TxBuilderHelper, Universal, SCHEMA };
|
|
57
57
|
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["Crypto","Keystore","Bytes","TxBuilder","TxBuilderHelper","SCHEMA","
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["Crypto","Keystore","Bytes","TxBuilder","TxBuilderHelper","SCHEMA","ACITransformation","AmountFormatter","HdWallet","Ae","Chain","ChainNode","Node","NodePool","Tx","Transaction","verifyTransaction","AccountBase","AccountMultiple","MemoryAccount","Aens","Contract","GeneralizeAccount","ContractCompilerAPI","RpcAepp","RpcWallet","Oracle","genSwaggerClient","Channel","Universal","default","ContentScriptBridge","AeppWalletHelpers","AeppWalletSchema","WalletDetector","BrowserRuntimeConnection","BrowserWindowMessageConnection","getDefaultPointerKey"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,MAAZ,MAAwB,gBAAxB;AACA,OAAO,KAAKC,QAAZ,MAA0B,kBAA1B;AACA,OAAO,KAAKC,KAAZ,MAAuB,eAAvB;AACA,OAAO,KAAKC,SAAZ,MAA2B,cAA3B;AACA,OAAO,KAAKC,eAAZ,MAAiC,sBAAjC;AACA,OAAO,KAAKC,MAAZ,MAAwB,qBAAxB;AACA,OAAO,KAAKC,iBAAZ,MAAmC,+BAAnC;AACA,OAAO,KAAKC,eAAZ,MAAiC,0BAAjC;AACA,OAAOC,QAAP,MAAqB,mBAArB;AAEA,OAAOC,EAAP,MAAe,MAAf;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,OAAOC,EAAP,MAAe,MAAf;AACA,OAAOC,WAAP,MAAwB,SAAxB;AACA,OAAOC,iBAAP,MAA8B,gBAA9B;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,OAAOC,IAAP,MAAiB,WAAjB;AACA,OAAOC,QAAP,MAAqB,eAArB;AACA,OAAOC,iBAAP,MAA8B,eAA9B;AACA,OAAOC,mBAAP,MAAgC,qBAAhC;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,SAAP,MAAsB,aAAtB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,OAAOC,gBAAP,MAA6B,iBAA7B;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,SAAP,MAAsB,gBAAtB;AAEA,SAASC,OAAO,IAAIC,mBAApB,QAA+C,yDAA/C;oCACmC,2C;+BAAvBC,iB;mCACsB,0C;8BAAtBC,gB;AACZ,SAASH,OAAO,IAAII,cAApB,QAA0C,mDAA1C;AACA,SAASJ,OAAO,IAAIK,wBAApB,QAAoD,8DAApD;AACA,SAASL,OAAO,IAAIM,8BAApB,QAA0D,qEAA1D;AAEA,OAAO,MAAMC,oBAAoB,GAAGjC,eAAe,CAACiC,oBAA7C;AAEP,SACE9B,eADF,EAEEU,WAFF,EAGEC,eAHF,EAIET,EAJF,EAKEW,IALF,EAMElB,KANF,EAOEmB,QAPF,EAQEE,mBARF,EASEjB,iBATF,EAUEK,SAVF,EAWEa,OAXF,EAYEC,SAZF,EAaEG,OAbF,EAcE5B,MAdF,EAeEC,QAfF,EAgBES,KAhBF,EAiBEY,iBAjBF,EAkBEd,QAlBF,EAmBEW,aAnBF,EAoBEP,IApBF,EAqBEC,QArBF,EAsBEa,MAtBF,EAuBEC,gBAvBF,EAwBEZ,WAxBF,EAyBEC,iBAzBF,EA0BEF,EA1BF,EA2BEX,SA3BF,EA4BEC,eA5BF,EA6BEyB,SA7BF,EA8BExB,MA9BF","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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\nimport * as Crypto from './utils/crypto'\nimport * as Keystore from './utils/keystore'\nimport * as Bytes from './utils/bytes'\nimport * as TxBuilder from './tx/builder'\nimport * as TxBuilderHelper from './tx/builder/helpers'\nimport * as SCHEMA from './tx/builder/schema'\nimport * as ACITransformation from './contract/aci/transformation'\nimport * as AmountFormatter from './utils/amount-formatter'\nimport HdWallet from './utils/hd-wallet'\n\nimport Ae from './ae'\nimport Chain from './chain'\nimport ChainNode from './chain/node'\nimport Node from './node'\nimport NodePool from './node-pool'\nimport Tx from './tx'\nimport Transaction from './tx/tx'\nimport verifyTransaction from './tx/validator'\nimport AccountBase from './account/base'\nimport AccountMultiple from './account/multiple'\nimport MemoryAccount from './account/memory'\nimport Aens from './ae/aens'\nimport Contract from './ae/contract'\nimport GeneralizeAccount from './contract/ga'\nimport ContractCompilerAPI from './contract/compiler'\nimport RpcAepp from './ae/aepp'\nimport RpcWallet from './ae/wallet'\nimport Oracle from './ae/oracle'\nimport genSwaggerClient from './utils/swagger'\nimport Channel from './channel'\nimport Universal from './ae/universal'\n\nexport { default as ContentScriptBridge } from './utils/aepp-wallet-communication/content-script-bridge'\nexport * as AeppWalletHelpers from './utils/aepp-wallet-communication/helpers'\nexport * as AeppWalletSchema from './utils/aepp-wallet-communication/schema'\nexport { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector'\nexport { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime'\nexport { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message'\n\nexport const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey\n\nexport {\n AmountFormatter,\n AccountBase,\n AccountMultiple,\n Ae,\n Aens,\n Bytes,\n Contract,\n ContractCompilerAPI,\n ACITransformation,\n ChainNode,\n RpcAepp,\n RpcWallet,\n Channel,\n Crypto,\n Keystore,\n Chain,\n GeneralizeAccount,\n HdWallet,\n MemoryAccount,\n Node,\n NodePool,\n Oracle,\n genSwaggerClient,\n Transaction,\n verifyTransaction,\n Tx,\n TxBuilder,\n TxBuilderHelper,\n Universal,\n SCHEMA\n}\n"],"file":"index.js"}
|
package/es/node-pool/index.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
7
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
8
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
14
|
-
|
|
15
|
-
import _Map from "@babel/runtime-corejs3/core-js-stable/map";
|
|
16
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
17
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
18
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
19
|
-
import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/entries";
|
|
20
|
-
|
|
21
1
|
/**
|
|
22
2
|
* NodePool module
|
|
23
3
|
* @module @aeternity/aepp-sdk/es/node-pool
|
|
@@ -25,7 +5,6 @@ import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
|
25
5
|
* @example import { NodePool } from '@aeternity/aepp-sdk'
|
|
26
6
|
*/
|
|
27
7
|
import stampit from '@stamp/it';
|
|
28
|
-
import Joi from 'joi-browser';
|
|
29
8
|
import { getNetworkId } from '../node';
|
|
30
9
|
/**
|
|
31
10
|
* Node Pool Stamp
|
|
@@ -39,36 +18,35 @@ import { getNetworkId } from '../node';
|
|
|
39
18
|
*/
|
|
40
19
|
|
|
41
20
|
export default stampit({
|
|
42
|
-
init
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
nodes = _ref$nodes === void 0 ? [] : _ref$nodes;
|
|
48
|
-
|
|
49
|
-
this.pool = new _Map();
|
|
21
|
+
init() {
|
|
22
|
+
let {
|
|
23
|
+
nodes = []
|
|
24
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
|
+
this.pool = new Map();
|
|
50
26
|
this.validateNodes(nodes);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
nodes.forEach((node, i) => {
|
|
28
|
+
const {
|
|
29
|
+
name,
|
|
30
|
+
instance
|
|
31
|
+
} = node;
|
|
32
|
+
this.addNode(name, instance, i === 0);
|
|
57
33
|
});
|
|
58
|
-
|
|
59
34
|
if (nodes.length) this.selectNode(nodes[0].name);
|
|
60
35
|
},
|
|
36
|
+
|
|
61
37
|
propertyDescriptors: {
|
|
62
38
|
api: {
|
|
63
39
|
enumerable: true,
|
|
64
40
|
configurable: false,
|
|
65
|
-
|
|
41
|
+
|
|
42
|
+
get() {
|
|
66
43
|
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
67
44
|
throw new Error('You can\'t use Node API. Node is not connected or not defined!');
|
|
68
45
|
}
|
|
69
46
|
|
|
70
47
|
return this.selectedNode.instance.api;
|
|
71
48
|
}
|
|
49
|
+
|
|
72
50
|
}
|
|
73
51
|
},
|
|
74
52
|
methods: {
|
|
@@ -82,17 +60,18 @@ export default stampit({
|
|
|
82
60
|
* @param {Boolean} select - Select this node as current
|
|
83
61
|
* @return {void}
|
|
84
62
|
* @example
|
|
85
|
-
*
|
|
63
|
+
* // add and select new node with name 'testNode'
|
|
64
|
+
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
|
|
86
65
|
*/
|
|
87
|
-
addNode
|
|
88
|
-
|
|
89
|
-
if (this.pool.has(name)) throw new Error(
|
|
66
|
+
addNode(name, node) {
|
|
67
|
+
let select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
68
|
+
if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`);
|
|
90
69
|
this.validateNodes([{
|
|
91
|
-
name
|
|
70
|
+
name,
|
|
92
71
|
instance: node
|
|
93
72
|
}]);
|
|
94
73
|
this.pool.set(name, {
|
|
95
|
-
name
|
|
74
|
+
name,
|
|
96
75
|
instance: node,
|
|
97
76
|
url: node.url,
|
|
98
77
|
internalUrl: node.internalUrl,
|
|
@@ -116,8 +95,8 @@ export default stampit({
|
|
|
116
95
|
* @example
|
|
117
96
|
* nodePool.selectNode('testNode')
|
|
118
97
|
*/
|
|
119
|
-
selectNode
|
|
120
|
-
if (!this.pool.has(name)) throw new Error(
|
|
98
|
+
selectNode(name) {
|
|
99
|
+
if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`);
|
|
121
100
|
this.selectedNode = this.pool.get(name);
|
|
122
101
|
},
|
|
123
102
|
|
|
@@ -130,7 +109,7 @@ export default stampit({
|
|
|
130
109
|
* @example
|
|
131
110
|
* nodePool.getNetworkId()
|
|
132
111
|
*/
|
|
133
|
-
getNetworkId
|
|
112
|
+
getNetworkId,
|
|
134
113
|
|
|
135
114
|
/**
|
|
136
115
|
* Check if you have selected node
|
|
@@ -141,7 +120,7 @@ export default stampit({
|
|
|
141
120
|
* @example
|
|
142
121
|
* nodePool.isNodeConnected()
|
|
143
122
|
*/
|
|
144
|
-
isNodeConnected
|
|
123
|
+
isNodeConnected() {
|
|
145
124
|
return !!this.selectedNode.instance;
|
|
146
125
|
},
|
|
147
126
|
|
|
@@ -154,11 +133,12 @@ export default stampit({
|
|
|
154
133
|
* @example
|
|
155
134
|
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
156
135
|
*/
|
|
157
|
-
getNodeInfo
|
|
136
|
+
getNodeInfo() {
|
|
158
137
|
if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected');
|
|
159
|
-
return
|
|
160
|
-
name: this.selectedNode.name
|
|
161
|
-
|
|
138
|
+
return {
|
|
139
|
+
name: this.selectedNode.name,
|
|
140
|
+
...this.selectedNode.instance.getNodeInfo()
|
|
141
|
+
};
|
|
162
142
|
},
|
|
163
143
|
|
|
164
144
|
/**
|
|
@@ -170,32 +150,35 @@ export default stampit({
|
|
|
170
150
|
* @example
|
|
171
151
|
* nodePool.getNodesInPool()
|
|
172
152
|
*/
|
|
173
|
-
getNodesInPool
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return _objectSpread({
|
|
182
|
-
name: name
|
|
183
|
-
}, node.instance.getNodeInfo());
|
|
153
|
+
getNodesInPool() {
|
|
154
|
+
return Array.from(this.pool.entries()).map(_ref => {
|
|
155
|
+
let [name, node] = _ref;
|
|
156
|
+
return {
|
|
157
|
+
name,
|
|
158
|
+
...node.instance.getNodeInfo()
|
|
159
|
+
};
|
|
184
160
|
});
|
|
185
161
|
},
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
162
|
+
|
|
163
|
+
validateNodes(nodes) {
|
|
164
|
+
// TODO: validate it on TypeScript level instead
|
|
165
|
+
// (to speedup development, save runtime resources)
|
|
166
|
+
if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array');
|
|
167
|
+
const notObject = nodes.map(n => typeof n).find(t => t !== 'object');
|
|
168
|
+
if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`);
|
|
169
|
+
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object');
|
|
170
|
+
|
|
171
|
+
if (notObject) {
|
|
172
|
+
throw new Error('Each node should have name (string), instance (object) ' + `fields, got ${JSON.stringify(wrongFields)} instead`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const wrongInstanceFields = nodes.map(n => n.instance).find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' || typeof i.consensusProtocolVersion !== 'number');
|
|
176
|
+
|
|
177
|
+
if (wrongInstanceFields) {
|
|
178
|
+
throw new Error('Each node instance should have api (object), consensusProtocolVersion (number), ' + `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`);
|
|
179
|
+
}
|
|
198
180
|
}
|
|
181
|
+
|
|
199
182
|
},
|
|
200
183
|
props: {
|
|
201
184
|
selectedNode: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","
|
|
1
|
+
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","getNetworkId","init","nodes","pool","Map","validateNodes","forEach","node","i","name","instance","addNode","length","selectNode","propertyDescriptors","api","enumerable","configurable","get","selectedNode","Error","methods","select","has","set","url","internalUrl","networkId","nodeNetworkId","version","consensusProtocolVersion","isNodeConnected","getNodeInfo","getNodesInPool","Array","from","entries","map","isArray","notObject","n","find","t","wrongFields","JSON","stringify","wrongInstanceFields","genesisHash","props"],"mappings":"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","sourcesContent":["/**\n * NodePool module\n * @module @aeternity/aepp-sdk/es/node-pool\n * @export NodePool\n * @example import { NodePool } from '@aeternity/aepp-sdk'\n */\nimport stampit from '@stamp/it'\nimport { getNetworkId } from '../node'\n\n/**\n * Node Pool Stamp\n * This stamp allow you to make basic manipulation(add, remove, select) on list of nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Array} [options.nodes] - Array with Node instances\n * @return {Object} NodePool instance\n */\nexport default stampit({\n init ({ nodes = [] } = {}) {\n this.pool = new Map()\n this.validateNodes(nodes)\n\n nodes.forEach((node, i) => {\n const { name, instance } = node\n this.addNode(name, instance, i === 0)\n })\n if (nodes.length) this.selectNode(nodes[0].name)\n },\n propertyDescriptors: {\n api: {\n enumerable: true,\n configurable: false,\n get () {\n if (!this.selectedNode || !this.selectedNode.instance) {\n throw new Error('You can\\'t use Node API. Node is not connected or not defined!')\n }\n return this.selectedNode.instance.api\n }\n }\n },\n methods: {\n /**\n * Add Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String, nodeInstance: Object, select: Boolean) => void\n * @param {String} name - Node name\n * @param {Object} node - Node instance\n * @param {Boolean} select - Select this node as current\n * @return {void}\n * @example\n * // add and select new node with name 'testNode'\n * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)\n */\n addNode (name, node, select = false) {\n if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)\n\n this.validateNodes([{ name, instance: node }])\n\n this.pool.set(name, {\n name,\n instance: node,\n url: node.url,\n internalUrl: node.internalUrl,\n networkId: node.nodeNetworkId,\n version: node.version,\n consensusProtocolVersion: node.consensusProtocolVersion\n })\n if (select || !this.selectedNode) {\n this.selectNode(name)\n }\n },\n /**\n * Select Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String) => void\n * @param {String} name - Node name\n * @return {void}\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode (name) {\n if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`)\n\n this.selectedNode = this.pool.get(name)\n },\n /**\n * Get NetworkId of current Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => String\n * @return {String}\n * @example\n * nodePool.getNetworkId()\n */\n getNetworkId,\n /**\n * Check if you have selected node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Boolean\n * @return {Boolean}\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected () {\n return !!this.selectedNode.instance\n },\n /**\n * Get information about node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object\n * @return {Object}\n * @example\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n */\n getNodeInfo () {\n if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected')\n return {\n name: this.selectedNode.name,\n ...this.selectedNode.instance.getNodeInfo()\n }\n },\n /**\n * Get array of available nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object[]\n * @return {Object[]}\n * @example\n * nodePool.getNodesInPool()\n */\n getNodesInPool () {\n return Array.from(this.pool.entries()).map(([name, node]) => ({\n name,\n ...node.instance.getNodeInfo()\n }))\n },\n validateNodes (nodes) {\n // TODO: validate it on TypeScript level instead\n // (to speedup development, save runtime resources)\n if (!Array.isArray(nodes)) throw new Error('\"nodes\" should be an array')\n const notObject = nodes.map(n => typeof n).find(t => t !== 'object')\n if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`)\n const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')\n if (notObject) {\n throw new Error(\n 'Each node should have name (string), instance (object) ' +\n `fields, got ${JSON.stringify(wrongFields)} instead`\n )\n }\n const wrongInstanceFields = nodes\n .map(n => n.instance)\n .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||\n typeof i.consensusProtocolVersion !== 'number')\n if (wrongInstanceFields) {\n throw new Error(\n 'Each node instance should have api (object), consensusProtocolVersion (number), ' +\n `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`\n )\n }\n }\n },\n props: {\n selectedNode: {}\n }\n})\n"],"file":"index.js"}
|