@airgap/aeternity 0.13.45-beta.1 → 0.13.45-beta.3
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/package.json +4 -4
- package/v0/index.js +7 -7
- package/v0/index.js.map +1 -1
- package/v0/protocol/AeternityAddress.js +27 -18
- package/v0/protocol/AeternityAddress.js.map +1 -1
- package/v0/protocol/AeternityCryptoClient.js +21 -84
- package/v0/protocol/AeternityCryptoClient.js.map +1 -1
- package/v0/protocol/AeternityProtocol.js +341 -657
- package/v0/protocol/AeternityProtocol.js.map +1 -1
- package/v0/protocol/AeternityProtocolOptions.js +22 -93
- package/v0/protocol/AeternityProtocolOptions.js.map +1 -1
- package/v0/serializer/validators/transaction-validator.js +30 -83
- package/v0/serializer/validators/transaction-validator.js.map +1 -1
- package/v0/serializer/validators/validators.js +19 -67
- package/v0/serializer/validators/validators.js.map +1 -1
- package/v1/block-explorer/AeternityBlockExplorer.js +12 -61
- package/v1/block-explorer/AeternityBlockExplorer.js.map +1 -1
- package/v1/data/AeternityAddress.js +12 -13
- package/v1/data/AeternityAddress.js.map +1 -1
- package/v1/index.js +3 -3
- package/v1/index.js.map +1 -1
- package/v1/module/AeternityModule.d.ts +1 -1
- package/v1/module/AeternityModule.js +37 -95
- package/v1/module/AeternityModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/protocol/AeternityCryptoClient.js +21 -84
- package/v1/protocol/AeternityCryptoClient.js.map +1 -1
- package/v1/protocol/AeternityProtocol.js +282 -497
- package/v1/protocol/AeternityProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +8 -20
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +69 -148
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +15 -63
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +19 -67
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/protocol.d.ts +1 -1
- package/v1/utils/convert.js +26 -17
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/key.js +9 -10
- package/v1/utils/key.js.map +1 -1
- package/v1/utils/signature.js +6 -7
- package/v1/utils/signature.js.map +1 -1
- package/v1/utils/transaction.d.ts +0 -1
- package/v1/utils/transaction.js +26 -17
- package/v1/utils/transaction.js.map +1 -1
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -30,405 +15,231 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
30
15
|
}) : function(o, v) {
|
|
31
16
|
o["default"] = v;
|
|
32
17
|
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
-
function step(op) {
|
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
-
while (_) try {
|
|
56
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
-
switch (op[0]) {
|
|
59
|
-
case 0: case 1: t = op; break;
|
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
-
default:
|
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
-
if (t[2]) _.ops.pop();
|
|
69
|
-
_.trys.pop(); continue;
|
|
70
|
-
}
|
|
71
|
-
op = body.call(thisArg, _);
|
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
-
}
|
|
75
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
76
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
77
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78
37
|
};
|
|
79
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
39
|
exports.AeternityProtocol = void 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
_this.identifier = ProtocolSymbols_1.MainProtocolSymbols.AE;
|
|
110
|
-
_this.feeDefaults = {
|
|
40
|
+
const index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
41
|
+
const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
42
|
+
const index_2 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0/index");
|
|
43
|
+
const bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
44
|
+
const index_3 = require("@airgap/coinlib-core/dependencies/src/hd-wallet-js-b216450e56954a6e82ace0aade9474673de5d9d5/src/index");
|
|
45
|
+
const rlp = __importStar(require("@airgap/coinlib-core/dependencies/src/rlp-2.2.3/index"));
|
|
46
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
47
|
+
const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
48
|
+
const NonExtendedProtocol_1 = require("@airgap/coinlib-core/protocols/NonExtendedProtocol");
|
|
49
|
+
const base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
|
|
50
|
+
const hex_1 = require("@airgap/coinlib-core/utils/hex");
|
|
51
|
+
const ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
|
|
52
|
+
const ed25519_1 = require("@stablelib/ed25519");
|
|
53
|
+
const AeternityAddress_1 = require("./AeternityAddress");
|
|
54
|
+
const AeternityCryptoClient_1 = require("./AeternityCryptoClient");
|
|
55
|
+
const AeternityProtocolOptions_1 = require("./AeternityProtocolOptions");
|
|
56
|
+
class AeternityProtocol extends NonExtendedProtocol_1.NonExtendedProtocol {
|
|
57
|
+
constructor(options = new AeternityProtocolOptions_1.AeternityProtocolOptions()) {
|
|
58
|
+
super();
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.symbol = 'AE';
|
|
61
|
+
this.name = 'æternity';
|
|
62
|
+
this.marketSymbol = 'ae';
|
|
63
|
+
this.feeSymbol = 'ae';
|
|
64
|
+
this.decimals = 18;
|
|
65
|
+
this.feeDecimals = 18;
|
|
66
|
+
this.identifier = ProtocolSymbols_1.MainProtocolSymbols.AE;
|
|
67
|
+
this.feeDefaults = {
|
|
111
68
|
low: '0.00021',
|
|
112
69
|
medium: '0.000315',
|
|
113
70
|
high: '0.00084'
|
|
114
71
|
};
|
|
115
|
-
|
|
72
|
+
this.units = [
|
|
116
73
|
{
|
|
117
74
|
unitSymbol: 'AE',
|
|
118
75
|
factor: '1'
|
|
119
76
|
}
|
|
120
77
|
];
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
78
|
+
this.supportsHD = false;
|
|
79
|
+
this.standardDerivationPath = `m/44h/457h/0h/0h/0h`;
|
|
80
|
+
this.addressIsCaseSensitive = true;
|
|
81
|
+
this.addressValidationPattern = '^ak_+[1-9A-Za-z]{38,50}$';
|
|
82
|
+
this.addressPlaceholder = 'ak_abc...';
|
|
126
83
|
// ae specifics
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
AeternityProtocol.prototype.getUnits = function () {
|
|
196
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
-
return __generator(this, function (_a) {
|
|
198
|
-
return [2 /*return*/, this.units];
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
AeternityProtocol.prototype.getSupportsHD = function () {
|
|
203
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
204
|
-
return __generator(this, function (_a) {
|
|
205
|
-
return [2 /*return*/, this.supportsHD];
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
AeternityProtocol.prototype.getStandardDerivationPath = function () {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
return [2 /*return*/, this.standardDerivationPath];
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
AeternityProtocol.prototype.getAddressIsCaseSensitive = function () {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
-
return __generator(this, function (_a) {
|
|
219
|
-
return [2 /*return*/, this.addressIsCaseSensitive];
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
};
|
|
223
|
-
AeternityProtocol.prototype.getAddressValidationPattern = function () {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
return __generator(this, function (_a) {
|
|
226
|
-
return [2 /*return*/, this.addressValidationPattern];
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
AeternityProtocol.prototype.getAddressPlaceholder = function () {
|
|
231
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
232
|
-
return __generator(this, function (_a) {
|
|
233
|
-
return [2 /*return*/, this.addressPlaceholder];
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
};
|
|
237
|
-
AeternityProtocol.prototype.getOptions = function () {
|
|
238
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
return __generator(this, function (_a) {
|
|
240
|
-
return [2 /*return*/, this.options];
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
AeternityProtocol.prototype.getBlockExplorerLinkForAddress = function (address) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
-
return __generator(this, function (_a) {
|
|
247
|
-
return [2 /*return*/, this.options.network.blockExplorer.getAddressLink(address)];
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
AeternityProtocol.prototype.getBlockExplorerLinkForTxId = function (txId) {
|
|
252
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
return __generator(this, function (_a) {
|
|
254
|
-
return [2 /*return*/, this.options.network.blockExplorer.getTransactionLink(txId)];
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
AeternityProtocol.prototype.getPublicKeyFromMnemonic = function (mnemonic, derivationPath, password) {
|
|
259
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
-
var secret;
|
|
261
|
-
return __generator(this, function (_a) {
|
|
262
|
-
secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
263
|
-
return [2 /*return*/, this.getPublicKeyFromHexSecret(secret, derivationPath)];
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
};
|
|
267
|
-
AeternityProtocol.prototype.getPrivateKeyFromMnemonic = function (mnemonic, derivationPath, password) {
|
|
268
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
-
var secret;
|
|
270
|
-
return __generator(this, function (_a) {
|
|
271
|
-
secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
272
|
-
return [2 /*return*/, this.getPrivateKeyFromHexSecret(secret, derivationPath)];
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
};
|
|
84
|
+
this.defaultNetworkId = 'ae_mainnet';
|
|
85
|
+
this.feesURL = 'https://api-airgap.gke.papers.tech/fees';
|
|
86
|
+
this.cryptoClient = new AeternityCryptoClient_1.AeternityCryptoClient();
|
|
87
|
+
}
|
|
88
|
+
async getSymbol() {
|
|
89
|
+
return this.symbol;
|
|
90
|
+
}
|
|
91
|
+
async getName() {
|
|
92
|
+
return this.name;
|
|
93
|
+
}
|
|
94
|
+
async getMarketSymbol() {
|
|
95
|
+
return this.marketSymbol;
|
|
96
|
+
}
|
|
97
|
+
async getAssetSymbol() {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
async getFeeSymbol() {
|
|
101
|
+
return this.feeSymbol;
|
|
102
|
+
}
|
|
103
|
+
async getDecimals() {
|
|
104
|
+
return this.decimals;
|
|
105
|
+
}
|
|
106
|
+
async getFeeDecimals() {
|
|
107
|
+
return this.feeDecimals;
|
|
108
|
+
}
|
|
109
|
+
async getIdentifier() {
|
|
110
|
+
return this.identifier;
|
|
111
|
+
}
|
|
112
|
+
async getFeeDefaults() {
|
|
113
|
+
return this.feeDefaults;
|
|
114
|
+
}
|
|
115
|
+
async getUnits() {
|
|
116
|
+
return this.units;
|
|
117
|
+
}
|
|
118
|
+
async getSupportsHD() {
|
|
119
|
+
return this.supportsHD;
|
|
120
|
+
}
|
|
121
|
+
async getStandardDerivationPath() {
|
|
122
|
+
return this.standardDerivationPath;
|
|
123
|
+
}
|
|
124
|
+
async getAddressIsCaseSensitive() {
|
|
125
|
+
return this.addressIsCaseSensitive;
|
|
126
|
+
}
|
|
127
|
+
async getAddressValidationPattern() {
|
|
128
|
+
return this.addressValidationPattern;
|
|
129
|
+
}
|
|
130
|
+
async getAddressPlaceholder() {
|
|
131
|
+
return this.addressPlaceholder;
|
|
132
|
+
}
|
|
133
|
+
async getOptions() {
|
|
134
|
+
return this.options;
|
|
135
|
+
}
|
|
136
|
+
async getBlockExplorerLinkForAddress(address) {
|
|
137
|
+
return this.options.network.blockExplorer.getAddressLink(address);
|
|
138
|
+
}
|
|
139
|
+
async getBlockExplorerLinkForTxId(txId) {
|
|
140
|
+
return this.options.network.blockExplorer.getTransactionLink(txId);
|
|
141
|
+
}
|
|
142
|
+
async getPublicKeyFromMnemonic(mnemonic, derivationPath, password) {
|
|
143
|
+
const secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
144
|
+
return this.getPublicKeyFromHexSecret(secret, derivationPath);
|
|
145
|
+
}
|
|
146
|
+
async getPrivateKeyFromMnemonic(mnemonic, derivationPath, password) {
|
|
147
|
+
const secret = (0, index_2.mnemonicToSeed)(mnemonic, password);
|
|
148
|
+
return this.getPrivateKeyFromHexSecret(secret, derivationPath);
|
|
149
|
+
}
|
|
276
150
|
/**
|
|
277
151
|
* Returns the PublicKey as String, derived from a supplied hex-string
|
|
278
152
|
* @param secret HEX-Secret from BIP39
|
|
279
153
|
* @param derivationPath DerivationPath for Key
|
|
280
154
|
*/
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
publicKey = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath).publicKey;
|
|
286
|
-
return [2 /*return*/, Buffer.from(publicKey).toString('hex')];
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
};
|
|
155
|
+
async getPublicKeyFromHexSecret(secret, derivationPath) {
|
|
156
|
+
const { publicKey } = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath);
|
|
157
|
+
return Buffer.from(publicKey).toString('hex');
|
|
158
|
+
}
|
|
290
159
|
/**
|
|
291
160
|
* Returns the PrivateKey as Buffer, derived from a supplied hex-string
|
|
292
161
|
* @param secret HEX-Secret from BIP39
|
|
293
162
|
* @param derivationPath DerivationPath for Key
|
|
294
163
|
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return __generator(this, function (_b) {
|
|
349
|
-
switch (_b.label) {
|
|
350
|
-
case 0:
|
|
351
|
-
endpoint = cursor === undefined ? "/txs/backward?account=".concat(address, "&limit=").concat(limit) : cursor.next[address];
|
|
352
|
-
url = endpoint !== undefined ? "".concat(this.options.network.rpcUrl, "/mdw/").concat(endpoint.replace(/^\/+/, '')) : undefined;
|
|
353
|
-
if (!(url !== undefined)) return [3 /*break*/, 2];
|
|
354
|
-
return [4 /*yield*/, index_1.default.get(url)];
|
|
355
|
-
case 1:
|
|
356
|
-
_a = _b.sent();
|
|
357
|
-
return [3 /*break*/, 3];
|
|
358
|
-
case 2:
|
|
359
|
-
_a = undefined;
|
|
360
|
-
_b.label = 3;
|
|
361
|
-
case 3:
|
|
362
|
-
response = _a;
|
|
363
|
-
return [2 /*return*/, {
|
|
364
|
-
address: address,
|
|
365
|
-
data: response === null || response === void 0 ? void 0 : response.data
|
|
366
|
-
}];
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}); }))];
|
|
370
|
-
case 1:
|
|
371
|
-
groupedTransactions = _b.sent();
|
|
372
|
-
_a = groupedTransactions.reduce(function (acc, curr) {
|
|
373
|
-
var _a;
|
|
374
|
-
var _b, _c;
|
|
375
|
-
var nextAcc = ((_b = curr.data) === null || _b === void 0 ? void 0 : _b.next) ? Object.assign(acc[0], (_a = {}, _a[curr.address] = curr.data.next, _a)) : acc[0];
|
|
376
|
-
var transactionsAcc = acc[1].concat(((_c = curr.data) === null || _c === void 0 ? void 0 : _c.data) || []);
|
|
377
|
-
return [nextAcc, transactionsAcc];
|
|
378
|
-
}, [{}, []]), next = _a[0], allTransactions = _a[1];
|
|
379
|
-
transactions = allTransactions.map(function (obj) {
|
|
380
|
-
var parsedTimestamp = parseInt(obj.micro_time, 10);
|
|
381
|
-
var airGapTx = {
|
|
382
|
-
amount: new bignumber_1.default(obj.tx.amount).toString(10),
|
|
383
|
-
fee: new bignumber_1.default(obj.tx.fee).toString(10),
|
|
384
|
-
from: [obj.tx.sender_id],
|
|
385
|
-
isInbound: addresses.indexOf(obj.tx.recipient_id) !== -1,
|
|
386
|
-
protocolIdentifier: _this.identifier,
|
|
387
|
-
network: _this.options.network,
|
|
388
|
-
to: [obj.tx.recipient_id],
|
|
389
|
-
hash: obj.hash,
|
|
390
|
-
blockHeight: obj.block_height
|
|
391
|
-
};
|
|
392
|
-
if (obj.tx.payload) {
|
|
393
|
-
airGapTx.data = obj.tx.payload;
|
|
394
|
-
}
|
|
395
|
-
if (!isNaN(parsedTimestamp)) {
|
|
396
|
-
airGapTx.timestamp = Math.round(parsedTimestamp / 1000);
|
|
397
|
-
}
|
|
398
|
-
return airGapTx;
|
|
399
|
-
});
|
|
400
|
-
return [2 /*return*/, { transactions: transactions, cursor: { next: next } }];
|
|
401
|
-
}
|
|
402
|
-
});
|
|
164
|
+
async getPrivateKeyFromHexSecret(secret, derivationPath) {
|
|
165
|
+
const { secretKey } = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath);
|
|
166
|
+
return Buffer.from(secretKey).toString('hex');
|
|
167
|
+
}
|
|
168
|
+
async getAddressFromPublicKey(publicKey, cursor) {
|
|
169
|
+
return {
|
|
170
|
+
address: AeternityAddress_1.AeternityAddress.from(publicKey).asString(),
|
|
171
|
+
cursor: { hasNext: false }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async getAddressesFromPublicKey(publicKey, cursor) {
|
|
175
|
+
const address = await this.getAddressFromPublicKey(publicKey, cursor);
|
|
176
|
+
return [address];
|
|
177
|
+
}
|
|
178
|
+
async getTransactionsFromPublicKey(publicKey, limit, cursor) {
|
|
179
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
180
|
+
return this.getTransactionsFromAddresses([address.address], limit, cursor);
|
|
181
|
+
}
|
|
182
|
+
async getTransactionsFromAddresses(addresses, limit, cursor) {
|
|
183
|
+
const groupedTransactions = await Promise.all(addresses.map(async (address) => {
|
|
184
|
+
const endpoint = cursor === undefined ? `/txs/backward?account=${address}&limit=${limit}` : cursor.next[address];
|
|
185
|
+
const url = endpoint !== undefined ? `${this.options.network.rpcUrl}/mdw/${endpoint.replace(/^\/+/, '')}` : undefined;
|
|
186
|
+
const response = url !== undefined ? await index_1.default.get(url) : undefined;
|
|
187
|
+
return {
|
|
188
|
+
address,
|
|
189
|
+
data: response?.data
|
|
190
|
+
};
|
|
191
|
+
}));
|
|
192
|
+
const [next, allTransactions] = groupedTransactions.reduce((acc, curr) => {
|
|
193
|
+
const nextAcc = curr.data?.next ? Object.assign(acc[0], { [curr.address]: curr.data.next }) : acc[0];
|
|
194
|
+
const transactionsAcc = acc[1].concat(curr.data?.data || []);
|
|
195
|
+
return [nextAcc, transactionsAcc];
|
|
196
|
+
}, [{}, []]);
|
|
197
|
+
const transactions = allTransactions.map((obj) => {
|
|
198
|
+
const parsedTimestamp = parseInt(obj.micro_time, 10);
|
|
199
|
+
const airGapTx = {
|
|
200
|
+
amount: new bignumber_1.default(obj.tx.amount).toString(10),
|
|
201
|
+
fee: new bignumber_1.default(obj.tx.fee).toString(10),
|
|
202
|
+
from: [obj.tx.sender_id],
|
|
203
|
+
isInbound: addresses.indexOf(obj.tx.recipient_id) !== -1,
|
|
204
|
+
protocolIdentifier: this.identifier,
|
|
205
|
+
network: this.options.network,
|
|
206
|
+
to: [obj.tx.recipient_id],
|
|
207
|
+
hash: obj.hash,
|
|
208
|
+
blockHeight: obj.block_height
|
|
209
|
+
};
|
|
210
|
+
if (obj.tx.payload) {
|
|
211
|
+
airGapTx.data = obj.tx.payload;
|
|
212
|
+
}
|
|
213
|
+
if (!isNaN(parsedTimestamp)) {
|
|
214
|
+
airGapTx.timestamp = Math.round(parsedTimestamp / 1000);
|
|
215
|
+
}
|
|
216
|
+
return airGapTx;
|
|
403
217
|
});
|
|
404
|
-
|
|
405
|
-
|
|
218
|
+
return { transactions, cursor: { next } };
|
|
219
|
+
}
|
|
220
|
+
getPageNumber(limit, offset) {
|
|
406
221
|
if (limit <= 0 || offset < 0) {
|
|
407
222
|
return 1;
|
|
408
223
|
}
|
|
409
224
|
return 1 + Math.floor(offset / limit); // We need +1 here because pages start at 1
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
|
-
AeternityProtocol.prototype.decodeTx = function (transaction) {
|
|
431
|
-
var rawTx;
|
|
225
|
+
}
|
|
226
|
+
async signWithPrivateKey(privateKey, transaction) {
|
|
227
|
+
// sign and cut off first byte ('ae')
|
|
228
|
+
const rawTx = this.decodeTx(transaction.transaction);
|
|
229
|
+
const signature = (0, ed25519_1.sign)(Buffer.from(privateKey, 'hex'), Buffer.concat([Buffer.from(transaction.networkId), rawTx]));
|
|
230
|
+
const txObj = {
|
|
231
|
+
tag: (0, hex_1.toHexBuffer)(11),
|
|
232
|
+
version: (0, hex_1.toHexBuffer)(1),
|
|
233
|
+
signatures: [Buffer.from(signature)],
|
|
234
|
+
transaction: rawTx
|
|
235
|
+
};
|
|
236
|
+
const txArray = Object.keys(txObj).map((a) => txObj[a]);
|
|
237
|
+
const rlpEncodedTx = rlp.encode(txArray);
|
|
238
|
+
const signedEncodedTx = `tx_${base64Check_1.default.encode(rlpEncodedTx)}`;
|
|
239
|
+
return signedEncodedTx;
|
|
240
|
+
}
|
|
241
|
+
decodeTx(transaction) {
|
|
242
|
+
let rawTx;
|
|
432
243
|
try {
|
|
433
244
|
rawTx = base64Check_1.default.decode(transaction.replace('tx_', ''));
|
|
434
245
|
return rawTx;
|
|
@@ -444,289 +255,162 @@ var AeternityProtocol = /** @class */ (function (_super) {
|
|
|
444
255
|
//
|
|
445
256
|
}
|
|
446
257
|
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.AETERNITY, 'invalid TX-encoding');
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
return [2 /*return*/, this.getTransactionDetails(unsignedAeternityTransaction)];
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
AeternityProtocol.prototype.getBalanceOfAddresses = function (addresses) {
|
|
497
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
498
|
-
var balance, _i, addresses_1, address, data, error_1;
|
|
499
|
-
return __generator(this, function (_a) {
|
|
500
|
-
switch (_a.label) {
|
|
501
|
-
case 0:
|
|
502
|
-
balance = new bignumber_1.default(0);
|
|
503
|
-
_i = 0, addresses_1 = addresses;
|
|
504
|
-
_a.label = 1;
|
|
505
|
-
case 1:
|
|
506
|
-
if (!(_i < addresses_1.length)) return [3 /*break*/, 6];
|
|
507
|
-
address = addresses_1[_i];
|
|
508
|
-
_a.label = 2;
|
|
509
|
-
case 2:
|
|
510
|
-
_a.trys.push([2, 4, , 5]);
|
|
511
|
-
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/v2/accounts/").concat(address))];
|
|
512
|
-
case 3:
|
|
513
|
-
data = (_a.sent()).data;
|
|
514
|
-
balance = balance.plus(new bignumber_1.default(data.balance));
|
|
515
|
-
return [3 /*break*/, 5];
|
|
516
|
-
case 4:
|
|
517
|
-
error_1 = _a.sent();
|
|
518
|
-
// if node returns 404 (which means 'no account found'), go with 0 balance
|
|
519
|
-
if (error_1.response && error_1.response.status !== 404) {
|
|
520
|
-
throw new errors_1.NetworkError(coinlib_error_1.Domain.AETERNITY, error_1);
|
|
521
|
-
}
|
|
522
|
-
return [3 /*break*/, 5];
|
|
523
|
-
case 5:
|
|
524
|
-
_i++;
|
|
525
|
-
return [3 /*break*/, 1];
|
|
526
|
-
case 6: return [2 /*return*/, balance.toString(10)];
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
};
|
|
531
|
-
AeternityProtocol.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
532
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
533
|
-
var address;
|
|
534
|
-
return __generator(this, function (_a) {
|
|
535
|
-
switch (_a.label) {
|
|
536
|
-
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
537
|
-
case 1:
|
|
538
|
-
address = _a.sent();
|
|
539
|
-
return [2 /*return*/, this.getBalanceOfAddresses([address.address])];
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
AeternityProtocol.prototype.getBalanceOfPublicKeyForSubProtocols = function (publicKey, subProtocols) {
|
|
545
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
546
|
-
return __generator(this, function (_a) {
|
|
547
|
-
throw Promise.reject('get balance of sub protocols not supported');
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
};
|
|
551
|
-
AeternityProtocol.prototype.getAvailableBalanceOfAddresses = function (addresses) {
|
|
552
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
553
|
-
return __generator(this, function (_a) {
|
|
554
|
-
return [2 /*return*/, this.getBalanceOfAddresses(addresses)];
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
};
|
|
558
|
-
AeternityProtocol.prototype.estimateMaxTransactionValueFromPublicKey = function (publicKey, recipients, fee) {
|
|
559
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
560
|
-
var balance, balanceWrapper, maxFee, estimatedFeeDefaults, amountWithoutFees;
|
|
561
|
-
return __generator(this, function (_a) {
|
|
562
|
-
switch (_a.label) {
|
|
563
|
-
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
564
|
-
case 1:
|
|
565
|
-
balance = _a.sent();
|
|
566
|
-
balanceWrapper = new bignumber_1.default(balance);
|
|
567
|
-
if (!(fee !== undefined)) return [3 /*break*/, 2];
|
|
568
|
-
maxFee = new bignumber_1.default(fee);
|
|
569
|
-
return [3 /*break*/, 4];
|
|
570
|
-
case 2: return [4 /*yield*/, this.estimateFeeDefaultsFromPublicKey(publicKey, recipients, [balance])];
|
|
571
|
-
case 3:
|
|
572
|
-
estimatedFeeDefaults = _a.sent();
|
|
573
|
-
maxFee = new bignumber_1.default(estimatedFeeDefaults.medium).shiftedBy(this.decimals);
|
|
574
|
-
if (maxFee.gte(balanceWrapper)) {
|
|
575
|
-
maxFee = new bignumber_1.default(0);
|
|
576
|
-
}
|
|
577
|
-
_a.label = 4;
|
|
578
|
-
case 4:
|
|
579
|
-
amountWithoutFees = balanceWrapper.minus(maxFee);
|
|
580
|
-
if (amountWithoutFees.isNegative()) {
|
|
581
|
-
amountWithoutFees = new bignumber_1.default(0);
|
|
582
|
-
}
|
|
583
|
-
return [2 /*return*/, amountWithoutFees.toFixed()];
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
};
|
|
588
|
-
AeternityProtocol.prototype.estimateFeeDefaultsFromPublicKey = function (publicKey, recipients, values, data) {
|
|
589
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
590
|
-
return __generator(this, function (_a) {
|
|
591
|
-
switch (_a.label) {
|
|
592
|
-
case 0: return [4 /*yield*/, index_1.default.get(this.feesURL)];
|
|
593
|
-
case 1: return [2 /*return*/, (_a.sent()).data];
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
};
|
|
598
|
-
AeternityProtocol.prototype.prepareTransactionFromPublicKey = function (publicKey, recipients, values, fee, data) {
|
|
599
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
600
|
-
var nonce, address, accountResponse, error_2, balance, _a, sender, recipient, txObj, txArray, rlpEncodedTx, preparedTx;
|
|
601
|
-
return __generator(this, function (_b) {
|
|
602
|
-
switch (_b.label) {
|
|
603
|
-
case 0:
|
|
604
|
-
nonce = 1;
|
|
605
|
-
return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
606
|
-
case 1:
|
|
607
|
-
address = _b.sent();
|
|
608
|
-
_b.label = 2;
|
|
609
|
-
case 2:
|
|
610
|
-
_b.trys.push([2, 4, , 5]);
|
|
611
|
-
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/v2/accounts/").concat(address.address))];
|
|
612
|
-
case 3:
|
|
613
|
-
accountResponse = (_b.sent()).data;
|
|
614
|
-
nonce = accountResponse.nonce + 1;
|
|
615
|
-
return [3 /*break*/, 5];
|
|
616
|
-
case 4:
|
|
617
|
-
error_2 = _b.sent();
|
|
618
|
-
// if node returns 404 (which means 'no account found'), go with nonce 0
|
|
619
|
-
if (error_2.response && error_2.response.status !== 404) {
|
|
620
|
-
throw new errors_1.NetworkError(coinlib_error_1.Domain.AETERNITY, error_2);
|
|
621
|
-
}
|
|
622
|
-
return [3 /*break*/, 5];
|
|
623
|
-
case 5:
|
|
624
|
-
_a = bignumber_1.default.bind;
|
|
625
|
-
return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
626
|
-
case 6:
|
|
627
|
-
balance = new (_a.apply(bignumber_1.default, [void 0, _b.sent()]))();
|
|
628
|
-
if (balance.isLessThan(fee)) {
|
|
629
|
-
throw new errors_1.BalanceError(coinlib_error_1.Domain.AETERNITY, 'not enough balance');
|
|
630
|
-
}
|
|
631
|
-
sender = publicKey;
|
|
632
|
-
recipient = bs58check.decode(recipients[0].replace('ak_', ''));
|
|
633
|
-
txObj = {
|
|
634
|
-
tag: (0, hex_1.toHexBuffer)(12),
|
|
635
|
-
version: (0, hex_1.toHexBuffer)(1),
|
|
636
|
-
sender_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(sender, 'hex')]),
|
|
637
|
-
recipient_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), recipient]),
|
|
638
|
-
amount: (0, hex_1.toHexBuffer)(new bignumber_1.default(values[0])),
|
|
639
|
-
fee: (0, hex_1.toHexBuffer)(new bignumber_1.default(fee)),
|
|
640
|
-
ttl: (0, hex_1.toHexBuffer)(0),
|
|
641
|
-
nonce: (0, hex_1.toHexBuffer)(nonce),
|
|
642
|
-
payload: Buffer.from((data === null || data === void 0 ? void 0 : data.payload) || '')
|
|
643
|
-
};
|
|
644
|
-
txArray = Object.keys(txObj).map(function (a) { return txObj[a]; });
|
|
645
|
-
rlpEncodedTx = rlp.encode(txArray);
|
|
646
|
-
preparedTx = "tx_".concat(base64Check_1.default.encode(rlpEncodedTx));
|
|
647
|
-
return [2 /*return*/, {
|
|
648
|
-
transaction: preparedTx,
|
|
649
|
-
networkId: this.defaultNetworkId
|
|
650
|
-
}];
|
|
258
|
+
}
|
|
259
|
+
async getTransactionDetails(unsignedTx) {
|
|
260
|
+
const transaction = unsignedTx.transaction.transaction;
|
|
261
|
+
const rlpEncodedTx = this.decodeTx(transaction);
|
|
262
|
+
const rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
263
|
+
const fromAddress = await this.getAddressFromPublicKey(rlpDecodedTx[2].slice(1).toString('hex'));
|
|
264
|
+
const toAddress = await this.getAddressFromPublicKey(rlpDecodedTx[3].slice(1).toString('hex'));
|
|
265
|
+
const airgapTx = {
|
|
266
|
+
amount: new bignumber_1.default(parseInt(rlpDecodedTx[4].toString('hex'), 16)).toString(10),
|
|
267
|
+
fee: new bignumber_1.default(parseInt(rlpDecodedTx[5].toString('hex'), 16)).toString(10),
|
|
268
|
+
from: [fromAddress.address],
|
|
269
|
+
isInbound: false,
|
|
270
|
+
protocolIdentifier: this.identifier,
|
|
271
|
+
network: this.options.network,
|
|
272
|
+
to: [toAddress.address],
|
|
273
|
+
data: (rlpDecodedTx[8] || '').toString('utf8'),
|
|
274
|
+
transactionDetails: unsignedTx.transaction
|
|
275
|
+
};
|
|
276
|
+
return [airgapTx];
|
|
277
|
+
}
|
|
278
|
+
async getTransactionDetailsFromSigned(signedTx) {
|
|
279
|
+
const rlpEncodedTx = this.decodeTx(signedTx.transaction);
|
|
280
|
+
const rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
281
|
+
const unsignedAeternityTransaction = {
|
|
282
|
+
publicKey: '',
|
|
283
|
+
transaction: {
|
|
284
|
+
networkId: 'ae_mainnet',
|
|
285
|
+
transaction: `tx_${base64Check_1.default.encode(rlpDecodedTx[3])}`
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
return this.getTransactionDetails(unsignedAeternityTransaction);
|
|
289
|
+
}
|
|
290
|
+
async getBalanceOfAddresses(addresses) {
|
|
291
|
+
let balance = new bignumber_1.default(0);
|
|
292
|
+
for (const address of addresses) {
|
|
293
|
+
try {
|
|
294
|
+
const { data } = await index_1.default.get(`${this.options.network.rpcUrl}/v2/accounts/${address}`);
|
|
295
|
+
balance = balance.plus(new bignumber_1.default(data.balance));
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
// if node returns 404 (which means 'no account found'), go with 0 balance
|
|
299
|
+
if (error.response && error.response.status !== 404) {
|
|
300
|
+
throw new errors_1.NetworkError(coinlib_error_1.Domain.AETERNITY, error);
|
|
651
301
|
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return balance.toString(10);
|
|
305
|
+
}
|
|
306
|
+
async getBalanceOfPublicKey(publicKey) {
|
|
307
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
308
|
+
return this.getBalanceOfAddresses([address.address]);
|
|
309
|
+
}
|
|
310
|
+
async getBalanceOfPublicKeyForSubProtocols(publicKey, subProtocols) {
|
|
311
|
+
throw Promise.reject('get balance of sub protocols not supported');
|
|
312
|
+
}
|
|
313
|
+
async getAvailableBalanceOfAddresses(addresses) {
|
|
314
|
+
return this.getBalanceOfAddresses(addresses);
|
|
315
|
+
}
|
|
316
|
+
async estimateMaxTransactionValueFromPublicKey(publicKey, recipients, fee) {
|
|
317
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
318
|
+
const balanceWrapper = new bignumber_1.default(balance);
|
|
319
|
+
let maxFee;
|
|
320
|
+
if (fee !== undefined) {
|
|
321
|
+
maxFee = new bignumber_1.default(fee);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const estimatedFeeDefaults = await this.estimateFeeDefaultsFromPublicKey(publicKey, recipients, [balance]);
|
|
325
|
+
maxFee = new bignumber_1.default(estimatedFeeDefaults.medium).shiftedBy(this.decimals);
|
|
326
|
+
if (maxFee.gte(balanceWrapper)) {
|
|
327
|
+
maxFee = new bignumber_1.default(0);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
let amountWithoutFees = balanceWrapper.minus(maxFee);
|
|
331
|
+
if (amountWithoutFees.isNegative()) {
|
|
332
|
+
amountWithoutFees = new bignumber_1.default(0);
|
|
333
|
+
}
|
|
334
|
+
return amountWithoutFees.toFixed();
|
|
335
|
+
}
|
|
336
|
+
async estimateFeeDefaultsFromPublicKey(publicKey, recipients, values, data) {
|
|
337
|
+
return (await index_1.default.get(this.feesURL)).data;
|
|
338
|
+
}
|
|
339
|
+
async prepareTransactionFromPublicKey(publicKey, recipients, values, fee, data) {
|
|
340
|
+
let nonce = 1;
|
|
341
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
342
|
+
try {
|
|
343
|
+
const { data: accountResponse } = await index_1.default.get(`${this.options.network.rpcUrl}/v2/accounts/${address.address}`);
|
|
344
|
+
nonce = accountResponse.nonce + 1;
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
// if node returns 404 (which means 'no account found'), go with nonce 0
|
|
348
|
+
if (error.response && error.response.status !== 404) {
|
|
349
|
+
throw new errors_1.NetworkError(coinlib_error_1.Domain.AETERNITY, error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const balance = new bignumber_1.default(await this.getBalanceOfPublicKey(publicKey));
|
|
353
|
+
if (balance.isLessThan(fee)) {
|
|
354
|
+
throw new errors_1.BalanceError(coinlib_error_1.Domain.AETERNITY, 'not enough balance');
|
|
355
|
+
}
|
|
356
|
+
const sender = publicKey;
|
|
357
|
+
const recipient = bs58check.decode(recipients[0].replace('ak_', ''));
|
|
358
|
+
const txObj = {
|
|
359
|
+
tag: (0, hex_1.toHexBuffer)(12),
|
|
360
|
+
version: (0, hex_1.toHexBuffer)(1),
|
|
361
|
+
sender_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(sender, 'hex')]),
|
|
362
|
+
recipient_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), recipient]),
|
|
363
|
+
amount: (0, hex_1.toHexBuffer)(new bignumber_1.default(values[0])),
|
|
364
|
+
fee: (0, hex_1.toHexBuffer)(new bignumber_1.default(fee)),
|
|
365
|
+
ttl: (0, hex_1.toHexBuffer)(0),
|
|
366
|
+
nonce: (0, hex_1.toHexBuffer)(nonce),
|
|
367
|
+
payload: Buffer.from(data?.payload || '')
|
|
368
|
+
};
|
|
369
|
+
const txArray = Object.keys(txObj).map((a) => txObj[a]);
|
|
370
|
+
const rlpEncodedTx = rlp.encode(txArray);
|
|
371
|
+
const preparedTx = `tx_${base64Check_1.default.encode(rlpEncodedTx)}`;
|
|
372
|
+
return {
|
|
373
|
+
transaction: preparedTx,
|
|
374
|
+
networkId: this.defaultNetworkId
|
|
375
|
+
};
|
|
376
|
+
}
|
|
655
377
|
/**
|
|
656
378
|
* This is a function that we only use to fix incompatibilitis with old vault versions that are unable to understand b64 encoded Txs.
|
|
657
379
|
*
|
|
658
380
|
* @deprecated
|
|
659
381
|
* @param preparedTx
|
|
660
382
|
*/
|
|
661
|
-
|
|
383
|
+
convertTxToBase58(preparedTx) {
|
|
662
384
|
return {
|
|
663
385
|
transaction: bs58check.encode(base64Check_1.default.decode(preparedTx.transaction)),
|
|
664
386
|
networkId: preparedTx.networkId
|
|
665
387
|
};
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
return
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
};
|
|
694
|
-
AeternityProtocol.prototype.encryptAsymmetric = function (message, publicKey) {
|
|
695
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
696
|
-
return __generator(this, function (_a) {
|
|
697
|
-
return [2 /*return*/, this.cryptoClient.encryptAsymmetric(message, publicKey)];
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
};
|
|
701
|
-
AeternityProtocol.prototype.decryptAsymmetric = function (message, keypair) {
|
|
702
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
703
|
-
return __generator(this, function (_a) {
|
|
704
|
-
return [2 /*return*/, this.cryptoClient.decryptAsymmetric(message, keypair)];
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
|
-
};
|
|
708
|
-
AeternityProtocol.prototype.encryptAES = function (message, privateKey) {
|
|
709
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
710
|
-
return __generator(this, function (_a) {
|
|
711
|
-
return [2 /*return*/, this.cryptoClient.encryptAES(message, privateKey)];
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
};
|
|
715
|
-
AeternityProtocol.prototype.decryptAES = function (message, privateKey) {
|
|
716
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
717
|
-
return __generator(this, function (_a) {
|
|
718
|
-
return [2 /*return*/, this.cryptoClient.decryptAES(message, privateKey)];
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
};
|
|
722
|
-
AeternityProtocol.prototype.getTransactionStatuses = function (transactionHashes) {
|
|
723
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
724
|
-
return __generator(this, function (_a) {
|
|
725
|
-
return [2 /*return*/, Promise.reject('Transaction status not implemented')];
|
|
726
|
-
});
|
|
727
|
-
});
|
|
728
|
-
};
|
|
729
|
-
return AeternityProtocol;
|
|
730
|
-
}(NonExtendedProtocol_1.NonExtendedProtocol));
|
|
388
|
+
}
|
|
389
|
+
async broadcastTransaction(rawTransaction) {
|
|
390
|
+
const { data } = await index_1.default.post(`${this.options.network.rpcUrl}/v2/transactions`, { tx: rawTransaction }, { headers: { 'Content-Type': 'application/json' } });
|
|
391
|
+
return data.tx_hash;
|
|
392
|
+
}
|
|
393
|
+
async signMessage(message, keypair) {
|
|
394
|
+
return this.cryptoClient.signMessage(message, keypair);
|
|
395
|
+
}
|
|
396
|
+
async verifyMessage(message, signature, publicKey) {
|
|
397
|
+
return this.cryptoClient.verifyMessage(message, signature, publicKey);
|
|
398
|
+
}
|
|
399
|
+
async encryptAsymmetric(message, publicKey) {
|
|
400
|
+
return this.cryptoClient.encryptAsymmetric(message, publicKey);
|
|
401
|
+
}
|
|
402
|
+
async decryptAsymmetric(message, keypair) {
|
|
403
|
+
return this.cryptoClient.decryptAsymmetric(message, keypair);
|
|
404
|
+
}
|
|
405
|
+
async encryptAES(message, privateKey) {
|
|
406
|
+
return this.cryptoClient.encryptAES(message, privateKey);
|
|
407
|
+
}
|
|
408
|
+
async decryptAES(message, privateKey) {
|
|
409
|
+
return this.cryptoClient.decryptAES(message, privateKey);
|
|
410
|
+
}
|
|
411
|
+
async getTransactionStatuses(transactionHashes) {
|
|
412
|
+
return Promise.reject('Transaction status not implemented');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
731
415
|
exports.AeternityProtocol = AeternityProtocol;
|
|
732
416
|
//# sourceMappingURL=AeternityProtocol.js.map
|