@ledgerhq/coin-filecoin
Version:
Ledger Filecoin Coin integration
57 lines • 2.24 kB
JavaScript
import { getEquivalentAddress } from "../network";
export var Methods;
(function (Methods) {
Methods[Methods["Transfer"] = 0] = "Transfer";
Methods[Methods["ERC20Transfer"] = 1] = "ERC20Transfer";
Methods[Methods["InvokeEVM"] = 3844450837] = "InvokeEVM";
})(Methods || (Methods = {}));
export var AccountType;
(function (AccountType) {
AccountType["Account"] = "Account";
AccountType["TokenAccount"] = "TokenAccount";
})(AccountType || (AccountType = {}));
export var BotScenario;
(function (BotScenario) {
BotScenario["DEFAULT"] = "default";
BotScenario["ETH_RECIPIENT"] = "eth-recipient";
BotScenario["F4_RECIPIENT"] = "f4-recipient";
BotScenario["TOKEN_TRANSFER"] = "token-transfer";
})(BotScenario || (BotScenario = {}));
const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/);
const validBase64RegExp = new RegExp(/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/);
// TODO Filecoin - Use the new package @zondax/ledger-utils instead
export const isValidHex = (msg) => validHexRegExp.test(msg) && msg.length % 2 === 0;
export const isValidBase64 = (msg) => validBase64RegExp.test(msg);
export const methodToString = (method) => {
switch (method) {
case Methods.Transfer:
return "Transfer";
case Methods.InvokeEVM:
return "InvokeEVM (3844450837)";
case Methods.ERC20Transfer:
return "ERC20 Transfer";
default:
return "Unknown";
}
};
export const getBufferFromString = (message) => isValidHex(message)
? Buffer.from(message, "hex")
: isValidBase64(message)
? Buffer.from(message, "base64")
: Buffer.from(message);
export const calculateEstimatedFees = (gasFeeCap, gasLimit) => gasFeeCap.multipliedBy(gasLimit);
export function getAccountUnit(account) {
if (account.type === AccountType.TokenAccount) {
return account.token.units[0];
}
return account.currency.units[0];
}
export const expectedToFieldForTokenTransfer = (recipient) => {
let value = recipient;
const equivalent = getEquivalentAddress(value);
if (equivalent && value != equivalent) {
value += ` / ${equivalent}`;
}
return value;
};
//# sourceMappingURL=utils.js.map