@@ -2,12 +2,9 @@ import { GnosisApiStrategy } from "./gnosisApi";
2
2
import { SafeTransaction } from '@safe-global/types-kit' ;
3
3
import { getEip712TxTypes } from "@safe-global/protocol-kit/dist/src/utils/eip-712/index"
4
4
import { getDefaultProvider } from 'ethers'
5
- import ora from "ora" ;
6
- import chalk from "chalk" ;
7
5
import { checkShouldSignGnosisMessage , pressAnyButtonToContinue } from "../../../../commands/prompts" ;
8
6
import { getLedgerSigner } from "../../ledgerTransport" ;
9
- import { TypedDataField } from "ethers" ;
10
- import { createPublicClient , getContract , http , verifyTypedData } from "viem" ;
7
+ import { createPublicClient , getContract , http , verifyMessage } from "viem" ;
11
8
import { ICachedArg , TStrategyOptions } from "../../../strategy" ;
12
9
import { SavebleDocument , Transaction } from "../../../../metadata/metadataStore" ;
13
10
import { TDeploy } from "../../../../metadata/schema" ;
@@ -16,6 +13,7 @@ import { JsonRpcProvider } from "ethers";
16
13
import * as AllChains from 'viem/chains' ;
17
14
import { abi } from "../onchain/Safe" ;
18
15
import { ethers } from 'ethers' ;
16
+ import { calculateSafeTransactionHash } from "@safe-global/protocol-kit/dist/src/utils" ;
19
17
20
18
export class GnosisLedgerStrategy extends GnosisApiStrategy {
21
19
id = "gnosis.api.ledger" ;
@@ -42,7 +40,6 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
42
40
43
41
const signer = await getLedgerSigner ( provider , derivationPath ) ;
44
42
const types = getEip712TxTypes ( version ) ;
45
-
46
43
const typedDataArgs = {
47
44
types : { SafeTx : types . SafeTx } ,
48
45
domain : {
@@ -60,6 +57,9 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
60
57
}
61
58
} as const ;
62
59
60
+ const gnosisHash = calculateSafeTransactionHash ( safeAddress , txn . data , version , BigInt ( this . deploy . _ . chainId ) ) ;
61
+ console . log ( `Expected gnosis hash: ${ gnosisHash } ` ) ;
62
+
63
63
await checkShouldSignGnosisMessage ( typedDataArgs ) ;
64
64
65
65
console . log ( `Signing with ledger (please check your device for instructions)...` ) ;
@@ -68,17 +68,15 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
68
68
const addr = await signer . getAddress ( ) as `0x${string } `;
69
69
console . log ( `The ledger reported this address: ${ addr } ` ) ;
70
70
71
- const signature = await signer . signTypedData (
72
- typedDataArgs . domain ,
73
- { SafeTx : typedDataArgs . types . SafeTx } ,
74
- typedDataArgs . message
71
+ const signature = await signer . signMessage (
72
+ gnosisHash
75
73
) as `0x${string } `
76
74
77
- const fromAddr = ethers . verifyTypedData ( typedDataArgs . domain , { SafeTx : typedDataArgs . types . SafeTx } , typedDataArgs . message , signature ) ;
78
- if ( fromAddr !== addr ) {
75
+ const valid = await verifyMessage ( { address : addr , message : gnosisHash , signature} ) ;
76
+ if ( ! valid ) {
79
77
console . error ( `Failed to verify signature. Nothing will be submitted. (signed from ${ addr } )` ) ;
80
- console . warn ( `Typed data: ` , typedDataArgs ) ;
81
78
console . warn ( `Signature: ${ signature } ` ) ;
79
+ console . warn ( `Gnosis Hash: ${ gnosisHash } ` ) ;
82
80
console . warn ( `From: ${ addr } ` ) ;
83
81
throw new Error ( `Invalid signature. Failed to verify typedData.` ) ;
84
82
} else {
0 commit comments