@airgap/aeternity 0.13.45-beta.3 → 0.13.45-beta.4
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 +18 -27
- package/v0/protocol/AeternityAddress.js.map +1 -1
- package/v0/protocol/AeternityCryptoClient.js +84 -21
- package/v0/protocol/AeternityCryptoClient.js.map +1 -1
- package/v0/protocol/AeternityProtocol.js +657 -341
- package/v0/protocol/AeternityProtocol.js.map +1 -1
- package/v0/protocol/AeternityProtocolOptions.js +93 -22
- package/v0/protocol/AeternityProtocolOptions.js.map +1 -1
- package/v0/serializer/validators/transaction-validator.js +83 -30
- package/v0/serializer/validators/transaction-validator.js.map +1 -1
- package/v0/serializer/validators/validators.js +67 -19
- package/v0/serializer/validators/validators.js.map +1 -1
- package/v1/block-explorer/AeternityBlockExplorer.js +61 -12
- package/v1/block-explorer/AeternityBlockExplorer.js.map +1 -1
- package/v1/data/AeternityAddress.js +13 -12
- 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 +95 -37
- package/v1/module/AeternityModule.js.map +1 -1
- package/v1/module.js +3 -2
- package/v1/module.js.map +1 -1
- package/v1/protocol/AeternityCryptoClient.js +84 -21
- package/v1/protocol/AeternityCryptoClient.js.map +1 -1
- package/v1/protocol/AeternityProtocol.js +497 -282
- package/v1/protocol/AeternityProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +20 -8
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +148 -69
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +63 -15
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +67 -19
- 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 +17 -26
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/key.js +10 -9
- package/v1/utils/key.js.map +1 -1
- package/v1/utils/signature.js +7 -6
- package/v1/utils/signature.js.map +1 -1
- package/v1/utils/transaction.d.ts +1 -0
- package/v1/utils/transaction.js +17 -26
- package/v1/utils/transaction.js.map +1 -1
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
14
|
if (k2 === undefined) k2 = k;
|
|
4
15
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,48 +26,73 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
26
|
}) : function(o, v) {
|
|
16
27
|
o["default"] = v;
|
|
17
28
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
return function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (_) try {
|
|
52
|
+
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;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
35
72
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
73
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
74
|
};
|
|
38
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AETERNITY_MAINNET_PROTOCOL_NETWORK = exports.AeternityProtocolImpl = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const transaction_1 = require("../utils/transaction");
|
|
56
|
-
const AeternityCryptoClient_1 = require("./AeternityCryptoClient");
|
|
76
|
+
exports.createAeternityProtocolOptions = exports.AETERNITY_MAINNET_PROTOCOL_NETWORK = exports.createAeternityProtocol = exports.AeternityProtocolImpl = void 0;
|
|
77
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
78
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
79
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
80
|
+
var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
81
|
+
var rlp = __importStar(require("@airgap/coinlib-core/dependencies/src/rlp-2.2.3/index"));
|
|
82
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
83
|
+
var base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
|
|
84
|
+
var hex_1 = require("@airgap/coinlib-core/utils/hex");
|
|
85
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
86
|
+
var ed25519_1 = require("@stablelib/ed25519");
|
|
87
|
+
var AeternityAddress_1 = require("../data/AeternityAddress");
|
|
88
|
+
var key_1 = require("../utils/key");
|
|
89
|
+
var signature_1 = require("../utils/signature");
|
|
90
|
+
var transaction_1 = require("../utils/transaction");
|
|
91
|
+
var AeternityCryptoClient_1 = require("./AeternityCryptoClient");
|
|
57
92
|
// Implementation
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
var AeternityProtocolImpl = /** @class */ (function () {
|
|
94
|
+
function AeternityProtocolImpl(options) {
|
|
95
|
+
if (options === void 0) { options = {}; }
|
|
60
96
|
// Common
|
|
61
97
|
this.units = {
|
|
62
98
|
AE: {
|
|
@@ -78,7 +114,7 @@ class AeternityProtocolImpl {
|
|
|
78
114
|
defaults: this.feeDefaults
|
|
79
115
|
},
|
|
80
116
|
account: {
|
|
81
|
-
standardDerivationPath:
|
|
117
|
+
standardDerivationPath: "m/44h/457h/0h/0h/0h",
|
|
82
118
|
address: {
|
|
83
119
|
isCaseSensitive: true,
|
|
84
120
|
placeholder: 'ak_abc...',
|
|
@@ -98,262 +134,439 @@ class AeternityProtocolImpl {
|
|
|
98
134
|
this.options = createAeternityProtocolOptions(options.network);
|
|
99
135
|
this.cryptoClient = new AeternityCryptoClient_1.AeternityCryptoClient();
|
|
100
136
|
}
|
|
101
|
-
|
|
102
|
-
return this
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return this
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
137
|
+
AeternityProtocolImpl.prototype.getMetadata = function () {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
return [2 /*return*/, this.metadata];
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
AeternityProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
return [2 /*return*/, AeternityAddress_1.AeternityAddress.from(publicKey).asString()];
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
AeternityProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, _publicKey) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var rlpEncodedTx, rlpDecodedTx;
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
switch (transaction.type) {
|
|
156
|
+
case 'signed':
|
|
157
|
+
rlpEncodedTx = (0, transaction_1.decodeTx)(transaction.transaction);
|
|
158
|
+
rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
159
|
+
return [2 /*return*/, this.getDetailsFromEncodedTransaction("tx_".concat(base64Check_1.default.encode(rlpDecodedTx[3])))];
|
|
160
|
+
case 'unsigned':
|
|
161
|
+
return [2 /*return*/, this.getDetailsFromEncodedTransaction(transaction.transaction)];
|
|
162
|
+
default:
|
|
163
|
+
(0, coinlib_core_1.assertNever)(transaction);
|
|
164
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.AETERNITY, 'Unsupported transaction type.');
|
|
165
|
+
}
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
AeternityProtocolImpl.prototype.getDetailsFromEncodedTransaction = function (tx) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var rlpEncodedTx, rlpDecodedTx, from, to, airgapTx;
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
rlpEncodedTx = (0, transaction_1.decodeTx)(tx);
|
|
177
|
+
rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
178
|
+
return [4 /*yield*/, this.getAddressFromPublicKey((0, module_kit_1.newPublicKey)(rlpDecodedTx[2].slice(1).toString('hex'), 'hex'))];
|
|
179
|
+
case 1:
|
|
180
|
+
from = _a.sent();
|
|
181
|
+
return [4 /*yield*/, this.getAddressFromPublicKey((0, module_kit_1.newPublicKey)(rlpDecodedTx[3].slice(1).toString('hex'), 'hex'))];
|
|
182
|
+
case 2:
|
|
183
|
+
to = _a.sent();
|
|
184
|
+
airgapTx = {
|
|
185
|
+
from: [from],
|
|
186
|
+
to: [to],
|
|
187
|
+
isInbound: false,
|
|
188
|
+
amount: (0, module_kit_1.newAmount)(parseInt(rlpDecodedTx[4].toString('hex'), 16), 'blockchain'),
|
|
189
|
+
fee: (0, module_kit_1.newAmount)(parseInt(rlpDecodedTx[5].toString('hex'), 16), 'blockchain'),
|
|
190
|
+
network: this.options.network,
|
|
191
|
+
arbitraryData: (rlpDecodedTx[8] || '').toString('utf8')
|
|
192
|
+
};
|
|
193
|
+
return [2 /*return*/, [airgapTx]];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
AeternityProtocolImpl.prototype.verifyMessageWithPublicKey = function (message, signature, publicKey) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var hexSignature, hexPublicKey;
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
hexSignature = (0, signature_1.convertSignature)(signature, 'hex');
|
|
203
|
+
hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex');
|
|
204
|
+
return [2 /*return*/, this.cryptoClient.verifyMessage(message, hexSignature.value, hexPublicKey.value)];
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
AeternityProtocolImpl.prototype.encryptAsymmetricWithPublicKey = function (payload, publicKey) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
+
var hexPublicKey;
|
|
211
|
+
return __generator(this, function (_a) {
|
|
212
|
+
hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex');
|
|
213
|
+
return [2 /*return*/, this.cryptoClient.encryptAsymmetric(payload, hexPublicKey.value)];
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
AeternityProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
return [2 /*return*/, this.cryptoConfiguration];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
AeternityProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
return [2 /*return*/, {
|
|
228
|
+
secretKey: (0, module_kit_1.newSecretKey)(Buffer.concat([Buffer.from(derivative.secretKey, 'hex'), Buffer.from(derivative.publicKey, 'hex')]).toString('hex'), 'hex'),
|
|
229
|
+
publicKey: (0, module_kit_1.newPublicKey)(derivative.publicKey, 'hex')
|
|
230
|
+
}];
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
AeternityProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
+
var rawTx, signature, txObj, txArray, rlpEncodedTx, signedEncodedTx;
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
if (secretKey.format !== 'hex') {
|
|
239
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Secret key is of an unexpected format.');
|
|
240
|
+
}
|
|
241
|
+
rawTx = (0, transaction_1.decodeTx)(transaction.transaction);
|
|
242
|
+
signature = (0, ed25519_1.sign)(Buffer.from(secretKey.value, 'hex'), Buffer.concat([Buffer.from(transaction.networkId), rawTx]));
|
|
243
|
+
txObj = {
|
|
244
|
+
tag: (0, hex_1.toHexBuffer)(11),
|
|
245
|
+
version: (0, hex_1.toHexBuffer)(1),
|
|
246
|
+
signatures: [Buffer.from(signature)],
|
|
247
|
+
transaction: rawTx
|
|
248
|
+
};
|
|
249
|
+
txArray = Object.keys(txObj).map(function (a) { return txObj[a]; });
|
|
250
|
+
rlpEncodedTx = rlp.encode(txArray);
|
|
251
|
+
signedEncodedTx = "tx_".concat(base64Check_1.default.encode(rlpEncodedTx));
|
|
252
|
+
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({ transaction: signedEncodedTx })];
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
AeternityProtocolImpl.prototype.signMessageWithKeyPair = function (message, keyPair) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var _a;
|
|
259
|
+
return __generator(this, function (_b) {
|
|
260
|
+
switch (_b.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
if (keyPair.secretKey.format !== 'hex') {
|
|
263
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Secret key is of an unexpected format.');
|
|
264
|
+
}
|
|
265
|
+
_a = module_kit_1.newSignature;
|
|
266
|
+
return [4 /*yield*/, this.cryptoClient.signMessage(message, { privateKey: keyPair.secretKey.value })];
|
|
267
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), 'hex'])];
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
AeternityProtocolImpl.prototype.decryptAsymmetricWithKeyPair = function (payload, keyPair) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
+
var hexPublicKey;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
if (keyPair.secretKey.format !== 'hex') {
|
|
277
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Secret key is of an unexpected format.');
|
|
278
|
+
}
|
|
279
|
+
hexPublicKey = (0, key_1.convertPublicKey)(keyPair.publicKey, 'hex');
|
|
280
|
+
return [2 /*return*/, this.cryptoClient.decryptAsymmetric(payload, { publicKey: hexPublicKey.value, privateKey: keyPair.secretKey.value })];
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
AeternityProtocolImpl.prototype.encryptAESWithSecretKey = function (payload, secretKey) {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
if (secretKey.format !== 'hex') {
|
|
288
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Secret key is of an unexpected format.');
|
|
289
|
+
}
|
|
290
|
+
return [2 /*return*/, this.cryptoClient.encryptAES(payload, secretKey.value)];
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
AeternityProtocolImpl.prototype.decryptAESWithSecretKey = function (payload, secretKey) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
if (secretKey.format !== 'hex') {
|
|
298
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Secret key is of an unexpected format.');
|
|
299
|
+
}
|
|
300
|
+
return [2 /*return*/, this.cryptoClient.decryptAES(payload, secretKey.value)];
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
196
304
|
// Online
|
|
197
|
-
|
|
198
|
-
return this
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return this.getTransactionsForAddress(address, limit, cursor);
|
|
203
|
-
}
|
|
204
|
-
async getTransactionsForAddress(address, limit, cursor) {
|
|
205
|
-
const endpoint = cursor === undefined ? `/txs/backward?account=${address}&limit=${limit}` : cursor.next;
|
|
206
|
-
const url = endpoint !== undefined ? `${this.options.network.rpcUrl}/mdw/${endpoint.replace(/^\/+/, '')}` : undefined;
|
|
207
|
-
const response = url !== undefined ? await index_1.default.get(url) : undefined;
|
|
208
|
-
const nodeTransactions = response?.data?.data || [];
|
|
209
|
-
const next = (0, module_kit_1.normalizeToUndefined)(response?.data?.next);
|
|
210
|
-
const transactions = nodeTransactions.map((obj) => {
|
|
211
|
-
const parsedTimestamp = parseInt(obj.micro_time, 10);
|
|
212
|
-
return {
|
|
213
|
-
from: [obj.tx.sender_id],
|
|
214
|
-
to: [obj.tx.recipient_id],
|
|
215
|
-
isInbound: address === obj.tx.recipient_id,
|
|
216
|
-
amount: (0, module_kit_1.newAmount)(obj.tx.amount, 'blockchain'),
|
|
217
|
-
fee: (0, module_kit_1.newAmount)(obj.tx.fee, 'blockchain'),
|
|
218
|
-
network: this.options.network,
|
|
219
|
-
timestamp: !isNaN(parsedTimestamp) ? Math.round(parsedTimestamp / 1000) : undefined,
|
|
220
|
-
status: {
|
|
221
|
-
type: 'unknown',
|
|
222
|
-
hash: obj.hash,
|
|
223
|
-
block: obj.block_height
|
|
224
|
-
},
|
|
225
|
-
details: obj.tx.payload ? [(0, module_kit_1.newPlainUIText)('Payload'), obj.tx.payload] : undefined
|
|
226
|
-
};
|
|
305
|
+
AeternityProtocolImpl.prototype.getNetwork = function () {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
+
return __generator(this, function (_a) {
|
|
308
|
+
return [2 /*return*/, this.options.network];
|
|
309
|
+
});
|
|
227
310
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
async getBalanceOfAddress(address) {
|
|
241
|
-
let balance;
|
|
242
|
-
try {
|
|
243
|
-
const { data } = await index_1.default.get(`${this.options.network.rpcUrl}/v2/accounts/${address}`);
|
|
244
|
-
balance = new bignumber_1.default(data.balance);
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
// if node returns 404 (which means 'no account found'), go with 0 balance
|
|
248
|
-
if (error.response && error.response.status !== 404) {
|
|
249
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.AETERNITY, error);
|
|
250
|
-
}
|
|
251
|
-
balance = new bignumber_1.default(0);
|
|
252
|
-
}
|
|
253
|
-
return { total: (0, module_kit_1.newAmount)(balance.toString(10), 'blockchain') };
|
|
254
|
-
}
|
|
255
|
-
async getTransactionMaxAmountWithPublicKey(publicKey, to, configuration) {
|
|
256
|
-
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
257
|
-
const balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.units).value);
|
|
258
|
-
let fee;
|
|
259
|
-
if (configuration?.fee !== undefined) {
|
|
260
|
-
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value);
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
const transactionDetails = to.map((address) => ({
|
|
264
|
-
to: address,
|
|
265
|
-
amount: (0, module_kit_1.newAmount)(balanceBn.div(to.length).toString(), 'blockchain')
|
|
266
|
-
}));
|
|
267
|
-
const feeEstimation = await this.getTransactionFeeWithPublicKey(publicKey, transactionDetails);
|
|
268
|
-
fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation.medium).blockchain(this.units).value);
|
|
269
|
-
if (fee.gte(balanceBn)) {
|
|
270
|
-
fee = new bignumber_1.default(0);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
let amountWithoutFees = balanceBn.minus(fee);
|
|
274
|
-
if (amountWithoutFees.isNegative()) {
|
|
275
|
-
amountWithoutFees = new bignumber_1.default(0);
|
|
276
|
-
}
|
|
277
|
-
return (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain');
|
|
278
|
-
}
|
|
279
|
-
async getTransactionFeeWithPublicKey(_publicKey, _details, _configuration) {
|
|
280
|
-
const feeDetaults = (await index_1.default.get(this.options.network.feesUrl)).data;
|
|
281
|
-
return {
|
|
282
|
-
low: (0, module_kit_1.newAmount)(feeDetaults.low, 'AE').blockchain(this.units),
|
|
283
|
-
medium: (0, module_kit_1.newAmount)(feeDetaults.medium, 'AE').blockchain(this.units),
|
|
284
|
-
high: (0, module_kit_1.newAmount)(feeDetaults.high, 'AE').blockchain(this.units)
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
async prepareTransactionWithPublicKey(publicKey, details, configuration) {
|
|
288
|
-
// should we support multiple transactions here?
|
|
289
|
-
let nonce = 1;
|
|
290
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
291
|
-
try {
|
|
292
|
-
const { data: accountResponse } = await index_1.default.get(`${this.options.network.rpcUrl}/v2/accounts/${address}`);
|
|
293
|
-
nonce = accountResponse.nonce + 1;
|
|
294
|
-
}
|
|
295
|
-
catch (error) {
|
|
296
|
-
// if node returns 404 (which means 'no account found'), go with nonce 0
|
|
297
|
-
if (error.response && error.response.status !== 404) {
|
|
298
|
-
throw new errors_1.NetworkError(coinlib_core_1.Domain.AETERNITY, error);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const balance = (0, module_kit_1.newAmount)((await this.getBalanceOfPublicKey(publicKey)).total).blockchain(this.units);
|
|
302
|
-
const balanceBn = new bignumber_1.default(balance.value);
|
|
303
|
-
const feeBn = configuration?.fee !== undefined
|
|
304
|
-
? new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value)
|
|
305
|
-
: new bignumber_1.default((0, module_kit_1.newAmount)(this.feeDefaults.medium).blockchain(this.units).value);
|
|
306
|
-
if (balanceBn.isLessThan(feeBn)) {
|
|
307
|
-
throw new errors_1.BalanceError(coinlib_core_1.Domain.AETERNITY, 'not enough balance');
|
|
308
|
-
}
|
|
309
|
-
const sender = (0, key_1.convertPublicKey)(publicKey, 'hex').value;
|
|
310
|
-
const recipient = (0, key_1.convertPublicKey)(AeternityAddress_1.AeternityAddress.from(details[0].to).toPublicKey(), 'hex').value;
|
|
311
|
-
const value = new bignumber_1.default((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
|
|
312
|
-
const payload = details[0].arbitraryData || '';
|
|
313
|
-
const txObj = {
|
|
314
|
-
tag: (0, hex_1.toHexBuffer)(12),
|
|
315
|
-
version: (0, hex_1.toHexBuffer)(1),
|
|
316
|
-
sender_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(sender, 'hex')]),
|
|
317
|
-
recipient_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(recipient, 'hex')]),
|
|
318
|
-
amount: (0, hex_1.toHexBuffer)(value),
|
|
319
|
-
fee: (0, hex_1.toHexBuffer)(feeBn),
|
|
320
|
-
ttl: (0, hex_1.toHexBuffer)(0),
|
|
321
|
-
nonce: (0, hex_1.toHexBuffer)(nonce),
|
|
322
|
-
payload: Buffer.from(payload)
|
|
323
|
-
};
|
|
324
|
-
const txArray = Object.keys(txObj).map((a) => txObj[a]);
|
|
325
|
-
const rlpEncodedTx = rlp.encode(txArray);
|
|
326
|
-
const preparedTx = (0, transaction_1.encodeTx)(rlpEncodedTx);
|
|
327
|
-
return (0, module_kit_1.newUnsignedTransaction)({
|
|
328
|
-
transaction: preparedTx,
|
|
329
|
-
networkId: this.networkId()
|
|
311
|
+
};
|
|
312
|
+
AeternityProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
|
|
313
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
314
|
+
var address;
|
|
315
|
+
return __generator(this, function (_a) {
|
|
316
|
+
switch (_a.label) {
|
|
317
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
318
|
+
case 1:
|
|
319
|
+
address = _a.sent();
|
|
320
|
+
return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
330
323
|
});
|
|
331
|
-
}
|
|
332
|
-
|
|
324
|
+
};
|
|
325
|
+
AeternityProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
|
|
326
|
+
var _a, _b;
|
|
327
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
328
|
+
var endpoint, url, response, _c, nodeTransactions, next, transactions;
|
|
329
|
+
var _this = this;
|
|
330
|
+
return __generator(this, function (_d) {
|
|
331
|
+
switch (_d.label) {
|
|
332
|
+
case 0:
|
|
333
|
+
endpoint = cursor === undefined ? "/txs/backward?account=".concat(address, "&limit=").concat(limit) : cursor.next;
|
|
334
|
+
url = endpoint !== undefined ? "".concat(this.options.network.rpcUrl, "/mdw/").concat(endpoint.replace(/^\/+/, '')) : undefined;
|
|
335
|
+
if (!(url !== undefined)) return [3 /*break*/, 2];
|
|
336
|
+
return [4 /*yield*/, index_1.default.get(url)];
|
|
337
|
+
case 1:
|
|
338
|
+
_c = _d.sent();
|
|
339
|
+
return [3 /*break*/, 3];
|
|
340
|
+
case 2:
|
|
341
|
+
_c = undefined;
|
|
342
|
+
_d.label = 3;
|
|
343
|
+
case 3:
|
|
344
|
+
response = _c;
|
|
345
|
+
nodeTransactions = ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.data) || [];
|
|
346
|
+
next = (0, module_kit_1.normalizeToUndefined)((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.next);
|
|
347
|
+
transactions = nodeTransactions.map(function (obj) {
|
|
348
|
+
var parsedTimestamp = parseInt(obj.micro_time, 10);
|
|
349
|
+
return {
|
|
350
|
+
from: [obj.tx.sender_id],
|
|
351
|
+
to: [obj.tx.recipient_id],
|
|
352
|
+
isInbound: address === obj.tx.recipient_id,
|
|
353
|
+
amount: (0, module_kit_1.newAmount)(obj.tx.amount, 'blockchain'),
|
|
354
|
+
fee: (0, module_kit_1.newAmount)(obj.tx.fee, 'blockchain'),
|
|
355
|
+
network: _this.options.network,
|
|
356
|
+
timestamp: !isNaN(parsedTimestamp) ? Math.round(parsedTimestamp / 1000) : undefined,
|
|
357
|
+
status: {
|
|
358
|
+
type: 'unknown',
|
|
359
|
+
hash: obj.hash,
|
|
360
|
+
block: obj.block_height
|
|
361
|
+
},
|
|
362
|
+
details: obj.tx.payload ? [(0, module_kit_1.newPlainUIText)('Payload'), obj.tx.payload] : undefined
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
return [2 /*return*/, {
|
|
366
|
+
transactions: transactions,
|
|
367
|
+
cursor: {
|
|
368
|
+
hasNext: next !== undefined,
|
|
369
|
+
next: next
|
|
370
|
+
}
|
|
371
|
+
}];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
AeternityProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
377
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
378
|
+
var address;
|
|
379
|
+
return __generator(this, function (_a) {
|
|
380
|
+
switch (_a.label) {
|
|
381
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
382
|
+
case 1:
|
|
383
|
+
address = _a.sent();
|
|
384
|
+
return [2 /*return*/, this.getBalanceOfAddress(address)];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
AeternityProtocolImpl.prototype.getBalanceOfAddress = function (address) {
|
|
390
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
391
|
+
var balance, data, error_1;
|
|
392
|
+
return __generator(this, function (_a) {
|
|
393
|
+
switch (_a.label) {
|
|
394
|
+
case 0:
|
|
395
|
+
_a.trys.push([0, 2, , 3]);
|
|
396
|
+
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/v2/accounts/").concat(address))];
|
|
397
|
+
case 1:
|
|
398
|
+
data = (_a.sent()).data;
|
|
399
|
+
balance = new bignumber_1.default(data.balance);
|
|
400
|
+
return [3 /*break*/, 3];
|
|
401
|
+
case 2:
|
|
402
|
+
error_1 = _a.sent();
|
|
403
|
+
// if node returns 404 (which means 'no account found'), go with 0 balance
|
|
404
|
+
if (error_1.response && error_1.response.status !== 404) {
|
|
405
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.AETERNITY, error_1);
|
|
406
|
+
}
|
|
407
|
+
balance = new bignumber_1.default(0);
|
|
408
|
+
return [3 /*break*/, 3];
|
|
409
|
+
case 3: return [2 /*return*/, { total: (0, module_kit_1.newAmount)(balance.toString(10), 'blockchain') }];
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
AeternityProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
415
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
+
var balance, balanceBn, fee, transactionDetails, feeEstimation, amountWithoutFees;
|
|
417
|
+
return __generator(this, function (_a) {
|
|
418
|
+
switch (_a.label) {
|
|
419
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
420
|
+
case 1:
|
|
421
|
+
balance = _a.sent();
|
|
422
|
+
balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.units).value);
|
|
423
|
+
if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 2];
|
|
424
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value);
|
|
425
|
+
return [3 /*break*/, 4];
|
|
426
|
+
case 2:
|
|
427
|
+
transactionDetails = to.map(function (address) { return ({
|
|
428
|
+
to: address,
|
|
429
|
+
amount: (0, module_kit_1.newAmount)(balanceBn.div(to.length).toString(), 'blockchain')
|
|
430
|
+
}); });
|
|
431
|
+
return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, transactionDetails)];
|
|
432
|
+
case 3:
|
|
433
|
+
feeEstimation = _a.sent();
|
|
434
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation.medium).blockchain(this.units).value);
|
|
435
|
+
if (fee.gte(balanceBn)) {
|
|
436
|
+
fee = new bignumber_1.default(0);
|
|
437
|
+
}
|
|
438
|
+
_a.label = 4;
|
|
439
|
+
case 4:
|
|
440
|
+
amountWithoutFees = balanceBn.minus(fee);
|
|
441
|
+
if (amountWithoutFees.isNegative()) {
|
|
442
|
+
amountWithoutFees = new bignumber_1.default(0);
|
|
443
|
+
}
|
|
444
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain')];
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
AeternityProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (_publicKey, _details, _configuration) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
451
|
+
var feeDetaults;
|
|
452
|
+
return __generator(this, function (_a) {
|
|
453
|
+
switch (_a.label) {
|
|
454
|
+
case 0: return [4 /*yield*/, index_1.default.get(this.options.network.feesUrl)];
|
|
455
|
+
case 1:
|
|
456
|
+
feeDetaults = (_a.sent()).data;
|
|
457
|
+
return [2 /*return*/, {
|
|
458
|
+
low: (0, module_kit_1.newAmount)(feeDetaults.low, 'AE').blockchain(this.units),
|
|
459
|
+
medium: (0, module_kit_1.newAmount)(feeDetaults.medium, 'AE').blockchain(this.units),
|
|
460
|
+
high: (0, module_kit_1.newAmount)(feeDetaults.high, 'AE').blockchain(this.units)
|
|
461
|
+
}];
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
};
|
|
466
|
+
AeternityProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
467
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
468
|
+
var nonce, address, accountResponse, error_2, balance, _a, balanceBn, feeBn, sender, recipient, value, payload, txObj, txArray, rlpEncodedTx, preparedTx;
|
|
469
|
+
return __generator(this, function (_b) {
|
|
470
|
+
switch (_b.label) {
|
|
471
|
+
case 0:
|
|
472
|
+
nonce = 1;
|
|
473
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
474
|
+
case 1:
|
|
475
|
+
address = _b.sent();
|
|
476
|
+
_b.label = 2;
|
|
477
|
+
case 2:
|
|
478
|
+
_b.trys.push([2, 4, , 5]);
|
|
479
|
+
return [4 /*yield*/, index_1.default.get("".concat(this.options.network.rpcUrl, "/v2/accounts/").concat(address))];
|
|
480
|
+
case 3:
|
|
481
|
+
accountResponse = (_b.sent()).data;
|
|
482
|
+
nonce = accountResponse.nonce + 1;
|
|
483
|
+
return [3 /*break*/, 5];
|
|
484
|
+
case 4:
|
|
485
|
+
error_2 = _b.sent();
|
|
486
|
+
// if node returns 404 (which means 'no account found'), go with nonce 0
|
|
487
|
+
if (error_2.response && error_2.response.status !== 404) {
|
|
488
|
+
throw new errors_1.NetworkError(coinlib_core_1.Domain.AETERNITY, error_2);
|
|
489
|
+
}
|
|
490
|
+
return [3 /*break*/, 5];
|
|
491
|
+
case 5:
|
|
492
|
+
_a = module_kit_1.newAmount;
|
|
493
|
+
return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
494
|
+
case 6:
|
|
495
|
+
balance = _a.apply(void 0, [(_b.sent()).total]).blockchain(this.units);
|
|
496
|
+
balanceBn = new bignumber_1.default(balance.value);
|
|
497
|
+
feeBn = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined
|
|
498
|
+
? new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value)
|
|
499
|
+
: new bignumber_1.default((0, module_kit_1.newAmount)(this.feeDefaults.medium).blockchain(this.units).value);
|
|
500
|
+
if (balanceBn.isLessThan(feeBn)) {
|
|
501
|
+
throw new errors_1.BalanceError(coinlib_core_1.Domain.AETERNITY, 'not enough balance');
|
|
502
|
+
}
|
|
503
|
+
sender = (0, key_1.convertPublicKey)(publicKey, 'hex').value;
|
|
504
|
+
recipient = (0, key_1.convertPublicKey)(AeternityAddress_1.AeternityAddress.from(details[0].to).toPublicKey(), 'hex').value;
|
|
505
|
+
value = new bignumber_1.default((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
|
|
506
|
+
payload = details[0].arbitraryData || '';
|
|
507
|
+
txObj = {
|
|
508
|
+
tag: (0, hex_1.toHexBuffer)(12),
|
|
509
|
+
version: (0, hex_1.toHexBuffer)(1),
|
|
510
|
+
sender_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(sender, 'hex')]),
|
|
511
|
+
recipient_id: Buffer.concat([(0, hex_1.toHexBuffer)(1), Buffer.from(recipient, 'hex')]),
|
|
512
|
+
amount: (0, hex_1.toHexBuffer)(value),
|
|
513
|
+
fee: (0, hex_1.toHexBuffer)(feeBn),
|
|
514
|
+
ttl: (0, hex_1.toHexBuffer)(0),
|
|
515
|
+
nonce: (0, hex_1.toHexBuffer)(nonce),
|
|
516
|
+
payload: Buffer.from(payload)
|
|
517
|
+
};
|
|
518
|
+
txArray = Object.keys(txObj).map(function (a) { return txObj[a]; });
|
|
519
|
+
rlpEncodedTx = rlp.encode(txArray);
|
|
520
|
+
preparedTx = (0, transaction_1.encodeTx)(rlpEncodedTx);
|
|
521
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
522
|
+
transaction: preparedTx,
|
|
523
|
+
networkId: this.networkId()
|
|
524
|
+
})];
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
AeternityProtocolImpl.prototype.networkId = function () {
|
|
333
530
|
switch (this.options.network.type) {
|
|
334
531
|
case 'mainnet':
|
|
335
532
|
return 'ae_mainnet';
|
|
336
533
|
default:
|
|
337
534
|
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.AETERNITY, 'Network type not supported.');
|
|
338
535
|
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
536
|
+
};
|
|
537
|
+
AeternityProtocolImpl.prototype.broadcastTransaction = function (transaction) {
|
|
538
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
539
|
+
var data;
|
|
540
|
+
return __generator(this, function (_a) {
|
|
541
|
+
switch (_a.label) {
|
|
542
|
+
case 0: return [4 /*yield*/, index_1.default.post("".concat(this.options.network.rpcUrl, "/v2/transactions"), { tx: transaction.transaction }, { headers: { 'Content-Type': 'application/json' } })];
|
|
543
|
+
case 1:
|
|
544
|
+
data = (_a.sent()).data;
|
|
545
|
+
return [2 /*return*/, data.tx_hash];
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
};
|
|
344
550
|
// Custom
|
|
345
|
-
|
|
346
|
-
return (0,
|
|
347
|
-
|
|
348
|
-
|
|
551
|
+
AeternityProtocolImpl.prototype.convertTransactionToBase58 = function (preparedTx) {
|
|
552
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
553
|
+
return __generator(this, function (_a) {
|
|
554
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
555
|
+
transaction: bs58check.encode(base64Check_1.default.decode(preparedTx.transaction)),
|
|
556
|
+
networkId: preparedTx.networkId
|
|
557
|
+
})];
|
|
558
|
+
});
|
|
349
559
|
});
|
|
350
|
-
}
|
|
351
|
-
|
|
560
|
+
};
|
|
561
|
+
return AeternityProtocolImpl;
|
|
562
|
+
}());
|
|
352
563
|
exports.AeternityProtocolImpl = AeternityProtocolImpl;
|
|
353
564
|
// Factory
|
|
354
|
-
function createAeternityProtocol(options
|
|
565
|
+
function createAeternityProtocol(options) {
|
|
566
|
+
if (options === void 0) { options = {}; }
|
|
355
567
|
return new AeternityProtocolImpl(options);
|
|
356
568
|
}
|
|
569
|
+
exports.createAeternityProtocol = createAeternityProtocol;
|
|
357
570
|
exports.AETERNITY_MAINNET_PROTOCOL_NETWORK = {
|
|
358
571
|
name: 'Mainnet',
|
|
359
572
|
type: 'mainnet',
|
|
@@ -361,10 +574,12 @@ exports.AETERNITY_MAINNET_PROTOCOL_NETWORK = {
|
|
|
361
574
|
blockExplorerUrl: 'https://explorer.aeternity.io',
|
|
362
575
|
feesUrl: 'https://api-airgap.gke.papers.tech/fees'
|
|
363
576
|
};
|
|
364
|
-
|
|
365
|
-
function createAeternityProtocolOptions(network
|
|
577
|
+
var DEFAULT_AETERNITY_PROTOCOL_NETWORK = exports.AETERNITY_MAINNET_PROTOCOL_NETWORK;
|
|
578
|
+
function createAeternityProtocolOptions(network) {
|
|
579
|
+
if (network === void 0) { network = {}; }
|
|
366
580
|
return {
|
|
367
|
-
network: {
|
|
581
|
+
network: __assign(__assign({}, DEFAULT_AETERNITY_PROTOCOL_NETWORK), network)
|
|
368
582
|
};
|
|
369
583
|
}
|
|
584
|
+
exports.createAeternityProtocolOptions = createAeternityProtocolOptions;
|
|
370
585
|
//# sourceMappingURL=AeternityProtocol.js.map
|