Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/provider/signing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ describe('signing', () => {
const domain = {
name: 'Ether Mail',
version: '1',
chainId: '1',
chainId: 1,
verifyingContract: '0xcccccccccccccccccccccccccccccccccccccccc',
}

const domainNoChain = {
name: 'Ether Mail',
version: '1',
verifyingContract: '0xcccccccccccccccccccccccccccccccccccccccc',
}

Expand Down Expand Up @@ -98,6 +104,15 @@ describe('signing', () => {
expect(JSON.parse(data)).toEqual(expect.objectContaining({ domain, message: value }))
})

it('does not fail when domain.chainId is not defined', async () => {
const send = jest.spyOn(signer.provider, 'send').mockImplementationOnce(() => Promise.resolve())

await signTypedData(signer, domainNoChain, types, value)
expect(send).toHaveBeenCalledTimes(1)
const data = send.mock.lastCall[1]?.[1]
expect(JSON.parse(data)).toEqual(expect.objectContaining({ domain: domainNoChain, message: value }))
})

itFallsBackToEthSignIfUnimplemented('eth_signTypedData_v4')
itFailsIfRejected('eth_signTypedData_v4')

Expand Down
7 changes: 6 additions & 1 deletion src/provider/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export async function signTypedData(

const method = supportsV4(signer.provider) ? 'eth_signTypedData_v4' : 'eth_signTypedData'
const address = (await signer.getAddress()).toLowerCase()
const message = JSON.stringify(_TypedDataEncoder.getPayload(populated.domain, types, populated.value))
const payload = _TypedDataEncoder.getPayload(populated.domain, types, populated.value)

// TODO(WEB-000): remove string to number parsing after Ethers v6 migration
payload.domain.chainId = payload.domain.chainId != null ? Number(payload.domain.chainId) : undefined

const message = JSON.stringify(payload)

try {
return await signer.provider.send(method, [address, message])
Expand Down