forked from Zondax/filecoin-signing-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultisig.js
173 lines (130 loc) · 4.17 KB
/
multisig.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const filecoin_signer = require('@zondax/filecoin-signer')
const axios = require('axios')
const URL = process.env.URL
const TOKEN = process.env.TOKEN
const privateKeyBase64 = 'YbDPh1vq3fBClzbiwDt6WjniAdZn8tNcCwcBO2hDwyk='
const privateKey = Buffer.from(privateKeyBase64, 'base64')
const headers = { 'Authorization': `Bearer ${TOKEN}` }
async function main() {
let response
/* Import private key */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.WalletImport',
id: 1,
params: [{ Type: 'secp256k1', PrivateKey: privateKeyBase64 }],
}, { headers })
console.log(response.data)
/* Get miner address with funds */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.WalletList',
id: 1,
params: [],
}, { headers })
let address = response.data.result[1]
console.log(address)
/* Get nonce */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolGetNonce',
id: 1,
params: [address],
}, { headers })
console.log(response.data)
let nonce = response.data.result
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.WalletSignMessage',
id: 1,
params: [address, {
From: address,
To: 't137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy',
Nonce: nonce,
GasPrice: '1',
GasLimit: 1000000,
Method: 0,
Value: '10000000000',
Params: '',
}],
}, { headers })
console.log(response.data)
let signedMessage = response.data.result
/* Send signed tx */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolPush',
id: 1,
params: [signedMessage],
}, { headers })
console.log(response.data)
let cid = response.data.result
/* Wait for message */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.StateWaitMsg',
id: 1,
params: [cid, null],
}, { headers })
console.log(response.data)
/* Create multisig */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolGetNonce',
id: 1,
params: ['t137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy'],
}, { headers })
console.log(response.data)
nonce = response.data.result
let addresses = ['t137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy', 't1d2xrzcslx7xlbbylc5c3d5lvandqw4iwl6epxba']
let sender_address = 't137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy'
let create_multisig_transaction = filecoin_signer.createMultisig(sender_address, addresses, '10000', 1, nonce)
let signed_create_multisig = filecoin_signer.transactionSignLotus(create_multisig_transaction, privateKey)
console.log(signed_create_multisig)
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolPush',
id: 1,
params: [JSON.parse(signed_create_multisig)],
}, { headers })
console.log(response.data)
cid = response.data.result
/* Wait for message */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.StateWaitMsg',
id: 1,
params: [cid, null],
}, { headers })
console.log(response.data.result.ReturnDec)
let actorAddress = response.data.result.ReturnDec.IDAddress
/* Propose multisig */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolGetNonce',
id: 1,
params: ['t137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy'],
}, { headers })
console.log(response.data)
nonce = response.data.result
let propose_multisig_transaction = filecoin_signer.proposeMultisig(actorAddress, 't137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy', 't137sjdbgunloi7couiy4l5nc7pd6k2jmq32vizpy', '1000', nonce)
let signed_propose_multisig = filecoin_signer.transactionSignLotus(propose_multisig_transaction, privateKey)
console.log(signed_propose_multisig)
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.MpoolPush',
id: 1,
params: [JSON.parse(signed_propose_multisig)],
}, { headers })
console.log(response.data)
cid = response.data.result
/* Wait for message */
response = await axios.post(URL, {
jsonrpc: '2.0',
method: 'Filecoin.StateWaitMsg',
id: 1,
params: [cid, null],
}, { headers })
console.log(response.data.result)
}
main()