-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
210 lines (159 loc) · 5.08 KB
/
index.ts
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import fs from "fs";
import * as readline from 'readline';
import { Address, Signer, Tap, Tx } from "@cmdcode/tapscript";
import util from "@cmdcode/crypto-utils";
import { assembleScript, transactionSubmitter } from "./helpers";
const seckey = Buffer.from("PRIVATE KEY EXPORT HERE", "hex");
const pubkey = util.keys.get_pubkey(seckey, true);
const [tseckey] = Tap.getSecKey(seckey);
const [tpubkey] = Tap.getPubKey(pubkey);
const targetAddress = Address.p2tr.fromPubKey(tpubkey, "testnet");
const xop = "@moto:swap::cbrc-20:swap?ab=PIZZA-WAGMI&a=1&b=0.00000143";
const transactionSplitterBasic = async (utxo: string) => {
const [txid, index] = utxo.split(":");
const vouts = Array(200).fill({ // x200
value: 5_000_000, // 0.05 BTC
scriptPubKey: Address.toScriptPubKey(targetAddress),
});
const vin = [
{
txid,
vout: Number(index),
prevout: {
value: 1_010_000_000, // 10.1 BTC
scriptPubKey: ["OP_1", tpubkey],
},
},
];
const txnData = Tx.create({
vin,
vout: [...vouts],
});
const sig = Signer.taproot.sign(tseckey, txnData, 0);
txnData.vin[0].witness = [sig];
const txHex = Tx.encode(txnData).hex;
const txId = await transactionSubmitter(txHex);
return {
inscriptionAddress: targetAddress,
txId,
};
};
const transactionSplitter = async (utxo: string) => {
const [txid, index] = utxo.split(":");
const inscribedXop = assembleScript(pubkey, xop);
const tapleaf = Tap.encodeScript(inscribedXop);
const [tspubkey, _] = Tap.getPubKey(pubkey, { target: tapleaf });
const tsAddress = Address.p2tr.fromPubKey(tspubkey, "testnet");
const vouts = Array(1000).fill({ // x1000
value: 3_000, // 0.0003 BTC
scriptPubKey: Address.toScriptPubKey(tsAddress),
});
const vin = [
{
txid,
vout: Number(index),
prevout: {
value: 5_000_000, // 0.05 BTC
scriptPubKey: ["OP_1", tpubkey],
},
},
];
const txnData = Tx.create({
vin,
vout: [...vouts],
});
const sig = Signer.taproot.sign(tseckey, txnData, 0);
txnData.vin[0].witness = [sig];
const txHex = Tx.encode(txnData).hex;
const txId = await transactionSubmitter(txHex);
return {
inscriptionAddress: tsAddress,
txId,
};
};
const createUtxo = (utxos: string) => {
const [txid, index] = utxos.split(":");
const inscribedXop = assembleScript(pubkey, xop);
const tapleaf = Tap.encodeScript(inscribedXop);
const [tpubkey, cblock] = Tap.getPubKey(pubkey, { target: tapleaf });
const vin = [
{
txid,
vout: Number(index),
prevout: {
value: 3_000, // 0.0003 BTC
scriptPubKey: ["OP_1", tpubkey],
},
},
];
const vout = [
{
value: 463,
scriptPubKey: Address.toScriptPubKey(targetAddress),
},
];
const txnData = Tx.create({
vin,
vout,
});
const sig = Signer.taproot.sign(seckey, txnData, 0, { extension: tapleaf });
txnData.vin[0].witness = [sig, inscribedXop, cblock];
const txHex = Tx.encode(txnData).hex;
return txHex;
};
const transactionsCrafter = (txid: string) => {
const utxos = Array.from({ length: 1000 }, (_, i) => `${txid}:${i}`); // x1000
utxos.forEach((utxo) => {
const createdUtxo = createUtxo(utxo);
fs.writeFileSync("./crafted-transactions.txt", `${createdUtxo}\n`, {
flag: "a",
});
});
};
function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
const splitSplitter = async (txid: string) => {
const utxos = Array.from({ length: 200 }, (_, i) => `${txid}:${i}`); // x200
for (const utxo of utxos) {
console.log(utxo)
await transactionSplitter(utxo).then(data => {
fs.appendFile('output_txns.txt', `${data['txId']}\n`, err => {
if (err) {
console.error('Error appending to file:', err);
} else {
console.log(data);
}
});
});
await sleep(500); // Sleep for 500ms before the next iteration
}
};
// ex: b4b8a2ec13703f22409cfe25dbfdf8052b5b02c259c1120f959c7ab9147fac81:0
const utxo = "utxo here:0";
// 1st step
//transactionSplitterBasic(utxo).then(console.log);
// 1.5 step
// take the txid from the previously created transaction and split-split the transactions
//splitSplitter("txid here")
// 2nd step
// take the txid from the previously created transaction and craft the transactions
// const filePath = 'output_txns.txt';
// // Create a readline interface
// const reader = readline.createInterface({
// input: fs.createReadStream(filePath),
// output: process.stdout,
// terminal: false
// });
// // Listen for the 'line' event
// reader.on('line', (line) => {
// // Perform your action on the line here
// console.log(`Processing line: ${line}`);
// transactionsCrafter(line)
// });
// // Handle the 'close' event
// reader.on('close', () => {
// console.log('Finished reading the file.');
// });
// 3rd step
// execute relayer_no_redis.ts (npx tsx relayer_no_redis.ts)