This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultisig_interaction.js
59 lines (51 loc) · 1.87 KB
/
multisig_interaction.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
const Accounts = require('web3-eth-accounts');
const axios = require('axios');
const config = require('./config.js');
const { ethers } = require('ethers');
const args = process.argv.slice(2);
console.log('got arguments: ', args);
if (!config.apiKey || !config.multiSigAdress || !config.privateKey){
console.error('Fill up all values in config.js');
process.exit(0);
}
const multiSigInstance = axios.create({
baseURL: config.apiPrefix + config.multiSigAdress,
timeout: 5000,
headers: {'X-API-KEY': config.apiKey}
});
const accounts = new Accounts('http://asasas:8545');
const sign_confirmation = async(request_id, contractaddr, private_key) => {
console.log('Signing data with settlementid, contractaddr...', request_id, contractaddr);
let pre_hash = ethers.utils.solidityKeccak256(['uint256', 'address'], [request_id, contractaddr])
let msg_hash = accounts.hashMessage(pre_hash)
let signingKey = new ethers.utils.SigningKey(private_key);
let signed_msg = signingKey.signDigest(msg_hash);
signed_msg = ethers.utils.joinSignature(signed_msg)
console.log('Signed message hash', signed_msg)
return signed_msg;
}
const confirm_request_with_sig = async(request_id, contract_address, privatekey) => {
let constructed_sig_obj = await sign_confirmation(request_id, contract_address, privatekey)
multiSigInstance.post('/confirmRequestWithSignature', {
_requestId: request_id,
signatureObject: constructed_sig_obj
})
.then(function (response) {
console.log(response.data);
if (!response.data.success){
process.exit(0);
}
})
.catch(function (error) {
if (error.response.data){
console.log(error.response.data);
if (error.response.data.error == 'unknown contract'){
console.error('You filled in the wrong contract address!');
}
} else {
console.log(error.response);
}
process.exit(0);
});
}
confirm_request_with_sig(parseInt(args[0]), args[1], config.privateKey);