@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.
Files changed (49) hide show
  1. package/package.json +4 -4
  2. package/v0/index.js +7 -7
  3. package/v0/index.js.map +1 -1
  4. package/v0/protocol/AeternityAddress.js +27 -18
  5. package/v0/protocol/AeternityAddress.js.map +1 -1
  6. package/v0/protocol/AeternityCryptoClient.js +21 -84
  7. package/v0/protocol/AeternityCryptoClient.js.map +1 -1
  8. package/v0/protocol/AeternityProtocol.js +341 -657
  9. package/v0/protocol/AeternityProtocol.js.map +1 -1
  10. package/v0/protocol/AeternityProtocolOptions.js +22 -93
  11. package/v0/protocol/AeternityProtocolOptions.js.map +1 -1
  12. package/v0/serializer/validators/transaction-validator.js +30 -83
  13. package/v0/serializer/validators/transaction-validator.js.map +1 -1
  14. package/v0/serializer/validators/validators.js +19 -67
  15. package/v0/serializer/validators/validators.js.map +1 -1
  16. package/v1/block-explorer/AeternityBlockExplorer.js +12 -61
  17. package/v1/block-explorer/AeternityBlockExplorer.js.map +1 -1
  18. package/v1/data/AeternityAddress.js +12 -13
  19. package/v1/data/AeternityAddress.js.map +1 -1
  20. package/v1/index.js +3 -3
  21. package/v1/index.js.map +1 -1
  22. package/v1/module/AeternityModule.d.ts +1 -1
  23. package/v1/module/AeternityModule.js +37 -95
  24. package/v1/module/AeternityModule.js.map +1 -1
  25. package/v1/module.js +2 -3
  26. package/v1/module.js.map +1 -1
  27. package/v1/protocol/AeternityCryptoClient.js +21 -84
  28. package/v1/protocol/AeternityCryptoClient.js.map +1 -1
  29. package/v1/protocol/AeternityProtocol.js +282 -497
  30. package/v1/protocol/AeternityProtocol.js.map +1 -1
  31. package/v1/serializer/v3/schemas/converter/transaction-converter.js +8 -20
  32. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  33. package/v1/serializer/v3/serializer-companion.js +69 -148
  34. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  35. package/v1/serializer/v3/validators/transaction-validator.js +15 -63
  36. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  37. package/v1/serializer/v3/validators/validators.js +19 -67
  38. package/v1/serializer/v3/validators/validators.js.map +1 -1
  39. package/v1/types/crypto.d.ts +1 -1
  40. package/v1/types/protocol.d.ts +1 -1
  41. package/v1/utils/convert.js +26 -17
  42. package/v1/utils/convert.js.map +1 -1
  43. package/v1/utils/key.js +9 -10
  44. package/v1/utils/key.js.map +1 -1
  45. package/v1/utils/signature.js +6 -7
  46. package/v1/utils/signature.js.map +1 -1
  47. package/v1/utils/transaction.d.ts +0 -1
  48. package/v1/utils/transaction.js +26 -17
  49. 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 (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
- };
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
- 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 = {
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
- _this.units = [
72
+ this.units = [
116
73
  {
117
74
  unitSymbol: 'AE',
118
75
  factor: '1'
119
76
  }
120
77
  ];
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...';
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
- _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
- };
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
- 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
- };
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
- 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
- });
302
- });
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
- });
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
- AeternityProtocol.prototype.getPageNumber = function (limit, offset) {
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
- 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;
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
- 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]];
475
- }
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
- }];
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
- AeternityProtocol.prototype.convertTxToBase58 = function (preparedTx) {
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
- 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));
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