@airgap/icp 0.13.15-beta.1 → 0.13.15-beta.10

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 (93) hide show
  1. package/package.json +8 -6
  2. package/v1/block-explorer/ICPBlockExplorer.d.ts +1 -1
  3. package/v1/block-explorer/ICPBlockExplorer.js +16 -49
  4. package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
  5. package/v1/index.d.ts +3 -2
  6. package/v1/index.js +9 -5
  7. package/v1/index.js.map +1 -1
  8. package/v1/module/ICPModule.d.ts +2 -4
  9. package/v1/module/ICPModule.js +53 -94
  10. package/v1/module/ICPModule.js.map +1 -1
  11. package/v1/module.js +1 -1
  12. package/v1/module.js.map +1 -1
  13. package/v1/protocol/ICPGovernance.d.ts +39 -0
  14. package/v1/protocol/ICPGovernance.js +1177 -0
  15. package/v1/protocol/ICPGovernance.js.map +1 -0
  16. package/v1/protocol/ICPImplementation.d.ts +30 -5
  17. package/v1/protocol/ICPImplementation.js +317 -252
  18. package/v1/protocol/ICPImplementation.js.map +1 -1
  19. package/v1/protocol/ICPProtocol.d.ts +60 -8
  20. package/v1/protocol/ICPProtocol.js +765 -320
  21. package/v1/protocol/ICPProtocol.js.map +1 -1
  22. package/v1/protocol/icrc/CkBTCProtocol.js +138 -225
  23. package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
  24. package/v1/protocol/icrc/ICRC1Protocol.d.ts +4 -4
  25. package/v1/protocol/icrc/ICRC1Protocol.js +338 -553
  26. package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -1
  27. package/v1/serializer/v3/schemas/converter/transaction-converter.js +48 -5
  28. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  29. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +8 -2
  30. package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +31 -1
  31. package/v1/serializer/v3/serializer-companion.js +85 -144
  32. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  33. package/v1/serializer/v3/validators/transaction-validator.js +22 -60
  34. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  35. package/v1/serializer/v3/validators/validators.js +19 -58
  36. package/v1/serializer/v3/validators/validators.js.map +1 -1
  37. package/v1/types/governance.d.ts +29 -0
  38. package/v1/types/governance.js +279 -210
  39. package/v1/types/governance.js.map +1 -1
  40. package/v1/types/icrc/ledger.js +22 -23
  41. package/v1/types/icrc/ledger.js.map +1 -1
  42. package/v1/types/ledger.d.ts +1 -0
  43. package/v1/types/ledger.js +37 -38
  44. package/v1/types/ledger.js.map +1 -1
  45. package/v1/types/management_idl.js +6 -7
  46. package/v1/types/management_idl.js.map +1 -1
  47. package/v1/types/protocol.d.ts +2 -1
  48. package/v1/types/transaction.d.ts +22 -3
  49. package/v1/types/transaction.js +38 -0
  50. package/v1/types/transaction.js.map +1 -1
  51. package/v1/utils/account.js +42 -70
  52. package/v1/utils/account.js.map +1 -1
  53. package/v1/utils/actor.js +139 -322
  54. package/v1/utils/actor.js.map +1 -1
  55. package/v1/utils/auth.js +44 -134
  56. package/v1/utils/auth.js.map +1 -1
  57. package/v1/utils/bls.js +41 -109
  58. package/v1/utils/bls.js.map +1 -1
  59. package/v1/utils/buffer.js +47 -111
  60. package/v1/utils/buffer.js.map +1 -1
  61. package/v1/utils/cbor.js +50 -85
  62. package/v1/utils/cbor.js.map +1 -1
  63. package/v1/utils/certificate.js +116 -238
  64. package/v1/utils/certificate.js.map +1 -1
  65. package/v1/utils/convert.d.ts +1 -1
  66. package/v1/utils/convert.js +29 -49
  67. package/v1/utils/convert.js.map +1 -1
  68. package/v1/utils/der.js +37 -35
  69. package/v1/utils/der.js.map +1 -1
  70. package/v1/utils/errors.js +10 -30
  71. package/v1/utils/errors.js.map +1 -1
  72. package/v1/utils/hdkey.js +33 -33
  73. package/v1/utils/hdkey.js.map +1 -1
  74. package/v1/utils/http.d.ts +1 -1
  75. package/v1/utils/http.js +202 -426
  76. package/v1/utils/http.js.map +1 -1
  77. package/v1/utils/icrc1.js +24 -41
  78. package/v1/utils/icrc1.js.map +1 -1
  79. package/v1/utils/idl.js +780 -1159
  80. package/v1/utils/idl.js.map +1 -1
  81. package/v1/utils/json.d.ts +1 -0
  82. package/v1/utils/json.js +19 -0
  83. package/v1/utils/json.js.map +1 -0
  84. package/v1/utils/leb128.js +29 -30
  85. package/v1/utils/leb128.js.map +1 -1
  86. package/v1/utils/polling.js +84 -234
  87. package/v1/utils/polling.js.map +1 -1
  88. package/v1/utils/principal.js +78 -126
  89. package/v1/utils/principal.js.map +1 -1
  90. package/v1/utils/secp256k1.js +68 -134
  91. package/v1/utils/secp256k1.js.map +1 -1
  92. package/v1/utils/transaction.js +7 -7
  93. package/v1/utils/transaction.js.map +1 -1
@@ -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);
@@ -42,70 +31,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
43
32
  });
44
33
  };
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
- };
72
- var __read = (this && this.__read) || function (o, n) {
73
- var m = typeof Symbol === "function" && o[Symbol.iterator];
74
- if (!m) return o;
75
- var i = m.call(o), r, ar = [], e;
76
- try {
77
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
78
- }
79
- catch (error) { e = { error: error }; }
80
- finally {
81
- try {
82
- if (r && !r.done && (m = i["return"])) m.call(i);
83
- }
84
- finally { if (e) throw e.error; }
85
- }
86
- return ar;
87
- };
88
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
89
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
90
36
  };
