Skip to content

Commit

Permalink
feat: eip712 clear sign on ledger, close #1816
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Nov 1, 2023
1 parent 71d9bfa commit 8de38de
Show file tree
Hide file tree
Showing 3 changed files with 442 additions and 87 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"@gnosis.pm/safe-core-sdk": "^1.1.1",
"@gnosis.pm/safe-core-sdk-types": "^0.1.1",
"@keystonehq/metamask-airgapped-keyring": "^0.2.5-alpha.0",
"@ledgerhq/devices": "^7.0.5",
"@ledgerhq/hw-app-eth": "^6.25.0",
"@ledgerhq/hw-transport-webhid": "^6.24.1",
"@ledgerhq/devices": "^8.0.7",
"@ledgerhq/hw-app-eth": "^6.34.8",
"@ledgerhq/hw-transport-webhid": "^6.27.19",
"@metamask/browser-passworder": "^4.1.0",
"@metamask/eth-sig-util": "5.1.0",
"@metamask/obs-store": "^6.0.2",
Expand Down
31 changes: 26 additions & 5 deletions src/background/service/keyring/eth-ledger-bridge-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,11 +718,32 @@ class LedgerBridgeKeyring extends EventEmitter {
if (this.isWebHID) {
try {
await this.makeApp(true);
const res = await this.app!.signEIP712HashedMessage(
hdPath,
domainSeparatorHex,
hashStructMessageHex
);

let res:
| {
v: number;
s: string;
r: string;
}
| undefined;
// https://github.com/LedgerHQ/ledger-live/blob/5bae039273beeeb02d8640d778fd7bf5f7fd3776/libs/coin-evm/src/hw-signMessage.ts#L68C7-L79C10
try {
res = await this.app!.signEIP712Message(hdPath, data);
} catch (e) {
if (
e instanceof Error &&
'statusText' in e &&
(e as any).statusText === 'INS_NOT_SUPPORTED'
) {
res = await this.app!.signEIP712HashedMessage(
hdPath,
domainSeparatorHex,
hashStructMessageHex
);
}
throw e;
}

let v = res.v.toString(16);
if (v.length < 2) {
v = `0${v}`;
Expand Down
Loading

0 comments on commit 8de38de

Please sign in to comment.