@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.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.
Files changed (145) hide show
  1. package/README.md +16 -9
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.js +33 -119
  10. package/es/account/base.js.map +1 -1
  11. package/es/account/memory.js +17 -19
  12. package/es/account/memory.js.map +1 -1
  13. package/es/account/multiple.js +75 -154
  14. package/es/account/multiple.js.map +1 -1
  15. package/es/ae/aens.js +164 -599
  16. package/es/ae/aens.js.map +1 -1
  17. package/es/ae/contract.js +108 -916
  18. package/es/ae/contract.js.map +1 -1
  19. package/es/ae/index.js +89 -250
  20. package/es/ae/index.js.map +1 -1
  21. package/es/ae/oracle.js +132 -500
  22. package/es/ae/oracle.js.map +1 -1
  23. package/es/chain/index.js +4 -23
  24. package/es/chain/index.js.map +1 -1
  25. package/es/chain/node.js +292 -1018
  26. package/es/chain/node.js.map +1 -1
  27. package/es/channel/handlers.js +597 -1086
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/channel/index.js +203 -451
  30. package/es/channel/index.js.map +1 -1
  31. package/es/channel/internal.js +129 -301
  32. package/es/channel/internal.js.map +1 -1
  33. package/es/contract/aci/index.js +319 -491
  34. package/es/contract/aci/index.js.map +1 -1
  35. package/es/contract/aci/transformation.js +35 -711
  36. package/es/contract/aci/transformation.js.map +1 -1
  37. package/es/contract/compiler.js +129 -203
  38. package/es/contract/compiler.js.map +1 -1
  39. package/es/contract/ga/helpers.js +17 -122
  40. package/es/contract/ga/helpers.js.map +1 -1
  41. package/es/contract/ga/index.js +102 -247
  42. package/es/contract/ga/index.js.map +1 -1
  43. package/es/contract/index.js +1 -1
  44. package/es/contract/index.js.map +1 -1
  45. package/es/index.js +2 -3
  46. package/es/index.js.map +1 -1
  47. package/es/node-pool/index.js +54 -73
  48. package/es/node-pool/index.js.map +1 -1
  49. package/es/node.js +56 -157
  50. package/es/node.js.map +1 -1
  51. package/es/other.d.ts +1 -1
  52. package/es/tx/builder/helpers.js +49 -89
  53. package/es/tx/builder/helpers.js.map +1 -1
  54. package/es/tx/builder/index.js +205 -303
  55. package/es/tx/builder/index.js.map +1 -1
  56. package/es/tx/builder/schema.js +585 -573
  57. package/es/tx/builder/schema.js.map +1 -1
  58. package/es/tx/index.js +1 -1
  59. package/es/tx/index.js.map +1 -1
  60. package/es/tx/tx-object.js +105 -135
  61. package/es/tx/tx-object.js.map +1 -1
  62. package/es/tx/tx.js +810 -1586
  63. package/es/tx/tx.js.map +1 -1
  64. package/es/tx/validator.js +191 -426
  65. package/es/tx/validator.js.map +1 -1
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  67. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  69. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  71. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  73. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  75. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  77. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
  79. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  81. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  83. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  84. package/es/utils/amount-formatter.js +41 -61
  85. package/es/utils/amount-formatter.js.map +1 -1
  86. package/es/utils/async-init.js +28 -64
  87. package/es/utils/async-init.js.map +1 -1
  88. package/es/utils/bignumber.js +3 -11
  89. package/es/utils/bignumber.js.map +1 -1
  90. package/es/utils/bytes.js +5 -9
  91. package/es/utils/bytes.js.map +1 -1
  92. package/es/utils/crypto.js +49 -75
  93. package/es/utils/crypto.js.map +1 -1
  94. package/es/utils/hd-wallet.js +45 -81
  95. package/es/utils/hd-wallet.js.map +1 -1
  96. package/es/utils/json-big.js +16 -49
  97. package/es/utils/json-big.js.map +1 -1
  98. package/es/utils/keystore.js +81 -246
  99. package/es/utils/keystore.js.map +1 -1
  100. package/es/utils/mptree.js +88 -134
  101. package/es/utils/mptree.js.map +1 -1
  102. package/es/utils/other.js +10 -60
  103. package/es/utils/other.js.map +1 -1
  104. package/es/utils/semver-satisfies.js +9 -28
  105. package/es/utils/semver-satisfies.js.map +1 -1
  106. package/es/utils/string.js +4 -13
  107. package/es/utils/string.js.map +1 -1
  108. package/es/utils/swagger.js +85 -218
  109. package/es/utils/swagger.js.map +1 -1
  110. package/package.json +52 -43
  111. package/src/account/base.js +8 -9
  112. package/src/account/multiple.js +20 -16
  113. package/src/ae/aens.js +25 -21
  114. package/src/ae/contract.js +65 -246
  115. package/src/ae/index.js +31 -7
  116. package/src/ae/oracle.js +21 -17
  117. package/src/chain/index.js +2 -12
  118. package/src/chain/node.js +26 -29
  119. package/src/channel/handlers.js +0 -1
  120. package/src/channel/index.js +4 -5
  121. package/src/contract/aci/index.js +221 -106
  122. package/src/contract/aci/transformation.js +30 -422
  123. package/src/contract/compiler.js +45 -4
  124. package/src/contract/ga/helpers.js +2 -12
  125. package/src/contract/ga/index.js +22 -26
  126. package/src/index.js +2 -4
  127. package/src/node-pool/index.js +21 -12
  128. package/src/node.js +22 -26
  129. package/src/tx/builder/helpers.js +12 -24
  130. package/src/tx/builder/index.js +18 -15
  131. package/src/tx/builder/schema.js +43 -108
  132. package/src/tx/tx-object.js +0 -2
  133. package/src/tx/tx.js +157 -144
  134. package/src/tx/validator.js +134 -202
  135. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  136. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
  137. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  138. package/src/utils/amount-formatter.ts +1 -1
  139. package/src/utils/bignumber.ts +2 -1
  140. package/src/utils/crypto.js +4 -17
  141. package/src/utils/other.ts +1 -1
  142. package/src/utils/semver-satisfies.ts +1 -1
  143. package/src/utils/swagger.js +24 -7
  144. package/CHANGELOG.md +0 -1716
  145. package/src/contract/aci/helpers.js +0 -140
