Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ DMK Eth Signer integration #8931

Open
wants to merge 11 commits into
base: feat/dsdk-508-listen-known-devices
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions .changeset/cuddly-pandas-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/hw-app-eth": patch
---

Move LoadConfig and ResolutionConfig types to @ledgerhq/types-live
5 changes: 5 additions & 0 deletions .changeset/heavy-lobsters-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-dmk": minor
---

Update Transport.listen to emit add and remove events
5 changes: 5 additions & 0 deletions .changeset/honest-seas-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/types-live": patch
---

Add EvmSigner interface, LoadConfig and ResolutionConfig types
5 changes: 5 additions & 0 deletions .changeset/hungry-pillows-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-evm": patch
---

Use EvmSigner interface from @ledgerhq/types-live
5 changes: 5 additions & 0 deletions .changeset/tall-toys-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

use dmk listenToKnownDevices in LLD:useListenToHidDevices
5 changes: 5 additions & 0 deletions .changeset/tame-boats-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Use DMK signer ETH if DMK transport is used instead of legacy hw-app-eth signer
5 changes: 5 additions & 0 deletions .changeset/wise-hairs-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/hw-app-eth": patch
---

Implement EvmSigner class from @ledgerhq/types-live
5 changes: 2 additions & 3 deletions apps/cli/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "nodenext",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand All @@ -10,8 +10,7 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,

