forked from menlatin/flappycore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateScript.js
76 lines (64 loc) · 2.2 KB
/
CreateScript.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
'use strict';
var run = function() {
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
var bitcore = require('../bitcore');
var networks = require('../networks');
var Script = bitcore.Script;
var WalletKey = bitcore.WalletKey;
var buffertools = bitcore.buffertools;
var Address = bitcore.Address;
var util = bitcore.util;
var opts = {
network: networks.testnet
};
var p = console.log;
var wk = new WalletKey(opts);
wk.generate();
var wkObj = wk.storeObj();
var s = Script.createPubKeyOut(wk.privKey.public);
p('\nScript PubKey:');
p('\tHex : ' + buffertools.toHex(s.buffer));
p('\tHuman : ' + s.toHumanReadable());
p('\tKey -------------------------------');
console.log('\tPrivate: ' + wkObj.priv);
console.log('\tPublic : ' + wkObj.pub);
console.log('\tAddr : ' + wkObj.addr);
s = Script.createPubKeyHashOut(wk.privKey.public);
p('\nScript PubKeyHash:');
p('\tHex : ' + buffertools.toHex(s.buffer));
p('\tHuman : ' + s.toHumanReadable());
p('\tKey -------------------------------');
console.log('\tPrivate: ' + wkObj.priv);
console.log('\tPublic : ' + wkObj.pub);
console.log('\tAddr : ' + wkObj.addr);
var wks = [];
var pubs = [];
for (var i = 0; i < 5; i++) {
wks[i] = new WalletKey(opts);
wks[i].generate();
pubs.push(wks[i].privKey.public);
}
s = Script.createMultisig(3, pubs);
p('\nScript MultiSig (3 out of 5 required signatures):');
p('\tHex : ' + buffertools.toHex(s.buffer));
p('\tHuman : ' + s.toHumanReadable());
for (i = 0; i < 5; i++) {
wkObj = wks[i].storeObj();
p('\tKey [' + i + '] -------------------------------');
console.log('\tPrivate: ' + wkObj.priv);
console.log('\tPublic : ' + wkObj.pub);
console.log('\tAddr : ' + wkObj.addr);
}
var hash = util.sha256ripe160(s.buffer);
s = Script.createP2SH(hash);
p('\nScript P2SH:');
p('\tHex : ' + buffertools.toHex(s.buffer));
p('\tHuman : ' + s.toHumanReadable());
p('\tScript Hash: ' + buffertools.toHex(hash));
var a = new Address(networks.livenet.P2SHVersion, hash);
p('\tp2sh Addr: ' + a.toString());
};
module.exports.run = run;
if (require.main === module) {
run();
}