@@ -1,130 +1,87 @@
1
- import _merge from "ramda/src/merge";
2
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
3
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
4
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
5
-
6
- var _NOTIFICATIONS, _RESPONSES;
7
-
8
- 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; }
9
-
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context13; _forEachInstanceProperty(_context13 = ownKeys(Object(source), true)).call(_context13, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context14; _forEachInstanceProperty(_context14 = ownKeys(Object(source))).call(_context14, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
11
-
12
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
13
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
14
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
15
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
16
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
17
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
18
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
19
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
20
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
21
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
1
+ /**
2
+ * RPC handler for AEPP side
3
+ *
4
+ * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc
5
+ * @export AeppRpc
6
+ * @example import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
7
+ */
22
8
  import { v4 as uuid } from 'uuid';
23
9
  import Ae from '../../../ae';
24
10
  import RpcClient from './rpc-client';
25
11
  import { getHandler, message, voidFn } from '../helpers';
26
12
  import { METHODS, RPC_STATUS, VERSION } from '../schema';
27
- var NOTIFICATIONS = (_NOTIFICATIONS = {}, _defineProperty(_NOTIFICATIONS, METHODS.wallet.updateAddress, function (instance) {
28
- return function (_ref) {
29
- var params = _ref.params;
13
+ const NOTIFICATIONS = {
14
+ [METHODS.wallet.updateAddress]: instance => _ref => {
15
+ let {
16
+ params
17
+ } = _ref;
30
18
  instance.rpcClient.accounts = params;
31
19
  instance.onAddressChange(params);
32
- };
33
- }), _defineProperty(_NOTIFICATIONS, METHODS.updateNetwork, function (instance) {
34
- return function (msg) {
20
+ },
21
+ [METHODS.updateNetwork]: instance => msg => {
35
22
  instance.rpcClient.info.networkId = msg.params.networkId;
36
23
  instance.onNetworkChange(msg.params);
37
- };
38
- }), _defineProperty(_NOTIFICATIONS, METHODS.closeConnection, function (instance) {
39
- return function (msg) {
24
+ },
25
+ [METHODS.closeConnection]: instance => msg => {
40
26
  instance.disconnectWallet();
41
27
  instance.onDisconnect(msg.params);
42
- };
43
- }), _NOTIFICATIONS);
44
- var RESPONSES = (_RESPONSES = {}, _defineProperty(_RESPONSES, METHODS.aepp.address, function (instance) {
45
- return function (msg) {
46
- return instance.rpcClient.processResponse(msg);
47
- };
48
- }), _defineProperty(_RESPONSES, METHODS.aepp.connect, function (instance) {
49
- return function (msg) {
28
+ }
29
+ };
30
+ const RESPONSES = {
31
+ [METHODS.aepp.address]: instance => msg => instance.rpcClient.processResponse(msg),
32
+ [METHODS.aepp.connect]: instance => msg => {
50
33
  if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED;
51
34
  instance.rpcClient.processResponse(msg);
52
- };
53
- }), _defineProperty(_RESPONSES, METHODS.aepp.subscribeAddress, function (instance) {
54
- return function (msg) {
35
+ },
36
+ [METHODS.aepp.subscribeAddress]: instance => msg => {
55
37
  if (msg.result) {
56
38
  msg.result.address && (instance.rpcClient.accounts = msg.result.address);
57
39
  msg.result.subscription && (instance.rpcClient.addressSubscription = msg.result.subscription);
58
40
  }
59
41
 
60
- instance.rpcClient.processResponse(msg, function (_ref2) {
61
- var id = _ref2.id,
62
- result = _ref2.result;
42
+ instance.rpcClient.processResponse(msg, _ref2 => {
43
+ let {
44
+ id,
45
+ result
46
+ } = _ref2;
63
47
  return [result];
64
48
  });
65
- };
66
- }), _defineProperty(_RESPONSES, METHODS.aepp.sign, function (instance) {
67
- return function (msg) {
68
- instance.rpcClient.processResponse(msg, function (_ref3) {
69
- var id = _ref3.id,
70
- result = _ref3.result;
49
+ },
50
+ [METHODS.aepp.sign]: instance => msg => {
51
+ instance.rpcClient.processResponse(msg, _ref3 => {
52
+ let {
53
+ id,
54
+ result
55
+ } = _ref3;
71
56
  return [result.signedTransaction || result.transactionHash];
72
57
  });
73
- };
74
- }), _defineProperty(_RESPONSES, METHODS.aepp.signMessage, function (instance) {
75
- return function (msg) {
76
- instance.rpcClient.processResponse(msg, function (_ref4) {
77
- var id = _ref4.id,
78
- result = _ref4.result;
58
+ },
59
+ [METHODS.aepp.signMessage]: instance => msg => {
60
+ instance.rpcClient.processResponse(msg, _ref4 => {
61
+ let {
62
+ id,
63
+ result
64
+ } = _ref4;
79
65
  return [result.signature];
80
66
  });
81
- };
82
- }), _RESPONSES);
83
- var REQUESTS = {};
84
-
85
- var handleMessage = function handleMessage(instance) {
86
- return /*#__PURE__*/function () {
87
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(msg) {
88
- return _regeneratorRuntime.wrap(function _callee$(_context) {
89
- while (1) {
90
- switch (_context.prev = _context.next) {
91
- case 0:
92
- if (msg.id) {
93
- _context.next = 4;
94
- break;
95
- }
96
-
97
- return _context.abrupt("return", getHandler(NOTIFICATIONS, msg, {
98
- debug: instance.debug
99
- })(instance)(msg));
100
-
101
- case 4:
102
- if (!Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {
103
- _context.next = 8;
104
- break;
105
- }
106
-
107
- return _context.abrupt("return", getHandler(RESPONSES, msg, {
108
- debug: instance.debug
109
- })(instance)(msg));
110
-
111
- case 8:
112
- return _context.abrupt("return", getHandler(REQUESTS, msg, {
113
- debug: instance.debug
114
- })(instance)(msg));
115
-
116
- case 9:
117
- case "end":
118
- return _context.stop();
119
- }
120
- }
121
- }, _callee);
122
- }));
123
-
124
- return function (_x) {
125
- return _ref5.apply(this, arguments);
126
- };
127
- }();
67
+ }
68
+ };
69
+ const REQUESTS = {};
70
+
71
+ const handleMessage = instance => async msg => {
72
+ if (!msg.id) {
73
+ return getHandler(NOTIFICATIONS, msg, {
74
+ debug: instance.debug
75
+ })(instance)(msg);
76
+ } else if (Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {
77
+ return getHandler(RESPONSES, msg, {
78
+ debug: instance.debug
79
+ })(instance)(msg);
80
+ } else {
81
+ return getHandler(REQUESTS, msg, {
82
+ debug: instance.debug
83
+ })(instance)(msg);
84
+ }
128
85
  };
129
86
  /**
130
87
  * Contain functionality for wallet interaction and connect it to sdk
@@ -142,48 +99,36 @@ var handleMessage = function handleMessage(instance) {
142
99
 
143
100
 
144
101
  export default Ae.compose({
145
- init: function init(_ref6) {
146
- var _this = this;
147
-
148
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
149
- var name, _ref6$onAddressChange, onAddressChange, _ref6$onDisconnect, onDisconnect, _ref6$onNetworkChange, onNetworkChange, connection, _ref6$forceValidation, forceValidation, _ref6$debug, debug, eventsHandlers;
150
-
151
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
152
- while (1) {
153
- switch (_context2.prev = _context2.next) {
154
- case 0:
155
- name = _ref6.name, _ref6$onAddressChange = _ref6.onAddressChange, onAddressChange = _ref6$onAddressChange === void 0 ? voidFn : _ref6$onAddressChange, _ref6$onDisconnect = _ref6.onDisconnect, onDisconnect = _ref6$onDisconnect === void 0 ? voidFn : _ref6$onDisconnect, _ref6$onNetworkChange = _ref6.onNetworkChange, onNetworkChange = _ref6$onNetworkChange === void 0 ? voidFn : _ref6$onNetworkChange, connection = _ref6.connection, _ref6$forceValidation = _ref6.forceValidation, forceValidation = _ref6$forceValidation === void 0 ? false : _ref6$forceValidation, _ref6$debug = _ref6.debug, debug = _ref6$debug === void 0 ? false : _ref6$debug;
156
- eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange'];
157
- _this.connection = connection;
158
- _this.name = name;
159
- _this.debug = debug;
160
-
161
- if (!connection) {
162
- _context2.next = 8;
163
- break;
164
- }
165
-
166
- _context2.next = 8;
167
- return _this.connectToWallet(connection);
168
-
169
- case 8:
170
- // Event callbacks
171
- _this.onDisconnect = onDisconnect;
172
- _this.onAddressChange = onAddressChange;
173
- _this.onNetworkChange = onNetworkChange; // validation
174
-
175
- _forEachInstanceProperty(eventsHandlers).call(eventsHandlers, function (event) {
176
- if (!forceValidation && typeof _this[event] !== 'function') throw new Error("Call-back for ".concat(event, " must be an function!"));
177
- });
178
-
179
- case 12:
180
- case "end":
181
- return _context2.stop();
182
- }
183
- }
184
- }, _callee2);
185
- }))();
102
+ async init(_ref5) {
103
+ let {
104
+ name,
105
+ onAddressChange = voidFn,
106
+ onDisconnect = voidFn,
107
+ onNetworkChange = voidFn,
108
+ connection,
109
+ forceValidation = false,
110
+ debug = false
111
+ } = _ref5;
112
+ const eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange'];
113
+ this.connection = connection;
114
+ this.name = name;
115
+ this.debug = debug;
116
+
117
+ if (connection) {
118
+ // Init RPCClient
119
+ await this.connectToWallet(connection);
120
+ } // Event callbacks
121
+
122
+
123
+ this.onDisconnect = onDisconnect;
124
+ this.onAddressChange = onAddressChange;
125
+ this.onNetworkChange = onNetworkChange; // validation
126
+
127
+ eventsHandlers.forEach(event => {
128
+ if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`);
129
+ });
186
130
  },
131
+
187
132
  deepProps: {
188
133
  Ae: {
189
134
  defaults: {
@@ -192,12 +137,11 @@ export default Ae.compose({
192
137
  }
193
138
  },
194
139
  methods: {
195
- sign: function sign() {},
196
- addresses: function addresses() {
197
- var _context3;
140
+ sign() {},
198
141
 
142
+ addresses() {
199
143
  if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
200
- return _concatInstanceProperty(_context3 = [this.rpcClient.currentAccount]).call(_context3, _toConsumableArray(_Object$keys(this.rpcClient.accounts.connected)));
144
+ return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)];
201
145
  },
202
146
 
203
147
  /**
@@ -208,40 +152,18 @@ export default Ae.compose({
208
152
  * @param {Object} connection Wallet connection object
209
153
  * @return {void}
210
154
  */
211
- connectToWallet: function connectToWallet(connection) {
212
- var _this2 = this;
213
-
214
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
215
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
216
- while (1) {
217
- switch (_context4.prev = _context4.next) {
218
- case 0:
219
- if (!(_this2.rpcClient && _this2.rpcClient.isConnected())) {
220
- _context4.next = 2;
221
- break;
222
- }
223
-
224
- throw new Error('You are already connected to wallet ' + _this2.rpcClient);
225
-
226
- case 2:
227
- _this2.rpcClient = RpcClient(_objectSpread(_objectSpread({
228
- connection: connection,
229
- networkId: _this2.getNetworkId({
230
- force: true
231
- })
232
- }, connection.connectionInfo), {}, {
233
- id: uuid(),
234
- handlers: [handleMessage(_this2), _this2.onDisconnect]
235
- }));
236
- return _context4.abrupt("return", _this2.sendConnectRequest());
237
-
238
- case 4:
239
- case "end":
240
- return _context4.stop();
241
- }
242
- }
243
- }, _callee3);
244
- }))();
155
+ async connectToWallet(connection) {
156
+ if (this.rpcClient && this.rpcClient.isConnected()) throw new Error('You are already connected to wallet ' + this.rpcClient);
157
+ this.rpcClient = RpcClient({
158
+ connection,
159
+ networkId: this.getNetworkId({
160
+ force: true
161
+ }),
162
+ ...connection.connectionInfo,
163
+ id: uuid(),
164
+ handlers: [handleMessage(this), this.onDisconnect]
165
+ });
166
+ return this.sendConnectRequest();
245
167
  },
246
168
 
247
169
  /**
@@ -252,90 +174,25 @@ export default Ae.compose({
252
174
  * @param {Boolean} sendDisconnect=false Force sending close connection message
253
175
  * @return {void}
254
176
  */
255
- disconnectWallet: function disconnectWallet() {
256
- var _arguments = arguments,
257
- _this3 = this;
258
-
259
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
260
- var sendDisconnect;
261
- return _regeneratorRuntime.wrap(function _callee4$(_context5) {
262
- while (1) {
263
- switch (_context5.prev = _context5.next) {
264
- case 0:
265
- sendDisconnect = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : true;
266
-
267
- if (!(!_this3.rpcClient || !_this3.rpcClient.isConnected())) {
268
- _context5.next = 3;
269
- break;
270
- }
271
-
272
- throw new Error('You are not connected to Wallet');
273
-
274
- case 3:
275
- sendDisconnect && _this3.rpcClient.sendMessage(message(METHODS.closeConnection, {
276
- reason: 'bye'
277
- }), true);
278
-
279
- _this3.rpcClient.disconnect();
280
-
281
- _this3.rpcClient = null;
282
-
283
- case 6:
284
- case "end":
285
- return _context5.stop();
286
- }
287
- }
288
- }, _callee4);
289
- }))();
177
+ async disconnectWallet() {
178
+ let sendDisconnect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
179
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
180
+ sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, {
181
+ reason: 'bye'
182
+ }), true);
183
+ this.rpcClient.disconnect();
184
+ this.rpcClient = null;
290
185
  },
291
- address: function address() {
292
- var _arguments2 = arguments,
293
- _this4 = this;
294
-
295
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
296
- var _ref7, onAccount, current;
297
-
298
- return _regeneratorRuntime.wrap(function _callee5$(_context6) {
299
- while (1) {
300
- switch (_context6.prev = _context6.next) {
301
- case 0:
302
- _ref7 = _arguments2.length > 0 && _arguments2[0] !== undefined ? _arguments2[0] : {}, onAccount = _ref7.onAccount;
303
-
304
- if (!(!_this4.rpcClient || !_this4.rpcClient.isConnected())) {
305
- _context6.next = 3;
306
- break;
307
- }
308
-
309
- throw new Error('You are not connected to Wallet');
310
-
311
- case 3:
312
- current = _this4.rpcClient.currentAccount;
313
-
314
- if (current) {
315
- _context6.next = 6;
316
- break;
317
- }
318
-
319
- throw new Error('You are not subscribed for an account.');
320
-
321
- case 6:
322
- if (!(onAccount && !_this4.rpcClient.hasAccessToAccount(onAccount))) {
323
- _context6.next = 8;
324
- break;
325
- }
326
186
 
327
- throw new Error("You do not have access to account ".concat(onAccount));
328
-
329
- case 8:
330
- return _context6.abrupt("return", onAccount || current);
331
-
332
- case 9:
333
- case "end":
334
- return _context6.stop();
335
- }
336
- }
337
- }, _callee5);
338
- }))();
187
+ async address() {
188
+ let {
189
+ onAccount
190
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
191
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
192
+ const current = this.rpcClient.currentAccount;
193
+ if (!current) throw new Error('You are not subscribed for an account.');
194
+ if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) throw new Error(`You do not have access to account ${onAccount}`);
195
+ return onAccount || current;
339
196
  },
