Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into support/hotfix-mer…
Browse files Browse the repository at this point in the history
…ge-conflicts
  • Loading branch information
jdabbech-ledger committed Feb 23, 2024
2 parents 9ce03e3 + 52d69c8 commit a24eef8
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-rockets-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Replace `@zondax/izari-filecoin` deprecated library by `iso-filecoin`.
2 changes: 1 addition & 1 deletion libs/ledger-live-common/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ yarn upgrade-interactive -i --latest
| TBD DEPRECATE? |
| algosdk | Algorand coin integration | monthly |
| @zondax/ledger-filecoin | Filecoin coin integration | monthly |
| @zondax/izari-filecoin | Filecoin coin integration | monthly |
| @zondax/ledger-stacks | Stacks coin integration | monthly |
| async | ??? | UNCLEAR IF USED |
| axios | network | monthly |
Expand Down Expand Up @@ -89,6 +88,7 @@ yarn upgrade-interactive -i --latest
| generic-pool | Bitcoin coin integration | monthly |
| invariant | generic helper | monthly |
| isomorphic-ws | WebSocket helper | monthly |
| iso-filecoin | Filecoin coin integration | monthly |
| json-rpc-2.0 | Ethereum coin integration | monthly |
| lodash | generic helper | monthly |
| long | Osmosis coin integration | monthly |
Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
"@types/redux-actions": "^2.6.2",
"@xstate/react": "^1.6.3",
"@zondax/cbor": "v8.1.0-zondax-no-bigint",
"@zondax/izari-filecoin": "^1.2.0",
"@zondax/ledger-casper": "^2.6.1",
"@zondax/ledger-cosmos-js": "^3.0.3",
"@zondax/ledger-filecoin": "^0.11.2",
Expand Down Expand Up @@ -222,6 +221,7 @@
"expect": "^27.4.6",
"fuse.js": "^6.6.2",
"invariant": "^2.2.2",
"iso-filecoin": "^4.0.3",
"isomorphic-ws": "^4.0.1",
"json-rpc-2.0": "^0.2.19",
"lodash": "^4.17.21",
Expand Down
10 changes: 4 additions & 6 deletions libs/ledger-live-common/src/families/filecoin/bridge/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
import { BigNumber } from "bignumber.js";
import Fil from "@zondax/ledger-filecoin";
import { Observable } from "rxjs";
import { Address } from "@zondax/izari-filecoin/address";
import { Methods } from "@zondax/izari-filecoin/artifacts";

import { makeAccountBridgeReceive, makeSync } from "../../../bridge/jsHelpers";
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
Expand All @@ -29,9 +27,9 @@ import { BroadcastBlockIncl } from "./utils/types";
import { getMainAccount } from "../../../account";
import { close } from "../../../hw";
import { toCBOR } from "./utils/serializer";
import { calculateEstimatedFees, getPath, isError } from "../utils";
import { Methods, calculateEstimatedFees, getPath, isError } from "../utils";
import { log } from "@ledgerhq/logs";
import { validateAddress } from "./utils/addresses";
import { isFilEthAddress, validateAddress } from "./utils/addresses";
import { encodeOperationId, patchOperationWithHash } from "../../../operation";
import { withDevice } from "../../../hw/deviceAccess";

