Variable TypedDataUtilsConst

TypedDataUtils: {
    eip712DomainHash: (<T>(typedData, version) => Buffer);
    eip712Hash: (<T>(typedData, version) => Buffer);
    encodeData: ((primaryType, data, types, version) => Buffer);
    encodeType: ((primaryType, types) => string);
    findTypeDependencies: ((primaryType, types, results?) => Set<string>);
    hashStruct: ((primaryType, data, types, version) => Buffer);
    hashType: ((primaryType, types) => Buffer);
    sanitizeData: (<T>(data) => TypedMessage<T>);
} = ...

A collection of utility functions used for signing typed data.

Type declaration

  • eip712DomainHash: (<T>(typedData, version) => Buffer)
      • <T>(typedData, version): Buffer
      • Create a EIP-712 Domain Hash. This hash is used at the top of the EIP-712 encoding.

        Type Parameters

        Parameters

        • typedData: TypedMessage<T>

          The typed message to hash.

        • version: V3 | V4

          The EIP-712 version the encoding should comply with.

        Returns Buffer

        The hash of the domain object.

  • eip712Hash: (<T>(typedData, version) => Buffer)
      • <T>(typedData, version): Buffer
      • Hash a typed message according to EIP-712. The returned message starts with the EIP-712 prefix, which is "1901", followed by the hash of the domain separator, then the data (if any). The result is hashed again and returned.

        This function does not sign the message. The resulting hash must still be signed to create an EIP-712 signature.

        Type Parameters

        Parameters

        • typedData: TypedMessage<T>

          The typed message to hash.

        • version: V3 | V4

          The EIP-712 version the encoding should comply with.

        Returns Buffer

        The hash of the typed message.

  • encodeData: ((primaryType, data, types, version) => Buffer)
      • (primaryType, data, types, version): Buffer
      • Encodes an object by encoding and concatenating each of its members.

        Parameters

        • primaryType: string

          The root type.

        • data: Record<string, unknown>

          The object to encode.

        • types: Record<string, MessageTypeProperty[]>

          Type definitions for all types included in the message.

        • version: V3 | V4

          The EIP-712 version the encoding should comply with.

        Returns Buffer

        An encoded representation of an object.

  • encodeType: ((primaryType, types) => string)
      • (primaryType, types): string
      • Encodes the type of an object by encoding a comma delimited list of its members.

        Parameters

        • primaryType: string

          The root type to encode.

        • types: Record<string, MessageTypeProperty[]>

          Type definitions for all types included in the message.

        Returns string

        An encoded representation of the primary type.

  • findTypeDependencies: ((primaryType, types, results?) => Set<string>)
      • (primaryType, types, results?): Set<string>
      • Finds all types within a type definition object.

        Parameters

        • primaryType: string

          The root type.

        • types: Record<string, MessageTypeProperty[]>

          Type definitions for all types included in the message.

        • results: Set<string> = ...

          The current set of accumulated types.

        Returns Set<string>

        The set of all types found in the type definition.

  • hashStruct: ((primaryType, data, types, version) => Buffer)
      • (primaryType, data, types, version): Buffer
      • Hashes an object.

        Parameters

        • primaryType: string

          The root type.

        • data: Record<string, unknown>

          The object to hash.

        • types: Record<string, MessageTypeProperty[]>

          Type definitions for all types included in the message.

        • version: V3 | V4

          The EIP-712 version the encoding should comply with.

        Returns Buffer

        The hash of the object.

  • hashType: ((primaryType, types) => Buffer)
      • (primaryType, types): Buffer
      • Hashes the type of an object.

        Parameters

        • primaryType: string

          The root type to hash.

        • types: Record<string, MessageTypeProperty[]>

          Type definitions for all types included in the message.

        Returns Buffer

        The hash of the object type.

  • sanitizeData: (<T>(data) => TypedMessage<T>)
      • <T>(data): TypedMessage<T>
      • Removes properties from a message object that are not defined per EIP-712.

        Type Parameters

        Parameters

        Returns TypedMessage<T>

        The typed message object with only allowed fields.