91
37
  Object.defineProperty(exports, "__esModule", { value: true });
92
38
  exports.ICRC1OnlineProtocolImpl = exports.ICRC1OfflineProtocolImpl = exports.ICRC1_ACCOUNT_METADATA = void 0;
93
39
  // tslint:disable: max-classes-per-file
94
- var coinlib_core_1 = require("@airgap/coinlib-core");
95
- var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
96
- var errors_1 = require("@airgap/coinlib-core/errors");
97
- var module_kit_1 = require("@airgap/module-kit");
98
- var ledger_1 = require("../../types/icrc/ledger");
99
- var actor_1 = require("../../utils/actor");
100
- var auth_1 = require("../../utils/auth");
101
- var Cbor = __importStar(require("../../utils/cbor"));
102
- var convert_1 = require("../../utils/convert");
103
- var icrc1_1 = require("../../utils/icrc1");
104
- var IDL = __importStar(require("../../utils/idl"));
105
- var principal_1 = require("../../utils/principal");
106
- var secp256k1_1 = __importDefault(require("../../utils/secp256k1"));
107
- var ICPImplementation_1 = require("../ICPImplementation");
108
- var ICPProtocol_1 = require("../ICPProtocol");
40
+ const coinlib_core_1 = require("@airgap/coinlib-core");
41
+ const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
42
+ const errors_1 = require("@airgap/coinlib-core/errors");
43
+ const array_1 = require("@airgap/coinlib-core/utils/array");
44
+ const module_kit_1 = require("@airgap/module-kit");
45
+ const ledger_1 = require("../../types/icrc/ledger");
46
+ const transaction_1 = require("../../types/transaction");
47
+ const actor_1 = require("../../utils/actor");
48
+ const auth_1 = require("../../utils/auth");
49
+ const Cbor = __importStar(require("../../utils/cbor"));
50
+ const convert_1 = require("../../utils/convert");
51
+ const icrc1_1 = require("../../utils/icrc1");
52
+ const IDL = __importStar(require("../../utils/idl"));
53
+ const principal_1 = require("../../utils/principal");
54
+ const secp256k1_1 = __importDefault(require("../../utils/secp256k1"));
55
+ const ICPImplementation_1 = require("../ICPImplementation");
56
+ const ICPProtocol_1 = require("../ICPProtocol");
109
57
  // Implementation
110
58
  exports.ICRC1_ACCOUNT_METADATA = {
111
59
  standardDerivationPath: ICPProtocol_1.ICP_DERIVATION_PATH,
@@ -122,46 +70,54 @@ function ICRC1_TRANSACTION_METADATA() {
122
70
  }
123
71
  };
124
72
  }
125
- var ICRC1CommonProtocolImpl = /** @class */ (function () {
126
- function ICRC1CommonProtocolImpl() {
127
- }
73
+ class ICRC1CommonProtocolImpl {
128
74
  // Common
129
- ICRC1CommonProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
130
- return __awaiter(this, void 0, void 0, function () {
131
- return __generator(this, function (_a) {
132
- return [2 /*return*/, (0, icrc1_1.getICRC1AddressFromPublicKey)(publicKey.value)];
133
- });
75
+ getAddressFromPublicKey(publicKey) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return (0, icrc1_1.getICRC1AddressFromPublicKey)(publicKey.value);
134
78
  });
135
- };
136
- ICRC1CommonProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey, network, defaultFee) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- return __generator(this, function (_a) {
139
- switch (transaction.type) {
140
- case 'signed':
141
- return [2 /*return*/, this.getDetailsFromSignedTransaction(transaction, publicKey, network, defaultFee)];
142
- case 'unsigned':
143
- return [2 /*return*/, this.getDetailsFromUnsignedTransaction(transaction, publicKey, network, defaultFee)];
144
- default:
145
- (0, coinlib_core_1.assertNever)(transaction);
146
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, 'Unsupported transaction type.');
147
- }
148
- return [2 /*return*/];
149
- });
79
+ }
80
+ getDetailsFromTransaction(transaction, publicKey, network, defaultFee) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ switch (transaction.type) {
83
+ case 'signed':
84
+ return this.getDetailsFromSignedTransaction(transaction, publicKey, network, defaultFee);
85
+ case 'unsigned':
86
+ return this.getDetailsFromUnsignedTransaction(transaction, publicKey, network, defaultFee);
87
+ default:
88
+ (0, coinlib_core_1.assertNever)(transaction);
89
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, 'Unsupported transaction type.');
90
+ }
150
91
  });
