@aeternity/aepp-sdk 8.2.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/CHANGELOG.md +216 -337
  2. package/README.md +16 -9
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/account/base.js +36 -120
  11. package/es/account/base.js.map +1 -1
  12. package/es/account/memory.js +17 -19
  13. package/es/account/memory.js.map +1 -1
  14. package/es/account/multiple.js +79 -156
  15. package/es/account/multiple.js.map +1 -1
  16. package/es/ae/aens.js +205 -626
  17. package/es/ae/aens.js.map +1 -1
  18. package/es/ae/contract.js +114 -918
  19. package/es/ae/contract.js.map +1 -1
  20. package/es/ae/index.js +90 -250
  21. package/es/ae/index.js.map +1 -1
  22. package/es/ae/oracle.js +136 -504
  23. package/es/ae/oracle.js.map +1 -1
  24. package/es/ae/universal.js.map +1 -1
  25. package/es/chain/index.js +12 -27
  26. package/es/chain/index.js.map +1 -1
  27. package/es/chain/node.js +289 -1020
  28. package/es/chain/node.js.map +1 -1
  29. package/es/channel/handlers.js +597 -1086
  30. package/es/channel/handlers.js.map +1 -1
  31. package/es/channel/index.js +238 -465
  32. package/es/channel/index.js.map +1 -1
  33. package/es/channel/internal.js +129 -301
  34. package/es/channel/internal.js.map +1 -1
  35. package/es/contract/aci/index.js +328 -495
  36. package/es/contract/aci/index.js.map +1 -1
  37. package/es/contract/aci/transformation.js +35 -711
  38. package/es/contract/aci/transformation.js.map +1 -1
  39. package/es/contract/compiler.js +131 -203
  40. package/es/contract/compiler.js.map +1 -1
  41. package/es/contract/ga/helpers.js +17 -122
  42. package/es/contract/ga/helpers.js.map +1 -1
  43. package/es/contract/ga/index.js +108 -249
  44. package/es/contract/ga/index.js.map +1 -1
  45. package/es/contract/index.js +7 -3
  46. package/es/contract/index.js.map +1 -1
  47. package/es/index.js +3 -3
  48. package/es/index.js.map +1 -1
  49. package/es/node-pool/index.js +57 -74
  50. package/es/node-pool/index.js.map +1 -1
  51. package/es/node.js +65 -161
  52. package/es/node.js.map +1 -1
  53. package/es/other.d.ts +1 -1
  54. package/es/tx/builder/helpers.js +62 -115
  55. package/es/tx/builder/helpers.js.map +1 -1
  56. package/es/tx/builder/index.js +218 -309
  57. package/es/tx/builder/index.js.map +1 -1
  58. package/es/tx/builder/schema.js +586 -573
  59. package/es/tx/builder/schema.js.map +1 -1
  60. package/es/tx/index.js +102 -13
  61. package/es/tx/index.js.map +1 -1
  62. package/es/tx/tx-object.js +114 -138
  63. package/es/tx/tx-object.js.map +1 -1
  64. package/es/tx/tx.js +810 -1586
  65. package/es/tx/tx.js.map +1 -1
  66. package/es/tx/validator.js +191 -426
  67. package/es/tx/validator.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
  69. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
  71. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
  73. package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
  75. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  77. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
  79. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
  81. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
  83. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  84. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  85. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  86. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  87. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  88. package/es/utils/amount-formatter.js +41 -61
  89. package/es/utils/amount-formatter.js.map +1 -1
  90. package/es/utils/async-init.js +28 -64
  91. package/es/utils/async-init.js.map +1 -1
  92. package/es/utils/bignumber.js +3 -11
  93. package/es/utils/bignumber.js.map +1 -1
  94. package/es/utils/bytes.js +5 -9
  95. package/es/utils/bytes.js.map +1 -1
  96. package/es/utils/crypto.js +41 -106
  97. package/es/utils/crypto.js.map +1 -1
  98. package/es/utils/hd-wallet.js +45 -81
  99. package/es/utils/hd-wallet.js.map +1 -1
  100. package/es/utils/json-big.js +16 -49
  101. package/es/utils/json-big.js.map +1 -1
  102. package/es/utils/keystore.js +81 -246
  103. package/es/utils/keystore.js.map +1 -1
  104. package/es/utils/mptree.js +88 -134
  105. package/es/utils/mptree.js.map +1 -1
  106. package/es/utils/other.js +10 -60
  107. package/es/utils/other.js.map +1 -1
  108. package/es/utils/semver-satisfies.js +9 -28
  109. package/es/utils/semver-satisfies.js.map +1 -1
  110. package/es/utils/string.js +4 -13
  111. package/es/utils/string.js.map +1 -1
  112. package/es/utils/swagger.js +87 -224
  113. package/es/utils/swagger.js.map +1 -1
  114. package/package.json +51 -44
  115. package/src/account/base.js +11 -10
  116. package/src/account/multiple.js +24 -18
  117. package/src/ae/aens.js +64 -61
  118. package/src/ae/contract.js +71 -248
  119. package/src/ae/index.js +34 -9
  120. package/src/ae/oracle.js +30 -22
  121. package/src/ae/universal.js +3 -1
  122. package/src/chain/index.js +10 -16
  123. package/src/chain/node.js +38 -38
  124. package/src/channel/handlers.js +10 -4
  125. package/src/channel/index.js +44 -20
  126. package/src/contract/aci/index.js +234 -112
  127. package/src/contract/aci/transformation.js +30 -422
  128. package/src/contract/compiler.js +50 -5
  129. package/src/contract/ga/helpers.js +6 -14
  130. package/src/contract/ga/index.js +28 -28
  131. package/src/contract/index.js +6 -2
  132. package/src/index.js +4 -4
  133. package/src/node-pool/index.js +24 -13
  134. package/src/node.js +29 -30
  135. package/src/tx/builder/helpers.js +31 -56
  136. package/src/tx/builder/index.js +67 -28
  137. package/src/tx/builder/schema.js +79 -121
  138. package/src/tx/index.js +101 -12
  139. package/src/tx/tx-object.js +25 -8
  140. package/src/tx/tx.js +229 -150
  141. package/src/tx/validator.js +134 -202
  142. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
  143. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
  144. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  145. package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
  146. package/src/utils/aepp-wallet-communication/helpers.js +4 -2
  147. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
  148. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
  149. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
  150. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  151. package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
  152. package/src/utils/amount-formatter.ts +1 -1
  153. package/src/utils/bignumber.ts +2 -1
  154. package/src/utils/crypto.js +4 -68
  155. package/src/utils/keystore.js +10 -2
  156. package/src/utils/other.ts +1 -1
  157. package/src/utils/semver-satisfies.ts +1 -1
  158. package/src/utils/swagger.js +22 -10
  159. package/src/contract/aci/helpers.js +0 -140
