@airgap/groestlcoin 0.13.45-beta.2 → 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 (30) hide show
  1. package/package.json +5 -5
  2. package/v0/index.js +5 -5
  3. package/v0/index.js.map +1 -1
  4. package/v0/protocol/GroestlcoinProtocol.js +40 -49
  5. package/v0/protocol/GroestlcoinProtocol.js.map +1 -1
  6. package/v0/protocol/GroestlcoinProtocolOptions.js +45 -111
  7. package/v0/protocol/GroestlcoinProtocolOptions.js.map +1 -1
  8. package/v0/protocol/GroestlcoinTestnetProtocol.js +25 -32
  9. package/v0/protocol/GroestlcoinTestnetProtocol.js.map +1 -1
  10. package/v1/block-explorer/CryptoIDBlockExplorer.js +12 -61
  11. package/v1/block-explorer/CryptoIDBlockExplorer.js.map +1 -1
  12. package/v1/index.js +3 -3
  13. package/v1/index.js.map +1 -1
  14. package/v1/module/GroestlcoinModule.d.ts +1 -1
  15. package/v1/module/GroestlcoinModule.js +37 -95
  16. package/v1/module/GroestlcoinModule.js.map +1 -1
  17. package/v1/module.js +2 -3
  18. package/v1/module.js.map +1 -1
  19. package/v1/protocol/GroestlcoinProtocol.js +195 -426
  20. package/v1/protocol/GroestlcoinProtocol.js.map +1 -1
  21. package/v1/serializer/v3/schemas/converter/transaction-converter.js +5 -6
  22. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  23. package/v1/serializer/v3/serializer-companion.js +69 -148
  24. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  25. package/v1/serializer/v3/validators/transaction-validator.js +3 -23
  26. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  27. package/v1/serializer/v3/validators/validators.js +1 -1
  28. package/v1/serializer/v3/validators/validators.js.map +1 -1
  29. package/v1/types/crypto.d.ts +1 -1
  30. package/v1/types/protocol.d.ts +2 -2
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -26,62 +15,38 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
26
15
  }) : function(o, v) {
27
16
  o["default"] = v;
28
17
  });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (_) try {
52
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
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
+ })();
72
35
  Object.defineProperty(exports, "__esModule", { value: true });
73
- exports.createGroestlcoinProtocolOptions = exports.GROESTLCOIN_TESTNET_PROTOCOL_NETWORK = exports.GROESTLCOIN_MAINNET_PROTOCOL_NETWORK = exports.createGroestlcoinProtocol = exports.GroestlcoinProtocolImpl = void 0;
74
- var BitcoinProtocol_1 = require("@airgap/bitcoin/v1/protocol/BitcoinProtocol");
75
- var coinlib_core_1 = require("@airgap/coinlib-core");
36
+ exports.GROESTLCOIN_TESTNET_PROTOCOL_NETWORK = exports.GROESTLCOIN_MAINNET_PROTOCOL_NETWORK = exports.GroestlcoinProtocolImpl = void 0;
37
+ exports.createGroestlcoinProtocol = createGroestlcoinProtocol;
38
+ exports.createGroestlcoinProtocolOptions = createGroestlcoinProtocolOptions;
39
+ const BitcoinProtocol_1 = require("@airgap/bitcoin/v1/protocol/BitcoinProtocol");
40
+ const coinlib_core_1 = require("@airgap/coinlib-core");
76
41
  // @ts-ignore
77
- var bitGoUTXO = __importStar(require("@airgap/coinlib-core/dependencies/src/bitgo-utxo-lib-5d91049fd7a988382df81c8260e244ee56d57aac/src/index"));
42
+ const bitGoUTXO = __importStar(require("@airgap/coinlib-core/dependencies/src/bitgo-utxo-lib-5d91049fd7a988382df81c8260e244ee56d57aac/src/index"));
78
43
  // @ts-ignore
79
- var groestlcoinJSMessage = __importStar(require("@airgap/coinlib-core/dependencies/src/groestlcoinjs-message-2.1.0/index"));
80
- var module_kit_1 = require("@airgap/module-kit");
44
+ const groestlcoinJSMessage = __importStar(require("@airgap/coinlib-core/dependencies/src/groestlcoinjs-message-2.1.0/index"));
45
+ const module_kit_1 = require("@airgap/module-kit");
81
46
  // Implementation