151
- };
152
- ICRC1CommonProtocolImpl.prototype.getDetailsFromSignedTransaction = function (transaction, publicKey, network, defaultFee) {
153
- var decoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(transaction.transaction));
154
- var transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(decoded.content.arg);
155
- return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
156
- };
157
- ICRC1CommonProtocolImpl.prototype.getDetailsFromUnsignedTransaction = function (transaction, publicKey, network, defaultFee) {
158
- var transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(Buffer.from(transaction.transaction, 'hex'));
159
- return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
160
- };
161
- return ICRC1CommonProtocolImpl;
162
- }());
163
- var ICRC1OfflineProtocolImpl = /** @class */ (function () {
164
- function ICRC1OfflineProtocolImpl(options) {
92
+ }
93
+ getDetailsFromSignedTransaction(transaction, publicKey, network, defaultFee) {
94
+ const transactions = transaction.transactions.map(({ encoded, actionType }) => {
95
+ switch (actionType) {
96
+ case transaction_1.ICPActionType.TRANSFER:
97
+ const decoded = Cbor.decode((0, convert_1.hexStringToArrayBuffer)(encoded));
98
+ const transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(decoded.content.arg);
99
+ return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
100
+ default:
101
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, `Unsupported ICRC1 action type ${actionType}.`);
102
+ }
103
+ });
104
+ return (0, array_1.flattenArray)(transactions);
105
+ }
106
+ getDetailsFromUnsignedTransaction(transaction, publicKey, network, defaultFee) {
107
+ const transactions = transaction.transactions.map(({ encoded, actionType }) => {
108
+ switch (actionType) {
109
+ case transaction_1.ICPActionType.TRANSFER:
110
+ const transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(Buffer.from(encoded, 'hex'));
111
+ return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
112
+ default:
113
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, `Unsupported ICRC1 ${actionType} action type.`);
114
+ }
115
+ });
116
+ return (0, array_1.flattenArray)(transactions);
117
+ }
118
+ }
119
+ class ICRC1OfflineProtocolImpl {
120
+ constructor(options) {
165
121
  this.options = options;
166
122
  this.icp = new ICPProtocol_1.ICPProtocolImpl();
167
123
  this.commonImpl = new ICRC1CommonProtocolImpl();
@@ -175,69 +131,52 @@ var ICRC1OfflineProtocolImpl = /** @class */ (function () {
175
131
  transaction: ICRC1_TRANSACTION_METADATA()
176
132
  };
177
133
  }
178
- ICRC1OfflineProtocolImpl.prototype.getMetadata = function () {
179
- return __awaiter(this, void 0, void 0, function () {
180
- return __generator(this, function (_a) {
181
- return [2 /*return*/, this.metadata];
182
- });
134
+ getMetadata() {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return this.metadata;
183
137
  });
184
- };
185
- ICRC1OfflineProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
186
- return __awaiter(this, void 0, void 0, function () {
187
- return __generator(this, function (_a) {
188
- return [2 /*return*/, this.commonImpl.getAddressFromPublicKey(publicKey)];
189
- });
138
+ }
139
+ getAddressFromPublicKey(publicKey) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ return this.commonImpl.getAddressFromPublicKey(publicKey);
190
142
  });
191
- };
192
- ICRC1OfflineProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
193
- return __awaiter(this, void 0, void 0, function () {
194
- var _a, _b, _c, _d;
195
- return __generator(this, function (_e) {
196
- switch (_e.label) {
197
- case 0:
198
- _b = (_a = this.commonImpl).getDetailsFromTransaction;
199
- _c = [transaction,
200
- publicKey];
201
- _d = [{}];
202
- return [4 /*yield*/, this.icp.getNetwork()];
203
- case 1: return [2 /*return*/, _b.apply(_a, _c.concat([__assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { ledgerCanisterId: this.options.ledgerCanisterId }]), this.options.feeDefaults.medium]))];
204
- }
205
- });
143
+ }
144
+ getDetailsFromTransaction(transaction, publicKey) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ return this.commonImpl.getDetailsFromTransaction(transaction, publicKey, Object.assign(Object.assign({}, (yield this.icp.getNetwork())), { ledgerCanisterId: this.options.ledgerCanisterId }), this.options.feeDefaults.medium);
206
147
  });
207
- };
148
+ }
208
149
  // Offline
209
- ICRC1OfflineProtocolImpl.prototype.getCryptoConfiguration = function () {
210
- return __awaiter(this, void 0, void 0, function () {
211
- return __generator(this, function (_a) {
212
- return [2 /*return*/, this.icp.getCryptoConfiguration()];
213
- });
150
+ getCryptoConfiguration() {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ return this.icp.getCryptoConfiguration();
214
153
  });
215
- };
216
- ICRC1OfflineProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
217
- return __awaiter(this, void 0, void 0, function () {
218
- return __generator(this, function (_a) {
219
- return [2 /*return*/, this.icp.getKeyPairFromDerivative(derivative)];
220
- });
154
+ }
155
+ getKeyPairFromDerivative(derivative) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return this.icp.getKeyPairFromDerivative(derivative);
221
158
  });
222
- };
223
- ICRC1OfflineProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var signedTransaction;
226
- return __generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0: return [4 /*yield*/, (0, ICPImplementation_1.signTransaction)(secretKey.value, this.options.ledgerCanisterId, Buffer.from(transaction.transaction, 'hex'), 'icrc1_transfer')];
229
- case 1:
230
- signedTransaction = _a.sent();
231
- return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({ transaction: signedTransaction })];
159
+ }
160
+ signTransactionWithSecretKey(transaction, secretKey) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const transactions = yield Promise.all(transaction.transactions.map(({ encoded, actionType }) => __awaiter(this, void 0, void 0, function* () {
163
+ switch (actionType) {
164
+ case transaction_1.ICPActionType.TRANSFER:
165
+ return {
166
+ actionType,
167
+ encoded: yield (0, ICPImplementation_1.signTransaction)(secretKey.value, this.options.ledgerCanisterId, Buffer.from(encoded, 'hex'), 'icrc1_transfer', 'call')
168
+ };
169
+ default:
170
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, `Unsupported ICRC1 action type ${actionType}.`);
232
171
  }
233
- });
172
+ })));
173
+ return (0, module_kit_1.newSignedTransaction)({ transactions });
234
174
  });
235
- };
236
- return ICRC1OfflineProtocolImpl;
237
- }());
175
+ }
176
+ }
238
177
  exports.ICRC1OfflineProtocolImpl = ICRC1OfflineProtocolImpl;