340
197
 
341
198
  /**
@@ -345,39 +202,10 @@ export default Ae.compose({
345
202
  * @rtype () => Promise
346
203
  * @return {Promise} Address from wallet
347
204
  */
348
- askAddresses: function askAddresses() {
349
- var _this5 = this;
350
-
351
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
352
- return _regeneratorRuntime.wrap(function _callee6$(_context7) {
353
- while (1) {
354
- switch (_context7.prev = _context7.next) {
355
- case 0:
356
- if (!(!_this5.rpcClient || !_this5.rpcClient.isConnected())) {
357
- _context7.next = 2;
358
- break;
359
- }
360
-
361
- throw new Error('You are not connected to Wallet');
362
-
363
- case 2:
364
- if (_this5.rpcClient.currentAccount) {
365
- _context7.next = 4;
366
- break;
367
- }
368
-
369
- throw new Error('You are not subscribed for an account.');
370
-
371
- case 4:
372
- return _context7.abrupt("return", _this5.rpcClient.request(METHODS.aepp.address));
373
-
374
- case 5:
375
- case "end":
376
- return _context7.stop();
377
- }
378
- }
379
- }, _callee6);
380
- }))();
205
+ async askAddresses() {
206
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
207
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
208
+ return this.rpcClient.request(METHODS.aepp.address);
381
209
  },
