1- import {
2- type AbiParameter ,
3- type TypedData ,
4- type TypedDataDefinition ,
5- concat ,
6- getTypesForEIP712Domain ,
7- hashDomain ,
8- validateTypedData ,
9- } from "viem" ;
1+ import type * as ox__AbiParameters from "ox/AbiParameters" ;
2+ import * as ox__Bytes from "ox/Bytes" ;
3+ import * as ox__TypedData from "ox/TypedData" ;
104import { encodeAbiParameters } from "../abi/encodeAbiParameters.js" ;
115import { type Hex , toHex } from "../encoding/hex.js" ;
126import { keccak256 } from "./keccak256.js" ;
@@ -17,15 +11,17 @@ type MessageTypeProperty = {
1711} ;
1812
1913export type HashTypedDataParams <
20- typedData extends TypedData | Record < string , unknown > = TypedData ,
14+ typedData extends
15+ | ox__TypedData . TypedData
16+ | Record < string , unknown > = ox__TypedData . TypedData ,
2117 primaryType extends keyof typedData | "EIP712Domain" = keyof typedData ,
22- > = TypedDataDefinition < typedData , primaryType > ;
18+ > = ox__TypedData . Definition < typedData , primaryType > ;
2319
2420/**
2521 * @internal
2622 */
2723export function hashTypedData <
28- const typedData extends TypedData | Record < string , unknown > ,
24+ const typedData extends ox__TypedData . TypedData | Record < string , unknown > ,
2925 primaryType extends keyof typedData | "EIP712Domain" ,
3026> ( parameters : HashTypedDataParams < typedData , primaryType > ) : Hex {
3127 const {
@@ -34,13 +30,13 @@ export function hashTypedData<
3430 primaryType,
3531 } = parameters as HashTypedDataParams ;
3632 const types = {
37- EIP712Domain : getTypesForEIP712Domain ( { domain } ) ,
33+ EIP712Domain : ox__TypedData . extractEip712DomainTypes ( domain ) ,
3834 ...parameters . types ,
3935 } ;
4036
4137 // Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
4238 // as we can't statically check this with TypeScript.
43- validateTypedData ( {
39+ ox__TypedData . validate ( {
4440 domain,
4541 message,
4642 primaryType,
@@ -50,7 +46,7 @@ export function hashTypedData<
5046 const parts : Hex [ ] = [ "0x1901" ] ;
5147 if ( domain )
5248 parts . push (
53- hashDomain ( {
49+ ox__TypedData . hashDomain ( {
5450 domain,
5551 types : types as Record < string , MessageTypeProperty [ ] > ,
5652 } ) ,
@@ -69,7 +65,7 @@ export function hashTypedData<
6965 parts . push ( hashedStruct ) ;
7066 }
7167
72- return keccak256 ( concat ( parts ) ) ;
68+ return keccak256 ( ox__Bytes . concat ( ... parts . map ( ( p ) => ox__Bytes . fromHex ( p ) ) ) ) ;
7369}
7470
7571function encodeData ( {
@@ -81,7 +77,7 @@ function encodeData({
8177 primaryType : string ;
8278 types : Record < string , MessageTypeProperty [ ] > ;
8379} ) {
84- const encodedTypes : AbiParameter [ ] = [ { type : "bytes32" } ] ;
80+ const encodedTypes : ox__AbiParameters . Parameter [ ] = [ { type : "bytes32" } ] ;
8581 const encodedValues : unknown [ ] = [ hashType ( { primaryType, types } ) ] ;
8682
8783 if ( ! types [ primaryType ] ) throw new Error ( "Invalid types" ) ;
@@ -168,7 +164,7 @@ function encodeField({
168164 // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
169165 value : any ;
170166 // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
171- } ) : [ type : AbiParameter , value : any ] {
167+ } ) : [ type : ox__AbiParameters . Parameter , value : any ] {
172168 if ( types [ type ] !== undefined ) {
173169 return [
174170 { type : "bytes32" } ,
@@ -186,15 +182,16 @@ function encodeField({
186182
187183 if ( type . lastIndexOf ( "]" ) === type . length - 1 ) {
188184 const parsedType = type . slice ( 0 , type . lastIndexOf ( "[" ) ) ;
189- // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
190- const typeValuePairs = ( value as [ AbiParameter , any ] [ ] ) . map ( ( item ) =>
191- encodeField ( {
192- name,
193- type : parsedType ,
194- types,
195- value : item ,
196- } ) ,
197- ) ;
185+ const typeValuePairs =
186+ // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
187+ ( value as [ ox__AbiParameters . Parameter , any ] [ ] ) . map ( ( item ) =>
188+ encodeField ( {
189+ name,
190+ type : parsedType ,
191+ types,
192+ value : item ,
193+ } ) ,
194+ ) ;
198195 return [
199196 { type : "bytes32" } ,
200197 keccak256 (
0 commit comments