forked from paulmillr/scure-btc-signer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_type_test.ts
67 lines (55 loc) · 1.96 KB
/
_type_test.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
import * as btc from './index.js';
import { hex } from '@scure/base';
import { secp256k1 as secp } from '@noble/curves/secp256k1';
const privKey1 = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
const P1 = secp.getPublicKey(privKey1, true);
const wpkh = btc.p2wpkh(P1);
const tx = new btc.Transaction();
// Basic input test
tx.addInput({
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
index: 0,
...wpkh,
finalScriptSig: new Uint8Array(),
sequence: 1,
});
// Doesn't force any fields on input addition (only on sign)
tx.addInput({
sequence: 1,
});
tx.updateInput(0, {
sequence: 1,
});
const nonWitnessUtxo =
'0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000';
const nonWitnessUtxoB = hex.decode(nonWitnessUtxo);
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxo });
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxoB });
tx.addInput({
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
index: 0,
nonWitnessUtxo: nonWitnessUtxo,
});
tx.addInput({
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
index: 0,
nonWitnessUtxo: nonWitnessUtxoB,
});
// Should fail!
// tx.updateInput(0, {
// nonWitnessUtxo: 1,
// });
// Outputs
tx.addOutput({ amount: 123n });
// should fail
// tx.updateOutput(0, { amount: '1' });
// tx.updateOutput(0, { amount: 1 });
// should fail
// tx.addOutput({ amount: '123' });
// tx.addOutput({ amount: 123 });
for (let i = 0; i < tx.inputsLength; i++) {
console.log('I', tx.getInput(i));
}
for (let i = 0; i < tx.outputsLength; i++) {
console.log('O', tx.getOutput(i));
}