Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/EIP712

crypto/EIP712

Classes

Eip712EncodingError

Defined in: src/crypto/EIP712/errors.js:45 EIP-712 encoding error

Example

throw new Eip712EncodingError('Failed to encode value', {
  code: 'EIP712_ENCODING_ERROR',
  context: { type: 'address', value: '0x...' },
  docsPath: '/crypto/eip712/encode-value#error-handling',
  cause: originalError
})

Extends

Constructors

Constructor
new Eip712EncodingError(message, options?): Eip712EncodingError
Defined in: src/crypto/EIP712/errors.js:50
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
Eip712EncodingError
Overrides
Eip712Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
Eip712Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
Eip712Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
Eip712Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
Eip712Error.docsPath
name
name: string
Defined in: src/crypto/EIP712/errors.js:57
Inherited from
Eip712Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
Eip712Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
Eip712Error.toJSON

Eip712Error

Defined in: src/crypto/EIP712/errors.js:16 Base EIP-712 error

Example

throw new Eip712Error('EIP-712 operation failed', {
  code: 'EIP712_ERROR',
  context: { operation: 'sign' },
  docsPath: '/crypto/eip712#error-handling',
  cause: originalError
})

Extends

Extended by

Constructors

Constructor
new Eip712Error(message, options?): Eip712Error
Defined in: src/crypto/EIP712/errors.js:21
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
Eip712Error
Overrides
CryptoError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
CryptoError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
CryptoError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
CryptoError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
CryptoError.docsPath
name
name: string
Defined in: src/crypto/EIP712/errors.js:28
Inherited from
CryptoError.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
CryptoError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
CryptoError.toJSON

Eip712InvalidMessageError

Defined in: src/crypto/EIP712/errors.js:103 EIP-712 invalid message error

Example

throw new Eip712InvalidMessageError('Missing required field', {
  code: 'EIP712_INVALID_MESSAGE',
  context: { field: 'name' },
  docsPath: '/crypto/eip712/encode-data#error-handling',
  cause: originalError
})

Extends

Constructors

Constructor
new Eip712InvalidMessageError(message, options?): Eip712InvalidMessageError
Defined in: src/crypto/EIP712/errors.js:108
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
Eip712InvalidMessageError
Overrides
Eip712Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
Eip712Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
Eip712Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
Eip712Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
Eip712Error.docsPath
name
name: string
Defined in: src/crypto/EIP712/errors.js:115
Inherited from
Eip712Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
Eip712Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
Eip712Error.toJSON

Eip712TypeNotFoundError

Defined in: src/crypto/EIP712/errors.js:74 EIP-712 type not found error

Example

throw new Eip712TypeNotFoundError('Type Person not found', {
  code: 'EIP712_TYPE_NOT_FOUND',
  context: { type: 'Person' },
  docsPath: '/crypto/eip712/encode-type#error-handling',
  cause: originalError
})

Extends

Constructors

Constructor
new Eip712TypeNotFoundError(message, options?): Eip712TypeNotFoundError
Defined in: src/crypto/EIP712/errors.js:79
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
Eip712TypeNotFoundError
Overrides
Eip712Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
Eip712Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
Eip712Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
Eip712Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
Eip712Error.docsPath
name
name: string
Defined in: src/crypto/EIP712/errors.js:86
Inherited from
Eip712Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
Eip712Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
Eip712Error.toJSON

Type Aliases

BrandedEIP712

BrandedEIP712 = TypedData & object
Defined in: src/crypto/EIP712/EIP712Type.ts:73 Branded EIP-712 TypedData type

Type Declaration

[brand]
readonly [brand]: "EIP712"

Domain

Domain = object
Defined in: src/crypto/EIP712/EIP712Type.ts:8 EIP-712 Domain separator fields

Properties

chainId?
optional chainId: bigint
Defined in: src/crypto/EIP712/EIP712Type.ts:11
name?
optional name: string
Defined in: src/crypto/EIP712/EIP712Type.ts:9
salt?
optional salt: HashType
Defined in: src/crypto/EIP712/EIP712Type.ts:13
verifyingContract?
optional verifyingContract: AddressType
Defined in: src/crypto/EIP712/EIP712Type.ts:12
version?
optional version: string
Defined in: src/crypto/EIP712/EIP712Type.ts:10

Message

