eip-712
Version:
Tiny library with utility functions that can help with signing and verifying EIP-712 based messages
60 lines (59 loc) • 2.32 kB
TypeScript
import { TypedData } from './types';
/**
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
* in the resulting array.
*/
export declare const getDependencies: (typedData: TypedData, type: string, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined, dependencies?: string[]) => string[];
/**
* Encode a type to a string. All dependant types are alphabetically sorted.
*
* @param {TypedData} typedData
* @param {string} type
* @param {Options} [options]
* @return {string}
*/
export declare const encodeType: (typedData: TypedData, type: string, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => string;
/**
* Get a type string as hash.
*/
export declare const getTypeHash: (typedData: TypedData, type: string, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => Uint8Array;
/**
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
* dependant types are automatically encoded.
*/
export declare const encodeData: (typedData: TypedData, type: string, data: Record<string, unknown>, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => Uint8Array;
/**
* Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
* types are automatically encoded.
*/
export declare const getStructHash: (typedData: TypedData, type: string, data: Record<string, unknown>, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => Uint8Array;
/**
* Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
* with Keccak256.
*/
export declare const getMessage: (typedData: TypedData, hash?: boolean | undefined, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => Uint8Array;
/**
* Get the typed data as array. This can be useful for encoding the typed data with the contract ABI.
*/
export declare const asArray: (typedData: TypedData, type?: string, data?: Record<string, unknown>, options?: Partial<{
domain: string;
verifyDomain: boolean;
}> | undefined) => unknown[];