Skip to content

Commit

Permalink
fix: Use proper chain ID for signTypedData example
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jan 14, 2025
1 parent 493eedc commit 8fc722a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "T/7hin+Vhg0SdK8RxXvonPhkTRe/luTzGwqfWrH/8MQ=",
"shasum": "1QLc9RhVgpwxBu8FjPo5kZY61mpNoNAfkiAatq99Nc4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
12 changes: 10 additions & 2 deletions packages/examples/packages/ethereum-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import {
type OnRpcRequestHandler,
} from '@metamask/snaps-sdk';
import type { Hex } from '@metamask/utils';
import { assert, stringToBytes, bytesToHex } from '@metamask/utils';
import {
assert,
stringToBytes,
bytesToHex,
hexToNumber,
} from '@metamask/utils';

import type { PersonalSignParams, SignTypedDataParams } from './types';

Expand Down Expand Up @@ -107,6 +112,9 @@ async function personalSign(message: string, from: string) {
* @see https://docs.metamask.io/wallet/concepts/signing-methods/#eth_signtypeddata_v4
*/
async function signTypedData(message: string, from: string) {
const chainId = (await ethereum.request<string>({
method: 'eth_chainId',
})) as string;
const signature = await ethereum.request<Hex>({
method: 'eth_signTypedData_v4',
params: [
Expand Down Expand Up @@ -160,7 +168,7 @@ async function signTypedData(message: string, from: string) {
domain: {
name: 'Ether Mail',
version: '1',
chainId: 1,
chainId: hexToNumber(chainId),
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
},
message: {
Expand Down

0 comments on commit 8fc722a

Please sign in to comment.