-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.ts
46 lines (45 loc) · 1.14 KB
/
index.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
45
46
import { TypedDataUtils } from 'ethers-eip712'
// obj: {
// chainId: u256,
// gem: address,
// owner: address,
// spender: address,
// value: u256,
// nonce: u256,
// deadline: u256,
// }
export function makeGemPermitDigest (obj: any) {
const typedData = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' }
],
GemPermit: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'bytes32' }
]
},
primaryType: 'GemPermit',
domain: {
name: 'GemPermit',
version: '0',
chainId: obj.chainId,
verifyingContract: obj.gem
},
message: {
owner: obj.owner,
spender: obj.spender,
value: obj.value,
nonce: obj.nonce,
deadline: obj.deadline
}
}
// debug('encoding digest...')
return Buffer.from(TypedDataUtils.encodeDigest(typedData))
}