-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patheip712.ts
44 lines (41 loc) · 1.14 KB
/
eip712.ts
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
import { Wallet } from "@ethersproject/wallet";
import { JsonRpcSigner } from "@ethersproject/providers";
import { MSG_TO_SIGN } from "./constants";
import { Chain } from "src/types";
/**
* Builds the canonical Polymarket CLOB EIP712 signature
* @param signer
* @param ts
* @returns string
*/
export const buildClobEip712Signature = async (
signer: Wallet | JsonRpcSigner,
chainId: Chain,
timestamp: number,
nonce: number,
): Promise<string> => {
const address = await signer.getAddress();
const ts = `${timestamp}`;
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,
};
// eslint-disable-next-line no-underscore-dangle
const sig = await signer._signTypedData(domain, types, value);
return sig;
};