Skip to content

Commit ae98f25

Browse files
committed
[1.0.8] use calculateTransactionHash directly
1 parent 347a416 commit ae98f25

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@layr-labs/zeus",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "web3 deployer / metadata manager",
55
"main": "src/index.ts",
66
"scripts": {

src/signing/strategies/gnosis/api/gnosisLedger.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import { GnosisApiStrategy } from "./gnosisApi";
22
import { SafeTransaction } from '@safe-global/types-kit';
33
import { getEip712TxTypes } from "@safe-global/protocol-kit/dist/src/utils/eip-712/index"
44
import { getDefaultProvider } from 'ethers'
5-
import ora from "ora";
6-
import chalk from "chalk";
75
import { checkShouldSignGnosisMessage, pressAnyButtonToContinue } from "../../../../commands/prompts";
86
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";
118
import { ICachedArg, TStrategyOptions } from "../../../strategy";
129
import { SavebleDocument, Transaction } from "../../../../metadata/metadataStore";
1310
import { TDeploy } from "../../../../metadata/schema";
@@ -16,6 +13,7 @@ import { JsonRpcProvider } from "ethers";
1613
import * as AllChains from 'viem/chains';
1714
import { abi } from "../onchain/Safe";
1815
import { ethers } from 'ethers';
16+
import { calculateSafeTransactionHash } from "@safe-global/protocol-kit/dist/src/utils";
1917

2018
export class GnosisLedgerStrategy extends GnosisApiStrategy {
2119
id = "gnosis.api.ledger";
@@ -42,7 +40,6 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
4240

4341
const signer = await getLedgerSigner(provider, derivationPath);
4442
const types = getEip712TxTypes(version);
45-
4643
const typedDataArgs = {
4744
types: {SafeTx: types.SafeTx},
4845
domain: {
@@ -60,6 +57,9 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
6057
}
6158
} as const;
6259

60+
const gnosisHash = calculateSafeTransactionHash(safeAddress, txn.data, version, BigInt(this.deploy._.chainId));
61+
console.log(`Expected gnosis hash: ${gnosisHash}`);
62+
6363
await checkShouldSignGnosisMessage(typedDataArgs);
6464

6565
console.log(`Signing with ledger (please check your device for instructions)...`);
@@ -68,17 +68,15 @@ export class GnosisLedgerStrategy extends GnosisApiStrategy {
6868
const addr = await signer.getAddress() as `0x${string}`;
6969
console.log(`The ledger reported this address: ${addr}`);
7070

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
7573
) as `0x${string}`
7674

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) {
7977
console.error(`Failed to verify signature. Nothing will be submitted. (signed from ${addr})`);
80-
console.warn(`Typed data: `, typedDataArgs);
8178
console.warn(`Signature: ${signature}`);
79+
console.warn(`Gnosis Hash: ${gnosisHash}`);
8280
console.warn(`From: ${addr}`);
8381
throw new Error(`Invalid signature. Failed to verify typedData.`);
8482
} else {

0 commit comments

Comments
 (0)