@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,130 +1,94 @@
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
7
+ * import ContentScriptBridge
8
+ * from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
9
+ */
22
10
  import { v4 as uuid } from 'uuid';
23
11
  import Ae from '../../../ae';
24
12
  import RpcClient from './rpc-client';
25
13
  import { getHandler, message, voidFn } from '../helpers';
26
14
  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;
15
+ const NOTIFICATIONS = {
16
+ [METHODS.wallet.updateAddress]: instance => _ref => {
17
+ let {
18
+ params
19
+ } = _ref;
30
20
  instance.rpcClient.accounts = params;
31
21
  instance.onAddressChange(params);
32
- };
33
- }), _defineProperty(_NOTIFICATIONS, METHODS.updateNetwork, function (instance) {
34
- return function (msg) {
22
+ },
23
+ [METHODS.updateNetwork]: instance => msg => {
35
24
  instance.rpcClient.info.networkId = msg.params.networkId;
36
25
  instance.onNetworkChange(msg.params);
37
- };
38
- }), _defineProperty(_NOTIFICATIONS, METHODS.closeConnection, function (instance) {
39
- return function (msg) {
26
+ },
27
+ [METHODS.closeConnection]: instance => msg => {
40
28
  instance.disconnectWallet();
41
29
  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) {
30
+ }
31
+ };
32
+ const RESPONSES = {
33
+ [METHODS.aepp.address]: instance => msg => instance.rpcClient.processResponse(msg),
34
+ [METHODS.aepp.connect]: instance => msg => {
50
35
  if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED;
51
36
  instance.rpcClient.processResponse(msg);
52
- };
53
- }), _defineProperty(_RESPONSES, METHODS.aepp.subscribeAddress, function (instance) {
54
- return function (msg) {
37
+ },
38
+ [METHODS.aepp.subscribeAddress]: instance => msg => {
55
39
  if (msg.result) {
56
- msg.result.address && (instance.rpcClient.accounts = msg.result.address);
57
- msg.result.subscription && (instance.rpcClient.addressSubscription = msg.result.subscription);
40
+ if (msg.result.address) {
41
+ instance.rpcClient.accounts = msg.result.address;
42
+ }
43
+
44
+ if (msg.result.subscription) {
45
+ instance.rpcClient.addressSubscription = msg.result.subscription;
46
+ }
58
47
  }
59
48
 
60
- instance.rpcClient.processResponse(msg, function (_ref2) {
61
- var id = _ref2.id,
62
- result = _ref2.result;
49
+ instance.rpcClient.processResponse(msg, _ref2 => {
50
+ let {
51
+ id,
52
+ result
53
+ } = _ref2;
63
54
  return [result];
64
55
  });
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;
56
+ },
57
+ [METHODS.aepp.sign]: instance => msg => {
58
+ instance.rpcClient.processResponse(msg, _ref3 => {
59
+ let {
60
+ id,
61
+ result
62
+ } = _ref3;
71
63
  return [result.signedTransaction || result.transactionHash];
72
64
  });
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;
65
+ },
66
+ [METHODS.aepp.signMessage]: instance => msg => {
67
+ instance.rpcClient.processResponse(msg, _ref4 => {
68
+ let {
69
+ id,
70
+ result
71
+ } = _ref4;
79
72
  return [result.signature];
80
73
  });
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
- }();
74
+ }
75
+ };
76
+ const REQUESTS = {};
77
+
78
+ const handleMessage = instance => async msg => {
79
+ if (!msg.id) {
80
+ return getHandler(NOTIFICATIONS, msg, {
81
+ debug: instance.debug
82
+ })(instance)(msg);
83
+ } else if (Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {
84
+ return getHandler(RESPONSES, msg, {
85
+ debug: instance.debug
86
+ })(instance)(msg);
87
+ } else {
88
+ return getHandler(REQUESTS, msg, {
89
+ debug: instance.debug
90
+ })(instance)(msg);
91
+ }
128
92
  };
129
93
  /**
130
94
  * Contain functionality for wallet interaction and connect it to sdk
@@ -142,48 +106,36 @@ var handleMessage = function handleMessage(instance) {
142
106
 
143
107
 
144
108
  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
- }))();
109
+ async init(_ref5) {
110
+ let {
111
+ name,
112
+ onAddressChange = voidFn,
113
+ onDisconnect = voidFn,
114
+ onNetworkChange = voidFn,
115
+ connection,
116
+ forceValidation = false,
117
+ debug = false
118
+ } = _ref5;
119
+ const eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange'];
120
+ this.connection = connection;
121
+ this.name = name;
122
+ this.debug = debug;
123
+
124
+ if (connection) {
125
+ // Init RPCClient
126
+ await this.connectToWallet(connection);
127
+ } // Event callbacks
128
+
129
+
130
+ this.onDisconnect = onDisconnect;
131
+ this.onAddressChange = onAddressChange;
132
+ this.onNetworkChange = onNetworkChange; // validation
133
+
134
+ eventsHandlers.forEach(event => {
135
+ if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`);
136
+ });
186
137
  },
138
+
187
139
  deepProps: {
188
140
  Ae: {
189
141
  defaults: {
@@ -192,12 +144,11 @@ export default Ae.compose({
192
144
  }
193
145
  },
194
146
  methods: {
195
- sign: function sign() {},
196
- addresses: function addresses() {
197
- var _context3;
147
+ sign() {},
198
148
 
149
+ addresses() {
199
150
  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)));
151
+ return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)];
201
152
  },
202
153
 
203
154
  /**
@@ -208,40 +159,18 @@ export default Ae.compose({
208
159
  * @param {Object} connection Wallet connection object
209
160
  * @return {void}
210
161
  */
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
- }))();
162
+ async connectToWallet(connection) {
163
+ if (this.rpcClient && this.rpcClient.isConnected()) throw new Error('You are already connected to wallet ' + this.rpcClient);
164
+ this.rpcClient = RpcClient({
165
+ connection,
166
+ networkId: this.getNetworkId({
167
+ force: true
168
+ }),
169
+ ...connection.connectionInfo,
170
+ id: uuid(),
171
+ handlers: [handleMessage(this), this.onDisconnect]
172
+ });
173
+ return this.sendConnectRequest();
245
174
  },
