@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,19 @@
|
|
|
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
|
+
})();
|
|
2
17
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
18
|
if (k2 === undefined) k2 = k;
|
|
4
19
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,231 +30,405 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
30
|
}) : function(o, v) {
|
|
16
31
|
o["default"] = v;
|
|
17
32
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
return function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
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
|
+
};
|
|
35
76
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
77
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
78
|
};
|
|
38
79
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
80
|
exports.AeternityProtocol = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
82
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
83
|
+
var index_2 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0/index");
|
|
84
|
+
var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
|
|
85
|
+
var index_3 = require("@airgap/coinlib-core/dependencies/src/hd-wallet-js-b216450e56954a6e82ace0aade9474673de5d9d5/src/index");
|
|
86
|
+
var rlp = __importStar(require("@airgap/coinlib-core/dependencies/src/rlp-2.2.3/index"));
|
|
87
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
88
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
89
|
+
var NonExtendedProtocol_1 = require("@airgap/coinlib-core/protocols/NonExtendedProtocol");
|
|
90
|
+
var base64Check_1 = __importDefault(require("@airgap/coinlib-core/utils/base64Check"));
|
|
91
|
+
var hex_1 = require("@airgap/coinlib-core/utils/hex");
|
|
92
|
+
var ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
|
|
93
|
+
var ed25519_1 = require("@stablelib/ed25519");
|
|
94
|
+
var AeternityAddress_1 = require("./AeternityAddress");
|
|
95
|
+
var AeternityCryptoClient_1 = require("./AeternityCryptoClient");
|
|
96
|
+
var AeternityProtocolOptions_1 = require("./AeternityProtocolOptions");
|
|
97
|
+
var AeternityProtocol = /** @class */ (function (_super) {
|
|
98
|
+
__extends(AeternityProtocol, _super);
|
|
99
|
+
function AeternityProtocol(options) {
|
|
100
|
+
if (options === void 0) { options = new AeternityProtocolOptions_1.AeternityProtocolOptions(); }
|
|
101
|
+
var _this = _super.call(this) || this;
|
|
102
|
+
_this.options = options;
|
|
103
|
+
_this.symbol = 'AE';
|
|
104
|
+
_this.name = 'æternity';
|
|
105
|
+
_this.marketSymbol = 'ae';
|
|
106
|
+
_this.feeSymbol = 'ae';
|
|
107
|
+
_this.decimals = 18;
|
|
108
|
+
_this.feeDecimals = 18;
|
|
109
|
+
_this.identifier = ProtocolSymbols_1.MainProtocolSymbols.AE;
|
|
110
|
+
_this.feeDefaults = {
|
|
68
111
|
low: '0.00021',
|
|
69
112
|
medium: '0.000315',
|
|
70
113
|
high: '0.00084'
|
|
71
114
|
};
|
|
72
|
-
|
|
115
|
+
_this.units = [
|
|
73
116
|
{
|
|
74
117
|
unitSymbol: 'AE',
|
|
75
118
|
factor: '1'
|
|
76
119
|
}
|
|
77
120
|
];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
_this.supportsHD = false;
|
|
122
|
+
_this.standardDerivationPath = "m/44h/457h/0h/0h/0h";
|
|
123
|
+
_this.addressIsCaseSensitive = true;
|
|
124
|
+
_this.addressValidationPattern = '^ak_+[1-9A-Za-z]{38,50}$';
|
|
125
|
+
_this.addressPlaceholder = 'ak_abc...';
|
|
83
126
|
// ae specifics
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return this
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
127
|
+
_this.defaultNetworkId = 'ae_mainnet';
|
|
128
|
+
_this.feesURL = 'https://api-airgap.gke.papers.tech/fees';
|
|
129
|
+
_this.cryptoClient = new AeternityCryptoClient_1.AeternityCryptoClient();
|
|
130
|
+
return _this;
|
|
131
|
+
}
|
|
132
|
+
AeternityProtocol.prototype.getSymbol = function () {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
return [2 /*return*/, this.symbol];
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
AeternityProtocol.prototype.getName = function () {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
return [2 /*return*/, this.name];
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
AeternityProtocol.prototype.getMarketSymbol = function () {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
return [2 /*return*/, this.marketSymbol];
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
AeternityProtocol.prototype.getAssetSymbol = function () {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
return [2 /*return*/, undefined];
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
AeternityProtocol.prototype.getFeeSymbol = function () {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
return [2 /*return*/, this.feeSymbol];
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
AeternityProtocol.prototype.getDecimals = function () {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
return [2 /*return*/, this.decimals];
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
AeternityProtocol.prototype.getFeeDecimals = function () {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
return [2 /*return*/, this.feeDecimals];
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
AeternityProtocol.prototype.getIdentifier = function () {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
+
return __generator(this, function (_a) {
|
|
184
|
+
return [2 /*return*/, this.identifier];
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
AeternityProtocol.prototype.getFeeDefaults = function () {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
return [2 /*return*/, this.feeDefaults];
|
|
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
|
+
};
|
|
150
276
|
/**
|
|
151
277
|
* Returns the PublicKey as String, derived from a supplied hex-string
|
|
152
278
|
* @param secret HEX-Secret from BIP39
|
|
153
279
|
* @param derivationPath DerivationPath for Key
|
|
154
280
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
281
|
+
AeternityProtocol.prototype.getPublicKeyFromHexSecret = function (secret, derivationPath) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
283
|
+
var publicKey;
|
|
284
|
+
return __generator(this, function (_a) {
|
|
285
|
+
publicKey = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath).publicKey;
|
|
286
|
+
return [2 /*return*/, Buffer.from(publicKey).toString('hex')];
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
};
|
|
159
290
|
/**
|
|
160
291
|
* Returns the PrivateKey as Buffer, derived from a supplied hex-string
|
|
161
292
|
* @param secret HEX-Secret from BIP39
|
|
162
293
|
* @param derivationPath DerivationPath for Key
|
|
163
294
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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;
|
|
295
|
+
AeternityProtocol.prototype.getPrivateKeyFromHexSecret = function (secret, derivationPath) {
|
|
296
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
+
var secretKey;
|
|
298
|
+
return __generator(this, function (_a) {
|
|
299
|
+
secretKey = (0, index_3.generateWalletUsingDerivationPath)(Buffer.from(secret, 'hex'), derivationPath).secretKey;
|
|
300
|
+
return [2 /*return*/, Buffer.from(secretKey).toString('hex')];
|
|
301
|
+
});
|
|
217
302
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
303
|
+
};
|
|
304
|
+
AeternityProtocol.prototype.getAddressFromPublicKey = function (publicKey, cursor) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
return [2 /*return*/, {
|
|
308
|
+
address: AeternityAddress_1.AeternityAddress.from(publicKey).asString(),
|
|
309
|
+
cursor: { hasNext: false }
|
|
310
|
+
}];
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
AeternityProtocol.prototype.getAddressesFromPublicKey = function (publicKey, cursor) {
|
|
315
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
316
|
+
var address;
|
|
317
|
+
return __generator(this, function (_a) {
|
|
318
|
+
switch (_a.label) {
|
|
319
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey, cursor)];
|
|
320
|
+
case 1:
|
|
321
|
+
address = _a.sent();
|
|
322
|
+
return [2 /*return*/, [address]];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
AeternityProtocol.prototype.getTransactionsFromPublicKey = function (publicKey, limit, cursor) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
329
|
+
var address;
|
|
330
|
+
return __generator(this, function (_a) {
|
|
331
|
+
switch (_a.label) {
|
|
332
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
333
|
+
case 1:
|
|
334
|
+
address = _a.sent();
|
|
335
|
+
return [2 /*return*/, this.getTransactionsFromAddresses([address.address], limit, cursor)];
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
AeternityProtocol.prototype.getTransactionsFromAddresses = function (addresses, limit, cursor) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
342
|
+
var groupedTransactions, _a, next, allTransactions, transactions;
|
|
343
|
+
var _this = this;
|
|
344
|
+
return __generator(this, function (_b) {
|
|
345
|
+
switch (_b.label) {
|
|
346
|
+
case 0: return [4 /*yield*/, Promise.all(addresses.map(function (address) { return __awaiter(_this, void 0, void 0, function () {
|
|
347
|
+
var endpoint, url, response, _a;
|
|
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
|
+
});
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
AeternityProtocol.prototype.getPageNumber = function (limit, offset) {
|
|
221
406
|
if (limit <= 0 || offset < 0) {
|
|
222
407
|
return 1;
|
|
223
408
|
}
|
|
224
409
|
return 1 + Math.floor(offset / limit); // We need +1 here because pages start at 1
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
410
|
+
};
|
|
411
|
+
AeternityProtocol.prototype.signWithPrivateKey = function (privateKey, transaction) {
|
|
412
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
413
|
+
var rawTx, signature, txObj, txArray, rlpEncodedTx, signedEncodedTx;
|
|
414
|
+
return __generator(this, function (_a) {
|
|
415
|
+
rawTx = this.decodeTx(transaction.transaction);
|
|
416
|
+
signature = (0, ed25519_1.sign)(Buffer.from(privateKey, 'hex'), Buffer.concat([Buffer.from(transaction.networkId), rawTx]));
|
|
417
|
+
txObj = {
|
|
418
|
+
tag: (0, hex_1.toHexBuffer)(11),
|
|
419
|
+
version: (0, hex_1.toHexBuffer)(1),
|
|
420
|
+
signatures: [Buffer.from(signature)],
|
|
421
|
+
transaction: rawTx
|
|
422
|
+
};
|
|
423
|
+
txArray = Object.keys(txObj).map(function (a) { return txObj[a]; });
|
|
424
|
+
rlpEncodedTx = rlp.encode(txArray);
|
|
425
|
+
signedEncodedTx = "tx_".concat(base64Check_1.default.encode(rlpEncodedTx));
|
|
426
|
+
return [2 /*return*/, signedEncodedTx];
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
AeternityProtocol.prototype.decodeTx = function (transaction) {
|
|
431
|
+
var rawTx;
|
|
243
432
|
try {
|
|
244
433
|
rawTx = base64Check_1.default.decode(transaction.replace('tx_', ''));
|
|
245
434
|
return rawTx;
|
|
@@ -255,162 +444,289 @@ class AeternityProtocol extends NonExtendedProtocol_1.NonExtendedProtocol {
|
|
|
255
444
|
//
|
|
256
445
|
}
|
|
257
446
|
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.AETERNITY, 'invalid TX-encoding');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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);
|
|
447
|
+
};
|
|
448
|
+
AeternityProtocol.prototype.getTransactionDetails = function (unsignedTx) {
|
|
449
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
450
|
+
var transaction, rlpEncodedTx, rlpDecodedTx, fromAddress, toAddress, airgapTx;
|
|
451
|
+
return __generator(this, function (_a) {
|
|
452
|
+
switch (_a.label) {
|
|
453
|
+
case 0:
|
|
454
|
+
transaction = unsignedTx.transaction.transaction;
|
|
455
|
+
rlpEncodedTx = this.decodeTx(transaction);
|
|
456
|
+
rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
457
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(rlpDecodedTx[2].slice(1).toString('hex'))];
|
|
458
|
+
case 1:
|
|
459
|
+
fromAddress = _a.sent();
|
|
460
|
+
return [4 /*yield*/, this.getAddressFromPublicKey(rlpDecodedTx[3].slice(1).toString('hex'))];
|
|
461
|
+
case 2:
|
|
462
|
+
toAddress = _a.sent();
|
|
463
|
+
airgapTx = {
|
|
464
|
+
amount: new bignumber_1.default(parseInt(rlpDecodedTx[4].toString('hex'), 16)).toString(10),
|
|
465
|
+
fee: new bignumber_1.default(parseInt(rlpDecodedTx[5].toString('hex'), 16)).toString(10),
|
|
466
|
+
from: [fromAddress.address],
|
|
467
|
+
isInbound: false,
|
|
468
|
+
protocolIdentifier: this.identifier,
|
|
469
|
+
network: this.options.network,
|
|
470
|
+
to: [toAddress.address],
|
|
471
|
+
data: (rlpDecodedTx[8] || '').toString('utf8'),
|
|
472
|
+
transactionDetails: unsignedTx.transaction
|
|
473
|
+
};
|
|
474
|
+
return [2 /*return*/, [airgapTx]];
|
|
301
475
|
}
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
};
|
|
376
|
-
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
};
|
|
479
|
+
AeternityProtocol.prototype.getTransactionDetailsFromSigned = function (signedTx) {
|
|
480
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
481
|
+
var rlpEncodedTx, rlpDecodedTx, unsignedAeternityTransaction;
|
|
482
|
+
return __generator(this, function (_a) {
|
|
483
|
+
rlpEncodedTx = this.decodeTx(signedTx.transaction);
|
|
484
|
+
rlpDecodedTx = rlp.decode(rlpEncodedTx, false);
|
|
485
|
+
unsignedAeternityTransaction = {
|
|
486
|
+
publicKey: '',
|
|
487
|
+
transaction: {
|
|
488
|
+
networkId: 'ae_mainnet',
|
|
489
|
+
transaction: "tx_".concat(base64Check_1.default.encode(rlpDecodedTx[3]))
|
|
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
|
+
}];
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
});
|
|
654
|
+
};
|
|
377
655
|
/**
|
|
378
656
|
* This is a function that we only use to fix incompatibilitis with old vault versions that are unable to understand b64 encoded Txs.
|
|
379
657
|
*
|
|
380
658
|
* @deprecated
|
|
381
659
|
* @param preparedTx
|
|
382
660
|
*/
|
|
383
|
-
convertTxToBase58(preparedTx) {
|
|
661
|
+
AeternityProtocol.prototype.convertTxToBase58 = function (preparedTx) {
|
|
384
662
|
return {
|
|
385
663
|
transaction: bs58check.encode(base64Check_1.default.decode(preparedTx.transaction)),
|
|
386
664
|
networkId: preparedTx.networkId
|
|
387
665
|
};
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return this
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
666
|
+
};
|
|
667
|
+
AeternityProtocol.prototype.broadcastTransaction = function (rawTransaction) {
|
|
668
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
669
|
+
var data;
|
|
670
|
+
return __generator(this, function (_a) {
|
|
671
|
+
switch (_a.label) {
|
|
672
|
+
case 0: return [4 /*yield*/, index_1.default.post("".concat(this.options.network.rpcUrl, "/v2/transactions"), { tx: rawTransaction }, { headers: { 'Content-Type': 'application/json' } })];
|
|
673
|
+
case 1:
|
|
674
|
+
data = (_a.sent()).data;
|
|
675
|
+
return [2 /*return*/, data.tx_hash];
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
};
|
|
680
|
+
AeternityProtocol.prototype.signMessage = function (message, keypair) {
|
|
681
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
682
|
+
return __generator(this, function (_a) {
|
|
683
|
+
return [2 /*return*/, this.cryptoClient.signMessage(message, keypair)];
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
AeternityProtocol.prototype.verifyMessage = function (message, signature, publicKey) {
|
|
688
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
689
|
+
return __generator(this, function (_a) {
|
|
690
|
+
return [2 /*return*/, this.cryptoClient.verifyMessage(message, signature, publicKey)];
|
|
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));
|
|
415
731
|
exports.AeternityProtocol = AeternityProtocol;
|
|
416
732
|
//# sourceMappingURL=AeternityProtocol.js.map
|