@airgap/icp 0.13.9-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.
Files changed (117) hide show
  1. package/LICENSE.md +7 -0
  2. package/airgap-coinlib-icp.min.js +91766 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +18 -0
  5. package/index.js.map +1 -0
  6. package/package.json +71 -0
  7. package/readme.md +121 -0
  8. package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
  9. package/v1/block-explorer/ICPBlockExplorer.js +74 -0
  10. package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
  11. package/v1/index.d.ts +12 -0
  12. package/v1/index.js +11 -0
  13. package/v1/index.js.map +1 -0
  14. package/v1/module/ICPModule.d.ts +15 -0
  15. package/v1/module/ICPModule.js +107 -0
  16. package/v1/module/ICPModule.js.map +1 -0
  17. package/v1/protocol/ICPImplementation.d.ts +26 -0
  18. package/v1/protocol/ICPImplementation.js +334 -0
  19. package/v1/protocol/ICPImplementation.js.map +1 -0
  20. package/v1/protocol/ICPProtocol.d.ts +38 -0
  21. package/v1/protocol/ICPProtocol.js +414 -0
  22. package/v1/protocol/ICPProtocol.js.map +1 -0
  23. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
  24. package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
  25. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  26. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
  27. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
  28. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
  29. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
  30. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
  31. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
  32. package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
  33. package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
  34. package/v1/serializer/v3/serializer-companion.d.ts +14 -0
  35. package/v1/serializer/v3/serializer-companion.js +174 -0
  36. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  37. package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
  38. package/v1/serializer/v3/validators/transaction-validator.js +100 -0
  39. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  40. package/v1/serializer/v3/validators/validators.d.ts +5 -0
  41. package/v1/serializer/v3/validators/validators.js +106 -0
  42. package/v1/serializer/v3/validators/validators.js.map +1 -0
  43. package/v1/types/governance.d.ts +580 -0
  44. package/v1/types/governance.js +796 -0
  45. package/v1/types/governance.js.map +1 -0
  46. package/v1/types/ledger.d.ts +143 -0
  47. package/v1/types/ledger.js +146 -0
  48. package/v1/types/ledger.js.map +1 -0
  49. package/v1/types/management_idl.d.ts +7 -0
  50. package/v1/types/management_idl.js +72 -0
  51. package/v1/types/management_idl.js.map +1 -0
  52. package/v1/types/protocol.d.ts +8 -0
  53. package/v1/types/protocol.js +3 -0
  54. package/v1/types/protocol.js.map +1 -0
  55. package/v1/types/transaction.d.ts +11 -0
  56. package/v1/types/transaction.js +3 -0
  57. package/v1/types/transaction.js.map +1 -0
  58. package/v1/utils/account.d.ts +24 -0
  59. package/v1/utils/account.js +112 -0
  60. package/v1/utils/account.js.map +1 -0
  61. package/v1/utils/actor.d.ts +246 -0
  62. package/v1/utils/actor.js +458 -0
  63. package/v1/utils/actor.js.map +1 -0
  64. package/v1/utils/agent.d.ts +156 -0
  65. package/v1/utils/agent.js +16 -0
  66. package/v1/utils/agent.js.map +1 -0
  67. package/v1/utils/auth.d.ts +110 -0
  68. package/v1/utils/auth.js +261 -0
  69. package/v1/utils/auth.js.map +1 -0
  70. package/v1/utils/bls.d.ts +38 -0
  71. package/v1/utils/bls.js +204 -0
  72. package/v1/utils/bls.js.map +1 -0
  73. package/v1/utils/buffer.d.ts +70 -0
  74. package/v1/utils/buffer.js +216 -0
  75. package/v1/utils/buffer.js.map +1 -0
  76. package/v1/utils/cbor.d.ts +9 -0
  77. package/v1/utils/cbor.js +178 -0
  78. package/v1/utils/cbor.js.map +1 -0
  79. package/v1/utils/certificate.d.ts +74 -0
  80. package/v1/utils/certificate.js +396 -0
  81. package/v1/utils/certificate.js.map +1 -0
  82. package/v1/utils/convert.d.ts +8 -0
  83. package/v1/utils/convert.js +80 -0
  84. package/v1/utils/convert.js.map +1 -0
  85. package/v1/utils/crypto.d.ts +0 -0
  86. package/v1/utils/crypto.js +104 -0
  87. package/v1/utils/crypto.js.map +1 -0
  88. package/v1/utils/der.d.ts +35 -0
  89. package/v1/utils/der.js +176 -0
  90. package/v1/utils/der.js.map +1 -0
  91. package/v1/utils/errors.d.ts +7 -0
  92. package/v1/utils/errors.js +38 -0
  93. package/v1/utils/errors.js.map +1 -0
  94. package/v1/utils/hdkey.d.ts +13 -0
  95. package/v1/utils/hdkey.js +242 -0
  96. package/v1/utils/hdkey.js.map +1 -0
  97. package/v1/utils/http.d.ts +284 -0
  98. package/v1/utils/http.js +614 -0
  99. package/v1/utils/http.js.map +1 -0
  100. package/v1/utils/idl.d.ts +515 -0
  101. package/v1/utils/idl.js +2103 -0
  102. package/v1/utils/idl.js.map +1 -0
  103. package/v1/utils/leb128.d.ts +63 -0
  104. package/v1/utils/leb128.js +224 -0
  105. package/v1/utils/leb128.js.map +1 -0
  106. package/v1/utils/polling.d.ts +59 -0
  107. package/v1/utils/polling.js +325 -0
  108. package/v1/utils/polling.js.map +1 -0
  109. package/v1/utils/principal.d.ts +58 -0
  110. package/v1/utils/principal.js +543 -0
  111. package/v1/utils/principal.js.map +1 -0
  112. package/v1/utils/secp256k1.d.ts +79 -0
  113. package/v1/utils/secp256k1.js +253 -0
  114. package/v1/utils/secp256k1.js.map +1 -0
  115. package/v1/utils/transaction.d.ts +3 -0
  116. package/v1/utils/transaction.js +56 -0
  117. package/v1/utils/transaction.js.map +1 -0
