Skip to content

Commit

Permalink
fix: eth_signTransaction signer verification for Celo (reown-com#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
kathaypacific authored Dec 21, 2022
1 parent 6aabae1 commit 5817d5e
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 22 deletions.
2 changes: 2 additions & 0 deletions dapps/react-dapp-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx}'"
},
"dependencies": {
"@celo/wallet-base": "^3.0.1",
"@elrondnetwork/erdjs": "11.1.1",
"@elrondnetwork/erdjs-walletcore": "2.1.0",
"@ethereumjs/tx": "^3.5.0",
Expand All @@ -28,6 +29,7 @@
"eth-sig-util": "^2.5.3",
"ethereumjs-util": "^7.0.6",
"ethers": "^5.3.0",
"fp-ts": "^2.13.1",
"next": "12.2.4",
"prop-types": "^15.7.2",
"qr-image": "^3.2.0",
Expand Down
20 changes: 17 additions & 3 deletions dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createContext, ReactNode, useContext, useState } from "react";
import * as encoding from "@walletconnect/encoding";
import { TypedDataField } from "@ethersproject/abstract-signer";
import { Transaction as EthTransaction } from "@ethereumjs/tx";
import { recoverTransaction } from "@celo/wallet-base";
import {
formatDirectSignDoc,
stringifySignDocValues,
Expand Down Expand Up @@ -252,9 +253,22 @@ export function JsonRpcContextProvider({
},
});

const valid = EthTransaction.fromSerializedTx(
signedTx as any
).verifySignature();
const CELO_ALFAJORES_CHAIN_ID = 44787;
const CELO_MAINNET_CHAIN_ID = 42220;

let valid = false;
const [, reference] = chainId.split(":");
if (
reference === CELO_ALFAJORES_CHAIN_ID.toString() ||
reference === CELO_MAINNET_CHAIN_ID.toString()
) {
const [, signer] = recoverTransaction(signedTx);
valid = signer.toLowerCase() === address.toLowerCase();
} else {
valid = EthTransaction.fromSerializedTx(
signedTx as any
).verifySignature();
}

return {
method: DEFAULT_EIP155_METHODS.ETH_SIGN_TRANSACTION,
Expand Down
Loading

0 comments on commit 5817d5e

Please sign in to comment.