"moduleResolution": "node",
"moduleResolution": "nodenext",
"downlevelIteration": true,
"resolveJsonModule": true,
"rootDir": ".",
Expand Down
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@ledgerhq/coin-evm": "workspace:^",
"@ledgerhq/coin-filecoin": "workspace:^",
"@ledgerhq/coin-framework": "workspace:^",
"@ledgerhq/devices": "workspace:*",
"@ledgerhq/devices": "workspace:^",
"@ledgerhq/domain-service": "workspace:^",
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/ethereum-provider": "workspace:^",
Expand All @@ -73,7 +73,7 @@
"@ledgerhq/live-config": "workspace:^",
"@ledgerhq/live-countervalues": "workspace:^",
"@ledgerhq/live-countervalues-react": "workspace:^",
"@ledgerhq/live-dmk": "workspace:*",
"@ledgerhq/live-dmk": "workspace:^",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/live-network": "workspace:^",
"@ledgerhq/live-nft": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Button as BaseButton, InvertTheme } from "@ledgerhq/react-ui";
import { ButtonProps as BaseButtonProps } from "@ledgerhq/react-ui/components/cta/Button";
import { ButtonProps as BaseButtonProps } from "@ledgerhq/react-ui/components/cta/Button/index";
import { useTrack } from "~/renderer/analytics/segment";
import styled from "styled-components";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const RenderLoadingImage = ({
alignItems="center"
data-testid={`device-action-image-loading-${progress}`}
>
<DeviceBlocker />
<AnimationWrapper>
<FramedPicture
frameConfig={getFramedPictureConfig("transfer", deviceModelId, type)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import {
Text,
Theme,
} from "@ledgerhq/react-ui";
import { LockAltMedium } from "@ledgerhq/react-ui/assets/icons";
import { withV3StyleProvider } from "~/renderer/styles/StyleProviderV3";
import DeviceIllustration from "~/renderer/components/DeviceIllustration";
import { Account } from "@ledgerhq/types-live";
Expand Down Expand Up @@ -642,7 +641,7 @@ export const renderLockedDeviceError = ({
return (
<Wrapper id="error-locked-device">
<ErrorBody
Icon={LockAltMedium}
Icon={IconsLegacy.LockAltMedium}
title={t("errors.LockedDeviceError.title")}
description={
productName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ const T = styled(Box).attrs((p: { color?: string; inline?: boolean; ff?: string
width: ${p => (p.inline ? "" : "100%")};
overflow: hidden;
`;
const I = ({ color, children }: { color?: string; children: React.ReactNode }) => (
const I = ({ color = undefined, children }: { color?: string; children: React.ReactNode }) => (
<Box color={color}>{children}</Box>
);
I.defaultProps = {
color: undefined,
};

export type OwnProps = {
unit?: Unit;
val?: BigNumber | number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled, { DefaultTheme, StyledComponent } from "styled-components";
import { Box } from "@ledgerhq/react-ui";
import { BoxProps } from "@ledgerhq/react-ui/components/layout/Box";
import { BoxProps } from "@ledgerhq/react-ui/components/layout/Box/index";

type Props = {
lightSource: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useTranslation } from "react-i18next";
import styled, { DefaultTheme, StyledComponent } from "styled-components";
import { Box, Text, Flex, Icon, Switch } from "@ledgerhq/react-ui";
import { BoxProps } from "@ledgerhq/react-ui/components/layout/Box/index";
import { SwitchProps } from "@ledgerhq/react-ui/components/form/Switch/Switch";
import { TextProps } from "@ledgerhq/react-ui/components/asorted/Text";
import { SwitchProps } from "@ledgerhq/react-ui/components/form/Switch/index";
import { TextProps } from "@ledgerhq/react-ui/components/asorted/Text/index";

export const WaveContainer: StyledComponent<"div", DefaultTheme, BoxProps> = styled(Box).attrs({
position: "absolute",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isStuckOperation } from "@ledgerhq/live-common/operation";
import { InfiniteLoader } from "@ledgerhq/react-ui";
import { WarningSolidMedium } from "@ledgerhq/react-ui/assets/icons";
import { InfiniteLoader, IconsLegacy } from "@ledgerhq/react-ui";
import { Operation } from "@ledgerhq/types-live";
import { TFunction } from "i18next";
import React from "react";
Expand Down Expand Up @@ -31,7 +30,7 @@ const PendingLoadingIcon = ({ displayWarning }: { displayWarning: boolean }): JS
if (displayWarning) {
return (
<Box style={{ verticalAlign: "sub", display: "inline" }}>
<WarningSolidMedium size={12} color={"#FFBD42"} />
<IconsLegacy.WarningSolidMedium size={12} color={"#FFBD42"} />
</Box>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { Account, AccountLike, TransactionCommon } from "@ledgerhq/types-live";
import { useDebounce } from "@ledgerhq/live-common//hooks/useDebounce";
import { useDebounce } from "@ledgerhq/live-common/hooks/useDebounce";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import FormattedVal from "~/renderer/components/FormattedVal";
import BigNumber from "bignumber.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Flex, Text, InfiniteLoader, IconsLegacy } from "@ledgerhq/react-ui";
import styled, { StyledComponent, DefaultTheme } from "styled-components";
import { FlexBoxProps } from "@ledgerhq/react-ui/components/layout/Flex";
import { FlexBoxProps } from "@ledgerhq/react-ui/components/layout/Flex/index";
import { Status } from "../types";

const BorderFlex: StyledComponent<"div", DefaultTheme, FlexBoxProps> = styled(Flex).attrs({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import SeedStep, { SeedPathStatus } from "./SeedStep";
import { analyticsFlowName, StepText } from "./shared";
import OnboardingAppInstallStep from "../../OnboardingAppInstall";
import { getOnboardingStatePolling } from "@ledgerhq/live-common/hw/getOnboardingStatePolling";
import { isAllowedOnboardingStatePollingErrorDmk } from "@ledgerhq/live-dmk";
import ContinueOnDeviceWithAnim from "./ContinueOnDeviceWithAnim";
import { RecoverState } from "~/renderer/screens/recover/Player";
import TrackPage from "~/renderer/analytics/TrackPage";
Expand Down Expand Up @@ -245,6 +246,7 @@ const SyncOnboardingCompanion: React.FC<SyncOnboardingCompanionProps> = ({
device: device || null,
pollingPeriodMs: POLLING_PERIOD_MS,
stopPolling: !isPollingOn,
allowedErrorChecks: [isAllowedOnboardingStatePollingErrorDmk],
});

const handleDeviceReady = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import SyncOnboardingDeviceConnection, {
import SyncOnboardingManual, { SyncOnboardingScreenProps } from "./Manual";
import CompletionScreen from "./Manual/CompletionScreen";
import { useKeepScreenAwake } from "~/renderer/hooks/useKeepScreenAwake";
import { useDeviceSessionRefresherToggle } from "@ledgerhq/live-dmk";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

export type DeviceConnectionRouteProps = RouteComponentProps<SyncOnboardingDeviceConnectionProps>;
export type ManualRouteProps = RouteComponentProps<SyncOnboardingScreenProps>;

const SyncOnboarding = () => {
const ldmkTransportFlag = useFeature("ldmkTransport");
const { path } = useRouteMatch();
useKeepScreenAwake(true);
useDeviceSessionRefresherToggle(ldmkTransportFlag?.enabled ?? false);

return (
<Flex width="100%" height="100%" position="relative">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { NotificationIndicator } from "~/renderer/components/TopBar/Notification
import { setTrackingSource } from "~/renderer/analytics/TrackPage";
import { LiveAppDrawer } from "~/renderer/components/LiveAppDrawer";
import { IconsLegacy } from "@ledgerhq/react-ui";

const Container = styled(Box).attrs(() => ({}))`
height: ${p => p.theme.sizes.topBarHeight}px;
box-sizing: content-box;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React, { useEffect, useMemo } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import logger from "~/renderer/logger";
import Text from "../Text";
import ExternalLink from "../ExternalLink";
Expand Down Expand Up @@ -35,6 +36,7 @@ function ErrorList({ translation }: ErrorListProps) {

export function TranslatedError({ error, fallback, field = "title", noLink }: Props): JSX.Element {
const { t } = useTranslation();
const ldmkTransportFlag = useFeature("ldmkTransport");

const errorName = error?.name;

Expand Down Expand Up @@ -65,7 +67,22 @@ export function TranslatedError({ error, fallback, field = "title", noLink }: Pr
}
}, [isValidError, error]);

if (!error || !isValidError) return <></>;
if (!error || !isValidError) {
// NOTE: Temporary handling of DMK errors
if (ldmkTransportFlag?.enabled && error && "_tag" in error) {
if (field === "description") {
const errorMessage =
"originalError" in error
? (error.originalError as Error).message
: (error._tag as string);

return <Text>{errorMessage}</Text>;
}
return <Text>{error._tag as string}</Text>;
}

return <></>;
}

if (!translation) {
if (fallback) return <>{fallback}</>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { Subscription, Observable } from "rxjs";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { useDeviceManagementKit, DeviceManagementKitTransport } from "@ledgerhq/live-dmk";
import { DeviceModelId } from "@ledgerhq/types-devices";
import { IPCTransport } from "~/renderer/IPCTransport";
import { addDevice, removeDevice, resetDevices } from "~/renderer/actions/devices";
import { IPCTransport } from "../IPCTransport";

export const useListenToHidDevices = () => {
const dispatch = useDispatch();
const ldmkFeatureFlag = useFeature("ldmkTransport");

const deviceManagementKit = useDeviceManagementKit();

useEffect(() => {
let sub: Subscription;
function syncDevices() {
const devices: { [key: string]: boolean } = {};

sub = new Observable(IPCTransport.listen).subscribe(
({ device, deviceModel, type, descriptor }) => {
function syncDevices() {
sub = new Observable(IPCTransport.listen).subscribe({
next: ({ device, deviceModel, type, descriptor }) => {
if (device) {
const deviceId = descriptor || "";
const stateDevice = {
Expand All @@ -23,32 +28,63 @@ export const useListenToHidDevices = () => {
};

if (type === "add") {
devices[deviceId] = true;
dispatch(addDevice(stateDevice));
} else if (type === "remove") {
delete devices[deviceId];
dispatch(removeDevice(stateDevice));
}
}
},
() => {
error: () => {
resetDevices();
syncDevices();
},
() => {
complete: () => {
resetDevices();
syncDevices();
},
);
});
}

function syncDevicesWithDmk() {
sub = new Observable(DeviceManagementKitTransport.listen).subscribe({
next: ({ descriptor, device, deviceModel, type }) => {
if (device) {
const deviceId = descriptor || "";
const stateDevice = {
deviceId,
modelId: deviceModel ? deviceModel.id : DeviceModelId.nanoS,
// TODO: Update the Transport.listen type whenever we switch to LDMK
// @ts-expect-error remapping type
wired: deviceModel?.type === "USB",
};
if (type === "add") {
dispatch(addDevice(stateDevice));
} else if (type === "remove") {
dispatch(removeDevice(stateDevice));
}
}
},
error: () => {
resetDevices();
syncDevicesWithDmk();
},
complete: () => {
resetDevices();
syncDevicesWithDmk();
},
});
}

const timeoutSyncDevices = setTimeout(syncDevices, 1000);
const fn = ldmkFeatureFlag?.enabled ? syncDevicesWithDmk : syncDevices;

const timeoutSyncDevices = setTimeout(fn, 1000);

return () => {
console.log("[[useListenToHidDevices]] cleanup");
clearTimeout?.(timeoutSyncDevices);
sub?.unsubscribe?.();
};
}, [dispatch]);
}, [dispatch, deviceManagementKit, ldmkFeatureFlag?.enabled]);

return null;
};
8 changes: 2 additions & 6 deletions apps/ledger-live-desktop/src/renderer/live-common-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import "~/live-common-setup-base";
import "~/live-common-set-supported-currencies";
import "./families";

import { Store } from "redux";
import VaultTransport from "@ledgerhq/hw-transport-vault";
import { registerTransportModule } from "@ledgerhq/live-common/hw/index";
import { getEnv } from "@ledgerhq/live-env";
import { retry } from "@ledgerhq/live-common/promise";
import { TraceContext, listen as listenLogs, trace } from "@ledgerhq/logs";
import { getUserId } from "~/helpers/user";
Expand All @@ -13,13 +15,7 @@ import logger from "./logger";
import { setDeviceMode } from "@ledgerhq/live-common/hw/actions/app";
import { getFeature } from "@ledgerhq/live-common/featureFlags/index";
import { overriddenFeatureFlagsSelector } from "~/renderer/reducers/settings";
import { State } from "./reducers";
import { DeviceManagementKitTransport } from "@ledgerhq/live-dmk";
import { getEnv } from "@ledgerhq/live-env";

interface Store {
getState: () => State;
}

const isDeviceManagementKitEnabled = (store: Store) => {
const state = store.getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Box from "~/renderer/components/Box";
import { Flex } from "@ledgerhq/react-ui";
import Text from "~/renderer/components/Text";
import ExternalLinkIcon from "~/renderer/icons/ExternalLink";
import { FlexBoxProps } from "@ledgerhq/react-ui/components/layout/Flex";
import { FlexBoxProps } from "@ledgerhq/react-ui/components/layout/Flex/index";

export const Wrapper = styled(Box).attrs({
alignItems: "center",
Expand Down
Loading
Loading