@@ -1,499 +1,319 @@
1
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
2
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
3
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
4
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
5
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
6
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
7
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
8
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
9
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
10
-
11
- var _REQUESTS;
12
-
13
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
14
-
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context21; _forEachInstanceProperty(_context21 = ownKeys(Object(source), true)).call(_context21, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context22; _forEachInstanceProperty(_context22 = ownKeys(Object(source))).call(_context22, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
-
17
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
18
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
19
- import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
20
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
21
- import _bindInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/bind";
22
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
23
- import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
24
- import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
25
- import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
26
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
27
-
28
1
  /**
29
2
  * RPC handler for WAELLET side
30
3
  *
31
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc
32
5
  * @export WalletRpc
33
- * @example import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
6
+ * @example
7
+ * import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
34
8
  */
35
9
  import { v4 as uuid } from 'uuid';
36
10
  import Ae from '../../../ae';
11
+ import verifyTransaction from '../../../tx/validator';
37
12
  import AccountMultiple from '../../../account/multiple';
38
13
  import TxObject from '../../../tx/tx-object';
39
14
  import RpcClient from './rpc-client';
40
15
  import { getBrowserAPI, getHandler, isValidAccounts, message, resolveOnAccount, sendResponseMessage } from '../helpers';
41
16
  import { ERRORS, METHODS, RPC_STATUS, VERSION, WALLET_TYPE } from '../schema';
42
-
43
- var NOTIFICATIONS = _defineProperty({}, METHODS.closeConnection, function (instance, _ref) {
44
- var client = _ref.client;
45
- return /*#__PURE__*/function () {
46
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(msg) {
47
- return _regeneratorRuntime.wrap(function _callee$(_context) {
48
- while (1) {
49
- switch (_context.prev = _context.next) {
50
- case 0:
51
- client.disconnect(true);
52
- instance.onDisconnect(msg.params, client);
53
-
54
- case 2:
55
- case "end":
56
- return _context.stop();
57
- }
58
- }
59
- }, _callee);
60
- }));
61
-
62
- return function (_x) {
63
- return _ref2.apply(this, arguments);
17
+ const NOTIFICATIONS = {
18
+ [METHODS.closeConnection]: (instance, _ref) => {
19
+ let {
20
+ client
21
+ } = _ref;
22
+ return async msg => {
23
+ client.disconnect(true);
24
+ instance.onDisconnect(msg.params, client);
64
25
  };
65
- }();
66
- });
26
+ }
27
+ };
28
+ const RESPONSES = {};
29
+ const REQUESTS = {
30
+ // Store client info and prepare two fn for each client `connect` and `denyConnection`
31
+ // which automatically prepare and send response for that client
32
+ [METHODS.aepp.connect](callInstance, instance, client, _ref2) {
33
+ let {
34
+ name,
35
+ networkId,
36
+ version,
37
+ icons
38
+ } = _ref2;
39
+ // Check if protocol and network is compatible with wallet
40
+ if (version !== VERSION) return {
41
+ error: ERRORS.unsupportedProtocol()
42
+ }; // Store new AEPP and wait for connection approve
67
43
 
68
- var RESPONSES = {};
69
- var REQUESTS = (_REQUESTS = {}, _defineProperty(_REQUESTS, METHODS.aepp.connect, function (callInstance, instance, client, _ref3) {
70
- var name = _ref3.name,
71
- networkId = _ref3.networkId,
72
- version = _ref3.version,
73
- icons = _ref3.icons;
74
- // Check if protocol and network is compatible with wallet
75
- if (version !== VERSION) return {
76
- error: ERRORS.unsupportedProtocol()
77
- }; // Store new AEPP and wait for connection approve
78
-
79
- client.updateInfo({
80
- status: RPC_STATUS.WAITING_FOR_CONNECTION_APPROVE,
81
- name: name,
82
- networkId: networkId,
83
- icons: icons,
84
- version: version
85
- }); // Call onConnection callBack to notice Wallet about new AEPP
86
-
87
- return callInstance('onConnection', {
88
- name: name,
89
- networkId: networkId,
90
- version: version
91
- }, function () {
92
- client.updateInfo({
93
- status: RPC_STATUS.CONNECTED
94
- });
95
- return {
96
- result: instance.getWalletInfo()
97
- };
98
- }, function (error) {
99
44
  client.updateInfo({
100
- status: RPC_STATUS.CONNECTION_REJECTED
45
+ status: RPC_STATUS.WAITING_FOR_CONNECTION_APPROVE,
46
+ name,
47
+ networkId,
48
+ icons,
49
+ version
50
+ }); // Call onConnection callBack to notice Wallet about new AEPP
51
+
52
+ return callInstance('onConnection', {
53
+ name,
54
+ networkId,
55
+ version
56
+ }, () => {
57
+ client.updateInfo({
58
+ status: RPC_STATUS.CONNECTED
59
+ });
60
+ return {
61
+ result: instance.getWalletInfo()
62
+ };
63
+ }, error => {
64
+ client.updateInfo({
65
+ status: RPC_STATUS.CONNECTION_REJECTED
66
+ });
67
+ return {
68
+ error: ERRORS.connectionDeny(error)
69
+ };
101
70
  });
102
- return {
103
- error: ERRORS.connectionDeny(error)
71
+ },
72
+
73
+ [METHODS.aepp.subscribeAddress](callInstance, instance, client, _ref3) {
74
+ let {
75
+ type,
76
+ value
77
+ } = _ref3;
78
+ // Authorization check
79
+ if (!client.isConnected()) return {
80
+ error: ERRORS.notAuthorize()
104
81
  };
105
- });
106
- }), _defineProperty(_REQUESTS, METHODS.aepp.subscribeAddress, function (callInstance, instance, client, _ref4) {
107
- var type = _ref4.type,
108
- value = _ref4.value;
109
- // Authorization check
110
- if (!client.isConnected()) return {
111
- error: ERRORS.notAuthorize()
112
- };
113
- return callInstance('onSubscription', {
114
- type: type,
115
- value: value
116
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
117
- var _ref6,
118
- accounts,
119
- clientAccounts,
120
- subscription,
121
- _args2 = arguments;
122
-
123
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
124
- while (1) {
125
- switch (_context2.prev = _context2.next) {
126
- case 0:
127
- _ref6 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, accounts = _ref6.accounts;
128
- _context2.prev = 1;
129
- clientAccounts = accounts || instance.getAccounts();
130
-
131
- if (isValidAccounts(clientAccounts)) {
132
- _context2.next = 5;
133
- break;
134
- }
135
-
136
- throw new Error('Invalid provided accounts object');
137
-
138
- case 5:
139
- subscription = client.updateSubscription(type, value);
140
- client.setAccounts(clientAccounts, {
141
- forceNotification: true
142
- });
143
- return _context2.abrupt("return", {
144
- result: {
145
- subscription: subscription,
146
- address: clientAccounts
147
- }
148
- });
149
-
150
- case 10:
151
- _context2.prev = 10;
152
- _context2.t0 = _context2["catch"](1);
153
- console.error(_context2.t0);
154
- return _context2.abrupt("return", {
155
- error: ERRORS.internalError({
156
- msg: _context2.t0.message
157
- })
158
- });
159
-
160
- case 14:
161
- case "end":
162
- return _context2.stop();
163
- }
82
+ return callInstance('onSubscription', {
83
+ type,
84
+ value
85
+ }, async function () {
86
+ let {
87
+ accounts
88
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
89
+
90
+ try {
91
+ const clientAccounts = accounts || instance.getAccounts();
92
+ if (!isValidAccounts(clientAccounts)) throw new Error('Invalid provided accounts object');
93
+ const subscription = client.updateSubscription(type, value);
94
+ client.setAccounts(clientAccounts, {
95
+ forceNotification: true
96
+ });
97
+ return {
98
+ result: {
99
+ subscription,
100
+ address: clientAccounts
101
+ }
102
+ };
103
+ } catch (e) {
104
+ if (instance.debug) console.error(e);
105
+ return {
106
+ error: ERRORS.internalError({
107
+ msg: e.message
108
+ })
109
+ };
164
110
  }
165
- }, _callee2, null, [[1, 10]]);
166
- })), function (error) {
167
- return {
111
+ }, error => ({
168
112
  error: ERRORS.rejectedByUser(error)
113
+ }));
114
+ },
115
+
116
+ [METHODS.aepp.address](callInstance, instance, client) {
117
+ // Authorization check
118
+ if (!client.isConnected()) return {
119
+ error: ERRORS.notAuthorize()
169
120
  };
170
- });
171
- }), _defineProperty(_REQUESTS, METHODS.aepp.address, function (callInstance, instance, client) {
172
- // Authorization check
173
- if (!client.isConnected()) return {
174
- error: ERRORS.notAuthorize()
175
- };
176
- if (!client.isSubscribed()) return {
177
- error: ERRORS.notAuthorize()
178
- };
179
- return callInstance('onAskAccounts', {}, function () {
180
- var _context3;
181
-
182
- var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
183
- accounts = _ref7.accounts;
184
-
185
- return {
186
- result: accounts || _concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(_Object$keys(client.accounts.current)), _toConsumableArray(_Object$keys(client.accounts.connected)))
121
+ if (!client.isSubscribed()) return {
122
+ error: ERRORS.notAuthorize()
187
123
  };
188
- }, function (error) {
189
- return {
124
+ return callInstance('onAskAccounts', {}, function () {
125
+ let {
126
+ accounts
127
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
128
+ return {
129
+ result: accounts || [...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)]
130
+ };
131
+ }, error => ({
190
132
  error: ERRORS.rejectedByUser(error)
191
- };
192
- });
193
- }), _defineProperty(_REQUESTS, METHODS.aepp.sign, function (callInstance, instance, client, _ref8) {
194
- var tx = _ref8.tx,
195
- onAccount = _ref8.onAccount,
196
- networkId = _ref8.networkId,
197
- _ref8$returnSigned = _ref8.returnSigned,
198
- returnSigned = _ref8$returnSigned === void 0 ? false : _ref8$returnSigned;
199
- var address = onAccount || client.currentAccount; // Update client with new networkId
200
-
201
- networkId && client.updateInfo({
202
- networkId: networkId
203
- }); // Authorization check
204
-
205
- if (!client.isConnected()) return {
206
- error: ERRORS.notAuthorize()
207
- }; // Account permission check
208
-
209
- if (!client.hasAccessToAccount(address)) return {
210
- error: ERRORS.permissionDeny({
211
- account: address
212
- })
213
- }; // NetworkId check
214
-
215
- if (!networkId || networkId !== instance.getNetworkId()) return {
216
- error: ERRORS.unsupportedNetwork()
217
- };
218
- return callInstance('onSign', {
219
- tx: tx,
220
- returnSigned: returnSigned,
221
- onAccount: address,
222
- txObject: TxObject.fromString(tx)
223
- }, /*#__PURE__*/function () {
224
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(rawTx) {
225
- var opt,
226
- onAcc,
227
- validationResult,
228
- _args3 = arguments;
229
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
230
- while (1) {
231
- switch (_context4.prev = _context4.next) {
232
- case 0:
233
- opt = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
234
- _context4.prev = 1;
235
- onAcc = resolveOnAccount(instance.addresses(), address, opt);
236
- _context4.next = 9;
237
- break;
238
-
239
- case 5:
240
- _context4.prev = 5;
241
- _context4.t0 = _context4["catch"](1);
242
- console.error(_context4.t0);
243
- return _context4.abrupt("return", {
244
- error: ERRORS.internalError({
245
- msg: _context4.t0.message
246
- })
247
- });
248
-
249
- case 9:
250
- _context4.prev = 9;
251
- _context4.t1 = _objectSpread;
252
- _context4.t2 = {};
253
-
254
- if (!returnSigned) {
255
- _context4.next = 19;
256
- break;
257
- }
258
-
259
- _context4.next = 15;
260
- return instance.signTransaction(rawTx || tx, {
261
- onAccount: onAcc
262
- });
263
-
264
- case 15:
265
- _context4.t4 = _context4.sent;
266
- _context4.t3 = {
267
- signedTransaction: _context4.t4
268
- };
269
- _context4.next = 23;
270
- break;
271
-
272
- case 19:
273
- _context4.next = 21;
274
- return instance.send(rawTx || tx, {
275
- onAccount: onAcc,
276
- verify: false
277
- });
278
-
279
- case 21:
280
- _context4.t5 = _context4.sent;
281
- _context4.t3 = {
282
- transactionHash: _context4.t5
283
- };
284
-
285
- case 23:
286
- _context4.t6 = _context4.t3;
287
- _context4.t7 = (0, _context4.t1)(_context4.t2, _context4.t6);
288
- return _context4.abrupt("return", {
289
- result: _context4.t7
290
- });
291
-
292
- case 28:
293
- _context4.prev = 28;
294
- _context4.t8 = _context4["catch"](9);
295
-
296
- if (returnSigned) {
297
- _context4.next = 37;
298
- break;
299
- }
300
-
301
- _context4.next = 33;
302
- return instance.unpackAndVerify(rawTx || tx);
303
-
304
- case 33:
305
- validationResult = _context4.sent;
306
-
307
- if (!validationResult.validation.length) {
308
- _context4.next = 36;
309
- break;
310
- }
311
-
312
- return _context4.abrupt("return", {
313
- error: ERRORS.invalidTransaction(validationResult)
314
- });
315
-
316
- case 36:
317
- return _context4.abrupt("return", {
318
- error: ERRORS.broadcastFailed(_context4.t8.message)
319
- });
320
-
321
- case 37:
322
- throw _context4.t8;
323
-
324
- case 38:
325
- case "end":
326
- return _context4.stop();
327
- }
328
- }
329
- }, _callee3, null, [[1, 5], [9, 28]]);
330
133
  }));
134
+ },
331
135
 
332
- return function (_x2) {
333
- return _ref9.apply(this, arguments);
334
- };
335
- }(), function (error) {
336
- return {
337
- error: ERRORS.rejectedByUser(error)
338
- };
339
- });
340
- }), _defineProperty(_REQUESTS, METHODS.aepp.signMessage, function (callInstance, instance, client, _ref10) {
341
- var message = _ref10.message,
342
- onAccount = _ref10.onAccount;
343
- // Authorization check
344
- if (!client.isConnected()) return {
345
- error: ERRORS.notAuthorize()
346
- };
347
- var address = onAccount || client.currentAccount;
348
- if (!client.hasAccessToAccount(address)) return {
349
- error: ERRORS.permissionDeny({
350
- account: address
351
- })
352
- };
353
- return callInstance('onMessageSign', {
354
- message: message,
355
- onAccount: address
356
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
357
- var opt,
358
- onAcc,
359
- _args4 = arguments;
360
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
361
- while (1) {
362
- switch (_context5.prev = _context5.next) {
363
- case 0:
364
- opt = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
365
- _context5.prev = 1;
366
- onAcc = resolveOnAccount(instance.addresses(), address, opt);
367
- _context5.next = 5;
368
- return instance.signMessage(message, {
369
- onAccount: onAcc,
370
- returnHex: true
371
- });
136
+ [METHODS.aepp.sign](callInstance, instance, client, options) {
137
+ const {
138
+ tx,
139
+ onAccount,
140
+ networkId,
141
+ returnSigned = false
142
+ } = options;
143
+ const address = onAccount || client.currentAccount; // Update client with new networkId
372
144
 
373
- case 5:
374
- _context5.t0 = _context5.sent;
375
- _context5.t1 = {
376
- signature: _context5.t0
377
- };
378
- return _context5.abrupt("return", {
379
- result: _context5.t1
380
- });
381
-
382
- case 10:
383
- _context5.prev = 10;
384
- _context5.t2 = _context5["catch"](1);
385
- console.error(_context5.t2);
386
- return _context5.abrupt("return", {
387
- error: ERRORS.internalError({
388
- msg: _context5.t2.message
389
- })
390
- });
391
-
392
- case 14:
393
- case "end":
394
- return _context5.stop();
145
+ networkId && client.updateInfo({
146
+ networkId
147
+ }); // Authorization check
148
+
149
+ if (!client.isConnected()) return {
150
+ error: ERRORS.notAuthorize()
151
+ }; // Account permission check
152
+
153
+ if (!client.hasAccessToAccount(address)) {
154
+ return {
155
+ error: ERRORS.permissionDeny({
156
+ account: address
157
+ })
158
+ };
159
+ } // NetworkId check
160
+
161
+
162
+ if (!networkId || networkId !== instance.getNetworkId()) {
163
+ return {
164
+ error: ERRORS.unsupportedNetwork()
165
+ };
166
+ }
167
+
168
+ return callInstance('onSign', {
169
+ tx,
170
+ returnSigned,
171
+ onAccount: address,
172
+ txObject: TxObject.fromString(tx)
173
+ }, async function (rawTx) {
174
+ let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
175
+ let onAcc;
176
+
177
+ try {
178
+ onAcc = resolveOnAccount(instance.addresses(), address, opt);
179
+ } catch (e) {
180
+ if (instance.debug) console.error(e);
181
+ return {
182
+ error: ERRORS.internalError({
183
+ msg: e.message
184
+ })
185
+ };
186
+ }
187
+
188
+ try {
189
+ const t = rawTx || tx;
190
+ const result = returnSigned ? {
191
+ signedTransaction: await instance.signTransaction(t, {
192
+ onAccount: onAcc
193
+ })
194
+ } : {
195
+ transactionHash: await instance.send(t, {
196
+ onAccount: onAcc,
197
+ verify: false
198
+ })
199
+ };
200
+ return {
201
+ result
202
+ };
203
+ } catch (e) {
204
+ if (!returnSigned) {
205
+ // Validate transaction
206
+ const validation = await verifyTransaction(rawTx || tx, instance.selectedNode.instance);
207
+ if (validation.length) return {
208
+ error: ERRORS.invalidTransaction(validation)
209
+ }; // Send broadcast failed error to aepp
210
+
211
+ return {
212
+ error: ERRORS.broadcastFailed(e.message)
213
+ };
395
214
  }
215
+
216
+ throw e;
396
217
  }
397
- }, _callee4, null, [[1, 10]]);
398
- })), function (error) {
399
- return {
218
+ }, error => ({
400
219
  error: ERRORS.rejectedByUser(error)
220
+ }));
221
+ },
222
+
223
+ [METHODS.aepp.signMessage](callInstance, instance, client, _ref4) {
224
+ let {
225
+ message,
226
+ onAccount
227
+ } = _ref4;
228
+ // Authorization check
229
+ if (!client.isConnected()) return {
230
+ error: ERRORS.notAuthorize()
401
231
  };
402
- });
403
- }), _REQUESTS);
404
-
405
- var handleMessage = function handleMessage(instance, id) {
406
- return /*#__PURE__*/function () {
407
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(msg, origin) {
408
- var client, _id, method, callInstance, errorObjectOrHandler, response;
409
-
410
- return _regeneratorRuntime.wrap(function _callee5$(_context6) {
411
- while (1) {
412
- switch (_context6.prev = _context6.next) {
413
- case 0:
414
- client = instance.rpcClients[id];
415
-
416
- if (msg.id) {
417
- _context6.next = 3;
418
- break;
419
- }
420
-
421
- return _context6.abrupt("return", getHandler(NOTIFICATIONS, msg, {
422
- debug: instance.debug
423
- })(instance, {
424
- client: client
425
- })(msg, origin));
426
-
427
- case 3:
428
- if (!Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
429
- _context6.next = 7;
430
- break;
431
- }
432
-
433
- return _context6.abrupt("return", getHandler(RESPONSES, msg, {
434
- debug: instance.debug
435
- })(instance, {
436
- client: client
437
- })(msg, origin));
438
-
439
- case 7:
440
- _id = msg.id, method = msg.method;
441
-
442
- callInstance = function callInstance(methodName, params, _accept, _deny) {
443
- return function () {
444
- return new _Promise(function (resolve) {
445
- instance[methodName](client, {
446
- id: _id,
447
- method: method,
448
- params: params,
449
- accept: function accept() {
450
- return resolve(_accept.apply(void 0, arguments));
451
- },
452
- deny: function deny() {
453
- return resolve(_deny.apply(void 0, arguments));
454
- }
455
- }, origin);
456
- });
457
- };
458
- }; // TODO make one structure for handler functions
459
-
460
-
461
- errorObjectOrHandler = getHandler(REQUESTS, msg, {
462
- debug: instance.debug
463
- })(callInstance, instance, client, msg.params);
464
-
465
- if (!(typeof errorObjectOrHandler === 'function')) {
466
- _context6.next = 16;
467
- break;
468
- }
469
-
470
- _context6.next = 13;
471
- return errorObjectOrHandler();
472
-
473
- case 13:
474
- _context6.t0 = _context6.sent;
475
- _context6.next = 17;
476
- break;
477
-
478
- case 16:
479
- _context6.t0 = errorObjectOrHandler;
480
-
481
- case 17:
482
- response = _context6.t0;
483
- sendResponseMessage(client)(_id, method, response);
484
-
485
- case 19:
486
- case "end":
487
- return _context6.stop();
232
+ const address = onAccount || client.currentAccount;
233
+
234
+ if (!client.hasAccessToAccount(address)) {
235
+ return {
236
+ error: ERRORS.permissionDeny({
237
+ account: address
238
+ })
239
+ };
240
+ }
241
+
242
+ return callInstance('onMessageSign', {
243
+ message,
244
+ onAccount: address
245
+ }, async function () {
246
+ let opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
247
+
248
+ try {
249
+ const onAcc = resolveOnAccount(instance.addresses(), address, opt);
250
+ return {
251
+ result: {
252
+ signature: await instance.signMessage(message, {
253
+ onAccount: onAcc,
254
+ returnHex: true
255
+ })
488
256
  }
489
- }
490
- }, _callee5);
257
+ };
258
+ } catch (e) {
259
+ if (instance.debug) console.error(e);
260
+ return {
261
+ error: ERRORS.internalError({
262
+ msg: e.message
263
+ })
264
+ };
265
+ }
266
+ }, error => ({
267
+ error: ERRORS.rejectedByUser(error)
491
268
  }));
269
+ }
492
270
 
493
- return function (_x3, _x4) {
494
- return _ref12.apply(this, arguments);
495
- };
496
- }();
271
+ };
272
+
273
+ const handleMessage = (instance, id) => async (msg, origin) => {
274
+ const client = instance.rpcClients[id];
275
+
276
+ if (!msg.id) {
277
+ return getHandler(NOTIFICATIONS, msg, {
278
+ debug: instance.debug
279
+ })(instance, {
280
+ client
281
+ })(msg, origin);
282
+ }
283
+
284
+ if (Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
285
+ return getHandler(RESPONSES, msg, {
286
+ debug: instance.debug
287
+ })(instance, {
288
+ client
289
+ })(msg, origin);
290
+ } else {
291
+ const {
292
+ id,
293
+ method
294
+ } = msg;
295
+
296
+ const callInstance = (methodName, params, accept, deny) => () => new Promise(resolve => {
297
+ instance[methodName](client, {
298
+ id,
299
+ method,
300
+ params,
301
+ accept: function () {
302
+ return resolve(accept(...arguments));
303
+ },
304
+ deny: function () {
305
+ return resolve(deny(...arguments));
306
+ }
307
+ }, origin);
308
+ }); // TODO make one structure for handler functions
309
+
310
+
311
+ const errorObjectOrHandler = getHandler(REQUESTS, msg, {
312
+ debug: instance.debug
313
+ })(callInstance, instance, client, msg.params);
314
+ const response = typeof errorObjectOrHandler === 'function' ? await errorObjectOrHandler() : errorObjectOrHandler;
315
+ sendResponseMessage(client)(id, method, response);
316
+ }
497
317
  };
498
318
  /**
499
319
  * Contain functionality for aepp interaction and managing multiple aepps
@@ -502,38 +322,34 @@ var handleMessage = function handleMessage(instance, id) {
502
322
  * @rtype Stamp
503
323
  * @param {Object} param Init params object
504
324
  * @param {String=} [param.name] Wallet name
505
- * @param {Function} onConnection Call-back function for incoming AEPP connection (Second argument contain function for accept/deny request)
506
- * @param {Function} onSubscription Call-back function for incoming AEPP account subscription (Second argument contain function for accept/deny request)
507
- * @param {Function} onSign Call-back function for incoming AEPP sign request (Second argument contain function for accept/deny request)
508
- * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request (Second argument contain function for accept/deny request)
509
- * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request (Second argument contain function for accept/deny request)
325
+ * @param {Function} onConnection Call-back function for incoming AEPP connection
326
+ * @param {Function} onSubscription Call-back function for incoming AEPP account subscription
327
+ * @param {Function} onSign Call-back function for incoming AEPP sign request
328
+ * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
329
+ * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
330
+ * Second argument of incoming call-backs contain function for accept/deny request
510
331
  * @param {Function} onDisconnect Call-back function for disconnect event
511
332
  * @return {Object}
512
333
  */
513
334
 
514
335
 
515
336
  export default Ae.compose(AccountMultiple, {
516
- init: function init() {
517
- var _this = this,
518
- _context7,
519
- _context8,
520
- _context9;
521
-
522
- var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
523
- name = _ref13.name,
524
- onConnection = _ref13.onConnection,
525
- onSubscription = _ref13.onSubscription,
526
- onSign = _ref13.onSign,
527
- onDisconnect = _ref13.onDisconnect,
528
- onAskAccounts = _ref13.onAskAccounts,
529
- onMessageSign = _ref13.onMessageSign,
530
- _ref13$forceValidatio = _ref13.forceValidation,
531
- forceValidation = _ref13$forceValidatio === void 0 ? false : _ref13$forceValidatio,
532
- _ref13$debug = _ref13.debug,
533
- debug = _ref13$debug === void 0 ? false : _ref13$debug;
534
-
337
+ init() {
338
+ var _this = this;
339
+
340
+ let {
341
+ name,
342
+ onConnection,
343
+ onSubscription,
344
+ onSign,
345
+ onDisconnect,
346
+ onAskAccounts,
347
+ onMessageSign,
348
+ forceValidation = false,
349
+ debug = false
350
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
535
351
  this.debug = debug;
536
- var eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']; // CallBacks for events
352
+ const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']; // CallBacks for events
537
353
 
538
354
  this.onConnection = onConnection;
539
355
  this.onSubscription = onSubscription;
@@ -542,127 +358,81 @@ export default Ae.compose(AccountMultiple, {
542
358
  this.onAskAccounts = onAskAccounts;
543
359
  this.onMessageSign = onMessageSign;
544
360
  this.rpcClients = {};
545
-
546
- _forEachInstanceProperty(eventsHandlers).call(eventsHandlers, function (event) {
547
- if (!forceValidation && typeof _this[event] !== 'function') throw new Error("Call-back for ".concat(event, " must be an function!"));
361
+ eventsHandlers.forEach(event => {
362
+ if (!forceValidation && typeof this[event] !== 'function') {
363
+ throw new Error(`Call-back for ${event} must be an function!`);
364
+ }
548
365
  }); //
549
366
 
550
-
551
367
  this.name = name;
552
368
  this.id = uuid();
553
369
 
554
- var _selectAccount = _bindInstanceProperty(_context7 = this.selectAccount).call(_context7, this);
370
+ const _selectAccount = this.selectAccount.bind(this);
555
371
 
556
- var _addAccount = _bindInstanceProperty(_context8 = this.addAccount).call(_context8, this);
372
+ const _addAccount = this.addAccount.bind(this);
557
373
 
558
- var _selectNode = _bindInstanceProperty(_context9 = this.selectNode).call(_context9, this); // Overwrite AE methods
374
+ const _selectNode = this.selectNode.bind(this); // Overwrite AE methods
559
375
 
560
376
 
561
377
  this.selectAccount = function (address) {
562
- var _context10, _context11;
563
-
564
- var _ref14 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
565
- _ref14$condition = _ref14.condition,
566
- condition = _ref14$condition === void 0 ? function () {
567
- return true;
568
- } : _ref14$condition;
378
+ let {
379
+ condition = () => true
380
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
569
381
 
570
382
  _selectAccount(address);
571
383
 
572
- _forEachInstanceProperty(_context10 = _filterInstanceProperty(_context11 = _Object$values(_this.rpcClients)).call(_context11, function (client) {
573
- return client.isConnected() && client.isSubscribed() && client.hasAccessToAccount(address) && condition(client);
574
- })).call(_context10, function (client) {
575
- var _context12, _context13;
576
-
577
- return client.setAccounts({
578
- current: _defineProperty({}, address, {}),
579
- connected: _objectSpread(_objectSpread({}, client.accounts.current), _reduceInstanceProperty(_context12 = _filterInstanceProperty(_context13 = _Object$entries(client.accounts.connected)).call(_context13, function (_ref15) {
580
- var _ref16 = _slicedToArray(_ref15, 2),
581
- k = _ref16[0],
582
- v = _ref16[1];
583
-
384
+ Object.values(_this.rpcClients).filter(client => client.isConnected() && client.isSubscribed() && client.hasAccessToAccount(address) && condition(client)).forEach(client => client.setAccounts({
385
+ current: {
386
+ [address]: {}
387
+ },
388
+ connected: { ...client.accounts.current,
389
+ ...Object.entries(client.accounts.connected).filter(_ref5 => {
390
+ let [k, v] = _ref5;
584
391
  return k !== address;
585
- })).call(_context12, function (acc, _ref17) {
586
- var _ref18 = _slicedToArray(_ref17, 2),
587
- k = _ref18[0],
588
- v = _ref18[1];
392
+ }).reduce((acc, _ref6) => {
393
+ let [k, v] = _ref6;
394
+ return { ...acc,
395
+ [k]: v
396
+ };
397
+ }, {})
398
+ }
399
+ }));
400
+ };
589
401
 
590
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, k, v));
591
- }, {}))
592
- });
402
+ this.addAccount = async function (account) {
403
+ let {
404
+ select,
405
+ meta = {},
406
+ condition = () => true
407
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
408
+ await _addAccount(account, {
409
+ select
593
410
  });
594
- };
411
+ const address = await account.address(); // Send notification 'update.address' to all Aepp which are subscribed for connected accounts
595
412
 
596
- this.addAccount = /*#__PURE__*/function () {
597
- var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(account) {
598
- var _context14, _context15;
599
-
600
- var _ref20,
601
- select,
602
- _ref20$meta,
603
- meta,
604
- _ref20$condition,
605
- condition,
606
- address,
607
- _args6 = arguments;
608
-
609
- return _regeneratorRuntime.wrap(function _callee6$(_context16) {
610
- while (1) {
611
- switch (_context16.prev = _context16.next) {
612
- case 0:
613
- _ref20 = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {}, select = _ref20.select, _ref20$meta = _ref20.meta, meta = _ref20$meta === void 0 ? {} : _ref20$meta, _ref20$condition = _ref20.condition, condition = _ref20$condition === void 0 ? function () {
614
- return true;
615
- } : _ref20$condition;
616
- _context16.next = 3;
617
- return _addAccount(account, {
618
- select: select
619
- });
620
-
621
- case 3:
622
- _context16.next = 5;
623
- return account.address();
624
-
625
- case 5:
626
- address = _context16.sent;
627
-
628
- // Send notification 'update.address' to all Aepp which are subscribed for connected accounts
629
- _forEachInstanceProperty(_context14 = _filterInstanceProperty(_context15 = _Object$values(_this.rpcClients)).call(_context15, function (client) {
630
- return client.isConnected() && client.isSubscribed() && condition(client);
631
- })).call(_context14, function (client) {
632
- return client.setAccounts({
633
- current: _objectSpread({}, select ? _defineProperty({}, address, meta) : client.accounts.current),
634
- connected: _objectSpread(_objectSpread({}, select ? client.accounts.current : _defineProperty({}, address, meta)), client.accounts.connected)
635
- });
636
- });
637
-
638
- case 7:
639
- case "end":
640
- return _context16.stop();
641
- }
642
- }
643
- }, _callee6);
413
+ Object.values(_this.rpcClients).filter(client => client.isConnected() && client.isSubscribed() && condition(client)).forEach(client => client.setAccounts({
414
+ current: { ...(select ? {
415
+ [address]: meta
416
+ } : client.accounts.current)
417
+ },
418
+ connected: { ...(select ? client.accounts.current : {
419
+ [address]: meta
420
+ }),
421
+ ...client.accounts.connected
422
+ }
644
423
  }));
424
+ };
645
425
 
646
- return function (_x5) {
647
- return _ref19.apply(this, arguments);
648
- };
649
- }();
650
-
651
- this.selectNode = function (name) {
652
- var _context17, _context18;
653
-
426
+ this.selectNode = name => {
654
427
  _selectNode(name); // Send notification 'update.network' to all Aepp which connected
655
428
 
656
429
 
657
- _forEachInstanceProperty(_context17 = _filterInstanceProperty(_context18 = _Object$values(_this.rpcClients)).call(_context18, function (client) {
658
- return client.isConnected();
659
- })).call(_context17, function (client) {
660
- return client.sendMessage(message(METHODS.updateNetwork, {
661
- networkId: _this.getNetworkId()
662
- }), true);
663
- });
430
+ Object.values(this.rpcClients).filter(client => client.isConnected()).forEach(client => client.sendMessage(message(METHODS.updateNetwork, {
431
+ networkId: this.getNetworkId()
432
+ }), true));
664
433
  };
665
434
  },
435
+
666
436
  methods: {
667
437
  /**
668
438
  * Remove specific RpcClient by ID
@@ -673,13 +443,12 @@ export default Ae.compose(AccountMultiple, {
673
443
  * @param {Object} [opt = {}]
674
444
  * @return {void}
675
445
  */
676
- removeRpcClient: function removeRpcClient(id) {
677
- var _ref23 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
678
- _ref23$forceConnectio = _ref23.forceConnectionClose,
679
- forceConnectionClose = _ref23$forceConnectio === void 0 ? false : _ref23$forceConnectio;
680
-
681
- var client = this.rpcClients[id];
682
- if (!client) throw new Error("RpcClient with id ".concat(id, " do not exist"));
446
+ removeRpcClient(id) {
447
+ let {
448
+ forceConnectionClose = false
449
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
450
+ const client = this.rpcClients[id];
451
+ if (!client) throw new Error(`RpcClient with id ${id} do not exist`);
683
452
  client.disconnect(forceConnectionClose);
684
453
  delete this.rpcClients[id];
685
454
  },
@@ -692,11 +461,12 @@ export default Ae.compose(AccountMultiple, {
692
461
  * @param {Object} clientConnection AEPP connection object
693
462
  * @return {String} Client ID
694
463
  */
695
- addRpcClient: function addRpcClient(clientConnection) {
696
- // @TODO detect if aepp has some history based on origin????: if yes use this instance for connection
697
- var id = uuid();
464
+ addRpcClient(clientConnection) {
465
+ // @TODO detect if aepp has some history based on origin????
466
+ // if yes use this instance for connection
467
+ const id = uuid();
698
468
  this.rpcClients[id] = RpcClient({
699
- id: id,
469
+ id,
700
470
  info: {
701
471
  status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST
702
472
  },
@@ -715,10 +485,11 @@ export default Ae.compose(AccountMultiple, {
715
485
  * @param {Function} postFn Send message function like `(msg) => void`
716
486
  * @return {void}
717
487
  */
718
- shareWalletInfo: function shareWalletInfo(postFn) {
719
- postFn(_objectSpread({
720
- jsonrpc: '2.0'
721
- }, message(METHODS.wallet.readyToConnect, this.getWalletInfo())));
488
+ shareWalletInfo(postFn) {
489
+ postFn({
490
+ jsonrpc: '2.0',
491
+ ...message(METHODS.wallet.readyToConnect, this.getWalletInfo())
492
+ });
722
493
  },
723
494
 
724
495
  /**
@@ -728,8 +499,8 @@ export default Ae.compose(AccountMultiple, {
728
499
  * @rtype () => Object
729
500
  * @return {Object} Object with wallet information(id, name, network, ...)
730
501
  */
731
- getWalletInfo: function getWalletInfo() {
732
- var runtime = getBrowserAPI(true).runtime;
502
+ getWalletInfo() {
503
+ const runtime = getBrowserAPI(true).runtime;
733
504
  return {
734
505
  id: runtime && runtime.id ? runtime.id : this.id,
735
506
  name: this.name,
@@ -746,20 +517,17 @@ export default Ae.compose(AccountMultiple, {
746
517
  * @rtype () => Object
747
518
  * @return {Object} Object with accounts information({ connected: Object, current: Object })
748
519
  */
749
- getAccounts: function getAccounts() {
750
- var _context19,
751
- _context20,
752
- _this2 = this;
753
-
520
+ getAccounts() {
754
521
  return {
755
- current: this.selectedAddress ? _defineProperty({}, this.selectedAddress, {}) : {},
756
- connected: _reduceInstanceProperty(_context19 = _filterInstanceProperty(_context20 = this.addresses()).call(_context20, function (a) {
757
- return a !== _this2.selectedAddress;
758
- })).call(_context19, function (acc, a) {
759
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, a, {}));
760
- }, {})
522
+ current: this.selectedAddress ? {
523
+ [this.selectedAddress]: {}
524
+ } : {},
525
+ connected: this.addresses().filter(a => a !== this.selectedAddress).reduce((acc, a) => ({ ...acc,
526
+ [a]: {}
527
+ }), {})
761
528
  };
762
529
  }
530
+
763
531
  }
764
532
  });
765
533
  //# sourceMappingURL=wallet-rpc.js.map