@airgap/icp 0.13.10 → 0.13.11-beta.1
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 +17 -15
- package/airgap-coinlib-icp.min.js +0 -91775
- package/index.d.ts +0 -1
- package/index.js +0 -18
- package/index.js.map +0 -1
- package/v1/block-explorer/ICPBlockExplorer.d.ts +0 -9
- package/v1/block-explorer/ICPBlockExplorer.js +0 -74
- package/v1/block-explorer/ICPBlockExplorer.js.map +0 -1
- package/v1/index.d.ts +0 -12
- package/v1/index.js +0 -11
- package/v1/index.js.map +0 -1
- package/v1/module/ICPModule.d.ts +0 -15
- package/v1/module/ICPModule.js +0 -107
- package/v1/module/ICPModule.js.map +0 -1
- package/v1/protocol/ICPImplementation.d.ts +0 -26
- package/v1/protocol/ICPImplementation.js +0 -342
- package/v1/protocol/ICPImplementation.js.map +0 -1
- package/v1/protocol/ICPProtocol.d.ts +0 -38
- package/v1/protocol/ICPProtocol.js +0 -414
- package/v1/protocol/ICPProtocol.js.map +0 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +0 -7
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +0 -21
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +0 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +0 -4
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +0 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +0 -1
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +0 -32
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +0 -19
- package/v1/serializer/v3/serializer-companion.d.ts +0 -14
- package/v1/serializer/v3/serializer-companion.js +0 -174
- package/v1/serializer/v3/serializer-companion.js.map +0 -1
- package/v1/serializer/v3/validators/transaction-validator.d.ts +0 -10
- package/v1/serializer/v3/validators/transaction-validator.js +0 -100
- package/v1/serializer/v3/validators/transaction-validator.js.map +0 -1
- package/v1/serializer/v3/validators/validators.d.ts +0 -5
- package/v1/serializer/v3/validators/validators.js +0 -106
- package/v1/serializer/v3/validators/validators.js.map +0 -1
- package/v1/types/governance.d.ts +0 -580
- package/v1/types/governance.js +0 -796
- package/v1/types/governance.js.map +0 -1
- package/v1/types/ledger.d.ts +0 -143
- package/v1/types/ledger.js +0 -146
- package/v1/types/ledger.js.map +0 -1
- package/v1/types/management_idl.d.ts +0 -7
- package/v1/types/management_idl.js +0 -72
- package/v1/types/management_idl.js.map +0 -1
- package/v1/types/protocol.d.ts +0 -8
- package/v1/types/protocol.js +0 -3
- package/v1/types/protocol.js.map +0 -1
- package/v1/types/transaction.d.ts +0 -11
- package/v1/types/transaction.js +0 -3
- package/v1/types/transaction.js.map +0 -1
- package/v1/utils/account.d.ts +0 -24
- package/v1/utils/account.js +0 -112
- package/v1/utils/account.js.map +0 -1
- package/v1/utils/actor.d.ts +0 -246
- package/v1/utils/actor.js +0 -458
- package/v1/utils/actor.js.map +0 -1
- package/v1/utils/agent.d.ts +0 -156
- package/v1/utils/agent.js +0 -16
- package/v1/utils/agent.js.map +0 -1
- package/v1/utils/auth.d.ts +0 -110
- package/v1/utils/auth.js +0 -261
- package/v1/utils/auth.js.map +0 -1
- package/v1/utils/bls.d.ts +0 -38
- package/v1/utils/bls.js +0 -204
- package/v1/utils/bls.js.map +0 -1
- package/v1/utils/buffer.d.ts +0 -70
- package/v1/utils/buffer.js +0 -216
- package/v1/utils/buffer.js.map +0 -1
- package/v1/utils/cbor.d.ts +0 -9
- package/v1/utils/cbor.js +0 -178
- package/v1/utils/cbor.js.map +0 -1
- package/v1/utils/certificate.d.ts +0 -74
- package/v1/utils/certificate.js +0 -396
- package/v1/utils/certificate.js.map +0 -1
- package/v1/utils/convert.d.ts +0 -8
- package/v1/utils/convert.js +0 -80
- package/v1/utils/convert.js.map +0 -1
- package/v1/utils/crypto.d.ts +0 -0
- package/v1/utils/crypto.js +0 -104
- package/v1/utils/crypto.js.map +0 -1
- package/v1/utils/der.d.ts +0 -35
- package/v1/utils/der.js +0 -176
- package/v1/utils/der.js.map +0 -1
- package/v1/utils/errors.d.ts +0 -7
- package/v1/utils/errors.js +0 -38
- package/v1/utils/errors.js.map +0 -1
- package/v1/utils/hdkey.d.ts +0 -13
- package/v1/utils/hdkey.js +0 -242
- package/v1/utils/hdkey.js.map +0 -1
- package/v1/utils/http.d.ts +0 -284
- package/v1/utils/http.js +0 -614
- package/v1/utils/http.js.map +0 -1
- package/v1/utils/idl.d.ts +0 -515
- package/v1/utils/idl.js +0 -2103
- package/v1/utils/idl.js.map +0 -1
- package/v1/utils/leb128.d.ts +0 -63
- package/v1/utils/leb128.js +0 -224
- package/v1/utils/leb128.js.map +0 -1
- package/v1/utils/polling.d.ts +0 -59
- package/v1/utils/polling.js +0 -325
- package/v1/utils/polling.js.map +0 -1
- package/v1/utils/principal.d.ts +0 -58
- package/v1/utils/principal.js +0 -543
- package/v1/utils/principal.js.map +0 -1
- package/v1/utils/secp256k1.d.ts +0 -79
- package/v1/utils/secp256k1.js +0 -254
- package/v1/utils/secp256k1.js.map +0 -1
- package/v1/utils/transaction.d.ts +0 -3
- package/v1/utils/transaction.js +0 -56
- package/v1/utils/transaction.js.map +0 -1
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './v1';
|
package/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./v1"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAoB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AirGapBlockExplorer, BlockExplorerMetadata } from '@airgap/module-kit';
|
|
2
|
-
export declare class ICPBlockExplorer implements AirGapBlockExplorer {
|
|
3
|
-
readonly url: string;
|
|
4
|
-
constructor(url?: string);
|
|
5
|
-
private readonly metadata;
|
|
6
|
-
getMetadata(): Promise<BlockExplorerMetadata>;
|
|
7
|
-
createAddressUrl(address: string): Promise<string>;
|
|
8
|
-
createTransactionUrl(transactionId: string): Promise<string>;
|
|
9
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ICPBlockExplorer = void 0;
|
|
40
|
-
var BLOCK_EXPLORER_URL = 'https://dashboard.internetcomputer.org/';
|
|
41
|
-
var ICPBlockExplorer = /** @class */ (function () {
|
|
42
|
-
function ICPBlockExplorer(url) {
|
|
43
|
-
if (url === void 0) { url = BLOCK_EXPLORER_URL; }
|
|
44
|
-
this.url = url;
|
|
45
|
-
this.metadata = {
|
|
46
|
-
name: 'ICP Explorer',
|
|
47
|
-
url: this.url
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
ICPBlockExplorer.prototype.getMetadata = function () {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
return [2 /*return*/, this.metadata];
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
ICPBlockExplorer.prototype.createAddressUrl = function (address) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
return __generator(this, function (_a) {
|
|
60
|
-
return [2 /*return*/, "".concat(this.url, "/account/").concat(address)];
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
ICPBlockExplorer.prototype.createTransactionUrl = function (transactionId) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
return __generator(this, function (_a) {
|
|
67
|
-
return [2 /*return*/, "".concat(this.url, "/transaction/").concat(transactionId)];
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
return ICPBlockExplorer;
|
|
72
|
-
}());
|
|
73
|
-
exports.ICPBlockExplorer = ICPBlockExplorer;
|
|
74
|
-
//# sourceMappingURL=ICPBlockExplorer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ICPBlockExplorer.js","sourceRoot":"","sources":["../../../src/v1/block-explorer/ICPBlockExplorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,kBAAkB,GAAW,yCAAyC,CAAA;AAE5E;IACE,0BAAmC,GAAgC;QAAhC,oBAAA,EAAA,wBAAgC;QAAhC,QAAG,GAAH,GAAG,CAA6B;QAElD,aAAQ,GAA0B;YACjD,IAAI,EAAE,cAAc;YACpB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;IALqE,CAAC;IAO1D,sCAAW,GAAxB;;;gBACE,sBAAO,IAAI,CAAC,QAAQ,EAAA;;;KACrB;IAEY,2CAAgB,GAA7B,UAA8B,OAAe;;;gBAC3C,sBAAO,UAAG,IAAI,CAAC,GAAG,sBAAY,OAAO,CAAE,EAAA;;;KACxC;IACY,+CAAoB,GAAjC,UAAkC,aAAqB;;;gBACrD,sBAAO,UAAG,IAAI,CAAC,GAAG,0BAAgB,aAAa,CAAE,EAAA;;;KAClD;IACH,uBAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,4CAAgB"}
|
package/v1/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ICPBlockExplorer } from './block-explorer/ICPBlockExplorer';
|
|
2
|
-
import { ICPModule } from './module/ICPModule';
|
|
3
|
-
import { ICPProtocol, createICPProtocol, createICPProtocolOptions } from './protocol/ICPProtocol';
|
|
4
|
-
import { ICPTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-icp';
|
|
5
|
-
import { ICPTransactionSignResponse } from './serializer/v3/schemas/definitions/transaction-sign-response-icp';
|
|
6
|
-
import { ICPProtocolNetwork, ICPProtocolOptions, ICPUnits } from './types/protocol';
|
|
7
|
-
import { ICPSignedTransaction, ICPUnsignedTransaction } from './types/transaction';
|
|
8
|
-
export { ICPModule };
|
|
9
|
-
export { ICPProtocol, createICPProtocol, createICPProtocolOptions };
|
|
10
|
-
export { ICPBlockExplorer };
|
|
11
|
-
export { ICPUnits, ICPProtocolOptions, ICPProtocolNetwork, ICPUnsignedTransaction, ICPSignedTransaction };
|
|
12
|
-
export { ICPTransactionSignRequest, ICPTransactionSignResponse };
|
package/v1/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ICPBlockExplorer = exports.createICPProtocolOptions = exports.createICPProtocol = exports.ICPModule = void 0;
|
|
4
|
-
var ICPBlockExplorer_1 = require("./block-explorer/ICPBlockExplorer");
|
|
5
|
-
Object.defineProperty(exports, "ICPBlockExplorer", { enumerable: true, get: function () { return ICPBlockExplorer_1.ICPBlockExplorer; } });
|
|
6
|
-
var ICPModule_1 = require("./module/ICPModule");
|
|
7
|
-
Object.defineProperty(exports, "ICPModule", { enumerable: true, get: function () { return ICPModule_1.ICPModule; } });
|
|
8
|
-
var ICPProtocol_1 = require("./protocol/ICPProtocol");
|
|
9
|
-
Object.defineProperty(exports, "createICPProtocol", { enumerable: true, get: function () { return ICPProtocol_1.createICPProtocol; } });
|
|
10
|
-
Object.defineProperty(exports, "createICPProtocolOptions", { enumerable: true, get: function () { return ICPProtocol_1.createICPProtocolOptions; } });
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/v1/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,sEAAoE;AAkB3D,iGAlBA,mCAAgB,OAkBA;AAjBzB,gDAA8C;AASrC,0FATA,qBAAS,OASA;AARlB,sDAAiG;AAY3E,kGAZA,+BAAiB,OAYA;AAAE,yGAZA,sCAAwB,OAYA"}
|
package/v1/module/ICPModule.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MainProtocolSymbols } from '@airgap/coinlib-core';
|
|
2
|
-
import { AirGapBlockExplorer, AirGapModule, AirGapOfflineProtocol, AirGapOnlineProtocol, AirGapV3SerializerCompanion, ProtocolConfiguration } from '@airgap/module-kit';
|
|
3
|
-
declare type SupportedProtocols = MainProtocolSymbols.ICP;
|
|
4
|
-
export declare class ICPModule implements AirGapModule<{
|
|
5
|
-
Protocols: SupportedProtocols;
|
|
6
|
-
}> {
|
|
7
|
-
private readonly networkRegistries;
|
|
8
|
-
readonly supportedProtocols: Record<SupportedProtocols, ProtocolConfiguration>;
|
|
9
|
-
createV3SerializerCompanion(): Promise<AirGapV3SerializerCompanion>;
|
|
10
|
-
createOfflineProtocol(identifier: SupportedProtocols): Promise<AirGapOfflineProtocol | undefined>;
|
|
11
|
-
createOnlineProtocol(identifier: SupportedProtocols, networkId?: string): Promise<AirGapOnlineProtocol | undefined>;
|
|
12
|
-
createBlockExplorer(identifier: SupportedProtocols, networkId?: string): Promise<AirGapBlockExplorer | undefined>;
|
|
13
|
-
private createProtocol;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/v1/module/ICPModule.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ICPModule = void 0;
|
|
40
|
-
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
|
-
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
42
|
-
var module_kit_1 = require("@airgap/module-kit");
|
|
43
|
-
var ICPBlockExplorer_1 = require("../block-explorer/ICPBlockExplorer");
|
|
44
|
-
var ICPProtocol_1 = require("../protocol/ICPProtocol");
|
|
45
|
-
var serializer_companion_1 = require("../serializer/v3/serializer-companion");
|
|
46
|
-
var ICPModule = /** @class */ (function () {
|
|
47
|
-
function ICPModule() {
|
|
48
|
-
var _a;
|
|
49
|
-
this.networkRegistries = (_a = {},
|
|
50
|
-
_a[coinlib_core_1.MainProtocolSymbols.ICP] = new module_kit_1.ModuleNetworkRegistry({
|
|
51
|
-
supportedNetworks: [ICPProtocol_1.ICP_MAINNET_PROTOCOL_NETWORK]
|
|
52
|
-
}),
|
|
53
|
-
_a);
|
|
54
|
-
this.supportedProtocols = (0, module_kit_1.createSupportedProtocols)(this.networkRegistries);
|
|
55
|
-
}
|
|
56
|
-
ICPModule.prototype.createV3SerializerCompanion = function () {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
return __generator(this, function (_a) {
|
|
59
|
-
return [2 /*return*/, new serializer_companion_1.ICPV3SerializerCompanion()];
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
ICPModule.prototype.createOfflineProtocol = function (identifier) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
return [2 /*return*/, this.createProtocol(identifier)];
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
ICPModule.prototype.createOnlineProtocol = function (identifier, networkId) {
|
|
71
|
-
var _a;
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
var network;
|
|
74
|
-
return __generator(this, function (_b) {
|
|
75
|
-
network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
|
|
76
|
-
if (network === undefined) {
|
|
77
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Protocol network not supported.');
|
|
78
|
-
}
|
|
79
|
-
return [2 /*return*/, this.createProtocol(identifier, network)];
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
ICPModule.prototype.createBlockExplorer = function (identifier, networkId) {
|
|
84
|
-
var _a;
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var network;
|
|
87
|
-
return __generator(this, function (_b) {
|
|
88
|
-
network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
|
|
89
|
-
if ((network === null || network === void 0 ? void 0 : network.type) !== 'mainnet') {
|
|
90
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Block Explorer network not supported.');
|
|
91
|
-
}
|
|
92
|
-
return [2 /*return*/, new ICPBlockExplorer_1.ICPBlockExplorer()];
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
ICPModule.prototype.createProtocol = function (identifier, network) {
|
|
97
|
-
switch (identifier) {
|
|
98
|
-
case coinlib_core_1.MainProtocolSymbols.ICP:
|
|
99
|
-
return (0, ICPProtocol_1.createICPProtocol)({ network: network });
|
|
100
|
-
default:
|
|
101
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, "Protocol ".concat(identifier, " not supported."));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
return ICPModule;
|
|
105
|
-
}());
|
|
106
|
-
exports.ICPModule = ICPModule;
|
|
107
|
-
//# sourceMappingURL=ICPModule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ICPModule.js","sourceRoot":"","sources":["../../../src/v1/module/ICPModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkE;AAClE,sDAAqE;AACrE,iDAW2B;AAE3B,uEAAqE;AACrE,uDAAyF;AACzF,8EAAgF;AAIhF;IAAA;;QACmB,sBAAiB;YAChC,GAAC,kCAAmB,CAAC,GAAG,IAAG,IAAI,kCAAqB,CAAC;gBACnD,iBAAiB,EAAE,CAAC,0CAA4B,CAAC;aAClD,CAAC;gBACH;QACe,uBAAkB,GAAsD,IAAA,qCAAwB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAoC1I,CAAC;IAlCc,+CAA2B,GAAxC;;;gBACE,sBAAO,IAAI,+CAAwB,EAAE,EAAA;;;KACtC;IAEY,yCAAqB,GAAlC,UAAmC,UAA8B;;;gBAC/D,sBAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAA;;;KACvC;IAEY,wCAAoB,GAAjC,UAAkC,UAA8B,EAAE,SAAkB;;;;;gBAC5E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,OAAO,KAAK,SAAS,EAAE;oBACzB,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,iCAAiC,CAAC,CAAA;iBACjF;gBAED,sBAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,EAAA;;;KAChD;IAEY,uCAAmB,GAAhC,UAAiC,UAA8B,EAAE,SAAkB;;;;;gBAC3E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,uCAAuC,CAAC,CAAA;iBACvF;gBAED,sBAAO,IAAI,mCAAgB,EAAE,EAAA;;;KAC9B;IAEO,kCAAc,GAAtB,UAAuB,UAA8B,EAAE,OAAyB;QAC9E,QAAQ,UAAU,EAAE;YAClB,KAAK,kCAAmB,CAAC,GAAG;gBAC1B,OAAO,IAAA,+BAAiB,EAAC,EAAE,OAAO,SAAA,EAAE,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,GAAG,EAAE,mBAAY,UAAU,oBAAiB,CAAC,CAAA;SACzF;IACH,CAAC;IACH,gBAAC;AAAD,CAAC,AA1CD,IA0CC;AA1CY,8BAAS"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import 'isomorphic-fetch';
|
|
2
|
-
interface Transaction {
|
|
3
|
-
to: string;
|
|
4
|
-
amount: bigint;
|
|
5
|
-
fee: bigint;
|
|
6
|
-
}
|
|
7
|
-
export declare function getKeyPairFromMnemonic(mnemonic: string, derivationPath?: string): {
|
|
8
|
-
publicKey: string;
|
|
9
|
-
privateKey: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function getAddressFromPublicKey(publicKey: string, subAccount?: Uint8Array): string;
|
|
12
|
-
export declare function createUnsignedTransaction(transaction: Transaction): string;
|
|
13
|
-
export declare function getInfoFromUnsignedTransaction(unsignedTransaction: string): {
|
|
14
|
-
to: string;
|
|
15
|
-
fee: bigint;
|
|
16
|
-
memo: bigint;
|
|
17
|
-
from_subaccount: string[];
|
|
18
|
-
created_at_time: any[];
|
|
19
|
-
amount: bigint;
|
|
20
|
-
};
|
|
21
|
-
export declare function signTransaction(unsignedTransaction: string, privateKey: string): Promise<string>;
|
|
22
|
-
export declare function getInfoFromSignedTransaction(signedTransaction: string): any;
|
|
23
|
-
export declare function decodeArguments(args: ArrayBuffer): any;
|
|
24
|
-
export declare function getBalanceFromAddress(address: string, host: string): Promise<bigint>;
|
|
25
|
-
export declare function broadcastTransaction(signedTransaction: string, host: string): Promise<string>;
|
|
26
|
-
export {};
|
|
@@ -1,342 +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 __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
|
-
// import { requestIdOf } from '../utils/auth'
|
|
113
|
-
var actor_1 = require("../utils/actor");
|
|
114
|
-
var Cbor = __importStar(require("../utils/cbor"));
|
|
115
|
-
// MNEMONIC -> KEY PAIR
|
|
116
|
-
function getKeyPairFromMnemonic(mnemonic, derivationPath) {
|
|
117
|
-
var identity = secp256k1_1.default.fromSeedPhrase(mnemonic, undefined, derivationPath);
|
|
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, 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
|
-
_a.label = 1;
|
|
311
|
-
case 1:
|
|
312
|
-
_a.trys.push([1, 3, , 4]);
|
|
313
|
-
/*const request = */ return [4 /*yield*/, index_1.default.post('' + new URL("/api/v2/canister/".concat(canister.toText(), "/call"), host), body, {
|
|
314
|
-
headers: {
|
|
315
|
-
'Content-Type': 'application/cbor'
|
|
316
|
-
}
|
|
317
|
-
})
|
|
318
|
-
// const submit: CallRequest = {
|
|
319
|
-
// ...signedTransactionInfo.content,
|
|
320
|
-
// ingress_expiry: new Expiry(1000)
|
|
321
|
-
// }
|
|
322
|
-
// await Promise.all([request, requestIdOf(submit)])
|
|
323
|
-
];
|
|
324
|
-
case 2:
|
|
325
|
-
/*const request = */ _a.sent();
|
|
326
|
-
// const submit: CallRequest = {
|
|
327
|
-
// ...signedTransactionInfo.content,
|
|
328
|
-
// ingress_expiry: new Expiry(1000)
|
|
329
|
-
// }
|
|
330
|
-
// await Promise.all([request, requestIdOf(submit)])
|
|
331
|
-
return [2 /*return*/, ''];
|
|
332
|
-
case 3:
|
|
333
|
-
error_1 = _a.sent();
|
|
334
|
-
console.error('Error: ', error_1);
|
|
335
|
-
return [2 /*return*/, ''];
|
|
336
|
-
case 4: return [2 /*return*/];
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
exports.broadcastTransaction = broadcastTransaction;
|
|
342
|
-
//# sourceMappingURL=ICPImplementation.js.map
|