UNPKG

5.38 kBTypeScriptView Raw
1import type { SignatureLike } from "../crypto/index.js";
2import type { BigNumberish, BytesLike } from "../utils/index.js";
3/**
4 * The domain for an [[link-eip-712]] payload.
5 */
6export interface TypedDataDomain {
7 /**
8 * The human-readable name of the signing domain.
9 */
10 name?: null | string;
11 /**
12 * The major version of the signing domain.
13 */
14 version?: null | string;
15 /**
16 * The chain ID of the signing domain.
17 */
18 chainId?: null | BigNumberish;
19 /**
20 * The the address of the contract that will verify the signature.
21 */
22 verifyingContract?: null | string;
23 /**
24 * A salt used for purposes decided by the specific domain.
25 */
26 salt?: null | BytesLike;
27}
28/**
29 * A specific field of a structured [[link-eip-712]] type.
30 */
31export interface TypedDataField {
32 /**
33 * The field name.
34 */
35 name: string;
36 /**
37 * The type of the field.
38 */
39 type: string;
40}
41/**
42 * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
43 * for signed typed data.
44 *
45 * This is useful for those that wish to compute various components of a
46 * typed data hash, primary types, or sub-components, but generally the
47 * higher level [[Signer-signTypedData]] is more useful.
48 */
49export declare class TypedDataEncoder {
50 #private;
51 /**
52 * The primary type for the structured [[types]].
53 *
54 * This is derived automatically from the [[types]], since no
55 * recursion is possible, once the DAG for the types is consturcted
56 * internally, the primary type must be the only remaining type with
57 * no parent nodes.
58 */
59 readonly primaryType: string;
60 /**
61 * The types.
62 */
63 get types(): Record<string, Array<TypedDataField>>;
64 /**
65 * Create a new **TypedDataEncoder** for %%types%%.
66 *
67 * This performs all necessary checking that types are valid and
68 * do not violate the [[link-eip-712]] structural constraints as
69 * well as computes the [[primaryType]].
70 */
71 constructor(_types: Record<string, Array<TypedDataField>>);
72 /**
73 * Returnthe encoder for the specific %%type%%.
74 */
75 getEncoder(type: string): (value: any) => string;
76 /**
77 * Return the full type for %%name%%.
78 */
79 encodeType(name: string): string;
80 /**
81 * Return the encoded %%value%% for the %%type%%.
82 */
83 encodeData(type: string, value: any): string;
84 /**
85 * Returns the hash of %%value%% for the type of %%name%%.
86 */
87 hashStruct(name: string, value: Record<string, any>): string;
88 /**
89 * Return the fulled encoded %%value%% for the [[types]].
90 */
91 encode(value: Record<string, any>): string;
92 /**
93 * Return the hash of the fully encoded %%value%% for the [[types]].
94 */
95 hash(value: Record<string, any>): string;
96 /**
97 * @_ignore:
98 */
99 _visit(type: string, value: any, callback: (type: string, data: any) => any): any;
100 /**
101 * Call %%calback%% for each value in %%value%%, passing the type and
102 * component within %%value%%.
103 *
104 * This is useful for replacing addresses or other transformation that
105 * may be desired on each component, based on its type.
106 */
107 visit(value: Record<string, any>, callback: (type: string, data: any) => any): any;
108 /**
109 * Create a new **TypedDataEncoder** for %%types%%.
110 */
111 static from(types: Record<string, Array<TypedDataField>>): TypedDataEncoder;
112 /**
113 * Return the primary type for %%types%%.
114 */
115 static getPrimaryType(types: Record<string, Array<TypedDataField>>): string;
116 /**
117 * Return the hashed struct for %%value%% using %%types%% and %%name%%.
118 */
119 static hashStruct(name: string, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
120 /**
121 * Return the domain hash for %%domain%%.
122 */
123 static hashDomain(domain: TypedDataDomain): string;
124 /**
125 * Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
126 */
127 static encode(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
128 /**
129 * Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
130 */
131 static hash(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
132 /**
133 * Resolves to the value from resolving all addresses in %%value%% for
134 * %%types%% and the %%domain%%.
135 */
136 static resolveNames(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, resolveName: (name: string) => Promise<string>): Promise<{
137 domain: TypedDataDomain;
138 value: any;
139 }>;
140 /**
141 * Returns the JSON-encoded payload expected by nodes which implement
142 * the JSON-RPC [[link-eip-712]] method.
143 */
144 static getPayload(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): any;
145}
146/**
147 * Compute the address used to sign the typed data for the %%signature%%.
148 */
149export declare function verifyTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, signature: SignatureLike): string;
150//# sourceMappingURL=typed-data.d.ts.map
\No newline at end of file