-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy patheip712.ts
More file actions
49 lines (45 loc) · 1.01 KB
/
eip712.ts
File metadata and controls
49 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { Chain } from "../types/index.js";
import { MSG_TO_SIGN } from "./constants.js";
import { type ClobSigner, getSignerAddress, signTypedDataWithSigner } from "./signer.js";
/**
* Builds the canonical Polymarket CLOB EIP712 signature
* @param signer
* @param ts
* @returns string
*/
export const buildClobEip712Signature = async (
signer: ClobSigner,
chainId: Chain,
timestamp: number,
nonce: number,
): Promise<string> => {
const address = await getSignerAddress(signer);
const ts = timestamp.toString();
const domain = {
name: "ClobAuthDomain",
version: "1",
chainId: chainId,
};
const types = {
ClobAuth: [
{ name: "address", type: "address" },
{ name: "timestamp", type: "string" },
{ name: "nonce", type: "uint256" },
{ name: "message", type: "string" },
],
};
const value = {
address,
timestamp: ts,
nonce,
message: MSG_TO_SIGN,
};
const sig = await signTypedDataWithSigner({
signer,
domain,
types,
value,
primaryType: "ClobAuth",
});
return sig;
};