Expand Down Expand Up @@ -133,7 +131,7 @@ const estimateMaxSpendable = async ({
}
recipient = recipientValidation.parsedAddress.toString();

methodNum = Address.isFilEthAddress(recipientValidation.parsedAddress)
methodNum = isFilEthAddress(recipientValidation.parsedAddress)
? Methods.InvokeEVM
: Methods.Transfer;
}
Expand Down Expand Up @@ -177,7 +175,7 @@ const prepareTransaction = async (a: Account, t: Transaction): Promise<Transacti
if (recipientValidation.isValid && senderValidation.isValid) {
const patch: Partial<Transaction> = {};

const method = Address.isFilEthAddress(recipientValidation.parsedAddress)
const method = isFilEthAddress(recipientValidation.parsedAddress)
? Methods.InvokeEVM
: Methods.Transfer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { Address } from "@zondax/izari-filecoin/address";
import { NetworkPrefix } from "@zondax/izari-filecoin/artifacts";
import { IAddress, PROTOCOL_INDICATOR, fromEthAddress, fromString } from "iso-filecoin/address";
import { log } from "@ledgerhq/logs";

export type ValidateAddressResult =
| {
isValid: true;
parsedAddress: Address;
parsedAddress: IAddress;
}
| {
isValid: false;
};

export const isFilEthAddress = (addr: IAddress) =>
addr.protocol === PROTOCOL_INDICATOR.DELEGATED && addr.namespace === 10;

export const validateAddress = (input: string): ValidateAddressResult => {
try {
const parsedAddress = Address.fromString(input);
const parsedAddress = fromString(input);
return { isValid: true, parsedAddress };
} catch (error) {
log("debug", `[validateAddress] fromString invalid address`);
}

try {
const parsedAddress = Address.fromEthAddress(NetworkPrefix.Mainnet, input);
// allow non 0x starting eth addresses as well
if (!input.startsWith("0x")) input = "0x" + input;
const parsedAddress = fromEthAddress(input, "mainnet");
return { isValid: true, parsedAddress };
} catch (error) {
log("debug", `[validateAddress] fromEthAddress invalid address`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export const toCBOR = (
answer.push(version);

// "to" field
answer.push(recipientValidation.parsedAddress.toBytes());
answer.push(Buffer.from(recipientValidation.parsedAddress.toBytes()));

// "from" field
answer.push(fromValidation.parsedAddress.toBytes());
answer.push(Buffer.from(fromValidation.parsedAddress.toBytes()));

// "nonce" field
answer.push(nonce);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address } from "@zondax/izari-filecoin/address";
import { Methods, NetworkPrefix } from "@zondax/izari-filecoin/artifacts";
import type { DeviceAction } from "../../bot/types";
import type { Transaction } from "./types";
import { deviceActionFlow, formatDeviceAmount, SpeculosButton } from "../../bot/specs";
import { BotScenario } from "./utils";
import { BotScenario, Methods } from "./utils";
import { isFilEthAddress } from "./bridge/utils/addresses";
import { fromEthAddress, fromString, toEthAddress } from "iso-filecoin/address";

export const generateDeviceActionFlow = (scenario: BotScenario): DeviceAction<Transaction, any> => {
const data: Parameters<typeof deviceActionFlow<Transaction>>[0] = { steps: [] };
Expand All @@ -18,9 +18,9 @@ export const generateDeviceActionFlow = (scenario: BotScenario): DeviceAction<Tr
title: "To",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => {
const addr = Address.fromString(transaction.recipient);
if (Address.isFilEthAddress(addr)) {
return addr.toEthAddressHex(true) + transaction.recipient;
const addr = fromString(transaction.recipient);
if (isFilEthAddress(addr)) {
return toEthAddress(addr) + transaction.recipient;
}
return "unexpected flow... address should be eth type";
},
Expand All @@ -30,7 +30,7 @@ export const generateDeviceActionFlow = (scenario: BotScenario): DeviceAction<Tr
title: "To",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => {
const addr = Address.fromEthAddress(NetworkPrefix.Mainnet, transaction.recipient);
const addr = fromEthAddress(transaction.recipient, "mainnet");
return transaction.recipient + addr.toString();
},
});
Expand Down
6 changes: 5 additions & 1 deletion libs/ledger-live-common/src/families/filecoin/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { BigNumber } from "bignumber.js";
import { Methods } from "@zondax/izari-filecoin/artifacts";

export enum Methods {
Transfer = 0,
InvokeEVM = 3844450837,
}

export enum BotScenario {
DEFAULT = "default",
Expand Down
Loading

0 comments on commit a24eef8

Please sign in to comment.