239
- var ICRC1OnlineProtocolImpl = /** @class */ (function () {
240
- function ICRC1OnlineProtocolImpl(options) {
178
+ class ICRC1OnlineProtocolImpl {
179
+ constructor(options) {
241
180
  this.options = options;
242
181
  // Common
243
182
  this._metadata = undefined;
@@ -252,427 +191,273 @@ var ICRC1OnlineProtocolImpl = /** @class */ (function () {
252
191
  this.icp = new ICPProtocol_1.ICPProtocolImpl({ network: options.network });
253
192
  this.commonImpl = new ICRC1CommonProtocolImpl();
254
193
  }
255
- ICRC1OnlineProtocolImpl.prototype.getMetadata = function () {
256
- return __awaiter(this, void 0, void 0, function () {
257
- var _a, _b;
258
- return __generator(this, function (_c) {
259
- switch (_c.label) {
260
- case 0:
261
- if (!(this._metadata === undefined)) return [3 /*break*/, 2];
262
- _a = this;
263
- _b = [{ identifier: this.options.identifier }];
264
- return [4 /*yield*/, this.getPartialMetadata()];
265
- case 1:
266
- _a._metadata = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_c.sent())])), { account: exports.ICRC1_ACCOUNT_METADATA, transaction: ICRC1_TRANSACTION_METADATA() }]);
267
- _c.label = 2;
268
- case 2: return [2 /*return*/, this._metadata];
269
- }
270
- });
194
+ getMetadata() {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ if (this._metadata === undefined) {
197
+ this._metadata = Object.assign(Object.assign({ identifier: this.options.identifier }, (yield this.getPartialMetadata())), { account: exports.ICRC1_ACCOUNT_METADATA, transaction: ICRC1_TRANSACTION_METADATA() });
198
+ }
199
+ return this._metadata;
271
200
  });
272
- };
273
- ICRC1OnlineProtocolImpl.prototype.getPartialMetadata = function () {
201
+ }
202
+ getPartialMetadata() {
274
203
  var _a, _b;
275
- return __awaiter(this, void 0, void 0, function () {
276
- var mainUnit, icrc1Metadata, _c, name, symbol, decimals, feeDefaults, fetchedUnits;
277
- var _d;
278
- return __generator(this, function (_e) {
279
- switch (_e.label) {
280
- case 0:
281
- mainUnit = (_a = this.options.mainUnit) !== null && _a !== void 0 ? _a : (this.options.units ? Object.keys(this.options.units)[0] : undefined);
282
- if (this.options.name && this.options.units && mainUnit) {
283
- return [2 /*return*/, {
284
- name: this.options.name,
285
- units: this.options.units,
286
- mainUnit: mainUnit,
287
- fee: {
288
- defaults: this.options.feeDefaults,
289
- units: this.options.units,
290
- mainUnit: mainUnit
291
- }
292
- }];
293
- }
294
- return [4 /*yield*/, this.metadata()];
295
- case 1:
296
- icrc1Metadata = _e.sent();
297
- return [4 /*yield*/, Promise.all([
298
- this.options.name ? Promise.resolve(this.options.name) : icrc1Metadata.name ? Promise.resolve(icrc1Metadata.name) : this.name(),
299
- mainUnit
300
- ? Promise.resolve(mainUnit)
301
- : (icrc1Metadata.symbol ? Promise.resolve(icrc1Metadata.symbol) : this.symbol()).then(function (symbol) { return symbol; }),
302
- mainUnit && this.options.units
303
- ? Promise.resolve(this.options.units[mainUnit].decimals)
304
- : icrc1Metadata.decimals
305
- ? Promise.resolve(icrc1Metadata.decimals)
306
- : this.decimals(),
307
- this.options.feeDefaults
308
- ? Promise.resolve(this.options.feeDefaults)
309
- : (icrc1Metadata.fee ? Promise.resolve(icrc1Metadata.fee) : this.fee()).then(function (fee) { return ({
310
- low: (0, module_kit_1.newAmount)(fee, 'blockchain'),
311
- medium: (0, module_kit_1.newAmount)(fee, 'blockchain'),
312
- high: (0, module_kit_1.newAmount)(fee, 'blockchain')
313
- }); })
314
- ])];
315
- case 2:
316
- _c = __read.apply(void 0, [_e.sent(), 4]), name = _c[0], symbol = _c[1], decimals = _c[2], feeDefaults = _c[3];
317
- fetchedUnits = (_d = {},
318
- _d[symbol] = {
319
- symbol: { value: symbol },
320
- decimals: decimals
321
- },
322
- _d);
323
- return [2 /*return*/, {
324
- name: name,
325
- units: (_b = this.options.units) !== null && _b !== void 0 ? _b : fetchedUnits,
326
- mainUnit: symbol,
327
- fee: {
328
- defaults: feeDefaults
329
- }
330
- }];
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ const mainUnit = (_a = this.options.mainUnit) !== null && _a !== void 0 ? _a : (this.options.units ? Object.keys(this.options.units)[0] : undefined);
206
+ if (this.options.name && this.options.units && mainUnit) {
207
+ return {
208
+ name: this.options.name,
209
+ units: this.options.units,
210
+ mainUnit,
211
+ fee: {
212
+ defaults: this.options.feeDefaults,
213
+ units: this.options.units,
214
+ mainUnit
215
+ }
216
+ };
217
+ }
218
+ const icrc1Metadata = yield this.metadata();
219
+ const [name, symbol, decimals, feeDefaults] = yield Promise.all([
220
+ this.options.name ? Promise.resolve(this.options.name) : icrc1Metadata.name ? Promise.resolve(icrc1Metadata.name) : this.name(),
221
+ mainUnit
222
+ ? Promise.resolve(mainUnit)
223
+ : (icrc1Metadata.symbol ? Promise.resolve(icrc1Metadata.symbol) : this.symbol()).then((symbol) => symbol),
224
+ mainUnit && this.options.units
225
+ ? Promise.resolve(this.options.units[mainUnit].decimals)
226
+ : icrc1Metadata.decimals
227
+ ? Promise.resolve(icrc1Metadata.decimals)
228
+ : this.decimals(),
229
+ this.options.feeDefaults
230
+ ? Promise.resolve(this.options.feeDefaults)
231
+ : (icrc1Metadata.fee ? Promise.resolve(icrc1Metadata.fee) : this.fee()).then((fee) => ({
232
+ low: (0, module_kit_1.newAmount)(fee, 'blockchain'),
233
+ medium: (0, module_kit_1.newAmount)(fee, 'blockchain'),
234
+ high: (0, module_kit_1.newAmount)(fee, 'blockchain')
235
+ }))
236
+ ]);
237
+ const fetchedUnits = {
238
+ [symbol]: {
239
+ symbol: { value: symbol },
240
+ decimals
331
241
  }
332
- });
242
+ };
243
+ return {
244
+ name,
245
+ units: (_b = this.options.units) !== null && _b !== void 0 ? _b : fetchedUnits,
246
+ mainUnit: symbol,
247
+ fee: {
248
+ defaults: feeDefaults
249
+ }
250
+ };
333
251
  });
334
- };
335
- ICRC1OnlineProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
336
- return __awaiter(this, void 0, void 0, function () {
337
- return __generator(this, function (_a) {
338
- return [2 /*return*/, this.commonImpl.getAddressFromPublicKey(publicKey)];
339
- });
252
+ }
253
+ getAddressFromPublicKey(publicKey) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ return this.commonImpl.getAddressFromPublicKey(publicKey);
340
256
  });
341
- };
342
- ICRC1OnlineProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
343
- return __awaiter(this, void 0, void 0, function () {
344
- var fee;
345
- return __generator(this, function (_a) {
346
- switch (_a.label) {
347
- case 0: return [4 /*yield*/, this.fee()];
348
- case 1:
349
- fee = _a.sent();
350
- return [2 /*return*/, this.commonImpl.getDetailsFromTransaction(transaction, publicKey, this.options.network, (0, module_kit_1.newAmount)(fee, 'blockchain'))];
351
- }
352
- });
257
+ }
258
+ getDetailsFromTransaction(transaction, publicKey) {
259
+ return __awaiter(this, void 0, void 0, function* () {
260
+ const fee = yield this.fee();
261
+ return this.commonImpl.getDetailsFromTransaction(transaction, publicKey, this.options.network, (0, module_kit_1.newAmount)(fee, 'blockchain'));
353
262
  });
354
- };
263
+ }
355
264
  // Online