382
210
 
383
211
  /**
@@ -389,34 +217,12 @@ export default Ae.compose({
389
217
  * @param {String} value Subscription action('subscribe'|'unsubscribe')
390
218
  * @return {Promise} Address from wallet
391
219
  */
392
- subscribeAddress: function subscribeAddress(type, value) {
393
- var _this6 = this;
394
-
395
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
396
- return _regeneratorRuntime.wrap(function _callee7$(_context8) {
397
- while (1) {
398
- switch (_context8.prev = _context8.next) {
399
- case 0:
400
- if (!(!_this6.rpcClient || !_this6.rpcClient.isConnected())) {
401
- _context8.next = 2;
402
- break;
403
- }
404
-
405
- throw new Error('You are not connected to Wallet');
406
-
407
- case 2:
408
- return _context8.abrupt("return", _this6.rpcClient.request(METHODS.aepp.subscribeAddress, {
409
- type: type,
410
- value: value
411
- }));
412
-
413
- case 3:
414
- case "end":
415
- return _context8.stop();
416
- }
417
- }
418
- }, _callee7);
419
- }))();
220
+ async subscribeAddress(type, value) {
221
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
222
+ return this.rpcClient.request(METHODS.aepp.subscribeAddress, {
223
+ type,
224
+ value
225
+ });
420
226
  },