82
- var BITCOINJS_MAINNET_NETWORK = 'groestlcoin';
83
- var GroestlcoinProtocolImpl = /** @class */ (function () {
84
- function GroestlcoinProtocolImpl(options) {
47
+ const BITCOINJS_MAINNET_NETWORK = 'groestlcoin';
48
+ class GroestlcoinProtocolImpl {
49
+ constructor(options) {
85
50
  // Common
86
51
  this.units = {
87
52
  GRS: {
@@ -111,7 +76,7 @@ var GroestlcoinProtocolImpl = /** @class */ (function () {
111
76
  defaults: this.feeDefaults
112
77
  },
113
78
  account: {
114
- standardDerivationPath: "m/44'/17'/0'",
79
+ standardDerivationPath: `m/44'/17'/0'`,
115
80
  address: {
116
81
  isCaseSensitive: true,
117
82
  placeholder: 'Fdb...',
@@ -121,380 +86,185 @@ var GroestlcoinProtocolImpl = /** @class */ (function () {
121
86
  };
122
87
  this.bitcoinUnits = undefined;
123
88
  this.options = createGroestlcoinProtocolOptions(options.network);
124
- this.bitcoinProtocol = new BitcoinProtocol_1.BitcoinProtocolImpl(__assign(__assign({}, this.options), { network: __assign(__assign({}, this.options.network), { type: 'custom', bitcoinjsNetworkName: BITCOINJS_MAINNET_NETWORK }) }), undefined, bitGoUTXO, groestlcoinJSMessage);
89
+ this.bitcoinProtocol = new BitcoinProtocol_1.BitcoinProtocolImpl({
90
+ ...this.options,
91
+ network: {
92
+ ...this.options.network,
93
+ type: 'custom',
94
+ bitcoinjsNetworkName: BITCOINJS_MAINNET_NETWORK
95
+ }
96
+ }, undefined, bitGoUTXO, groestlcoinJSMessage);
97
+ }
98
+ async getMetadata() {
99
+ return this.metadata;
100
+ }
101
+ async getAddressFromPublicKey(publicKey) {
102
+ return this.bitcoinProtocol.getAddressFromPublicKey(publicKey);
103
+ }
104
+ async deriveFromExtendedPublicKey(extendedPublicKey, visibilityIndex, addressIndex) {
105
+ return this.bitcoinProtocol.deriveFromExtendedPublicKey(extendedPublicKey, visibilityIndex, addressIndex);
106
+ }
107
+ async getDetailsFromTransaction(transaction, publicKey) {
108
+ const bitcoinTransactions = await this.bitcoinProtocol.getDetailsFromTransaction(transaction, publicKey);
109
+ return Promise.all(bitcoinTransactions.map((transaction) => this.fromBitcoinAirGapTransaction(transaction)));
110
+ }
111
+ async verifyMessageWithPublicKey(message, signature, publicKey) {
112
+ return this.bitcoinProtocol.verifyMessageWithPublicKey(message, signature, publicKey);
113
+ }
114
+ async encryptAsymmetricWithPublicKey(payload, publicKey) {
115
+ return this.bitcoinProtocol.encryptAsymmetricWithPublicKey(payload, publicKey);
125
116
  }
126
- GroestlcoinProtocolImpl.prototype.getMetadata = function () {
127
- return __awaiter(this, void 0, void 0, function () {
128
- return __generator(this, function (_a) {
129
- return [2 /*return*/, this.metadata];
130
- });
131
- });
132
- };
133
- GroestlcoinProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
134
- return __awaiter(this, void 0, void 0, function () {
135
- return __generator(this, function (_a) {
136
- return [2 /*return*/, this.bitcoinProtocol.getAddressFromPublicKey(publicKey)];
137
- });
138
- });
139
- };
140
- GroestlcoinProtocolImpl.prototype.deriveFromExtendedPublicKey = function (extendedPublicKey, visibilityIndex, addressIndex) {
141
- return __awaiter(this, void 0, void 0, function () {
142
- return __generator(this, function (_a) {
143
- return [2 /*return*/, this.bitcoinProtocol.deriveFromExtendedPublicKey(extendedPublicKey, visibilityIndex, addressIndex)];
144
- });
145
- });
146
- };
147
- GroestlcoinProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
148
- return __awaiter(this, void 0, void 0, function () {
149
- var bitcoinTransactions;
150
- var _this = this;
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getDetailsFromTransaction(transaction, publicKey)];
154
- case 1:
155
- bitcoinTransactions = _a.sent();
156
- return [2 /*return*/, Promise.all(bitcoinTransactions.map(function (transaction) { return _this.fromBitcoinAirGapTransaction(transaction); }))];
157
- }
158
- });
159
- });
160
- };
161
- GroestlcoinProtocolImpl.prototype.verifyMessageWithPublicKey = function (message, signature, publicKey) {
162
- return __awaiter(this, void 0, void 0, function () {
163
- return __generator(this, function (_a) {
164
- return [2 /*return*/, this.bitcoinProtocol.verifyMessageWithPublicKey(message, signature, publicKey)];
165
- });
166
- });
167
- };
168
- GroestlcoinProtocolImpl.prototype.encryptAsymmetricWithPublicKey = function (payload, publicKey) {
169
- return __awaiter(this, void 0, void 0, function () {
170
- return __generator(this, function (_a) {
171
- return [2 /*return*/, this.bitcoinProtocol.encryptAsymmetricWithPublicKey(payload, publicKey)];
172
- });
173
- });
174
- };
175
117
  // Offline
176
- GroestlcoinProtocolImpl.prototype.getCryptoConfiguration = function () {
177
- return __awaiter(this, void 0, void 0, function () {
178
- return __generator(this, function (_a) {
179
- return [2 /*return*/, this.bitcoinProtocol.getCryptoConfiguration()];
180
- });
181
- });
182
- };
183
- GroestlcoinProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
184
- return __awaiter(this, void 0, void 0, function () {
185
- return __generator(this, function (_a) {
186
- return [2 /*return*/, this.bitcoinProtocol.getKeyPairFromDerivative(derivative)];
187
- });
188
- });
189
- };
190
- GroestlcoinProtocolImpl.prototype.getExtendedKeyPairFromDerivative = function (derivative) {
191
- return __awaiter(this, void 0, void 0, function () {
192
- return __generator(this, function (_a) {
193
- return [2 /*return*/, this.bitcoinProtocol.getExtendedKeyPairFromDerivative(derivative)];
194
- });
195
- });
196
- };
197
- GroestlcoinProtocolImpl.prototype.deriveFromExtendedSecretKey = function (extendedSecretKey, visibilityIndex, addressIndex) {
198
- return __awaiter(this, void 0, void 0, function () {
199
- return __generator(this, function (_a) {
200
- return [2 /*return*/, this.bitcoinProtocol.deriveFromExtendedSecretKey(extendedSecretKey, visibilityIndex, addressIndex)];
201
- });
202
- });
203
- };
204
- GroestlcoinProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
205
- return __awaiter(this, void 0, void 0, function () {
206
- return __generator(this, function (_a) {
207
- return [2 /*return*/, this.bitcoinProtocol.signTransactionWithSecretKey(transaction, secretKey)];
208
- });
209
- });
210
- };
211
- GroestlcoinProtocolImpl.prototype.signMessageWithKeyPair = function (message, keyPair) {
212
- return __awaiter(this, void 0, void 0, function () {
213
- return __generator(this, function (_a) {
214
- return [2 /*return*/, this.bitcoinProtocol.signMessageWithKeyPair(message, keyPair)];
215
- });
216
- });
217
- };
218
- GroestlcoinProtocolImpl.prototype.decryptAsymmetricWithKeyPair = function (payload, keyPair) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- return __generator(this, function (_a) {
221
- return [2 /*return*/, this.bitcoinProtocol.decryptAsymmetricWithKeyPair(payload, keyPair)];
222
- });
223
- });
224
- };
225
- GroestlcoinProtocolImpl.prototype.encryptAESWithSecretKey = function (payload, secretKey) {
226
- return __awaiter(this, void 0, void 0, function () {
227
- return __generator(this, function (_a) {
228
- return [2 /*return*/, this.bitcoinProtocol.encryptAESWithSecretKey(payload, secretKey)];
229
- });
230
- });
231
- };
232
- GroestlcoinProtocolImpl.prototype.decryptAESWithSecretKey = function (payload, secretKey) {
233
- return __awaiter(this, void 0, void 0, function () {
234
- return __generator(this, function (_a) {
235
- return [2 /*return*/, this.bitcoinProtocol.decryptAESWithSecretKey(payload, secretKey)];
236
- });
237
- });
238
- };
118
+ async getCryptoConfiguration() {
119
+ return this.bitcoinProtocol.getCryptoConfiguration();
120
+ }
121
+ async getKeyPairFromDerivative(derivative) {
122
+ return this.bitcoinProtocol.getKeyPairFromDerivative(derivative);
123
+ }
124
+ async getExtendedKeyPairFromDerivative(derivative) {
125
+ return this.bitcoinProtocol.getExtendedKeyPairFromDerivative(derivative);
126
+ }
127
+ async deriveFromExtendedSecretKey(extendedSecretKey, visibilityIndex, addressIndex) {
128
+ return this.bitcoinProtocol.deriveFromExtendedSecretKey(extendedSecretKey, visibilityIndex, addressIndex);
129
+ }
130
+ async signTransactionWithSecretKey(transaction, secretKey) {
131
+ return this.bitcoinProtocol.signTransactionWithSecretKey(transaction, secretKey);
132
+ }
133
+ async signMessageWithKeyPair(message, keyPair) {
134
+ return this.bitcoinProtocol.signMessageWithKeyPair(message, keyPair);
135
+ }
136
+ async decryptAsymmetricWithKeyPair(payload, keyPair) {
137
+ return this.bitcoinProtocol.decryptAsymmetricWithKeyPair(payload, keyPair);
138
+ }
139
+ async encryptAESWithSecretKey(payload, secretKey) {
140
+ return this.bitcoinProtocol.encryptAESWithSecretKey(payload, secretKey);
141
+ }
142
+ async decryptAESWithSecretKey(payload, secretKey) {
143
+ return this.bitcoinProtocol.decryptAESWithSecretKey(payload, secretKey);
144
+ }
239
145
  // Online