356
- ICRC1OnlineProtocolImpl.prototype.getNetwork = function () {
357
- return __awaiter(this, void 0, void 0, function () {
358
- return __generator(this, function (_a) {
359
- return [2 /*return*/, this.options.network];
360
- });
265
+ getNetwork() {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ return this.options.network;
361
268
  });
362
- };
363
- ICRC1OnlineProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
364
- return __awaiter(this, void 0, void 0, function () {
365
- var principal;
366
- return __generator(this, function (_a) {
367
- principal = (0, ICPImplementation_1.getPrincipalFromPublicKey)(publicKey.value);
368
- return [2 /*return*/, this.getBalanceOfAccount({ owner: principal.toText() })];
369
- });
269
+ }
270
+ getBalanceOfPublicKey(publicKey) {
271
+ return __awaiter(this, void 0, void 0, function* () {
272
+ const principal = (0, ICPImplementation_1.getPrincipalFromPublicKey)(publicKey.value);
273
+ return this.getBalanceOfAccount({ owner: principal.toText() });
370
274
  });
371
- };
372
- ICRC1OnlineProtocolImpl.prototype.getBalanceOfAddress = function (address) {
373
- return __awaiter(this, void 0, void 0, function () {
374
- var account;
375
- return __generator(this, function (_a) {
376
- account = (0, icrc1_1.getICRC1AccountFromAddress)(address);
377
- return [2 /*return*/, this.getBalanceOfAccount(account)];
378
- });
275
+ }
276
+ getBalanceOfAddress(address) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ const account = (0, icrc1_1.getICRC1AccountFromAddress)(address);
279
+ return this.getBalanceOfAccount(account);
379
280
  });
380
- };
381
- ICRC1OnlineProtocolImpl.prototype.getBalanceOfAccount = function (account) {
382
- return __awaiter(this, void 0, void 0, function () {
383
- var balance;
384
- return __generator(this, function (_a) {
385
- switch (_a.label) {
386
- case 0: return [4 /*yield*/, this.balanceOf(account)];
387
- case 1:
388
- balance = _a.sent();
389
- return [2 /*return*/, { total: (0, module_kit_1.newAmount)(balance, 'blockchain') }];
390
- }
391
- });
281
+ }
282
+ getBalanceOfAccount(account) {
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ const balance = yield this.balanceOf(account);
285
+ return { total: (0, module_kit_1.newAmount)(balance, 'blockchain') };
392
286
  });
393
- };
394
- ICRC1OnlineProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
395
- return __awaiter(this, void 0, void 0, function () {
396
- var balance, balanceBn, fee, feeEstimation, amountWithoutFees;
397
- return __generator(this, function (_a) {
398
- switch (_a.label) {
399
- case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
400
- case 1:
401
- balance = _a.sent();
402
- balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).value);
403
- if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 2];
404
- fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).value);
405
- return [3 /*break*/, 4];
406
- case 2: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, [])];
407
- case 3:
408
- feeEstimation = _a.sent();
409
- fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation).value);
410
- if (fee.gte(balanceBn)) {
411
- fee = new bignumber_1.default(0);
412
- }
413
- _a.label = 4;
414
- case 4:
415
- amountWithoutFees = balanceBn.minus(fee);
416
- if (amountWithoutFees.isNegative()) {
417
- amountWithoutFees = new bignumber_1.default(0);
418
- }
419
- return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain')];
287
+ }
288
+ getTransactionMaxAmountWithPublicKey(publicKey, to, configuration) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ const balance = yield this.getBalanceOfPublicKey(publicKey);
291
+ const balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).value);
292
+ let fee;
293
+ if ((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined) {
294
+ fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).value);
295
+ }
296
+ else {
297
+ const feeEstimation = yield this.getTransactionFeeWithPublicKey(publicKey, []);
298
+ fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation).value);
299
+ if (fee.gte(balanceBn)) {
300
+ fee = new bignumber_1.default(0);
420
301
  }
421
- });
302
+ }
303
+ let amountWithoutFees = balanceBn.minus(fee);
304
+ if (amountWithoutFees.isNegative()) {
305
+ amountWithoutFees = new bignumber_1.default(0);
306
+ }
307
+ return (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain');
422
308
  });