421
227
 
422
228
  /**
@@ -427,55 +233,16 @@ export default Ae.compose({
427
233
  * @rtype (tx: String, options = {}) => Promise
428
234
  * @return {Promise<String>} Signed transaction
429
235
  */
430
- signTransaction: function signTransaction(tx) {
431
- var _arguments3 = arguments,
432
- _this7 = this;
433
-
434
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
435
- var opt;
436
- return _regeneratorRuntime.wrap(function _callee8$(_context9) {
437
- while (1) {
438
- switch (_context9.prev = _context9.next) {
439
- case 0:
440
- opt = _arguments3.length > 1 && _arguments3[1] !== undefined ? _arguments3[1] : {};
441
-
442
- if (!(!_this7.rpcClient || !_this7.rpcClient.isConnected())) {
443
- _context9.next = 3;
444
- break;
445
- }
446
-
447
- throw new Error('You are not connected to Wallet');
448
-
449
- case 3:
450
- if (_this7.rpcClient.currentAccount) {
451
- _context9.next = 5;
452
- break;
453
- }
454
-
455
- throw new Error('You are not subscribed for an account.');
456
-
457
- case 5:
458
- if (!(opt.onAccount && !_this7.rpcClient.hasAccessToAccount(opt.onAccount))) {
459
- _context9.next = 7;
460
- break;
461
- }
462
-
463
- throw new Error("You do not have access to account ".concat(opt.onAccount));
464
-
465
- case 7:
466
- return _context9.abrupt("return", _this7.rpcClient.request(METHODS.aepp.sign, _objectSpread(_objectSpread({}, opt), {}, {
467
- tx: tx,
468
- returnSigned: true,
469
- networkId: _this7.getNetworkId()
470
- })));
471
-
472
- case 8:
473
- case "end":
474
- return _context9.stop();
475
- }
476
- }
477
- }, _callee8);
478
- }))();
236
+ async signTransaction(tx) {
237
+ let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
238
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
239
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
240
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`);
241
+ return this.rpcClient.request(METHODS.aepp.sign, { ...opt,
242
+ tx,
243
+ returnSigned: true,
244
+ networkId: this.getNetworkId()
245
+ });
479
246
  },
480
247
 
481
248
  /**
@@ -486,53 +253,14 @@ export default Ae.compose({
486
253
  * @rtype (msg: String, options = {}) => Promise
487
254
  * @return {Promise<String>} Signed transaction
488
255
  */
489
- signMessage: function signMessage(msg) {
490
- var _arguments4 = arguments,
491
- _this8 = this;
492
-
493
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
494
- var opt;
495
- return _regeneratorRuntime.wrap(function _callee9$(_context10) {
496
- while (1) {
497
- switch (_context10.prev = _context10.next) {
498
- case 0:
499
- opt = _arguments4.length > 1 && _arguments4[1] !== undefined ? _arguments4[1] : {};
500
-
501
- if (!(!_this8.rpcClient || !_this8.rpcClient.isConnected())) {
502
- _context10.next = 3;
503
- break;
504
- }
505
-
506
- throw new Error('You are not connected to Wallet');
507
-
508
- case 3:
509
- if (_this8.rpcClient.currentAccount) {
510
- _context10.next = 5;
511
- break;
512
- }
513
-
514
- throw new Error('You are not subscribed for an account.');
515
-
516
- case 5:
517
- if (!(opt.onAccount && !_this8.rpcClient.hasAccessToAccount(opt.onAccount))) {
518
- _context10.next = 7;
519
- break;
520
- }
521
-
522
- throw new Error("You do not have access to account ".concat(opt.onAccount));
523
-
524
- case 7:
525
- return _context10.abrupt("return", _this8.rpcClient.request(METHODS.aepp.signMessage, _objectSpread(_objectSpread({}, opt), {}, {
526
- message: msg
527
- })));
528
-
529
- case 8:
530
- case "end":
531
- return _context10.stop();
532
- }
533
- }
534
- }, _callee9);
535
- }))();
256
+ async signMessage(msg) {
257
+ let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
258
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
259
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
260
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`);
261
+ return this.rpcClient.request(METHODS.aepp.signMessage, { ...opt,
262
+ message: msg
263
+ });
536
264
  },
