Skip to content

Commit 96c2046

Browse files
mmv08claudejxom
authored
fix: handle bigint chainId in TypedData.extractEip712DomainTypes (#98)
* fix: handle bigint chainId in TypedData.extractEip712DomainTypes Fixes #97 where TypedData.getSignPayload produced invalid EIP-712 hash when chainId was passed as bigint instead of number. The extractEip712DomainTypes function now correctly handles both number and bigint types for chainId field. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Update late-kings-promise.md --------- Co-authored-by: Claude <[email protected]> Co-authored-by: jxom <[email protected]>
1 parent cad577e commit 96c2046

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.changeset/late-kings-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ox": patch
3+
---
4+
5+
Added handling for `bigint` chain IDs in `TypedData.extractEip712DomainTypes`.

src/core/TypedData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ export function extractEip712DomainTypes(
394394
return [
395395
typeof domain?.name === 'string' && { name: 'name', type: 'string' },
396396
domain?.version && { name: 'version', type: 'string' },
397-
typeof domain?.chainId === 'number' && {
397+
(typeof domain?.chainId === 'number' ||
398+
typeof domain?.chainId === 'bigint') && {
398399
name: 'chainId',
399400
type: 'uint256',
400401
},

src/core/_test/TypedData.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,37 @@ describe('getSignPayload', () => {
780780
)
781781
})
782782

783+
test('domain: bigint chainId produces same hash as number chainId', () => {
784+
const typedDataWithNumberChainId = {
785+
domain: {
786+
name: 'Test',
787+
version: '1',
788+
chainId: 1,
789+
verifyingContract: '0x0000000000000000000000000000000000000000',
790+
},
791+
types: {
792+
Message: [{ name: 'content', type: 'string' }],
793+
},
794+
primaryType: 'Message',
795+
message: {
796+
content: 'Hello World',
797+
},
798+
} as const
799+
800+
const typedDataWithBigintChainId = {
801+
...typedDataWithNumberChainId,
802+
domain: {
803+
...typedDataWithNumberChainId.domain,
804+
chainId: 1n,
805+
},
806+
}
807+
808+
const hashWithNumber = TypedData.getSignPayload(typedDataWithNumberChainId)
809+
const hashWithBigint = TypedData.getSignPayload(typedDataWithBigintChainId)
810+
811+
expect(hashWithNumber).toBe(hashWithBigint)
812+
})
813+
783814
test('minimal valid typed message', () => {
784815
const payload = TypedData.getSignPayload({
785816
types: {

0 commit comments

Comments
 (0)