forked from bitpay/bitcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet-airsign
executable file
·49 lines (44 loc) · 1.24 KB
/
wallet-airsign
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
#!/usr/bin/env node
var _ = require('lodash');
var fs = require('fs');
var program = require('commander');
var utils = require('./cli-utils');
program = utils.configureCommander(program);
program
.usage('[options] <file>')
.option('-o, --output <filename>', 'write signatures to file')
.parse(process.argv);
var args = program.args;
if (!args[0])
program.help();
var file = args[0];
utils.getClient(program, { mustExist: true, doNotComplete: true }, function (client) {
var task = JSON.parse(fs.readFileSync(file));
var errors = [];
var signatures = _.map(task.txps, function (txp) {
try {
return {
txpId: txp.id,
signatures: client.signTxProposalFromAirGapped(txp, task.encryptedPkr, task.m, task.n),
};
} catch (ex) {
errors.push({
txp: txp,
error: ex
});
}
});
if (errors.length == 0) {
if (program.output) {
fs.writeFileSync(program.output, JSON.stringify(signatures));
console.log('Signatures written to file.');
} else {
console.log(JSON.stringify(signatures));
}
} else {
console.log('Error signing transactions:');
_.each(errors, function (e) {
console.log('\tTransaction %s: %s', e.txp.id, e.error.message);
});
}
});