246
175
 
247
176
  /**
@@ -252,90 +181,25 @@ export default Ae.compose({
252
181
  * @param {Boolean} sendDisconnect=false Force sending close connection message
253
182
  * @return {void}
254
183
  */
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
- }))();
184
+ async disconnectWallet() {
185
+ let sendDisconnect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
186
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
187
+ sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, {
188
+ reason: 'bye'
189
+ }), true);
190
+ this.rpcClient.disconnect();
191
+ this.rpcClient = null;
290
192
  },
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
193
 
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
-
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
- }))();
194
+ async address() {
195
+ let {
196
+ onAccount
197
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
198
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
199
+ const current = this.rpcClient.currentAccount;
200
+ if (!current) throw new Error('You are not subscribed for an account.');
201
+ if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) throw new Error(`You do not have access to account ${onAccount}`);
202
+ return onAccount || current;
339
203
  },
340
204
 
341
205
  /**
@@ -345,39 +209,10 @@ export default Ae.compose({
345
209
  * @rtype () => Promise
346
210
  * @return {Promise} Address from wallet
347
211
  */
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
- }))();
212
+ async askAddresses() {
213
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
214
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
215
+ return this.rpcClient.request(METHODS.aepp.address);
381
216
  },
382
217
 
383
218
  /**
@@ -385,38 +220,16 @@ export default Ae.compose({
385
220
  * @function subscribeAddress
386
221
  * @instance
387
222
  * @rtype (type: String, value: String) => Promise
388
- * @param {String} type Type of subscription can be one of ['current'(just for selected account updates), 'connected(all accounts)']
223
+ * @param {String} type Should be one of 'current' (the selected account), 'connected' (all)
389
224
  * @param {String} value Subscription action('subscribe'|'unsubscribe')
390
225
  * @return {Promise} Address from wallet
391
226
  */
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
- }))();
227
+ async subscribeAddress(type, value) {
228
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
229
+ return this.rpcClient.request(METHODS.aepp.subscribeAddress, {
230
+ type,
231
+ value
232
+ });
420
233
  },
