@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.
- package/CHANGELOG.md +216 -337
- package/README.md +16 -9
- 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 +36 -120
- 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 +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- 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 +238 -465
- 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 +328 -495
- 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 +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- 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 +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- 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 +41 -106
- 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 +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
|
@@ -1,130 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
return function (msg) {
|
|
26
|
+
},
|
|
27
|
+
[METHODS.closeConnection]: instance => msg => {
|
|
40
28
|
instance.disconnectWallet();
|
|
41
29
|
instance.onDisconnect(msg.params);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
54
|
-
return function (msg) {
|
|
37
|
+
},
|
|
38
|
+
[METHODS.aepp.subscribeAddress]: instance => msg => {
|
|
55
39
|
if (msg.result) {
|
|
56
|
-
|
|
57
|
-
|
|
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,
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
instance.rpcClient.processResponse(msg, _ref2 => {
|
|
50
|
+
let {
|
|
51
|
+
id,
|
|
52
|
+
result
|
|
53
|
+
} = _ref2;
|
|
63
54
|
return [result];
|
|
64
55
|
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return
|
|
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
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
|
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
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|