423
- };
424
- ICRC1OnlineProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, _configuration) {
309
+ }
310
+ getTransactionFeeWithPublicKey(publicKey, details) {
425
311
  var _a;
426
- return __awaiter(this, void 0, void 0, function () {
427
- var metadata, fee;
428
- return __generator(this, function (_b) {
429
- switch (_b.label) {
430
- case 0: return [4 /*yield*/, this.getMetadata()];
431
- case 1:
432
- metadata = _b.sent();
433
- if ((_a = metadata.fee) === null || _a === void 0 ? void 0 : _a.defaults) {
434
- return [2 /*return*/, (0, module_kit_1.newAmount)(metadata.fee.defaults.medium).blockchain(metadata.units)];
435
- }
436
- return [4 /*yield*/, this.fee()];
437
- case 2:
438
- fee = _b.sent();
439
- return [2 /*return*/, (0, module_kit_1.newAmount)(fee, 'blockchain')];
440
- }
441
- });
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ const metadata = yield this.getMetadata();
314
+ if ((_a = metadata.fee) === null || _a === void 0 ? void 0 : _a.defaults) {
315
+ return (0, module_kit_1.newAmount)(metadata.fee.defaults.medium).blockchain(metadata.units);
316
+ }
317
+ const fee = yield this.fee();
318
+ return (0, module_kit_1.newAmount)(fee, 'blockchain');
442
319
  });
443
- };
444
- ICRC1OnlineProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
445
- return __awaiter(this, void 0, void 0, function () {
446
- var TransferArg, metadata, to, amount, fee, _a, _b, memo, transferArg, encodedTransferArg;
447
- return __generator(this, function (_c) {
448
- switch (_c.label) {
449
- case 0:
450
- TransferArg = (0, ledger_1.icrcIDLTypes)(IDL).TransferArg;
451
- return [4 /*yield*/, this.getMetadata()];
452
- case 1:
453
- metadata = _c.sent();
454
- to = (0, icrc1_1.getICRC1AccountFromAddress)(details[0].to);
455
- amount = (0, module_kit_1.newAmount)(details[0].amount).blockchain(metadata.units);
456
- if (!(configuration === null || configuration === void 0 ? void 0 : configuration.fee)) return [3 /*break*/, 2];
457
- _a = (0, module_kit_1.newAmount)(configuration.fee).blockchain(metadata.units);
458
- return [3 /*break*/, 4];
459
- case 2:
460
- _b = module_kit_1.newAmount;
461
- return [4 /*yield*/, this.fee()];
462
- case 3:
463
- _a = _b.apply(void 0, [_c.sent(), 'blockchain']);
464
- _c.label = 4;
465
- case 4:
466
- fee = _a;
467
- memo = details[0].arbitraryData;
468
- transferArg = {
469
- to: {
470
- owner: principal_1.Principal.fromText(to.owner),
471
- subaccount: to.subaccount ? [Buffer.from(to.subaccount, 'hex')] : []
472
- },
473
- fee: [BigInt(fee.value)],
474
- memo: memo ? [Buffer.from(memo, 'hex')] : [],
475
- from_subaccount: [],
476
- created_at_time: [],
477
- amount: BigInt(amount.value)
478
- };
479
- encodedTransferArg = Buffer.from(IDL.encode([TransferArg], [transferArg]));
480
- return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
481
- transaction: encodedTransferArg.toString('hex'),
482
- networkId: '' // TODO: do we need this?
483
- })];
484
- }
320
+ }
321
+ prepareTransactionWithPublicKey(publicKey, details, configuration) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ const { TransferArg } = (0, ledger_1.icrcIDLTypes)(IDL);
324
+ const metadata = yield this.getMetadata();
325
+ const to = (0, icrc1_1.getICRC1AccountFromAddress)(details[0].to);
326
+ const amount = (0, module_kit_1.newAmount)(details[0].amount).blockchain(metadata.units);
327
+ const fee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee)
328
+ ? (0, module_kit_1.newAmount)(configuration.fee).blockchain(metadata.units)
329
+ : (0, module_kit_1.newAmount)(yield this.fee(), 'blockchain');
330
+ const memo = details[0].arbitraryData;
331
+ const transferArg = {
332
+ to: {
333
+ owner: principal_1.Principal.fromText(to.owner),
334
+ subaccount: to.subaccount ? [Buffer.from(to.subaccount, 'hex')] : []
335
+ },
336
+ fee: [BigInt(fee.value)],
337
+ memo: memo ? [Buffer.from(memo, 'hex')] : [],
338
+ from_subaccount: [],
339
+ created_at_time: [],
340
+ amount: BigInt(amount.value)
341
+ };
342
+ const encodedTransferArg = Buffer.from(IDL.encode([TransferArg], [transferArg]));
343
+ return (0, module_kit_1.newUnsignedTransaction)({
344
+ transactions: [
345
+ {
346
+ actionType: transaction_1.ICPActionType.TRANSFER,
347
+ encoded: encodedTransferArg.toString('hex')
348
+ }
349
+ ]
485
350
  });
486
351
  });