Message = object
Defined in: src/crypto/EIP712/EIP712Type.ts:47 Message data (object with arbitrary structure matching types)

Index Signature

[key: string]: MessageValue

MessageValue

MessageValue = string | bigint | number | boolean | AddressType | Uint8Array | MessageValue[] | {[key: string]: MessageValue; }
Defined in: src/crypto/EIP712/EIP712Type.ts:34 Message value (can be primitive or nested object)

Signature

Signature = object
Defined in: src/crypto/EIP712/EIP712Type.ts:64 ECDSA Signature

Properties

r
r: Uint8Array
Defined in: src/crypto/EIP712/EIP712Type.ts:65
s
s: Uint8Array
Defined in: src/crypto/EIP712/EIP712Type.ts:66
v
v: number
Defined in: src/crypto/EIP712/EIP712Type.ts:67

TypedData

TypedData = object
Defined in: src/crypto/EIP712/EIP712Type.ts:54 Complete EIP-712 typed data structure

Properties

domain
domain: Domain
Defined in: src/crypto/EIP712/EIP712Type.ts:55
message
message: Message
Defined in: src/crypto/EIP712/EIP712Type.ts:58
primaryType
primaryType: string
Defined in: src/crypto/EIP712/EIP712Type.ts:57
types
types: TypeDefinitions
Defined in: src/crypto/EIP712/EIP712Type.ts:56

TypeDefinitions

TypeDefinitions = object
Defined in: src/crypto/EIP712/EIP712Type.ts:27 Type definitions mapping type names to their properties

Index Signature

[typeName: string]: readonly TypeProperty[]

TypeProperty

TypeProperty = object
Defined in: src/crypto/EIP712/EIP712Type.ts:19 Type property definition

Properties

name
name: string
Defined in: src/crypto/EIP712/EIP712Type.ts:20
type
type: string
Defined in: src/crypto/EIP712/EIP712Type.ts:21

Variables

_signTypedData()

const _signTypedData: (typedData, privateKey) => Signature
Defined in: src/crypto/EIP712/EIP712.js:76

Parameters

typedData
TypedData
privateKey
Uint8Array

Returns

Signature

EIP712

const EIP712: object
Defined in: src/crypto/EIP712/EIP712.js:157 EIP-712 Typed Data Signing Complete implementation of EIP-712 typed structured data hashing and signing.

Type Declaration