537
265
 
538
266
  /**
@@ -542,29 +270,14 @@ export default Ae.compose({
542
270
  * @rtype () => Promise
543
271
  * @return {Promise} Connection response
544
272
  */
545
- sendConnectRequest: function sendConnectRequest() {
546
- var _this9 = this;
547
-
548
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
549
- return _regeneratorRuntime.wrap(function _callee10$(_context11) {
550
- while (1) {
551
- switch (_context11.prev = _context11.next) {
552
- case 0:
553
- return _context11.abrupt("return", _this9.rpcClient.request(METHODS.aepp.connect, {
554
- name: _this9.name,
555
- version: VERSION,
556
- networkId: _this9.getNetworkId({
557
- force: true
558
- })
559
- }));
560
-
561
- case 1:
562
- case "end":
563
- return _context11.stop();
564
- }
565
- }
566
- }, _callee10);
567
- }))();
273
+ async sendConnectRequest() {
274
+ return this.rpcClient.request(METHODS.aepp.connect, {
275
+ name: this.name,
276
+ version: VERSION,
277
+ networkId: this.getNetworkId({
278
+ force: true
279
+ })
280
+ });
568
281
  },
569
282
 
570
283
  /**
@@ -579,74 +292,30 @@ export default Ae.compose({
579
292
  * @param {Object} [options.walletBroadcast=true]
580
293
  * @return {Promise<Object>} Transaction broadcast result
581
294
  */
