@ledgerhq/coin-filecoin 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +21 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/api.d.ts +9 -0
- package/lib/api/api.d.ts.map +1 -0
- package/lib/api/api.js +99 -0
- package/lib/api/api.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +18 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +27 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +62 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +71 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +100 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +84 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +8 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +75 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serializer.d.ts +13 -0
- package/lib/bridge/serializer.d.ts.map +1 -0
- package/lib/bridge/serializer.js +65 -0
- package/lib/bridge/serializer.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +80 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +41 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/bridge/utils.d.ts +26 -0
- package/lib/bridge/utils.d.ts.map +1 -0
- package/lib/bridge/utils.js +67 -0
- package/lib/bridge/utils.js.map +1 -0
- package/lib/bridge/utils.unit.test.d.ts +2 -0
- package/lib/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib/bridge/utils.unit.test.js +23 -0
- package/lib/bridge/utils.unit.test.js.map +1 -0
- package/lib/common-logic/index.d.ts +2 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +13 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/utils.d.ts +22 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +189 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/erc20/ERC20.json +12 -0
- package/lib/erc20/tokenAccounts.d.ts +10 -0
- package/lib/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib/erc20/tokenAccounts.js +169 -0
- package/lib/erc20/tokenAccounts.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +13 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +32 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/network/addresses.d.ts +16 -0
- package/lib/network/addresses.d.ts.map +1 -0
- package/lib/network/addresses.js +75 -0
- package/lib/network/addresses.js.map +1 -0
- package/lib/network/index.d.ts +2 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +18 -0
- package/lib/network/index.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +30 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +3 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +8 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +151 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +401 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +19 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +59 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +5 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +159 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/bridge.d.ts +35 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/common.d.ts +96 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +10 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +20 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +19 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/api.d.ts +9 -0
- package/lib-es/api/api.d.ts.map +1 -0
- package/lib-es/api/api.js +87 -0
- package/lib-es/api/api.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +2 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +23 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +58 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +69 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +93 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +80 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +8 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +47 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +68 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serializer.d.ts +13 -0
- package/lib-es/bridge/serializer.d.ts.map +1 -0
- package/lib-es/bridge/serializer.js +58 -0
- package/lib-es/bridge/serializer.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +76 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +33 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/bridge/utils.d.ts +26 -0
- package/lib-es/bridge/utils.d.ts.map +1 -0
- package/lib-es/bridge/utils.js +57 -0
- package/lib-es/bridge/utils.js.map +1 -0
- package/lib-es/bridge/utils.unit.test.d.ts +2 -0
- package/lib-es/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib-es/bridge/utils.unit.test.js +21 -0
- package/lib-es/bridge/utils.unit.test.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +2 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +2 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/utils.d.ts +22 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +175 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/erc20/ERC20.json +12 -0
- package/lib-es/erc20/tokenAccounts.d.ts +10 -0
- package/lib-es/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib-es/erc20/tokenAccounts.js +158 -0
- package/lib-es/erc20/tokenAccounts.js.map +1 -0
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +28 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +2 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/network/addresses.d.ts +16 -0
- package/lib-es/network/addresses.d.ts.map +1 -0
- package/lib-es/network/addresses.js +64 -0
- package/lib-es/network/addresses.js.map +1 -0
- package/lib-es/network/index.d.ts +2 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +2 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +28 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +3 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +3 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +146 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +395 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +19 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +53 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +5 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +152 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/bridge.d.ts +35 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/common.d.ts +96 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +7 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +4 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +19 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +135 -0
- package/src/api/api.ts +125 -0
- package/src/api/index.ts +1 -0
- package/src/bridge/broadcast.ts +20 -0
- package/src/bridge/buildOptimisticOperation.ts +58 -0
- package/src/bridge/createTransaction.ts +20 -0
- package/src/bridge/deviceTransactionConfig.ts +119 -0
- package/src/bridge/estimateMaxSpendable.ts +120 -0
- package/src/bridge/getTransactionStatus.ts +80 -0
- package/src/bridge/index.ts +63 -0
- package/src/bridge/prepareTransaction.ts +82 -0
- package/src/bridge/serializer.ts +63 -0
- package/src/bridge/signOperation.ts +97 -0
- package/src/bridge/transaction.ts +69 -0
- package/src/bridge/utils.ts +73 -0
- package/src/bridge/utils.unit.test.ts +27 -0
- package/src/common-logic/index.ts +10 -0
- package/src/common-logic/utils.ts +232 -0
- package/src/erc20/ERC20.json +12 -0
- package/src/erc20/tokenAccounts.ts +183 -0
- package/src/errors.ts +13 -0
- package/src/hw-signMessage.ts +27 -0
- package/src/index.ts +1 -0
- package/src/network/addresses.ts +93 -0
- package/src/network/index.ts +1 -0
- package/src/signer/getAddress.ts +28 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-specs.ts +163 -0
- package/src/test/bridgeDatasetTest.ts +403 -0
- package/src/test/cli.ts +80 -0
- package/src/test/index.ts +6 -0
- package/src/test/speculos-deviceActions.ts +166 -0
- package/src/types/bridge.ts +42 -0
- package/src/types/common.ts +105 -0
- package/src/types/index.ts +3 -0
- package/src/types/signer.ts +19 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAqB,MAAM,UAAU,CAAC;AAO1D,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CAgEnF,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTransactionStatus = void 0;
|
|
13
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
14
|
+
const network_1 = require("../network");
|
|
15
|
+
const common_logic_1 = require("../common-logic");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
17
|
+
const errors_2 = require("../errors");
|
|
18
|
+
const getTransactionStatus = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
// log("debug", "[getTransactionStatus] start fn");
|
|
20
|
+
const errors = {};
|
|
21
|
+
const warnings = {};
|
|
22
|
+
const { balance } = account;
|
|
23
|
+
const { address } = (0, common_logic_1.getAddress)(account);
|
|
24
|
+
const subAccount = (0, common_logic_1.getSubAccount)(account, transaction);
|
|
25
|
+
const { recipient, useAllAmount, gasPremium, gasFeeCap, gasLimit } = transaction;
|
|
26
|
+
let { amount } = transaction;
|
|
27
|
+
const invalidAddressErr = new errors_1.InvalidAddress(undefined, {
|
|
28
|
+
currencyName: account.currency.name,
|
|
29
|
+
});
|
|
30
|
+
if (!recipient)
|
|
31
|
+
errors.recipient = new errors_1.RecipientRequired();
|
|
32
|
+
else if (!(0, network_1.validateAddress)(recipient).isValid)
|
|
33
|
+
errors.recipient = invalidAddressErr;
|
|
34
|
+
else if (!(0, network_1.validateAddress)(address).isValid)
|
|
35
|
+
errors.sender = invalidAddressErr;
|
|
36
|
+
if (gasFeeCap.eq(0) || gasPremium.eq(0) || gasLimit.eq(0))
|
|
37
|
+
errors.gas = new errors_1.FeeNotLoaded();
|
|
38
|
+
// This is the worst case scenario (the tx won't cost more than this value)
|
|
39
|
+
const estimatedFees = (0, utils_1.calculateEstimatedFees)(gasFeeCap, gasLimit);
|
|
40
|
+
let totalSpent;
|
|
41
|
+
if (useAllAmount && !subAccount) {
|
|
42
|
+
totalSpent = account.spendableBalance;
|
|
43
|
+
amount = totalSpent.minus(estimatedFees);
|
|
44
|
+
if (amount.lte(0) || totalSpent.gt(balance)) {
|
|
45
|
+
errors.amount = new errors_1.NotEnoughBalance();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (subAccount) {
|
|
49
|
+
totalSpent = estimatedFees;
|
|
50
|
+
if (totalSpent.gt(account.spendableBalance))
|
|
51
|
+
errors.amount = new errors_1.NotEnoughBalance();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
totalSpent = amount.plus(estimatedFees);
|
|
55
|
+
if (amount.eq(0)) {
|
|
56
|
+
errors.amount = new errors_1.AmountRequired();
|
|
57
|
+
}
|
|
58
|
+
else if (totalSpent.gt(account.spendableBalance))
|
|
59
|
+
errors.amount = new errors_1.NotEnoughBalance();
|
|
60
|
+
}
|
|
61
|
+
if (subAccount) {
|
|
62
|
+
const spendable = subAccount.spendableBalance;
|
|
63
|
+
if (transaction.amount.gt(spendable)) {
|
|
64
|
+
errors.amount = new errors_1.NotEnoughBalance();
|
|
65
|
+
}
|
|
66
|
+
if (useAllAmount) {
|
|
67
|
+
amount = spendable;
|
|
68
|
+
}
|
|
69
|
+
totalSpent = amount;
|
|
70
|
+
if (recipient && !(0, network_1.isRecipientValidForTokenTransfer)(recipient)) {
|
|
71
|
+
errors.recipient = new errors_2.InvalidRecipientForTokenTransfer();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// log("debug", "[getTransactionStatus] finish fn");
|
|
75
|
+
return {
|
|
76
|
+
errors,
|
|
77
|
+
warnings,
|
|
78
|
+
estimatedFees,
|
|
79
|
+
amount,
|
|
80
|
+
totalSpent,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
exports.getTransactionStatus = getTransactionStatus;
|
|
84
|
+
//# sourceMappingURL=getTransactionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRo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,CAAC;YACjB,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;QACD,UAAU,GAAG,MAAM,CAAC;QAEpB,IAAI,SAAS,IAAI,CAAC,IAAA,0CAAgC,EAAC,SAAS,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,SAAS,GAAG,IAAI,yCAAgC,EAAE,CAAC;QAC5D,CAAC;IACH,CAAC;IAED,oDAAoD;IAEpD,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa;QACb,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC,CAAA,CAAC;AAhEW,QAAA,oBAAoB,wBAgE/B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
+
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction, FilecoinSigner } from "../types";
|
|
4
|
+
export declare function createBridges(signerContext: SignerContext<FilecoinSigner>): {
|
|
5
|
+
currencyBridge: CurrencyBridge;
|
|
6
|
+
accountBridge: AccountBridge<Transaction, Account, import("@ledgerhq/types-live").TransactionStatusCommon, import("@ledgerhq/types-live").AccountRaw>;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAqB,cAAc,EAAE,MAAM,UAAU,CAAC;AA+C/E,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,CAAC,cAAc,CAAC;;;EAKzE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createBridges = void 0;
|
|
7
|
+
const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
8
|
+
const signer_1 = __importDefault(require("../signer"));
|
|
9
|
+
const getAddressWrapper_1 = __importDefault(require("@ledgerhq/coin-framework/bridge/getAddressWrapper"));
|
|
10
|
+
const jsHelpers_2 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
11
|
+
const getTransactionStatus_1 = require("./getTransactionStatus");
|
|
12
|
+
const estimateMaxSpendable_1 = require("./estimateMaxSpendable");
|
|
13
|
+
const prepareTransaction_1 = require("./prepareTransaction");
|
|
14
|
+
const createTransaction_1 = require("./createTransaction");
|
|
15
|
+
const utils_1 = require("../common-logic/utils");
|
|
16
|
+
const signOperation_1 = require("./signOperation");
|
|
17
|
+
const broadcast_1 = require("./broadcast");
|
|
18
|
+
function buildCurrencyBridge(signerContext) {
|
|
19
|
+
const getAddress = (0, signer_1.default)(signerContext);
|
|
20
|
+
const scanAccounts = (0, jsHelpers_1.makeScanAccounts)({
|
|
21
|
+
getAccountShape: utils_1.getAccountShape,
|
|
22
|
+
getAddressFn: (0, getAddressWrapper_1.default)(getAddress),
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
preload: () => Promise.resolve({}),
|
|
26
|
+
hydrate: () => { },
|
|
27
|
+
scanAccounts,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const sync = (0, jsHelpers_1.makeSync)({ getAccountShape: utils_1.getAccountShape });
|
|
31
|
+
function buildAccountBridge(signerContext) {
|
|
32
|
+
const getAddress = (0, signer_1.default)(signerContext);
|
|
33
|
+
const receive = (0, jsHelpers_1.makeAccountBridgeReceive)((0, getAddressWrapper_1.default)(getAddress));
|
|
34
|
+
const signOperation = (0, signOperation_1.buildSignOperation)(signerContext);
|
|
35
|
+
return {
|
|
36
|
+
estimateMaxSpendable: estimateMaxSpendable_1.estimateMaxSpendable,
|
|
37
|
+
createTransaction: createTransaction_1.createTransaction,
|
|
38
|
+
updateTransaction: jsHelpers_2.defaultUpdateTransaction,
|
|
39
|
+
getTransactionStatus: getTransactionStatus_1.getTransactionStatus,
|
|
40
|
+
prepareTransaction: prepareTransaction_1.prepareTransaction,
|
|
41
|
+
sync,
|
|
42
|
+
receive,
|
|
43
|
+
signOperation,
|
|
44
|
+
broadcast: broadcast_1.broadcast,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createBridges(signerContext) {
|
|
48
|
+
return {
|
|
49
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
50
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.createBridges = createBridges;
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":";;;;;;AAAA,yEAImD;AACnD,uDAAiC;AACjC,0GAAkF;AAGlF,yEAAqF;AAErF,iEAA8D;AAC9D,iEAA8D;AAC9D,6DAA0D;AAC1D,2DAAwD;AACxD,iDAAwD;AACxD,mDAAqD;AACrD,2CAAwC;AAExC,SAAS,mBAAmB,CAAC,aAA4C;IACvE,MAAM,UAAU,GAAG,IAAA,gBAAQ,EAAC,aAAa,CAAC,CAAC;IAE3C,MAAM,YAAY,GAAG,IAAA,4BAAgB,EAAC;QACpC,eAAe,EAAf,uBAAe;QACf,YAAY,EAAE,IAAA,2BAAiB,EAAC,UAAU,CAAC;KAC5C,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;QACjB,YAAY;KACb,CAAC;AACJ,CAAC;AAED,MAAM,IAAI,GAAG,IAAA,oBAAQ,EAAC,EAAE,eAAe,EAAf,uBAAe,EAAE,CAAC,CAAC;AAE3C,SAAS,kBAAkB,CACzB,aAA4C;IAE5C,MAAM,UAAU,GAAG,IAAA,gBAAQ,EAAC,aAAa,CAAC,CAAC;IAE3C,MAAM,OAAO,GAAG,IAAA,oCAAwB,EAAC,IAAA,2BAAiB,EAAC,UAAU,CAAC,CAAC,CAAC;IACxE,MAAM,aAAa,GAAG,IAAA,kCAAkB,EAAC,aAAa,CAAC,CAAC;IAExD,OAAO;QACL,oBAAoB,EAApB,2CAAoB;QACpB,iBAAiB,EAAjB,qCAAiB;QACjB,iBAAiB,EAAE,oCAAwB;QAC3C,oBAAoB,EAApB,2CAAoB;QACpB,kBAAkB,EAAlB,uCAAkB;QAClB,IAAI;QACJ,OAAO;QACP,aAAa;QACb,SAAS,EAAT,qBAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,aAA4C;IACxE,OAAO;QACL,cAAc,EAAE,mBAAmB,CAAC,aAAa,CAAC;QAClD,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC;KACjD,CAAC;AACJ,CAAC;AALD,sCAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareTransaction.d.ts","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAsB,WAAW,EAAE,MAAM,UAAU,CAAC;AAM3D,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAuE/E,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.prepareTransaction = void 0;
|
|
16
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
|
+
const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
18
|
+
const network_1 = require("../network");
|
|
19
|
+
const types_1 = require("../types");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const index_1 = require("../api/index");
|
|
22
|
+
const utils_2 = require("../common-logic/utils");
|
|
23
|
+
const tokenAccounts_1 = require("../erc20/tokenAccounts");
|
|
24
|
+
const prepareTransaction = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
var _a;
|
|
26
|
+
const { balance } = account;
|
|
27
|
+
const { address } = (0, utils_2.getAddress)(account);
|
|
28
|
+
const { useAllAmount } = transaction;
|
|
29
|
+
const recipient = transaction.recipient.toLowerCase();
|
|
30
|
+
const subAccount = (0, utils_2.getSubAccount)(account, transaction);
|
|
31
|
+
const tokenAccountTxn = !!subAccount;
|
|
32
|
+
if (recipient && address) {
|
|
33
|
+
const recipientValidation = (0, network_1.validateAddress)(recipient);
|
|
34
|
+
const senderValidation = (0, network_1.validateAddress)(address);
|
|
35
|
+
if (recipientValidation.isValid && senderValidation.isValid) {
|
|
36
|
+
const patch = {};
|
|
37
|
+
const method = (0, network_1.isFilEthAddress)(recipientValidation.parsedAddress) || tokenAccountTxn
|
|
38
|
+
? utils_1.Methods.InvokeEVM
|
|
39
|
+
: utils_1.Methods.Transfer;
|
|
40
|
+
const validatedContractAddress = (0, network_1.validateAddress)((_a = subAccount === null || subAccount === void 0 ? void 0 : subAccount.token.contractAddress) !== null && _a !== void 0 ? _a : "");
|
|
41
|
+
let finalRecipient = recipientValidation;
|
|
42
|
+
let params = undefined;
|
|
43
|
+
// used as fallback only for estimation of fees
|
|
44
|
+
let fallbackParams = "";
|
|
45
|
+
if (tokenAccountTxn && validatedContractAddress.isValid) {
|
|
46
|
+
finalRecipient = validatedContractAddress;
|
|
47
|
+
// If token transfer, the evm payload is required to estimate fees
|
|
48
|
+
if ((0, network_1.isEthereumConvertableAddr)(recipientValidation.parsedAddress)) {
|
|
49
|
+
params = (0, tokenAccounts_1.generateTokenTxnParams)(recipient, transaction.amount.isZero() ? (0, bignumber_js_1.default)(1) : transaction.amount);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
fallbackParams = (0, tokenAccounts_1.generateTokenTxnParams)(subAccount.token.contractAddress, (0, bignumber_js_1.default)(1));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const paramsForEstimation = params ? params : fallbackParams;
|
|
56
|
+
const result = yield (0, index_1.fetchEstimatedFees)(Object.assign(Object.assign({ to: finalRecipient.parsedAddress.toString(), from: senderValidation.parsedAddress.toString(), methodNum: method, blockIncl: types_1.BroadcastBlockIncl }, (tokenAccountTxn && { params: (0, tokenAccounts_1.encodeTxnParams)(paramsForEstimation) })), (tokenAccountTxn && { value: "0" })));
|
|
57
|
+
patch.gasFeeCap = new bignumber_js_1.default(result.gas_fee_cap);
|
|
58
|
+
patch.gasPremium = new bignumber_js_1.default(result.gas_premium);
|
|
59
|
+
patch.gasLimit = new bignumber_js_1.default(result.gas_limit);
|
|
60
|
+
patch.nonce = result.nonce;
|
|
61
|
+
patch.method = method;
|
|
62
|
+
patch.params = params;
|
|
63
|
+
const fee = (0, utils_1.calculateEstimatedFees)(patch.gasFeeCap, patch.gasLimit);
|
|
64
|
+
if (useAllAmount) {
|
|
65
|
+
patch.amount = subAccount ? subAccount.spendableBalance : balance.minus(fee);
|
|
66
|
+
patch.params =
|
|
67
|
+
tokenAccountTxn && params ? (0, tokenAccounts_1.generateTokenTxnParams)(recipient, patch.amount) : undefined;
|
|
68
|
+
}
|
|
69
|
+
return (0, jsHelpers_1.defaultUpdateTransaction)(transaction, patch);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return transaction;
|
|
73
|
+
});
|
|
74
|
+
exports.prepareTransaction = prepareTransaction;
|
|
75
|
+
//# sourceMappingURL=prepareTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAAqC;AAErC,yEAAqF;AACrF,wCAAyF;AACzF,oCAA2D;AAC3D,mCAA0D;AAC1D,wCAAkD;AAClD,iDAAkE;AAClE,0DAAiF;AAE1E,MAAM,kBAAkB,GAAqD,CAClF,OAAO,EACP,WAAW,EACX,EAAE;;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;IACxC,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;IACrC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACvD,MAAM,eAAe,GAAG,CAAC,CAAC,UAAU,CAAC;IAErC,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;QACzB,MAAM,mBAAmB,GAAG,IAAA,yBAAe,EAAC,SAAS,CAAC,C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AAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAA,CAAC;AAvEW,QAAA,kBAAkB,sBAuE7B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
export interface toCBORResponse {
|
|
6
|
+
txPayload: Buffer;
|
|
7
|
+
recipientToBroadcast: string;
|
|
8
|
+
parsedSender: string;
|
|
9
|
+
encodedParams: string;
|
|
10
|
+
amountToBroadcast: BigNumber;
|
|
11
|
+
}
|
|
12
|
+
export declare const toCBOR: (account: Account, tx: Transaction) => Promise<toCBORResponse>;
|
|
13
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/bridge/serializer.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKvC,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;CAC9B;AAED,eAAO,MAAM,MAAM,YAAmB,OAAO,MAAM,WAAW,KAAG,QAAQ,cAAc,CA4CtF,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toCBOR = void 0;
|
|
16
|
+
const index_1 = require("../common-logic/index");
|
|
17
|
+
const network_1 = require("../network");
|
|
18
|
+
const message_1 = require("iso-filecoin/message");
|
|
19
|
+
const tokenAccounts_1 = require("../erc20/tokenAccounts");
|
|
20
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
|
+
const toCBOR = (account, tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
const { address: from } = (0, index_1.getAddress)(account);
|
|
25
|
+
const { method, version, nonce, gasLimit, gasPremium, gasFeeCap, amount, recipient } = tx;
|
|
26
|
+
const recipientValidation = (0, network_1.validateAddress)(recipient);
|
|
27
|
+
const fromValidation = (0, network_1.validateAddress)(from);
|
|
28
|
+
const subAccount = (0, index_1.getSubAccount)(account, tx);
|
|
29
|
+
const tokenTransfer = subAccount && subAccount.type === utils_1.AccountType.TokenAccount;
|
|
30
|
+
const params = tokenTransfer ? (0, tokenAccounts_1.encodeTxnParams)((_a = tx.params) !== null && _a !== void 0 ? _a : "") : undefined;
|
|
31
|
+
if (!recipientValidation.isValid || !fromValidation.isValid)
|
|
32
|
+
throw new Error("recipient and/or from address are not valid");
|
|
33
|
+
let finalRecipient;
|
|
34
|
+
if (tokenTransfer) {
|
|
35
|
+
const validated = (0, network_1.validateAddress)(subAccount.token.contractAddress);
|
|
36
|
+
if (!validated.isValid)
|
|
37
|
+
throw new Error("token contract address is not valid");
|
|
38
|
+
finalRecipient = validated.parsedAddress.toString();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
finalRecipient = recipientValidation.parsedAddress.toString();
|
|
42
|
+
}
|
|
43
|
+
const finalAmount = tokenTransfer ? "0" : amount.toString();
|
|
44
|
+
const message = new message_1.Message({
|
|
45
|
+
to: finalRecipient,
|
|
46
|
+
from: fromValidation.parsedAddress.toString(),
|
|
47
|
+
gasFeeCap: gasFeeCap.toString(),
|
|
48
|
+
gasLimit: gasLimit.toNumber(),
|
|
49
|
+
gasPremium: gasPremium.toString(),
|
|
50
|
+
method,
|
|
51
|
+
nonce,
|
|
52
|
+
params,
|
|
53
|
+
version: version === 0 ? 0 : undefined,
|
|
54
|
+
value: finalAmount,
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
txPayload: message.serialize(),
|
|
58
|
+
recipientToBroadcast: finalRecipient,
|
|
59
|
+
parsedSender: fromValidation.parsedAddress.toString(),
|
|
60
|
+
encodedParams: params !== null && params !== void 0 ? params : "",
|
|
61
|
+
amountToBroadcast: new bignumber_js_1.default(finalAmount),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
exports.toCBOR = toCBOR;
|
|
65
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/bridge/serializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,iDAAkE;AAClE,wCAA6C;AAC7C,kDAA+C;AAC/C,0DAAyD;AACzD,gEAAqC;AACrC,mCAAsC;AAU/B,MAAM,MAAM,GAAG,CAAO,OAAgB,EAAE,EAAe,EAA2B,EAAE;;IACzF,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAA,kBAAU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,iBAAO,CAAC;QAC1B,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,cAAc,CAAC,aAAa,CAAC,QAAQ,EAAE;QAC7C,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;QAC/B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;QAC7B,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE;QACjC,MAAM;QACN,KAAK;QACL,MAAM;QACN,OAAO,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QACtC,KAAK,EAAE,WAAW;KACnB,CAAC,CAAC;IAEH,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE;QAC9B,oBAAoB,EAAE,cAAc;QACpC,YAAY,EAAE,cAAc,CAAC,aAAa,CAAC,QAAQ,EAAE;QACrD,aAAa,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE;QAC3B,iBAAiB,EAAE,IAAI,sBAAS,CAAC,WAAW,CAAC;KAC9C,CAAC;AACJ,CAAC,CAAA,CAAC;AA5CW,QAAA,MAAM,UA4CjB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { Transaction, FilecoinSigner } from "../types";
|
|
4
|
+
export declare const buildSignOperation: (signerContext: SignerContext<FilecoinSigner>) => AccountBridge<Transaction, Account>["signOperation"];
|
|
5
|
+
//# sourceMappingURL=signOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.d.ts","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAa,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAIhE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEvD,eAAO,MAAM,kBAAkB,kBAEZ,cAAc,cAAc,CAAC,KAC3C,cAAc,WAAW,EAAE,OAAO,CAAC,CAAC,eAAe,CAkFlD,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.buildSignOperation = void 0;
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
15
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
16
|
+
const buildOptimisticOperation_1 = require("./buildOptimisticOperation");
|
|
17
|
+
const serializer_1 = require("./serializer");
|
|
18
|
+
const utils_1 = require("../common-logic/utils");
|
|
19
|
+
const utils_2 = require("./utils");
|
|
20
|
+
const buildSignOperation = (signerContext) => ({ account, deviceId, transaction }) => new rxjs_1.Observable(o => {
|
|
21
|
+
function main() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const { method, version, nonce, gasFeeCap, gasLimit, gasPremium } = transaction;
|
|
24
|
+
const { derivationPath } = (0, utils_1.getAddress)(account);
|
|
25
|
+
const subAccount = (0, utils_1.getSubAccount)(account, transaction);
|
|
26
|
+
const tokenAccountTxn = (subAccount === null || subAccount === void 0 ? void 0 : subAccount.type) === utils_2.AccountType.TokenAccount;
|
|
27
|
+
if (!gasFeeCap.gt(0) || !gasLimit.gt(0)) {
|
|
28
|
+
(0, logs_1.log)("debug", `signOperation missingData --> gasFeeCap=${gasFeeCap} gasLimit=${gasLimit}`);
|
|
29
|
+
throw new errors_1.FeeNotLoaded();
|
|
30
|
+
}
|
|
31
|
+
o.next({
|
|
32
|
+
type: "device-signature-requested",
|
|
33
|
+
});
|
|
34
|
+
// Serialize tx
|
|
35
|
+
const toCBORResponse = yield (0, serializer_1.toCBOR)(account, transaction);
|
|
36
|
+
const { txPayload, parsedSender, recipientToBroadcast, encodedParams, amountToBroadcast: finalAmount, } = toCBORResponse;
|
|
37
|
+
(0, logs_1.log)("debug", `[signOperation] serialized CBOR tx: [${txPayload.toString("hex")}]`);
|
|
38
|
+
// Sign by device
|
|
39
|
+
const { r } = yield signerContext(deviceId, (signer) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const r = yield signer.sign(derivationPath, txPayload);
|
|
41
|
+
return { r };
|
|
42
|
+
}));
|
|
43
|
+
o.next({
|
|
44
|
+
type: "device-signature-granted",
|
|
45
|
+
});
|
|
46
|
+
if (!r.signature_compact) {
|
|
47
|
+
throw new Error("Signature compact is null");
|
|
48
|
+
}
|
|
49
|
+
// build signature on the correct format
|
|
50
|
+
const signature = `${Buffer.from(r.signature_compact).toString("base64")}`;
|
|
51
|
+
const operation = yield (0, buildOptimisticOperation_1.buildOptimisticOperation)(account, transaction, toCBORResponse);
|
|
52
|
+
// Necessary for broadcast
|
|
53
|
+
const additionalTxFields = {
|
|
54
|
+
sender: parsedSender,
|
|
55
|
+
recipient: recipientToBroadcast,
|
|
56
|
+
params: encodedParams,
|
|
57
|
+
gasLimit,
|
|
58
|
+
gasFeeCap,
|
|
59
|
+
gasPremium,
|
|
60
|
+
method,
|
|
61
|
+
version,
|
|
62
|
+
nonce,
|
|
63
|
+
signatureType: 1,
|
|
64
|
+
tokenTransfer: tokenAccountTxn,
|
|
65
|
+
value: finalAmount.toString(),
|
|
66
|
+
};
|
|
67
|
+
o.next({
|
|
68
|
+
type: "signed",
|
|
69
|
+
signedOperation: {
|
|
70
|
+
operation,
|
|
71
|
+
signature,
|
|
72
|
+
rawData: additionalTxFields,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
main().then(() => o.complete(), e => o.error(e));
|
|
78
|
+
});
|
|
79
|
+
exports.buildSignOperation = buildSignOperation;
|
|
80
|
+
//# sourceMappingURL=signOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAkC;AAClC,yCAAqC;AACrC,6CAAgD;AAEhD,yEAAsE;AAEtE,6CAAsC;AACtC,iDAAkE;AAClE,mCAAsC;AAG/B,MAAM,kBAAkB,GAC7B,CACE,aAA4C,EACU,EAAE,CAC1D,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,CACrC,IAAI,iBAAU,CAAC,CAAC,CAAC,EAAE;IACjB,SAAe,IAAI;;YACjB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;YAChF,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;YAC/C,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACvD,MAAM,eAAe,GAAG,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,MAAK,mBAAW,CAAC,YAAY,CAAC;YAEtE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,C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AM,kBAAkB,GAAG;gBACzB,MAAM,EAAE,YAAY;gBACpB,SAAS,EAAE,oBAAoB;gBAC/B,MAAM,EAAE,aAAa;gBACrB,QAAQ;gBACR,SAAS;gBACT,UAAU;gBACV,MAAM;gBACN,OAAO;gBACP,KAAK;gBACL,aAAa,EAAE,CAAC;gBAChB,aAAa,EAAE,eAAe;gBAC9B,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE;aAC9B,CAAC;YAEF,CAAC,CAAC,IAAI,CAAC;gBACL,IAAI,EAAE,QAAQ;gBACd,eAAe,EAAE;oBACf,SAAS;oBACT,SAAS;oBACT,OAAO,EAAE,kBAAkB;iBAC5B;aACF,CAAC,CAAC;QACL,CAAC;KAAA;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;AArFM,QAAA,kBAAkB,sBAqFxB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "../types";
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
export declare const formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
4
|
+
export declare const fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
7
|
+
fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
8
|
+
toTransactionRaw: (t: Transaction) => TransactionRaw;
|
|
9
|
+
fromTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommonRaw) => import("@ledgerhq/types-live").TransactionStatusCommon;
|
|
10
|
+
toTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommon) => import("@ledgerhq/types-live").TransactionStatusCommonRaw;
|
|
11
|
+
formatTransactionStatus: (t: import("@ledgerhq/types-live").TransactionCommon, { errors, warnings, estimatedFees, amount, totalSpent }: import("@ledgerhq/types-live").TransactionStatusCommon, mainAccount: Account) => string;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/bridge/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQ5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAKpD,eAAO,MAAM,iBAAiB,wCACS,WAAW,WACvC,OAAO,KACf,MAYa,CAAC;AAEjB,eAAO,MAAM,kBAAkB,OAAQ,cAAc,KAAG,WAavD,CAAC;;;;;;;;;AAkBF,wBAOE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fromTransactionRaw = exports.formatTransaction = void 0;
|
|
7
|
+
const formatters_1 = require("@ledgerhq/coin-framework/formatters");
|
|
8
|
+
const serialization_1 = require("@ledgerhq/coin-framework/serialization");
|
|
9
|
+
const index_1 = require("@ledgerhq/coin-framework/account/index");
|
|
10
|
+
const index_2 = require("@ledgerhq/coin-framework/currencies/index");
|
|
11
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
12
|
+
const formatTransaction = ({ recipient, useAllAmount, amount }, account) => `
|
|
13
|
+
SEND ${useAllAmount
|
|
14
|
+
? "MAX"
|
|
15
|
+
: amount.isZero()
|
|
16
|
+
? ""
|
|
17
|
+
: " " +
|
|
18
|
+
(0, index_2.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], amount, {
|
|
19
|
+
showCode: true,
|
|
20
|
+
disableRounding: true,
|
|
21
|
+
})}
|
|
22
|
+
TO ${recipient}`;
|
|
23
|
+
exports.formatTransaction = formatTransaction;
|
|
24
|
+
const fromTransactionRaw = (tr) => {
|
|
25
|
+
const common = (0, serialization_1.fromTransactionCommonRaw)(tr);
|
|
26
|
+
return Object.assign(Object.assign({}, common), { family: tr.family, version: tr.version, method: tr.method, nonce: tr.nonce, amount: new bignumber_js_1.default(tr.amount), gasFeeCap: new bignumber_js_1.default(tr.gasFeeCap), gasLimit: new bignumber_js_1.default(tr.gasLimit), gasPremium: new bignumber_js_1.default(tr.gasPremium) });
|
|
27
|
+
};
|
|
28
|
+
exports.fromTransactionRaw = fromTransactionRaw;
|
|
29
|
+
const toTransactionRaw = (t) => {
|
|
30
|
+
const common = (0, serialization_1.toTransactionCommonRaw)(t);
|
|
31
|
+
return Object.assign(Object.assign({}, common), { method: t.method, version: t.version, family: t.family, nonce: t.nonce, amount: t.amount.toFixed(), gasFeeCap: t.gasFeeCap.toString(), gasLimit: t.gasLimit.toNumber(), gasPremium: t.gasPremium.toString() });
|
|
32
|
+
};
|
|
33
|
+
exports.default = {
|
|
34
|
+
formatTransaction: exports.formatTransaction,
|
|
35
|
+
fromTransactionRaw: exports.fromTransactionRaw,
|
|
36
|
+
toTransactionRaw,
|
|
37
|
+
fromTransactionStatusRaw: serialization_1.fromTransactionStatusRawCommon,
|
|
38
|
+
toTransactionStatusRaw: serialization_1.toTransactionStatusRawCommon,
|
|
39
|
+
formatTransactionStatus: formatters_1.formatTransactionStatus,
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/bridge/transaction.ts"],"names":[],"mappings":";;;;;;AACA,oEAA8E;AAC9E,0EAKgD;AAEhD,kEAA4E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B,OAAO,EAAE,CAAC,CAAC,OAAO,EAClB,MAAM,EAAE,CAAC,CAAC,MAAM,EAChB,KAAK,EAAE,CAAC,CAAC,KAAK,EACd,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,EAC1B,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,EACjC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAC/B,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,IACnC;AACJ,CAAC,CAAC;AAEF,kBAAe;IACb,iBAAiB,EAAjB,yBAAiB;IACjB,kBAAkB,EAAlB,0BAAkB;IAClB,gBAAgB;IAChB,wBAAwB,EAAxB,8CAAwB;IACxB,sBAAsB,EAAtB,4CAAsB;IACtB,uBAAuB,EAAvB,oCAAuB;CACxB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
export declare enum Methods {
|
|
5
|
+
Transfer = 0,
|
|
6
|
+
ERC20Transfer = 1,
|
|
7
|
+
InvokeEVM = 3844450837
|
|
8
|
+
}
|
|
9
|
+
export declare enum AccountType {
|
|
10
|
+
Account = "Account",
|
|
11
|
+
TokenAccount = "TokenAccount"
|
|
12
|
+
}
|
|
13
|
+
export declare enum BotScenario {
|
|
14
|
+
DEFAULT = "default",
|
|
15
|
+
ETH_RECIPIENT = "eth-recipient",
|
|
16
|
+
F4_RECIPIENT = "f4-recipient",
|
|
17
|
+
TOKEN_TRANSFER = "token-transfer"
|
|
18
|
+
}
|
|
19
|
+
export declare const isValidHex: (msg: string) => boolean;
|
|
20
|
+
export declare const isValidBase64: (msg: string) => boolean;
|
|
21
|
+
export declare const methodToString: (method: number) => string;
|
|
22
|
+
export declare const getBufferFromString: (message: string) => Buffer;
|
|
23
|
+
export declare const calculateEstimatedFees: (gasFeeCap: BigNumber, gasLimit: BigNumber) => BigNumber;
|
|
24
|
+
export declare function getAccountUnit(account: AccountLike): import("@ledgerhq/types-cryptoassets").Unit;
|
|
25
|
+
export declare const expectedToFieldForTokenTransfer: (recipient: string) => string;
|
|
26
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/bridge/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,oBAAY,OAAO;IACjB,QAAQ,IAAI;IACZ,aAAa,IAAI;IACjB,SAAS,aAAa;CACvB;AAED,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,YAAY,iBAAiB;CAC9B;AAED,oBAAY,WAAW;IACrB,OAAO,YAAY;IACnB,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,cAAc,mBAAmB;CAClC;AASD,eAAO,MAAM,UAAU,QAAS,MAAM,YAAqD,CAAC;AAC5F,eAAO,MAAM,aAAa,QAAS,MAAM,YAAgC,CAAC;AAE1E,eAAO,MAAM,cAAc,WAAY,MAAM,KAAG,MAW/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MAK1B,CAAC;AAE7B,eAAO,MAAM,sBAAsB,cAAe,SAAS,YAAY,SAAS,KAAG,SACjD,CAAC;AAEnC,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,+CAMlD;AAED,eAAO,MAAM,+BAA+B,cAAe,MAAM,WAShE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectedToFieldForTokenTransfer = exports.getAccountUnit = exports.calculateEstimatedFees = exports.getBufferFromString = exports.methodToString = exports.isValidBase64 = exports.isValidHex = exports.BotScenario = exports.AccountType = exports.Methods = void 0;
|
|
4
|
+
const network_1 = require("../network");
|
|
5
|
+
var Methods;
|
|
6
|
+
(function (Methods) {
|
|
7
|
+
Methods[Methods["Transfer"] = 0] = "Transfer";
|
|
8
|
+
Methods[Methods["ERC20Transfer"] = 1] = "ERC20Transfer";
|
|
9
|
+
Methods[Methods["InvokeEVM"] = 3844450837] = "InvokeEVM";
|
|
10
|
+
})(Methods || (exports.Methods = Methods = {}));
|
|
11
|
+
var AccountType;
|
|
12
|
+
(function (AccountType) {
|
|
13
|
+
AccountType["Account"] = "Account";
|
|
14
|
+
AccountType["TokenAccount"] = "TokenAccount";
|
|
15
|
+
})(AccountType || (exports.AccountType = AccountType = {}));
|
|
16
|
+
var BotScenario;
|
|
17
|
+
(function (BotScenario) {
|
|
18
|
+
BotScenario["DEFAULT"] = "default";
|
|
19
|
+
BotScenario["ETH_RECIPIENT"] = "eth-recipient";
|
|
20
|
+
BotScenario["F4_RECIPIENT"] = "f4-recipient";
|
|
21
|
+
BotScenario["TOKEN_TRANSFER"] = "token-transfer";
|
|
22
|
+
})(BotScenario || (exports.BotScenario = BotScenario = {}));
|
|
23
|
+
const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/);
|
|
24
|
+
const validBase64RegExp = new RegExp(/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/);
|
|
25
|
+
// TODO Filecoin - Use the new package @zondax/ledger-utils instead
|
|
26
|
+
const isValidHex = (msg) => validHexRegExp.test(msg) && msg.length % 2 === 0;
|
|
27
|
+
exports.isValidHex = isValidHex;
|
|
28
|
+
const isValidBase64 = (msg) => validBase64RegExp.test(msg);
|
|
29
|
+
exports.isValidBase64 = isValidBase64;
|
|
30
|
+
const methodToString = (method) => {
|
|
31
|
+
switch (method) {
|
|
32
|
+
case Methods.Transfer:
|
|
33
|
+
return "Transfer";
|
|
34
|
+
case Methods.InvokeEVM:
|
|
35
|
+
return "InvokeEVM (3844450837)";
|
|
36
|
+
case Methods.ERC20Transfer:
|
|
37
|
+
return "ERC20 Transfer";
|
|
38
|
+
default:
|
|
39
|
+
return "Unknown";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.methodToString = methodToString;
|
|
43
|
+
const getBufferFromString = (message) => (0, exports.isValidHex)(message)
|
|
44
|
+
? Buffer.from(message, "hex")
|
|
45
|
+
: (0, exports.isValidBase64)(message)
|
|
46
|
+
? Buffer.from(message, "base64")
|
|
47
|
+
: Buffer.from(message);
|
|
48
|
+
exports.getBufferFromString = getBufferFromString;
|
|
49
|
+
const calculateEstimatedFees = (gasFeeCap, gasLimit) => gasFeeCap.multipliedBy(gasLimit);
|
|
50
|
+
exports.calculateEstimatedFees = calculateEstimatedFees;
|
|
51
|
+
function getAccountUnit(account) {
|
|
52
|
+
if (account.type === AccountType.TokenAccount) {
|
|
53
|
+
return account.token.units[0];
|
|
54
|
+
}
|
|
55
|
+
return account.currency.units[0];
|
|
56
|
+
}
|
|
57
|
+
exports.getAccountUnit = getAccountUnit;
|
|
58
|
+
const expectedToFieldForTokenTransfer = (recipient) => {
|
|
59
|
+
let value = recipient;
|
|
60
|
+
const equivalent = (0, network_1.getEquivalentAddress)(value);
|
|
61
|
+
if (equivalent && value != equivalent) {
|
|
62
|
+
value += ` / ${equivalent}`;
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
exports.expectedToFieldForTokenTransfer = expectedToFieldForTokenTransfer;
|
|
67
|
+
//# sourceMappingURL=utils.js.map
|