@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/es/AeSdk.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import AeSdkBase, { Account } from './AeSdkBase';
|
|
2
2
|
import AccountBase from './account/Base';
|
|
3
|
-
import {
|
|
3
|
+
import { Encoded } from './utils/encoder';
|
|
4
4
|
export default class AeSdk extends AeSdkBase {
|
|
5
5
|
accounts: {
|
|
6
|
-
[key:
|
|
6
|
+
[key: Encoded.AccountAddress]: AccountBase;
|
|
7
7
|
};
|
|
8
|
-
selectedAddress?:
|
|
9
|
-
_resolveAccount(account?: Account |
|
|
8
|
+
selectedAddress?: Encoded.AccountAddress;
|
|
9
|
+
_resolveAccount(account?: Account | Encoded.AccountAddress): AccountBase;
|
|
10
10
|
/**
|
|
11
11
|
* Get accounts addresses
|
|
12
12
|
* @example addresses()
|
|
13
13
|
*/
|
|
14
|
-
addresses():
|
|
14
|
+
addresses(): Encoded.AccountAddress[];
|
|
15
15
|
/**
|
|
16
16
|
* Add specific account
|
|
17
17
|
* @param account - Account instance
|
|
@@ -27,11 +27,11 @@ export default class AeSdk extends AeSdkBase {
|
|
|
27
27
|
* @param address - Address of account to remove
|
|
28
28
|
* @example removeAccount(address)
|
|
29
29
|
*/
|
|
30
|
-
removeAccount(address:
|
|
30
|
+
removeAccount(address: Encoded.AccountAddress): void;
|
|
31
31
|
/**
|
|
32
32
|
* Select specific account
|
|
33
33
|
* @param address - Address of account to select
|
|
34
34
|
* @example selectAccount('ak_xxxxxxxx')
|
|
35
35
|
*/
|
|
36
|
-
selectAccount(address:
|
|
36
|
+
selectAccount(address: Encoded.AccountAddress): void;
|
|
37
37
|
}
|
package/es/AeSdk.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdk.mjs","names":["AeSdkBase","decode","UnavailableAccountError","AeSdk","_resolveAccount","account","selectedAddress","address","accounts","addresses","Object","keys","addAccount","select","selectAccount","removeAccount","console","warn"],"sources":["../src/AeSdk.ts"],"sourcesContent":["import AeSdkBase, { Account } from './AeSdkBase'
|
|
1
|
+
{"version":3,"file":"AeSdk.mjs","names":["AeSdkBase","decode","UnavailableAccountError","AeSdk","_resolveAccount","account","selectedAddress","address","accounts","addresses","Object","keys","addAccount","select","selectAccount","removeAccount","console","warn"],"sources":["../src/AeSdk.ts"],"sourcesContent":["import AeSdkBase, { Account } from './AeSdkBase';\nimport AccountBase from './account/Base';\nimport { decode, Encoded } from './utils/encoder';\nimport { UnavailableAccountError } from './utils/errors';\n\nexport default class AeSdk extends AeSdkBase {\n accounts: { [key: Encoded.AccountAddress]: AccountBase } = {};\n\n selectedAddress?: Encoded.AccountAddress;\n\n _resolveAccount(\n account: Account | Encoded.AccountAddress = this.selectedAddress,\n ): AccountBase {\n if (typeof account === 'string') {\n const address = account as Encoded.AccountAddress;\n decode(address);\n if (this.accounts[address] == null) throw new UnavailableAccountError(account);\n account = this.accounts[address];\n }\n return super._resolveAccount(account);\n }\n\n /**\n * Get accounts addresses\n * @example addresses()\n */\n addresses(): Encoded.AccountAddress[] {\n return Object.keys(this.accounts) as Encoded.AccountAddress[];\n }\n\n /**\n * Add specific account\n * @param account - Account instance\n * @param options - Options\n * @param options.select - Select account\n * @example addAccount(account)\n */\n async addAccount(account: AccountBase, { select }: { select?: boolean } = {}): Promise<void> {\n const address = await account.address();\n this.accounts[address] = account;\n if (select === true) this.selectAccount(address);\n }\n\n /**\n * Remove specific account\n * @param address - Address of account to remove\n * @example removeAccount(address)\n */\n removeAccount(address: Encoded.AccountAddress): void {\n if (this.accounts[address] == null) {\n console.warn(`removeAccount: Account for ${address} not available`);\n return;\n }\n delete this.accounts[address]; // eslint-disable-line @typescript-eslint/no-dynamic-delete\n if (this.selectedAddress === address) delete this.selectedAddress;\n }\n\n /**\n * Select specific account\n * @param address - Address of account to select\n * @example selectAccount('ak_xxxxxxxx')\n */\n selectAccount(address: Encoded.AccountAddress): void {\n decode(address);\n if (this.accounts[address] == null) throw new UnavailableAccountError(address);\n this.selectedAddress = address;\n }\n}\n"],"mappings":";OAAOA,S;SAEEC,M;SACAC,uB;AAET,eAAe,MAAMC,KAAN,SAAoBH,SAApB,CAA8B;EAAA;IAAA;;IAAA,kCACgB,EADhB;EAAA;;EAK3CI,eAAe,GAEA;IAAA,IADb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M,IAAIL,uBAAJ,CAA4BK,OAA5B,CAAN;IACpC,KAAKD,eAAL,GAAuBC,OAAvB;EACD;;AA7D0C"}
|
package/es/AeSdkAepp.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AeSdkBase, { Account } from './AeSdkBase';
|
|
2
2
|
import AccountBase from './account/Base';
|
|
3
|
-
import {
|
|
3
|
+
import { Encoded } from './utils/encoder';
|
|
4
4
|
import { Accounts, WalletInfo, Network, WalletApi, AeppApi } from './aepp-wallet-communication/rpc/types';
|
|
5
5
|
import RpcClient from './aepp-wallet-communication/rpc/RpcClient';
|
|
6
6
|
import { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema';
|
|
@@ -8,6 +8,7 @@ import BrowserConnection from './aepp-wallet-communication/connection/Browser';
|
|
|
8
8
|
/**
|
|
9
9
|
* RPC handler for AEPP side
|
|
10
10
|
* Contain functionality for wallet interaction and connect it to sdk
|
|
11
|
+
* @category aepp wallet communication
|
|
11
12
|
*/
|
|
12
13
|
export default class AeSdkAepp extends AeSdkBase {
|
|
13
14
|
name: string;
|
|
@@ -30,7 +31,7 @@ export default class AeSdkAepp extends AeSdkBase {
|
|
|
30
31
|
onNetworkChange: (a: Network) => void;
|
|
31
32
|
} & ConstructorParameters<typeof AeSdkBase>[0]);
|
|
32
33
|
_resolveAccount(account?: Account): AccountBase;
|
|
33
|
-
addresses():
|
|
34
|
+
addresses(): Encoded.AccountAddress[];
|
|
34
35
|
/**
|
|
35
36
|
* Connect to wallet
|
|
36
37
|
* @param connection - Wallet connection object
|
|
@@ -52,7 +53,7 @@ export default class AeSdkAepp extends AeSdkBase {
|
|
|
52
53
|
* Ask addresses from wallet
|
|
53
54
|
* @returns Addresses from wallet
|
|
54
55
|
*/
|
|
55
|
-
askAddresses(): Promise<
|
|
56
|
+
askAddresses(): Promise<Encoded.AccountAddress[]>;
|
|
56
57
|
/**
|
|
57
58
|
* Subscribe for addresses from wallet
|
|
58
59
|
* @param type - Subscription type
|
package/es/AeSdkAepp.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import Node from "./Node.mjs";
|
|
|
11
11
|
/**
|
|
12
12
|
* RPC handler for AEPP side
|
|
13
13
|
* Contain functionality for wallet interaction and connect it to sdk
|
|
14
|
+
* @category aepp wallet communication
|
|
14
15
|
*/
|
|
15
16
|
export default class AeSdkAepp extends AeSdkBase {
|
|
16
17
|
/**
|
|
@@ -138,7 +139,7 @@ export default class AeSdkAepp extends AeSdkBase {
|
|
|
138
139
|
async askAddresses() {
|
|
139
140
|
this._ensureAccountAccess();
|
|
140
141
|
|
|
141
|
-
return
|
|
142
|
+
return this.rpcClient.request(METHODS.address, undefined);
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* Subscribe for addresses from wallet
|
package/es/AeSdkAepp.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkAepp.mjs","names":["AeSdkBase","AccountRpc","decode","RPC_VERSION","RpcClient","METHODS","AlreadyConnectedError","NoWalletConnectedError","UnsubscribedAccountError","UnAuthorizedAccountError","RpcConnectionError","Node","AeSdkAepp","constructor","name","onAddressChange","onDisconnect","onNetworkChange","other","_resolveAccount","account","addresses","address","rpcClient","_ensureAccountAccess","_accounts","current","Object","keys","connected","connectToWallet","connection","connectNode","select","disconnectParams","client","updateAddress","params","updateNetwork","node","addNode","url","closeConnection","disconnect","readyToConnect","walletInfo","request","connect","version","disconnectWallet","_ensureConnected","notify","reason","askAddresses","undefined","subscribeAddress","type","value","result","length"],"sources":["../src/AeSdkAepp.ts"],"sourcesContent":["import AeSdkBase, { Account } from './AeSdkBase'\nimport AccountBase from './account/Base'\nimport AccountRpc from './account/Rpc'\nimport { decode, EncodedData } from './utils/encoder'\nimport { Accounts, RPC_VERSION, WalletInfo, Network, WalletApi, AeppApi } from './aepp-wallet-communication/rpc/types'\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient'\nimport { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema'\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n UnsubscribedAccountError,\n UnAuthorizedAccountError,\n RpcConnectionError\n} from './utils/errors'\nimport Node from './Node'\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser'\n\n/**\n * RPC handler for AEPP side\n * Contain functionality for wallet interaction and connect it to sdk\n */\nexport default class AeSdkAepp extends AeSdkBase {\n name: string\n onAddressChange: (a: Accounts) => void\n onDisconnect: (p: any) => void\n onNetworkChange: (a: Network) => void\n rpcClient?: RpcClient<WalletApi, AeppApi>\n _accounts?: Accounts\n\n /**\n * @param options - Options\n * @param options.name - Aepp name\n * @param options.onAddressChange - Call-back function for update address event\n * @param options.onDisconnect - Call-back function for disconnect event\n * @param options.onNetworkChange - Call-back function for update network event\n */\n constructor ({\n name,\n onAddressChange = () => {},\n onDisconnect = () => {},\n onNetworkChange = () => {},\n ...other\n }: {\n name: string\n onAddressChange: (a: Accounts) => void\n onDisconnect: (p: any) => void\n onNetworkChange: (a: Network) => void\n } & ConstructorParameters<typeof AeSdkBase>[0]) {\n super(other)\n this.onAddressChange = onAddressChange\n this.onDisconnect = onDisconnect\n this.onNetworkChange = onNetworkChange\n this.name = name\n }\n\n _resolveAccount (account: Account = this.addresses()[0]): AccountBase {\n if (typeof account === 'string') {\n const address = account as EncodedData<'ak'>\n decode(address)\n if (!this.addresses().includes(address)) throw new UnAuthorizedAccountError(address)\n account = new AccountRpc({ rpcClient: this.rpcClient, address })\n }\n if (account == null) this._ensureAccountAccess()\n return super._resolveAccount(account)\n }\n\n addresses (): Array<EncodedData<'ak'>> {\n if (this._accounts == null) return []\n const current = Object.keys(this._accounts.current)[0]\n return [\n ...current != null ? [current] : [], ...Object.keys(this._accounts.connected)\n ] as Array<EncodedData<'ak'>>\n }\n\n /**\n * Connect to wallet\n * @param connection - Wallet connection object\n * @param options - Options\n * @param options.connectNode - Request wallet to bind node\n * @param options.name - Node name\n * @param options.select - Select this node as current\n */\n async connectToWallet (\n connection: BrowserConnection,\n { connectNode = false, name = 'wallet-node', select = false }:\n { connectNode?: boolean, name?: string, select?: boolean } = {}\n ): Promise<WalletInfo> {\n if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet')\n let disconnectParams: any\n const client = new RpcClient<WalletApi, AeppApi>(\n connection,\n () => {\n delete this.rpcClient\n delete this._accounts\n this.onDisconnect(disconnectParams)\n }, {\n [METHODS.updateAddress]: (params) => {\n this._accounts = params\n this.onAddressChange(params)\n },\n [METHODS.updateNetwork]: (params) => {\n const { node } = params\n if (node != null) this.addNode(node.name, new Node(node.url), true)\n this.onNetworkChange(params)\n },\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params\n client.connection.disconnect()\n },\n [METHODS.readyToConnect]: () => {}\n }\n )\n const { node, ...walletInfo } = await client.request(\n METHODS.connect, { name: this.name, version: RPC_VERSION, connectNode }\n )\n if (connectNode) {\n if (node == null) throw new RpcConnectionError('Missing URLs of the Node')\n this.addNode(name, new Node(node.url), select)\n }\n this.rpcClient = client\n return walletInfo\n }\n\n /**\n * Disconnect from wallet\n */\n disconnectWallet (): void {\n this._ensureConnected()\n this.rpcClient.notify(METHODS.closeConnection, { reason: 'bye' })\n this.rpcClient.connection.disconnect()\n }\n\n /**\n * Ask addresses from wallet\n * @returns Addresses from wallet\n */\n async askAddresses (): Promise<Array<EncodedData<'ak'>>> {\n this._ensureAccountAccess()\n return await this.rpcClient.request(METHODS.address, undefined)\n }\n\n /**\n * Subscribe for addresses from wallet\n * @param type - Subscription type\n * @param value - Should be one of 'current' (the selected account), 'connected' (all)\n * @returns Accounts from wallet\n */\n async subscribeAddress (\n type: SUBSCRIPTION_TYPES, value: 'current' | 'connected'\n ): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>> {\n this._ensureConnected()\n const result = await this.rpcClient.request(METHODS.subscribeAddress, { type, value })\n this._accounts = result.address\n return result\n }\n\n _ensureConnected (): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n if (this.rpcClient != null) return\n throw new NoWalletConnectedError('You are not connected to Wallet')\n }\n\n _ensureAccountAccess (): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n this._ensureConnected()\n if (this.addresses().length !== 0) return\n throw new UnsubscribedAccountError()\n }\n}\n"],"mappings":";OAAOA,S;OAEAC,U;SACEC,M;SACUC,W;OACZC,S;SACEC,O;SAEPC,qB,EACAC,sB,EACAC,wB,EACAC,wB,EACAC,kB;OAEKC,I;;AAGP;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAN,SAAwBZ,SAAxB,CAAkC;EAQ/C;AACF;AACA;AACA;AACA;AACA;AACA;EACEa,WAAW,OAWqC;IAAA,IAXnC;MACXC,IADW;MAEXC,eAAe,GAAG,MAAM,CAAE,CAFf;MAGXC,YAAY,GAAG,MAAM,CAAE,CAHZ;MAIXC,eAAe,GAAG,MAAM,CAAE,CAJf;MAKX,GAAGC;IALQ,CAWmC;IAC9C,MAAMA,KAAN;IACA,KAAKH,eAAL,GAAuBA,eAAvB;IACA,KAAKC,YAAL,GAAoBA,YAApB;IACA,KAAKC,eAAL,GAAuBA,eAAvB;IACA,KAAKH,IAAL,GAAYA,IAAZ;EACD;;EAEDK,eAAe,GAAuD;IAAA,IAArDC,OAAqD,uEAAlC,KAAKC,SAAL,GAAiB,CAAjB,CAAkC;;IACpE,IAAI,OAAOD,OAAP,KAAmB,QAAvB,EAAiC;MAAA;;MAC/B,MAAME,OAAO,GAAGF,OAAhB;MACAlB,MAAM,CAACoB,OAAD,CAAN;MACA,IAAI,CAAC,0CAAKD,SAAL,mBAA0BC,OAA1B,CAAL,EAAyC,MAAM,IAAIb,wBAAJ,CAA6Ba,OAA7B,CAAN;MACzCF,OAAO,GAAG,IAAInB,UAAJ,CAAe;QAAEsB,SAAS,EAAE,KAAKA,SAAlB;QAA6BD;MAA7B,CAAf,CAAV;IACD;;IACD,IAAIF,OAAO,IAAI,IAAf,EAAqB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C,IADoB,EACMC,KADN,EAEsC;IAC1D,KAAKP,gBAAL;;IACA,MAAMQ,MAAM,GAAG,MAAM,KAAKnC,SAAL,CAAeuB,OAAf,CAAuBzC,OAAO,CAACkD,gBAA/B,EAAiD;MAAEC,IAAF;MAAQC;IAAR,CAAjD,CAArB;IACA,KAAKhC,SAAL,GAAiBiC,MAAM,CAACpC,OAAxB;IACA,OAAOoC,MAAP;EACD;;EAEDR,gBAAgB,GAAoF;IAClG,IAAI,KAAK3B,SAAL,IAAkB,IAAtB,EAA4B;IAC5B,MAAM,IAAIhB,sBAAJ,CAA2B,iCAA3B,CAAN;EACD;;EAEDiB,oBAAoB,GAAoF;IACtG,KAAK0B,gBAAL;;IACA,IAAI,KAAK7B,SAAL,GAAiBsC,MAAjB,KAA4B,CAAhC,EAAmC;IACnC,MAAM,IAAInD,wBAAJ,EAAN;EACD;;AAhJ8C"}
|
|
1
|
+
{"version":3,"file":"AeSdkAepp.mjs","names":["AeSdkBase","AccountRpc","decode","RPC_VERSION","RpcClient","METHODS","AlreadyConnectedError","NoWalletConnectedError","UnsubscribedAccountError","UnAuthorizedAccountError","RpcConnectionError","Node","AeSdkAepp","constructor","name","onAddressChange","onDisconnect","onNetworkChange","other","_resolveAccount","account","addresses","address","rpcClient","_ensureAccountAccess","_accounts","current","Object","keys","connected","connectToWallet","connection","connectNode","select","disconnectParams","client","updateAddress","params","updateNetwork","node","addNode","url","closeConnection","disconnect","readyToConnect","walletInfo","request","connect","version","disconnectWallet","_ensureConnected","notify","reason","askAddresses","undefined","subscribeAddress","type","value","result","length"],"sources":["../src/AeSdkAepp.ts"],"sourcesContent":["import AeSdkBase, { Account } from './AeSdkBase';\nimport AccountBase from './account/Base';\nimport AccountRpc from './account/Rpc';\nimport { decode, Encoded } from './utils/encoder';\nimport {\n Accounts, RPC_VERSION, WalletInfo, Network, WalletApi, AeppApi,\n} from './aepp-wallet-communication/rpc/types';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema';\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n UnsubscribedAccountError,\n UnAuthorizedAccountError,\n RpcConnectionError,\n} from './utils/errors';\nimport Node from './Node';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\n\n/**\n * RPC handler for AEPP side\n * Contain functionality for wallet interaction and connect it to sdk\n * @category aepp wallet communication\n */\nexport default class AeSdkAepp extends AeSdkBase {\n name: string;\n\n onAddressChange: (a: Accounts) => void;\n\n onDisconnect: (p: any) => void;\n\n onNetworkChange: (a: Network) => void;\n\n rpcClient?: RpcClient<WalletApi, AeppApi>;\n\n _accounts?: Accounts;\n\n /**\n * @param options - Options\n * @param options.name - Aepp name\n * @param options.onAddressChange - Call-back function for update address event\n * @param options.onDisconnect - Call-back function for disconnect event\n * @param options.onNetworkChange - Call-back function for update network event\n */\n constructor({\n name,\n onAddressChange = () => {},\n onDisconnect = () => {},\n onNetworkChange = () => {},\n ...other\n }: {\n name: string;\n onAddressChange: (a: Accounts) => void;\n onDisconnect: (p: any) => void;\n onNetworkChange: (a: Network) => void;\n } & ConstructorParameters<typeof AeSdkBase>[0]) {\n super(other);\n this.onAddressChange = onAddressChange;\n this.onDisconnect = onDisconnect;\n this.onNetworkChange = onNetworkChange;\n this.name = name;\n }\n\n _resolveAccount(account: Account = this.addresses()[0]): AccountBase {\n if (typeof account === 'string') {\n const address = account as Encoded.AccountAddress;\n decode(address);\n if (!this.addresses().includes(address)) throw new UnAuthorizedAccountError(address);\n account = new AccountRpc({ rpcClient: this.rpcClient, address });\n }\n if (account == null) this._ensureAccountAccess();\n return super._resolveAccount(account);\n }\n\n addresses(): Encoded.AccountAddress[] {\n if (this._accounts == null) return [];\n const current = Object.keys(this._accounts.current)[0];\n return [\n ...current != null ? [current] : [], ...Object.keys(this._accounts.connected),\n ] as Encoded.AccountAddress[];\n }\n\n /**\n * Connect to wallet\n * @param connection - Wallet connection object\n * @param options - Options\n * @param options.connectNode - Request wallet to bind node\n * @param options.name - Node name\n * @param options.select - Select this node as current\n */\n async connectToWallet(\n connection: BrowserConnection,\n { connectNode = false, name = 'wallet-node', select = false }:\n { connectNode?: boolean; name?: string; select?: boolean } = {},\n ): Promise<WalletInfo> {\n if (this.rpcClient != null) throw new AlreadyConnectedError('You are already connected to wallet');\n let disconnectParams: any;\n const client = new RpcClient<WalletApi, AeppApi>(\n connection,\n () => {\n delete this.rpcClient;\n delete this._accounts;\n this.onDisconnect(disconnectParams);\n },\n {\n [METHODS.updateAddress]: (params) => {\n this._accounts = params;\n this.onAddressChange(params);\n },\n [METHODS.updateNetwork]: (params) => {\n const { node } = params;\n if (node != null) this.addNode(node.name, new Node(node.url), true);\n this.onNetworkChange(params);\n },\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n client.connection.disconnect();\n },\n [METHODS.readyToConnect]: () => {},\n },\n );\n const { node, ...walletInfo } = await client\n .request(METHODS.connect, { name: this.name, version: RPC_VERSION, connectNode });\n if (connectNode) {\n if (node == null) throw new RpcConnectionError('Missing URLs of the Node');\n this.addNode(name, new Node(node.url), select);\n }\n this.rpcClient = client;\n return walletInfo;\n }\n\n /**\n * Disconnect from wallet\n */\n disconnectWallet(): void {\n this._ensureConnected();\n this.rpcClient.notify(METHODS.closeConnection, { reason: 'bye' });\n this.rpcClient.connection.disconnect();\n }\n\n /**\n * Ask addresses from wallet\n * @returns Addresses from wallet\n */\n async askAddresses(): Promise<Encoded.AccountAddress[]> {\n this._ensureAccountAccess();\n return this.rpcClient.request(METHODS.address, undefined);\n }\n\n /**\n * Subscribe for addresses from wallet\n * @param type - Subscription type\n * @param value - Should be one of 'current' (the selected account), 'connected' (all)\n * @returns Accounts from wallet\n */\n async subscribeAddress(\n type: SUBSCRIPTION_TYPES,\n value: 'current' | 'connected',\n ): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>> {\n this._ensureConnected();\n const result = await this.rpcClient.request(METHODS.subscribeAddress, { type, value });\n this._accounts = result.address;\n return result;\n }\n\n _ensureConnected(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n if (this.rpcClient != null) return;\n throw new NoWalletConnectedError('You are not connected to Wallet');\n }\n\n _ensureAccountAccess(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']> } {\n this._ensureConnected();\n if (this.addresses().length !== 0) return;\n throw new UnsubscribedAccountError();\n }\n}\n"],"mappings":";OAAOA,S;OAEAC,U;SACEC,M;SAEGC,W;OAELC,S;SACEC,O;SAEPC,qB,EACAC,sB,EACAC,wB,EACAC,wB,EACAC,kB;OAEKC,I;;AAGP;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,SAAN,SAAwBZ,SAAxB,CAAkC;EAa/C;AACF;AACA;AACA;AACA;AACA;AACA;EACEa,WAAW,OAWqC;IAAA,IAXpC;MACVC,IADU;MAEVC,eAAe,GAAG,MAAM,CAAE,CAFhB;MAGVC,YAAY,GAAG,MAAM,CAAE,CAHb;MAIVC,eAAe,GAAG,MAAM,CAAE,CAJhB;MAKV,GAAGC;IALO,CAWoC;IAC9C,MAAMA,KAAN;IACA,KAAKH,eAAL,GAAuBA,eAAvB;IACA,KAAKC,YAAL,GAAoBA,YAApB;IACA,KAAKC,eAAL,GAAuBA,eAAvB;IACA,KAAKH,IAAL,GAAYA,IAAZ;EACD;;EAEDK,eAAe,GAAsD;IAAA,IAArDC,OAAqD,uEAAlC,KAAKC,SAAL,GAAiB,CAAjB,CAAkC;;IACnE,IAAI,OAAOD,OAAP,KAAmB,QAAvB,EAAiC;MAAA;;MAC/B,MAAME,OAAO,GAAGF,OAAhB;MACAlB,MAAM,CAACoB,OAAD,CAAN;MACA,IAAI,CAAC,0CAAKD,SAAL,mBAA0BC,OAA1B,CAAL,EAAyC,MAAM,IAAIb,wBAAJ,CAA6Ba,OAA7B,CAAN;MACzCF,OAAO,GAAG,IAAInB,UAAJ,CAAe;QAAEsB,SAAS,EAAE,KAAKA,S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CAAP;EACD;EAED;AACF;AACA;AACA;AACA;AACA;;;EACwB,MAAhBC,gBAAgB,CACpBC,IADoB,EAEpBC,KAFoB,EAGsC;IAC1D,KAAKP,gBAAL;;IACA,MAAMQ,MAAM,GAAG,MAAM,KAAKnC,SAAL,CAAeuB,OAAf,CAAuBzC,OAAO,CAACkD,gBAA/B,EAAiD;MAAEC,IAAF;MAAQC;IAAR,CAAjD,CAArB;IACA,KAAKhC,SAAL,GAAiBiC,MAAM,CAACpC,OAAxB;IACA,OAAOoC,MAAP;EACD;;EAEDR,gBAAgB,GAAmF;IACjG,IAAI,KAAK3B,SAAL,IAAkB,IAAtB,EAA4B;IAC5B,MAAM,IAAIhB,sBAAJ,CAA2B,iCAA3B,CAAN;EACD;;EAEDiB,oBAAoB,GAAmF;IACrG,KAAK0B,gBAAL;;IACA,IAAI,KAAK7B,SAAL,GAAiBsC,MAAjB,KAA4B,CAAhC,EAAmC;IACnC,MAAM,IAAInD,wBAAJ,EAAN;EACD;;AAtJ8C"}
|
package/es/AeSdkBase.d.ts
CHANGED
|
@@ -5,13 +5,14 @@ import * as spendMethods from './spend';
|
|
|
5
5
|
import * as oracleMethods from './oracle';
|
|
6
6
|
import * as contractMethods from './contract/methods';
|
|
7
7
|
import * as contractGaMethods from './contract/ga';
|
|
8
|
+
import * as deprecatedMethods from './deprecated/methods';
|
|
8
9
|
import { _buildTx } from './tx';
|
|
9
10
|
import Node, { getNetworkId } from './Node';
|
|
10
11
|
import { AE_AMOUNT_FORMATS } from './utils/amount-formatter';
|
|
11
|
-
import {
|
|
12
|
+
import { Tag } from './tx/builder/constants';
|
|
12
13
|
import { Keypair } from './account/Memory';
|
|
13
14
|
import AccountBase from './account/Base';
|
|
14
|
-
import {
|
|
15
|
+
import { Encoded } from './utils/encoder';
|
|
15
16
|
import Compiler from './contract/Compiler';
|
|
16
17
|
export declare type Account = Keypair | AccountBase | any;
|
|
17
18
|
declare type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & {
|
|
@@ -110,16 +111,16 @@ declare class AeSdkBase {
|
|
|
110
111
|
* nodePool.getNodesInPool()
|
|
111
112
|
*/
|
|
112
113
|
getNodesInPool(): Promise<NodeInfo[]>;
|
|
113
|
-
addresses():
|
|
114
|
+
addresses(): Encoded.AccountAddress[];
|
|
114
115
|
address({ onAccount }?: {
|
|
115
116
|
onAccount?: Account;
|
|
116
|
-
}): Promise<
|
|
117
|
+
}): Promise<Encoded.AccountAddress>;
|
|
117
118
|
sign(data: string | Uint8Array, { onAccount, ...options }?: {
|
|
118
119
|
onAccount?: Account;
|
|
119
120
|
}): Promise<Uint8Array>;
|
|
120
|
-
signTransaction(tx:
|
|
121
|
+
signTransaction(tx: Encoded.Transaction, { onAccount, ...options }?: {
|
|
121
122
|
onAccount?: Account;
|
|
122
|
-
} & Parameters<AccountBase['signTransaction']>[1]): Promise<
|
|
123
|
+
} & Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
|
|
123
124
|
signMessage(message: string, { onAccount, ...options }?: {
|
|
124
125
|
onAccount?: Account;
|
|
125
126
|
} & Parameters<AccountBase['signMessage']>[1]): Promise<string | Uint8Array>;
|
|
@@ -131,17 +132,18 @@ declare class AeSdkBase {
|
|
|
131
132
|
* @param account - ak-address, instance of AccountBase, or keypair
|
|
132
133
|
*/
|
|
133
134
|
_resolveAccount(account?: Account): AccountBase;
|
|
134
|
-
_getOptions():
|
|
135
|
+
_getOptions(): {
|
|
135
136
|
onNode: Node;
|
|
136
137
|
onAccount: AccountBase;
|
|
137
138
|
onCompiler: Compiler;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
buildTx<TxType extends TX_TYPE>(txType: TxType, options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & {
|
|
139
|
+
};
|
|
140
|
+
buildTx<TxType extends Tag>(txType: TxType, options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & {
|
|
141
141
|
onNode?: Node;
|
|
142
|
-
}): Promise<
|
|
142
|
+
}): Promise<Encoded.Transaction>;
|
|
143
143
|
}
|
|
144
144
|
declare const methods: {
|
|
145
|
+
readonly signUsingGA: typeof deprecatedMethods.signUsingGA;
|
|
146
|
+
readonly height: typeof deprecatedMethods.height;
|
|
145
147
|
readonly isGA: typeof contractGaMethods.isGA;
|
|
146
148
|
readonly createGeneralizedAccount: typeof contractGaMethods.createGeneralizedAccount;
|
|
147
149
|
readonly createMetaTx: typeof contractGaMethods.createMetaTx;
|
|
@@ -149,16 +151,15 @@ declare const methods: {
|
|
|
149
151
|
readonly createAensDelegationSignature: typeof contractMethods.createAensDelegationSignature;
|
|
150
152
|
readonly createOracleDelegationSignature: typeof contractMethods.createOracleDelegationSignature;
|
|
151
153
|
readonly getContractInstance: typeof contractMethods.getContractInstance;
|
|
152
|
-
readonly getOracleObject: typeof oracleMethods.getOracleObject;
|
|
153
154
|
readonly pollForQueries: typeof oracleMethods.pollForQueries;
|
|
154
|
-
readonly getQueryObject: typeof oracleMethods.getQueryObject;
|
|
155
155
|
readonly pollForQueryResponse: typeof oracleMethods.pollForQueryResponse;
|
|
156
|
-
readonly
|
|
156
|
+
readonly getQueryObject: typeof oracleMethods.getQueryObject;
|
|
157
157
|
readonly postQueryToOracle: typeof oracleMethods.postQueryToOracle;
|
|
158
158
|
readonly extendOracleTtl: typeof oracleMethods.extendOracleTtl;
|
|
159
159
|
readonly respondToQuery: typeof oracleMethods.respondToQuery;
|
|
160
|
+
readonly getOracleObject: typeof oracleMethods.getOracleObject;
|
|
161
|
+
readonly registerOracle: typeof oracleMethods.registerOracle;
|
|
160
162
|
readonly send: typeof spendMethods.send;
|
|
161
|
-
readonly signUsingGA: typeof spendMethods.signUsingGA;
|
|
162
163
|
readonly spend: typeof spendMethods.spend;
|
|
163
164
|
readonly transferFunds: typeof spendMethods.transferFunds;
|
|
164
165
|
readonly payForTransaction: typeof spendMethods.payForTransaction;
|
|
@@ -172,13 +173,13 @@ declare const methods: {
|
|
|
172
173
|
readonly getVmVersion: typeof txMethods.getVmVersion;
|
|
173
174
|
readonly prepareTxParams: typeof txMethods.prepareTxParams;
|
|
174
175
|
readonly _getPollInterval: typeof chainMethods._getPollInterval;
|
|
175
|
-
readonly
|
|
176
|
+
readonly getHeight: typeof chainMethods.getHeight;
|
|
177
|
+
readonly poll: typeof chainMethods.poll;
|
|
178
|
+
readonly awaitHeight: typeof chainMethods.awaitHeight;
|
|
176
179
|
readonly waitForTxConfirm: typeof chainMethods.waitForTxConfirm;
|
|
180
|
+
readonly sendTransaction: typeof chainMethods.sendTransaction;
|
|
177
181
|
readonly getAccount: typeof chainMethods.getAccount;
|
|
178
182
|
readonly getBalance: typeof chainMethods.getBalance;
|
|
179
|
-
readonly height: typeof chainMethods.height;
|
|
180
|
-
readonly awaitHeight: typeof chainMethods.awaitHeight;
|
|
181
|
-
readonly poll: typeof chainMethods.poll;
|
|
182
183
|
readonly getCurrentGeneration: typeof chainMethods.getCurrentGeneration;
|
|
183
184
|
readonly getGeneration: typeof chainMethods.getGeneration;
|
|
184
185
|
readonly getMicroBlockTransactions: typeof chainMethods.getMicroBlockTransactions;
|
|
@@ -198,7 +199,7 @@ declare type MakeOptional<Args extends any[]> = Args extends [infer Head, ...inf
|
|
|
198
199
|
Omit<Head, 'onNode' | 'onCompiler' | 'onAccount'> & {
|
|
199
200
|
onNode?: Node;
|
|
200
201
|
onCompiler?: Compiler;
|
|
201
|
-
onAccount?: AccountBase |
|
|
202
|
+
onAccount?: AccountBase | Encoded.AccountAddress | Keypair;
|
|
202
203
|
}
|
|
203
204
|
]> : [Head] : [Head, ...MakeOptional<Tail>] : never;
|
|
204
205
|
declare type TransformMethods<Methods extends {
|
|
@@ -208,5 +209,5 @@ declare type TransformMethods<Methods extends {
|
|
|
208
209
|
};
|
|
209
210
|
interface AeSdkBaseMethods extends TransformMethods<typeof methods> {
|
|
210
211
|
}
|
|
211
|
-
declare const _default: new (options
|
|
212
|
+
declare const _default: new (options?: ConstructorParameters<typeof AeSdkBase>[0]) => AeSdkBase & AeSdkBaseMethods;
|
|
212
213
|
export default _default;
|
package/es/AeSdkBase.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import * as spendMethods from "./spend.mjs";
|
|
|
6
6
|
import * as oracleMethods from "./oracle.mjs";
|
|
7
7
|
import * as contractMethods from "./contract/methods.mjs";
|
|
8
8
|
import * as contractGaMethods from "./contract/ga.mjs";
|
|
9
|
+
import * as deprecatedMethods from "./deprecated/methods.mjs";
|
|
9
10
|
import { _buildTx } from "./tx/index.mjs";
|
|
10
11
|
import { mapObject } from "./utils/other.mjs";
|
|
11
12
|
import { getNetworkId } from "./Node.mjs";
|
|
@@ -176,14 +177,15 @@ class AeSdkBase {
|
|
|
176
177
|
|
|
177
178
|
|
|
178
179
|
async getNodesInPool() {
|
|
179
|
-
return
|
|
180
|
+
return Promise.all(Array.from(this.pool.entries()).map(async _ref2 => {
|
|
180
181
|
let [name, node] = _ref2;
|
|
181
182
|
return {
|
|
182
183
|
name,
|
|
183
184
|
...(await node.getNodeInfo())
|
|
184
185
|
};
|
|
185
186
|
}));
|
|
186
|
-
}
|
|
187
|
+
} // eslint-disable-next-line class-methods-use-this
|
|
188
|
+
|
|
187
189
|
|
|
188
190
|
addresses() {
|
|
189
191
|
return [];
|
|
@@ -193,7 +195,7 @@ class AeSdkBase {
|
|
|
193
195
|
let {
|
|
194
196
|
onAccount
|
|
195
197
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
196
|
-
return
|
|
198
|
+
return this._resolveAccount(onAccount).address();
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
async sign(data) {
|
|
@@ -201,7 +203,7 @@ class AeSdkBase {
|
|
|
201
203
|
onAccount,
|
|
202
204
|
...options
|
|
203
205
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
204
|
-
return
|
|
206
|
+
return this._resolveAccount(onAccount).sign(data, options);
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
async signTransaction(tx) {
|
|
@@ -209,7 +211,7 @@ class AeSdkBase {
|
|
|
209
211
|
onAccount,
|
|
210
212
|
...options
|
|
211
213
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
212
|
-
return
|
|
214
|
+
return this._resolveAccount(onAccount).signTransaction(tx, { ...options,
|
|
213
215
|
networkId: await this.getNetworkId(options)
|
|
214
216
|
});
|
|
215
217
|
}
|
|
@@ -219,7 +221,7 @@ class AeSdkBase {
|
|
|
219
221
|
onAccount,
|
|
220
222
|
...options
|
|
221
223
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
222
|
-
return
|
|
224
|
+
return this._resolveAccount(onAccount).signMessage(message, options);
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
async verifyMessage(message, signature) {
|
|
@@ -227,12 +229,13 @@ class AeSdkBase {
|
|
|
227
229
|
onAccount,
|
|
228
230
|
...options
|
|
229
231
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
230
|
-
return
|
|
232
|
+
return this._resolveAccount(onAccount).verifyMessage(message, signature, options);
|
|
231
233
|
}
|
|
232
234
|
/**
|
|
233
235
|
* Resolves an account
|
|
234
236
|
* @param account - ak-address, instance of AccountBase, or keypair
|
|
235
237
|
*/
|
|
238
|
+
// eslint-disable-next-line class-methods-use-this
|
|
236
239
|
|
|
237
240
|
|
|
238
241
|
_resolveAccount(account) {
|
|
@@ -250,21 +253,17 @@ class AeSdkBase {
|
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
|
|
253
|
-
|
|
254
|
-
var _this$api;
|
|
255
|
-
|
|
256
|
+
_getOptions() {
|
|
256
257
|
return { ...this._options,
|
|
257
258
|
onNode: getValueOrErrorProxy(() => this.api),
|
|
258
259
|
onAccount: getValueOrErrorProxy(() => this._resolveAccount()),
|
|
259
|
-
onCompiler: getValueOrErrorProxy(() => this.compilerApi)
|
|
260
|
-
// TODO: remove networkId
|
|
261
|
-
networkId: (await ((_this$api = this.api) === null || _this$api === void 0 ? void 0 : _this$api.getStatus())).networkId
|
|
260
|
+
onCompiler: getValueOrErrorProxy(() => this.compilerApi)
|
|
262
261
|
};
|
|
263
262
|
}
|
|
264
263
|
|
|
265
264
|
async buildTx(txType, options) {
|
|
266
|
-
// @ts-expect-error
|
|
267
|
-
return
|
|
265
|
+
// @ts-expect-error TODO: need to figure out what's wrong here
|
|
266
|
+
return _buildTx(txType, { ...this._getOptions(),
|
|
268
267
|
...options
|
|
269
268
|
});
|
|
270
269
|
}
|
|
@@ -275,18 +274,23 @@ const {
|
|
|
275
274
|
_buildTx: _,
|
|
276
275
|
...txMethodsOther
|
|
277
276
|
} = txMethods;
|
|
278
|
-
const
|
|
277
|
+
const {
|
|
278
|
+
InvalidTxError: _2,
|
|
279
|
+
...chainMethodsOther
|
|
280
|
+
} = chainMethods;
|
|
281
|
+
const methods = { ...chainMethodsOther,
|
|
279
282
|
...txMethodsOther,
|
|
280
283
|
...aensMethods,
|
|
281
284
|
...spendMethods,
|
|
282
285
|
...oracleMethods,
|
|
283
286
|
...contractMethods,
|
|
284
|
-
...contractGaMethods
|
|
287
|
+
...contractGaMethods,
|
|
288
|
+
...deprecatedMethods
|
|
285
289
|
};
|
|
286
290
|
Object.assign(AeSdkBase.prototype, mapObject(methods, _ref3 => {
|
|
287
291
|
let [name, handler] = _ref3;
|
|
288
|
-
return [name,
|
|
289
|
-
const instanceOptions =
|
|
292
|
+
return [name, function methodWrapper() {
|
|
293
|
+
const instanceOptions = this._getOptions();
|
|
290
294
|
|
|
291
295
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
292
296
|
args[_key] = arguments[_key];
|
|
@@ -295,12 +299,12 @@ Object.assign(AeSdkBase.prototype, mapObject(methods, _ref3 => {
|
|
|
295
299
|
const lastArg = args[args.length - 1];
|
|
296
300
|
|
|
297
301
|
if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
|
|
298
|
-
|
|
302
|
+
args[args.length - 1] = { ...instanceOptions,
|
|
299
303
|
...lastArg,
|
|
300
304
|
...(lastArg.onAccount != null && {
|
|
301
305
|
onAccount: this._resolveAccount(lastArg.onAccount)
|
|
302
306
|
})
|
|
303
|
-
}
|
|
307
|
+
};
|
|
304
308
|
} else args.push(instanceOptions);
|
|
305
309
|
|
|
306
310
|
return handler(...args);
|
package/es/AeSdkBase.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AeSdkBase.mjs","names":["chainMethods","txMethods","aensMethods","spendMethods","oracleMethods","contractMethods","contractGaMethods","_buildTx","mapObject","getNetworkId","AE_AMOUNT_FORMATS","AMOUNT","MemoryAccount","isAccountBase","CompilerError","DuplicateNodeError","NodeNotFoundError","NotImplementedError","TypeError","Compiler","getValueOrErrorProxy","valueCb","error","Proxy","Object","fromEntries","map","name","AeSdkBase","constructor","nodes","compilerUrl","ignoreVersion","options","denomination","AETTOS","amount","Map","assign","_options","forEach","i","instance","addNode","compilerApi","setCompilerUrl","api","ensureNodeConnected","pool","get","selectedNodeName","node","select","has","set","selectNode","isNodeConnected","getNodeInfo","getNodesInPool","Promise","all","Array","from","entries","addresses","address","onAccount","_resolveAccount","sign","data","signTransaction","tx","networkId","signMessage","message","verifyMessage","signature","account","keypair","String","_getOptions","onNode","onCompiler","getStatus","buildTx","txType","_","txMethodsOther","methods","prototype","handler","instanceOptions","args","lastArg","length","push"],"sources":["../src/AeSdkBase.ts"],"sourcesContent":["import * as chainMethods from './chain'\nimport * as txMethods from './tx'\nimport * as aensMethods from './aens'\nimport * as spendMethods from './spend'\nimport * as oracleMethods from './oracle'\nimport * as contractMethods from './contract/methods'\nimport * as contractGaMethods from './contract/ga'\nimport { _buildTx } from './tx'\nimport { mapObject } from './utils/other'\nimport Node, { getNetworkId } from './Node'\nimport { AE_AMOUNT_FORMATS } from './utils/amount-formatter'\nimport { AMOUNT, TX_TYPE } from './tx/builder/schema'\nimport MemoryAccount, { Keypair } from './account/Memory'\nimport AccountBase, { isAccountBase } from './account/Base'\nimport {\n CompilerError,\n DuplicateNodeError,\n NodeNotFoundError,\n NotImplementedError,\n TypeError\n} from './utils/errors'\nimport { EncodedData } from './utils/encoder'\nimport Compiler from './contract/Compiler'\n\nexport type Account = Keypair | AccountBase | any\n\ntype NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string }\n\nfunction getValueOrErrorProxy<Value extends object> (valueCb: () => Value): Value {\n try {\n return valueCb()\n } catch (error) {\n return new Proxy(\n {},\n Object.fromEntries(['get', 'set', 'has'].map(name => [name, () => { throw error }]))\n ) as Value\n }\n}\n\n/**\n * Basic AeSdk class\n *\n * AeSdkBase objects are the composition of:\n * - chain methods\n * - tx methods\n * - aens methods\n * - spend methods\n * - oracle methods\n * - contract methods\n * - contract ga methods\n * Only by providing the joint functionality of them, most more advanced\n * operations, i.e. the ones with actual use value on the chain, become\n * available.\n */\nclass AeSdkBase {\n _options: {\n denomination: AE_AMOUNT_FORMATS\n amount: number\n [key: string]: any\n } = { denomination: AE_AMOUNT_FORMATS.AETTOS, amount: AMOUNT }\n\n pool: Map<string, Node> = new Map()\n selectedNodeName?: string\n compilerApi: Compiler\n\n /**\n * @param options - Options\n * @param options.nodes - Array of nodes\n * @param options.compilerUrl - Url for compiler API\n * @param options.ignoreVersion - Don't check node or compiler version\n */\n constructor (\n { nodes = [], compilerUrl, ignoreVersion = false, ...options }:\n {\n nodes?: Array<{ name: string, instance: Node }>\n compilerUrl?: string\n ignoreVersion?: boolean\n [key: string]: any // TODO: consider combining all possible options instead\n } = {}\n ) {\n Object.assign(this._options, options)\n\n nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0))\n\n if (compilerUrl == null) {\n this.compilerApi = getValueOrErrorProxy(() => {\n throw new CompilerError('You can\\'t use Compiler API. Compiler is not ready!')\n })\n } else this.setCompilerUrl(compilerUrl, { ignoreVersion })\n }\n\n setCompilerUrl (\n compilerUrl: string, { ignoreVersion = false }: { ignoreVersion?: boolean } = {}\n ): void {\n this.compilerApi = new Compiler(compilerUrl, { ignoreVersion })\n }\n\n get api (): Node {\n this.ensureNodeConnected()\n return this.pool.get(this.selectedNodeName) as Node\n }\n\n /**\n * Add Node\n * @param name - Node name\n * @param node - Node instance\n * @param select - Select this node as current\n * @example\n * ```js\n * // add and select new node with name 'testNode'\n * aeSdkBase.addNode('testNode', new Node({ url }), true)\n * ```\n */\n addNode (name: string, node: Node, select = false): void {\n if (this.pool.has(name)) throw new DuplicateNodeError(name)\n\n this.pool.set(name, node)\n if (select || this.selectedNodeName == null) {\n this.selectNode(name)\n }\n }\n\n /**\n * Select Node\n * @param name - Node name\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode (name: string): void {\n if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)\n this.selectedNodeName = name\n }\n\n /**\n * Get NetworkId of current Node\n * @example\n * nodePool.getNetworkId()\n */\n readonly getNetworkId = getNetworkId\n\n /**\n * Check if you have selected node\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected (): this is AeSdkBase & { selectedNodeName: string } {\n return this.selectedNodeName != null\n }\n\n protected ensureNodeConnected (): asserts this is AeSdkBase & { selectedNodeName: string } {\n if (!this.isNodeConnected()) {\n throw new NodeNotFoundError('You can\\'t use Node API. Node is not connected or not defined!')\n }\n }\n\n /**\n * Get information about node\n * @example\n * ```js\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n * ```\n */\n async getNodeInfo (): Promise<NodeInfo> {\n this.ensureNodeConnected()\n return {\n name: this.selectedNodeName,\n ...await this.api.getNodeInfo()\n }\n }\n\n /**\n * Get array of available nodes\n * @example\n * nodePool.getNodesInPool()\n */\n async getNodesInPool (): Promise<NodeInfo[]> {\n return await Promise.all(\n Array.from(this.pool.entries()).map(async ([name, node]) => ({\n name,\n ...await node.getNodeInfo()\n }))\n )\n }\n\n addresses (): Array<EncodedData<'ak'>> {\n return []\n }\n\n async address ({ onAccount }: { onAccount?: Account } = {}): Promise<EncodedData<'ak'>> {\n return await this._resolveAccount(onAccount).address()\n }\n\n async sign (\n data: string | Uint8Array, { onAccount, ...options }: { onAccount?: Account } = {}\n ): Promise<Uint8Array> {\n return await this._resolveAccount(onAccount).sign(data, options)\n }\n\n async signTransaction (\n tx: EncodedData<'tx'>,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signTransaction']>[1] = {}\n ): Promise<EncodedData<'tx'>> {\n return await this._resolveAccount(onAccount)\n .signTransaction(tx, { ...options, networkId: await this.getNetworkId(options) })\n }\n\n async signMessage (\n message: string,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signMessage']>[1] = {}\n ): Promise<string | Uint8Array> {\n return await this._resolveAccount(onAccount).signMessage(message, options)\n }\n\n async verifyMessage (\n message: string,\n signature: string | Uint8Array,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['verifyMessage']>[2] = {}\n ): Promise<boolean> {\n return await this._resolveAccount(onAccount).verifyMessage(message, signature, options)\n }\n\n /**\n * Resolves an account\n * @param account - ak-address, instance of AccountBase, or keypair\n */\n _resolveAccount (account?: Account): AccountBase {\n switch (account !== null && typeof account) {\n case 'string':\n throw new NotImplementedError('Address in AccountResolver')\n case 'object':\n return isAccountBase(account) ? account : new MemoryAccount({ keypair: account })\n default:\n throw new TypeError(\n 'Account should be an address (ak-prefixed string), ' +\n `keypair, or instance of AccountBase, got ${String(account)} instead`)\n }\n }\n\n async _getOptions (\n ): Promise<{ onNode: Node, onAccount: AccountBase, onCompiler: Compiler, networkId: string }> {\n return {\n ...this._options,\n onNode: getValueOrErrorProxy(() => this.api),\n onAccount: getValueOrErrorProxy(() => this._resolveAccount()),\n onCompiler: getValueOrErrorProxy(() => this.compilerApi),\n // TODO: remove networkId\n networkId: (await this.api?.getStatus()).networkId\n }\n }\n\n async buildTx<TxType extends TX_TYPE> (\n txType: TxType,\n options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & { onNode?: Node }\n ): Promise<EncodedData<'tx'>> {\n // @ts-expect-error\n return await _buildTx<TxType>(txType, {\n ...await this._getOptions(),\n ...options\n })\n }\n}\n\nconst { _buildTx: _, ...txMethodsOther } = txMethods\n\nconst methods = {\n ...chainMethods,\n ...txMethodsOther,\n ...aensMethods,\n ...spendMethods,\n ...oracleMethods,\n ...contractMethods,\n ...contractGaMethods\n} as const\n\ntype RequiredKeys<T> = {\n [K in keyof T]-?: {} extends Pick<T, K> ? never : K\n}[keyof T]\n\ntype OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T\n\ntype MakeOptional<Args extends any[]> = Args extends [infer Head, ...infer Tail]\n ? Tail extends []\n ? Head extends object\n ? OptionalIfNotRequired<[Omit<Head, 'onNode' | 'onCompiler' | 'onAccount'>\n & { onNode?: Node, onCompiler?: Compiler, onAccount?: AccountBase | EncodedData<'ak'> | Keypair }]>\n : [Head]\n : [Head, ...MakeOptional<Tail>]\n : never\n\ntype TransformMethods <Methods extends { [key: string]: Function }> =\n {\n [Name in keyof Methods]:\n Methods[Name] extends (...args: infer Args) => infer Ret\n ? (...args: MakeOptional<Args>) => Ret\n : never\n }\n\ninterface AeSdkBaseMethods extends TransformMethods<typeof methods> {}\n\nObject.assign(AeSdkBase.prototype, mapObject<Function, Function>(\n methods,\n ([name, handler]) => [\n name,\n async function (...args: any[]) {\n const instanceOptions = await this._getOptions()\n const lastArg = args[args.length - 1]\n if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {\n Object.assign(lastArg, {\n ...instanceOptions,\n ...lastArg,\n ...lastArg.onAccount != null && { onAccount: this._resolveAccount(lastArg.onAccount) }\n })\n } else args.push(instanceOptions)\n return handler(...args)\n }\n ]\n))\n\nexport default AeSdkBase as new (options: ConstructorParameters<typeof AeSdkBase>[0]) =>\nAeSdkBase & AeSdkBaseMethods\n"],"mappings":";OAAO,KAAKA,Y;OACL,KAAKC,S;OACL,KAAKC,W;OACL,KAAKC,Y;OACL,KAAKC,a;OACL,KAAKC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SAAR,IAAqB,IAArB,IAA6B;UAAEA,SAAS,EAAE,KAAKC,eAAL,CAAqB0B,OAAO,CAAC3B,SAA7B;QAAb,CAAhC;MAHqB,CAAvB;IAKD,CAND,MAMO0B,IAAI,CAACG,IAAL,CAAUJ,eAAV;;IACP,OAAOD,OAAO,CAAC,GAAGE,IAAJ,CAAd;EACD,CAbkB,CAArB;AAAA,CAF0C,CAA5C;AAmBA,eAAehE,SAAf"}
|
|
1
|
+
{"version":3,"file":"AeSdkBase.mjs","names":["chainMethods","txMethods","aensMethods","spendMethods","oracleMethods","contractMethods","contractGaMethods","deprecatedMethods","_buildTx","mapObject","getNetworkId","AE_AMOUNT_FORMATS","AMOUNT","MemoryAccount","isAccountBase","CompilerError","DuplicateNodeError","NodeNotFoundError","NotImplementedError","TypeError","Compiler","getValueOrErrorProxy","valueCb","error","Proxy","Object","fromEntries","map","name","AeSdkBase","constructor","nodes","compilerUrl","ignoreVersion","options","denomination","AETTOS","amount","Map","assign","_options","forEach","i","instance","addNode","compilerApi","setCompilerUrl","api","ensureNodeConnected","pool","get","selectedNodeName","node","select","has","set","selectNode","isNodeConnected","getNodeInfo","getNodesInPool","Promise","all","Array","from","entries","addresses","address","onAccount","_resolveAccount","sign","data","signTransaction","tx","networkId","signMessage","message","verifyMessage","signature","account","keypair","String","_getOptions","onNode","onCompiler","buildTx","txType","_","txMethodsOther","InvalidTxError","_2","chainMethodsOther","methods","prototype","handler","methodWrapper","instanceOptions","args","lastArg","length","push"],"sources":["../src/AeSdkBase.ts"],"sourcesContent":["import * as chainMethods from './chain';\nimport * as txMethods from './tx';\nimport * as aensMethods from './aens';\nimport * as spendMethods from './spend';\nimport * as oracleMethods from './oracle';\nimport * as contractMethods from './contract/methods';\nimport * as contractGaMethods from './contract/ga';\nimport * as deprecatedMethods from './deprecated/methods';\nimport { _buildTx } from './tx';\nimport { mapObject } from './utils/other';\nimport Node, { getNetworkId } from './Node';\nimport { AE_AMOUNT_FORMATS } from './utils/amount-formatter';\nimport { AMOUNT } from './tx/builder/schema';\nimport { Tag } from './tx/builder/constants';\nimport MemoryAccount, { Keypair } from './account/Memory';\nimport AccountBase, { isAccountBase } from './account/Base';\nimport {\n CompilerError,\n DuplicateNodeError,\n NodeNotFoundError,\n NotImplementedError,\n TypeError,\n} from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport Compiler from './contract/Compiler';\n\nexport type Account = Keypair | AccountBase | any;\n\ntype NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };\n\nfunction getValueOrErrorProxy<Value extends object>(valueCb: () => Value): Value {\n try {\n return valueCb();\n } catch (error) {\n return new Proxy(\n {},\n Object.fromEntries(['get', 'set', 'has'].map((name) => [name, () => { throw error; }])),\n ) as Value;\n }\n}\n\n/**\n * Basic AeSdk class\n *\n * AeSdkBase objects are the composition of:\n * - chain methods\n * - tx methods\n * - aens methods\n * - spend methods\n * - oracle methods\n * - contract methods\n * - contract ga methods\n * Only by providing the joint functionality of them, most more advanced\n * operations, i.e. the ones with actual use value on the chain, become\n * available.\n */\nclass AeSdkBase {\n _options: {\n denomination: AE_AMOUNT_FORMATS;\n amount: number;\n [key: string]: any;\n } = { denomination: AE_AMOUNT_FORMATS.AETTOS, amount: AMOUNT };\n\n pool: Map<string, Node> = new Map();\n\n selectedNodeName?: string;\n\n compilerApi: Compiler;\n\n /**\n * @param options - Options\n * @param options.nodes - Array of nodes\n * @param options.compilerUrl - Url for compiler API\n * @param options.ignoreVersion - Don't check node or compiler version\n */\n constructor(\n {\n nodes = [], compilerUrl, ignoreVersion = false, ...options\n }:\n {\n nodes?: Array<{ name: string; instance: Node }>;\n compilerUrl?: string;\n ignoreVersion?: boolean;\n [key: string]: any; // TODO: consider combining all possible options instead\n } = {},\n ) {\n Object.assign(this._options, options);\n\n nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0));\n\n if (compilerUrl == null) {\n this.compilerApi = getValueOrErrorProxy(() => {\n throw new CompilerError('You can\\'t use Compiler API. Compiler is not ready!');\n });\n } else this.setCompilerUrl(compilerUrl, { ignoreVersion });\n }\n\n setCompilerUrl(\n compilerUrl: string,\n { ignoreVersion = false }: { ignoreVersion?: boolean } = {},\n ): void {\n this.compilerApi = new Compiler(compilerUrl, { ignoreVersion });\n }\n\n get api(): Node {\n this.ensureNodeConnected();\n return this.pool.get(this.selectedNodeName) as Node;\n }\n\n /**\n * Add Node\n * @param name - Node name\n * @param node - Node instance\n * @param select - Select this node as current\n * @example\n * ```js\n * // add and select new node with name 'testNode'\n * aeSdkBase.addNode('testNode', new Node({ url }), true)\n * ```\n */\n addNode(name: string, node: Node, select = false): void {\n if (this.pool.has(name)) throw new DuplicateNodeError(name);\n\n this.pool.set(name, node);\n if (select || this.selectedNodeName == null) {\n this.selectNode(name);\n }\n }\n\n /**\n * Select Node\n * @param name - Node name\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode(name: string): void {\n if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);\n this.selectedNodeName = name;\n }\n\n /**\n * Get NetworkId of current Node\n * @example\n * nodePool.getNetworkId()\n */\n readonly getNetworkId = getNetworkId;\n\n /**\n * Check if you have selected node\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected(): this is AeSdkBase & { selectedNodeName: string } {\n return this.selectedNodeName != null;\n }\n\n protected ensureNodeConnected(): asserts this is AeSdkBase & { selectedNodeName: string } {\n if (!this.isNodeConnected()) {\n throw new NodeNotFoundError('You can\\'t use Node API. Node is not connected or not defined!');\n }\n }\n\n /**\n * Get information about node\n * @example\n * ```js\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n * ```\n */\n async getNodeInfo(): Promise<NodeInfo> {\n this.ensureNodeConnected();\n return {\n name: this.selectedNodeName,\n ...await this.api.getNodeInfo(),\n };\n }\n\n /**\n * Get array of available nodes\n * @example\n * nodePool.getNodesInPool()\n */\n async getNodesInPool(): Promise<NodeInfo[]> {\n return Promise.all(\n Array.from(this.pool.entries()).map(async ([name, node]) => ({\n name,\n ...await node.getNodeInfo(),\n })),\n );\n }\n\n // eslint-disable-next-line class-methods-use-this\n addresses(): Encoded.AccountAddress[] {\n return [];\n }\n\n async address({ onAccount }: { onAccount?: Account } = {}): Promise<Encoded.AccountAddress> {\n return this._resolveAccount(onAccount).address();\n }\n\n async sign(\n data: string | Uint8Array,\n { onAccount, ...options }: { onAccount?: Account } = {},\n ): Promise<Uint8Array> {\n return this._resolveAccount(onAccount).sign(data, options);\n }\n\n async signTransaction(\n tx: Encoded.Transaction,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n return this._resolveAccount(onAccount)\n .signTransaction(tx, { ...options, networkId: await this.getNetworkId(options) });\n }\n\n async signMessage(\n message: string,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['signMessage']>[1] = {},\n ): Promise<string | Uint8Array> {\n return this._resolveAccount(onAccount).signMessage(message, options);\n }\n\n async verifyMessage(\n message: string,\n signature: string | Uint8Array,\n { onAccount, ...options }: { onAccount?: Account } & Parameters<AccountBase['verifyMessage']>[2] = {},\n ): Promise<boolean> {\n return this._resolveAccount(onAccount).verifyMessage(message, signature, options);\n }\n\n /**\n * Resolves an account\n * @param account - ak-address, instance of AccountBase, or keypair\n */\n // eslint-disable-next-line class-methods-use-this\n _resolveAccount(account?: Account): AccountBase {\n switch (account !== null && typeof account) {\n case 'string':\n throw new NotImplementedError('Address in AccountResolver');\n case 'object':\n return isAccountBase(account) ? account : new MemoryAccount({ keypair: account });\n default:\n throw new TypeError(\n 'Account should be an address (ak-prefixed string), '\n + `keypair, or instance of AccountBase, got ${String(account)} instead`,\n );\n }\n }\n\n _getOptions(): {\n onNode: Node;\n onAccount: AccountBase;\n onCompiler: Compiler;\n } {\n return {\n ...this._options,\n onNode: getValueOrErrorProxy(() => this.api),\n onAccount: getValueOrErrorProxy(() => this._resolveAccount()),\n onCompiler: getValueOrErrorProxy(() => this.compilerApi),\n };\n }\n\n async buildTx<TxType extends Tag>(\n txType: TxType,\n options: Omit<Parameters<typeof _buildTx<TxType>>[1], 'onNode'> & { onNode?: Node },\n ): Promise<Encoded.Transaction> {\n // @ts-expect-error TODO: need to figure out what's wrong here\n return _buildTx<TxType>(txType, {\n ...this._getOptions(),\n ...options,\n });\n }\n}\n\nconst { _buildTx: _, ...txMethodsOther } = txMethods;\nconst { InvalidTxError: _2, ...chainMethodsOther } = chainMethods;\n\nconst methods = {\n ...chainMethodsOther,\n ...txMethodsOther,\n ...aensMethods,\n ...spendMethods,\n ...oracleMethods,\n ...contractMethods,\n ...contractGaMethods,\n ...deprecatedMethods,\n} as const;\n\ntype RequiredKeys<T> = {\n [K in keyof T]-?: {} extends Pick<T, K> ? never : K\n}[keyof T];\n\ntype OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T;\n\ntype MakeOptional<Args extends any[]> = Args extends [infer Head, ...infer Tail]\n ? Tail extends []\n ? Head extends object\n ? OptionalIfNotRequired<[Omit<Head, 'onNode' | 'onCompiler' | 'onAccount'>\n & {\n onNode?: Node;\n onCompiler?: Compiler;\n onAccount?: AccountBase | Encoded.AccountAddress | Keypair;\n }]>\n : [Head]\n : [Head, ...MakeOptional<Tail>]\n : never;\n\ntype TransformMethods <Methods extends { [key: string]: Function }> =\n {\n [Name in keyof Methods]:\n Methods[Name] extends (...args: infer Args) => infer Ret\n ? (...args: MakeOptional<Args>) => Ret\n : never\n };\n\ninterface AeSdkBaseMethods extends TransformMethods<typeof methods> {}\n\nObject.assign(AeSdkBase.prototype, mapObject<Function, Function>(\n methods,\n ([name, handler]) => [\n name,\n function methodWrapper(...args: any[]) {\n const instanceOptions = this._getOptions();\n const lastArg = args[args.length - 1];\n if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {\n args[args.length - 1] = {\n ...instanceOptions,\n ...lastArg,\n ...lastArg.onAccount != null && { onAccount: this._resolveAccount(lastArg.onAccount) },\n };\n } else args.push(instanceOptions);\n return handler(...args);\n },\n ],\n));\n\nexport default AeSdkBase as new (options?: ConstructorParameters<typeof AeSdkBase>[0]) =>\nAeSdkBase & AeSdkBaseMethods;\n"],"mappings":";OAAO,KAAKA,Y;OACL,KAAKC,S;OACL,KAAKC,W;OACL,KAAKC,Y;OACL,KAAKC,a;OACL,KAAKC,e;OACL,KAAKC,iB;OACL,KAAKC,iB;SACHC,Q;SACAC,S;SACMC,Y;SACNC,iB;SACAC,M;OAEFC,a;SACeC,a;SAEpBC,a,EACAC,kB,EACAC,iB,EACAC,mB,EACAC,S;OAGKC,Q;;AAMP,SAASC,oBAAT,CAAoDC,OAApD,EAAiF;EAC/E,IAAI;IACF,OAAOA,OAAO,EAAd;EACD,CAFD,CAEE,OAAOC,KAAP,EAAc;IACd,OAAO,IAAIC,KAAJ,CACL,EADK,EAELC,MAAM,CAACC,WAAP,CAAmB,CAAC,KAAD,EAAQ,KAAR,EAAe,KAAf,EAAsBC,GAAtB,CAA2BC,IAAD,IAAU,CAACA,IAAD,EAAO,MAAM;MAAE,MAAML,KAAN;IAAc,CAA7B,CAApC,CAAnB,CAFK,CAAP;EAID;AACF;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMM,SAAN,CAAgB;EAad;AACF;AACA;AACA;AACA;AACA;EACEC,WAAW,GAUT;IAAA,IATA;MACEC,KAAK,GAAG,EADV;MACcC,WADd;MAC2BC,aAAa,GAAG,KAD3C;MACkD,GAAGC;IADrD,CASA,uEADI,EACJ;;IAAA,kCAxBE;MAAEC,YAAY,EAAExB,iBAAiB,CAACyB,MAAlC;MAA0CC,MAAM,EAAEzB;IAAlD,CAwBF;;IAAA,8BAtBwB,IAAI0B,GAAJ,EAsBxB;;IAAA,sCA4DsB5B,YA5DtB;;IACAe,MAAM,CAACc,MAAP,CAAc,KAAKC,QAAnB,EAA6BN,OAA7B;IAEAH,KAAK,CAACU,OAAN,CAAc,OAA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kDA,OAAO,CAACnE,WAAR,KAAwBL,MAA9E,EAAsF;MACpFuE,IAAI,CAACA,IAAI,CAACE,MAAL,GAAc,CAAf,CAAJ,GAAwB,EACtB,GAAGH,eADmB;QAEtB,GAAGE,OAFmB;QAGtB,IAAGA,OAAO,CAAC9B,SAAR,IAAqB,IAArB,IAA6B;UAAEA,SAAS,EAAE,KAAKC,eAAL,CAAqB6B,OAAO,CAAC9B,SAA7B;QAAb,CAAhC;MAHsB,CAAxB;IAKD,CAND,MAMO6B,IAAI,CAACG,IAAL,CAAUJ,eAAV;;IACP,OAAOF,OAAO,CAAC,GAAGG,IAAJ,CAAd;EACD,CAbkB,CAArB;AAAA,CAF0C,CAA5C;AAmBA,eAAenE,SAAf"}
|
package/es/AeSdkWallet.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ import { METHODS, RPC_STATUS, WALLET_TYPE } from './aepp-wallet-communication/sc
|
|
|
5
5
|
import AccountBase from './account/Base';
|
|
6
6
|
import BrowserConnection from './aepp-wallet-communication/connection/Browser';
|
|
7
7
|
import { Accounts, AeppApi, Network, WalletApi, WalletInfo } from './aepp-wallet-communication/rpc/types';
|
|
8
|
-
import {
|
|
8
|
+
import { Encoded } from './utils/encoder';
|
|
9
9
|
declare type RpcClientWallet = RpcClient<AeppApi, WalletApi>;
|
|
10
10
|
declare type OnConnection = (clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string) => void;
|
|
11
11
|
declare type OnSubscription = (clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string) => void;
|
|
12
12
|
declare type OnSign = (clientId: string, params: Parameters<WalletApi[METHODS.sign]>[0], origin: string) => Promise<{
|
|
13
|
-
tx?:
|
|
13
|
+
tx?: Encoded.Transaction;
|
|
14
14
|
onAccount?: Account;
|
|
15
15
|
} | undefined> | Promise<void>;
|
|
16
16
|
declare type OnDisconnect = (clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]) => void;
|
|
@@ -27,6 +27,7 @@ interface RpcClientsInfo {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Contain functionality for aepp interaction and managing multiple aepps
|
|
30
|
+
* @category aepp wallet communication
|
|
30
31
|
*/
|
|
31
32
|
export default class AeSdkWallet extends AeSdk {
|
|
32
33
|
id: string;
|
|
@@ -63,7 +64,7 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
63
64
|
onMessageSign: OnMessageSign;
|
|
64
65
|
} & ConstructorParameters<typeof AeSdk>[0]);
|
|
65
66
|
_pushAccountsToApps(): void;
|
|
66
|
-
selectAccount(address:
|
|
67
|
+
selectAccount(address: Encoded.AccountAddress): void;
|
|
67
68
|
addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): Promise<void>;
|
|
68
69
|
_getNode(): {
|
|
69
70
|
node: Network['node'];
|
package/es/AeSdkWallet.mjs
CHANGED
|
@@ -4,12 +4,13 @@ import AeSdk from "./AeSdk.mjs";
|
|
|
4
4
|
import verifyTransaction from "./tx/validator.mjs";
|
|
5
5
|
import RpcClient from "./aepp-wallet-communication/rpc/RpcClient.mjs";
|
|
6
6
|
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, RpcBroadcastError, RpcInvalidTransactionError, RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError } from "./aepp-wallet-communication/schema.mjs";
|
|
7
|
-
import { UnknownRpcClientError } from "./utils/errors.mjs";
|
|
7
|
+
import { InternalError, UnknownRpcClientError } from "./utils/errors.mjs";
|
|
8
8
|
import { RPC_VERSION } from "./aepp-wallet-communication/rpc/types.mjs";
|
|
9
9
|
import jsonBig from "./utils/json-big.mjs";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Contain functionality for aepp interaction and managing multiple aepps
|
|
13
|
+
* @category aepp wallet communication
|
|
13
14
|
*/
|
|
14
15
|
export default class AeSdkWallet extends AeSdk {
|
|
15
16
|
/**
|
|
@@ -187,6 +188,9 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
187
188
|
case SUBSCRIPTION_TYPES.unsubscribe:
|
|
188
189
|
client.addressSubscription.delete(value);
|
|
189
190
|
break;
|
|
191
|
+
|
|
192
|
+
default:
|
|
193
|
+
throw new InternalError(`Unknown subscription type: ${type}`);
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
return {
|