240
- GroestlcoinProtocolImpl.prototype.getNetwork = function () {
241
- return __awaiter(this, void 0, void 0, function () {
242
- return __generator(this, function (_a) {
243
- return [2 /*return*/, this.options.network];
244
- });
245
- });
246
- };
247
- GroestlcoinProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
248
- return __awaiter(this, void 0, void 0, function () {
249
- var bitcoinTransactions;
250
- return __generator(this, function (_a) {
251
- switch (_a.label) {
252
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getTransactionsForPublicKey(publicKey, limit, cursor)];
253
- case 1:
254
- bitcoinTransactions = _a.sent();
255
- return [2 /*return*/, this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions)];
256
- }
257
- });
258
- });
259
- };
260
- GroestlcoinProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
261
- return __awaiter(this, void 0, void 0, function () {
262
- var bitcoinTransactions;
263
- return __generator(this, function (_a) {
264
- switch (_a.label) {
265
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getTransactionsForAddress(address, limit, cursor)];
266
- case 1:
267
- bitcoinTransactions = _a.sent();
268
- return [2 /*return*/, this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions)];
269
- }
270
- });
271
- });
272
- };
273
- GroestlcoinProtocolImpl.prototype.getTransactionsForAddresses = function (addresses, limit, cursor) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- var bitcoinTransactions;
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getTransactionsForAddresses(addresses, limit, cursor)];
279
- case 1:
280
- bitcoinTransactions = _a.sent();
281
- return [2 /*return*/, this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions)];
282
- }
283
- });
284
- });
285
- };
286
- GroestlcoinProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
287
- return __awaiter(this, void 0, void 0, function () {
288
- var bitcoinBalance;
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getBalanceOfPublicKey(publicKey)];
292
- case 1:
293
- bitcoinBalance = _a.sent();
294
- return [2 /*return*/, this.fromBitcoinBalance(bitcoinBalance)];
295
- }
296
- });
297
- });
298
- };
299
- GroestlcoinProtocolImpl.prototype.getBalanceOfAddress = function (address) {
300
- return __awaiter(this, void 0, void 0, function () {
301
- var bitcoinBalance;
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getBalanceOfAddress(address)];
305
- case 1:
306
- bitcoinBalance = _a.sent();
307
- return [2 /*return*/, this.fromBitcoinBalance(bitcoinBalance)];
308
- }
309
- });
310
- });
311
- };
312
- GroestlcoinProtocolImpl.prototype.getBalanceOfAddresses = function (addresses) {
313
- return __awaiter(this, void 0, void 0, function () {
314
- var bitcoinBalance;
315
- return __generator(this, function (_a) {
316
- switch (_a.label) {
317
- case 0: return [4 /*yield*/, this.bitcoinProtocol.getBalanceOfAddresses(addresses)];
318
- case 1:
319
- bitcoinBalance = _a.sent();
320
- return [2 /*return*/, this.fromBitcoinBalance(bitcoinBalance)];
321
- }
322
- });
323
- });
324
- };
325
- GroestlcoinProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
326
- return __awaiter(this, void 0, void 0, function () {
327
- var bitcoinFee, bitcoinMax;
328
- return __generator(this, function (_a) {
329
- switch (_a.label) {
330
- case 0:
331
- bitcoinFee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) ? this.toBitcoinAmount(configuration.fee) : undefined;
332
- return [4 /*yield*/, this.bitcoinProtocol.getTransactionMaxAmountWithPublicKey(publicKey, to, __assign(__assign({}, configuration), { fee: bitcoinFee }))];
333
- case 1:
334
- bitcoinMax = _a.sent();
335
- return [2 /*return*/, this.fromBitcoinAmount(bitcoinMax)];
336
- }
337
- });
338
- });
339
- };
340
- GroestlcoinProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, configuration) {
341
- return __awaiter(this, void 0, void 0, function () {
342
- var bitcoinDetails, bitcoinFeeEstimation;
343
- var _this = this;
344
- return __generator(this, function (_a) {
345
- switch (_a.label) {
346
- case 0:
347
- bitcoinDetails = details.map(function (details) {
348
- return _this.toBitcoinTransactionDetails(details);
349
- });
350
- return [4 /*yield*/, this.bitcoinProtocol.getTransactionFeeWithPublicKey(publicKey, bitcoinDetails, configuration)];
351
- case 1:
352
- bitcoinFeeEstimation = _a.sent();
353
- return [2 /*return*/, this.fromBitcoinFeeEstimation(bitcoinFeeEstimation)];
354
- }
355
- });
356
- });
357
- };
358
- GroestlcoinProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
359
- return __awaiter(this, void 0, void 0, function () {
360
- var bitcoinDetails, bitcoinFee;
361
- var _this = this;
362
- return __generator(this, function (_a) {
363
- bitcoinDetails = details.map(function (details) {
364
- return _this.toBitcoinTransactionDetails(details);
365
- });
366
- bitcoinFee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) ? this.toBitcoinAmount(configuration.fee) : undefined;
367
- return [2 /*return*/, this.bitcoinProtocol.prepareTransactionWithPublicKey(publicKey, bitcoinDetails, __assign(__assign({}, configuration), { fee: bitcoinFee }))];
368
- });
146
+ async getNetwork() {
147
+ return this.options.network;
148
+ }
149
+ async getTransactionsForPublicKey(publicKey, limit, cursor) {
150
+ const bitcoinTransactions = await this.bitcoinProtocol.getTransactionsForPublicKey(publicKey, limit, cursor);
151
+ return this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions);
152
+ }
153
+ async getTransactionsForAddress(address, limit, cursor) {
154
+ const bitcoinTransactions = await this.bitcoinProtocol.getTransactionsForAddress(address, limit, cursor);
155
+ return this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions);
156
+ }
157
+ async getTransactionsForAddresses(addresses, limit, cursor) {
158
+ const bitcoinTransactions = await this.bitcoinProtocol.getTransactionsForAddresses(addresses, limit, cursor);
159
+ return this.fromBitcoinAirGapTransactionWithCursor(bitcoinTransactions);
160
+ }
161
+ async getBalanceOfPublicKey(publicKey) {
162
+ const bitcoinBalance = await this.bitcoinProtocol.getBalanceOfPublicKey(publicKey);
163
+ return this.fromBitcoinBalance(bitcoinBalance);
164
+ }
165
+ async getBalanceOfAddress(address) {
166
+ const bitcoinBalance = await this.bitcoinProtocol.getBalanceOfAddress(address);
167
+ return this.fromBitcoinBalance(bitcoinBalance);
168
+ }
169
+ async getBalanceOfAddresses(addresses) {
170
+ const bitcoinBalance = await this.bitcoinProtocol.getBalanceOfAddresses(addresses);
171
+ return this.fromBitcoinBalance(bitcoinBalance);
172
+ }
173
+ async getTransactionMaxAmountWithPublicKey(publicKey, to, configuration) {
174
+ const bitcoinFee = configuration?.fee ? this.toBitcoinAmount(configuration.fee) : undefined;
175
+ const bitcoinMax = await this.bitcoinProtocol.getTransactionMaxAmountWithPublicKey(publicKey, to, {
176
+ ...configuration,
177
+ fee: bitcoinFee
369
178
  });
370
- };
371
- GroestlcoinProtocolImpl.prototype.broadcastTransaction = function (transaction) {
372
- return __awaiter(this, void 0, void 0, function () {
373
- return __generator(this, function (_a) {
374
- return [2 /*return*/, this.bitcoinProtocol.broadcastTransaction(transaction)];
375
- });
179
+ return this.fromBitcoinAmount(bitcoinMax);
180
+ }
181
+ async getTransactionFeeWithPublicKey(publicKey, details, configuration) {
182
+ const bitcoinDetails = details.map((details) => this.toBitcoinTransactionDetails(details));
183
+ const bitcoinFeeEstimation = await this.bitcoinProtocol.getTransactionFeeWithPublicKey(publicKey, bitcoinDetails, configuration);
184
+ return this.fromBitcoinFeeEstimation(bitcoinFeeEstimation);
185
+ }
186
+ async prepareTransactionWithPublicKey(publicKey, details, configuration) {
187
+ const bitcoinDetails = details.map((details) => this.toBitcoinTransactionDetails(details));
188
+ const bitcoinFee = configuration?.fee ? this.toBitcoinAmount(configuration.fee) : undefined;
189
+ return this.bitcoinProtocol.prepareTransactionWithPublicKey(publicKey, bitcoinDetails, {
190
+ ...configuration,
191
+ fee: bitcoinFee
376
192
  });
377
- };
193
+ }
194
+ async broadcastTransaction(transaction) {
195
+ return this.bitcoinProtocol.broadcastTransaction(transaction);
196
+ }
378
197
  // Custom
379
- GroestlcoinProtocolImpl.prototype.fromBitcoinAirGapTransaction = function (transaction) {
380
- return __awaiter(this, void 0, void 0, function () {
381
- var _a, amount, fee;
382
- return __generator(this, function (_b) {
383
- switch (_b.label) {
384
- case 0: return [4 /*yield*/, Promise.all([
385
- this.fromBitcoinAmount(transaction.amount),
386
- this.fromBitcoinAmount(transaction.fee)
387
- ])];
388
- case 1:
389
- _a = _b.sent(), amount = _a[0], fee = _a[1];
390
- return [2 /*return*/, __assign(__assign({}, transaction), { amount: amount, fee: fee })];
391
- }
392
- });
393
- });
394
- };
395
- GroestlcoinProtocolImpl.prototype.fromBitcoinAirGapTransactionWithCursor = function (transactionsWithCursor) {
396
- return __awaiter(this, void 0, void 0, function () {
397
- var _a;
398
- var _this = this;
399
- return __generator(this, function (_b) {
400
- switch (_b.label) {
401
- case 0:
402
- _a = {};
403
- return [4 /*yield*/, Promise.all(transactionsWithCursor.transactions.map(function (transaction) {
404
- return _this.fromBitcoinAirGapTransaction(transaction);
405
- }))];
406
- case 1: return [2 /*return*/, (_a.transactions = _b.sent(),
407
- _a.cursor = {
408
- hasNext: transactionsWithCursor.cursor.hasNext,
409
- page: transactionsWithCursor.cursor.page
410
- },
411
- _a)];
412
- }
413
- });
414
- });
415
- };
416
- GroestlcoinProtocolImpl.prototype.fromBitcoinBalance = function (balance) {
417
- return __awaiter(this, void 0, void 0, function () {
418
- var _a, total, transferable;
419
- return __generator(this, function (_b) {
420
- switch (_b.label) {
421
- case 0: return [4 /*yield*/, Promise.all([
422
- this.fromBitcoinAmount(balance.total),
423
- balance.transferable ? this.fromBitcoinAmount(balance.transferable) : Promise.resolve(undefined)
424
- ])];
425
- case 1:
426
- _a = _b.sent(), total = _a[0], transferable = _a[1];
427
- return [2 /*return*/, { total: total, transferable: transferable }];
428
- }
429
- });
430
- });
431
- };
432
- GroestlcoinProtocolImpl.prototype.fromBitcoinFeeEstimation = function (feeEstimation) {
433
- return __awaiter(this, void 0, void 0, function () {
434
- return __generator(this, function (_a) {
435
- // const [low, medium, high]: [Amount<GroestlcoinUnits>, Amount<GroestlcoinUnits>, Amount<GroestlcoinUnits>] = await Promise.all([
436
- // this.fromBitcoinAmount(feeEstimation.low),
437
- // this.fromBitcoinAmount(feeEstimation.medium),
438
- // this.fromBitcoinAmount(feeEstimation.high)
439
- // ])
440
- return [2 /*return*/, __assign({}, this.feeDefaults)];
441
- });
442
- });
443
- };
444
- GroestlcoinProtocolImpl.prototype.fromBitcoinAmount = function (amount) {
445
- return __awaiter(this, void 0, void 0, function () {
446
- var bitcoinUnits;
447
- return __generator(this, function (_a) {
448
- switch (_a.label) {
449
- case 0: return [4 /*yield*/, this.getBitcoinUnits()];
450
- case 1:
451
- bitcoinUnits = _a.sent();
452
- return [2 /*return*/, this.convertAmount(amount, bitcoinUnits)];
453
- }
454
- });
455
- });
456
- };
457
- GroestlcoinProtocolImpl.prototype.toBitcoinTransactionDetails = function (details) {
458
- return __assign(__assign({}, details), { amount: this.toBitcoinAmount(details.amount) });
459
- };
460
- GroestlcoinProtocolImpl.prototype.toBitcoinAmount = function (amount) {
198
+ async fromBitcoinAirGapTransaction(transaction) {
199
+ const [amount, fee] = await Promise.all([
200
+ this.fromBitcoinAmount(transaction.amount),
201
+ this.fromBitcoinAmount(transaction.fee)
202
+ ]);
203
+ return {
204
+ ...transaction,
205
+ amount,
206
+ fee
207
+ };
208
+ }
209
+ async fromBitcoinAirGapTransactionWithCursor(transactionsWithCursor) {
210
+ return {
211
+ transactions: await Promise.all(transactionsWithCursor.transactions.map((transaction) => this.fromBitcoinAirGapTransaction(transaction))),
212
+ cursor: {
213
+ hasNext: transactionsWithCursor.cursor.hasNext,
214
+ page: transactionsWithCursor.cursor.page
215
+ }
216
+ };
217
+ }
218
+ async fromBitcoinBalance(balance) {
219
+ const [total, transferable] = await Promise.all([
220
+ this.fromBitcoinAmount(balance.total),
221
+ balance.transferable ? this.fromBitcoinAmount(balance.transferable) : Promise.resolve(undefined)
222
+ ]);
223
+ return { total, transferable };
224
+ }
225
+ async fromBitcoinFeeEstimation(feeEstimation) {
226
+ // const [low, medium, high]: [Amount<GroestlcoinUnits>, Amount<GroestlcoinUnits>, Amount<GroestlcoinUnits>] = await Promise.all([
227
+ // this.fromBitcoinAmount(feeEstimation.low),
228
+ // this.fromBitcoinAmount(feeEstimation.medium),
229
+ // this.fromBitcoinAmount(feeEstimation.high)
230
+ // ])
231
+ return { ...this.feeDefaults };
232
+ }
233
+ async fromBitcoinAmount(amount) {
234
+ const bitcoinUnits = await this.getBitcoinUnits();
235
+ return this.convertAmount(amount, bitcoinUnits);
236
+ }
237
+ toBitcoinTransactionDetails(details) {
238
+ return {
239
+ ...details,
240
+ amount: this.toBitcoinAmount(details.amount)
241
+ };
242
+ }
243
+ toBitcoinAmount(amount) {
461
244
  return this.convertAmount(amount, this.units);
462
- };
463
- GroestlcoinProtocolImpl.prototype.getBitcoinUnits = function () {
464
- return __awaiter(this, void 0, void 0, function () {
465
- var metadata;
466
- return __generator(this, function (_a) {
467
- switch (_a.label) {
468
- case 0:
469
- if (!(this.bitcoinUnits === undefined)) return [3 /*break*/, 2];
470
- return [4 /*yield*/, this.bitcoinProtocol.getMetadata()];
471
- case 1:
472
- metadata = _a.sent();
473
- this.bitcoinUnits = metadata.units;
474
- _a.label = 2;
475
- case 2: return [2 /*return*/, this.bitcoinUnits];
476
- }
477
- });
478
- });
479
- };
480
- GroestlcoinProtocolImpl.prototype.convertAmount = function (amount, fromUnits) {
245
+ }
246
+ async getBitcoinUnits() {
247
+ if (this.bitcoinUnits === undefined) {
248
+ const metadata = await this.bitcoinProtocol.getMetadata();
249
+ this.bitcoinUnits = metadata.units;
250
+ }
251
+ return this.bitcoinUnits;
252
+ }
253
+ convertAmount(amount, fromUnits) {
481
254
  return (0, module_kit_1.newAmount)((0, module_kit_1.newAmount)(amount).blockchain(fromUnits).value, 'blockchain');
482
- };
483
- return GroestlcoinProtocolImpl;
484
- }());
255
+ }
256
+ }
485
257
  exports.GroestlcoinProtocolImpl = GroestlcoinProtocolImpl;