421
234
 
422
235
  /**
@@ -427,55 +240,16 @@ export default Ae.compose({
427
240
  * @rtype (tx: String, options = {}) => Promise
428
241
  * @return {Promise<String>} Signed transaction
429
242
  */
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
- }))();
243
+ async signTransaction(tx) {
244
+ let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
245
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
246
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
247
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`);
248
+ return this.rpcClient.request(METHODS.aepp.sign, { ...opt,
249
+ tx,
250
+ returnSigned: true,
251
+ networkId: this.getNetworkId()
252
+ });
479
253
  },
480
254
 
481
255
  /**
@@ -486,53 +260,14 @@ export default Ae.compose({
486
260
  * @rtype (msg: String, options = {}) => Promise
487
261
  * @return {Promise<String>} Signed transaction
488
262
  */
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
- }))();
263
+ async signMessage(msg) {
264
+ let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
265
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
266
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
267
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`);
268
+ return this.rpcClient.request(METHODS.aepp.signMessage, { ...opt,
269
+ message: msg
270
+ });
536
271
  },
537
272
 
538
273
  /**
@@ -542,35 +277,21 @@ export default Ae.compose({
542
277
  * @rtype () => Promise
543
278
  * @return {Promise} Connection response
544
279
  */
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
- }))();
280
+ async sendConnectRequest() {
281
+ return this.rpcClient.request(METHODS.aepp.connect, {
282
+ name: this.name,
283
+ version: VERSION,
284
+ networkId: this.getNetworkId({
285
+ force: true
286
+ })
287
+ });
568
288
  },
569
289
 
570
290
  /**
571
291
  * Overwriting of `send` AE method
572
292
  * All sdk API which use it will be send notification to wallet and wait for callBack
573
- * This method will sign, broadcast and wait until transaction will be accepted using rpc communication with wallet
293
+ * This method will sign, broadcast and wait until transaction will be accepted using rpc
294
+ * communication with wallet
574
295
  * @function send
575
296
  * @instance
576
297
  * @rtype (tx: String, options = {}) => Promise
@@ -579,74 +300,30 @@ export default Ae.compose({
579
300
  * @param {Object} [options.walletBroadcast=true]
580
301
  * @return {Promise<Object>} Transaction broadcast result
581
302
  */
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
- }));
303
+ async send(tx) {
304
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
305
+ if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet');
306
+ if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.');
307
+ if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) throw new Error(`You do not have access to account ${options.onAccount}`);
308
+ const opt = { ...this.Ae.defaults,
309
+ ...options
310
+ };
311
+
312
+ if (!opt.walletBroadcast) {
313
+ const signed = await this.signTransaction(tx, {
314
+ onAccount: opt.onAccount
315
+ });
316
+ return this.sendTransaction(signed, opt);
317
+ }
641
318
 
642
- case 14:
643
- case "end":
644
- return _context12.stop();
645
- }
646
- }
647
- }, _callee11);
648
- }))();
319
+ return this.rpcClient.request(METHODS.aepp.sign, {
320
+ onAccount: opt.onAccount,
321
+ tx,
322
+ returnSigned: false,
323
+ networkId: this.getNetworkId()
324
+ });
649
325
  }
326
+
650
327
  }
651
328
  });
652
329
  //# sourceMappingURL=aepp-rpc.js.map