注意: 此页面尚未翻译成中文。以下内容为英文原版。A TypedDataEncode prepares and encodes EIP-712 payloads for signed typed data. This is useful for those that wish to compute various components of a typed data hash, primary types, or sub-components, but generally the higher level
Signer.signTypedData is more
useful.
Constructors
new TypedDataEncoder()
types.
This performs all necessary checking that types are valid and do not violate the
EIP-712 structural constraints as well as computes the
primaryType.
Parameters
| Parameter | Type |
|---|---|
types | Record<string, TypedDataField[]> |
Returns
TypedDataEncoder
Source
hash/typed-data.ts:259Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
primaryType | readonly | string | The primary type for the structured types. This is derived automatically from the types, since no recursion is possible, once the DAG for the types is consturcted internally, the primary type must be the only remaining type with no parent nodes. |
Accessors
types
Returns
Record<string, TypedDataField[]>
Source
hash/typed-data.ts:244Methods
encode()
value for the types.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | Record<string, any> | The value to encode. |
Returns
string
The encoded value.
Source
hash/typed-data.ts:465encodeData()
value for the type.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | string | The type to encode the value for. |
value | any | The value to encode. |
Returns
string
The encoded value.
Source
hash/typed-data.ts:444encodeType()
name.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name to get the full type for. |
Returns
string
The full type.
Source
hash/typed-data.ts:431getEncoder()
type.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | string | The type to get the encoder for. |
Returns
Function
The encoder for the type.
Parameters
| Parameter | Type |
|---|---|
value | any |
Returns
string
Source
hash/typed-data.ts:365hash()
value for the types.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | Record<string, any> | The value to hash. |
Returns
string
The hash of the value.
Source
hash/typed-data.ts:475hashStruct()
value for the type of name.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the type. |
value | Record<string, any> | The value to hash. |
Returns
string
The hash of the value.
Source
hash/typed-data.ts:455visit()
calback for each value in value, passing the type and component within value.
This is useful for replacing addresses or other transformation that may be desired on each component, based on
its type.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | Record<string, any> | The value to visit. |
callback | (type, data) => any | The callback to call for each value. |
Returns
any
The result of the callback.
Source
hash/typed-data.ts:528encode()
value for types with domain.
Parameters
| Parameter | Type | Description |
|---|---|---|
domain | TypedDataDomain | The domain to use. |
types | Record<string, TypedDataField[]> | The types to encode. |
value | Record<string, any> | The value to encode. |
Returns
string
The encoded value.
Source
hash/typed-data.ts:599from()
types.
Parameters
| Parameter | Type | Description |
|---|---|---|
types | Record<string, TypedDataField[]> | The types to encode. |
Returns
TypedDataEncoder
The encoder for the types.
Throws
If the types are invalid.Source
hash/typed-data.ts:539getPayload()
Parameters
| Parameter | Type | Description |
|---|---|---|
domain | TypedDataDomain | The domain to use. |
types | Record<string, TypedDataField[]> | The types to encode. |
value | Record<string, any> | The value to encode. |
Returns
any
The JSON-encoded payload.
Source
hash/typed-data.ts:633getPrimaryType()
types.
Parameters
| Parameter | Type | Description |
|---|---|---|
types | Record<string, TypedDataField[]> | The types to get the primary type for. |
Returns
string
The primary type.
Throws
If the types are invalid.Source
hash/typed-data.ts:550hash()
value for types with
domain.
Parameters
| Parameter | Type | Description |
|---|---|---|
domain | TypedDataDomain | The domain to use. |
types | Record<string, TypedDataField[]> | The types to hash. |
value | Record<string, any> | The value to hash. |
Returns
string
The hash of the value.
Source
hash/typed-data.ts:616hashDomain()
domain.
Parameters
| Parameter | Type | Description |
|---|---|---|
domain | TypedDataDomain | The domain to hash. |
Returns
string
The hash of the domain.
Throws
If the domain is invalid.Source
hash/typed-data.ts:573hashStruct()
value using types and name.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the type. |
types | Record<string, TypedDataField[]> | The types to hash. |
value | Record<string, any> | The value to hash. |
Returns
string
The hash of the value.