486
258
  // Factory
487
- function createGroestlcoinProtocol(options) {
488
- if (options === void 0) { options = {}; }
259
+ function createGroestlcoinProtocol(options = {}) {
489
260
  return new GroestlcoinProtocolImpl(options);
490
261
  }
491
- exports.createGroestlcoinProtocol = createGroestlcoinProtocol;
492
262
  exports.GROESTLCOIN_MAINNET_PROTOCOL_NETWORK = {
493
263
  name: 'Mainnet',
494
264
  type: 'mainnet',
495
265
  rpcUrl: '',
496
266
  blockExplorerUrl: 'https://chainz.cryptoid.info/grs',
497
- indexerApi: "https://cors-proxy.airgap.prod.gke.papers.tech/proxy?url=".concat('https://blockbook.groestlcoin.org')
267
+ indexerApi: `https://cors-proxy.airgap.prod.gke.papers.tech/proxy?url=${'https://blockbook.groestlcoin.org'}`
498
268
  };
499
269
  exports.GROESTLCOIN_TESTNET_PROTOCOL_NETWORK = {
500
270
  name: 'Testnet',
@@ -503,13 +273,12 @@ exports.GROESTLCOIN_TESTNET_PROTOCOL_NETWORK = {
503
273
  blockExplorerUrl: 'https://chainz.cryptoid.info/grs-test',
504
274
  indexerApi: 'https://blockbook-test.groestlcoin.org/'
505
275
  };
506
- var DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK = exports.GROESTLCOIN_MAINNET_PROTOCOL_NETWORK;
507
- function createGroestlcoinProtocolOptions(network) {
508
- if (network === void 0) { network = {}; }
276
+ const DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK = exports.GROESTLCOIN_MAINNET_PROTOCOL_NETWORK;
277
+ function createGroestlcoinProtocolOptions(network = {}) {
509
278
  return {
510
279
  network: network.type === 'custom'
511
- ? __assign(__assign(__assign({}, DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK), { bitcoinjsNetworkName: BITCOINJS_MAINNET_NETWORK }), network) : __assign(__assign({}, DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK), network)
280
+ ? { ...DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK, bitcoinjsNetworkName: BITCOINJS_MAINNET_NETWORK, ...network }
281
+ : { ...DEFAULT_GROESTLCOIN_PROTOCOL_NETWORK, ...network }
512
282
  };
513
283
  }
514
- exports.createGroestlcoinProtocolOptions = createGroestlcoinProtocolOptions;
515
284
  //# sourceMappingURL=GroestlcoinProtocol.js.map