@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/AeSdkBase.ts
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import * as chainMethods from './chain'
|
|
2
|
-
import * as txMethods from './tx'
|
|
3
|
-
import * as aensMethods from './aens'
|
|
4
|
-
import * as spendMethods from './spend'
|
|
5
|
-
import * as oracleMethods from './oracle'
|
|
6
|
-
import * as contractMethods from './contract/methods'
|
|
7
|
-
import * as contractGaMethods from './contract/ga'
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
1
|
+
import * as chainMethods from './chain';
|
|
2
|
+
import * as txMethods from './tx';
|
|
3
|
+
import * as aensMethods from './aens';
|
|
4
|
+
import * as spendMethods from './spend';
|
|
5
|
+
import * as oracleMethods from './oracle';
|
|
6
|
+
import * as contractMethods from './contract/methods';
|
|
7
|
+
import * as contractGaMethods from './contract/ga';
|
|
8
|
+
import * as deprecatedMethods from './deprecated/methods';
|
|
9
|
+
import { _buildTx } from './tx';
|
|
10
|
+
import { mapObject } from './utils/other';
|
|
11
|
+
import Node, { getNetworkId } from './Node';
|
|
12
|
+
import { AE_AMOUNT_FORMATS } from './utils/amount-formatter';
|
|
13
|
+
import { AMOUNT } from './tx/builder/schema';
|
|
14
|
+
import { Tag } from './tx/builder/constants';
|
|
15
|
+
import MemoryAccount, { Keypair } from './account/Memory';
|
|
16
|
+
import AccountBase, { isAccountBase } from './account/Base';
|
|
15
17
|
import {
|
|
16
18
|
CompilerError,
|
|
17
19
|
DuplicateNodeError,
|
|
18
20
|
NodeNotFoundError,
|
|
19
21
|
NotImplementedError,
|
|
20
|
-
TypeError
|
|
21
|
-
} from './utils/errors'
|
|
22
|
-
import {
|
|
23
|
-
import Compiler from './contract/Compiler'
|
|
22
|
+
TypeError,
|
|
23
|
+
} from './utils/errors';
|
|
24
|
+
import { Encoded } from './utils/encoder';
|
|
25
|
+
import Compiler from './contract/Compiler';
|
|
24
26
|
|
|
25
|
-
export type Account = Keypair | AccountBase | any
|
|
27
|
+
export type Account = Keypair | AccountBase | any;
|
|
26
28
|
|
|
27
|
-
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string }
|
|
29
|
+
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };
|
|
28
30
|
|
|
29
|
-
function getValueOrErrorProxy<Value extends object>
|
|
31
|
+
function getValueOrErrorProxy<Value extends object>(valueCb: () => Value): Value {
|
|
30
32
|
try {
|
|
31
|
-
return valueCb()
|
|
33
|
+
return valueCb();
|
|
32
34
|
} catch (error) {
|
|
33
35
|
return new Proxy(
|
|
34
36
|
{},
|
|
35
|
-
Object.fromEntries(['get', 'set', 'has'].map(name => [name, () => { throw error }]))
|
|
36
|
-
) as Value
|
|
37
|
+
Object.fromEntries(['get', 'set', 'has'].map((name) => [name, () => { throw error; }])),
|
|
38
|
+
) as Value;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -54,14 +56,16 @@ function getValueOrErrorProxy<Value extends object> (valueCb: () => Value): Valu
|
|
|
54
56
|
*/
|
|
55
57
|
class AeSdkBase {
|
|
56
58
|
_options: {
|
|
57
|
-
denomination: AE_AMOUNT_FORMATS
|
|
58
|
-
amount: number
|
|
59
|
-
[key: string]: any
|
|
60
|
-
} = { denomination: AE_AMOUNT_FORMATS.AETTOS, amount: AMOUNT }
|
|
59
|
+
denomination: AE_AMOUNT_FORMATS;
|
|
60
|
+
amount: number;
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
} = { denomination: AE_AMOUNT_FORMATS.AETTOS, amount: AMOUNT };
|
|
61
63
|
|
|
62
|
-
pool: Map<string, Node> = new Map()
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
pool: Map<string, Node> = new Map();
|
|
65
|
+
|
|
66
|
+
selectedNodeName?: string;
|
|
67
|
+
|
|
68
|
+
compilerApi: Compiler;
|
|
65
69
|
|
|
66
70
|
/**
|
|
67
71
|
* @param options - Options
|
|
@@ -69,35 +73,38 @@ class AeSdkBase {
|
|
|
69
73
|
* @param options.compilerUrl - Url for compiler API
|
|
70
74
|
* @param options.ignoreVersion - Don't check node or compiler version
|
|
71
75
|
*/
|
|
72
|
-
constructor
|
|
73
|
-
{ nodes = [], compilerUrl, ignoreVersion = false, ...options }:
|
|
76
|
+
constructor(
|
|
74
77
|
{
|
|
75
|
-
nodes
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
nodes = [], compilerUrl, ignoreVersion = false, ...options
|
|
79
|
+
}:
|
|
80
|
+
{
|
|
81
|
+
nodes?: Array<{ name: string; instance: Node }>;
|
|
82
|
+
compilerUrl?: string;
|
|
83
|
+
ignoreVersion?: boolean;
|
|
84
|
+
[key: string]: any; // TODO: consider combining all possible options instead
|
|
85
|
+
} = {},
|
|
80
86
|
) {
|
|
81
|
-
Object.assign(this._options, options)
|
|
87
|
+
Object.assign(this._options, options);
|
|
82
88
|
|
|
83
|
-
nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0))
|
|
89
|
+
nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0));
|
|
84
90
|
|
|
85
91
|
if (compilerUrl == null) {
|
|
86
92
|
this.compilerApi = getValueOrErrorProxy(() => {
|
|
87
|
-
throw new CompilerError('You can\'t use Compiler API. Compiler is not ready!')
|
|
88
|
-
})
|
|
89
|
-
} else this.setCompilerUrl(compilerUrl, { ignoreVersion })
|
|
93
|
+
throw new CompilerError('You can\'t use Compiler API. Compiler is not ready!');
|
|
94
|
+
});
|
|
95
|
+
} else this.setCompilerUrl(compilerUrl, { ignoreVersion });
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
setCompilerUrl
|
|
93
|
-
compilerUrl: string,
|
|
98
|
+
setCompilerUrl(
|
|
99
|
+
compilerUrl: string,
|
|
100
|
+
{ ignoreVersion = false }: { ignoreVersion?: boolean } = {},
|
|
94
101
|
): void {
|
|
95
|
-
this.compilerApi = new Compiler(compilerUrl, { ignoreVersion })
|
|
102
|
+
this.compilerApi = new Compiler(compilerUrl, { ignoreVersion });
|
|
96
103
|
}
|
|
97
104
|
|
|
98
|
-
get api
|
|
99
|
-
this.ensureNodeConnected()
|
|
100
|
-
return this.pool.get(this.selectedNodeName) as Node
|
|
105
|
+
get api(): Node {
|
|
106
|
+
this.ensureNodeConnected();
|
|
107
|
+
return this.pool.get(this.selectedNodeName) as Node;
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
/**
|
|
@@ -111,12 +118,12 @@ class AeSdkBase {
|
|
|
111
118
|
* aeSdkBase.addNode('testNode', new Node({ url }), true)
|
|
112
119
|
* ```
|
|
113
120
|
*/
|
|
114
|
-
addNode
|
|
115
|
-
if (this.pool.has(name)) throw new DuplicateNodeError(name)
|
|
121
|
+
addNode(name: string, node: Node, select = false): void {
|
|
122
|
+
if (this.pool.has(name)) throw new DuplicateNodeError(name);
|
|
116
123
|
|
|
117
|
-
this.pool.set(name, node)
|
|
124
|
+
this.pool.set(name, node);
|
|
118
125
|
if (select || this.selectedNodeName == null) {
|
|
119
|
-
this.selectNode(name)
|
|
126
|
+
this.selectNode(name);
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|
|
@@ -126,9 +133,9 @@ class AeSdkBase {
|
|
|
126
133
|
* @example
|
|
127
134
|
* nodePool.selectNode('testNode')
|
|
128
135
|
*/
|
|
129
|
-
selectNode
|
|
130
|
-
if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)
|
|
131
|
-
this.selectedNodeName = name
|
|
136
|
+
selectNode(name: string): void {
|
|
137
|
+
if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);
|
|
138
|
+
this.selectedNodeName = name;
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
/**
|
|
@@ -136,20 +143,20 @@ class AeSdkBase {
|
|
|
136
143
|
* @example
|
|
137
144
|
* nodePool.getNetworkId()
|
|
138
145
|
*/
|
|
139
|
-
readonly getNetworkId = getNetworkId
|
|
146
|
+
readonly getNetworkId = getNetworkId;
|
|
140
147
|
|
|
141
148
|
/**
|
|
142
149
|
* Check if you have selected node
|
|
143
150
|
* @example
|
|
144
151
|
* nodePool.isNodeConnected()
|
|
145
152
|
*/
|
|
146
|
-
isNodeConnected
|
|
147
|
-
return this.selectedNodeName != null
|
|
153
|
+
isNodeConnected(): this is AeSdkBase & { selectedNodeName: string } {
|
|
154
|
+
return this.selectedNodeName != null;
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
protected ensureNodeConnected
|
|
157
|
+
protected ensureNodeConnected(): asserts this is AeSdkBase & { selectedNodeName: string } {
|
|
151
158
|
if (!this.isNodeConnected()) {
|
|
152
|
-
throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!')
|
|
159
|
+
throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!');
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
|
|
@@ -160,12 +167,12 @@ class AeSdkBase {
|
|
|
160
167
|
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
161
168
|
* ```
|
|
162
169
|
*/
|
|
163
|
-
async getNodeInfo
|
|
164
|
-
this.ensureNodeConnected()
|
|
170
|
+
async getNodeInfo(): Promise<NodeInfo> {
|
|
171
|
+
this.ensureNodeConnected();
|
|
165
172
|
return {
|
|
166
173
|
name: this.selectedNodeName,
|
|
167
|
-
...await this.api.getNodeInfo()
|
|
168
|
-
}
|
|
174
|
+
...await this.api.getNodeInfo(),
|
|
175
|
+
};
|
|
169
176
|
}
|
|
170
177
|
|
|
171
178
|
/**
|
|
@@ -173,119 +180,130 @@ class AeSdkBase {
|
|
|
173
180
|
* @example
|
|
174
181
|
* nodePool.getNodesInPool()
|
|
175
182
|
*/
|
|
176
|
-
async getNodesInPool
|
|
177
|
-
return
|
|
183
|
+
async getNodesInPool(): Promise<NodeInfo[]> {
|
|
184
|
+
return Promise.all(
|
|
178
185
|
Array.from(this.pool.entries()).map(async ([name, node]) => ({
|
|
179
186
|
name,
|
|
180
|
-
...await node.getNodeInfo()
|
|
181
|
-
}))
|
|
182
|
-
)
|
|
187
|
+
...await node.getNodeInfo(),
|
|
188
|
+
})),
|
|
189
|
+
);
|
|
183
190
|
}
|
|
184
191
|
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
// eslint-disable-next-line class-methods-use-this
|
|
193
|
+
addresses(): Encoded.AccountAddress[] {
|
|
194
|
+
return [];
|
|
187
195
|
}
|
|
188
196
|
|
|
189
|
-
async address
|
|
190
|
-
return
|
|
197
|
+
async address({ onAccount }: { onAccount?: Account } = {}): Promise<Encoded.AccountAddress> {
|
|
198
|
+
return this._resolveAccount(onAccount).address();
|
|
191
199
|
}
|
|
192
200
|
|
|
193
|
-
async sign
|
|
194
|
-
data: string | Uint8Array,
|
|
201
|
+
async sign(
|
|
202
|
+
data: string | Uint8Array,
|
|
203
|
+
{ onAccount, ...options }: { onAccount?: Account } = {},
|
|
195
204
|
): Promise<Uint8Array> {
|
|
196
|
-
return
|
|
205
|
+
return this._resolveAccount(onAccount).sign(data, options);
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
async signTransaction
|
|
200
|
-
tx:
|
|
201
|
-
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signTransaction']>[1] = {}
|
|
202
|
-
): Promise<
|
|
203
|
-
return
|
|
204
|
-
.signTransaction(tx, { ...options, networkId: await this.getNetworkId(options) })
|
|
208
|
+
async signTransaction(
|
|
209
|
+
tx: Encoded.Transaction,
|
|
210
|
+
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signTransaction']>[1] = {},
|
|
211
|
+
): Promise<Encoded.Transaction> {
|
|
212
|
+
return this._resolveAccount(onAccount)
|
|
213
|
+
.signTransaction(tx, { ...options, networkId: await this.getNetworkId(options) });
|
|
205
214
|
}
|
|
206
215
|
|
|
207
|
-
async signMessage
|
|
216
|
+
async signMessage(
|
|
208
217
|
message: string,
|
|
209
|
-
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signMessage']>[1] = {}
|
|
218
|
+
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signMessage']>[1] = {},
|
|
210
219
|
): Promise<string | Uint8Array> {
|
|
211
|
-
return
|
|
220
|
+
return this._resolveAccount(onAccount).signMessage(message, options);
|
|
212
221
|
}
|
|
213
222
|
|
|
214
|
-
async verifyMessage
|
|
223
|
+
async verifyMessage(
|
|
215
224
|
message: string,
|
|
216
225
|
signature: string | Uint8Array,
|
|
217
|
-
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['verifyMessage']>[2] = {}
|
|
226
|
+
{ onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['verifyMessage']>[2] = {},
|
|
218
227
|
): Promise<boolean> {
|
|
219
|
-
return
|
|
228
|
+
return this._resolveAccount(onAccount).verifyMessage(message, signature, options);
|
|
220
229
|
}
|
|
221
230
|
|
|
222
231
|
/**
|
|
223
232
|
* Resolves an account
|
|
224
233
|
* @param account - ak-address, instance of AccountBase, or keypair
|
|
225
234
|
*/
|
|
226
|
-
|
|
235
|
+
// eslint-disable-next-line class-methods-use-this
|
|
236
|
+
_resolveAccount(account?: Account): AccountBase {
|
|
227
237
|
switch (account !== null && typeof account) {
|
|
228
238
|
case 'string':
|
|
229
|
-
throw new NotImplementedError('Address in AccountResolver')
|
|
239
|
+
throw new NotImplementedError('Address in AccountResolver');
|
|
230
240
|
case 'object':
|
|
231
|
-
return isAccountBase(account) ? account : new MemoryAccount({ keypair: account })
|
|
241
|
+
return isAccountBase(account) ? account : new MemoryAccount({ keypair: account });
|
|
232
242
|
default:
|
|
233
243
|
throw new TypeError(
|
|
234
|
-
'Account should be an address (ak-prefixed string), '
|
|
235
|
-
`keypair, or instance of AccountBase, got ${String(account)} instead
|
|
244
|
+
'Account should be an address (ak-prefixed string), '
|
|
245
|
+
+ `keypair, or instance of AccountBase, got ${String(account)} instead`,
|
|
246
|
+
);
|
|
236
247
|
}
|
|
237
248
|
}
|
|
238
249
|
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
_getOptions(): {
|
|
251
|
+
onNode: Node;
|
|
252
|
+
onAccount: AccountBase;
|
|
253
|
+
onCompiler: Compiler;
|
|
254
|
+
} {
|
|
241
255
|
return {
|
|
242
256
|
...this._options,
|
|
243
257
|
onNode: getValueOrErrorProxy(() => this.api),
|
|
244
258
|
onAccount: getValueOrErrorProxy(() => this._resolveAccount()),
|
|
245
259
|
onCompiler: getValueOrErrorProxy(() => this.compilerApi),
|
|
246
|
-
|
|
247
|
-
networkId: (await this.api?.getStatus()).networkId
|
|
248
|
-
}
|
|
260
|
+
};
|
|
249
261
|
}
|
|
250
262
|
|
|
251
|
-
async buildTx<TxType extends
|
|
263
|
+
async buildTx<TxType extends Tag>(
|
|
252
264
|
txType: TxType,
|
|
253
|
-
options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & { onNode?: Node }
|
|
254
|
-
): Promise<
|
|
255
|
-
// @ts-expect-error
|
|
256
|
-
return
|
|
257
|
-
...
|
|
258
|
-
...options
|
|
259
|
-
})
|
|
265
|
+
options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & { onNode?: Node },
|
|
266
|
+
): Promise<Encoded.Transaction> {
|
|
267
|
+
// @ts-expect-error TODO: need to figure out what's wrong here
|
|
268
|
+
return _buildTx<TxType>(txType, {
|
|
269
|
+
...this._getOptions(),
|
|
270
|
+
...options,
|
|
271
|
+
});
|
|
260
272
|
}
|
|
261
273
|
}
|
|
262
274
|
|
|
263
|
-
const { _buildTx: _, ...txMethodsOther } = txMethods
|
|
275
|
+
const { _buildTx: _, ...txMethodsOther } = txMethods;
|
|
276
|
+
const { InvalidTxError: _2, ...chainMethodsOther } = chainMethods;
|
|
264
277
|
|
|
265
278
|
const methods = {
|
|
266
|
-
...
|
|
279
|
+
...chainMethodsOther,
|
|
267
280
|
...txMethodsOther,
|
|
268
281
|
...aensMethods,
|
|
269
282
|
...spendMethods,
|
|
270
283
|
...oracleMethods,
|
|
271
284
|
...contractMethods,
|
|
272
|
-
...contractGaMethods
|
|
273
|
-
|
|
285
|
+
...contractGaMethods,
|
|
286
|
+
...deprecatedMethods,
|
|
287
|
+
} as const;
|
|
274
288
|
|
|
275
289
|
type RequiredKeys<T> = {
|
|
276
290
|
[K in keyof T]-?: {} extends Pick<T, K> ? never : K
|
|
277
|
-
}[keyof T]
|
|
291
|
+
}[keyof T];
|
|
278
292
|
|
|
279
|
-
type OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T
|
|
293
|
+
type OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T;
|
|
280
294
|
|
|
281
295
|
type MakeOptional<Args extends any[]> = Args extends [infer Head, ...infer Tail]
|
|
282
296
|
? Tail extends []
|
|
283
297
|
? Head extends object
|
|
284
298
|
? OptionalIfNotRequired<[Omit<Head, 'onNode' | 'onCompiler' | 'onAccount'>
|
|
285
|
-
& {
|
|
299
|
+
& {
|
|
300
|
+
onNode?: Node;
|
|
301
|
+
onCompiler?: Compiler;
|
|
302
|
+
onAccount?: AccountBase | Encoded.AccountAddress | Keypair;
|
|
303
|
+
}]>
|
|
286
304
|
: [Head]
|
|
287
305
|
: [Head, ...MakeOptional<Tail>]
|
|
288
|
-
: never
|
|
306
|
+
: never;
|
|
289
307
|
|
|
290
308
|
type TransformMethods <Methods extends { [key: string]: Function }> =
|
|
291
309
|
{
|
|
@@ -293,7 +311,7 @@ type TransformMethods <Methods extends { [key: string]: Function }> =
|
|
|
293
311
|
Methods[Name] extends (...args: infer Args) => infer Ret
|
|
294
312
|
? (...args: MakeOptional<Args>) => Ret
|
|
295
313
|
: never
|
|
296
|
-
}
|
|
314
|
+
};
|
|
297
315
|
|
|
298
316
|
interface AeSdkBaseMethods extends TransformMethods<typeof methods> {}
|
|
299
317
|
|
|
@@ -301,20 +319,20 @@ Object.assign(AeSdkBase.prototype, mapObject<Function, Function>(
|
|
|
301
319
|
methods,
|
|
302
320
|
([name, handler]) => [
|
|
303
321
|
name,
|
|
304
|
-
|
|
305
|
-
const instanceOptions =
|
|
306
|
-
const lastArg = args[args.length - 1]
|
|
322
|
+
function methodWrapper(...args: any[]) {
|
|
323
|
+
const instanceOptions = this._getOptions();
|
|
324
|
+
const lastArg = args[args.length - 1];
|
|
307
325
|
if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
|
|
308
|
-
|
|
326
|
+
args[args.length - 1] = {
|
|
309
327
|
...instanceOptions,
|
|
310
328
|
...lastArg,
|
|
311
|
-
...lastArg.onAccount != null && { onAccount: this._resolveAccount(lastArg.onAccount) }
|
|
312
|
-
}
|
|
313
|
-
} else args.push(instanceOptions)
|
|
314
|
-
return handler(...args)
|
|
315
|
-
}
|
|
316
|
-
]
|
|
317
|
-
))
|
|
318
|
-
|
|
319
|
-
export default AeSdkBase as new (options
|
|
320
|
-
AeSdkBase & AeSdkBaseMethods
|
|
329
|
+
...lastArg.onAccount != null && { onAccount: this._resolveAccount(lastArg.onAccount) },
|
|
330
|
+
};
|
|
331
|
+
} else args.push(instanceOptions);
|
|
332
|
+
return handler(...args);
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
));
|
|
336
|
+
|
|
337
|
+
export default AeSdkBase as new (options?: ConstructorParameters<typeof AeSdkBase>[0]) =>
|
|
338
|
+
AeSdkBase & AeSdkBaseMethods;
|