Domain
Domain: object
Domain.hash()
hash: (domain) => HashType = hashDomain
Parameters
domain
Domain
Returns
HashType
encodeData()
encodeData: (primaryType, data, types) => Uint8Array
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
Uint8Array
EncodeData()
EncodeData: (deps) => (primaryType, data, types) => Uint8Array
Factory: Encode struct data according to EIP-712.
Parameters
deps
Crypto dependencies
encodeValue
(type, value, types) => Uint8Array Encode value function
hashType
(primaryType, types) => HashType Hash type function
Returns
Function that encodes data
(primaryType, data, types): Uint8Array
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
Uint8Array
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If primaryType is not found in types
Throws
If required field is missing from data
Example
import { EncodeData } from './crypto/EIP712/encodeData.js';
import { HashType } from './hashType.js';
import { EncodeValue } from './encodeValue.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashType = HashType({ keccak256 });
const encodeValue = EncodeValue({ keccak256, hashStruct });
const encodeData = EncodeData({ hashType, encodeValue });
const types = { Person: [{ name: 'name', type: 'string' }, { name: 'wallet', type: 'address' }] };
const encoded = encodeData('Person', { name: 'Alice', wallet: '0x...' }, types);
encodeType()
encodeType: (primaryType, types) => string
Encode type string for EIP-712 hashing. Produces type encoding like “Mail(Person from,Person to,string contents)Person(string name,address wallet)“
Parameters
primaryType
string Primary type name to encode
types
TypeDefinitions Type definitions mapping
Returns
string Encoded type string with primary type followed by referenced types in alphabetical order
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If primaryType or any referenced type is not found
Example
import * as EIP712 from './crypto/EIP712/index.js';
const types = { Mail: [{ name: 'from', type: 'Person' }], Person: [{ name: 'name', type: 'string' }] };
const typeString = EIP712.encodeType('Mail', types);
// Returns: "Mail(Person from)Person(string name)"
encodeValue()
encodeValue: (type, value, types) => Uint8Array
Parameters
type
string
value
MessageValue
types
TypeDefinitions
Returns
Uint8Array
EncodeValue()
EncodeValue: (deps) => (type, value, types) => Uint8Array
Factory: Encode single value to 32 bytes according to EIP-712. Handles primitive types, arrays, strings, bytes, and custom structs. Addresses must be pre-validated BrandedAddress types.
Parameters
deps
Crypto dependencies
hashStruct
(type, data, types) => HashType Hash struct function
keccak256
(data) => Uint8Array Keccak256 hash function
Returns
Function that encodes value
(type, value, types): Uint8Array
Parameters
type
string
value
MessageValue
types
TypeDefinitions
Returns
Uint8Array
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If type is unsupported or value format is invalid
Example
import { EncodeValue } from './crypto/EIP712/encodeValue.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { HashStruct } from './hashStruct.js';
const hashStruct = HashStruct({ keccak256, encodeData });
const encodeValue = EncodeValue({ keccak256, hashStruct });
const encoded = encodeValue('uint256', 42n, types);
format()
format: (typedData) => string
Format typed data for human-readable display.
Parameters
typedData
TypedData Typed data to format
Returns
string Human-readable multi-line string representation
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import * as EIP712 from './crypto/EIP712/index.js';
const formatted = EIP712.format(typedData);
console.log(formatted);
HashDomain()
HashDomain: (deps) => (domain) => HashType
Factory: Hash EIP-712 domain separator. Only includes fields that are defined in the domain object.
Parameters
deps
Crypto dependencies
hashStruct
(primaryType, data, types) => HashType Hash struct function
Returns
Function that hashes domain
(domain): HashType
Parameters
domain
Domain
Returns
HashType
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If domain type encoding fails
Example
import { Hash as HashDomain } from './crypto/EIP712/Domain/hash.js';
import { HashStruct } from '../hashStruct.js';
import { hash as keccak256 } from '../../Keccak256/hash.js';
const hashStruct = HashStruct({ keccak256, encodeData });
const hashDomain = HashDomain({ hashStruct });
const domain = { name: 'MyApp', version: '1', chainId: 1n };
const domainHash = hashDomain(domain);
hashStruct()
hashStruct: (primaryType, data, types) => HashType
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
HashType
HashStruct()
HashStruct: (deps) => (primaryType, data, types) => HashType
Factory: Hash struct according to EIP-712 specification. Computes keccak256 of the encoded struct data.
Parameters
deps
Crypto dependencies
encodeData
(primaryType, data, types) => Uint8Array Encode data function
keccak256
(data) => Uint8Array Keccak256 hash function
Returns
Function that hashes struct
(primaryType, data, types): HashType
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
HashType
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If type is not found
Throws
If message data is invalid
Example
import { HashStruct } from './crypto/EIP712/hashStruct.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { EncodeData } from './encodeData.js';
const encodeData = EncodeData({ hashType, encodeValue });
const hashStruct = HashStruct({ keccak256, encodeData });
const types = { Person: [{ name: 'name', type: 'string' }] };
const hash = hashStruct('Person', { name: 'Alice' }, types);
hashType()
hashType: (primaryType, types) => HashType
Parameters
primaryType
string
types
TypeDefinitions
Returns
HashType
HashType()
HashType: (deps) => (primaryType, types) => HashType
Factory: Hash type string according to EIP-712. Computes keccak256 of the encoded type string.
Parameters
deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function
Returns
Function that hashes type string
(primaryType, types): HashType
Parameters
primaryType
string
types
TypeDefinitions
Returns
HashType
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If type is not found
Example
import { HashType } from './crypto/EIP712/hashType.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashType = HashType({ keccak256 });
const types = { Mail: [{ name: 'contents', type: 'string' }] };
const typeHash = hashType('Mail', types);
hashTypedData()
hashTypedData: (typedData) => HashType
Parameters
typedData
TypedData
Returns
HashType
HashTypedData()
HashTypedData: (deps) => (typedData) => HashType
Factory: Hash typed data according to EIP-712 specification. Computes: keccak256(“\x19\x01” ‖ domainSeparator ‖ hashStruct(message))
Parameters
deps
Crypto dependencies
hashDomain
(domain) => HashType Hash domain function
hashStruct
(primaryType, data, types) => HashType Hash struct function
keccak256
(data) => Uint8Array Keccak256 hash function
Returns
Function that hashes typed data
(typedData): HashType
Parameters
typedData
TypedData
Returns
HashType
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If types are not found
Throws
If message data is invalid
Example
import { HashTypedData } from './crypto/EIP712/hashTypedData.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { Hash as HashDomain } from './Domain/hash.js';
import { HashStruct } from './hashStruct.js';
const hashDomain = HashDomain({ hashStruct });
const hashStruct = HashStruct({ keccak256, encodeData });
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const hash = hashTypedData(typedData);
recoverAddress()
recoverAddress: (signature, typedData) => AddressType
Parameters
signature
Signature
typedData
TypedData
Returns
AddressType
RecoverAddress()
RecoverAddress: (deps) => (signature, typedData) => AddressType
Factory: Recover Ethereum address from EIP-712 typed data signature. Uses ECDSA public key recovery to determine the signer’s address.
Parameters
deps
Crypto dependencies
hashTypedData
(typedData) => HashType Hash typed data function
keccak256
(data) => Uint8Array Keccak256 hash function
recoverPublicKey
(signature, hash, recoveryBit) => Uint8Array Secp256k1 public key recovery function
Returns
Function that recovers address
(signature, typedData): AddressType
Parameters
signature
Signature
typedData
TypedData
Returns
AddressType
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If signature recovery fails or public key format is invalid
Example
import { RecoverAddress } from './crypto/EIP712/recoverAddress.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { recoverPublicKey } from '../Secp256k1/recoverPublicKey.js';
import { HashTypedData } from './hashTypedData.js';
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const recoverAddress = RecoverAddress({ keccak256, recoverPublicKey, hashTypedData });
const address = recoverAddress(signature, typedData);
signTypedData()
signTypedData: (typedData, privateKey) => Signature
Parameters
typedData
any
privateKey
any
Returns
Signature
SignTypedData()
SignTypedData: (deps) => (typedData, privateKey) => Signature
Factory: Sign EIP-712 typed data with ECDSA private key. Produces a signature that can be verified against the signer’s address.
Parameters
deps
Crypto dependencies
hashTypedData
(typedData) => HashType Hash typed data function
sign
(hash, privateKey) => Signature Secp256k1 sign function
Returns
Function that signs typed data
(typedData, privateKey): Signature
Parameters
typedData
TypedData
privateKey
Uint8Array
Returns
Signature
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If private key length is invalid or signing fails
Example
import { SignTypedData } from './crypto/EIP712/signTypedData.js';
import { HashTypedData } from './hashTypedData.js';
import { sign } from '../Secp256k1/sign.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const signTypedData = SignTypedData({ hashTypedData, sign });
const privateKey = new Uint8Array(32);
const signature = signTypedData(typedData, privateKey);
validate()
validate: (typedData) => void
Validate typed data structure against EIP-712 specification. Checks domain, types, primaryType, and message structure.
Parameters
typedData
TypedData Typed data to validate
Returns
void
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If structure is invalid or missing required fields
Example
import * as EIP712 from './crypto/EIP712/index.js';
EIP712.validate(typedData); // Throws if invalid
verifyTypedData()
verifyTypedData: (signature, typedData, address) => boolean
Parameters
signature
Signature
typedData
TypedData
address
AddressType
Returns
boolean
VerifyTypedData()
VerifyTypedData: (deps) => (signature, typedData, address) => boolean
Factory: Verify EIP-712 typed data signature against expected signer address. Uses constant-time comparison to prevent timing attacks.
Parameters
deps
Crypto dependencies
recoverAddress
(signature, typedData) => AddressType Recover address function
Returns
Function that verifies signature
(signature, typedData, address): boolean
Parameters
signature
Signature
typedData
TypedData
address
AddressType
Returns
boolean
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { VerifyTypedData } from './crypto/EIP712/verifyTypedData.js';
import { RecoverAddress } from './recoverAddress.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { recoverPublicKey } from '../Secp256k1/recoverPublicKey.js';
const recoverAddress = RecoverAddress({ keccak256, recoverPublicKey, hashTypedData });
const verifyTypedData = VerifyTypedData({ recoverAddress });
const valid = verifyTypedData(signature, typedData, signerAddress);

