@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +33 -119
- 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 +75 -154
- 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 +108 -916
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +89 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +132 -500
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +4 -23
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +292 -1018
- 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 -491
- 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 +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +102 -247
- 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 +2 -3
- 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 +49 -89
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +205 -303
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +585 -573
- 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 -135
- 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 +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 +354 -603
- 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 +49 -75
- 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 -218
- package/es/utils/swagger.js.map +1 -1
- package/package.json +52 -43
- package/src/account/base.js +8 -9
- package/src/account/multiple.js +20 -16
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +65 -246
- package/src/ae/index.js +31 -7
- package/src/ae/oracle.js +21 -17
- package/src/chain/index.js +2 -12
- package/src/chain/node.js +26 -29
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -106
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +2 -12
- package/src/contract/ga/index.js +22 -26
- package/src/index.js +2 -4
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/helpers.js +12 -24
- package/src/tx/builder/index.js +18 -15
- package/src/tx/builder/schema.js +43 -108
- package/src/tx/tx-object.js +0 -2
- package/src/tx/tx.js +157 -144
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -17
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +24 -7
- package/CHANGELOG.md +0 -1716
- package/src/contract/aci/helpers.js +0 -140
package/es/utils/swagger.js
CHANGED
|
@@ -1,35 +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 _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
4
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
5
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
6
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
7
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
8
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
11
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
12
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
13
|
-
var _excluded = ["__requestBody"];
|
|
14
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source), true)).call(_context11, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context12; _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
21
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
22
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
23
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
24
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
25
|
-
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
|
26
|
-
import _flatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/flat";
|
|
27
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
28
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
29
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
30
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
31
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
32
|
-
|
|
33
1
|
/*
|
|
34
2
|
* ISC License (ISC)
|
|
35
3
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -56,7 +24,7 @@ import SwaggerClient from 'swagger-client';
|
|
|
56
24
|
import fetch from 'cross-fetch';
|
|
57
25
|
import JsonBig from './json-big';
|
|
58
26
|
import { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other';
|
|
59
|
-
|
|
27
|
+
let warnedAboutInternalApiUsage = false;
|
|
60
28
|
/**
|
|
61
29
|
* Generator of Swagger client
|
|
62
30
|
* @function
|
|
@@ -68,196 +36,95 @@ var warnedAboutInternalApiUsage = false;
|
|
|
68
36
|
* @param {String} [options.internalUrl] - Node internal URL
|
|
69
37
|
* @param {Boolean} [options.disableBigNumbers]
|
|
70
38
|
* @param {Boolean} [options.disableCaseConversion]
|
|
39
|
+
* @param {Function} [options.responseInterceptor]
|
|
71
40
|
* @return {Object} Swagger client
|
|
72
41
|
* @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')
|
|
73
42
|
*/
|
|
74
43
|
|
|
75
|
-
export default
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
_context10.next = 8;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_context10.next = 5;
|
|
107
|
-
return fetch(specUrl);
|
|
108
|
-
|
|
109
|
-
case 5:
|
|
110
|
-
_context10.next = 7;
|
|
111
|
-
return _context10.sent.json();
|
|
112
|
-
|
|
113
|
-
case 7:
|
|
114
|
-
_context10.t0 = _context10.sent;
|
|
115
|
-
|
|
116
|
-
case 8:
|
|
117
|
-
spec = _context10.t0;
|
|
118
|
-
jsonImp = disableBigNumbers ? JSON : JsonBig;
|
|
119
|
-
_context10.next = 12;
|
|
120
|
-
return _Promise.all(_mapInstanceProperty(_context = [specUrl, internalUrl]).call(_context, function (url) {
|
|
121
|
-
if (!url) return null;
|
|
122
|
-
return SwaggerClient({
|
|
123
|
-
url: url,
|
|
124
|
-
spec: spec,
|
|
125
|
-
responseInterceptor: function responseInterceptor(response) {
|
|
126
|
-
if (!response.text) return response;
|
|
127
|
-
var body = jsonImp.parse(response.text);
|
|
128
|
-
return _Object$assign(response, {
|
|
129
|
-
body: disableCaseConversion ? body : pascalizeKeys(body)
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
case 12:
|
|
136
|
-
_yield$Promise$all = _context10.sent;
|
|
137
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
138
|
-
external = _yield$Promise$all2[0];
|
|
139
|
-
internal = _yield$Promise$all2[1];
|
|
140
|
-
combinedApi = _reduceInstanceProperty(_context2 = _concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(_Object$values(external.apis)), [mapObject((internal === null || internal === void 0 ? void 0 : internal.apis.internal) || {}, function (_ref3) {
|
|
141
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
142
|
-
key = _ref4[0],
|
|
143
|
-
handler = _ref4[1];
|
|
144
|
-
|
|
145
|
-
return [key, function () {
|
|
146
|
-
if (!warnedAboutInternalApiUsage) {
|
|
147
|
-
console.warn('SDK\'s wrapper of aeternity node internal API is deprecated, please use external ' + 'equivalent (for example, "sdk.api.protectedDryRunTxs" instead of "sdk.api.dryRunTxs") ' + 'or create a wrapper of internal API by yourself (using "genSwaggerClient")');
|
|
148
|
-
warnedAboutInternalApiUsage = true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return handler.apply(void 0, arguments);
|
|
152
|
-
}];
|
|
153
|
-
})])).call(_context2, function (acc, n) {
|
|
154
|
-
return _objectSpread(_objectSpread({}, acc), n);
|
|
155
|
-
});
|
|
156
|
-
opSpecs = _reduceInstanceProperty(_context4 = _flatInstanceProperty(_context5 = _mapInstanceProperty(_context6 = _Object$values(spec.paths)).call(_context6, function (paths) {
|
|
157
|
-
return _Object$values(paths);
|
|
158
|
-
})).call(_context5)).call(_context4, function (acc, n) {
|
|
159
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, n.operationId, n));
|
|
160
|
-
}, {});
|
|
161
|
-
api = mapObject(combinedApi, function (_ref5) {
|
|
162
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
163
|
-
opId = _ref6[0],
|
|
164
|
-
handler = _ref6[1];
|
|
165
|
-
|
|
166
|
-
return [_sliceInstanceProperty(opId).call(opId, 0, 1).toLowerCase() + _sliceInstanceProperty(opId).call(opId, 1), /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
167
|
-
var _context7, _context8;
|
|
168
|
-
|
|
169
|
-
var _len,
|
|
170
|
-
args,
|
|
171
|
-
_key,
|
|
172
|
-
opSpec,
|
|
173
|
-
parameters,
|
|
174
|
-
required,
|
|
175
|
-
values,
|
|
176
|
-
_mapObject,
|
|
177
|
-
__requestBody,
|
|
178
|
-
stringified,
|
|
179
|
-
_args = arguments;
|
|
180
|
-
|
|
181
|
-
return _regeneratorRuntime.wrap(function _callee$(_context9) {
|
|
182
|
-
while (1) {
|
|
183
|
-
switch (_context9.prev = _context9.next) {
|
|
184
|
-
case 0:
|
|
185
|
-
for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
186
|
-
args[_key] = _args[_key];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
opSpec = opSpecs[opId];
|
|
190
|
-
parameters = _concatInstanceProperty(_context7 = []).call(_context7, _toConsumableArray(opSpec.parameters), _toConsumableArray(opSpec.requestBody ? [{
|
|
191
|
-
required: opSpec.requestBody.required,
|
|
192
|
-
schema: _Object$values(opSpec.requestBody.content)[0].schema,
|
|
193
|
-
name: '__requestBody'
|
|
194
|
-
}] : []));
|
|
195
|
-
required = _mapInstanceProperty(_context8 = _filterInstanceProperty(parameters).call(parameters, function (param) {
|
|
196
|
-
return param.required;
|
|
197
|
-
})).call(_context8, function (p) {
|
|
198
|
-
return p.name;
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
if (!(args.length < required.length)) {
|
|
202
|
-
_context9.next = 6;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
throw new Error('swagger: Not enough arguments');
|
|
207
|
-
|
|
208
|
-
case 6:
|
|
209
|
-
values = _reduceInstanceProperty(required).call(required, function (acc, req, idx) {
|
|
210
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, req, args[idx]));
|
|
211
|
-
}, args[required.length] || {});
|
|
212
|
-
_mapObject = mapObject(values, function (_ref8) {
|
|
213
|
-
var _ref9 = _slicedToArray(_ref8, 2),
|
|
214
|
-
param = _ref9[0],
|
|
215
|
-
value = _ref9[1];
|
|
216
|
-
|
|
217
|
-
if (_typeof(value) !== 'object') return [param, value];
|
|
218
|
-
|
|
219
|
-
var rootKeys = _Object$keys(_findInstanceProperty(parameters).call(parameters, function (p) {
|
|
220
|
-
return p.name === param;
|
|
221
|
-
}).schema.properties);
|
|
222
|
-
|
|
223
|
-
var filteredValue = filterObject(disableCaseConversion ? value : snakizeKeys(value), function (_ref10) {
|
|
224
|
-
var _ref11 = _slicedToArray(_ref10, 1),
|
|
225
|
-
key = _ref11[0];
|
|
226
|
-
|
|
227
|
-
return _includesInstanceProperty(rootKeys).call(rootKeys, key);
|
|
228
|
-
});
|
|
229
|
-
return [param, jsonImp.stringify(filteredValue)];
|
|
230
|
-
}), __requestBody = _mapObject.__requestBody, stringified = _objectWithoutProperties(_mapObject, _excluded);
|
|
231
|
-
_context9.next = 10;
|
|
232
|
-
return handler(stringified, {
|
|
233
|
-
requestBody: __requestBody
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
case 10:
|
|
237
|
-
return _context9.abrupt("return", _context9.sent.body);
|
|
238
|
-
|
|
239
|
-
case 11:
|
|
240
|
-
case "end":
|
|
241
|
-
return _context9.stop();
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}, _callee);
|
|
245
|
-
}))];
|
|
246
|
-
});
|
|
247
|
-
return _context10.abrupt("return", _Object$assign(external, {
|
|
248
|
-
api: api
|
|
249
|
-
}));
|
|
250
|
-
|
|
251
|
-
case 20:
|
|
252
|
-
case "end":
|
|
253
|
-
return _context10.stop();
|
|
254
|
-
}
|
|
44
|
+
export default (async function (specUrl) {
|
|
45
|
+
let {
|
|
46
|
+
spec,
|
|
47
|
+
internalUrl,
|
|
48
|
+
disableBigNumbers,
|
|
49
|
+
disableCaseConversion,
|
|
50
|
+
responseInterceptor
|
|
51
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
|
+
spec = spec || (await (await fetch(specUrl)).json());
|
|
53
|
+
const jsonImp = disableBigNumbers ? JSON : JsonBig;
|
|
54
|
+
|
|
55
|
+
if (['https://compiler.aepps.com', 'https://latest.compiler.aepps.com'].includes(new URL(specUrl).origin) || new URL(specUrl).origin.includes('https://')) {
|
|
56
|
+
spec.schemes = ['https'];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [external, internal] = await Promise.all([specUrl, internalUrl].map(url => {
|
|
60
|
+
if (!url) return null;
|
|
61
|
+
return SwaggerClient({
|
|
62
|
+
url,
|
|
63
|
+
spec,
|
|
64
|
+
responseInterceptor: response => {
|
|
65
|
+
if (!response.text) return response;
|
|
66
|
+
const body = jsonImp.parse(response.text);
|
|
67
|
+
Object.assign(response, {
|
|
68
|
+
body: disableCaseConversion ? body : pascalizeKeys(body)
|
|
69
|
+
});
|
|
70
|
+
return responseInterceptor && responseInterceptor(response) || response;
|
|
255
71
|
}
|
|
256
|
-
}
|
|
72
|
+
});
|
|
257
73
|
}));
|
|
74
|
+
const combinedApi = [...Object.values(external.apis), mapObject((internal === null || internal === void 0 ? void 0 : internal.apis.internal) || {}, _ref => {
|
|
75
|
+
let [key, handler] = _ref;
|
|
76
|
+
return [key, function () {
|
|
77
|
+
if (!warnedAboutInternalApiUsage) {
|
|
78
|
+
console.warn('SDK\'s wrapper of aeternity node internal API is deprecated, please use external ' + 'equivalent (for example, "sdk.api.protectedDryRunTxs" instead of "sdk.api.dryRunTxs") ' + 'or create a wrapper of internal API by yourself (using "genSwaggerClient")');
|
|
79
|
+
warnedAboutInternalApiUsage = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return handler(...arguments);
|
|
83
|
+
}];
|
|
84
|
+
})].reduce((acc, n) => ({ ...acc,
|
|
85
|
+
...n
|
|
86
|
+
}));
|
|
87
|
+
const opSpecs = Object.values(spec.paths).map(paths => Object.values(paths)).flat().reduce((acc, n) => ({ ...acc,
|
|
88
|
+
[n.operationId]: n
|
|
89
|
+
}), {});
|
|
90
|
+
const api = mapObject(combinedApi, _ref2 => {
|
|
91
|
+
let [opId, handler] = _ref2;
|
|
92
|
+
return [opId.slice(0, 1).toLowerCase() + opId.slice(1), async function () {
|
|
93
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
94
|
+
args[_key] = arguments[_key];
|
|
95
|
+
}
|
|
258
96
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
97
|
+
const opSpec = opSpecs[opId];
|
|
98
|
+
const parameters = [...opSpec.parameters, ...(opSpec.requestBody ? [{
|
|
99
|
+
required: opSpec.requestBody.required,
|
|
100
|
+
schema: Object.values(opSpec.requestBody.content)[0].schema,
|
|
101
|
+
name: '__requestBody'
|
|
102
|
+
}] : [])];
|
|
103
|
+
const required = parameters.filter(param => param.required).map(p => p.name);
|
|
104
|
+
if (args.length < required.length) throw new Error('swagger: Not enough arguments');
|
|
105
|
+
const values = required.reduce((acc, req, idx) => ({ ...acc,
|
|
106
|
+
[req]: args[idx]
|
|
107
|
+
}), args[required.length] || {});
|
|
108
|
+
const {
|
|
109
|
+
__requestBody,
|
|
110
|
+
...stringified
|
|
111
|
+
} = mapObject(values, _ref3 => {
|
|
112
|
+
let [param, value] = _ref3;
|
|
113
|
+
if (typeof value !== 'object') return [param, value];
|
|
114
|
+
const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties);
|
|
115
|
+
const filteredValue = filterObject(disableCaseConversion ? value : snakizeKeys(value), _ref4 => {
|
|
116
|
+
let [key] = _ref4;
|
|
117
|
+
return rootKeys.includes(key);
|
|
118
|
+
});
|
|
119
|
+
return [param, jsonImp.stringify(filteredValue)];
|
|
120
|
+
});
|
|
121
|
+
return (await handler(stringified, {
|
|
122
|
+
requestBody: __requestBody
|
|
123
|
+
})).body;
|
|
124
|
+
}];
|
|
125
|
+
});
|
|
126
|
+
return Object.assign(external, {
|
|
127
|
+
api
|
|
128
|
+
});
|
|
129
|
+
});
|
|
263
130
|
//# sourceMappingURL=swagger.js.map
|
package/es/utils/swagger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/swagger.js"],"names":["SwaggerClient","fetch","JsonBig","snakizeKeys","pascalizeKeys","mapObject","filterObject","warnedAboutInternalApiUsage","specUrl","spec","internalUrl","disableBigNumbers","disableCaseConversion","json","jsonImp","JSON","all","url","responseInterceptor","response","text","body","parse","external","internal","combinedApi","apis","key","handler","console","warn","acc","n","opSpecs","paths","operationId","api","opId","toLowerCase","args","opSpec","parameters","requestBody","required","schema","content","name","param","p","length","Error","values","req","idx","value","rootKeys","properties","filteredValue","stringify","__requestBody","stringified"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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C License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Generator of Swagger client module\n * @module @aeternity/aepp-sdk/es/utils/swagger\n * @export genSwaggerClient\n */\n\nimport SwaggerClient from 'swagger-client'\nimport fetch from 'cross-fetch'\nimport JsonBig from './json-big'\nimport { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other'\n\nlet warnedAboutInternalApiUsage = false\n\n/**\n * Generator of Swagger client\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/swagger\n * @rtype Object\n * @param {String} specUrl - Swagger specification URL on external node host\n * @param {Object} options\n * @param {String} [options.spec] - Override OpenAPI definition\n * @param {String} [options.internalUrl] - Node internal URL\n * @param {Boolean} [options.disableBigNumbers]\n * @param {Boolean} [options.disableCaseConversion]\n * @return {Object} Swagger client\n * @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')\n */\nexport default async (specUrl, { spec, internalUrl, disableBigNumbers, disableCaseConversion } = {}) => {\n spec = spec || await (await fetch(specUrl)).json()\n const jsonImp = disableBigNumbers ? JSON : JsonBig\n\n const [external, internal] = await Promise.all([specUrl, internalUrl].map((url) => {\n if (!url) return null\n return SwaggerClient({\n url,\n spec,\n responseInterceptor: response => {\n if (!response.text) return response\n const body = jsonImp.parse(response.text)\n return Object.assign(response, {\n body: disableCaseConversion ? body : pascalizeKeys(body)\n })\n }\n })\n }))\n\n const combinedApi = [\n ...Object.values(external.apis),\n mapObject(internal?.apis.internal || {}, ([key, handler]) => [key, (...args) => {\n if (!warnedAboutInternalApiUsage) {\n console.warn(\n 'SDK\\'s wrapper of aeternity node internal API is deprecated, please use external ' +\n 'equivalent (for example, \"sdk.api.protectedDryRunTxs\" instead of \"sdk.api.dryRunTxs\") ' +\n 'or create a wrapper of internal API by yourself (using \"genSwaggerClient\")'\n )\n warnedAboutInternalApiUsage = true\n }\n return handler(...args)\n }])\n ].reduce((acc, n) => ({ ...acc, ...n }))\n\n const opSpecs = Object.values(spec.paths)\n .map(paths => Object.values(paths))\n .flat()\n .reduce((acc, n) => ({ ...acc, [n.operationId]: n }), {})\n\n const api = mapObject(combinedApi, ([opId, handler]) => [\n opId.slice(0, 1).toLowerCase() + opId.slice(1),\n async (...args) => {\n const opSpec = opSpecs[opId]\n const parameters = [\n ...opSpec.parameters,\n ...opSpec.requestBody ? [{\n required: opSpec.requestBody.required,\n schema: Object.values(opSpec.requestBody.content)[0].schema,\n name: '__requestBody'\n }] : []\n ]\n const required = parameters.filter(param => param.required).map(p => p.name)\n if (args.length < required.length) throw new Error('swagger: Not enough arguments')\n const values = required.reduce(\n (acc, req, idx) => ({ ...acc, [req]: args[idx] }),\n args[required.length] || {}\n )\n const { __requestBody, ...stringified } = mapObject(values, ([param, value]) => {\n if (typeof value !== 'object') return [param, value]\n const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties)\n const filteredValue = filterObject(\n disableCaseConversion ? value : snakizeKeys(value),\n ([key]) => rootKeys.includes(key)\n )\n return [param, jsonImp.stringify(filteredValue)]\n })\n return (await handler(stringified, { requestBody: __requestBody })).body\n }\n ])\n\n return Object.assign(external, { api })\n}\n"],"file":"swagger.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/swagger.js"],"names":["SwaggerClient","fetch","JsonBig","snakizeKeys","pascalizeKeys","mapObject","filterObject","warnedAboutInternalApiUsage","specUrl","spec","internalUrl","disableBigNumbers","disableCaseConversion","responseInterceptor","json","jsonImp","JSON","includes","URL","origin","schemes","external","internal","Promise","all","map","url","response","text","body","parse","Object","assign","combinedApi","values","apis","key","handler","console","warn","reduce","acc","n","opSpecs","paths","flat","operationId","api","opId","slice","toLowerCase","args","opSpec","parameters","requestBody","required","schema","content","name","filter","param","p","length","Error","req","idx","__requestBody","stringified","value","rootKeys","keys","find","properties","filteredValue","stringify"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,aAAP,MAA0B,gBAA1B;AACA,OAAOC,KAAP,MAAkB,aAAlB;AACA,OAAOC,OAAP,MAAoB,YAApB;AACA,SAASC,WAAT,EAAsBC,aAAtB,EAAqCC,SAArC,EAAgDC,YAAhD,QAAoE,SAApE;AAEA,IAAIC,2BAA2B,GAAG,KAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,gBAAe,gBACbC,OADa,EAGV;AAAA,MADH;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,WAAR;AAAqBC,IAAAA,iBAArB;AAAwCC,IAAAA,qBAAxC;AAA+DC,IAAAA;AAA/D,GACG,uEADoF,EACpF;AACHJ,EAAAA,IAAI,GAAGA,IAAI,KAAI,MAAM,CAAC,MAAMR,KAAK,CAACO,OAAD,CAAZ,EAAuBM,IAAvB,EAAV,CAAX;AACA,QAAMC,OAAO,GAAGJ,iBAAiB,GAAGK,IAAH,GAAUd,OAA3C;;AAEA,MACE,CACE,4BADF,EAEE,mCAFF,EAGEe,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,aAAlB,CAAR,CAAP;AACD,OARkD,CAAnD;AASA,aAAO,CAAC,MAAMpC,OAAO,CAAC8B,WAAD,EAAc;AAAEb,QAAAA,WAAW,EAAEY;AAAf,OAAd,CAAd,EAA6DrC,IAApE;AACD,KA9BqD,CAArB;AAAA,GAAd,CAArB;AAiCA,SAAOE,MAAM,CAACC,MAAP,CAAcX,QAAd,EAAwB;AAAE0B,IAAAA;AAAF,GAAxB,CAAP;AACD,CAvFD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Generator of Swagger client module\n * @module @aeternity/aepp-sdk/es/utils/swagger\n * @export genSwaggerClient\n */\n\nimport SwaggerClient from 'swagger-client'\nimport fetch from 'cross-fetch'\nimport JsonBig from './json-big'\nimport { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other'\n\nlet warnedAboutInternalApiUsage = false\n\n/**\n * Generator of Swagger client\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/swagger\n * @rtype Object\n * @param {String} specUrl - Swagger specification URL on external node host\n * @param {Object} options\n * @param {String} [options.spec] - Override OpenAPI definition\n * @param {String} [options.internalUrl] - Node internal URL\n * @param {Boolean} [options.disableBigNumbers]\n * @param {Boolean} [options.disableCaseConversion]\n * @param {Function} [options.responseInterceptor]\n * @return {Object} Swagger client\n * @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')\n */\nexport default async (\n specUrl,\n { spec, internalUrl, disableBigNumbers, disableCaseConversion, responseInterceptor } = {}\n) => {\n spec = spec || await (await fetch(specUrl)).json()\n const jsonImp = disableBigNumbers ? JSON : JsonBig\n\n if (\n [\n 'https://compiler.aepps.com',\n 'https://latest.compiler.aepps.com'\n ].includes(new URL(specUrl).origin) ||\n new URL(specUrl).origin.includes('https://')\n ) {\n spec.schemes = ['https']\n }\n\n const [external, internal] = await Promise.all([specUrl, internalUrl].map((url) => {\n if (!url) return null\n return SwaggerClient({\n url,\n spec,\n responseInterceptor: response => {\n if (!response.text) return response\n const body = jsonImp.parse(response.text)\n Object.assign(response, {\n body: disableCaseConversion ? body : pascalizeKeys(body)\n })\n return (responseInterceptor && responseInterceptor(response)) || response\n }\n })\n }))\n\n const combinedApi = [\n ...Object.values(external.apis),\n mapObject(internal?.apis.internal || {}, ([key, handler]) => [key, (...args) => {\n if (!warnedAboutInternalApiUsage) {\n console.warn(\n 'SDK\\'s wrapper of aeternity node internal API is deprecated, please use external ' +\n 'equivalent (for example, \"sdk.api.protectedDryRunTxs\" instead of \"sdk.api.dryRunTxs\") ' +\n 'or create a wrapper of internal API by yourself (using \"genSwaggerClient\")'\n )\n warnedAboutInternalApiUsage = true\n }\n return handler(...args)\n }])\n ].reduce((acc, n) => ({ ...acc, ...n }))\n\n const opSpecs = Object.values(spec.paths)\n .map(paths => Object.values(paths))\n .flat()\n .reduce((acc, n) => ({ ...acc, [n.operationId]: n }), {})\n\n const api = mapObject(combinedApi, ([opId, handler]) => [\n opId.slice(0, 1).toLowerCase() + opId.slice(1),\n async (...args) => {\n const opSpec = opSpecs[opId]\n const parameters = [\n ...opSpec.parameters,\n ...opSpec.requestBody\n ? [{\n required: opSpec.requestBody.required,\n schema: Object.values(opSpec.requestBody.content)[0].schema,\n name: '__requestBody'\n }]\n : []\n ]\n const required = parameters.filter(param => param.required).map(p => p.name)\n if (args.length < required.length) throw new Error('swagger: Not enough arguments')\n const values = required.reduce(\n (acc, req, idx) => ({ ...acc, [req]: args[idx] }),\n args[required.length] || {}\n )\n const { __requestBody, ...stringified } = mapObject(values, ([param, value]) => {\n if (typeof value !== 'object') return [param, value]\n const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties)\n const filteredValue = filterObject(\n disableCaseConversion ? value : snakizeKeys(value),\n ([key]) => rootKeys.includes(key)\n )\n return [param, jsonImp.stringify(filteredValue)]\n })\n return (await handler(stringified, { requestBody: __requestBody })).body\n }\n ])\n\n return Object.assign(external, { api })\n}\n"],"file":"swagger.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeternity/aepp-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-beta.1",
|
|
4
4
|
"description": "SDK for the æternity blockchain",
|
|
5
5
|
"main": "dist/aepp-sdk.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -13,18 +13,19 @@
|
|
|
13
13
|
"build:es": "tsc && babel src --config-file ./babel.esm.config.js --out-dir es --extensions '.js,.ts' --source-maps true",
|
|
14
14
|
"build": "webpack --mode=production && npm run build:es",
|
|
15
15
|
"build:dev": "webpack --mode=development && npm run build:es",
|
|
16
|
-
"docs:
|
|
16
|
+
"docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.js",
|
|
17
17
|
"docs:api": "node apidoc.js",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"docs:changelog": "cp CHANGELOG.md docs/CHANGELOG.md",
|
|
19
|
+
"lint": "commitlint --from 635f1aa --verbose && ts-standard",
|
|
20
|
+
"test": "nyc --require @babel/register --require ts-node/register mocha './test/unit/' './test/integration/' --recursive --exit --timeout 40s",
|
|
20
21
|
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
21
|
-
"test:integration:channel,accounts": "nyc --require @babel/register --require ts-node/register mocha './test/integration/@(channel|accounts).js' --exit --timeout
|
|
22
|
-
"test:integration:contract,chain": "nyc --require @babel/register --require ts-node/register mocha './test/integration/@(contract|chain).js' --timeout
|
|
23
|
-
"test:integration:else": "nyc --require @babel/register --require ts-node/register mocha './test/integration/!(channel|accounts|contract|chain).js' --timeout
|
|
22
|
+
"test:integration:channel,accounts": "nyc --require @babel/register --require ts-node/register mocha './test/integration/@(channel|accounts).js' --exit --timeout 40s",
|
|
23
|
+
"test:integration:contract,chain": "nyc --require @babel/register --require ts-node/register mocha './test/integration/@(contract|contract-aci|chain).js' --timeout 40s",
|
|
24
|
+
"test:integration:else": "nyc --require @babel/register --require ts-node/register mocha './test/integration/!(channel|accounts|contract|chain).js' --timeout 40s",
|
|
24
25
|
"test:unit": "nyc --require @babel/register --require ts-node/register mocha './test/unit/*'",
|
|
25
|
-
"test:watch": "mocha --recursive --require @babel/register --require ts-node/register --watch --timeout
|
|
26
|
+
"test:watch": "mocha --recursive --require @babel/register --require ts-node/register --watch --timeout 40s",
|
|
26
27
|
"prepare": "npm run build",
|
|
27
|
-
"prepublishOnly": "npm run docs:
|
|
28
|
+
"prepublishOnly": "npm run docs:examples && npm run docs:changelog",
|
|
28
29
|
"release": "standard-version --skip.tag"
|
|
29
30
|
},
|
|
30
31
|
"license": "ISC",
|
|
@@ -35,29 +36,30 @@
|
|
|
35
36
|
"SDK"
|
|
36
37
|
],
|
|
37
38
|
"dependencies": {
|
|
39
|
+
"@aeternity/aepp-calldata": "^1.0.0-rc1",
|
|
38
40
|
"@aeternity/bip39": "^0.1.0",
|
|
39
41
|
"@aeternity/json-bigint": "^0.3.1",
|
|
40
|
-
"@babel/runtime-corejs3": "^7.
|
|
42
|
+
"@babel/runtime-corejs3": "^7.16.3",
|
|
41
43
|
"@stamp/it": "^1.1.0",
|
|
42
44
|
"@stamp/required": "^1.0.1",
|
|
43
45
|
"aes-js": "^3.1.2",
|
|
44
46
|
"bignumber.js": "^9.0.1",
|
|
45
47
|
"bip32-path": "^0.4.2",
|
|
46
|
-
"blakejs": "^1.1.
|
|
48
|
+
"blakejs": "^1.1.1",
|
|
47
49
|
"bs58check": "^2.1.2",
|
|
48
50
|
"buffer": "^6.0.3",
|
|
49
51
|
"cross-fetch": "^3.1.4",
|
|
50
52
|
"crypto-browserify": "^3.12.0",
|
|
51
53
|
"ed2curve": "^0.3.0",
|
|
52
|
-
"
|
|
53
|
-
"libsodium-wrappers-sumo": "0.7.9",
|
|
54
|
+
"events": "^3.3.0",
|
|
55
|
+
"libsodium-wrappers-sumo": "^0.7.9",
|
|
54
56
|
"path-browserify": "^1.0.1",
|
|
55
57
|
"process": "^0.11.10",
|
|
56
58
|
"ramda": "^0.27.1",
|
|
57
|
-
"rlp": "2.2.
|
|
59
|
+
"rlp": "^2.2.7",
|
|
58
60
|
"sha.js": "^2.4.11",
|
|
59
61
|
"stream-browserify": "^3.0.0",
|
|
60
|
-
"swagger-client": "^3.
|
|
62
|
+
"swagger-client": "^3.17.0",
|
|
61
63
|
"tweetnacl": "^1.0.3",
|
|
62
64
|
"tweetnacl-auth": "^1.0.1",
|
|
63
65
|
"uuid": "^8.3.2",
|
|
@@ -68,44 +70,51 @@
|
|
|
68
70
|
"url": "https://github.com/aeternity/aepp-sdk-js"
|
|
69
71
|
},
|
|
70
72
|
"devDependencies": {
|
|
71
|
-
"@babel/cli": "7.
|
|
72
|
-
"@babel/core": "7.
|
|
73
|
-
"@babel/node": "7.
|
|
74
|
-
"@babel/plugin-
|
|
75
|
-
"@babel/
|
|
76
|
-
"@babel/
|
|
77
|
-
"@babel/
|
|
78
|
-
"@
|
|
79
|
-
"@
|
|
80
|
-
"@commitlint/cli": "^12.1.4",
|
|
81
|
-
"@commitlint/config-conventional": "^12.1.4",
|
|
73
|
+
"@babel/cli": "^7.16.0",
|
|
74
|
+
"@babel/core": "^7.16.0",
|
|
75
|
+
"@babel/node": "^7.16.0",
|
|
76
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
77
|
+
"@babel/preset-env": "^7.16.4",
|
|
78
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
79
|
+
"@babel/register": "^7.16.0",
|
|
80
|
+
"@commitlint/cli": "^15.0.0",
|
|
81
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
82
82
|
"@types/bn.js": "^5.1.0",
|
|
83
|
-
"@types/chai": "^4.2.
|
|
84
|
-
"@types/mocha": "^
|
|
85
|
-
"@types/node": "^
|
|
86
|
-
"babel-loader": "^8.2.
|
|
83
|
+
"@types/chai": "^4.2.22",
|
|
84
|
+
"@types/mocha": "^9.0.0",
|
|
85
|
+
"@types/node": "^16.11.9",
|
|
86
|
+
"babel-loader": "^8.2.3",
|
|
87
87
|
"babel-plugin-ramda": "^2.0.0",
|
|
88
88
|
"chai": "^4.3.4",
|
|
89
89
|
"chai-as-promised": "^7.1.1",
|
|
90
|
-
"codecov": "^3.8.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"mocha": "^8.4.0",
|
|
90
|
+
"codecov": "^3.8.3",
|
|
91
|
+
"jsdoc-to-markdown": "^7.1.0",
|
|
92
|
+
"mocha": "^9.1.3",
|
|
94
93
|
"nyc": "^15.1.0",
|
|
95
|
-
"
|
|
96
|
-
"sinon": "^11.1.1",
|
|
94
|
+
"sinon": "^12.0.1",
|
|
97
95
|
"source-map": "^0.7.3",
|
|
98
|
-
"standard-version": "^9.3.
|
|
99
|
-
"ts-node": "^10.
|
|
100
|
-
"ts-standard": "^
|
|
101
|
-
"typescript": "^4.
|
|
102
|
-
"webpack": "^5.
|
|
103
|
-
"webpack-bundle-analyzer": "^4.
|
|
104
|
-
"webpack-cli": "4.
|
|
96
|
+
"standard-version": "^9.3.2",
|
|
97
|
+
"ts-node": "^10.4.0",
|
|
98
|
+
"ts-standard": "^11.0.0",
|
|
99
|
+
"typescript": "^4.5.2",
|
|
100
|
+
"webpack": "^5.64.1",
|
|
101
|
+
"webpack-bundle-analyzer": "^4.5.0",
|
|
102
|
+
"webpack-cli": "^4.9.1"
|
|
105
103
|
},
|
|
106
104
|
"files": [
|
|
107
105
|
"dist",
|
|
108
106
|
"src",
|
|
109
107
|
"es"
|
|
108
|
+
],
|
|
109
|
+
"ts-standard": {
|
|
110
|
+
"ignore": [
|
|
111
|
+
"examples/**/*.js"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"browserslist": [
|
|
115
|
+
"> 1%",
|
|
116
|
+
"last 2 versions",
|
|
117
|
+
"not dead",
|
|
118
|
+
"not ie 11"
|
|
110
119
|
]
|
|
111
120
|
}
|
package/src/account/base.js
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
import stampit from '@stamp/it'
|
|
26
26
|
import { required } from '@stamp/required'
|
|
27
|
-
import { messageToHash,
|
|
28
|
-
import { buildTx
|
|
27
|
+
import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto'
|
|
28
|
+
import { buildTx } from '../tx/builder'
|
|
29
29
|
import { decode } from '../tx/builder/helpers'
|
|
30
30
|
import { TX_TYPE } from '../tx/builder/schema'
|
|
31
31
|
import { getNetworkId } from '../node'
|
|
@@ -45,15 +45,14 @@ export const isAccountBase = (acc) => !['sign', 'address'].find(f => typeof acc[
|
|
|
45
45
|
* @rtype (tx: String) => tx: Promise[String], throws: Error
|
|
46
46
|
* @param {String} tx - Transaction to sign
|
|
47
47
|
* @param {Object} opt - Options
|
|
48
|
+
* @param {Object} [opt.innerTx] - Sign as inner transaction for PayingFor
|
|
48
49
|
* @return {String} Signed transaction
|
|
49
50
|
*/
|
|
50
|
-
async function signTransaction (tx, opt) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
buildTxHash(rlpBinaryTx, { raw: true })
|
|
56
|
-
])
|
|
51
|
+
async function signTransaction (tx, opt = {}) {
|
|
52
|
+
const prefixes = [this.getNetworkId(opt)]
|
|
53
|
+
if (opt.innerTx) prefixes.push('inner_tx')
|
|
54
|
+
const rlpBinaryTx = decode(tx, 'tx')
|
|
55
|
+
const txWithNetworkId = Buffer.concat([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)])
|
|
57
56
|
|
|
58
57
|
const signatures = [await this.sign(txWithNetworkId, opt)]
|
|
59
58
|
return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx
|
package/src/account/multiple.js
CHANGED
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
* @export AccountMultiple
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import * as R from 'ramda'
|
|
25
24
|
import AsyncInit from '../utils/async-init'
|
|
26
25
|
import MemoryAccount from './memory'
|
|
27
|
-
import {
|
|
26
|
+
import { decode } from '../tx/builder/helpers'
|
|
28
27
|
import AccountBase, { isAccountBase } from './base'
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -50,10 +49,11 @@ import AccountBase, { isAccountBase } from './base'
|
|
|
50
49
|
*/
|
|
51
50
|
export default AccountBase.compose(AsyncInit, {
|
|
52
51
|
async init ({ accounts = [], address }) {
|
|
53
|
-
this.accounts =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
this.accounts = Object.fromEntries(await Promise.all(
|
|
53
|
+
accounts.map(async a => [await a.address(), a])
|
|
54
|
+
))
|
|
55
|
+
address = address || Object.keys(this.accounts)[0]
|
|
56
|
+
if (address) this.selectAccount(address)
|
|
57
57
|
},
|
|
58
58
|
props: {
|
|
59
59
|
accounts: {}
|
|
@@ -122,7 +122,7 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
122
122
|
* @example selectAccount('ak_xxxxxxxx')
|
|
123
123
|
*/
|
|
124
124
|
selectAccount (address) {
|
|
125
|
-
|
|
125
|
+
decode(address, 'ak')
|
|
126
126
|
if (!this.accounts[address]) throw new Error(`Account for ${address} not available`)
|
|
127
127
|
this.selectedAddress = address
|
|
128
128
|
},
|
|
@@ -133,15 +133,19 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
133
133
|
* @private
|
|
134
134
|
*/
|
|
135
135
|
_resolveAccount (account) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
if (account === null) {
|
|
137
|
+
throw new Error('No account or wallet configured')
|
|
138
|
+
} else {
|
|
139
|
+
switch (typeof account) {
|
|
140
|
+
case 'string':
|
|
141
|
+
decode(account, 'ak')
|
|
142
|
+
if (!this.accounts[account]) throw new Error(`Account for ${account} not available`)
|
|
143
|
+
return this.accounts[account]
|
|
144
|
+
case 'object':
|
|
145
|
+
return isAccountBase(account) ? account : MemoryAccount({ keypair: account })
|
|
146
|
+
default:
|
|
147
|
+
throw new Error(`Unknown account type: ${typeof account} (account: ${account})`)
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
}
|