487
- };
488
- ICRC1OnlineProtocolImpl.prototype.broadcastTransaction = function (transaction) {
489
- return __awaiter(this, void 0, void 0, function () {
490
- return __generator(this, function (_a) {
491
- return [2 /*return*/, this.icp.broadcastTransaction(transaction)];
492
- });
352
+ }
353
+ broadcastTransaction(transaction) {
354
+ return __awaiter(this, void 0, void 0, function* () {
355
+ return this.icp.broadcastTransaction(transaction);
493
356
  });
494
- };
495
- ICRC1OnlineProtocolImpl.prototype.name = function () {
496
- return __awaiter(this, void 0, void 0, function () {
497
- var actor, name_1;
498
- return __generator(this, function (_a) {
499
- switch (_a.label) {
500
- case 0:
501
- if (!!this._name) return [3 /*break*/, 2];
502
- actor = this.createLedgerActor();
503
- return [4 /*yield*/, actor.icrc1_name()];
504
- case 1:
505
- name_1 = _a.sent();
506
- this._name = name_1;
507
- _a.label = 2;
508
- case 2: return [2 /*return*/, this._name];
509
- }
510
- });
357
+ }
358
+ name() {
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ if (!this._name) {
361
+ const actor = this.createLedgerActor();
362
+ const name = yield actor.icrc1_name();
363
+ this._name = name;
364
+ }
365
+ return this._name;
511
366
  });
512
- };
513
- ICRC1OnlineProtocolImpl.prototype.symbol = function () {
514
- return __awaiter(this, void 0, void 0, function () {
515
- var actor, symbol;
516
- return __generator(this, function (_a) {
517
- switch (_a.label) {
518
- case 0:
519
- if (!!this._symbol) return [3 /*break*/, 2];
520
- actor = this.createLedgerActor();
521
- return [4 /*yield*/, actor.icrc1_symbol()];
522
- case 1:
523
- symbol = _a.sent();
524
- this._symbol = symbol;
525
- _a.label = 2;
526
- case 2: return [2 /*return*/, this._symbol];
527
- }
528
- });
367
+ }
368
+ symbol() {
369
+ return __awaiter(this, void 0, void 0, function* () {
370
+ if (!this._symbol) {
371
+ const actor = this.createLedgerActor();
372
+ const symbol = yield actor.icrc1_symbol();
373
+ this._symbol = symbol;
374
+ }
375
+ return this._symbol;
529
376
  });
530
- };
531
- ICRC1OnlineProtocolImpl.prototype.decimals = function () {
532
- return __awaiter(this, void 0, void 0, function () {
533
- var actor, decimals;
534
- return __generator(this, function (_a) {
535
- switch (_a.label) {
536
- case 0:
537
- if (!!this._decimals) return [3 /*break*/, 2];
538
- actor = this.createLedgerActor();
539
- return [4 /*yield*/, actor.icrc1_decimals()];
540
- case 1:
541
- decimals = _a.sent();
542
- this._decimals = decimals;
543
- _a.label = 2;
544
- case 2: return [2 /*return*/, this._decimals];
545
- }
546
- });
377
+ }
378
+ decimals() {
379
+ return __awaiter(this, void 0, void 0, function* () {
380
+ if (!this._decimals) {
381
+ const actor = this.createLedgerActor();
382
+ const decimals = yield actor.icrc1_decimals();
383
+ this._decimals = decimals;
384
+ }
385
+ return this._decimals;
547
386
  });
548
- };
549
- ICRC1OnlineProtocolImpl.prototype.fee = function () {
550
- return __awaiter(this, void 0, void 0, function () {
551
- var actor, fee;
552
- return __generator(this, function (_a) {
553
- switch (_a.label) {
554
- case 0:
555
- if (!!this._fee) return [3 /*break*/, 2];
556
- actor = this.createLedgerActor();
557
- return [4 /*yield*/, actor.icrc1_fee()];
558
- case 1:
559
- fee = _a.sent();
560
- this._fee = fee.toString();
561
- _a.label = 2;
562
- case 2: return [2 /*return*/, this._fee];
563
- }
564
- });
387
+ }
388
+ fee() {
389
+ return __awaiter(this, void 0, void 0, function* () {
390
+ if (!this._fee) {
391
+ const actor = this.createLedgerActor();
392
+ const fee = yield actor.icrc1_fee();
393
+ this._fee = fee.toString();
394
+ }
395
+ return this._fee;
565
396
  });
566
- };
567
- ICRC1OnlineProtocolImpl.prototype.baseMetadata = function () {
568
- return __awaiter(this, void 0, void 0, function () {
569
- var actor, metadata;
570
- return __generator(this, function (_a) {
571
- switch (_a.label) {
572
- case 0:
573
- if (!!this._baseMetadata) return [3 /*break*/, 2];
574
- actor = this.createLedgerActor();
575
- return [4 /*yield*/, actor.icrc1_metadata()];
576
- case 1:
577
- metadata = _a.sent();
578
- this._baseMetadata = (0, icrc1_1.decodeICRC1Metadata)(metadata);
579
- _a.label = 2;
580
- case 2: return [2 /*return*/, this._baseMetadata];
581
- }
582
- });
397
+ }
398
+ baseMetadata() {
399
+ return __awaiter(this, void 0, void 0, function* () {
400
+ if (!this._baseMetadata) {
401
+ const actor = this.createLedgerActor();
402
+ const metadata = yield actor.icrc1_metadata();
403
+ this._baseMetadata = (0, icrc1_1.decodeICRC1Metadata)(metadata);
404
+ }
405
+ return this._baseMetadata;
583
406
  });
584
- };
585
- ICRC1OnlineProtocolImpl.prototype.totalSupply = function () {
586
- return __awaiter(this, void 0, void 0, function () {
587
- var actor, totalSupply;
588
- return __generator(this, function (_a) {
589
- switch (_a.label) {
590
- case 0:
591
- if (!!this._totalSupply) return [3 /*break*/, 2];
592
- actor = this.createLedgerActor();
593
- return [4 /*yield*/, actor.icrc1_total_supply()];
594
- case 1:
595
- totalSupply = _a.sent();
596
- this._totalSupply = totalSupply.toString();
597
- _a.label = 2;
598
- case 2: return [2 /*return*/, this._totalSupply];
599
- }
600
- });
407
+ }
408
+ totalSupply() {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ if (!this._totalSupply) {
411
+ const actor = this.createLedgerActor();
412
+ const totalSupply = yield actor.icrc1_total_supply();
413
+ this._totalSupply = totalSupply.toString();
414
+ }
415
+ return this._totalSupply;
601
416
  });
602
- };
603
- ICRC1OnlineProtocolImpl.prototype.mintingAccount = function () {
604
- return __awaiter(this, void 0, void 0, function () {
605
- var actor, mintingAccount;
606
- return __generator(this, function (_a) {
607
- switch (_a.label) {
608
- case 0:
609
- if (!(this._mintingAccount === null)) return [3 /*break*/, 2];
610
- actor = this.createLedgerActor();
611
- return [4 /*yield*/, actor.icrc1_minting_account()];
612
- case 1:
613
- mintingAccount = _a.sent();
614
- this._mintingAccount = (0, icrc1_1.decodeOptionalICRC1Account)(mintingAccount);
615
- _a.label = 2;
616
- case 2: return [2 /*return*/, this._mintingAccount];
617
- }
618
- });
417
+ }
418
+ mintingAccount() {
419
+ return __awaiter(this, void 0, void 0, function* () {
420
+ if (this._mintingAccount === null) {
421
+ const actor = this.createLedgerActor();
422
+ const mintingAccount = yield actor.icrc1_minting_account();
423
+ this._mintingAccount = (0, icrc1_1.decodeOptionalICRC1Account)(mintingAccount);
424
+ }
425
+ return this._mintingAccount;
619
426
  });
620
- };
621
- ICRC1OnlineProtocolImpl.prototype.balanceOf = function (account) {
622
- return __awaiter(this, void 0, void 0, function () {
623
- var actor, balance;
624
- return __generator(this, function (_a) {
625
- switch (_a.label) {
626
- case 0:
627
- actor = this.createLedgerActor();
628
- return [4 /*yield*/, actor.icrc1_balance_of((0, icrc1_1.encodeICRC1Account)(account))];
629
- case 1:
630
- balance = _a.sent();
631
- return [2 /*return*/, balance];
632
- }
633
- });
427
+ }
428
+ balanceOf(account) {
429
+ return __awaiter(this, void 0, void 0, function* () {
430
+ const actor = this.createLedgerActor();
431
+ const balance = yield actor.icrc1_balance_of((0, icrc1_1.encodeICRC1Account)(account));
432
+ return balance;
634
433
  });
635
- };
636
- ICRC1OnlineProtocolImpl.prototype.transfer = function (privateKey, args) {
637
- return __awaiter(this, void 0, void 0, function () {
638
- var actor, result;
639
- return __generator(this, function (_a) {
640
- switch (_a.label) {
641
- case 0:
642
- actor = this.createLedgerActor(ledger_1.icrcIDLFactory, secp256k1_1.default.fromSecretKey((0, convert_1.hexStringToArrayBuffer)(privateKey)));
643
- return [4 /*yield*/, actor.icrc1_transfer({
644
- to: (0, icrc1_1.encodeICRC1Account)(args.to),
645
- fee: args.fee ? [BigInt(args.fee)] : [],
646
- memo: args.memo ? [Buffer.from(args.memo)] : [],
647
- from_subaccount: args.fromSubaccount ? [Buffer.from(args.fromSubaccount)] : [],
648
- created_at_time: args.createdAtTime ? [BigInt(args.createdAtTime)] : [],
649
- amount: BigInt(args.amount)
650
- })];
651
- case 1:
652
- result = _a.sent();
653
- if (result.Ok) {
654
- return [2 /*return*/, result.Ok.toString()];
655
- }
656
- else {
657
- throw new coinlib_core_1.TransactionError(coinlib_core_1.Domain.ICP, "ICRC1 transfer failed (".concat(result.Err.GenericError.error_code.toString(), ": ").concat(result.Err.GenericError.message, ")"));
658
- }
659
- return [2 /*return*/];
660
- }
434
+ }
435
+ transfer(privateKey, args) {
436
+ return __awaiter(this, void 0, void 0, function* () {
437
+ const actor = this.createLedgerActor(ledger_1.icrcIDLFactory, secp256k1_1.default.fromSecretKey((0, convert_1.hexStringToArrayBuffer)(privateKey)));
438
+ const result = yield actor.icrc1_transfer({
439
+ to: (0, icrc1_1.encodeICRC1Account)(args.to),
440
+ fee: args.fee ? [BigInt(args.fee)] : [],
441
+ memo: args.memo ? [Buffer.from(args.memo)] : [],
442
+ from_subaccount: args.fromSubaccount ? [Buffer.from(args.fromSubaccount)] : [],
443
+ created_at_time: args.createdAtTime ? [BigInt(args.createdAtTime)] : [],
444
+ amount: BigInt(args.amount)
661
445
  });
446
+ if (result.Ok) {
447
+ return result.Ok.toString();
448
+ }
449
+ else {
450
+ throw new coinlib_core_1.TransactionError(coinlib_core_1.Domain.ICP, `ICRC1 transfer failed (${result.Err.GenericError.error_code.toString()}: ${result.Err.GenericError.message})`);
451
+ }
662
452
  });
663
- };
664
- ICRC1OnlineProtocolImpl.prototype.createLedgerActor = function (idlFactory, identity) {
665
- if (idlFactory === void 0) { idlFactory = ledger_1.icrcIDLFactory; }
666
- if (identity === void 0) { identity = new auth_1.AnonymousIdentity(); }
453
+ }
454
+ createLedgerActor(idlFactory = ledger_1.icrcIDLFactory, identity = new auth_1.AnonymousIdentity()) {
667
455
  return this.createActor(this.options.network.ledgerCanisterId, idlFactory, identity);
668
- };
669
- ICRC1OnlineProtocolImpl.prototype.createActor = function (canisterId, idlFactory, identity) {
670
- if (idlFactory === void 0) { idlFactory = ledger_1.icrcIDLFactory; }
671
- if (identity === void 0) { identity = new auth_1.AnonymousIdentity(); }
672
- var agent = (0, ICPImplementation_1.createHttpAgent)(this.options.network.rpcUrl, identity);
673
- return actor_1.Actor.createActor(idlFactory, { agent: agent, canisterId: canisterId });
674
- };
675
- return ICRC1OnlineProtocolImpl;
676
- }());
456
+ }
457
+ createActor(canisterId, idlFactory = ledger_1.icrcIDLFactory, identity = new auth_1.AnonymousIdentity()) {
458
+ const agent = (0, ICPImplementation_1.createHttpAgent)(this.options.network.rpcUrl, identity);
459
+ return actor_1.Actor.createActor(idlFactory, { agent, canisterId });
460
+ }
461
+ }
677
462
  exports.ICRC1OnlineProtocolImpl = ICRC1OnlineProtocolImpl;
678
463
  //# sourceMappingURL=ICRC1Protocol.js.map