@ledgerhq/coin-internet_computer 1.9.0-nightly.8 → 1.9.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -73
- package/lib/api/api.d.ts +11 -6
- package/lib/api/api.d.ts.map +1 -1
- package/lib/api/api.js +64 -84
- package/lib/api/api.js.map +1 -1
- package/lib/bridge/bridgeHelpers/account.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/account.js +33 -52
- package/lib/bridge/bridgeHelpers/account.js.map +1 -1
- package/lib/bridge/bridgeHelpers/addresses.d.ts +6 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/addresses.js +29 -1
- package/lib/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib/bridge/bridgeHelpers/icpRosetta/index.d.ts +30 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/index.js +88 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/index.js.map +1 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts +145 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/types.js +3 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts +17 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.js +155 -0
- package/lib/bridge/bridgeHelpers/icpRosetta/utils.js.map +1 -0
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +6 -22
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +3 -4
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts +2 -2
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +13 -44
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/consts.d.ts +0 -2
- package/lib/consts.d.ts.map +1 -1
- package/lib/consts.js +1 -8
- package/lib/consts.js.map +1 -1
- package/lib/hw-signMessage.d.ts.map +1 -1
- package/lib/hw-signMessage.js +2 -1
- package/lib/hw-signMessage.js.map +1 -1
- package/lib/types/signer.d.ts +1 -1
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/api/api.d.ts +11 -6
- package/lib-es/api/api.d.ts.map +1 -1
- package/lib-es/api/api.js +60 -81
- package/lib-es/api/api.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/account.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/account.js +33 -52
- package/lib-es/bridge/bridgeHelpers/account.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts +6 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/addresses.js +23 -0
- package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.d.ts +30 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js +76 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts +145 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js +2 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts +17 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js +123 -0
- package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +6 -19
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +1 -2
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts +2 -2
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +13 -41
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/consts.d.ts +0 -2
- package/lib-es/consts.d.ts.map +1 -1
- package/lib-es/consts.js +0 -3
- package/lib-es/consts.js.map +1 -1
- package/lib-es/hw-signMessage.d.ts.map +1 -1
- package/lib-es/hw-signMessage.js +2 -1
- package/lib-es/hw-signMessage.js.map +1 -1
- package/lib-es/types/signer.d.ts +1 -1
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +13 -7
- package/src/api/api.ts +71 -126
- package/src/bridge/bridgeHelpers/account.ts +43 -70
- package/src/bridge/bridgeHelpers/addresses.ts +25 -0
- package/src/bridge/bridgeHelpers/icpRosetta/index.ts +154 -0
- package/src/bridge/bridgeHelpers/icpRosetta/types.ts +166 -0
- package/src/bridge/bridgeHelpers/icpRosetta/utils.ts +151 -0
- package/src/bridge/broadcast.ts +6 -31
- package/src/bridge/getTransactionStatus.ts +1 -2
- package/src/bridge/prepareTransaction.ts +1 -2
- package/src/bridge/signOperation.ts +18 -68
- package/src/consts.ts +0 -10
- package/src/hw-signMessage.ts +6 -1
- package/src/types/signer.ts +1 -1
|
@@ -1,69 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.buildSignOperation = void 0;
|
|
7
4
|
const rxjs_1 = require("rxjs");
|
|
8
5
|
const addresses_1 = require("./bridgeHelpers/addresses");
|
|
9
|
-
const
|
|
10
|
-
const agent_1 = require("@zondax/ledger-live-icp/agent");
|
|
6
|
+
const icpRosetta_1 = require("./bridgeHelpers/icpRosetta");
|
|
11
7
|
const buildOptimisticOperation_1 = require("./buildOptimisticOperation");
|
|
12
8
|
const common_logic_1 = require("../common-logic");
|
|
13
|
-
const logs_1 = require("@ledgerhq/logs");
|
|
14
|
-
const invariant_1 = __importDefault(require("invariant"));
|
|
15
|
-
const signICPTransaction = async (unsignedTxn, derivationPath, signerContext, account, deviceId) => {
|
|
16
|
-
const blob = agent_1.Cbor.encode({ content: unsignedTxn });
|
|
17
|
-
(0, logs_1.log)("debug", "[signICPTransaction] blob", Buffer.from(blob).toString("hex"));
|
|
18
|
-
const signatures = await signerContext(deviceId, signer => signer.sign(derivationPath, Buffer.from(blob)));
|
|
19
|
-
(0, invariant_1.default)(signatures.signatureRS, "[ICP](signICPTransaction) Signature not found");
|
|
20
|
-
(0, invariant_1.default)(account.xpub, "[ICP](signICPTransaction) Account xpub is required");
|
|
21
|
-
return {
|
|
22
|
-
signature: Buffer.from(signatures.signatureRS).toString("hex"),
|
|
23
|
-
callBody: {
|
|
24
|
-
content: unsignedTxn,
|
|
25
|
-
sender_pubkey: (0, utils_1.pubkeyToDer)(account.xpub),
|
|
26
|
-
sender_sig: signatures.signatureRS,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
9
|
const buildSignOperation = (signerContext) => ({ account, transaction, deviceId }) => new rxjs_1.Observable(o => {
|
|
31
10
|
async function main() {
|
|
32
|
-
(0, logs_1.log)("debug", "[signOperation] icp start fn");
|
|
33
|
-
(0, logs_1.log)("debug", "[signOperation] transaction", transaction);
|
|
34
11
|
const { xpub } = account;
|
|
35
|
-
(0, invariant_1.default)(xpub, "[ICP](signOperation) Account xpub is required");
|
|
36
12
|
const { derivationPath } = (0, addresses_1.getAddress)(account);
|
|
37
|
-
const {
|
|
13
|
+
const { unsignedTxn, payloads } = await (0, icpRosetta_1.getUnsignedTransaction)(transaction, account);
|
|
38
14
|
o.next({
|
|
39
15
|
type: "device-signature-requested",
|
|
40
16
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
17
|
+
const { signedTxn } = await (0, icpRosetta_1.signICPTransaction)({
|
|
18
|
+
signerContext,
|
|
19
|
+
deviceId,
|
|
20
|
+
unsignedTxn,
|
|
21
|
+
path: (0, common_logic_1.getPath)(derivationPath),
|
|
22
|
+
payloads,
|
|
23
|
+
pubkey: xpub ?? "",
|
|
24
|
+
});
|
|
47
25
|
o.next({
|
|
48
26
|
type: "device-signature-granted",
|
|
49
27
|
});
|
|
50
|
-
const hash = (0,
|
|
51
|
-
from: account.freshAddress,
|
|
52
|
-
to: transaction.recipient,
|
|
53
|
-
amount: transferRawRequest.amount.e8s,
|
|
54
|
-
fee: transferRawRequest.fee.e8s,
|
|
55
|
-
memo: transferRawRequest.memo,
|
|
56
|
-
created_at_time: transferRawRequest.created_at_time[0]["timestamp_nanos"],
|
|
57
|
-
});
|
|
28
|
+
const { hash } = await (0, icpRosetta_1.getTxnMetadata)(signedTxn);
|
|
58
29
|
const operation = await (0, buildOptimisticOperation_1.buildOptimisticOperation)(account, transaction, hash);
|
|
59
30
|
o.next({
|
|
60
31
|
type: "signed",
|
|
61
32
|
signedOperation: {
|
|
62
33
|
operation,
|
|
63
|
-
signature,
|
|
64
|
-
|
|
65
|
-
encodedSignedCallBlob,
|
|
66
|
-
},
|
|
34
|
+
signature: signedTxn,
|
|
35
|
+
expirationDate: (0, icpRosetta_1.getTxnExpirationDate)(unsignedTxn),
|
|
67
36
|
},
|
|
68
37
|
});
|
|
69
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":";;;AAAA,+BAAkC;AAElC,yDAAuD;AACvD,2DAKoC;AACpC,yEAAsE;AAItE,kDAA0C;AAEnC,MAAM,kBAAkB,GAC7B,CAAC,aAAuC,EAAwD,EAAE,CAClG,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CACrC,IAAI,iBAAU,CAAC,CAAC,CAAC,EAAE;IACjB,KAAK,UAAU,IAAI;QACjB,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QACzB,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,sBAAU,EAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,mCAAsB,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAErF,CAAC,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,4BAA4B;SACnC,CAAC,CAAC;QAEH,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,+BAAkB,EAAC;YAC7C,aAAa;YACb,QAAQ;YACR,WAAW;YACX,IAAI,EAAE,IAAA,sBAAO,EAAC,cAAc,CAAC;YAC7B,QAAQ;YACR,MAAM,EAAE,IAAI,IAAI,EAAE;SACnB,CAAC,CAAC;QAEH,CAAC,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,0BAA0B;SACjC,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,2BAAc,EAAC,SAAS,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,MAAM,IAAA,mDAAwB,EAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAE7E,CAAC,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,QAAQ;YACd,eAAe,EAAE;gBACf,SAAS;gBACT,SAAS,EAAE,SAAS;gBACpB,cAAc,EAAE,IAAA,iCAAoB,EAAC,WAAW,CAAC;aAClD;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,EAAE,CAAC,IAAI,CACT,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,EAClB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC;AA3CM,QAAA,kBAAkB,sBA2CxB"}
|
package/lib/consts.d.ts
CHANGED
|
@@ -3,6 +3,4 @@ export declare const ICP_BLK_NAME_ROSETTA = "Internet Computer";
|
|
|
3
3
|
export declare const ICP_NET_ID_ROSETTA = "00000000000000020101";
|
|
4
4
|
export declare const ICP_FEES = 10000;
|
|
5
5
|
export declare const MAX_MEMO_VALUE: number;
|
|
6
|
-
export declare const FETCH_TXNS_LIMIT = 100;
|
|
7
|
-
export { MAINNET_GOVERNANCE_CANISTER_ID, MAINNET_LEDGER_CANISTER_ID, MAINNET_INDEX_CANISTER_ID, ICP_NETWORK_URL, } from "@zondax/ledger-live-icp/neurons";
|
|
8
6
|
//# sourceMappingURL=consts.d.ts.map
|
package/lib/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAGnC,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AACxD,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AAGzD,eAAO,MAAM,QAAQ,QAAM,CAAC;AAG5B,eAAO,MAAM,cAAc,QAA0B,CAAC
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAGnC,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AACxD,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AAGzD,eAAO,MAAM,QAAQ,QAAM,CAAC;AAG5B,eAAO,MAAM,cAAc,QAA0B,CAAC"}
|
package/lib/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MAX_MEMO_VALUE = exports.ICP_FEES = exports.ICP_NET_ID_ROSETTA = exports.ICP_BLK_NAME_ROSETTA = exports.ICP_SEND_TXN_TYPE = void 0;
|
|
4
4
|
exports.ICP_SEND_TXN_TYPE = 0;
|
|
5
5
|
// ICP Rosetta ids
|
|
6
6
|
exports.ICP_BLK_NAME_ROSETTA = "Internet Computer";
|
|
@@ -9,11 +9,4 @@ exports.ICP_NET_ID_ROSETTA = "00000000000000020101";
|
|
|
9
9
|
exports.ICP_FEES = 1e4;
|
|
10
10
|
// Max Memo value on ICP network
|
|
11
11
|
exports.MAX_MEMO_VALUE = Number.MAX_SAFE_INTEGER;
|
|
12
|
-
// API limits
|
|
13
|
-
exports.FETCH_TXNS_LIMIT = 100;
|
|
14
|
-
var neurons_1 = require("@zondax/ledger-live-icp/neurons");
|
|
15
|
-
Object.defineProperty(exports, "MAINNET_GOVERNANCE_CANISTER_ID", { enumerable: true, get: function () { return neurons_1.MAINNET_GOVERNANCE_CANISTER_ID; } });
|
|
16
|
-
Object.defineProperty(exports, "MAINNET_LEDGER_CANISTER_ID", { enumerable: true, get: function () { return neurons_1.MAINNET_LEDGER_CANISTER_ID; } });
|
|
17
|
-
Object.defineProperty(exports, "MAINNET_INDEX_CANISTER_ID", { enumerable: true, get: function () { return neurons_1.MAINNET_INDEX_CANISTER_ID; } });
|
|
18
|
-
Object.defineProperty(exports, "ICP_NETWORK_URL", { enumerable: true, get: function () { return neurons_1.ICP_NETWORK_URL; } });
|
|
19
12
|
//# sourceMappingURL=consts.js.map
|
package/lib/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,CAAC,CAAC;AAEnC,kBAAkB;AACL,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAC3C,QAAA,kBAAkB,GAAG,sBAAsB,CAAC;AAEzD,eAAe;AACF,QAAA,QAAQ,GAAG,GAAG,CAAC;AAE5B,gCAAgC;AACnB,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,CAAC,CAAC;AAEnC,kBAAkB;AACL,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAC3C,QAAA,kBAAkB,GAAG,sBAAsB,CAAC;AAEzD,eAAe;AACF,QAAA,QAAQ,GAAG,GAAG,CAAC;AAE5B,gCAAgC;AACnB,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hw-signMessage.d.ts","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hw-signMessage.d.ts","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAO3D,eAAO,MAAM,WAAW,kBACN,cAAc,SAAS,CAAC,gBACvB,MAAM,WAAW,OAAO,eAAe,UAAU;;;;;;;EA2BjE,CAAC"}
|
package/lib/hw-signMessage.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.signMessage = void 0;
|
|
4
4
|
const logs_1 = require("@ledgerhq/logs");
|
|
5
5
|
const utils_1 = require("./common-logic/utils");
|
|
6
|
+
const consts_1 = require("./consts");
|
|
6
7
|
function bufferToArrayBuffer(buffer) {
|
|
7
8
|
const sig = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
8
9
|
return Buffer.from(sig);
|
|
@@ -14,7 +15,7 @@ const signMessage = (signerContext) => async (deviceId, account, { message }) =>
|
|
|
14
15
|
if (typeof message !== "string")
|
|
15
16
|
throw new Error("Message must be a string");
|
|
16
17
|
const { r } = await signerContext(deviceId, async (signer) => {
|
|
17
|
-
const r = await signer.sign(account.freshAddressPath, (0, utils_1.getBufferFromString)(message));
|
|
18
|
+
const r = await signer.sign(account.freshAddressPath, (0, utils_1.getBufferFromString)(message), consts_1.ICP_SEND_TXN_TYPE);
|
|
18
19
|
return { r };
|
|
19
20
|
});
|
|
20
21
|
if (!r.signatureRS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hw-signMessage.js","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AACrC,gDAA2D;
|
|
1
|
+
{"version":3,"file":"hw-signMessage.js","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AACrC,gDAA2D;AAC3D,qCAA6C;AAK7C,SAAS,mBAAmB,CAAC,MAAc;IACzC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UA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17
|
showAddressAndPubKey(path: string): Promise<ICPGetAddrResponse>;
|
|
18
18
|
getAddressAndPubKey(path: string): Promise<ICPGetAddrResponse>;
|
|
19
|
-
sign(path: string, message: Buffer): Promise<ICPSignature>;
|
|
19
|
+
sign(path: string, message: Buffer, txtype: number): Promise<ICPSignature>;
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5E"}
|
package/lib-es/api/api.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ICPRosettaBlockHeightResponse, ICPRosettaGetBalancesResponse, ICPRosettaGetTxnsHistoryResponse } from "../bridge/bridgeHelpers/icpRosetta/types";
|
|
2
|
+
export declare const getICPRosettaNetworkIdentifier: () => {
|
|
3
|
+
network_identifier: {
|
|
4
|
+
blockchain: string;
|
|
5
|
+
network: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const fetchBlockHeight: () => Promise<ICPRosettaBlockHeightResponse>;
|
|
9
|
+
export declare const fetchBalances: (accountId: string) => Promise<ICPRosettaGetBalancesResponse>;
|
|
10
|
+
export declare const fetchTxns: (accountId: string) => Promise<ICPRosettaGetTxnsHistoryResponse>;
|
|
11
|
+
export declare const constructionInvoke: <TRequest, TResponse>(opts: TRequest, method: string) => Promise<TResponse>;
|
|
7
12
|
//# sourceMappingURL=api.d.ts.map
|
package/lib-es/api/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,EAC7B,gCAAgC,EACjC,MAAM,0CAA0C,CAAC;AA8BlD,eAAO,MAAM,8BAA8B;;;;;CAO1C,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAa,QAAQ,6BAA6B,CAM9E,CAAC;AAEF,eAAO,MAAM,aAAa,cAAqB,MAAM,KAAG,QAAQ,6BAA6B,CAU5F,CAAC;AAEF,eAAO,MAAM,SAAS,cAAqB,MAAM,KAAG,QAAQ,gCAAgC,CAU3F,CAAC;AAEF,eAAO,MAAM,kBAAkB,8BACvB,QAAQ,UACN,MAAM,KACb,QAAQ,SAAS,CAQnB,CAAC"}
|
package/lib-es/api/api.js
CHANGED
|
@@ -1,90 +1,69 @@
|
|
|
1
1
|
import { log } from "@ledgerhq/logs";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const queryBlocksRawRequest = {
|
|
11
|
-
start: BigInt(0),
|
|
12
|
-
length: BigInt(1),
|
|
13
|
-
};
|
|
14
|
-
const queryBlocksIdlFunc = getCanisterIdlFunc(ledgerIdlFactory, "query_blocks");
|
|
15
|
-
const queryBlocksargs = encodeCanisterIdlFunc(queryBlocksIdlFunc, [queryBlocksRawRequest]);
|
|
16
|
-
const agent = await getAgent(ICP_NETWORK_URL);
|
|
17
|
-
const blockHeightRes = await agent.query(canisterId, {
|
|
18
|
-
arg: queryBlocksargs,
|
|
19
|
-
methodName: "query_blocks",
|
|
20
|
-
});
|
|
21
|
-
invariant(blockHeightRes.status === "replied", "[ICP](fetchBlockHeight) Query failed");
|
|
22
|
-
const decodedIdl = decodeCanisterIdlFunc(queryBlocksIdlFunc, blockHeightRes.reply.arg);
|
|
23
|
-
const decoded = fromNullable(decodedIdl);
|
|
24
|
-
invariant(decoded, "[ICP](fetchBlockHeight) Decoding failed");
|
|
25
|
-
return BigNumber(decoded.chain_length.toString());
|
|
2
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
3
|
+
import network from "@ledgerhq/live-network/network";
|
|
4
|
+
import { ICP_BLK_NAME_ROSETTA, ICP_NET_ID_ROSETTA } from "../consts";
|
|
5
|
+
const getICPURL = (path) => {
|
|
6
|
+
const baseUrl = getEnv("API_ICP_ENDPOINT");
|
|
7
|
+
if (!baseUrl)
|
|
8
|
+
throw new Error("API base URL not available");
|
|
9
|
+
return `${baseUrl}${path ? path : ""}`;
|
|
26
10
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
const ICPFetchWrapper = async (path, body) => {
|
|
12
|
+
const url = getICPURL(path);
|
|
13
|
+
// We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
|
|
14
|
+
const opts = {
|
|
31
15
|
method: "POST",
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
16
|
+
data: body,
|
|
17
|
+
url,
|
|
18
|
+
};
|
|
19
|
+
const rawResponse = await network(opts);
|
|
20
|
+
if (rawResponse && rawResponse.data && rawResponse.data.details?.error_message) {
|
|
21
|
+
log("error", rawResponse.data.details?.error_message);
|
|
38
22
|
}
|
|
39
|
-
|
|
23
|
+
// We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
|
|
24
|
+
const { data } = rawResponse;
|
|
25
|
+
log("http", url);
|
|
26
|
+
return data;
|
|
40
27
|
};
|
|
41
|
-
export const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
methodName: "get_account_identifier_balance",
|
|
49
|
-
});
|
|
50
|
-
if (balanceRes.status !== "replied") {
|
|
51
|
-
log("debug", `[ICP](fetchBalance) Query failed: ${balanceRes.status}`);
|
|
52
|
-
return BigNumber(0);
|
|
53
|
-
}
|
|
54
|
-
const decodedBalance = decodeCanisterIdlFunc(getBalanceIdlFunc, balanceRes.reply.arg);
|
|
55
|
-
const balance = fromNullable(decodedBalance);
|
|
56
|
-
if (!balance) {
|
|
57
|
-
return BigNumber(0);
|
|
58
|
-
}
|
|
59
|
-
return BigNumber(balance.toString());
|
|
28
|
+
export const getICPRosettaNetworkIdentifier = () => {
|
|
29
|
+
return {
|
|
30
|
+
network_identifier: {
|
|
31
|
+
blockchain: ICP_BLK_NAME_ROSETTA,
|
|
32
|
+
network: ICP_NET_ID_ROSETTA,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
60
35
|
};
|
|
61
|
-
export const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
account_identifier:
|
|
69
|
-
|
|
70
|
-
|
|
36
|
+
export const fetchBlockHeight = async () => {
|
|
37
|
+
const data = await ICPFetchWrapper("network/status", getICPRosettaNetworkIdentifier());
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
export const fetchBalances = async (accountId) => {
|
|
41
|
+
const body = {
|
|
42
|
+
...getICPRosettaNetworkIdentifier(),
|
|
43
|
+
account_identifier: {
|
|
44
|
+
address: accountId,
|
|
45
|
+
metadata: {},
|
|
46
|
+
},
|
|
71
47
|
};
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
48
|
+
const data = await ICPFetchWrapper("account/balance", body);
|
|
49
|
+
return data;
|
|
50
|
+
};
|
|
51
|
+
export const fetchTxns = async (accountId) => {
|
|
52
|
+
const body = {
|
|
53
|
+
...getICPRosettaNetworkIdentifier(),
|
|
54
|
+
account_identifier: {
|
|
55
|
+
address: accountId,
|
|
56
|
+
metadata: {},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const data = await ICPFetchWrapper("search/transactions", body);
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
export const constructionInvoke = async (opts, method) => {
|
|
63
|
+
const body = {
|
|
64
|
+
...opts,
|
|
65
|
+
};
|
|
66
|
+
const data = await ICPFetchWrapper(`construction/${method}`, body);
|
|
67
|
+
return data;
|
|
89
68
|
};
|
|
90
69
|
//# sourceMappingURL=api.js.map
|
package/lib-es/api/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,OAAO,MAAM,gCAAgC,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAOrE,MAAM,SAAS,GAAG,CAAC,IAAa,EAAU,EAAE;IAC1C,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,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AAI,GAAG;QACX,GAAG,8BAA8B,EAAE;QACnC,kBAAkB,EAAE;YAClB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,EAAE;SACb;KACF,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,eAAe,CAAgC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAC3F,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,SAAiB,EAA6C,EAAE;IAC9F,MAAM,IAAI,GAAG;QACX,GAAG,8BAA8B,EAAE;QACnC,kBAAkB,EAAE;YAClB,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,EAAE;SACb;KACF,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,eAAe,CAAmC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IAClG,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,IAAc,EACd,MAAc,EACM,EAAE;IACtB,MAAM,IAAI,GAAa;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,eAAe,CAAY,gBAAgB,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAcjF,eAAO,MAAM,eAAe,EAAE,eAmC7B,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
-
import {
|
|
2
|
+
import { fetchBalances, fetchBlockHeight, fetchTxns } from "../../api";
|
|
3
3
|
import flatMap from "lodash/flatMap";
|
|
4
4
|
import BigNumber from "bignumber.js";
|
|
5
5
|
import { ICP_FEES } from "../../consts";
|
|
6
6
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
7
7
|
import { normalizeEpochTimestamp } from "../../common-logic/utils";
|
|
8
8
|
import invariant from "invariant";
|
|
9
|
-
import { deriveAddressFromPubkey
|
|
9
|
+
import { deriveAddressFromPubkey } from "./icpRosetta";
|
|
10
10
|
export const getAccountShape = async (info) => {
|
|
11
11
|
const { currency, derivationMode, rest = {}, initialAccount } = info;
|
|
12
12
|
const publicKey = reconciliatePublicKey(rest.publicKey, initialAccount);
|
|
@@ -23,15 +23,16 @@ export const getAccountShape = async (info) => {
|
|
|
23
23
|
});
|
|
24
24
|
// log("debug", `Generation account shape for ${address}`);
|
|
25
25
|
const blockHeight = await fetchBlockHeight();
|
|
26
|
-
const
|
|
27
|
-
const
|
|
26
|
+
const balanceResp = await fetchBalances(address);
|
|
27
|
+
const balance = balanceResp.balances[0];
|
|
28
|
+
const txns = await fetchTxns(address);
|
|
28
29
|
const result = {
|
|
29
30
|
id: accountId,
|
|
30
|
-
balance,
|
|
31
|
-
spendableBalance: balance,
|
|
32
|
-
operations: flatMap(txns, mapTxToOps(accountId, address)),
|
|
33
|
-
blockHeight: blockHeight.
|
|
34
|
-
operationsCount:
|
|
31
|
+
balance: BigNumber(balance.value),
|
|
32
|
+
spendableBalance: BigNumber(balance.value),
|
|
33
|
+
operations: flatMap(txns.transactions.reverse(), mapTxToOps(accountId, address)),
|
|
34
|
+
blockHeight: blockHeight.current_block_identifier.index,
|
|
35
|
+
operationsCount: txns.transactions.length,
|
|
35
36
|
xpub: publicKey,
|
|
36
37
|
};
|
|
37
38
|
return result;
|
|
@@ -47,56 +48,36 @@ function reconciliatePublicKey(publicKey, initialAccount) {
|
|
|
47
48
|
}
|
|
48
49
|
const mapTxToOps = (accountId, address, fee = ICP_FEES) => {
|
|
49
50
|
return (txInfo) => {
|
|
50
|
-
const { transaction: txn } = txInfo;
|
|
51
51
|
const ops = [];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
hash = hashTransaction({
|
|
68
|
-
from: fromAccount,
|
|
69
|
-
to: toAccount,
|
|
70
|
-
amount: txn.operation.Transfer.amount.e8s,
|
|
71
|
-
fee: txn.operation.Transfer.fee.e8s,
|
|
72
|
-
memo: txn.memo,
|
|
73
|
-
created_at_time: txn.created_at_time[0]?.timestamp_nanos ?? BigInt(0),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const blockHeight = Number(txInfo.id);
|
|
77
|
-
const blockHash = "";
|
|
78
|
-
const memo = txInfo.transaction.memo.toString();
|
|
52
|
+
const ownerOperation = txInfo.transaction.operations.find(cur => cur.account.address === address);
|
|
53
|
+
const counterOperation = txInfo.transaction.operations.find(cur => cur.account.address !== address);
|
|
54
|
+
if (!ownerOperation || !counterOperation)
|
|
55
|
+
return ops;
|
|
56
|
+
const timeStamp = txInfo.transaction.metadata.timestamp;
|
|
57
|
+
const amount = BigNumber(ownerOperation.amount.value);
|
|
58
|
+
const hash = txInfo.transaction.transaction_identifier.hash;
|
|
59
|
+
const fromAccount = amount.isPositive()
|
|
60
|
+
? counterOperation.account.address
|
|
61
|
+
: ownerOperation.account.address;
|
|
62
|
+
const toAccount = amount.isNegative()
|
|
63
|
+
? counterOperation.account.address
|
|
64
|
+
: ownerOperation.account.address;
|
|
65
|
+
const memo = txInfo.transaction.metadata.memo.toString();
|
|
66
|
+
const blockHeight = txInfo.transaction.metadata.block_height;
|
|
79
67
|
const date = new Date(normalizeEpochTimestamp(timeStamp.toString()));
|
|
80
68
|
const value = amount.abs();
|
|
81
69
|
const feeToUse = BigNumber(fee);
|
|
82
|
-
const isSending =
|
|
83
|
-
const isReceiving =
|
|
84
|
-
let type;
|
|
85
|
-
if (isSending) {
|
|
86
|
-
type = "OUT";
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
type = "IN";
|
|
90
|
-
}
|
|
70
|
+
const isSending = amount.isNegative();
|
|
71
|
+
const isReceiving = amount.isPositive();
|
|
91
72
|
if (isSending) {
|
|
92
73
|
ops.push({
|
|
93
|
-
id: encodeOperationId(accountId, hash,
|
|
74
|
+
id: encodeOperationId(accountId, hash, "OUT"),
|
|
94
75
|
hash,
|
|
95
|
-
type,
|
|
76
|
+
type: "OUT",
|
|
96
77
|
value: value.plus(feeToUse),
|
|
97
78
|
fee: feeToUse,
|
|
98
79
|
blockHeight,
|
|
99
|
-
blockHash,
|
|
80
|
+
blockHash: null,
|
|
100
81
|
accountId,
|
|
101
82
|
senders: [fromAccount],
|
|
102
83
|
recipients: [toAccount],
|
|
@@ -108,13 +89,13 @@ const mapTxToOps = (accountId, address, fee = ICP_FEES) => {
|
|
|
108
89
|
}
|
|
109
90
|
if (isReceiving) {
|
|
110
91
|
ops.push({
|
|
111
|
-
id: encodeOperationId(accountId, hash,
|
|
92
|
+
id: encodeOperationId(accountId, hash, "IN"),
|
|
112
93
|
hash,
|
|
113
|
-
type,
|
|
94
|
+
type: "IN",
|
|
114
95
|
value,
|
|
115
96
|
fee: feeToUse,
|
|
116
97
|
blockHeight,
|
|
117
|
-
blockHash,
|
|
98
|
+
blockHash: null,
|
|
118
99
|
accountId,
|
|
119
100
|
senders: [fromAccount],
|
|
120
101
|
recipients: [toAccount],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EA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CAAC;QACtC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QAExC,IAAI,SAAS,EAAE,CAAC;YACd,GAAG,CAAC,IAAI,CAAC;gBACP,EAAE,EAAE,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC;gBAC7C,IAAI;gBACJ,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3B,GAAG,EAAE,QAAQ;gBACb,WAAW;gBACX,SAAS,EAAE,IAAI;gBACf,SAAS;gBACT,OAAO,EAAE,CAAC,WAAW,CAAC;gBACtB,UAAU,EAAE,CAAC,SAAS,CAAC;gBACvB,IAAI;gBACJ,KAAK,EAAE;oBACL,IAAI;iBACL;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,CAAC,IAAI,CAAC;gBACP,EAAE,EAAE,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC;gBAC5C,IAAI;gBACJ,IAAI,EAAE,IAAI;gBACV,KAAK;gBACL,GAAG,EAAE,QAAQ;gBACb,WAAW;gBACX,SAAS,EAAE,IAAI;gBACf,SAAS;gBACT,OAAO,EAAE,CAAC,WAAW,CAAC;gBACtB,UAAU,EAAE,CAAC,SAAS,CAAC;gBACvB,IAAI;gBACJ,KAAK,EAAE;oBACL,IAAI;iBACL;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -3,4 +3,10 @@ export declare const getAddress: (a: Account) => {
|
|
|
3
3
|
address: string;
|
|
4
4
|
derivationPath: string;
|
|
5
5
|
};
|
|
6
|
+
export declare function validateAddress(address: string): Promise<{
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function validateMemo(memo?: string): {
|
|
10
|
+
isValid: boolean;
|
|
11
|
+
};
|
|
6
12
|
//# sourceMappingURL=addresses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/addresses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/addresses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAK/C,eAAO,MAAM,UAAU,MAClB,OAAO,KACT;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CAC6C,CAAC;AAEvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CASpF;AAED,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAQhE"}
|
|
@@ -1,2 +1,25 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { MAX_MEMO_VALUE } from "../../consts";
|
|
4
|
+
import { fetchBalances } from "../../api";
|
|
1
5
|
export const getAddress = (a) => ({ address: a.freshAddress, derivationPath: a.freshAddressPath });
|
|
6
|
+
export async function validateAddress(address) {
|
|
7
|
+
try {
|
|
8
|
+
const res = await fetchBalances(address);
|
|
9
|
+
if (!res.balances)
|
|
10
|
+
throw Error(res.details?.error_message);
|
|
11
|
+
return { isValid: true };
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
log("error", e.message ?? "Failed to validate address");
|
|
15
|
+
return { isValid: false };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function validateMemo(memo) {
|
|
19
|
+
const res = BigNumber(memo ?? 0);
|
|
20
|
+
if (res.isNaN() || res.lt(0) || res.gt(BigNumber(MAX_MEMO_VALUE))) {
|
|
21
|
+
return { isValid: false };
|
|
22
|
+
}
|
|
23
|
+
return { isValid: true };
|
|
24
|
+
}
|
|
2
25
|
//# sourceMappingURL=addresses.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/addresses.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/bridge/bridgeHelpers/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,CAAU,EAIV,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,YAAY,EAAE,cAAc,EAAE,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC;AAEvE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAe;IACnD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,QAAQ;YAAE,MAAM,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAC3D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC;QACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,IAAI,C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