@airgap/icp 0.13.15-beta.0 → 0.13.15-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -6
- package/v1/block-explorer/ICPBlockExplorer.js +16 -51
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -1
- package/v1/index.d.ts +2 -2
- package/v1/index.js +7 -5
- package/v1/index.js.map +1 -1
- package/v1/module/ICPModule.js +53 -94
- package/v1/module/ICPModule.js.map +1 -1
- package/v1/module.js +1 -1
- package/v1/module.js.map +1 -1
- package/v1/protocol/ICPGovernance.d.ts +38 -0
- package/v1/protocol/ICPGovernance.js +748 -0
- package/v1/protocol/ICPGovernance.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +27 -5
- package/v1/protocol/ICPImplementation.js +368 -250
- package/v1/protocol/ICPImplementation.js.map +1 -1
- package/v1/protocol/ICPProtocol.d.ts +29 -4
- package/v1/protocol/ICPProtocol.js +507 -320
- package/v1/protocol/ICPProtocol.js.map +1 -1
- package/v1/protocol/icrc/CkBTCProtocol.js +137 -223
- package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -1
- package/v1/protocol/icrc/ICRC1Protocol.js +338 -553
- package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +17 -4
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +35 -6
- package/v1/serializer/v3/serializer-companion.js +86 -144
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +22 -60
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +19 -58
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/governance.d.ts +2 -0
- package/v1/types/governance.js +268 -210
- package/v1/types/governance.js.map +1 -1
- package/v1/types/icrc/ledger.js +22 -23
- package/v1/types/icrc/ledger.js.map +1 -1
- package/v1/types/ledger.d.ts +1 -0
- package/v1/types/ledger.js +37 -38
- package/v1/types/ledger.js.map +1 -1
- package/v1/types/management_idl.js +6 -7
- package/v1/types/management_idl.js.map +1 -1
- package/v1/types/protocol.d.ts +1 -0
- package/v1/types/transaction.d.ts +21 -3
- package/v1/types/transaction.js +28 -0
- package/v1/types/transaction.js.map +1 -1
- package/v1/utils/account.js +42 -70
- package/v1/utils/account.js.map +1 -1
- package/v1/utils/actor.js +139 -322
- package/v1/utils/actor.js.map +1 -1
- package/v1/utils/auth.js +44 -134
- package/v1/utils/auth.js.map +1 -1
- package/v1/utils/bls.js +41 -109
- package/v1/utils/bls.js.map +1 -1
- package/v1/utils/buffer.js +47 -111
- package/v1/utils/buffer.js.map +1 -1
- package/v1/utils/cbor.js +50 -85
- package/v1/utils/cbor.js.map +1 -1
- package/v1/utils/certificate.js +116 -238
- package/v1/utils/certificate.js.map +1 -1
- package/v1/utils/convert.d.ts +1 -1
- package/v1/utils/convert.js +29 -49
- package/v1/utils/convert.js.map +1 -1
- package/v1/utils/der.js +37 -35
- package/v1/utils/der.js.map +1 -1
- package/v1/utils/errors.js +10 -30
- package/v1/utils/errors.js.map +1 -1
- package/v1/utils/hdkey.js +33 -33
- package/v1/utils/hdkey.js.map +1 -1
- package/v1/utils/http.d.ts +1 -1
- package/v1/utils/http.js +202 -426
- package/v1/utils/http.js.map +1 -1
- package/v1/utils/icrc1.js +24 -41
- package/v1/utils/icrc1.js.map +1 -1
- package/v1/utils/idl.js +780 -1159
- package/v1/utils/idl.js.map +1 -1
- package/v1/utils/leb128.js +29 -30
- package/v1/utils/leb128.js.map +1 -1
- package/v1/utils/polling.js +84 -234
- package/v1/utils/polling.js.map +1 -1
- package/v1/utils/principal.js +78 -126
- package/v1/utils/principal.js.map +1 -1
- package/v1/utils/secp256k1.js +68 -134
- package/v1/utils/secp256k1.js.map +1 -1
- package/v1/utils/transaction.js +7 -7
- 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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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/src/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
|
-
|
|
126
|
-
function ICRC1CommonProtocolImpl() {
|
|
127
|
-
}
|
|
73
|
+
class ICRC1CommonProtocolImpl {
|
|
128
74
|
// Common
|
|
129
|
-
|
|
130
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
return
|
|
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
|
-
|
|
137
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
179
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
-
return
|
|
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
|
-
|
|
186
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
-
return
|
|
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
|
-
|
|
193
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
-
|
|
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
|
-
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
return
|
|
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
|
-
|
|
217
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
-
return
|
|
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
|
-
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
237
|
-
}());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
238
177
|
exports.ICRC1OfflineProtocolImpl = ICRC1OfflineProtocolImpl;
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
256
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
201
|
+
}
|
|
202
|
+
getPartialMetadata() {
|
|
274
203
|
var _a, _b;
|
|
275
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
336
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
-
return
|
|
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
|
-
|
|
343
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
-
|
|
345
|
-
return
|
|
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
|
-
|
|
357
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
-
return
|
|
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
|
-
|
|
364
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
365
|
-
|
|
366
|
-
return
|
|
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
|
-
|
|
373
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
-
|
|
375
|
-
return
|
|
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
|
-
|
|
382
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
383
|
-
|
|
384
|
-
return
|
|
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
|
-
|
|
395
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
309
|
+
}
|
|
310
|
+
getTransactionFeeWithPublicKey(publicKey, details) {
|
|
425
311
|
var _a;
|
|
426
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
445
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
-
|
|
489
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
490
|
-
return
|
|
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
|
-
|
|
496
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
514
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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
|
-
|
|
532
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
-
|
|
550
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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
|
-
|
|
568
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
-
|
|
586
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
|
|
604
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
|
|
622
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
637
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
-
|
|
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
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|