@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/AeSdkWallet.ts
CHANGED
|
@@ -1,75 +1,85 @@
|
|
|
1
|
-
import { v4 as uuid } from '@aeternity/uuid'
|
|
2
|
-
import AeSdk from './AeSdk'
|
|
3
|
-
import { Account } from './AeSdkBase'
|
|
4
|
-
import verifyTransaction from './tx/validator'
|
|
5
|
-
import RpcClient from './aepp-wallet-communication/rpc/RpcClient'
|
|
1
|
+
import { v4 as uuid } from '@aeternity/uuid';
|
|
2
|
+
import AeSdk from './AeSdk';
|
|
3
|
+
import { Account } from './AeSdkBase';
|
|
4
|
+
import verifyTransaction from './tx/validator';
|
|
5
|
+
import RpcClient from './aepp-wallet-communication/rpc/RpcClient';
|
|
6
6
|
import {
|
|
7
7
|
METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,
|
|
8
8
|
RpcBroadcastError, RpcInvalidTransactionError,
|
|
9
|
-
RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError
|
|
10
|
-
} from './aepp-wallet-communication/schema'
|
|
11
|
-
import { UnknownRpcClientError } from './utils/errors'
|
|
12
|
-
import AccountBase from './account/Base'
|
|
13
|
-
import BrowserConnection from './aepp-wallet-communication/connection/Browser'
|
|
9
|
+
RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,
|
|
10
|
+
} from './aepp-wallet-communication/schema';
|
|
11
|
+
import { InternalError, UnknownRpcClientError } from './utils/errors';
|
|
12
|
+
import AccountBase from './account/Base';
|
|
13
|
+
import BrowserConnection from './aepp-wallet-communication/connection/Browser';
|
|
14
14
|
import {
|
|
15
15
|
Accounts,
|
|
16
16
|
AeppApi,
|
|
17
17
|
Network,
|
|
18
18
|
RPC_VERSION,
|
|
19
19
|
WalletApi,
|
|
20
|
-
WalletInfo
|
|
21
|
-
} from './aepp-wallet-communication/rpc/types'
|
|
22
|
-
import {
|
|
23
|
-
import jsonBig from './utils/json-big'
|
|
20
|
+
WalletInfo,
|
|
21
|
+
} from './aepp-wallet-communication/rpc/types';
|
|
22
|
+
import { Encoded } from './utils/encoder';
|
|
23
|
+
import jsonBig from './utils/json-big';
|
|
24
24
|
|
|
25
|
-
type RpcClientWallet = RpcClient<AeppApi, WalletApi
|
|
25
|
+
type RpcClientWallet = RpcClient<AeppApi, WalletApi>;
|
|
26
26
|
|
|
27
27
|
type OnConnection = (
|
|
28
28
|
clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string
|
|
29
|
-
) => void
|
|
29
|
+
) => void;
|
|
30
30
|
|
|
31
31
|
type OnSubscription = (
|
|
32
32
|
clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string
|
|
33
|
-
) => void
|
|
33
|
+
) => void;
|
|
34
34
|
|
|
35
35
|
type OnSign = (
|
|
36
36
|
clientId: string, params: Parameters<WalletApi[METHODS.sign]>[0], origin: string
|
|
37
|
-
) => Promise<{ tx?:
|
|
37
|
+
) => Promise<{ tx?: Encoded.Transaction; onAccount?: Account } | undefined> | Promise<void>;
|
|
38
38
|
|
|
39
39
|
type OnDisconnect = (
|
|
40
40
|
clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]
|
|
41
|
-
) => void
|
|
41
|
+
) => void;
|
|
42
42
|
|
|
43
43
|
type OnAskAccounts = (
|
|
44
44
|
clientId: string, params: undefined, origin: string
|
|
45
|
-
) => void
|
|
45
|
+
) => void;
|
|
46
46
|
|
|
47
47
|
type OnMessageSign = (
|
|
48
48
|
clientId: string, params: Parameters<WalletApi[METHODS.signMessage]>[0], origin: string
|
|
49
|
-
) => Promise<{ onAccount?: Account } | undefined> | Promise<void
|
|
49
|
+
) => Promise<{ onAccount?: Account } | undefined> | Promise<void>;
|
|
50
50
|
|
|
51
51
|
interface RpcClientsInfo {
|
|
52
|
-
id: string
|
|
53
|
-
status: RPC_STATUS
|
|
54
|
-
connectNode: boolean
|
|
55
|
-
addressSubscription: Set<'connected' | 'current'
|
|
56
|
-
rpc: RpcClientWallet
|
|
52
|
+
id: string;
|
|
53
|
+
status: RPC_STATUS;
|
|
54
|
+
connectNode: boolean;
|
|
55
|
+
addressSubscription: Set<'connected' | 'current'>;
|
|
56
|
+
rpc: RpcClientWallet;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Contain functionality for aepp interaction and managing multiple aepps
|
|
61
|
+
* @category aepp wallet communication
|
|
61
62
|
*/
|
|
62
63
|
export default class AeSdkWallet extends AeSdk {
|
|
63
|
-
id: string
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
id: string;
|
|
65
|
+
|
|
66
|
+
_type: WALLET_TYPE;
|
|
67
|
+
|
|
68
|
+
name: string;
|
|
69
|
+
|
|
70
|
+
_clients: Map<string, RpcClientsInfo>;
|
|
71
|
+
|
|
72
|
+
onConnection: OnConnection;
|
|
73
|
+
|
|
74
|
+
onSubscription: OnSubscription;
|
|
75
|
+
|
|
76
|
+
onSign: OnSign;
|
|
77
|
+
|
|
78
|
+
onDisconnect: OnDisconnect;
|
|
79
|
+
|
|
80
|
+
onAskAccounts: OnAskAccounts;
|
|
81
|
+
|
|
82
|
+
onMessageSign: OnMessageSign;
|
|
73
83
|
|
|
74
84
|
/**
|
|
75
85
|
* @param options - Options
|
|
@@ -83,7 +93,7 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
83
93
|
* @param options.onMessageSign - Call-back function for incoming AEPP sign message request
|
|
84
94
|
* @param options.onDisconnect - Call-back function for disconnect event
|
|
85
95
|
*/
|
|
86
|
-
constructor
|
|
96
|
+
constructor({
|
|
87
97
|
name,
|
|
88
98
|
id,
|
|
89
99
|
type,
|
|
@@ -95,98 +105,98 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
95
105
|
onMessageSign,
|
|
96
106
|
...options
|
|
97
107
|
}: {
|
|
98
|
-
id: string
|
|
99
|
-
type: WALLET_TYPE
|
|
100
|
-
name: string
|
|
101
|
-
onConnection: OnConnection
|
|
102
|
-
onSubscription: OnSubscription
|
|
103
|
-
onSign: OnSign
|
|
104
|
-
onDisconnect: OnDisconnect
|
|
105
|
-
onAskAccounts: OnAskAccounts
|
|
106
|
-
onMessageSign: OnMessageSign
|
|
108
|
+
id: string;
|
|
109
|
+
type: WALLET_TYPE;
|
|
110
|
+
name: string;
|
|
111
|
+
onConnection: OnConnection;
|
|
112
|
+
onSubscription: OnSubscription;
|
|
113
|
+
onSign: OnSign;
|
|
114
|
+
onDisconnect: OnDisconnect;
|
|
115
|
+
onAskAccounts: OnAskAccounts;
|
|
116
|
+
onMessageSign: OnMessageSign;
|
|
107
117
|
} & ConstructorParameters<typeof AeSdk>[0]) {
|
|
108
|
-
super(options)
|
|
109
|
-
this.onConnection = onConnection
|
|
110
|
-
this.onSubscription = onSubscription
|
|
111
|
-
this.onSign = onSign
|
|
112
|
-
this.onDisconnect = onDisconnect
|
|
113
|
-
this.onAskAccounts = onAskAccounts
|
|
114
|
-
this.onMessageSign = onMessageSign
|
|
115
|
-
this._clients = new Map()
|
|
116
|
-
this.name = name
|
|
117
|
-
this.id = id
|
|
118
|
-
this._type = type
|
|
118
|
+
super(options);
|
|
119
|
+
this.onConnection = onConnection;
|
|
120
|
+
this.onSubscription = onSubscription;
|
|
121
|
+
this.onSign = onSign;
|
|
122
|
+
this.onDisconnect = onDisconnect;
|
|
123
|
+
this.onAskAccounts = onAskAccounts;
|
|
124
|
+
this.onMessageSign = onMessageSign;
|
|
125
|
+
this._clients = new Map();
|
|
126
|
+
this.name = name;
|
|
127
|
+
this.id = id;
|
|
128
|
+
this._type = type;
|
|
119
129
|
}
|
|
120
130
|
|
|
121
|
-
_pushAccountsToApps
|
|
131
|
+
_pushAccountsToApps(): void {
|
|
122
132
|
Array.from(this._clients.keys())
|
|
123
|
-
.filter(clientId => this._isRpcClientSubscribed(clientId))
|
|
124
|
-
.map(clientId => this._getClient(clientId).rpc)
|
|
125
|
-
.forEach(client => client.notify(METHODS.updateAddress, this.getAccounts()))
|
|
133
|
+
.filter((clientId) => this._isRpcClientSubscribed(clientId))
|
|
134
|
+
.map((clientId) => this._getClient(clientId).rpc)
|
|
135
|
+
.forEach((client) => client.notify(METHODS.updateAddress, this.getAccounts()));
|
|
126
136
|
}
|
|
127
137
|
|
|
128
|
-
selectAccount
|
|
129
|
-
super.selectAccount(address)
|
|
130
|
-
this._pushAccountsToApps()
|
|
138
|
+
selectAccount(address: Encoded.AccountAddress): void {
|
|
139
|
+
super.selectAccount(address);
|
|
140
|
+
this._pushAccountsToApps();
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
async addAccount
|
|
143
|
+
async addAccount(
|
|
134
144
|
account: AccountBase,
|
|
135
|
-
options?: Parameters<AeSdk['addAccount']>[1]
|
|
145
|
+
options?: Parameters<AeSdk['addAccount']>[1],
|
|
136
146
|
): Promise<void> {
|
|
137
|
-
await super.addAccount(account, options)
|
|
138
|
-
this._pushAccountsToApps()
|
|
147
|
+
await super.addAccount(account, options);
|
|
148
|
+
this._pushAccountsToApps();
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
_getNode
|
|
142
|
-
this.ensureNodeConnected()
|
|
143
|
-
return { node: { url: this.api.url, name: this.selectedNodeName } }
|
|
151
|
+
_getNode(): { node: Network['node'] } {
|
|
152
|
+
this.ensureNodeConnected();
|
|
153
|
+
return { node: { url: this.api.url, name: this.selectedNodeName } };
|
|
144
154
|
}
|
|
145
155
|
|
|
146
|
-
async selectNode
|
|
147
|
-
super.selectNode(name)
|
|
148
|
-
const networkId = await this.getNetworkId()
|
|
156
|
+
async selectNode(name: string): Promise<void> {
|
|
157
|
+
super.selectNode(name);
|
|
158
|
+
const networkId = await this.getNetworkId();
|
|
149
159
|
Array.from(this._clients.keys())
|
|
150
|
-
.filter(clientId => this._isRpcClientConnected(clientId))
|
|
151
|
-
.map(clientId => this._getClient(clientId))
|
|
152
|
-
.forEach(client => {
|
|
160
|
+
.filter((clientId) => this._isRpcClientConnected(clientId))
|
|
161
|
+
.map((clientId) => this._getClient(clientId))
|
|
162
|
+
.forEach((client) => {
|
|
153
163
|
client.rpc.notify(METHODS.updateNetwork, {
|
|
154
164
|
networkId,
|
|
155
|
-
...client.connectNode && this._getNode()
|
|
156
|
-
})
|
|
157
|
-
})
|
|
165
|
+
...client.connectNode && this._getNode(),
|
|
166
|
+
});
|
|
167
|
+
});
|
|
158
168
|
}
|
|
159
169
|
|
|
160
|
-
_getClient
|
|
161
|
-
const client = this._clients.get(clientId)
|
|
162
|
-
if (client == null) throw new UnknownRpcClientError(clientId)
|
|
163
|
-
return client
|
|
170
|
+
_getClient(clientId: string): RpcClientsInfo {
|
|
171
|
+
const client = this._clients.get(clientId);
|
|
172
|
+
if (client == null) throw new UnknownRpcClientError(clientId);
|
|
173
|
+
return client;
|
|
164
174
|
}
|
|
165
175
|
|
|
166
|
-
_isRpcClientSubscribed
|
|
167
|
-
return this._isRpcClientConnected(clientId)
|
|
168
|
-
this._getClient(clientId).addressSubscription.size !== 0
|
|
176
|
+
_isRpcClientSubscribed(clientId: string): boolean {
|
|
177
|
+
return this._isRpcClientConnected(clientId)
|
|
178
|
+
&& this._getClient(clientId).addressSubscription.size !== 0;
|
|
169
179
|
}
|
|
170
180
|
|
|
171
|
-
_isRpcClientConnected
|
|
172
|
-
return RPC_STATUS.CONNECTED === this._getClient(clientId).status
|
|
173
|
-
this._getClient(clientId).rpc.connection.isConnected()
|
|
181
|
+
_isRpcClientConnected(clientId: string): boolean {
|
|
182
|
+
return RPC_STATUS.CONNECTED === this._getClient(clientId).status
|
|
183
|
+
&& this._getClient(clientId).rpc.connection.isConnected();
|
|
174
184
|
}
|
|
175
185
|
|
|
176
|
-
_disconnectRpcClient
|
|
177
|
-
const client = this._getClient(clientId)
|
|
178
|
-
client.rpc.connection.disconnect()
|
|
179
|
-
client.status = RPC_STATUS.DISCONNECTED
|
|
180
|
-
client.addressSubscription = new Set()
|
|
186
|
+
_disconnectRpcClient(clientId: string): void {
|
|
187
|
+
const client = this._getClient(clientId);
|
|
188
|
+
client.rpc.connection.disconnect();
|
|
189
|
+
client.status = RPC_STATUS.DISCONNECTED;
|
|
190
|
+
client.addressSubscription = new Set();
|
|
181
191
|
}
|
|
182
192
|
|
|
183
193
|
/**
|
|
184
194
|
* Remove specific RpcClient by ID
|
|
185
195
|
* @param id - Client ID
|
|
186
196
|
*/
|
|
187
|
-
removeRpcClient
|
|
188
|
-
this._disconnectRpcClient(id)
|
|
189
|
-
this._clients.delete(id)
|
|
197
|
+
removeRpcClient(id: string): void {
|
|
198
|
+
this._disconnectRpcClient(id);
|
|
199
|
+
this._clients.delete(id);
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
/**
|
|
@@ -194,11 +204,11 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
194
204
|
* @param clientConnection - AEPP connection object
|
|
195
205
|
* @returns Client ID
|
|
196
206
|
*/
|
|
197
|
-
addRpcClient
|
|
207
|
+
addRpcClient(clientConnection: BrowserConnection): string {
|
|
198
208
|
// @TODO detect if aepp has some history based on origin????
|
|
199
209
|
// if yes use this instance for connection
|
|
200
|
-
const id = uuid()
|
|
201
|
-
let disconnectParams: any
|
|
210
|
+
const id = uuid();
|
|
211
|
+
let disconnectParams: any;
|
|
202
212
|
const client: RpcClientsInfo = {
|
|
203
213
|
id,
|
|
204
214
|
status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,
|
|
@@ -207,126 +217,132 @@ export default class AeSdkWallet extends AeSdk {
|
|
|
207
217
|
rpc: new RpcClient<AeppApi, WalletApi>(
|
|
208
218
|
clientConnection,
|
|
209
219
|
() => {
|
|
210
|
-
this._clients.delete(id)
|
|
211
|
-
this.onDisconnect(id, disconnectParams) // also related info
|
|
212
|
-
},
|
|
220
|
+
this._clients.delete(id);
|
|
221
|
+
this.onDisconnect(id, disconnectParams); // also related info
|
|
222
|
+
},
|
|
223
|
+
{
|
|
213
224
|
[METHODS.closeConnection]: (params) => {
|
|
214
|
-
disconnectParams = params
|
|
215
|
-
this._disconnectRpcClient(id)
|
|
225
|
+
disconnectParams = params;
|
|
226
|
+
this._disconnectRpcClient(id);
|
|
216
227
|
},
|
|
217
228
|
// Store client info and prepare two fn for each client `connect` and `denyConnection`
|
|
218
229
|
// which automatically prepare and send response for that client
|
|
219
|
-
[METHODS.connect]: async ({
|
|
220
|
-
|
|
230
|
+
[METHODS.connect]: async ({
|
|
231
|
+
name, version, icons, connectNode,
|
|
232
|
+
}, origin) => {
|
|
233
|
+
if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();
|
|
221
234
|
|
|
222
|
-
await this.onConnection(id, { name, icons, connectNode }, origin)
|
|
223
|
-
client.status = RPC_STATUS.CONNECTED
|
|
224
|
-
client.connectNode = connectNode
|
|
235
|
+
await this.onConnection(id, { name, icons, connectNode }, origin);
|
|
236
|
+
client.status = RPC_STATUS.CONNECTED;
|
|
237
|
+
client.connectNode = connectNode;
|
|
225
238
|
return {
|
|
226
239
|
...await this.getWalletInfo(),
|
|
227
|
-
...connectNode && this._getNode()
|
|
228
|
-
}
|
|
240
|
+
...connectNode && this._getNode(),
|
|
241
|
+
};
|
|
229
242
|
},
|
|
230
243
|
[METHODS.subscribeAddress]: async ({ type, value }, origin) => {
|
|
231
|
-
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
244
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
232
245
|
|
|
233
|
-
await this.onSubscription(id, { type, value }, origin)
|
|
246
|
+
await this.onSubscription(id, { type, value }, origin);
|
|
234
247
|
|
|
235
248
|
switch (type) {
|
|
236
249
|
case SUBSCRIPTION_TYPES.subscribe:
|
|
237
|
-
client.addressSubscription.add(value)
|
|
238
|
-
break
|
|
250
|
+
client.addressSubscription.add(value);
|
|
251
|
+
break;
|
|
239
252
|
case SUBSCRIPTION_TYPES.unsubscribe:
|
|
240
|
-
client.addressSubscription.delete(value)
|
|
241
|
-
break
|
|
253
|
+
client.addressSubscription.delete(value);
|
|
254
|
+
break;
|
|
255
|
+
default:
|
|
256
|
+
throw new InternalError(`Unknown subscription type: ${type}`);
|
|
242
257
|
}
|
|
243
258
|
|
|
244
259
|
return {
|
|
245
260
|
subscription: Array.from(client.addressSubscription),
|
|
246
|
-
address: this.getAccounts()
|
|
247
|
-
}
|
|
261
|
+
address: this.getAccounts(),
|
|
262
|
+
};
|
|
248
263
|
},
|
|
249
264
|
[METHODS.address]: async (params, origin) => {
|
|
250
|
-
if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError()
|
|
251
|
-
await this.onAskAccounts(id, params, origin)
|
|
252
|
-
return this.addresses()
|
|
265
|
+
if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError();
|
|
266
|
+
await this.onAskAccounts(id, params, origin);
|
|
267
|
+
return this.addresses();
|
|
253
268
|
},
|
|
254
269
|
[METHODS.sign]: async ({ tx, onAccount, returnSigned }, origin) => {
|
|
255
|
-
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
256
|
-
onAccount ??= await this.address()
|
|
270
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
271
|
+
onAccount ??= await this.address();
|
|
257
272
|
if (!this.addresses().includes(onAccount)) {
|
|
258
|
-
throw new RpcPermissionDenyError(onAccount)
|
|
273
|
+
throw new RpcPermissionDenyError(onAccount);
|
|
259
274
|
}
|
|
260
275
|
|
|
261
|
-
const overrides = await this.onSign(id, { tx, returnSigned, onAccount }, origin)
|
|
262
|
-
onAccount = overrides?.onAccount ?? onAccount
|
|
263
|
-
tx = overrides?.tx ?? tx
|
|
276
|
+
const overrides = await this.onSign(id, { tx, returnSigned, onAccount }, origin);
|
|
277
|
+
onAccount = overrides?.onAccount ?? onAccount;
|
|
278
|
+
tx = overrides?.tx ?? tx;
|
|
264
279
|
if (returnSigned) {
|
|
265
|
-
return { signedTransaction: await this.signTransaction(tx, { onAccount }) }
|
|
280
|
+
return { signedTransaction: await this.signTransaction(tx, { onAccount }) };
|
|
266
281
|
}
|
|
267
282
|
try {
|
|
268
283
|
return jsonBig.parse(jsonBig.stringify({
|
|
269
|
-
transactionHash: await this.send(tx, { onAccount, verify: false })
|
|
270
|
-
}))
|
|
284
|
+
transactionHash: await this.send(tx, { onAccount, verify: false }),
|
|
285
|
+
}));
|
|
271
286
|
} catch (error) {
|
|
272
|
-
const validation = await verifyTransaction(tx, this.api)
|
|
273
|
-
if (validation.length > 0) throw new RpcInvalidTransactionError(validation)
|
|
274
|
-
throw new RpcBroadcastError(error.message)
|
|
287
|
+
const validation = await verifyTransaction(tx, this.api);
|
|
288
|
+
if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
|
|
289
|
+
throw new RpcBroadcastError(error.message);
|
|
275
290
|
}
|
|
276
291
|
},
|
|
277
292
|
[METHODS.signMessage]: async ({ message, onAccount }, origin) => {
|
|
278
|
-
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError()
|
|
279
|
-
onAccount ??= await this.address()
|
|
293
|
+
if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
|
|
294
|
+
onAccount ??= await this.address();
|
|
280
295
|
if (!this.addresses().includes(onAccount)) {
|
|
281
|
-
throw new RpcPermissionDenyError(onAccount)
|
|
296
|
+
throw new RpcPermissionDenyError(onAccount);
|
|
282
297
|
}
|
|
283
298
|
|
|
284
|
-
const overrides = await this.onMessageSign(id, { message, onAccount }, origin)
|
|
285
|
-
onAccount = overrides?.onAccount ?? onAccount
|
|
299
|
+
const overrides = await this.onMessageSign(id, { message, onAccount }, origin);
|
|
300
|
+
onAccount = overrides?.onAccount ?? onAccount;
|
|
286
301
|
return {
|
|
287
302
|
// TODO: fix signMessage return type
|
|
288
303
|
signature: await this.signMessage(message, { onAccount, returnHex: true }) as
|
|
289
|
-
unknown as string
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
304
|
+
unknown as string,
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
),
|
|
309
|
+
};
|
|
310
|
+
this._clients.set(id, client);
|
|
311
|
+
return id;
|
|
296
312
|
}
|
|
297
313
|
|
|
298
314
|
/**
|
|
299
315
|
* Send shareWalletInfo message to notify AEPP about wallet
|
|
300
316
|
* @param clientId - ID of RPC client send message to
|
|
301
317
|
*/
|
|
302
|
-
async shareWalletInfo
|
|
303
|
-
this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo())
|
|
318
|
+
async shareWalletInfo(clientId: string): Promise<void> {
|
|
319
|
+
this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo());
|
|
304
320
|
}
|
|
305
321
|
|
|
306
322
|
/**
|
|
307
323
|
* Get Wallet info object
|
|
308
324
|
* @returns Object with wallet information
|
|
309
325
|
*/
|
|
310
|
-
async getWalletInfo
|
|
326
|
+
async getWalletInfo(): Promise<WalletInfo> {
|
|
311
327
|
return {
|
|
312
328
|
id: this.id,
|
|
313
329
|
name: this.name,
|
|
314
330
|
networkId: await this.getNetworkId(),
|
|
315
331
|
origin: window.location.origin,
|
|
316
|
-
type: this._type
|
|
317
|
-
}
|
|
332
|
+
type: this._type,
|
|
333
|
+
};
|
|
318
334
|
}
|
|
319
335
|
|
|
320
336
|
/**
|
|
321
337
|
* Get Wallet accounts
|
|
322
338
|
* @returns Object with accounts information (\{ connected: Object, current: Object \})
|
|
323
339
|
*/
|
|
324
|
-
getAccounts
|
|
340
|
+
getAccounts(): Accounts {
|
|
325
341
|
return {
|
|
326
342
|
current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},
|
|
327
343
|
connected: this.addresses()
|
|
328
344
|
.filter((a) => a !== this.selectedAddress)
|
|
329
|
-
.reduce((acc, a) => ({ ...acc, [a]: {} }), {})
|
|
330
|
-
}
|
|
345
|
+
.reduce((acc, a) => ({ ...acc, [a]: {} }), {}),
|
|
346
|
+
};
|
|
331
347
|
}
|
|
332
348
|
}
|