-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti2.js
More file actions
52 lines (45 loc) · 1.66 KB
/
Copy pathmulti2.js
File metadata and controls
52 lines (45 loc) · 1.66 KB
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
require ('dotenv').config();
const bitcoin = require('bitcoinjs-lib')
const ecc = require('tiny-secp256k1');
const ecpair = require('ecpair');
const ecpairFactory = ecpair.ECPairFactory(ecc);
let alice = JSON.parse(process.env.ALICE);
let claus = JSON.parse(process.env.CLAUS);
let dima = JSON.parse(process.env.DIMA);
const network = bitcoin.networks.bitcoin
const p2ms = bitcoin.payments.p2ms({
m: 2, pubkeys: [
Buffer.from(alice.publicKey, 'hex'),
Buffer.from(claus.publicKey, 'hex'),
Buffer.from(dima.publicKey, 'hex'),
], network
})
console.log('Redeem script:')
console.log(p2ms.output.toString('hex'))
const p2sh = bitcoin.payments.p2sh({redeem: p2ms, network})
console.log('P2SH address')
console.log(p2sh.address)
const p2wsh = bitcoin.payments.p2wsh({redeem: p2ms, network})
console.log('P2WSH address')
console.log(p2wsh.address)
const psbt = new bitcoin.Psbt({network})
.addInput({
hash: '088ea60bc6691dae1027019b5214abac0df576a7a7b818c0bc3a8a24fefe36f4',
index: 0,
witnessScript: p2wsh.redeem.output,
witnessUtxo: {
script: Buffer.from('0020' + bitcoin.crypto.sha256(p2ms.output).toString('hex'), 'hex'),
value: 100000,
}
})
.addOutput({
address: "36b5Z19fLrbgEcV1dwhwiFjix86bGweXKC",
value: 95000,
})
const keyPairClaus1 = ecpairFactory.fromPrivateKey(Buffer.from(claus.privateKey, 'hex'))
const keyPairDima1 = ecpairFactory.fromPrivateKey(Buffer.from(dima.privateKey, 'hex'))
psbt.signInput(0, keyPairClaus1)
psbt.signInput(0, keyPairDima1)
psbt.finalizeAllInputs()
console.log('Transaction hexadecimal:')
console.log(psbt.extractTransaction().toHex())