Example

import { EIP712 } from './EIP712.js';

// Define typed data
const typedData = {
  domain: {
    name: 'MyApp',
    version: '1',
    chainId: 1n,
    verifyingContract: contractAddress,
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' },
    ],
    Mail: [
      { name: 'from', type: 'Person' },
      { name: 'to', type: 'Person' },
      { name: 'contents', type: 'string' },
    ],
  },
  primaryType: 'Mail',
  message: {
    from: { name: 'Alice', wallet: '0x...' },
    to: { name: 'Bob', wallet: '0x...' },
    contents: 'Hello!',
  },
};

// Hash typed data
const hash = EIP712.hashTypedData(typedData);

// Sign typed data
const signature = EIP712.signTypedData(typedData, privateKey);

// Verify signature
const valid = EIP712.verifyTypedData(signature, typedData, address);

encodeData()

const encodeData: (primaryType, data, types) => Uint8Array
Defined in: src/crypto/EIP712/EIP712.js:54

Parameters

primaryType
string
data
Message
types
TypeDefinitions

Returns

Uint8Array

encodeValue()

const encodeValue: (type, value, types) => Uint8Array
Defined in: src/crypto/EIP712/EIP712.js:49

Parameters

type
string
value
MessageValue
types
TypeDefinitions

Returns

