@airgap/icp 0.13.11-beta.1 → 0.13.11-beta.3
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/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +4 -8
- package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
- package/v1/block-explorer/ICPBlockExplorer.js +74 -0
- package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
- package/v1/index.d.ts +13 -0
- package/v1/index.js +11 -0
- package/v1/index.js.map +1 -0
- package/v1/module/ICPModule.d.ts +15 -0
- package/v1/module/ICPModule.js +107 -0
- package/v1/module/ICPModule.js.map +1 -0
- package/v1/module.d.ts +3 -0
- package/v1/module.js +24 -0
- package/v1/module.js.map +1 -0
- package/v1/protocol/ICPImplementation.d.ts +26 -0
- package/v1/protocol/ICPImplementation.js +344 -0
- package/v1/protocol/ICPImplementation.js.map +1 -0
- package/v1/protocol/ICPProtocol.d.ts +42 -0
- package/v1/protocol/ICPProtocol.js +416 -0
- package/v1/protocol/ICPProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +174 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
- package/v1/serializer/v3/validators/transaction-validator.js +100 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +5 -0
- package/v1/serializer/v3/validators/validators.js +106 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/governance.d.ts +580 -0
- package/v1/types/governance.js +796 -0
- package/v1/types/governance.js.map +1 -0
- package/v1/types/ledger.d.ts +143 -0
- package/v1/types/ledger.js +146 -0
- package/v1/types/ledger.js.map +1 -0
- package/v1/types/management_idl.d.ts +7 -0
- package/v1/types/management_idl.js +72 -0
- package/v1/types/management_idl.js.map +1 -0
- package/v1/types/protocol.d.ts +8 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +11 -0
- package/v1/types/transaction.js +3 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/account.d.ts +24 -0
- package/v1/utils/account.js +112 -0
- package/v1/utils/account.js.map +1 -0
- package/v1/utils/actor.d.ts +246 -0
- package/v1/utils/actor.js +458 -0
- package/v1/utils/actor.js.map +1 -0
- package/v1/utils/agent.d.ts +156 -0
- package/v1/utils/agent.js +16 -0
- package/v1/utils/agent.js.map +1 -0
- package/v1/utils/auth.d.ts +110 -0
- package/v1/utils/auth.js +261 -0
- package/v1/utils/auth.js.map +1 -0
- package/v1/utils/bls.d.ts +38 -0
- package/v1/utils/bls.js +204 -0
- package/v1/utils/bls.js.map +1 -0
- package/v1/utils/buffer.d.ts +70 -0
- package/v1/utils/buffer.js +216 -0
- package/v1/utils/buffer.js.map +1 -0
- package/v1/utils/cbor.d.ts +9 -0
- package/v1/utils/cbor.js +178 -0
- package/v1/utils/cbor.js.map +1 -0
- package/v1/utils/certificate.d.ts +74 -0
- package/v1/utils/certificate.js +396 -0
- package/v1/utils/certificate.js.map +1 -0
- package/v1/utils/convert.d.ts +8 -0
- package/v1/utils/convert.js +80 -0
- package/v1/utils/convert.js.map +1 -0
- package/v1/utils/crypto.d.ts +0 -0
- package/v1/utils/crypto.js +104 -0
- package/v1/utils/crypto.js.map +1 -0
- package/v1/utils/der.d.ts +35 -0
- package/v1/utils/der.js +176 -0
- package/v1/utils/der.js.map +1 -0
- package/v1/utils/errors.d.ts +7 -0
- package/v1/utils/errors.js +38 -0
- package/v1/utils/errors.js.map +1 -0
- package/v1/utils/hdkey.d.ts +13 -0
- package/v1/utils/hdkey.js +265 -0
- package/v1/utils/hdkey.js.map +1 -0
- package/v1/utils/http.d.ts +284 -0
- package/v1/utils/http.js +614 -0
- package/v1/utils/http.js.map +1 -0
- package/v1/utils/idl.d.ts +515 -0
- package/v1/utils/idl.js +2103 -0
- package/v1/utils/idl.js.map +1 -0
- package/v1/utils/leb128.d.ts +63 -0
- package/v1/utils/leb128.js +224 -0
- package/v1/utils/leb128.js.map +1 -0
- package/v1/utils/polling.d.ts +59 -0
- package/v1/utils/polling.js +325 -0
- package/v1/utils/polling.js.map +1 -0
- package/v1/utils/principal.d.ts +58 -0
- package/v1/utils/principal.js +543 -0
- package/v1/utils/principal.js.map +1 -0
- package/v1/utils/secp256k1.d.ts +79 -0
- package/v1/utils/secp256k1.js +278 -0
- package/v1/utils/secp256k1.js.map +1 -0
- package/v1/utils/transaction.d.ts +3 -0
- package/v1/utils/transaction.js +56 -0
- package/v1/utils/transaction.js.map +1 -0
|
@@ -0,0 +1,416 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.createICPProtocolOptions = exports.ICP_MAINNET_PROTOCOL_NETWORK = exports.createICPProtocol = exports.ICPProtocolImpl = void 0;
|
|
54
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
55
|
+
var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
|
|
56
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
57
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
58
|
+
var crypto_1 = require("@airgap/crypto");
|
|
59
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
60
|
+
var convert_1 = require("../utils/convert");
|
|
61
|
+
var ICPImplementation_1 = require("./ICPImplementation");
|
|
62
|
+
// Implementation
|
|
63
|
+
var ICPProtocolImpl = /** @class */ (function () {
|
|
64
|
+
function ICPProtocolImpl(options) {
|
|
65
|
+
if (options === void 0) { options = {}; }
|
|
66
|
+
// Common
|
|
67
|
+
this.units = {
|
|
68
|
+
ICP: {
|
|
69
|
+
symbol: { value: 'ICP', market: 'icp' },
|
|
70
|
+
decimals: 8
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
this.feeDefaults = {
|
|
74
|
+
low: (0, module_kit_1.newAmount)(0.0001, 'ICP'),
|
|
75
|
+
medium: (0, module_kit_1.newAmount)(0.0001, 'ICP'),
|
|
76
|
+
high: (0, module_kit_1.newAmount)(0.0001, 'ICP')
|
|
77
|
+
};
|
|
78
|
+
this.metadata = {
|
|
79
|
+
identifier: coinlib_core_1.MainProtocolSymbols.ICP,
|
|
80
|
+
name: 'Internet Computer Protocol',
|
|
81
|
+
units: this.units,
|
|
82
|
+
mainUnit: 'ICP',
|
|
83
|
+
fee: {
|
|
84
|
+
defaults: this.feeDefaults
|
|
85
|
+
},
|
|
86
|
+
account: {
|
|
87
|
+
standardDerivationPath: "m/44'/223'/0'/0/0",
|
|
88
|
+
address: {
|
|
89
|
+
isCaseSensitive: true,
|
|
90
|
+
placeholder: '',
|
|
91
|
+
regex: '^[a-f0-9]{64}$'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
transaction: {
|
|
95
|
+
arbitraryData: {
|
|
96
|
+
inner: { name: 'payload' }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
// Offline
|
|
101
|
+
this.cryptoConfiguration = {
|
|
102
|
+
algorithm: 'secp256k1'
|
|
103
|
+
};
|
|
104
|
+
this.options = createICPProtocolOptions(options.network);
|
|
105
|
+
}
|
|
106
|
+
ICPProtocolImpl.prototype.getMetadata = function () {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
return [2 /*return*/, this.metadata];
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
ICPProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
return [2 /*return*/, (0, ICPImplementation_1.getAddressFromPublicKey)(publicKey.value)];
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
ICPProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, _publicKey) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var signedTransactionInfo, args, unsignedTransactionInfo;
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
switch (transaction.type) {
|
|
125
|
+
case 'signed':
|
|
126
|
+
signedTransactionInfo = (0, ICPImplementation_1.getInfoFromSignedTransaction)(transaction.transaction);
|
|
127
|
+
args = (0, ICPImplementation_1.decodeArguments)(signedTransactionInfo.content.arg)[0];
|
|
128
|
+
return [2 /*return*/, [
|
|
129
|
+
{
|
|
130
|
+
from: [(0, ICPImplementation_1.getAddressFromPublicKey)(_publicKey.value)],
|
|
131
|
+
to: [(0, convert_1.uint8ArrayToHexString)(args.to)],
|
|
132
|
+
isInbound: false,
|
|
133
|
+
amount: (0, module_kit_1.newAmount)(args.amount.e8s.toString(), 'blockchain'),
|
|
134
|
+
fee: (0, module_kit_1.newAmount)(args.fee.e8s.toString(), 'blockchain'),
|
|
135
|
+
network: this.options.network
|
|
136
|
+
}
|
|
137
|
+
]];
|
|
138
|
+
case 'unsigned':
|
|
139
|
+
unsignedTransactionInfo = (0, ICPImplementation_1.getInfoFromUnsignedTransaction)(transaction.transaction);
|
|
140
|
+
return [2 /*return*/, [
|
|
141
|
+
{
|
|
142
|
+
from: [(0, ICPImplementation_1.getAddressFromPublicKey)(_publicKey.value)],
|
|
143
|
+
to: [unsignedTransactionInfo.to],
|
|
144
|
+
isInbound: false,
|
|
145
|
+
amount: (0, module_kit_1.newAmount)(unsignedTransactionInfo.amount.toString(), 'blockchain'),
|
|
146
|
+
fee: (0, module_kit_1.newAmount)(unsignedTransactionInfo.fee.toString(), 'blockchain'),
|
|
147
|
+
network: this.options.network
|
|
148
|
+
}
|
|
149
|
+
]];
|
|
150
|
+
default:
|
|
151
|
+
(0, coinlib_core_1.assertNever)(transaction);
|
|
152
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ICP, 'Unsupported transaction type.');
|
|
153
|
+
}
|
|
154
|
+
return [2 /*return*/];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
ICPProtocolImpl.prototype.getCryptoConfiguration = function () {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
return [2 /*return*/, this.cryptoConfiguration];
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
ICPProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var bip32Node, _a, publicKey, privateKey;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
bip32Node = (0, crypto_1.encodeDerivative)('bip32', derivative);
|
|
170
|
+
_a = (0, ICPImplementation_1.getKeyPairFromExtendedSecretKey)(bip32Node.secretKey), publicKey = _a.publicKey, privateKey = _a.privateKey;
|
|
171
|
+
return [2 /*return*/, {
|
|
172
|
+
secretKey: (0, module_kit_1.newSecretKey)(privateKey, 'hex'),
|
|
173
|
+
publicKey: (0, module_kit_1.newPublicKey)(publicKey, 'hex')
|
|
174
|
+
}];
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
ICPProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
var signedTransaction;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
if (secretKey.format !== 'hex') {
|
|
185
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Secret key is of an unexpected format.');
|
|
186
|
+
}
|
|
187
|
+
return [4 /*yield*/, (0, ICPImplementation_1.signTransaction)(transaction.transaction, secretKey.value)];
|
|
188
|
+
case 1:
|
|
189
|
+
signedTransaction = _a.sent();
|
|
190
|
+
return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({ transaction: signedTransaction })];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
// Online
|
|
196
|
+
ICPProtocolImpl.prototype.getNetwork = function () {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
return [2 /*return*/, this.options.network];
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
ICPProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
var address;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
209
|
+
case 1:
|
|
210
|
+
address = _a.sent();
|
|
211
|
+
return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
ICPProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
|
|
217
|
+
var _a;
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
var endpoint, url, response, _b, nodeTransactions, tokens, offset, next, transactions;
|
|
220
|
+
var _this = this;
|
|
221
|
+
return __generator(this, function (_c) {
|
|
222
|
+
switch (_c.label) {
|
|
223
|
+
case 0:
|
|
224
|
+
endpoint = cursor === undefined ? "/accounts/".concat(address, "/transactions?limit=").concat(limit, "&offset=0") : cursor.next;
|
|
225
|
+
url = endpoint !== undefined ? "".concat(this.options.network.explorerUrl).concat(endpoint) : undefined;
|
|
226
|
+
if (!(url !== undefined)) return [3 /*break*/, 2];
|
|
227
|
+
return [4 /*yield*/, index_1.default.get(url)];
|
|
228
|
+
case 1:
|
|
229
|
+
_b = _c.sent();
|
|
230
|
+
return [3 /*break*/, 3];
|
|
231
|
+
case 2:
|
|
232
|
+
_b = undefined;
|
|
233
|
+
_c.label = 3;
|
|
234
|
+
case 3:
|
|
235
|
+
response = _b;
|
|
236
|
+
nodeTransactions = ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.blocks) || [];
|
|
237
|
+
tokens = endpoint.split('=');
|
|
238
|
+
offset = parseInt(tokens[tokens.length - 1]);
|
|
239
|
+
tokens[tokens.length - 1] = (offset + limit).toString();
|
|
240
|
+
next = tokens.join('=');
|
|
241
|
+
transactions = nodeTransactions.map(function (obj) {
|
|
242
|
+
return {
|
|
243
|
+
from: [obj.from_account_identifier],
|
|
244
|
+
to: [obj.to_account_identifier],
|
|
245
|
+
isInbound: address === obj.to_account_identifier,
|
|
246
|
+
amount: (0, module_kit_1.newAmount)(obj.amount, 'blockchain'),
|
|
247
|
+
fee: (0, module_kit_1.newAmount)(obj.fee, 'blockchain'),
|
|
248
|
+
network: _this.options.network,
|
|
249
|
+
timestamp: obj.created_at,
|
|
250
|
+
status: {
|
|
251
|
+
type: obj.transfer_type,
|
|
252
|
+
hash: obj.transaction_hash,
|
|
253
|
+
block: obj.block_height
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
return [2 /*return*/, {
|
|
258
|
+
transactions: transactions,
|
|
259
|
+
cursor: {
|
|
260
|
+
hasNext: next !== undefined,
|
|
261
|
+
next: next
|
|
262
|
+
}
|
|
263
|
+
}];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
ICPProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var address;
|
|
271
|
+
return __generator(this, function (_a) {
|
|
272
|
+
address = (0, ICPImplementation_1.getAddressFromPublicKey)(publicKey.value);
|
|
273
|
+
return [2 /*return*/, this.getBalanceOfAddress(address)];
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
ICPProtocolImpl.prototype.getBalanceOfAddress = function (address) {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
+
var balance;
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
switch (_a.label) {
|
|
282
|
+
case 0:
|
|
283
|
+
if (!address)
|
|
284
|
+
return [2 /*return*/, { total: (0, module_kit_1.newAmount)(0, 'blockchain') }];
|
|
285
|
+
return [4 /*yield*/, (0, ICPImplementation_1.getBalanceFromAddress)(address, this.options.network.rpcUrl)];
|
|
286
|
+
case 1:
|
|
287
|
+
balance = _a.sent();
|
|
288
|
+
return [2 /*return*/, { total: (0, module_kit_1.newAmount)(balance.toString(10), 'blockchain') }];
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
ICPProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
295
|
+
var balance, balanceBn, fee, feeEstimation, amountWithoutFees;
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
switch (_a.label) {
|
|
298
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
299
|
+
case 1:
|
|
300
|
+
balance = _a.sent();
|
|
301
|
+
balanceBn = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).value);
|
|
302
|
+
if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 2];
|
|
303
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(configuration.fee).value);
|
|
304
|
+
return [3 /*break*/, 4];
|
|
305
|
+
case 2: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, [])];
|
|
306
|
+
case 3:
|
|
307
|
+
feeEstimation = _a.sent();
|
|
308
|
+
fee = new bignumber_1.default((0, module_kit_1.newAmount)(feeEstimation.medium).value);
|
|
309
|
+
if (fee.gte(balanceBn)) {
|
|
310
|
+
fee = new bignumber_1.default(0);
|
|
311
|
+
}
|
|
312
|
+
_a.label = 4;
|
|
313
|
+
case 4:
|
|
314
|
+
amountWithoutFees = balanceBn.minus(fee);
|
|
315
|
+
if (amountWithoutFees.isNegative()) {
|
|
316
|
+
amountWithoutFees = new bignumber_1.default(0);
|
|
317
|
+
}
|
|
318
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees.toFixed(), 'blockchain')];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
// TODO : Get default from chain
|
|
324
|
+
ICPProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (_publicKey, _details) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
// const ledger = LedgerCanister.create()
|
|
328
|
+
// const feeDefault = await ledger.transactionFee()
|
|
329
|
+
// return {
|
|
330
|
+
// low: newAmount(feeDefault.toString(10), 'ICP'),
|
|
331
|
+
// medium: newAmount(feeDefault.toString(10), 'ICP'),
|
|
332
|
+
// high: newAmount(feeDefault.toString(10), 'ICP')
|
|
333
|
+
// }
|
|
334
|
+
return [2 /*return*/, this.feeDefaults];
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
ICPProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
|
|
339
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
+
var balance, _a, balanceBn, feeBn, amountBn, transaction, unsignedTransaction;
|
|
341
|
+
return __generator(this, function (_b) {
|
|
342
|
+
switch (_b.label) {
|
|
343
|
+
case 0:
|
|
344
|
+
_a = module_kit_1.newAmount;
|
|
345
|
+
return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
346
|
+
case 1:
|
|
347
|
+
balance = _a.apply(void 0, [(_b.sent()).total]).blockchain(this.units);
|
|
348
|
+
balanceBn = BigInt(balance.value);
|
|
349
|
+
feeBn = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined
|
|
350
|
+
? BigInt((0, module_kit_1.newAmount)(configuration.fee).blockchain(this.units).value)
|
|
351
|
+
: BigInt((0, module_kit_1.newAmount)(this.feeDefaults.medium).blockchain(this.units).value);
|
|
352
|
+
// Throw if not enough balance for fee
|
|
353
|
+
if (balanceBn < feeBn) {
|
|
354
|
+
throw new errors_1.BalanceError(coinlib_core_1.Domain.ICP, 'not enough balance');
|
|
355
|
+
}
|
|
356
|
+
amountBn = BigInt((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
|
|
357
|
+
transaction = {
|
|
358
|
+
from: (0, ICPImplementation_1.getAddressFromPublicKey)(publicKey.value),
|
|
359
|
+
to: details[0].to,
|
|
360
|
+
amount: amountBn,
|
|
361
|
+
fee: feeBn
|
|
362
|
+
};
|
|
363
|
+
unsignedTransaction = (0, ICPImplementation_1.createUnsignedTransaction)(transaction);
|
|
364
|
+
return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
|
|
365
|
+
transaction: unsignedTransaction,
|
|
366
|
+
networkId: this.networkId()
|
|
367
|
+
})];
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
ICPProtocolImpl.prototype.networkId = function () {
|
|
373
|
+
switch (this.options.network.type) {
|
|
374
|
+
case 'mainnet':
|
|
375
|
+
return 'icp_mainnet';
|
|
376
|
+
default:
|
|
377
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ICP, 'Network type not supported.');
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
// TODO : discover how to get transaction hash after broadcast
|
|
381
|
+
// https://github.com/dfinity/ic-js/tree/main/packages/nns
|
|
382
|
+
// Search for : Transfer ICP from the caller to the destination accountIdentifier. Returns the index of the block containing the tx if it was successful.
|
|
383
|
+
ICPProtocolImpl.prototype.broadcastTransaction = function (transaction) {
|
|
384
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
385
|
+
return __generator(this, function (_a) {
|
|
386
|
+
switch (_a.label) {
|
|
387
|
+
case 0: return [4 /*yield*/, (0, ICPImplementation_1.broadcastTransaction)(transaction.transaction, this.options.network.rpcUrl)];
|
|
388
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
return ICPProtocolImpl;
|
|
394
|
+
}());
|
|
395
|
+
exports.ICPProtocolImpl = ICPProtocolImpl;
|
|
396
|
+
// Factory
|
|
397
|
+
function createICPProtocol(options) {
|
|
398
|
+
if (options === void 0) { options = {}; }
|
|
399
|
+
return new ICPProtocolImpl(options);
|
|
400
|
+
}
|
|
401
|
+
exports.createICPProtocol = createICPProtocol;
|
|
402
|
+
exports.ICP_MAINNET_PROTOCOL_NETWORK = {
|
|
403
|
+
name: 'Mainnet',
|
|
404
|
+
type: 'mainnet',
|
|
405
|
+
rpcUrl: 'https://boundary.ic0.app/',
|
|
406
|
+
explorerUrl: 'https://ledger-api.internetcomputer.org'
|
|
407
|
+
};
|
|
408
|
+
var DEFAULT_ICP_PROTOCOL_NETWORK = exports.ICP_MAINNET_PROTOCOL_NETWORK;
|
|
409
|
+
function createICPProtocolOptions(network) {
|
|
410
|
+
if (network === void 0) { network = {}; }
|
|
411
|
+
return {
|
|
412
|
+
network: __assign(__assign({}, DEFAULT_ICP_PROTOCOL_NETWORK), network)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
exports.createICPProtocolOptions = createICPProtocolOptions;
|
|
416
|
+
//# sourceMappingURL=ICPProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ICPProtocol.js","sourceRoot":"","sources":["../../../src/v1/protocol/ICPProtocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA+E;AAC/E,mGAA4E;AAC5E,iHAA0F;AAC1F,sDAAqG;AACrG,yCAAiD;AACjD,iDAsB2B;AAK3B,4CAAwD;AAExD,yDAU4B;AAmB5B,iBAAiB;AAEjB;IAGE,yBAAmB,OAAkD;QAAlD,wBAAA,EAAA,YAAkD;QAIrE,SAAS;QACQ,UAAK,GAAoC;YACxD,GAAG,EAAE;gBACH,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;gBACvC,QAAQ,EAAE,CAAC;aACZ;SACF,CAAA;QAEgB,gBAAW,GAA0B;YACpD,GAAG,EAAE,IAAA,sBAAS,EAAC,MAAM,EAAE,KAAK,CAAC;YAC7B,MAAM,EAAE,IAAA,sBAAS,EAAC,MAAM,EAAE,KAAK,CAAC;YAChC,IAAI,EAAE,IAAA,sBAAS,EAAC,MAAM,EAAE,KAAK,CAAC;SAC/B,CAAA;QAEgB,aAAQ,GAA+B;YACtD,UAAU,EAAE,kCAAmB,CAAC,GAAG;YACnC,IAAI,EAAE,4BAA4B;YAElC,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,KAAK;YAEf,GAAG,EAAE;gBACH,QAAQ,EAAE,IAAI,CAAC,WAAW;aAC3B;YAED,OAAO,EAAE;gBACP,sBAAsB,EAAE,mBAAmB;gBAC3C,OAAO,EAAE;oBACP,eAAe,EAAE,IAAI;oBACrB,WAAW,EAAE,EAAE;oBACf,KAAK,EAAE,gBAAgB;iBACxB;aACF;YAED,WAAW,EAAE;gBACX,aAAa,EAAE;oBACb,KAA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D;IAAlD,wBAAA,EAAA,YAAkD;IAClF,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC;AAFD,8CAEC;AAEY,QAAA,4BAA4B,GAAuB;IAC9D,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,2BAA2B;IACnC,WAAW,EAAE,yCAAyC;CACvD,CAAA;AAED,IAAM,4BAA4B,GAAuB,oCAA4B,CAAA;AAErF,SAAgB,wBAAwB,CAAC,OAAyC;IAAzC,wBAAA,EAAA,YAAyC;IAChF,OAAO;QACL,OAAO,wBAAO,4BAA4B,GAAK,OAAO,CAAE;KACzD,CAAA;AACH,CAAC;AAJD,4DAIC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ICPSignedTransaction, ICPUnsignedTransaction } from '../../../../types/transaction';
|
|
2
|
+
import { ICPTransactionSignRequest } from '../definitions/transaction-sign-request-icp';
|
|
3
|
+
import { ICPTransactionSignResponse } from '../definitions/transaction-sign-response-icp';
|
|
4
|
+
export declare function icpUnsignedTransactionToRequest(unsigned: ICPUnsignedTransaction, publicKey: string, callbackUrl?: string): ICPTransactionSignRequest;
|
|
5
|
+
export declare function icpSignedTransactionToResponse(signed: ICPSignedTransaction, accountIdentifier: string): ICPTransactionSignResponse;
|
|
6
|
+
export declare function icpTransactionSignRequestToUnsigned(request: ICPTransactionSignRequest): ICPUnsignedTransaction;
|
|
7
|
+
export declare function icpTransactionSignResponseToSigned(response: ICPTransactionSignResponse): ICPSignedTransaction;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.icpTransactionSignResponseToSigned = exports.icpTransactionSignRequestToUnsigned = exports.icpSignedTransactionToResponse = exports.icpUnsignedTransactionToRequest = void 0;
|
|
4
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
5
|
+
function icpUnsignedTransactionToRequest(unsigned, publicKey, callbackUrl) {
|
|
6
|
+
return { transaction: unsigned, publicKey: publicKey, callbackURL: callbackUrl };
|
|
7
|
+
}
|
|
8
|
+
exports.icpUnsignedTransactionToRequest = icpUnsignedTransactionToRequest;
|
|
9
|
+
function icpSignedTransactionToResponse(signed, accountIdentifier) {
|
|
10
|
+
return { transaction: signed.transaction, accountIdentifier: accountIdentifier };
|
|
11
|
+
}
|
|
12
|
+
exports.icpSignedTransactionToResponse = icpSignedTransactionToResponse;
|
|
13
|
+
function icpTransactionSignRequestToUnsigned(request) {
|
|
14
|
+
return (0, module_kit_1.newUnsignedTransaction)(request.transaction);
|
|
15
|
+
}
|
|
16
|
+
exports.icpTransactionSignRequestToUnsigned = icpTransactionSignRequestToUnsigned;
|
|
17
|
+
function icpTransactionSignResponseToSigned(response) {
|
|
18
|
+
return (0, module_kit_1.newSignedTransaction)({ transaction: response.transaction });
|
|
19
|
+
}
|
|
20
|
+
exports.icpTransactionSignResponseToSigned = icpTransactionSignResponseToSigned;
|
|
21
|
+
//# sourceMappingURL=transaction-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-converter.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/converter/transaction-converter.ts"],"names":[],"mappings":";;;AAAA,iDAAiF;AAKjF,SAAgB,+BAA+B,CAC7C,QAAgC,EAChC,SAAiB,EACjB,WAAoB;IAEpB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,WAAA,EAAE,WAAW,EAAE,WAAW,EAAE,CAAA;AACvE,CAAC;AAND,0EAMC;AAED,SAAgB,8BAA8B,CAAC,MAA4B,EAAE,iBAAyB;IACpG,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,iBAAiB,mBAAA,EAAE,CAAA;AAC/D,CAAC;AAFD,wEAEC;AAED,SAAgB,mCAAmC,CAAC,OAAkC;IACpF,OAAO,IAAA,mCAAsB,EAAyB,OAAO,CAAC,WAAW,CAAC,CAAA;AAC5E,CAAC;AAFD,kFAEC;AAED,SAAgB,kCAAkC,CAAC,QAAoC;IACrF,OAAO,IAAA,iCAAoB,EAAuB,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;AAC1F,CAAC;AAFD,gFAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sign-request-icp.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sign-response-icp.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$ref": "#/definitions/ICPTransactionSignRequest",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"definitions": {
|
|
5
|
+
"ICPTransactionSignRequest": {
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"callbackURL": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"publicKey": {
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
"transaction": {
|
|
15
|
+
"additionalProperties": false,
|
|
16
|
+
"properties": {
|
|
17
|
+
"networkId": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
},
|
|
20
|
+
"transaction": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"required": ["networkId", "transaction"],
|
|
25
|
+
"type": "object"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"required": ["publicKey", "transaction"],
|
|
29
|
+
"type": "object"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$ref": "#/definitions/ICPTransactionSignResponse",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"definitions": {
|
|
5
|
+
"ICPTransactionSignResponse": {
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"accountIdentifier": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"transaction": {
|
|
12
|
+
"type": "string"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"required": ["accountIdentifier", "transaction"],
|
|
16
|
+
"type": "object"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AirGapV3SerializerCompanion, SignedTransaction, UnsignedTransaction } from '@airgap/module-kit';
|
|
2
|
+
import { V3SchemaConfiguration } from '@airgap/module-kit/types/serializer';
|
|
3
|
+
import { TransactionSignRequest, TransactionSignResponse } from '@airgap/serializer';
|
|
4
|
+
export declare class ICPV3SerializerCompanion implements AirGapV3SerializerCompanion {
|
|
5
|
+
readonly schemas: V3SchemaConfiguration[];
|
|
6
|
+
private readonly icpTransactionValidator;
|
|
7
|
+
constructor();
|
|
8
|
+
toTransactionSignRequest(identifier: string, unsignedTransaction: UnsignedTransaction, publicKey: string, callbackUrl?: string): Promise<TransactionSignRequest>;
|
|
9
|
+
fromTransactionSignRequest(identifier: string, transactionSignRequest: TransactionSignRequest): Promise<UnsignedTransaction>;
|
|
10
|
+
validateTransactionSignRequest(identifier: string, transactionSignRequest: TransactionSignRequest): Promise<boolean>;
|
|
11
|
+
toTransactionSignResponse(identifier: string, signedTransaction: SignedTransaction, accountIdentifier: string): Promise<TransactionSignResponse>;
|
|
12
|
+
fromTransactionSignResponse(identifier: string, transactionSignResponse: TransactionSignResponse): Promise<SignedTransaction>;
|
|
13
|
+
validateTransactionSignResponse(identifier: string, transactionSignResponse: TransactionSignResponse): Promise<boolean>;
|
|
14
|
+
}
|