forked from rarible/protocol-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.js
47 lines (41 loc) · 1.22 KB
/
order.js
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
const EIP712 = require("./EIP712");
function AssetType(assetClass, data) {
return { assetClass, data }
}
function Asset(assetClass, assetData, value) {
return { assetType: AssetType(assetClass, assetData), value };
}
function Order(maker, makeAsset, taker, takeAsset, salt, start, end, dataType, data) {
return { maker, makeAsset, taker, takeAsset, salt, start, end, dataType, data };
}
const Types = {
AssetType: [
{name: 'assetClass', type: 'bytes4'},
{name: 'data', type: 'bytes'}
],
Asset: [
{name: 'assetType', type: 'AssetType'},
{name: 'value', type: 'uint256'}
],
Order: [
{name: 'maker', type: 'address'},
{name: 'makeAsset', type: 'Asset'},
{name: 'taker', type: 'address'},
{name: 'takeAsset', type: 'Asset'},
{name: 'salt', type: 'uint256'},
{name: 'start', type: 'uint256'},
{name: 'end', type: 'uint256'},
{name: 'dataType', type: 'bytes4'},
{name: 'data', type: 'bytes'},
]
};
async function sign(order, account, chainId, verifyingContract) {
const data = EIP712.createTypeData({
name: "Exchange",
version: "2",
chainId,
verifyingContract
}, 'Order', order, Types);
return (await EIP712.signTypedData(web3, account, data)).sig;
}
module.exports = { AssetType, Asset, Order, sign }