Uint8Array

hashDomain()

const hashDomain: (domain) => HashType
Defined in: src/crypto/EIP712/EIP712.js:57

Parameters

domain
Domain

Returns

HashType

hashStruct

hashStruct: any
Defined in: src/crypto/EIP712/EIP712.js:48

hashType()

const hashType: (primaryType, types) => HashType
Defined in: src/crypto/EIP712/EIP712.js:43

Parameters

primaryType
string
types
TypeDefinitions

Returns

HashType

hashTypedData()

const hashTypedData: (typedData) => HashType
Defined in: src/crypto/EIP712/EIP712.js:58

Parameters

typedData
TypedData

Returns

HashType

recoverAddress()

const recoverAddress: (signature, typedData) => AddressType
Defined in: src/crypto/EIP712/EIP712.js:70

Parameters

signature
Signature
typedData
TypedData

Returns

AddressType

verifyTypedData()

const verifyTypedData: (signature, typedData, address) => boolean
Defined in: src/crypto/EIP712/EIP712.js:77

Parameters

signature
Signature
typedData
TypedData
address
AddressType

Returns

boolean

Functions

EncodeData()

EncodeData(deps): (primaryType, data, types) => Uint8Array
Defined in: src/crypto/EIP712/encodeData.js:30 Factory: Encode struct data according to EIP-712.

Parameters

deps
Crypto dependencies
encodeValue
(type, value, types) => Uint8Array Encode value function
hashType
(primaryType, types) => HashType Hash type function

Returns

Function that encodes data
(primaryType, data, types): Uint8Array
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
Uint8Array

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If primaryType is not found in types

Throws

If required field is missing from data

Example

import { EncodeData } from './crypto/EIP712/encodeData.js';
import { HashType } from './hashType.js';
import { EncodeValue } from './encodeValue.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashType = HashType({ keccak256 });
const encodeValue = EncodeValue({ keccak256, hashStruct });
const encodeData = EncodeData({ hashType, encodeValue });
const types = { Person: [{ name: 'name', type: 'string' }, { name: 'wallet', type: 'address' }] };
const encoded = encodeData('Person', { name: 'Alice', wallet: '0x...' }, types);

encodeType()

encodeType(primaryType, types): string
Defined in: src/crypto/EIP712/encodeType.js:22 Encode type string for EIP-712 hashing. Produces type encoding like “Mail(Person from,Person to,string contents)Person(string name,address wallet)“

Parameters

primaryType
string Primary type name to encode
types
TypeDefinitions Type definitions mapping

Returns

string Encoded type string with primary type followed by referenced types in alphabetical order

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If primaryType or any referenced type is not found

Example

import * as EIP712 from './crypto/EIP712/index.js';
const types = { Mail: [{ name: 'from', type: 'Person' }], Person: [{ name: 'name', type: 'string' }] };
const typeString = EIP712.encodeType('Mail', types);
// Returns: "Mail(Person from)Person(string name)"