@@ -0,0 +1,334 @@
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
89
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
90
+ if (ar || !(i in from)) {
91
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
92
+ ar[i] = from[i];
93
+ }
94
+ }
95
+ return to.concat(ar || Array.prototype.slice.call(from));
96
+ };
97
+ var __importDefault = (this && this.__importDefault) || function (mod) {
98
+ return (mod && mod.__esModule) ? mod : { "default": mod };
99
+ };
100
+ Object.defineProperty(exports, "__esModule", { value: true });
101
+ exports.broadcastTransaction = exports.getBalanceFromAddress = exports.decodeArguments = exports.getInfoFromSignedTransaction = exports.signTransaction = exports.getInfoFromUnsignedTransaction = exports.createUnsignedTransaction = exports.getAddressFromPublicKey = exports.getKeyPairFromMnemonic = void 0;
102
+ require("isomorphic-fetch");
103
+ var convert_1 = require("../utils/convert");
104
+ var js_sha256_1 = require("js-sha256");
105
+ var ledger_1 = require("../types/ledger");
106
+ var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
107
+ var IDL = __importStar(require("../utils/idl"));
108
+ var principal_1 = require("../utils/principal");
109
+ var secp256k1_1 = __importDefault(require("../utils/secp256k1"));
110
+ var http_1 = require("../utils/http");
111
+ var account_1 = require("../utils/account");
112
+ var auth_1 = require("../utils/auth");
113
+ var actor_1 = require("../utils/actor");
114
+ var Cbor = __importStar(require("../utils/cbor"));
115
+ // MNEMONIC -> KEY PAIR
116
+ function getKeyPairFromMnemonic(mnemonic) {
117
+ var identity = secp256k1_1.default.fromSeedPhrase(mnemonic);
118
+ var publicKey = new Uint8Array(identity.getPublicKey().toDer());
119
+ var privateKey = new Uint8Array(identity.getKeyPair().secretKey);
120
+ return {
121
+ publicKey: (0, convert_1.uint8ArrayToHexString)(publicKey),
122
+ privateKey: (0, convert_1.uint8ArrayToHexString)(privateKey)
123
+ };
124
+ }
125
+ exports.getKeyPairFromMnemonic = getKeyPairFromMnemonic;
126
+ // PUBLIC KEY -> ADDRESS
127
+ function getAddressFromPublicKey(publicKey, subAccount) {
128
+ // Get principal from public key
129
+ var principal = principal_1.Principal.selfAuthenticating((0, convert_1.hexStringToUint8Array)(publicKey));
130
+ // Hash (sha224) the principal, the subAccount and some padding
131
+ var padding = (0, convert_1.asciiStringToByteArray)('\x0Aaccount-id');
132
+ var shaObj = js_sha256_1.sha224.create();
133
+ shaObj.update(__spreadArray(__spreadArray(__spreadArray([], __read(padding), false), __read(principal.toUint8Array()), false), __read((subAccount !== null && subAccount !== void 0 ? subAccount : Array(32).fill(0))), false));
134
+ var hash = new Uint8Array(shaObj.array());
135
+ // Prepend the checksum of the hash and convert to a hex string
136
+ var checksum = (0, convert_1.calculateCrc32)(hash);
137
+ var bytes = new Uint8Array(__spreadArray(__spreadArray([], __read(checksum), false), __read(hash), false));
138
+ return (0, convert_1.uint8ArrayToHexString)(bytes);
139
+ }
140
+ exports.getAddressFromPublicKey = getAddressFromPublicKey;
141
+ // TRANSACTION OBJECT -> UNSIGNED TRANSACTION HEX
142
+ function createUnsignedTransaction(transaction) {
143
+ var to = account_1.AccountIdentifier.fromHex(transaction.to);
144
+ // Create raw request body
145
+ var rawRequestBody = {
146
+ to: to.toNumbers(),
147
+ fee: (0, convert_1.e8sToTokens)(transaction.fee),
148
+ amount: (0, convert_1.e8sToTokens)(transaction.amount),
149
+ // Always explicitly set the memo for compatibility with ledger wallet - hardware wallet
150
+ memo: BigInt(0),
151
+ created_at_time: [],
152
+ from_subaccount: []
153
+ };
154
+ // Encode raw request
155
+ //@ts-ignore
156
+ var unsignedTransaction = IDL.encode(ledger_1.TransferFn.argTypes, [rawRequestBody]);
157
+ return (0, convert_1.arrayBufferToHexString)(unsignedTransaction);
158
+ }
159
+ exports.createUnsignedTransaction = createUnsignedTransaction;
160
+ // UNSIGNED TRANSACTION -> TRANSACTION DETAILS
161
+ function getInfoFromUnsignedTransaction(unsignedTransaction) {
162
+ //@ts-ignore
163
+ var transaction = IDL.decode(ledger_1.TransferFn.argTypes, Buffer.from(unsignedTransaction, 'hex'))[0];
164
+ return {
165
+ to: (0, convert_1.uint8ArrayToHexString)(transaction.to),
166
+ fee: transaction.fee.e8s,
167
+ memo: transaction.memo,
168
+ from_subaccount: transaction.from_subaccount,
169
+ created_at_time: transaction.created_at_time,
170
+ amount: transaction.amount.e8s
171
+ };
172
+ }
173
+ exports.getInfoFromUnsignedTransaction = getInfoFromUnsignedTransaction;
174
+ // UNSIGNED TRANSACTION, PRIVATE KEY -> SIGNED TRANSACTION
175
+ function signTransaction(unsignedTransaction, privateKey) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var identity, transactionDetails, Address, ICP, Memo, SubAccount, TimeStamp, TransferArgs, DEFAULT_TRANSACTION_FEE, toTransferRawRequest, rawRequestBody, args, submit, transform, request, transformedRequest, encoded;
178
+ var _this = this;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ identity = secp256k1_1.default.fromSecretKey((0, convert_1.hexStringToArrayBuffer)(privateKey));
183
+ transactionDetails = getInfoFromUnsignedTransaction(unsignedTransaction);
184
+ Address = IDL.Vec(IDL.Nat8);
185
+ ICP = IDL.Record({ e8s: IDL.Nat64 });
186
+ Memo = IDL.Nat64;
187
+ SubAccount = IDL.Vec(IDL.Nat8);
188
+ TimeStamp = IDL.Record({ timestamp_nanos: IDL.Nat64 });
189
+ TransferArgs = IDL.Record({
190
+ to: Address,
191
+ fee: ICP,
192
+ memo: Memo,
193
+ from_subaccount: IDL.Opt(SubAccount),
194
+ created_at_time: IDL.Opt(TimeStamp),
195
+ amount: ICP
196
+ });
197
+ DEFAULT_TRANSACTION_FEE = BigInt(10000);
198
+ toTransferRawRequest = function (_a) {
199
+ var to = _a.to, amount = _a.amount, memo = _a.memo, fee = _a.fee, fromSubAccount = _a.fromSubAccount;
200
+ return {
201
+ to: to.toNumbers(),
202
+ fee: (0, convert_1.e8sToTokens)(fee !== null && fee !== void 0 ? fee : DEFAULT_TRANSACTION_FEE),
203
+ amount: (0, convert_1.e8sToTokens)(amount),
204
+ // Always explicitly set the memo for compatibility with ledger wallet - hardware wallet
205
+ memo: memo !== null && memo !== void 0 ? memo : BigInt(0),
206
+ created_at_time: [],
207
+ from_subaccount: fromSubAccount === undefined ? [] : [fromSubAccount]
208
+ };
209
+ };
210
+ rawRequestBody = toTransferRawRequest(__assign(__assign({}, transactionDetails), { to: account_1.AccountIdentifier.fromHex(transactionDetails.to) }));
211
+ args = IDL.encode([TransferArgs], [rawRequestBody]);
212
+ submit = {
213
+ request_type: http_1.SubmitRequestType.Call,
214
+ //@ts-ignore
215
+ canister_id: principal_1.Principal.from(ledger_1.canisterId),
216
+ method_name: 'transfer',
217
+ arg: args,
218
+ //@ts-ignore
219
+ sender: identity.getPrincipal(),
220
+ ingress_expiry: new http_1.Expiry(5 * 60 * 1000)
221
+ };
222
+ transform = function (request) { return __awaiter(_this, void 0, void 0, function () {
223
+ var p;
224
+ return __generator(this, function (_a) {
225
+ p = Promise.resolve(request);
226
+ return [2 /*return*/, p];
227
+ });
228
+ }); };
229
+ return [4 /*yield*/, transform({
230
+ request: {
231
+ body: null,
232
+ method: 'POST',
233
+ headers: {
234
+ 'Content-Type': 'application/cbor'
235
+ }
236
+ },
237
+ endpoint: "call" /* Endpoint.Call */,
238
+ body: submit
239
+ })];
240
+ case 1:
241
+ request = (_a.sent());
242
+ return [4 /*yield*/, identity.transformRequest(request)];
243
+ case 2:
244
+ transformedRequest = (_a.sent());
245
+ encoded = Cbor.encode(transformedRequest.body);
246
+ return [2 /*return*/, (0, convert_1.arrayBufferToHexString)(encoded)];
247
+ }
248
+ });
249
+ });
250
+ }
251
+ exports.signTransaction = signTransaction;
252
+ // SIGNED TRANSACTION -> TRANSACTION DETAILS
253
+ function getInfoFromSignedTransaction(signedTransaction) {
254
+ return Cbor.decode((0, convert_1.hexStringToArrayBuffer)(signedTransaction));
255
+ }
256
+ exports.getInfoFromSignedTransaction = getInfoFromSignedTransaction;
257
+ function decodeArguments(args) {
258
+ var Address = IDL.Vec(IDL.Nat8);
259
+ var ICP = IDL.Record({ e8s: IDL.Nat64 });
260
+ var Memo = IDL.Nat64;
261
+ var SubAccount = IDL.Vec(IDL.Nat8);
262
+ var TimeStamp = IDL.Record({ timestamp_nanos: IDL.Nat64 });
263
+ var TransferArgs = IDL.Record({
264
+ to: Address,
265
+ fee: ICP,
266
+ memo: Memo,
267
+ from_subaccount: IDL.Opt(SubAccount),
268
+ created_at_time: IDL.Opt(TimeStamp),
269
+ amount: ICP
270
+ });
271
+ return IDL.decode([TransferArgs], args);
272
+ }
273
+ exports.decodeArguments = decodeArguments;
274
+ // ADDRESS -> BALANCE
275
+ function getBalanceFromAddress(address, host) {
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var identity, agent, actor, acc, b;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0:
281
+ identity = secp256k1_1.default.generate();
282
+ agent = new http_1.HttpAgent({
283
+ identity: identity,
284
+ host: host
285
+ });
286
+ actor = actor_1.Actor.createActor(ledger_1.idlFactory, {
287
+ agent: agent,
288
+ canisterId: ledger_1.canisterId
289
+ });
290
+ acc = Uint8Array.from(Buffer.from(address, 'hex'));
291
+ return [4 /*yield*/, actor.account_balance({
292
+ account: __spreadArray([], __read(acc), false)
293
+ })];
294
+ case 1:
295
+ b = (_a.sent());
296
+ return [2 /*return*/, b.e8s];
297
+ }
298
+ });
299
+ });
300
+ }
301
+ exports.getBalanceFromAddress = getBalanceFromAddress;
302
+ function broadcastTransaction(signedTransaction, host) {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var canister, body, signedTransactionInfo, request, submit, error_1;
305
+ return __generator(this, function (_a) {
306
+ switch (_a.label) {
307
+ case 0:
308
+ canister = principal_1.Principal.from(ledger_1.canisterId);
309
+ body = (0, convert_1.hexStringToArrayBuffer)(signedTransaction);
310
+ signedTransactionInfo = getInfoFromSignedTransaction(signedTransaction);
311
+ _a.label = 1;
312
+ case 1:
313
+ _a.trys.push([1, 3, , 4]);
314
+ request = index_1.default.post('' + new URL("/api/v2/canister/".concat(canister.toText(), "/call"), host), body, {
315
+ headers: {
316
+ 'Content-Type': 'application/cbor'
317
+ }
318
+ });
319
+ submit = __assign(__assign({}, signedTransactionInfo.content), { ingress_expiry: new http_1.Expiry(1000) });
320
+ return [4 /*yield*/, Promise.all([request, (0, auth_1.requestIdOf)(submit)])];
321
+ case 2:
322
+ _a.sent();
323
+ return [2 /*return*/, ''];
324
+ case 3:
325
+ error_1 = _a.sent();
326
+ console.error('Error: ', error_1);
327
+ return [2 /*return*/, ''];
328
+ case 4: return [2 /*return*/];
329
+ }
330
+ });
331
+ });
332
+ }
333
+ exports.broadcastTransaction = broadcastTransaction;
334
+ //# sourceMappingURL=ICPImplementation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICPImplementation.js","sourceRoot":"","sources":["../../../src/v1/protocol/ICPImplementation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAAyB;AAEzB,4CAQyB;AACzB,uCAAkC;AAClC,0CAA4G;AAC5G,mGAA4E;AAC5E,gDAAmC;AACnC,gDAA8C;AAC9C,iEAAqD;AACrD,sCASsB;AACtB,4CAAoD;AACpD,sCAA2C;AAC3C,wCAAsC;AACtC,kDAAqC;AAQrC,uBAAuB;AACvB,SAAgB,sBAAsB,CAAC,QAAgB;IACrD,IAAM,QAAQ,GAAG,mBAAoB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IAE9D,IAAM,SAAS,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,C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C,CAAA;oBAC/B,sBAAO,EAAE,EAAA;;;;;CAEZ;AAzBD,oDAyBC"}
@@ -0,0 +1,38 @@
1
+ import { Address, AirGapProtocol, AirGapTransaction, AirGapTransactionsWithCursor, Amount, Balance, FeeDefaults, KeyPair, ProtocolMetadata, PublicKey, RecursivePartial, Secret, SecretKey, TransactionConfiguration, TransactionDetails } from '@airgap/module-kit';
2
+ import { ICPProtocolNetwork, ICPProtocolOptions, ICPUnits } from '../types/protocol';
3
+ import { ICPSignedTransaction, ICPTransactionCursor, ICPUnsignedTransaction } from '../types/transaction';
4
+ export interface ICPProtocol extends AirGapProtocol<{
5
+ AddressResult: Address;
6
+ ProtocolNetwork: ICPProtocolNetwork;
7
+ SignedTransaction: ICPSignedTransaction;
8
+ TransactionCursor: ICPTransactionCursor;
9
+ Units: ICPUnits;
10
+ FeeEstimation: FeeDefaults<ICPUnits>;
11
+ UnsignedTransaction: ICPUnsignedTransaction;
12
+ }, 'FetchDataForAddress'> {
13
+ }
14
+ export declare class ICPProtocolImpl implements ICPProtocol {
15
+ private readonly options;
16
+ constructor(options?: RecursivePartial<ICPProtocolOptions>);
17
+ private readonly units;
18
+ private readonly feeDefaults;
19
+ private readonly metadata;
20
+ getMetadata(): Promise<ProtocolMetadata<ICPUnits>>;
21
+ getAddressFromPublicKey(publicKey: PublicKey): Promise<string>;
22
+ getDetailsFromTransaction(transaction: ICPSignedTransaction | ICPUnsignedTransaction, _publicKey: PublicKey): Promise<AirGapTransaction<ICPUnits>[]>;
23
+ getKeyPairFromSecret(secret: Secret, derivationPath?: string): Promise<KeyPair>;
24
+ signTransactionWithSecretKey(transaction: ICPUnsignedTransaction, secretKey: SecretKey): Promise<ICPSignedTransaction>;
25
+ getNetwork(): Promise<ICPProtocolNetwork>;
26
+ getTransactionsForPublicKey(publicKey: PublicKey, limit: number, cursor?: ICPTransactionCursor): Promise<AirGapTransactionsWithCursor<ICPTransactionCursor, ICPUnits>>;
27
+ getTransactionsForAddress(address: string, limit: number, cursor?: ICPTransactionCursor): Promise<AirGapTransactionsWithCursor<ICPTransactionCursor, ICPUnits>>;
28
+ getBalanceOfPublicKey(publicKey: PublicKey): Promise<Balance<ICPUnits>>;
29
+ getBalanceOfAddress(address: string): Promise<Balance<ICPUnits>>;
30
+ getTransactionMaxAmountWithPublicKey(publicKey: PublicKey, to: string[], configuration?: TransactionConfiguration<ICPUnits>): Promise<Amount<ICPUnits>>;
31
+ getTransactionFeeWithPublicKey(_publicKey: PublicKey, _details: TransactionDetails<ICPUnits>[]): Promise<FeeDefaults<ICPUnits>>;
32
+ prepareTransactionWithPublicKey(publicKey: PublicKey, details: TransactionDetails<ICPUnits>[], configuration?: TransactionConfiguration<ICPUnits>): Promise<ICPUnsignedTransaction>;
33
+ private networkId;
34
+ broadcastTransaction(transaction: ICPSignedTransaction): Promise<string>;
35
+ }
36
+ export declare function createICPProtocol(options?: RecursivePartial<ICPProtocolOptions>): ICPProtocol;
37
+ export declare const ICP_MAINNET_PROTOCOL_NETWORK: ICPProtocolNetwork;
38
+ export declare function createICPProtocolOptions(network?: Partial<ICPProtocolNetwork>): ICPProtocolOptions;