582
- send: function send(tx) {
583
- var _arguments5 = arguments,
584
- _this10 = this;
585
-
586
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
587
- var options, opt, signed;
588
- return _regeneratorRuntime.wrap(function _callee11$(_context12) {
589
- while (1) {
590
- switch (_context12.prev = _context12.next) {
591
- case 0:
592
- options = _arguments5.length > 1 && _arguments5[1] !== undefined ? _arguments5[1] : {};
593
-
594
- if (!(!_this10.rpcClient || !_this10.rpcClient.isConnected())) {
595
- _context12.next = 3;
596
- break;
597
- }
598
-
599
- throw new Error('You are not connected to Wallet');
600
-
601
- case 3:
602
- if (_this10.rpcClient.currentAccount) {
603
- _context12.next = 5;
604
- break;
605
- }
606
-
607
- throw new Error('You are not subscribed for an account.');
608
-
609
- case 5:
610
- if (!(options.onAccount && !_this10.rpcClient.hasAccessToAccount(options.onAccount))) {
611
- _context12.next = 7;
612
- break;
613
- }
614
-
615
- throw new Error("You do not have access to account ".concat(options.onAccount));
616
-
617
- case 7:
618
- opt = _merge(_this10.Ae.defaults, options);
619
-
620
- if (opt.walletBroadcast) {
621
- _context12.next = 13;
622
- break;
623
- }
624
-
625
- _context12.next = 11;
626
- return _this10.signTransaction(tx, {
627
- onAccount: opt.onAccount
628
- });
629
-
630
- case 11:
631
- signed = _context12.sent;
632
- return _context12.abrupt("return", _this10.sendTransaction(signed, opt));
633
-
634
- case 13:
635
- return _context12.abrupt("return", _this10.rpcClient.request(METHODS.aepp.sign, {
636
- onAccount: opt.onAccount,
637
- tx: tx,
638
- returnSigned: false,
639
- networkId: _this10.getNetworkId()
640
- }));
295
+ async send(tx) {
296
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
297
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
298
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
299
+ if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) throw new Error(`You do not have access to account ${options.onAccount}`);
300
+ const opt = { ...this.Ae.defaults,
301
+ ...options
302
+ };
303
+
304
+ if (!opt.walletBroadcast) {
305
+ const signed = await this.signTransaction(tx, {
306
+ onAccount: opt.onAccount
307
+ });
308
+ return this.sendTransaction(signed, opt);
309
+ }
641
310
 
642
- case 14:
643
- case "end":
644
- return _context12.stop();
645
- }
646
- }
647
- }, _callee11);
648
- }))();
311
+ return this.rpcClient.request(METHODS.aepp.sign, {
312
+ onAccount: opt.onAccount,
313
+ tx,
314
+ returnSigned: false,
315
+ networkId: this.getNetworkId()
316
+ });
649
317
  }
318
+
650
319
  }
651
320
  });
652
321
  //# sourceMappingURL=aepp-rpc.js.map