EncodeValue()

EncodeValue(deps): (type, value, types) => Uint8Array
Defined in: src/crypto/EIP712/encodeValue.js:26 Factory: Encode single value to 32 bytes according to EIP-712. Handles primitive types, arrays, strings, bytes, and custom structs. Addresses must be pre-validated BrandedAddress types.

Parameters

deps
Crypto dependencies
hashStruct
(type, data, types) => HashType Hash struct function
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that encodes value
(type, value, types): Uint8Array
Parameters
type
string
value
MessageValue
types
TypeDefinitions
Returns
Uint8Array

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If type is unsupported or value format is invalid

Example

import { EncodeValue } from './crypto/EIP712/encodeValue.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { HashStruct } from './hashStruct.js';
const hashStruct = HashStruct({ keccak256, encodeData });
const encodeValue = EncodeValue({ keccak256, hashStruct });
const encoded = encodeValue('uint256', 42n, types);

format()

format(typedData): string
Defined in: src/crypto/EIP712/format.js:16 Format typed data for human-readable display.

Parameters

typedData
TypedData Typed data to format

Returns

string Human-readable multi-line string representation

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example

import * as EIP712 from './crypto/EIP712/index.js';
const formatted = EIP712.format(typedData);
console.log(formatted);

HashDomain()

HashDomain(deps): (domain) => HashType
Defined in: src/crypto/EIP712/Domain/hash.js:35 Factory: Hash EIP-712 domain separator. Only includes fields that are defined in the domain object.

Parameters

deps
Crypto dependencies
hashStruct
(primaryType, data, types) => HashType Hash struct function

Returns

Function that hashes domain
(domain): HashType
Parameters
domain
Domain
Returns
HashType

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If domain type encoding fails

Example

import { Hash as HashDomain } from './crypto/EIP712/Domain/hash.js';
import { HashStruct } from '../hashStruct.js';
import { hash as keccak256 } from '../../Keccak256/hash.js';
const hashStruct = HashStruct({ keccak256, encodeData });
const hashDomain = HashDomain({ hashStruct });
const domain = { name: 'MyApp', version: '1', chainId: 1n };
const domainHash = hashDomain(domain);

HashStruct()

HashStruct(deps): (primaryType, data, types) => HashType
Defined in: src/crypto/EIP712/hashStruct.js:25 Factory: Hash struct according to EIP-712 specification. Computes keccak256 of the encoded struct data.

Parameters

deps
Crypto dependencies
encodeData
(primaryType, data, types) => Uint8Array Encode data function
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes struct
(primaryType, data, types): HashType
Parameters
primaryType
string
data
Message
types
TypeDefinitions
Returns
HashType

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If type is not found

Throws

If message data is invalid

Example

import { HashStruct } from './crypto/EIP712/hashStruct.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { EncodeData } from './encodeData.js';
const encodeData = EncodeData({ hashType, encodeValue });
const hashStruct = HashStruct({ keccak256, encodeData });
const types = { Person: [{ name: 'name', type: 'string' }] };
const hash = hashStruct('Person', { name: 'Alice' }, types);

HashType()

HashType(deps): (primaryType, types) => HashType
Defined in: src/crypto/EIP712/hashType.js:23 Factory: Hash type string according to EIP-712. Computes keccak256 of the encoded type string.

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes type string
(primaryType, types): HashType
Parameters
primaryType
string
types
TypeDefinitions
Returns
HashType

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If type is not found

Example

import { HashType } from './crypto/EIP712/hashType.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashType = HashType({ keccak256 });
const types = { Mail: [{ name: 'contents', type: 'string' }] };
const typeHash = hashType('Mail', types);

HashTypedData()

HashTypedData(deps): (typedData) => HashType
Defined in: src/crypto/EIP712/hashTypedData.js:27 Factory: Hash typed data according to EIP-712 specification. Computes: keccak256(“\x19\x01” ‖ domainSeparator ‖ hashStruct(message))

Parameters

deps
Crypto dependencies
hashDomain
(domain) => HashType Hash domain function
hashStruct
(primaryType, data, types) => HashType Hash struct function
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes typed data
(typedData): HashType
Parameters
typedData
TypedData
Returns
HashType

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If types are not found

