@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/{base.js → base.mjs} +23 -11
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +14 -11
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +69 -59
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/{index.js → index.mjs} +12 -10
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +37 -20
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +28 -8
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +133 -90
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +43 -22
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +51 -35
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/{index.js → index.mjs} +40 -28
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/encoder.d.ts +26 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/{index.js → index.mjs} +15 -12
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +17 -11
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/constants.mjs +108 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +321 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +92 -74
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +16 -172
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +106 -14
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/{crypto.js → crypto.mjs} +42 -156
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.mjs +106 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +49 -15
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +49 -58
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +16 -6
- package/src/ae/aens.js +52 -58
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +21 -154
- package/src/ae/index.js +6 -4
- package/src/ae/oracle.js +33 -14
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -65
- package/src/channel/handlers.js +30 -20
- package/src/channel/index.js +46 -16
- package/src/channel/internal.js +35 -30
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +22 -113
- package/src/contract/ga/helpers.js +10 -6
- package/src/contract/ga/index.js +31 -24
- package/src/index.js +9 -8
- package/src/node-pool/index.js +13 -10
- package/src/node.js +11 -10
- package/src/tx/builder/constants.js +100 -0
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +99 -103
- package/src/tx/builder/index.js +81 -40
- package/src/tx/builder/schema.js +44 -132
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +110 -35
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +11 -155
- package/src/utils/encoder.ts +101 -0
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +68 -45
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -308
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -356
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -242
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -56
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -318
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/index.js +0 -310
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
|
@@ -3,24 +3,37 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc
|
|
5
5
|
* @export AeppRpc
|
|
6
|
-
* @example
|
|
6
|
+
* @example
|
|
7
|
+
* import ContentScriptBridge
|
|
8
|
+
* from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
|
|
7
9
|
*/
|
|
8
|
-
import { v4 as uuid } from 'uuid'
|
|
10
|
+
import { v4 as uuid } from '@aeternity/uuid'
|
|
9
11
|
import Ae from '../../../ae'
|
|
10
12
|
import RpcClient from './rpc-client'
|
|
11
|
-
import { getHandler, message
|
|
13
|
+
import { getHandler, message } from '../helpers'
|
|
12
14
|
import { METHODS, RPC_STATUS, VERSION } from '../schema'
|
|
15
|
+
import {
|
|
16
|
+
AlreadyConnectedError,
|
|
17
|
+
NoWalletConnectedError,
|
|
18
|
+
UnsubscribedAccountError,
|
|
19
|
+
UnAuthorizedAccountError,
|
|
20
|
+
ArgumentError,
|
|
21
|
+
RpcConnectionError
|
|
22
|
+
} from '../../errors'
|
|
23
|
+
import Node from '../../../node'
|
|
13
24
|
|
|
14
25
|
const NOTIFICATIONS = {
|
|
15
|
-
[METHODS.
|
|
26
|
+
[METHODS.updateAddress]: (instance) =>
|
|
16
27
|
({ params }) => {
|
|
17
28
|
instance.rpcClient.accounts = params
|
|
18
29
|
instance.onAddressChange(params)
|
|
19
30
|
},
|
|
20
31
|
[METHODS.updateNetwork]: (instance) =>
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
instance.
|
|
32
|
+
async ({ params }) => {
|
|
33
|
+
const { networkId, node } = params
|
|
34
|
+
instance.rpcClient.info.networkId = networkId
|
|
35
|
+
node && instance.addNode(node.name, await Node(node), true)
|
|
36
|
+
instance.onNetworkChange(params)
|
|
24
37
|
},
|
|
25
38
|
[METHODS.closeConnection]: (instance) =>
|
|
26
39
|
(msg) => {
|
|
@@ -30,27 +43,33 @@ const NOTIFICATIONS = {
|
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
const RESPONSES = {
|
|
33
|
-
[METHODS.
|
|
46
|
+
[METHODS.address]: (instance) =>
|
|
34
47
|
(msg) => instance.rpcClient.processResponse(msg),
|
|
35
|
-
[METHODS.
|
|
48
|
+
[METHODS.connect]: (instance) =>
|
|
36
49
|
(msg) => {
|
|
37
50
|
if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED
|
|
38
51
|
instance.rpcClient.processResponse(msg)
|
|
39
52
|
},
|
|
40
|
-
[METHODS.
|
|
53
|
+
[METHODS.subscribeAddress]: (instance) =>
|
|
41
54
|
(msg) => {
|
|
42
55
|
if (msg.result) {
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
if (msg.result.address) {
|
|
57
|
+
instance.rpcClient.accounts = msg.result.address
|
|
58
|
+
}
|
|
59
|
+
if (msg.result.subscription) {
|
|
60
|
+
instance.rpcClient.addressSubscription = msg.result.subscription
|
|
61
|
+
}
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
instance.rpcClient.processResponse(msg, ({ id, result }) => [result])
|
|
48
65
|
},
|
|
49
|
-
[METHODS.
|
|
66
|
+
[METHODS.sign]: (instance) =>
|
|
50
67
|
(msg) => {
|
|
51
|
-
instance.rpcClient.processResponse(
|
|
68
|
+
instance.rpcClient.processResponse(
|
|
69
|
+
msg, ({ id, result }) => [result.signedTransaction || result.transactionHash]
|
|
70
|
+
)
|
|
52
71
|
},
|
|
53
|
-
[METHODS.
|
|
72
|
+
[METHODS.signMessage]: (instance) =>
|
|
54
73
|
(msg) => {
|
|
55
74
|
instance.rpcClient.processResponse(msg, ({ id, result }) => [result.signature])
|
|
56
75
|
}
|
|
@@ -82,8 +101,18 @@ const handleMessage = (instance) => async (msg) => {
|
|
|
82
101
|
* @return {Object}
|
|
83
102
|
*/
|
|
84
103
|
export default Ae.compose({
|
|
85
|
-
async init ({
|
|
86
|
-
|
|
104
|
+
async init ({
|
|
105
|
+
name,
|
|
106
|
+
connection,
|
|
107
|
+
debug = false,
|
|
108
|
+
...other
|
|
109
|
+
}) {
|
|
110
|
+
['onAddressChange', 'onDisconnect', 'onNetworkChange'].forEach(event => {
|
|
111
|
+
const handler = other[event] ?? (() => {})
|
|
112
|
+
if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler)
|
|
113
|
+
this[event] = handler
|
|
114
|
+
})
|
|
115
|
+
|
|
87
116
|
this.connection = connection
|
|
88
117
|
this.name = name
|
|
89
118
|
this.debug = debug
|
|
@@ -92,21 +121,13 @@ export default Ae.compose({
|
|
|
92
121
|
// Init RPCClient
|
|
93
122
|
await this.connectToWallet(connection)
|
|
94
123
|
}
|
|
95
|
-
// Event callbacks
|
|
96
|
-
this.onDisconnect = onDisconnect
|
|
97
|
-
this.onAddressChange = onAddressChange
|
|
98
|
-
this.onNetworkChange = onNetworkChange
|
|
99
|
-
// validation
|
|
100
|
-
eventsHandlers.forEach(event => {
|
|
101
|
-
if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
|
|
102
|
-
})
|
|
103
124
|
},
|
|
104
125
|
deepProps: { Ae: { defaults: { walletBroadcast: true } } },
|
|
105
126
|
methods: {
|
|
106
127
|
sign () {
|
|
107
128
|
},
|
|
108
129
|
addresses () {
|
|
109
|
-
if (!this.
|
|
130
|
+
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
|
|
110
131
|
return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)]
|
|
111
132
|
},
|
|
112
133
|
/**
|
|
@@ -115,10 +136,14 @@ export default Ae.compose({
|
|
|
115
136
|
* @instance
|
|
116
137
|
* @rtype (connection: Object) => void
|
|
117
138
|
* @param {Object} connection Wallet connection object
|
|
118
|
-
* @
|
|
139
|
+
* @param {Object} [options={}]
|
|
140
|
+
* @param {Boolean} [options.connectNode=true] - Request wallet to bind node
|
|
141
|
+
* @param {String} [options.name=wallet-node] - Node name
|
|
142
|
+
* @param {Boolean} [options.select=false] - Select this node as current
|
|
143
|
+
* @return {Object}
|
|
119
144
|
*/
|
|
120
|
-
async connectToWallet (connection) {
|
|
121
|
-
if (this.rpcClient && this.rpcClient.isConnected()) throw new
|
|
145
|
+
async connectToWallet (connection, { connectNode = false, name = 'wallet-node', select = false } = {}) {
|
|
146
|
+
if (this.rpcClient && this.rpcClient.isConnected()) throw new AlreadyConnectedError('You are already connected to wallet ' + this.rpcClient)
|
|
122
147
|
this.rpcClient = RpcClient({
|
|
123
148
|
connection,
|
|
124
149
|
networkId: this.getNetworkId({ force: true }),
|
|
@@ -126,7 +151,12 @@ export default Ae.compose({
|
|
|
126
151
|
id: uuid(),
|
|
127
152
|
handlers: [handleMessage(this), this.onDisconnect]
|
|
128
153
|
})
|
|
129
|
-
|
|
154
|
+
const walletInfo = await this.sendConnectRequest(connectNode)
|
|
155
|
+
if (connectNode && !Object.prototype.hasOwnProperty.call(walletInfo, 'node')) {
|
|
156
|
+
throw new RpcConnectionError('Missing URLs of the Node')
|
|
157
|
+
}
|
|
158
|
+
connectNode && this.addNode(name, await Node(walletInfo.node), select)
|
|
159
|
+
return walletInfo
|
|
130
160
|
},
|
|
131
161
|
/**
|
|
132
162
|
* Disconnect from wallet
|
|
@@ -137,16 +167,18 @@ export default Ae.compose({
|
|
|
137
167
|
* @return {void}
|
|
138
168
|
*/
|
|
139
169
|
async disconnectWallet (sendDisconnect = true) {
|
|
140
|
-
if (!this.
|
|
170
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
141
171
|
sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, { reason: 'bye' }), true)
|
|
142
172
|
this.rpcClient.disconnect()
|
|
143
173
|
this.rpcClient = null
|
|
144
174
|
},
|
|
145
175
|
async address ({ onAccount } = {}) {
|
|
146
|
-
if (!this.
|
|
176
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
147
177
|
const current = this.rpcClient.currentAccount
|
|
148
|
-
if (!current) throw new
|
|
149
|
-
if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount))
|
|
178
|
+
if (!current) throw new UnsubscribedAccountError()
|
|
179
|
+
if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) {
|
|
180
|
+
throw new UnAuthorizedAccountError(onAccount)
|
|
181
|
+
}
|
|
150
182
|
return onAccount || current
|
|
151
183
|
},
|
|
152
184
|
/**
|
|
@@ -157,22 +189,22 @@ export default Ae.compose({
|
|
|
157
189
|
* @return {Promise} Address from wallet
|
|
158
190
|
*/
|
|
159
191
|
async askAddresses () {
|
|
160
|
-
if (!this.
|
|
161
|
-
if (!this.
|
|
162
|
-
return this.rpcClient.request(METHODS.
|
|
192
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
193
|
+
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
|
|
194
|
+
return this.rpcClient.request(METHODS.address)
|
|
163
195
|
},
|
|
164
196
|
/**
|
|
165
197
|
* Subscribe for addresses from wallet
|
|
166
198
|
* @function subscribeAddress
|
|
167
199
|
* @instance
|
|
168
200
|
* @rtype (type: String, value: String) => Promise
|
|
169
|
-
* @param {String} type
|
|
201
|
+
* @param {String} type Should be one of 'current' (the selected account), 'connected' (all)
|
|
170
202
|
* @param {String} value Subscription action('subscribe'|'unsubscribe')
|
|
171
203
|
* @return {Promise} Address from wallet
|
|
172
204
|
*/
|
|
173
205
|
async subscribeAddress (type, value) {
|
|
174
|
-
if (!this.
|
|
175
|
-
return this.rpcClient.request(METHODS.
|
|
206
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
207
|
+
return this.rpcClient.request(METHODS.subscribeAddress, { type, value })
|
|
176
208
|
},
|
|
177
209
|
/**
|
|
178
210
|
* Overwriting of `signTransaction` AE method
|
|
@@ -183,10 +215,15 @@ export default Ae.compose({
|
|
|
183
215
|
* @return {Promise<String>} Signed transaction
|
|
184
216
|
*/
|
|
185
217
|
async signTransaction (tx, opt = {}) {
|
|
186
|
-
if (!this.
|
|
187
|
-
if (!this.
|
|
188
|
-
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount))
|
|
189
|
-
|
|
218
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
219
|
+
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
|
|
220
|
+
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
|
|
221
|
+
throw new UnAuthorizedAccountError(opt.onAccount)
|
|
222
|
+
}
|
|
223
|
+
return this.rpcClient.request(
|
|
224
|
+
METHODS.sign,
|
|
225
|
+
{ ...opt, tx, returnSigned: true, networkId: this.getNetworkId() }
|
|
226
|
+
)
|
|
190
227
|
},
|
|
191
228
|
/**
|
|
192
229
|
* Overwriting of `signMessage` AE method
|
|
@@ -197,31 +234,36 @@ export default Ae.compose({
|
|
|
197
234
|
* @return {Promise<String>} Signed transaction
|
|
198
235
|
*/
|
|
199
236
|
async signMessage (msg, opt = {}) {
|
|
200
|
-
if (!this.
|
|
201
|
-
if (!this.
|
|
202
|
-
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount))
|
|
203
|
-
|
|
237
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
238
|
+
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
|
|
239
|
+
if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
|
|
240
|
+
throw new UnAuthorizedAccountError(opt.onAccount)
|
|
241
|
+
}
|
|
242
|
+
return this.rpcClient.request(METHODS.signMessage, { ...opt, message: msg })
|
|
204
243
|
},
|
|
205
244
|
/**
|
|
206
245
|
* Send connection request to wallet
|
|
207
246
|
* @function sendConnectRequest
|
|
208
247
|
* @instance
|
|
248
|
+
* @param {Boolean} connectNode - Request wallet to bind node
|
|
209
249
|
* @rtype () => Promise
|
|
210
250
|
* @return {Promise} Connection response
|
|
211
251
|
*/
|
|
212
|
-
async sendConnectRequest () {
|
|
252
|
+
async sendConnectRequest (connectNode) {
|
|
213
253
|
return this.rpcClient.request(
|
|
214
|
-
METHODS.
|
|
254
|
+
METHODS.connect, {
|
|
215
255
|
name: this.name,
|
|
216
256
|
version: VERSION,
|
|
217
|
-
networkId: this.getNetworkId({ force: true })
|
|
257
|
+
networkId: this.getNetworkId({ force: true }),
|
|
258
|
+
connectNode
|
|
218
259
|
}
|
|
219
260
|
)
|
|
220
261
|
},
|
|
221
262
|
/**
|
|
222
263
|
* Overwriting of `send` AE method
|
|
223
264
|
* All sdk API which use it will be send notification to wallet and wait for callBack
|
|
224
|
-
* This method will sign, broadcast and wait until transaction will be accepted using rpc
|
|
265
|
+
* This method will sign, broadcast and wait until transaction will be accepted using rpc
|
|
266
|
+
* communication with wallet
|
|
225
267
|
* @function send
|
|
226
268
|
* @instance
|
|
227
269
|
* @rtype (tx: String, options = {}) => Promise
|
|
@@ -231,15 +273,22 @@ export default Ae.compose({
|
|
|
231
273
|
* @return {Promise<Object>} Transaction broadcast result
|
|
232
274
|
*/
|
|
233
275
|
async send (tx, options = {}) {
|
|
234
|
-
if (!this.
|
|
235
|
-
if (!this.
|
|
236
|
-
if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount))
|
|
276
|
+
if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
|
|
277
|
+
if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
|
|
278
|
+
if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) {
|
|
279
|
+
throw new UnAuthorizedAccountError(options.onAccount)
|
|
280
|
+
}
|
|
237
281
|
const opt = { ...this.Ae.defaults, ...options }
|
|
238
282
|
if (!opt.walletBroadcast) {
|
|
239
283
|
const signed = await this.signTransaction(tx, { onAccount: opt.onAccount })
|
|
240
284
|
return this.sendTransaction(signed, opt)
|
|
241
285
|
}
|
|
242
|
-
return this.rpcClient.request(
|
|
243
|
-
|
|
286
|
+
return this.rpcClient.request(
|
|
287
|
+
METHODS.sign,
|
|
288
|
+
{ onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() }
|
|
289
|
+
)
|
|
290
|
+
},
|
|
291
|
+
isConnected () { return (this.rpcClient && this.rpcClient.isConnected()) },
|
|
292
|
+
isSubscribedAccount () { return typeof this.rpcClient.currentAccount !== 'undefined' }
|
|
244
293
|
}
|
|
245
294
|
})
|
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client
|
|
5
5
|
* @export { RpcClient, RpcClients }
|
|
6
|
-
* @example
|
|
6
|
+
* @example
|
|
7
|
+
* import RpcClient from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client'
|
|
7
8
|
*/
|
|
8
9
|
import stampit from '@stamp/it'
|
|
9
10
|
|
|
10
11
|
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES } from '../schema'
|
|
11
12
|
import { sendMessage, message, isValidAccounts } from '../helpers'
|
|
13
|
+
import {
|
|
14
|
+
InvalidRpcMessageError,
|
|
15
|
+
TypeError,
|
|
16
|
+
DuplicateCallbackError,
|
|
17
|
+
MissingCallbackError
|
|
18
|
+
} from '../../errors'
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* Contain functionality for using RPC conection
|
|
@@ -18,7 +25,9 @@ import { sendMessage, message, isValidAccounts } from '../helpers'
|
|
|
18
25
|
* @param {Object} param Init params object
|
|
19
26
|
* @param {String} param.name Client name
|
|
20
27
|
* @param {Object} param.connection Connection object
|
|
21
|
-
* @param {Function[]} param.handlers
|
|
28
|
+
* @param {Function[]} param.handlers Array with two function for message handling
|
|
29
|
+
* @param {Function} param.handlers[0] Message handler
|
|
30
|
+
* @param {Function} param.handlers[1] Disconnect callback
|
|
22
31
|
* @return {Object}
|
|
23
32
|
*/
|
|
24
33
|
export default stampit({
|
|
@@ -42,7 +51,7 @@ export default stampit({
|
|
|
42
51
|
|
|
43
52
|
const handleMessage = (msg, origin) => {
|
|
44
53
|
if (!msg || !msg.jsonrpc || msg.jsonrpc !== '2.0' || !msg.method) {
|
|
45
|
-
throw new
|
|
54
|
+
throw new InvalidRpcMessageError(msg)
|
|
46
55
|
}
|
|
47
56
|
onMessage(msg, origin)
|
|
48
57
|
}
|
|
@@ -120,7 +129,8 @@ export default stampit({
|
|
|
120
129
|
* @return {Boolean} is connected
|
|
121
130
|
*/
|
|
122
131
|
isConnected () {
|
|
123
|
-
return this.connection.isConnected() &&
|
|
132
|
+
return this.connection.isConnected() &&
|
|
133
|
+
(this.info.status === RPC_STATUS.CONNECTED || this.info.status === RPC_STATUS.NODE_BINDED)
|
|
124
134
|
},
|
|
125
135
|
/**
|
|
126
136
|
* Get selected account
|
|
@@ -148,17 +158,18 @@ export default stampit({
|
|
|
148
158
|
},
|
|
149
159
|
/**
|
|
150
160
|
* Update accounts and sent `update.address` notification to AEPP
|
|
151
|
-
* @param {{ current: Object, connected: Object }} accounts
|
|
152
|
-
* @param {
|
|
161
|
+
* @param {{ current: Object, connected: Object }} accounts Current and connected accounts
|
|
162
|
+
* @param {Object} [options]
|
|
163
|
+
* @param {Boolean} [options.forceNotification] Don't sent update notification to AEPP
|
|
153
164
|
*/
|
|
154
|
-
setAccounts (accounts, { forceNotification
|
|
165
|
+
setAccounts (accounts, { forceNotification } = {}) {
|
|
155
166
|
if (!isValidAccounts(accounts)) {
|
|
156
|
-
throw new
|
|
167
|
+
throw new TypeError('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
|
|
157
168
|
}
|
|
158
169
|
this.accounts = accounts
|
|
159
170
|
if (!forceNotification) {
|
|
160
171
|
// Sent notification about account updates
|
|
161
|
-
this.sendMessage(message(METHODS.
|
|
172
|
+
this.sendMessage(message(METHODS.updateAddress, this.accounts), true)
|
|
162
173
|
}
|
|
163
174
|
},
|
|
164
175
|
/**
|
|
@@ -190,7 +201,9 @@ export default stampit({
|
|
|
190
201
|
*/
|
|
191
202
|
request (name, params) {
|
|
192
203
|
const msgId = this.sendMessage(message(name, params))
|
|
193
|
-
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId))
|
|
204
|
+
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId)) {
|
|
205
|
+
throw new DuplicateCallbackError()
|
|
206
|
+
}
|
|
194
207
|
return new Promise((resolve, reject) => {
|
|
195
208
|
this.callbacks[msgId] = { resolve, reject }
|
|
196
209
|
})
|
|
@@ -205,7 +218,7 @@ export default stampit({
|
|
|
205
218
|
* @return {void}
|
|
206
219
|
*/
|
|
207
220
|
processResponse ({ id, error, result }, transformResult) {
|
|
208
|
-
if (!this.callbacks[id]) throw new
|
|
221
|
+
if (!this.callbacks[id]) throw new MissingCallbackError(id)
|
|
209
222
|
if (result) {
|
|
210
223
|
this.callbacks[id].resolve(...typeof transformResult === 'function'
|
|
211
224
|
? transformResult({ id, result })
|