@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
package/es/node.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
6
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
7
|
-
|
|
8
1
|
/*
|
|
9
2
|
* ISC License (ISC)
|
|
10
3
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -40,24 +33,16 @@ import semverSatisfies from './utils/semver-satisfies';
|
|
|
40
33
|
*/
|
|
41
34
|
|
|
42
35
|
export function getNetworkId() {
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* get consensus protocol version
|
|
54
|
-
* @param {Array} protocols Array of protocols
|
|
55
|
-
* @param {Number} height Height
|
|
56
|
-
* @return {Number} version Protocol version
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function getConsensusProtocolVersion() {
|
|
60
|
-
return _getConsensusProtocolVersion.apply(this, arguments);
|
|
36
|
+
var _this$selectedNode;
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
networkId,
|
|
40
|
+
force = false
|
|
41
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
42
|
+
const res = networkId || this.networkId || ((_this$selectedNode = this.selectedNode) === null || _this$selectedNode === void 0 ? void 0 : _this$selectedNode.networkId);
|
|
43
|
+
if (!force && !res) throw new Error('networkId is not provided');
|
|
44
|
+
if (force && !res) return null;
|
|
45
|
+
return res;
|
|
61
46
|
}
|
|
62
47
|
/**
|
|
63
48
|
* {@link genSwaggerClient} based Node remote API Stamp
|
|
@@ -67,145 +52,64 @@ function getConsensusProtocolVersion() {
|
|
|
67
52
|
* @param {Object} [options={}] - Options
|
|
68
53
|
* @param {String} options.url - Base URL for Node
|
|
69
54
|
* @param {String} options.internalUrl - Base URL for internal requests
|
|
70
|
-
* @param {
|
|
55
|
+
* @param {Object} options.axiosConfig - Object with axios configuration
|
|
56
|
+
* @param {Object} options.axiosConfig.config
|
|
57
|
+
* @param {Function} options.axiosConfig.errorHandler - (err) => throw err
|
|
71
58
|
* @return {Object} Node client
|
|
72
59
|
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
73
60
|
*/
|
|
74
61
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
throw new Error('Protocols must be an array');
|
|
96
|
-
|
|
97
|
-
case 4:
|
|
98
|
-
if (height) {
|
|
99
|
-
_context4.next = 8;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_context4.next = 7;
|
|
104
|
-
return this.api.getCurrentKeyBlock();
|
|
105
|
-
|
|
106
|
-
case 7:
|
|
107
|
-
height = _context4.sent.height;
|
|
108
|
-
|
|
109
|
-
case 8:
|
|
110
|
-
if (!(height < 0)) {
|
|
111
|
-
_context4.next = 10;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
throw new Error('height must be a number >= 0');
|
|
116
|
-
|
|
117
|
-
case 10:
|
|
118
|
-
return _context4.abrupt("return", _reduceInstanceProperty(_context3 = _filterInstanceProperty(protocols).call(protocols, function (_ref3) {
|
|
119
|
-
var effectiveAtHeight = _ref3.effectiveAtHeight;
|
|
120
|
-
return height >= effectiveAtHeight;
|
|
121
|
-
})).call(_context3, function (acc, p) {
|
|
122
|
-
return p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc;
|
|
123
|
-
}, {
|
|
124
|
-
effectiveAtHeight: -1,
|
|
125
|
-
version: 0
|
|
126
|
-
}).version);
|
|
127
|
-
|
|
128
|
-
case 11:
|
|
129
|
-
case "end":
|
|
130
|
-
return _context4.stop();
|
|
131
|
-
}
|
|
62
|
+
const Node = AsyncInit.compose({
|
|
63
|
+
async init(_ref) {
|
|
64
|
+
let {
|
|
65
|
+
url,
|
|
66
|
+
internalUrl,
|
|
67
|
+
ignoreVersion
|
|
68
|
+
} = _ref;
|
|
69
|
+
if (!url) throw new Error('"url" required');
|
|
70
|
+
this.url = url.replace(/\/$/, '');
|
|
71
|
+
this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url;
|
|
72
|
+
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
73
|
+
internalUrl: this.internalUrl,
|
|
74
|
+
responseInterceptor: response => {
|
|
75
|
+
if (response.ok) return;
|
|
76
|
+
return Object.assign(response, {
|
|
77
|
+
statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
|
|
78
|
+
});
|
|
132
79
|
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return genSwaggerClient("".concat(_this.url, "/api?oas3"), {
|
|
163
|
-
internalUrl: _this.internalUrl
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
case 7:
|
|
167
|
-
client = _context2.sent;
|
|
168
|
-
_this.version = client.spec.info.version;
|
|
169
|
-
|
|
170
|
-
if (!(!semverSatisfies(_this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion)) {
|
|
171
|
-
_context2.next = 11;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
throw new Error("Unsupported node version ".concat(_this.version, ". ") + _concatInstanceProperty(_context = "Supported: >= ".concat(NODE_GE_VERSION, " < ")).call(_context, NODE_LT_VERSION));
|
|
176
|
-
|
|
177
|
-
case 11:
|
|
178
|
-
_this.api = client.api;
|
|
179
|
-
_context2.next = 14;
|
|
180
|
-
return _this.api.getStatus();
|
|
181
|
-
|
|
182
|
-
case 14:
|
|
183
|
-
_yield$_this$api$getS = _context2.sent;
|
|
184
|
-
revision = _yield$_this$api$getS.nodeRevision;
|
|
185
|
-
genesisHash = _yield$_this$api$getS.genesisKeyBlockHash;
|
|
186
|
-
networkId = _yield$_this$api$getS.networkId;
|
|
187
|
-
protocols = _yield$_this$api$getS.protocols;
|
|
188
|
-
_context2.next = 21;
|
|
189
|
-
return _this.getConsensusProtocolVersion(protocols);
|
|
190
|
-
|
|
191
|
-
case 21:
|
|
192
|
-
_this.consensusProtocolVersion = _context2.sent;
|
|
193
|
-
_this.nodeNetworkId = networkId;
|
|
194
|
-
return _context2.abrupt("return", _Object$assign(_this, {
|
|
195
|
-
revision: revision,
|
|
196
|
-
genesisHash: genesisHash
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
|
-
case 24:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context2.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee);
|
|
205
|
-
}))();
|
|
80
|
+
});
|
|
81
|
+
this.version = client.spec.info.version;
|
|
82
|
+
|
|
83
|
+
if (!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion) {
|
|
84
|
+
throw new Error(`Unsupported node version ${this.version}. ` + `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.api = client.api;
|
|
88
|
+
const {
|
|
89
|
+
nodeRevision: revision,
|
|
90
|
+
genesisKeyBlockHash: genesisHash,
|
|
91
|
+
networkId,
|
|
92
|
+
protocols,
|
|
93
|
+
topBlockHeight
|
|
94
|
+
} = await this.api.getStatus();
|
|
95
|
+
this.consensusProtocolVersion = protocols.filter(_ref2 => {
|
|
96
|
+
let {
|
|
97
|
+
effectiveAtHeight
|
|
98
|
+
} = _ref2;
|
|
99
|
+
return topBlockHeight >= effectiveAtHeight;
|
|
100
|
+
}).reduce((acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc, {
|
|
101
|
+
effectiveAtHeight: -1,
|
|
102
|
+
version: 0
|
|
103
|
+
}).version;
|
|
104
|
+
this.nodeNetworkId = networkId;
|
|
105
|
+
return Object.assign(this, {
|
|
106
|
+
revision,
|
|
107
|
+
genesisHash
|
|
108
|
+
});
|
|
206
109
|
},
|
|
110
|
+
|
|
207
111
|
methods: {
|
|
208
|
-
getNodeInfo
|
|
112
|
+
getNodeInfo() {
|
|
209
113
|
return {
|
|
210
114
|
url: this.url,
|
|
211
115
|
internalUrl: this.internalUrl,
|
|
@@ -213,8 +117,8 @@ var Node = AsyncInit.compose({
|
|
|
213
117
|
version: this.version,
|
|
214
118
|
consensusProtocolVersion: this.consensusProtocolVersion
|
|
215
119
|
};
|
|
216
|
-
}
|
|
217
|
-
|
|
120
|
+
}
|
|
121
|
+
|
|
218
122
|
},
|
|
219
123
|
props: {
|
|
220
124
|
version: null,
|
|
@@ -222,7 +126,7 @@ var Node = AsyncInit.compose({
|
|
|
222
126
|
nodeNetworkId: null
|
|
223
127
|
}
|
|
224
128
|
});
|
|
225
|
-
|
|
226
|
-
|
|
129
|
+
const NODE_GE_VERSION = '6.2.0';
|
|
130
|
+
const NODE_LT_VERSION = '7.0.0';
|
|
227
131
|
export default Node;
|
|
228
132
|
//# sourceMappingURL=node.js.map
|
package/es/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node.js"],"names":["AsyncInit","genSwaggerClient","semverSatisfies","getNetworkId","networkId","force","selectedNode","Error","
|
|
1
|
+
{"version":3,"sources":["../src/node.js"],"names":["AsyncInit","genSwaggerClient","semverSatisfies","getNetworkId","networkId","force","res","selectedNode","Error","Node","compose","init","url","internalUrl","ignoreVersion","replace","client","responseInterceptor","response","ok","Object","assign","statusText","URL","pathname","slice","body","reason","version","spec","info","NODE_GE_VERSION","NODE_LT_VERSION","api","nodeRevision","revision","genesisKeyBlockHash","genesisHash","protocols","topBlockHeight","getStatus","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","nodeNetworkId","methods","getNodeInfo","props"],"mappings":"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","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 * Node module\n * @module @aeternity/aepp-sdk/es/node\n * @export Node\n * @example import { Node } from '@aeternity/aepp-sdk'\n */\n\nimport AsyncInit from './utils/async-init'\nimport genSwaggerClient from './utils/swagger'\nimport semverSatisfies from './utils/semver-satisfies'\n\n/**\n * Obtain networkId from account or node\n * @instance\n * @category async\n * @rtype () => networkId: String\n * @return {String} NetworkId\n */\nexport function getNetworkId ({ networkId, force = false } = {}) {\n const res = networkId || this.networkId || this.selectedNode?.networkId\n if (!force && !res) throw new Error('networkId is not provided')\n if (force && !res) return null\n return res\n}\n\n/**\n * {@link genSwaggerClient} based Node remote API Stamp\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node\n * @rtype Stamp\n * @param {Object} [options={}] - Options\n * @param {String} options.url - Base URL for Node\n * @param {String} options.internalUrl - Base URL for internal requests\n * @param {Object} options.axiosConfig - Object with axios configuration\n * @param {Object} options.axiosConfig.config\n * @param {Function} options.axiosConfig.errorHandler - (err) => throw err\n * @return {Object} Node client\n * @example Node({url: 'https://testnet.aeternity.io'})\n */\nconst Node = AsyncInit.compose({\n async init ({ url, internalUrl, ignoreVersion }) {\n if (!url) throw new Error('\"url\" required')\n this.url = url.replace(/\\/$/, '')\n this.internalUrl = internalUrl ? internalUrl.replace(/\\/$/, '') : this.url\n const client = await genSwaggerClient(`${this.url}/api?oas3`, {\n internalUrl: this.internalUrl,\n responseInterceptor: response => {\n if (response.ok) return\n return Object.assign(response, {\n statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason\n })\n }\n })\n this.version = client.spec.info.version\n if (\n !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&\n !ignoreVersion\n ) {\n throw new Error(\n `Unsupported node version ${this.version}. ` +\n `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`\n )\n }\n this.api = client.api\n\n const {\n nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,\n protocols, topBlockHeight\n } = await this.api.getStatus()\n this.consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,\n { effectiveAtHeight: -1, version: 0 }\n )\n .version\n this.nodeNetworkId = networkId\n return Object.assign(this, { revision, genesisHash })\n },\n methods: {\n getNodeInfo () {\n return {\n url: this.url,\n internalUrl: this.internalUrl,\n nodeNetworkId: this.nodeNetworkId,\n version: this.version,\n consensusProtocolVersion: this.consensusProtocolVersion\n }\n }\n },\n props: {\n version: null,\n consensusProtocolVersion: null,\n nodeNetworkId: null\n }\n})\n\nconst NODE_GE_VERSION = '6.2.0'\nconst NODE_LT_VERSION = '7.0.0'\n\nexport default Node\n"],"file":"node.js"}
|
package/es/other.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const pause: (duration: number) => Promise<
|
|
1
|
+
export declare const pause: (duration: number) => Promise<void>;
|
|
2
2
|
export declare const mapObject: (object: object, fn: (value: [string, any], index: number, array: Array<[string, any]>) => Array<[string, any]>) => object;
|
|
3
3
|
export declare const filterObject: (object: object, fn: (value: [string, any], index: number, array: Array<[string, any]>) => boolean) => object;
|
|
4
4
|
/**
|
package/es/tx/builder/helpers.js
CHANGED
|
@@ -3,20 +3,10 @@ import _lte from "ramda/src/lte";
|
|
|
3
3
|
import _always from "ramda/src/always";
|
|
4
4
|
import _lt from "ramda/src/lt";
|
|
5
5
|
import _cond from "ramda/src/cond";
|
|
6
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
7
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
8
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
9
|
-
import _padStartInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/pad-start";
|
|
10
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
11
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
12
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
13
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
14
|
-
import _endsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/ends-with";
|
|
15
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
16
6
|
import BigNumber from 'bignumber.js';
|
|
17
|
-
import {
|
|
7
|
+
import { decodeBase58Check, decodeBase64Check, encodeBase58Check, encodeBase64Check, hash, salt } from '../../utils/crypto';
|
|
18
8
|
import { toBytes } from '../../utils/bytes';
|
|
19
|
-
import { ID_TAG_PREFIX, PREFIX_ID_TAG, NAME_BID_RANGES, NAME_BID_MAX_LENGTH, NAME_FEE, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUTS,
|
|
9
|
+
import { ID_TAG_PREFIX, PREFIX_ID_TAG, NAME_BID_RANGES, NAME_BID_MAX_LENGTH, NAME_FEE, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUTS, NAME_MAX_LENGTH_FEE, POINTER_KEY_BY_PREFIX } from './schema';
|
|
20
10
|
import { ceil } from '../../utils/bignumber';
|
|
21
11
|
/**
|
|
22
12
|
* JavaScript-based Transaction builder helper function's
|
|
@@ -25,8 +15,8 @@ import { ceil } from '../../utils/bignumber';
|
|
|
25
15
|
* @example import { TxBuilderHelper } from '@aeternity/aepp-sdk'
|
|
26
16
|
*/
|
|
27
17
|
|
|
28
|
-
export
|
|
29
|
-
|
|
18
|
+
export const createSalt = salt;
|
|
19
|
+
const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba'];
|
|
30
20
|
/**
|
|
31
21
|
* Build a contract public key
|
|
32
22
|
* @function
|
|
@@ -37,27 +27,10 @@ var base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba'];
|
|
|
37
27
|
*/
|
|
38
28
|
|
|
39
29
|
export function buildContractId(ownerId, nonce) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var ownerIdAndNonce = Buffer.from(_concatInstanceProperty(_context = []).call(_context, _toConsumableArray(decode(ownerId, 'ak')), _toConsumableArray(toBytes(nonce))));
|
|
43
|
-
var b2bHash = hash(ownerIdAndNonce);
|
|
30
|
+
const ownerIdAndNonce = Buffer.from([...decode(ownerId, 'ak'), ...toBytes(nonce)]);
|
|
31
|
+
const b2bHash = hash(ownerIdAndNonce);
|
|
44
32
|
return encode(b2bHash, 'ct');
|
|
45
33
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Build hash
|
|
48
|
-
* @function
|
|
49
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
50
|
-
* @param {String} prefix Transaction hash prefix
|
|
51
|
-
* @param {Buffer} data Rlp encoded transaction buffer
|
|
52
|
-
* @param {Object} options
|
|
53
|
-
* @param {Boolean} options.raw
|
|
54
|
-
* @return {String} Transaction hash
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
export function buildHash(prefix, data) {
|
|
58
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
59
|
-
return options.raw ? hash(data) : encode(hash(data), prefix);
|
|
60
|
-
}
|
|
61
34
|
/**
|
|
62
35
|
* Build a oracle query id
|
|
63
36
|
* @function
|
|
@@ -69,14 +42,12 @@ export function buildHash(prefix, data) {
|
|
|
69
42
|
*/
|
|
70
43
|
|
|
71
44
|
export function oracleQueryId(senderId, nonce, oracleId) {
|
|
72
|
-
var _context2;
|
|
73
|
-
|
|
74
45
|
function _int32(val) {
|
|
75
|
-
|
|
76
|
-
return
|
|
46
|
+
const nonceBE = toBytes(val, true);
|
|
47
|
+
return Buffer.concat([Buffer.alloc(32 - nonceBE.length), nonceBE]);
|
|
77
48
|
}
|
|
78
49
|
|
|
79
|
-
|
|
50
|
+
const b2bHash = hash(Buffer.from([...decode(senderId, 'ak'), ..._int32(nonce), ...decode(oracleId, 'ok')]));
|
|
80
51
|
return encode(b2bHash, 'oq');
|
|
81
52
|
}
|
|
82
53
|
/**
|
|
@@ -88,9 +59,7 @@ export function oracleQueryId(senderId, nonce, oracleId) {
|
|
|
88
59
|
*/
|
|
89
60
|
|
|
90
61
|
export function formatSalt(salt) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return Buffer.from(_padStartInstanceProperty(_context3 = salt.toString(16)).call(_context3, 64, '0'), 'hex');
|
|
62
|
+
return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex');
|
|
94
63
|
}
|
|
95
64
|
/**
|
|
96
65
|
* Encode a domain name
|
|
@@ -118,23 +87,29 @@ export function produceNameId(name) {
|
|
|
118
87
|
*/
|
|
119
88
|
|
|
120
89
|
export function commitmentHash(name) {
|
|
121
|
-
|
|
90
|
+
let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createSalt();
|
|
122
91
|
ensureNameValid(name);
|
|
123
|
-
return
|
|
92
|
+
return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])))}`;
|
|
124
93
|
}
|
|
125
94
|
/**
|
|
126
95
|
* Decode data using the default encoding/decoding algorithm
|
|
127
96
|
* @function
|
|
128
97
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
129
|
-
* @param {string} data
|
|
130
|
-
* @param {string}
|
|
131
|
-
* @return {Buffer}
|
|
98
|
+
* @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
|
|
99
|
+
* @param {string} [requiredPrefix] Ensure that data have this prefix
|
|
100
|
+
* @return {Buffer} Decoded data
|
|
132
101
|
*/
|
|
133
102
|
|
|
134
|
-
export function decode(data) {
|
|
135
|
-
|
|
136
|
-
if (!
|
|
137
|
-
|
|
103
|
+
export function decode(data, requiredPrefix) {
|
|
104
|
+
const [prefix, payload, extra] = data.split('_');
|
|
105
|
+
if (!payload) throw new Error(`Encoded string missing payload: ${data}`);
|
|
106
|
+
if (extra) throw new Error(`Encoded string have extra parts: ${data}`);
|
|
107
|
+
|
|
108
|
+
if (requiredPrefix && requiredPrefix !== prefix) {
|
|
109
|
+
throw new Error(`Encoded string have a wrong type: ${prefix} (expected: ${requiredPrefix})`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (base64Types.includes(prefix) ? decodeBase64Check : decodeBase58Check)(payload);
|
|
138
113
|
}
|
|
139
114
|
/**
|
|
140
115
|
* Encode data using the default encoding/decoding algorithm
|
|
@@ -146,9 +121,7 @@ export function decode(data) {
|
|
|
146
121
|
*/
|
|
147
122
|
|
|
148
123
|
export function encode(data, type) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return _concatInstanceProperty(_context4 = "".concat(type, "_")).call(_context4, _includesInstanceProperty(base64Types).call(base64Types, type) ? encodeBase64Check(data) : encodeBase58Check(data));
|
|
124
|
+
return `${type}_${base64Types.includes(type) ? encodeBase64Check(data) : encodeBase58Check(data)}`;
|
|
152
125
|
}
|
|
153
126
|
/**
|
|
154
127
|
* Utility function to create and _id type
|
|
@@ -159,13 +132,14 @@ export function encode(data, type) {
|
|
|
159
132
|
*/
|
|
160
133
|
|
|
161
134
|
export function writeId(hashId) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
135
|
+
if (typeof hashId !== 'string') {
|
|
136
|
+
throw new Error(`Address should be a string, got ${hashId} instead`);
|
|
137
|
+
}
|
|
165
138
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
139
|
+
const prefix = hashId.slice(0, 2);
|
|
140
|
+
const idTag = PREFIX_ID_TAG[prefix];
|
|
141
|
+
if (!idTag) throw new Error(`Id tag for prefix ${prefix} not found.`);
|
|
142
|
+
return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)]);
|
|
169
143
|
}
|
|
170
144
|
/**
|
|
171
145
|
* Utility function to read and _id type
|
|
@@ -176,10 +150,10 @@ export function writeId(hashId) {
|
|
|
176
150
|
*/
|
|
177
151
|
|
|
178
152
|
export function readId(buf) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (!prefix) throw new Error(
|
|
182
|
-
return encode(
|
|
153
|
+
const tag = buf.readUIntBE(0, 1);
|
|
154
|
+
const prefix = ID_TAG_PREFIX[tag];
|
|
155
|
+
if (!prefix) throw new Error(`Prefix for id-tag ${tag} not found.`);
|
|
156
|
+
return encode(buf.slice(1, buf.length), prefix);
|
|
183
157
|
}
|
|
184
158
|
/**
|
|
185
159
|
* Utility function to convert int to bytes
|
|
@@ -201,37 +175,34 @@ export function writeInt(val) {
|
|
|
201
175
|
*/
|
|
202
176
|
|
|
203
177
|
export function readInt() {
|
|
204
|
-
|
|
178
|
+
let buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Buffer.from([]);
|
|
205
179
|
return BigNumber(buf.toString('hex'), 16).toString(10);
|
|
206
180
|
}
|
|
207
181
|
/**
|
|
208
182
|
* Helper function to build pointers for name update TX
|
|
209
183
|
* @function
|
|
210
184
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
211
|
-
* @param {Array} pointers - Array of pointers
|
|
185
|
+
* @param {Array} pointers - Array of pointers
|
|
186
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
212
187
|
* @return {Array} Serialized pointers array
|
|
213
188
|
*/
|
|
214
189
|
|
|
215
190
|
export function buildPointers(pointers) {
|
|
216
|
-
return
|
|
217
|
-
return [toBytes(p.key), writeId(p.id)];
|
|
218
|
-
});
|
|
191
|
+
return pointers.map(p => [toBytes(p.key), writeId(p.id)]);
|
|
219
192
|
}
|
|
220
193
|
/**
|
|
221
194
|
* Helper function to read pointers from name update TX
|
|
222
195
|
* @function
|
|
223
196
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
224
|
-
* @param {Array} pointers - Array of pointers
|
|
197
|
+
* @param {Array} pointers - Array of pointers
|
|
198
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
225
199
|
* @return {Array} Deserialize pointer array
|
|
226
200
|
*/
|
|
227
201
|
|
|
228
202
|
export function readPointers(pointers) {
|
|
229
|
-
return
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
id = _ref2[1];
|
|
233
|
-
|
|
234
|
-
return _Object$assign({
|
|
203
|
+
return pointers.map(_ref => {
|
|
204
|
+
let [key, id] = _ref;
|
|
205
|
+
return Object.assign({
|
|
235
206
|
key: key.toString(),
|
|
236
207
|
id: readId(id)
|
|
237
208
|
});
|
|
@@ -248,7 +219,7 @@ export function readPointers(pointers) {
|
|
|
248
219
|
|
|
249
220
|
export function ensureNameValid(name) {
|
|
250
221
|
if (!name || typeof name !== 'string') throw new Error('Name must be a string');
|
|
251
|
-
if (!
|
|
222
|
+
if (!name.endsWith('.chain')) throw new Error(`Name should end with .chain: ${name}`);
|
|
252
223
|
}
|
|
253
224
|
/**
|
|
254
225
|
* Is name valid
|
|
@@ -267,41 +238,17 @@ export function isNameValid(name) {
|
|
|
267
238
|
}
|
|
268
239
|
}
|
|
269
240
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* @param s - the hash.
|
|
274
|
-
* returns the type, or throws an exception if type not found.
|
|
275
|
-
*/
|
|
276
|
-
|
|
277
|
-
export function classify(s) {
|
|
278
|
-
if (!s.match(/^[a-z]{2}_.+/)) {
|
|
279
|
-
throw new Error('Not a valid hash');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var klass = s.substr(0, 2);
|
|
283
|
-
|
|
284
|
-
if (klass in NAME_ID_KEY) {
|
|
285
|
-
return NAME_ID_KEY[klass];
|
|
286
|
-
} else {
|
|
287
|
-
throw new Error("Unknown class ".concat(klass));
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Validate name pointers array
|
|
292
|
-
* @function
|
|
293
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
294
|
-
* @param {String[]} pointers Pointers array. Allowed values is: account(ak_), oracle(ok_), contract(ct_), channel(ch_)
|
|
295
|
-
* @return {Boolean}
|
|
241
|
+
* @param identifier - account/oracle/contract address, or channel
|
|
242
|
+
* @returns {String} default AENS pointer key
|
|
243
|
+
* @throws exception when default key not defined
|
|
296
244
|
*/
|
|
297
245
|
|
|
298
|
-
export function
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
});
|
|
246
|
+
export function getDefaultPointerKey(identifier) {
|
|
247
|
+
decode(identifier);
|
|
248
|
+
const prefix = identifier.substr(0, 2);
|
|
249
|
+
return POINTER_KEY_BY_PREFIX[prefix] || (() => {
|
|
250
|
+
throw new Error(`Default AENS pointer key is not defined for ${prefix} prefix`);
|
|
251
|
+
})();
|
|
305
252
|
}
|
|
306
253
|
/**
|
|
307
254
|
* Get the minimum name fee for a domain
|
|
@@ -312,8 +259,8 @@ export function validatePointers() {
|
|
|
312
259
|
*/
|
|
313
260
|
|
|
314
261
|
export function getMinimumNameFee(domain) {
|
|
315
|
-
|
|
316
|
-
return NAME_BID_RANGES[nameLength >=
|
|
262
|
+
const nameLength = domain.replace('.chain', '').length;
|
|
263
|
+
return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength];
|
|
317
264
|
}
|
|
318
265
|
/**
|
|
319
266
|
* Compute bid fee for AENS auction
|
|
@@ -326,10 +273,10 @@ export function getMinimumNameFee(domain) {
|
|
|
326
273
|
*/
|
|
327
274
|
|
|
328
275
|
export function computeBidFee(domain) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(
|
|
332
|
-
if (increment < NAME_FEE_BID_INCREMENT) throw new Error(
|
|
276
|
+
let startFee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NAME_FEE;
|
|
277
|
+
let increment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NAME_FEE_BID_INCREMENT;
|
|
278
|
+
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`);
|
|
279
|
+
if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);
|
|
333
280
|
return ceil(BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1)));
|
|
334
281
|
}
|
|
335
282
|
/**
|