Throws

If message data is invalid

Example

import { HashTypedData } from './crypto/EIP712/hashTypedData.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { Hash as HashDomain } from './Domain/hash.js';
import { HashStruct } from './hashStruct.js';
const hashDomain = HashDomain({ hashStruct });
const hashStruct = HashStruct({ keccak256, encodeData });
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const hash = hashTypedData(typedData);

RecoverAddress()

RecoverAddress(deps): (signature, typedData) => AddressType
Defined in: src/crypto/EIP712/recoverAddress.js:27 Factory: Recover Ethereum address from EIP-712 typed data signature. Uses ECDSA public key recovery to determine the signer’s address.

Parameters

deps
Crypto dependencies
hashTypedData
(typedData) => HashType Hash typed data function
keccak256
(data) => Uint8Array Keccak256 hash function
recoverPublicKey
(signature, hash, recoveryBit) => Uint8Array Secp256k1 public key recovery function

Returns

Function that recovers address
(signature, typedData): AddressType
Parameters
signature
Signature
typedData
TypedData
Returns
AddressType

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If signature recovery fails or public key format is invalid

Example

import { RecoverAddress } from './crypto/EIP712/recoverAddress.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { recoverPublicKey } from '../Secp256k1/recoverPublicKey.js';
import { HashTypedData } from './hashTypedData.js';
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const recoverAddress = RecoverAddress({ keccak256, recoverPublicKey, hashTypedData });
const address = recoverAddress(signature, typedData);

signTypedData()

signTypedData(typedData, privateKey): Signature
Defined in: src/crypto/EIP712/EIP712.js:80

Parameters

typedData
any
privateKey
any

Returns

Signature

SignTypedData()

SignTypedData(deps): (typedData, privateKey) => Signature
Defined in: src/crypto/EIP712/signTypedData.js:25 Factory: Sign EIP-712 typed data with ECDSA private key. Produces a signature that can be verified against the signer’s address.

Parameters

deps
Crypto dependencies
hashTypedData
(typedData) => HashType Hash typed data function
sign
(hash, privateKey) => Signature Secp256k1 sign function

Returns

Function that signs typed data
(typedData, privateKey): Signature
Parameters
typedData
TypedData
privateKey
Uint8Array
Returns
Signature

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If private key length is invalid or signing fails

Example

import { SignTypedData } from './crypto/EIP712/signTypedData.js';
import { HashTypedData } from './hashTypedData.js';
import { sign } from '../Secp256k1/sign.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
const hashTypedData = HashTypedData({ keccak256, hashDomain, hashStruct });
const signTypedData = SignTypedData({ hashTypedData, sign });
const privateKey = new Uint8Array(32);
const signature = signTypedData(typedData, privateKey);

validate()

validate(typedData): void
Defined in: src/crypto/EIP712/validate.js:19 Validate typed data structure against EIP-712 specification. Checks domain, types, primaryType, and message structure.

Parameters

typedData
TypedData Typed data to validate

Returns

void

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If structure is invalid or missing required fields

Example

import * as EIP712 from './crypto/EIP712/index.js';
EIP712.validate(typedData); // Throws if invalid

VerifyTypedData()

VerifyTypedData(deps): (signature, typedData, address) => boolean
Defined in: src/crypto/EIP712/verifyTypedData.js:23 Factory: Verify EIP-712 typed data signature against expected signer address. Uses constant-time comparison to prevent timing attacks.

Parameters

deps
Crypto dependencies
recoverAddress
(signature, typedData) => AddressType Recover address function

Returns

Function that verifies signature
(signature, typedData, address): boolean
Parameters
signature
Signature
typedData
TypedData
address
AddressType
Returns
boolean

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example

import { VerifyTypedData } from './crypto/EIP712/verifyTypedData.js';
import { RecoverAddress } from './recoverAddress.js';
import { hash as keccak256 } from '../Keccak256/hash.js';
import { recoverPublicKey } from '../Secp256k1/recoverPublicKey.js';
const recoverAddress = RecoverAddress({ keccak256, recoverPublicKey, hashTypedData });
const verifyTypedData = VerifyTypedData({ recoverAddress });
const valid = verifyTypedData(signature, typedData, signerAddress);