Skip to content

Commit

Permalink
feat: sync 7739 (wevm#3096)
Browse files Browse the repository at this point in the history
feat: up 7739
  • Loading branch information
jxom authored Dec 5, 2024
1 parent 2d03645 commit 092615f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-rockets-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Synced ERC-7739 extension to latest spec.
2 changes: 1 addition & 1 deletion contracts/lib/solady
Submodule solady updated 143 files
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ const abi = [
name: 'eip712Domain',
inputs: [],
outputs: [
{
name: 'fields',
type: 'bytes1',
},
{
name: 'name',
type: 'string',
Expand All @@ -322,10 +318,6 @@ const abi = [
name: 'salt',
type: 'bytes32',
},
{
name: 'extensions',
type: 'uint256[]',
},
],
stateMutability: 'view',
},
Expand Down
4 changes: 0 additions & 4 deletions src/experimental/erc7739/actions/signTypedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ describe('args: verifierDomain', () => {
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
verifyingContract: verifier,
},
fields: '0x0f',
extensions: [],
primaryType: 'Mail',
})

Expand All @@ -124,8 +122,6 @@ describe('args: verifierDomain', () => {
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
verifyingContract: verifier,
},
fields: '0x0f',
extensions: [],
primaryType: 'Mail',
})

Expand Down
18 changes: 2 additions & 16 deletions src/experimental/erc7739/actions/signTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export type SignTypedDataParameters<
TypedDataDomain,
'chainId' | 'name' | 'verifyingContract' | 'salt' | 'version'
>
fields: Hex
extensions: readonly bigint[]
verifier?: undefined
}
| (GetVerifierParameter<verifier> & {
Expand All @@ -48,8 +46,6 @@ export type SignTypedDataParameters<
'chainId' | 'name' | 'verifyingContract' | 'salt' | 'version'
>
| undefined
fields?: Hex | undefined
extensions?: readonly bigint[] | undefined
})
>

Expand Down Expand Up @@ -189,16 +185,10 @@ export async function signTypedData<
const account = parseAccount(account_!)

// Retrieve account EIP712 domain.
const {
domain: verifierDomain,
fields,
extensions,
} = await (async () => {
if (parameters.verifierDomain && parameters.fields && parameters.extensions)
const { domain: verifierDomain } = await (async () => {
if (parameters.verifierDomain)
return {
domain: parameters.verifierDomain,
fields: parameters.fields,
extensions: parameters.extensions,
}
return getAction(
client,
Expand All @@ -223,20 +213,16 @@ export async function signTypedData<
...types,
TypedDataSign: [
{ name: 'contents', type: primaryType },
{ name: 'fields', type: 'bytes1' },
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
{ name: 'extensions', type: 'uint256[]' },
],
},
primaryType: 'TypedDataSign',
message: {
contents: message as any,
fields,
extensions,
...(verifierDomain as any),
},
})
Expand Down
8 changes: 1 addition & 7 deletions src/experimental/erc7739/utils/hashTypedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ beforeAll(async () => {
})

test('default', async () => {
const {
domain: verifierDomain,
extensions,
fields,
} = await getEip712Domain(client, {
const { domain: verifierDomain } = await getEip712Domain(client, {
address: verifier,
})

const hash = hashTypedData({
...typedData.complex,
extensions,
fields,
verifierDomain,
primaryType: 'Mail',
})
Expand Down
16 changes: 1 addition & 15 deletions src/experimental/erc7739/utils/hashTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export type HashTypedDataParameters<
///
primaryTypes = typedData extends TypedData ? keyof typedData : string,
> = TypedDataDefinition<typedData, primaryType, primaryTypes> & {
fields: Hex
extensions: readonly bigint[]
verifierDomain: RequiredBy<
TypedDataDomain,
'chainId' | 'name' | 'verifyingContract' | 'version'
Expand Down Expand Up @@ -76,36 +74,24 @@ export function hashTypedData<
>(
parameters: HashTypedDataParameters<typedData, primaryType>,
): HashTypedDataReturnType {
const {
domain,
extensions,
fields,
message,
primaryType,
types,
verifierDomain,
} = parameters
const { domain, message, primaryType, types, verifierDomain } = parameters

return hashTypedData_({
domain: domain as any,
types: {
...types,
TypedDataSign: [
{ name: 'contents', type: primaryType },
{ name: 'fields', type: 'bytes1' },
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
{ name: 'extensions', type: 'uint256[]' },
],
},
primaryType: 'TypedDataSign',
message: {
contents: message as any,
fields,
extensions,
...(verifierDomain as any),
},
})
Expand Down

0 comments on commit 092615f

Please sign in to comment.