This repository was archived by the owner on Dec 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhack.ts
More file actions
100 lines (74 loc) · 2.39 KB
/
Copy pathhack.ts
File metadata and controls
100 lines (74 loc) · 2.39 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
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
#!/usr/bin/env ts-node
import * as program from 'commander';
const datapay = require('datapay');
const explorer = require('bitcore-explorers');
const bitcoin = require('bsv');
function callback(res){
console.log("callback", )
}
program
.command('playsong <url>')
.action(async (url) => {
const key = 'L2n9J4UzXDpJrbgo8gMVS3BmBSMZCJsmvStyPTkCQXYFdu2rxYR5';
const privateKey = new bitcoin.PrivateKey(key);
const address = privateKey.toAddress();
const insight = new explorer.Insight('https://api.bitindex.network')
insight.getUnspentUtxos(address, async function (err, res) {
if(err){
console.log('error', err)
return;
}
console.log('res', res)
let tx = new bitcoin.Transaction()
.from(res[1])
.to('1MqjrXZuy5Ad22iH1qVHGe4WPhX8CYJfag', 1000)
.fee(400)
.change(address)
let options = {
safe : false,
data : [`j"1MqjrXZuy5Ad22iH1qVHGe4WPhX8CYJfagF${url}`]
}
var script = _script(options)
tx.addOutput(new bitcoin.Transaction.Output({ script: script, satoshis: 0 }));
tx.sign(privateKey)
insight.broadcast(tx.toString(), callback)
})
});
program.parse(process.argv);
var _script = function(options) {
var s = null;
if (options.data) {
if (Array.isArray(options.data)) {
s = new bitcoin.Script();
if (options.safe) {
s.add(bitcoin.Opcode.OP_FALSE);
}
// Add op_return
s.add(bitcoin.Opcode.OP_RETURN);
options.data.forEach(function(item) {
// add push data
if (item.constructor.name === 'ArrayBuffer') {
let buffer = Buffer.from(item)
s.add(buffer)
} else if (item.constructor.name === 'Buffer') {
s.add(item)
} else if (typeof item === 'string') {
if (/^0x/i.test(item)) {
// ex: 0x6d02
console.log('here')
s.add(Buffer.from(item.slice(2), "hex"))
} else {
// ex: "hello"
s.add(Buffer.from(item))
}
} else if (typeof item === 'object' && item.hasOwnProperty('op')) {
s.add({ opcodenum: item.op })
}
})
} else if (typeof options.data === 'string') {
// Exported transaction
s = bitcoin.Script.fromHex(options.data);
}
}
return s;
}