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