@airgap/icp 0.13.11-beta.4 → 0.13.11-beta.5
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 +1 -1
- package/v1/index.d.ts +2 -3
- package/v1/index.js +1 -4
- package/v1/index.js.map +1 -1
- package/v1/module/ICPModule.d.ts +3 -2
- package/v1/module/ICPModule.js +10 -22
- package/v1/module/ICPModule.js.map +1 -1
- package/v1/protocol/ICPImplementation.d.ts +4 -12
- package/v1/protocol/ICPImplementation.js +55 -87
- package/v1/protocol/ICPImplementation.js.map +1 -1
- package/v1/protocol/ICPProtocol.d.ts +1 -4
- package/v1/protocol/ICPProtocol.js +17 -24
- package/v1/protocol/ICPProtocol.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +0 -16
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/types/ledger.d.ts +1 -0
- package/v1/types/ledger.js +2 -1
- package/v1/types/ledger.js.map +1 -1
- package/v1/types/protocol.d.ts +1 -21
- package/v1/protocol/icrc/CkBTCProtocol.d.ts +0 -16
- package/v1/protocol/icrc/CkBTCProtocol.js +0 -366
- package/v1/protocol/icrc/CkBTCProtocol.js.map +0 -1
- package/v1/protocol/icrc/ICRC1Protocol.d.ts +0 -93
- package/v1/protocol/icrc/ICRC1Protocol.js +0 -684
- package/v1/protocol/icrc/ICRC1Protocol.js.map +0 -1
- package/v1/types/ckbtc/metadata.d.ts +0 -4
- package/v1/types/ckbtc/metadata.js +0 -3
- package/v1/types/ckbtc/metadata.js.map +0 -1
- package/v1/types/icrc/account.d.ts +0 -4
- package/v1/types/icrc/account.js +0 -3
- package/v1/types/icrc/account.js.map +0 -1
- package/v1/types/icrc/ledger.d.ts +0 -15
- package/v1/types/icrc/ledger.js +0 -92
- package/v1/types/icrc/ledger.js.map +0 -1
- package/v1/types/icrc/metadata.d.ts +0 -6
- package/v1/types/icrc/metadata.js +0 -3
- package/v1/types/icrc/metadata.js.map +0 -1
- package/v1/types/icrc/transfer.d.ts +0 -9
- package/v1/types/icrc/transfer.js +0 -3
- package/v1/types/icrc/transfer.js.map +0 -1
- package/v1/utils/icrc1.d.ts +0 -16
- package/v1/utils/icrc1.js +0 -109
- package/v1/utils/icrc1.js.map +0 -1
|
@@ -1,684 +0,0 @@
|
|
|
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
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
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
|
-
};
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
89
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
90
|
-
};
|
|
91
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
-
exports.ICRC1OnlineProtocolImpl = exports.ICRC1OfflineProtocolImpl = void 0;
|
|
93
|
-
// 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 secp256k1_1 = __importDefault(require("../../utils/secp256k1"));
|
|
106
|
-
var ICPImplementation_1 = require("../ICPImplementation");
|
|
107
|
-
var ICPProtocol_1 = require("../ICPProtocol");
|
|
108
|
-
// Implementation
|
|
109
|
-
function ICRC1_TRANSACTION_METADATA() {
|
|
110
|
-
return {
|
|
111
|
-
arbitraryData: {
|
|
112
|
-
inner: { name: 'memo' }
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
var ICRC1CommonProtocolImpl = /** @class */ (function () {
|
|
117
|
-
function ICRC1CommonProtocolImpl(canisterId, icp) {
|
|
118
|
-
this.canisterId = canisterId;
|
|
119
|
-
this.icp = icp;
|
|
120
|
-
}
|
|
121
|
-
// SubProtocol
|
|
122
|
-
ICRC1CommonProtocolImpl.prototype.getType = function () {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
return __generator(this, function (_a) {
|
|
125
|
-
return [2 /*return*/, 'token'];
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
ICRC1CommonProtocolImpl.prototype.getContractAddress = function () {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
-
return __generator(this, function (_a) {
|
|
132
|
-
return [2 /*return*/, this.canisterId];
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
ICRC1CommonProtocolImpl.prototype.mainProtocol = function () {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
-
return __generator(this, function (_a) {
|
|
139
|
-
return [2 /*return*/, coinlib_core_1.MainProtocolSymbols.ICP];
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
// Common
|
|
144
|
-
ICRC1CommonProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
145
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
return __generator(this, function (_a) {
|
|
147
|
-
return [2 /*return*/, this.icp.getAddressFromPublicKey(publicKey)];
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
ICRC1CommonProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey, network, defaultFee) {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (transaction.type) {
|
|
155
|
-
case 'signed':
|
|
156
|
-
return [2 /*return*/, this.getDetailsFromSignedTransaction(transaction, publicKey, network, defaultFee)];
|
|
157
|
-
case 'unsigned':
|
|
158
|
-
return [2 /*return*/, this.getDetailsFromUnsignedTransaction(transaction, publicKey, network, defaultFee)];
|
|
159
|
-
default:
|
|
160
|
-
(0, coinlib_core_1.assertNever)(transaction);
|
|
161
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, 'Unsupported transaction type.');
|
|
162
|
-
}
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
ICRC1CommonProtocolImpl.prototype.getDetailsFromSignedTransaction = function (transaction, publicKey, network, defaultFee) {
|
|
168
|
-
var transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(Cbor.decode((0, convert_1.hexStringToArrayBuffer)(transaction.transaction)));
|
|
169
|
-
return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
|
|
170
|
-
};
|
|
171
|
-
ICRC1CommonProtocolImpl.prototype.getDetailsFromUnsignedTransaction = function (transaction, publicKey, network, defaultFee) {
|
|
172
|
-
var transferArgs = (0, icrc1_1.decodeICRC1TransferArgs)(Buffer.from(transaction.transaction, 'hex'));
|
|
173
|
-
return (0, icrc1_1.getDetailsFromTransferArgs)(transferArgs, publicKey.value, network, defaultFee);
|
|
174
|
-
};
|
|
175
|
-
return ICRC1CommonProtocolImpl;
|
|
176
|
-
}());
|
|
177
|
-
var ICRC1OfflineProtocolImpl = /** @class */ (function () {
|
|
178
|
-
function ICRC1OfflineProtocolImpl(options) {
|
|
179
|
-
this.options = options;
|
|
180
|
-
this.icp = new ICPProtocol_1.ICPProtocolImpl();
|
|
181
|
-
this.commonImpl = new ICRC1CommonProtocolImpl(options.canisterId, this.icp);
|
|
182
|
-
this.metadata = {
|
|
183
|
-
identifier: options.identifier,
|
|
184
|
-
name: options.name,
|
|
185
|
-
units: options.units,
|
|
186
|
-
mainUnit: options.mainUnit,
|
|
187
|
-
fee: { defaults: options.feeDefaults },
|
|
188
|
-
account: ICPProtocol_1.ICP_ACCOUNT_METADATA,
|
|
189
|
-
transaction: ICRC1_TRANSACTION_METADATA()
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
// SubProtocol
|
|
193
|
-
ICRC1OfflineProtocolImpl.prototype.getType = function () {
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
return __generator(this, function (_a) {
|
|
196
|
-
return [2 /*return*/, this.commonImpl.getType()];
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
ICRC1OfflineProtocolImpl.prototype.getContractAddress = function () {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
-
return __generator(this, function (_a) {
|
|
203
|
-
return [2 /*return*/, this.commonImpl.getContractAddress()];
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
ICRC1OfflineProtocolImpl.prototype.mainProtocol = function () {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
-
return __generator(this, function (_a) {
|
|
210
|
-
return [2 /*return*/, this.commonImpl.mainProtocol()];
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
ICRC1OfflineProtocolImpl.prototype.getMetadata = function () {
|
|
215
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
-
return __generator(this, function (_a) {
|
|
217
|
-
return [2 /*return*/, this.metadata];
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
};
|
|
221
|
-
ICRC1OfflineProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
222
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
-
return __generator(this, function (_a) {
|
|
224
|
-
return [2 /*return*/, this.commonImpl.getAddressFromPublicKey(publicKey)];
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
ICRC1OfflineProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
|
|
229
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
230
|
-
var _a, _b, _c, _d;
|
|
231
|
-
return __generator(this, function (_e) {
|
|
232
|
-
switch (_e.label) {
|
|
233
|
-
case 0:
|
|
234
|
-
_b = (_a = this.commonImpl).getDetailsFromTransaction;
|
|
235
|
-
_c = [transaction,
|
|
236
|
-
publicKey];
|
|
237
|
-
_d = [{}];
|
|
238
|
-
return [4 /*yield*/, this.icp.getNetwork()];
|
|
239
|
-
case 1: return [2 /*return*/, _b.apply(_a, _c.concat([__assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_e.sent())])), { canisterId: this.options.canisterId }]), this.options.feeDefaults.medium]))];
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
// Offline
|
|
245
|
-
ICRC1OfflineProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
246
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
-
return __generator(this, function (_a) {
|
|
248
|
-
return [2 /*return*/, this.icp.getCryptoConfiguration()];
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
};
|
|
252
|
-
ICRC1OfflineProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
254
|
-
return __generator(this, function (_a) {
|
|
255
|
-
return [2 /*return*/, this.icp.getKeyPairFromDerivative(derivative)];
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
ICRC1OfflineProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
260
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
261
|
-
var TransferArg, arg, signedTransaction;
|
|
262
|
-
return __generator(this, function (_a) {
|
|
263
|
-
switch (_a.label) {
|
|
264
|
-
case 0:
|
|
265
|
-
TransferArg = (0, ledger_1.icrcIDLTypes)(IDL).TransferArg;
|
|
266
|
-
arg = IDL.decode([TransferArg], Buffer.from(transaction.transaction, 'hex'));
|
|
267
|
-
return [4 /*yield*/, (0, ICPImplementation_1.signTransaction)(secretKey.value, this.options.canisterId, arg)];
|
|
268
|
-
case 1:
|
|
269
|
-
signedTransaction = _a.sent();
|
|
270
|
-
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({ transaction: signedTransaction })];
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
return ICRC1OfflineProtocolImpl;
|
|
276
|
-
}());
|
|
277
|
-
exports.ICRC1OfflineProtocolImpl = ICRC1OfflineProtocolImpl;
|
|
278
|
-
var ICRC1OnlineProtocolImpl = /** @class */ (function () {
|
|
279
|
-
function ICRC1OnlineProtocolImpl(options) {
|
|
280
|
-
this.options = options;
|
|
281
|
-
// Common
|
|
282
|
-
this._metadata = undefined;
|
|
283
|
-
// Custom
|
|
284
|
-
this._name = undefined;
|
|
285
|
-
this._symbol = undefined;
|
|
286
|
-
this._decimals = undefined;
|
|
287
|
-
this._fee = undefined;
|
|
288
|
-
this._baseMetadata = undefined;
|
|
289
|
-
this._totalSupply = undefined;
|
|
290
|
-
this._mintingAccount = null;
|
|
291
|
-
this.icp = new ICPProtocol_1.ICPProtocolImpl({ network: options.network });
|
|
292
|
-
this.commonImpl = new ICRC1CommonProtocolImpl(this.options.network.canisterId, this.icp);
|
|
293
|
-
}
|
|
294
|
-
// SubProtocol
|
|
295
|
-
ICRC1OnlineProtocolImpl.prototype.getType = function () {
|
|
296
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
-
return __generator(this, function (_a) {
|
|
298
|
-
return [2 /*return*/, this.commonImpl.getType()];
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
ICRC1OnlineProtocolImpl.prototype.getContractAddress = function () {
|
|
303
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
304
|
-
return __generator(this, function (_a) {
|
|
305
|
-
return [2 /*return*/, this.commonImpl.getContractAddress()];
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
};
|
|
309
|
-
ICRC1OnlineProtocolImpl.prototype.mainProtocol = function () {
|
|
310
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
311
|
-
return __generator(this, function (_a) {
|
|
312
|
-
return [2 /*return*/, this.commonImpl.mainProtocol()];
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
};
|
|
316
|
-
ICRC1OnlineProtocolImpl.prototype.getMetadata = function () {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
-
var _a, _b;
|
|
319
|
-
return __generator(this, function (_c) {
|
|
320
|
-
switch (_c.label) {
|
|
321
|
-
case 0:
|
|
322
|
-
if (!(this._metadata === undefined)) return [3 /*break*/, 2];
|
|
323
|
-
_a = this;
|
|
324
|
-
_b = [{ identifier: this.options.identifier }];
|
|
325
|
-
return [4 /*yield*/, this.getPartialMetadata()];
|
|
326
|
-
case 1:
|
|
327
|
-
_a._metadata = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_c.sent())])), { account: ICPProtocol_1.ICP_ACCOUNT_METADATA, transaction: ICRC1_TRANSACTION_METADATA() }]);
|
|
328
|
-
_c.label = 2;
|
|
329
|
-
case 2: return [2 /*return*/, this._metadata];
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
ICRC1OnlineProtocolImpl.prototype.getPartialMetadata = function () {
|
|
335
|
-
var _a, _b;
|
|
336
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
-
var mainUnit, icrc1Metadata, _c, name, symbol, decimals, feeDefaults, fetchedUnits;
|
|
338
|
-
var _d;
|
|
339
|
-
return __generator(this, function (_e) {
|
|
340
|
-
switch (_e.label) {
|
|
341
|
-
case 0:
|
|
342
|
-
mainUnit = (_a = this.options.mainUnit) !== null && _a !== void 0 ? _a : (this.options.units ? Object.keys(this.options.units)[0] : undefined);
|
|
343
|
-
if (this.options.name && this.options.units && mainUnit) {
|
|
344
|
-
return [2 /*return*/, {
|
|
345
|
-
name: this.options.name,
|
|
346
|
-
units: this.options.units,
|
|
347
|
-
mainUnit: mainUnit,
|
|
348
|
-
fee: {
|
|
349
|
-
defaults: this.options.feeDefaults,
|
|
350
|
-
units: this.options.units,
|
|
351
|
-
mainUnit: mainUnit
|
|
352
|
-
}
|
|
353
|
-
}];
|
|
354
|
-
}
|
|
355
|
-
return [4 /*yield*/, this.metadata()];
|
|
356
|
-
case 1:
|
|
357
|
-
icrc1Metadata = _e.sent();
|
|
358
|
-
return [4 /*yield*/, Promise.all([
|
|
359
|
-
this.options.name ? Promise.resolve(this.options.name) : icrc1Metadata.name ? Promise.resolve(icrc1Metadata.name) : this.name(),
|
|
360
|
-
mainUnit
|
|
361
|
-
? Promise.resolve(mainUnit)
|
|
362
|
-
: (icrc1Metadata.symbol ? Promise.resolve(icrc1Metadata.symbol) : this.symbol()).then(function (symbol) { return symbol; }),
|
|
363
|
-
mainUnit && this.options.units
|
|
364
|
-
? Promise.resolve(this.options.units[mainUnit].decimals)
|
|
365
|
-
: icrc1Metadata.decimals
|
|
366
|
-
? Promise.resolve(icrc1Metadata.decimals)
|
|
367
|
-
: this.decimals(),
|
|
368
|
-
this.options.feeDefaults
|
|
369
|
-
? Promise.resolve(this.options.feeDefaults)
|
|
370
|
-
: (icrc1Metadata.fee ? Promise.resolve(icrc1Metadata.fee) : this.fee()).then(function (fee) { return ({
|
|
371
|
-
low: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
372
|
-
medium: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
373
|
-
high: (0, module_kit_1.newAmount)(fee, 'blockchain')
|
|
374
|
-
}); })
|
|
375
|
-
])];
|
|
376
|
-
case 2:
|
|
377
|
-
_c = __read.apply(void 0, [_e.sent(), 4]), name = _c[0], symbol = _c[1], decimals = _c[2], feeDefaults = _c[3];
|
|
378
|
-
fetchedUnits = (_d = {},
|
|
379
|
-
_d[symbol] = {
|
|
380
|
-
symbol: { value: symbol },
|
|
381
|
-
decimals: decimals
|
|
382
|
-
},
|
|
383
|
-
_d);
|
|
384
|
-
return [2 /*return*/, {
|
|
385
|
-
name: name,
|
|
386
|
-
units: (_b = this.options.units) !== null && _b !== void 0 ? _b : fetchedUnits,
|
|
387
|
-
mainUnit: symbol,
|
|
388
|
-
fee: {
|
|
389
|
-
defaults: feeDefaults
|
|
390
|
-
}
|
|
391
|
-
}];
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
ICRC1OnlineProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
397
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
-
return __generator(this, function (_a) {
|
|
399
|
-
return [2 /*return*/, this.commonImpl.getAddressFromPublicKey(publicKey)];
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
};
|
|
403
|
-
ICRC1OnlineProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
|
|
404
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
405
|
-
var fee;
|
|
406
|
-
return __generator(this, function (_a) {
|
|
407
|
-
switch (_a.label) {
|
|
408
|
-
case 0: return [4 /*yield*/, this.fee()];
|
|
409
|
-
case 1:
|
|
410
|
-
fee = _a.sent();
|
|
411
|
-
return [2 /*return*/, this.commonImpl.getDetailsFromTransaction(transaction, publicKey, this.options.network, (0, module_kit_1.newAmount)(fee, 'blockchain'))];
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
};
|
|
416
|
-
// Online
|
|
417
|
-
ICRC1OnlineProtocolImpl.prototype.getNetwork = function () {
|
|
418
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
419
|
-
return __generator(this, function (_a) {
|
|
420
|
-
return [2 /*return*/, this.options.network];
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
};
|
|
424
|
-
ICRC1OnlineProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
425
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
426
|
-
var principal, balance;
|
|
427
|
-
return __generator(this, function (_a) {
|
|
428
|
-
switch (_a.label) {
|
|
429
|
-
case 0:
|
|
430
|
-
principal = (0, ICPImplementation_1.getPrincipalFromPublicKey)(publicKey.value);
|
|
431
|
-
return [4 /*yield*/, this.balanceOf({ owner: principal.toText() })];
|
|
432
|
-
case 1:
|
|
433
|
-
balance = _a.sent();
|
|
434
|
-
return [2 /*return*/, { total: (0, module_kit_1.newAmount)(balance, 'blockchain') }];
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
};
|
|
439
|
-
ICRC1OnlineProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
440
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
441
|
-
var balance, balanceBn, fee, feeEstimation, amountWithoutFees;
|
|
442
|
-
return __generator(this, function (_a) {
|
|
443
|
-
switch (_a.label) {
|
|
444
|
-
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
445
|
-
case 1:
|
|
446
|
-
balance = _a.sent();
|
|
447
|
-
balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).value);
|
|
448
|
-
if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 2];
|
|
449
|
-
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).value);
|
|
450
|
-
return [3 /*break*/, 4];
|
|
451
|
-
case 2: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, [])];
|
|
452
|
-
case 3:
|
|
453
|
-
feeEstimation = _a.sent();
|
|
454
|
-
fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation).value);
|
|
455
|
-
if (fee.gte(balanceBn)) {
|
|
456
|
-
fee = new bignumber_1.default(0);
|
|
457
|
-
}
|
|
458
|
-
_a.label = 4;
|
|
459
|
-
case 4:
|
|
460
|
-
amountWithoutFees = balanceBn.minus(fee);
|
|
461
|
-
if (amountWithoutFees.isNegative()) {
|
|
462
|
-
amountWithoutFees = new bignumber_1.default(0);
|
|
463
|
-
}
|
|
464
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain')];
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
};
|
|
469
|
-
ICRC1OnlineProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details) {
|
|
470
|
-
var _a;
|
|
471
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
472
|
-
var metadata, fee;
|
|
473
|
-
return __generator(this, function (_b) {
|
|
474
|
-
switch (_b.label) {
|
|
475
|
-
case 0: return [4 /*yield*/, this.getMetadata()];
|
|
476
|
-
case 1:
|
|
477
|
-
metadata = _b.sent();
|
|
478
|
-
if ((_a = metadata.fee) === null || _a === void 0 ? void 0 : _a.defaults) {
|
|
479
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(metadata.fee.defaults.medium).blockchain(metadata.units)];
|
|
480
|
-
}
|
|
481
|
-
return [4 /*yield*/, this.fee()];
|
|
482
|
-
case 2:
|
|
483
|
-
fee = _b.sent();
|
|
484
|
-
return [2 /*return*/, (0, module_kit_1.newAmount)(fee, 'blockchain')];
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
};
|
|
489
|
-
ICRC1OnlineProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
490
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
491
|
-
return __generator(this, function (_a) {
|
|
492
|
-
throw new Error('Method not implemented.');
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
ICRC1OnlineProtocolImpl.prototype.broadcastTransaction = function (transaction) {
|
|
497
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
498
|
-
return __generator(this, function (_a) {
|
|
499
|
-
return [2 /*return*/, this.icp.broadcastTransaction(transaction)];
|
|
500
|
-
});
|
|
501
|
-
});
|
|
502
|
-
};
|
|
503
|
-
ICRC1OnlineProtocolImpl.prototype.name = function () {
|
|
504
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
-
var actor, name_1;
|
|
506
|
-
return __generator(this, function (_a) {
|
|
507
|
-
switch (_a.label) {
|
|
508
|
-
case 0:
|
|
509
|
-
if (!!this._name) return [3 /*break*/, 2];
|
|
510
|
-
actor = this.createActor();
|
|
511
|
-
return [4 /*yield*/, actor.icrc1_name()];
|
|
512
|
-
case 1:
|
|
513
|
-
name_1 = _a.sent();
|
|
514
|
-
this._name = name_1;
|
|
515
|
-
_a.label = 2;
|
|
516
|
-
case 2: return [2 /*return*/, this._name];
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
};
|
|
521
|
-
ICRC1OnlineProtocolImpl.prototype.symbol = function () {
|
|
522
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
523
|
-
var actor, symbol;
|
|
524
|
-
return __generator(this, function (_a) {
|
|
525
|
-
switch (_a.label) {
|
|
526
|
-
case 0:
|
|
527
|
-
if (!!this._symbol) return [3 /*break*/, 2];
|
|
528
|
-
actor = this.createActor();
|
|
529
|
-
return [4 /*yield*/, actor.icrc1_symbol()];
|
|
530
|
-
case 1:
|
|
531
|
-
symbol = _a.sent();
|
|
532
|
-
this._symbol = symbol;
|
|
533
|
-
_a.label = 2;
|
|
534
|
-
case 2: return [2 /*return*/, this._symbol];
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
ICRC1OnlineProtocolImpl.prototype.decimals = function () {
|
|
540
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
541
|
-
var actor, decimals;
|
|
542
|
-
return __generator(this, function (_a) {
|
|
543
|
-
switch (_a.label) {
|
|
544
|
-
case 0:
|
|
545
|
-
if (!!this._decimals) return [3 /*break*/, 2];
|
|
546
|
-
actor = this.createActor();
|
|
547
|
-
return [4 /*yield*/, actor.icrc1_decimals()];
|
|
548
|
-
case 1:
|
|
549
|
-
decimals = _a.sent();
|
|
550
|
-
this._decimals = decimals;
|
|
551
|
-
_a.label = 2;
|
|
552
|
-
case 2: return [2 /*return*/, this._decimals];
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
};
|
|
557
|
-
ICRC1OnlineProtocolImpl.prototype.fee = function () {
|
|
558
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
559
|
-
var actor, fee;
|
|
560
|
-
return __generator(this, function (_a) {
|
|
561
|
-
switch (_a.label) {
|
|
562
|
-
case 0:
|
|
563
|
-
if (!!this._fee) return [3 /*break*/, 2];
|
|
564
|
-
actor = this.createActor();
|
|
565
|
-
return [4 /*yield*/, actor.icrc1_fee()];
|
|
566
|
-
case 1:
|
|
567
|
-
fee = _a.sent();
|
|
568
|
-
this._fee = fee.toString();
|
|
569
|
-
_a.label = 2;
|
|
570
|
-
case 2: return [2 /*return*/, this._fee];
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
};
|
|
575
|
-
ICRC1OnlineProtocolImpl.prototype.baseMetadata = function () {
|
|
576
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
577
|
-
var actor, metadata;
|
|
578
|
-
return __generator(this, function (_a) {
|
|
579
|
-
switch (_a.label) {
|
|
580
|
-
case 0:
|
|
581
|
-
if (!!this._baseMetadata) return [3 /*break*/, 2];
|
|
582
|
-
actor = this.createActor();
|
|
583
|
-
return [4 /*yield*/, actor.icrc1_metadata()];
|
|
584
|
-
case 1:
|
|
585
|
-
metadata = _a.sent();
|
|
586
|
-
this._baseMetadata = (0, icrc1_1.decodeICRC1Metadata)(metadata);
|
|
587
|
-
_a.label = 2;
|
|
588
|
-
case 2: return [2 /*return*/, this._baseMetadata];
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
});
|
|
592
|
-
};
|
|
593
|
-
ICRC1OnlineProtocolImpl.prototype.totalSupply = function () {
|
|
594
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
595
|
-
var actor, totalSupply;
|
|
596
|
-
return __generator(this, function (_a) {
|
|
597
|
-
switch (_a.label) {
|
|
598
|
-
case 0:
|
|
599
|
-
if (!!this._totalSupply) return [3 /*break*/, 2];
|
|
600
|
-
actor = this.createActor();
|
|
601
|
-
return [4 /*yield*/, actor.icrc1_total_supply()];
|
|
602
|
-
case 1:
|
|
603
|
-
totalSupply = _a.sent();
|
|
604
|
-
this._totalSupply = totalSupply.toString();
|
|
605
|
-
_a.label = 2;
|
|
606
|
-
case 2: return [2 /*return*/, this._totalSupply];
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
};
|
|
611
|
-
ICRC1OnlineProtocolImpl.prototype.mintingAccount = function () {
|
|
612
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
613
|
-
var actor, mintingAccount;
|
|
614
|
-
return __generator(this, function (_a) {
|
|
615
|
-
switch (_a.label) {
|
|
616
|
-
case 0:
|
|
617
|
-
if (!(this._mintingAccount === null)) return [3 /*break*/, 2];
|
|
618
|
-
actor = this.createActor();
|
|
619
|
-
return [4 /*yield*/, actor.icrc1_minting_account()];
|
|
620
|
-
case 1:
|
|
621
|
-
mintingAccount = _a.sent();
|
|
622
|
-
this._mintingAccount = (0, icrc1_1.decodeOptionalICRC1Account)(mintingAccount);
|
|
623
|
-
_a.label = 2;
|
|
624
|
-
case 2: return [2 /*return*/, this._mintingAccount];
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
};
|
|
629
|
-
ICRC1OnlineProtocolImpl.prototype.balanceOf = function (account) {
|
|
630
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
631
|
-
var actor, balance;
|
|
632
|
-
return __generator(this, function (_a) {
|
|
633
|
-
switch (_a.label) {
|
|
634
|
-
case 0:
|
|
635
|
-
actor = this.createActor();
|
|
636
|
-
return [4 /*yield*/, actor.icrc1_balance_of((0, icrc1_1.encodeICRC1Account)(account))];
|
|
637
|
-
case 1:
|
|
638
|
-
balance = _a.sent();
|
|
639
|
-
return [2 /*return*/, balance];
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
});
|
|
643
|
-
};
|
|
644
|
-
ICRC1OnlineProtocolImpl.prototype.transfer = function (privateKey, args) {
|
|
645
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
646
|
-
var actor, result;
|
|
647
|
-
return __generator(this, function (_a) {
|
|
648
|
-
switch (_a.label) {
|
|
649
|
-
case 0:
|
|
650
|
-
actor = this.createActor(ledger_1.icrcIDLFactory, secp256k1_1.default.fromSecretKey((0, convert_1.hexStringToArrayBuffer)(privateKey)));
|
|
651
|
-
return [4 /*yield*/, actor.icrc1_transfer({
|
|
652
|
-
to: (0, icrc1_1.encodeICRC1Account)(args.to),
|
|
653
|
-
fee: args.fee ? [BigInt(args.fee)] : [],
|
|
654
|
-
memo: args.memo ? [Buffer.from(args.memo)] : [],
|
|
655
|
-
from_subaccount: args.fromSubaccount ? [Buffer.from(args.fromSubaccount)] : [],
|
|
656
|
-
created_at_time: args.createdAtTime ? [BigInt(args.createdAtTime)] : [],
|
|
657
|
-
amount: BigInt(args.amount)
|
|
658
|
-
})];
|
|
659
|
-
case 1:
|
|
660
|
-
result = _a.sent();
|
|
661
|
-
if (result.Ok) {
|
|
662
|
-
return [2 /*return*/, result.Ok.toString()];
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
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, ")"));
|
|
666
|
-
}
|
|
667
|
-
return [2 /*return*/];
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
};
|
|
672
|
-
ICRC1OnlineProtocolImpl.prototype.createActor = function (idlFactory, identity) {
|
|
673
|
-
if (idlFactory === void 0) { idlFactory = ledger_1.icrcIDLFactory; }
|
|
674
|
-
if (identity === void 0) { identity = new auth_1.AnonymousIdentity(); }
|
|
675
|
-
var agent = (0, ICPImplementation_1.createHttpAgent)(this.options.network.rpcUrl, identity);
|
|
676
|
-
return actor_1.Actor.createActor(idlFactory, {
|
|
677
|
-
agent: agent,
|
|
678
|
-
canisterId: this.options.network.canisterId
|
|
679
|
-
});
|
|
680
|
-
};
|
|
681
|
-
return ICRC1OnlineProtocolImpl;
|
|
682
|
-
}());
|
|
683
|
-
exports.ICRC1OnlineProtocolImpl = ICRC1OnlineProtocolImpl;
|
|
684
|
-
//# sourceMappingURL=ICRC1Protocol.js.map
|