Skip to content

Commit

Permalink
feat: derive eip-712 type
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Nov 18, 2024
1 parent a2688ea commit 6e4b635
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-drinks-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ox": patch
---

Derive EIP-712 Domain type if not provided in `TypedData.serialize`.
4 changes: 2 additions & 2 deletions src/core/TypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ export function serialize<
}

const domain = (() => {
if (!types.EIP712Domain) return {}
if (!domain_) return {}
return normalizeData(types.EIP712Domain, domain_)
const type = types.EIP712Domain ?? extractEip712DomainTypes(domain_)
return normalizeData(type, domain_)
})()

const message = (() => {
Expand Down
10 changes: 5 additions & 5 deletions src/core/_test/TypedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ describe('serialize', () => {
},
}),
).toMatchInlineSnapshot(
`"{"domain":{},"message":{"address":"0xb9cab4f0e46f7f6b1024b5a7463734fa68e633f9","name":"jxom","foo":"0xb9CAB4F0E46F7F6b1024b5A7463734fa68E633f9"},"primaryType":"Foo","types":{"Foo":[{"name":"address","type":"address"},{"name":"name","type":"string"},{"name":"foo","type":"string"}]}}"`,
`"{"domain":{"name":"Ether!","version":"1","chainId":1,"verifyingContract":"0xcccccccccccccccccccccccccccccccccccccccc"},"message":{"address":"0xb9cab4f0e46f7f6b1024b5a7463734fa68e633f9","name":"jxom","foo":"0xb9CAB4F0E46F7F6b1024b5A7463734fa68E633f9"},"primaryType":"Foo","types":{"Foo":[{"name":"address","type":"address"},{"name":"name","type":"string"},{"name":"foo","type":"string"}]}}"`,
)
})

Expand Down Expand Up @@ -1444,6 +1444,10 @@ test('InvalidPrimaryTypeError', () => {
test('exports', () => {
expect(Object.keys(TypedData)).toMatchInlineSnapshot(`
[
"BytesSizeMismatchError",
"InvalidDomainError",
"InvalidPrimaryTypeError",
"InvalidStructTypeError",
"assert",
"domainSeparator",
"encode",
Expand All @@ -1454,10 +1458,6 @@ test('exports', () => {
"hashStruct",
"serialize",
"validate",
"BytesSizeMismatchError",
"InvalidDomainError",
"InvalidPrimaryTypeError",
"InvalidStructTypeError",
"encodeData",
"hashType",
"encodeField",
Expand Down

0 comments on commit 6e4b635

Please sign in to comment.