From cd3308334b16984e962ac0a4f084ea107f61d999 Mon Sep 17 00:00:00 2001 From: Louis Aussedat Date: Tue, 3 Sep 2024 11:41:20 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20(sample):=20Implement=20signTra?= =?UTF-8?q?nsaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sample/package.json | 1 + .../src/components/KeyringEthView/index.tsx | 36 ++++++++++++++++++- pnpm-lock.yaml | 20 +++-------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/apps/sample/package.json b/apps/sample/package.json index e18776101..686d53710 100644 --- a/apps/sample/package.json +++ b/apps/sample/package.json @@ -17,6 +17,7 @@ "@ledgerhq/keyring-eth": "workspace:*", "@ledgerhq/react-ui": "^0.15.3", "@sentry/nextjs": "^8.27.0", + "ethers": "^6.13.2", "next": "14.2.6", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/apps/sample/src/components/KeyringEthView/index.tsx b/apps/sample/src/components/KeyringEthView/index.tsx index 770fa4890..afba23dae 100644 --- a/apps/sample/src/components/KeyringEthView/index.tsx +++ b/apps/sample/src/components/KeyringEthView/index.tsx @@ -14,12 +14,16 @@ import { SignTypedDataDAOutput, KeyringEthBuilder, TypedData, + SignTransactionDAOutput, + SignTransactionDAError, + SignTransactionDAIntermediateValue, } from "@ledgerhq/keyring-eth"; import { DeviceAction, DeviceActionProps, } from "@/components/DeviceActionsView/DeviceAction"; import { PageWithHeader } from "@/components/PageWithHeader"; +import { ethers } from "ethers"; export const KeyringEthView: React.FC<{ sessionId: string }> = ({ sessionId, @@ -60,7 +64,7 @@ export const KeyringEthView: React.FC<{ sessionId: string }> = ({ GetAddressDAIntermediateValue >, { - title: "Sign Message", + title: "Sign message", description: "Perform all the actions necessary to sign a message with the device", executeDeviceAction: ({ derivationPath, message }) => { @@ -79,6 +83,36 @@ export const KeyringEthView: React.FC<{ sessionId: string }> = ({ SignPersonalMessageDAError, SignPersonalMessageDAIntermediateValue >, + { + title: "Sign transaction", + description: + "Perform all the actions necessary to sign a transaction with the device", + executeDeviceAction: ({ + derivationPath, + transaction, + recipientDomain, + }) => { + return keyring.signTransaction( + derivationPath, + ethers.Transaction.from(transaction), + { domain: recipientDomain }, + ); + }, + initialValues: { + derivationPath: "44'/60'/0'/0/0", + transaction: "", + recipientDomain: "", + }, + } satisfies DeviceActionProps< + SignTransactionDAOutput, + { + derivationPath: string; + transaction: string; + recipientDomain: string; + }, + SignTransactionDAError, + SignTransactionDAIntermediateValue + >, { title: "Sign typed message", description: diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a9fe7fb19..08bd10aef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ importers: '@sentry/nextjs': specifier: ^8.27.0 version: 8.27.0(@opentelemetry/api@1.9.0)(@opentelemetry/core@1.25.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.52.1(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.25.1(@opentelemetry/api@1.9.0))(next@14.2.6(@babel/core@7.24.7)(@opentelemetry/api@1.9.0)(babel-plugin-macros@3.1.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(webpack@5.92.1) + ethers: + specifier: ^6.13.2 + version: 6.13.2 next: specifier: 14.2.6 version: 14.2.6(@babel/core@7.24.7)(@opentelemetry/api@1.9.0)(babel-plugin-macros@3.1.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -6467,7 +6470,7 @@ snapshots: '@babel/helpers': 7.24.4 '@babel/parser': 7.24.4 '@babel/template': 7.24.0 - '@babel/traverse': 7.24.1 + '@babel/traverse': 7.24.1(supports-color@5.5.0) '@babel/types': 7.24.0 convert-source-map: 2.0.0 debug: 4.3.5(supports-color@5.5.0) @@ -7545,21 +7548,6 @@ snapshots: '@babel/parser': 7.24.7 '@babel/types': 7.24.7 - '@babel/traverse@7.24.1': - dependencies: - '@babel/code-frame': 7.24.7 - '@babel/generator': 7.24.7 - '@babel/helper-environment-visitor': 7.22.20 - '@babel/helper-function-name': 7.23.0 - '@babel/helper-hoist-variables': 7.22.5 - '@babel/helper-split-export-declaration': 7.22.6 - '@babel/parser': 7.24.7 - '@babel/types': 7.24.7 - debug: 4.3.5(supports-color@5.5.0) - globals: 11.12.0 - transitivePeerDependencies: - - supports-color - '@babel/traverse@7.24.1(supports-color@5.5.0)': dependencies: '@babel/code-frame': 7.24.2 From ccd1464254cad4ac5b823cb6ba9fc5eb32596582 Mon Sep 17 00:00:00 2001 From: Louis Aussedat Date: Thu, 29 Aug 2024 11:12:21 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A9=B9=20(sample):=20Fix=20duplicate?= =?UTF-8?q?=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sample/src/components/DeviceActionsView/DeviceAction.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/sample/src/components/DeviceActionsView/DeviceAction.tsx b/apps/sample/src/components/DeviceActionsView/DeviceAction.tsx index 483c9725a..c2a121444 100644 --- a/apps/sample/src/components/DeviceActionsView/DeviceAction.tsx +++ b/apps/sample/src/components/DeviceActionsView/DeviceAction.tsx @@ -190,7 +190,9 @@ export function DeviceActionDrawer< {responses.map((response, index, arr) => { const isLatest = index === arr.length - 1; return ( - +