@scure/btc-signer 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/lib/_type_test.d.ts +2 -0
- package/lib/_type_test.d.ts.map +1 -0
- package/lib/_type_test.js +59 -0
- package/lib/_type_test.js.map +1 -0
- package/lib/esm/_type_test.js +57 -0
- package/lib/esm/_type_test.js.map +1 -0
- package/lib/esm/index.js +13 -3007
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/payment.js +681 -0
- package/lib/esm/payment.js.map +1 -0
- package/lib/esm/psbt.js +441 -0
- package/lib/esm/psbt.js.map +1 -0
- package/lib/esm/script.js +347 -0
- package/lib/esm/script.js.map +1 -0
- package/lib/esm/transaction.js +1013 -0
- package/lib/esm/transaction.js.map +1 -0
- package/lib/esm/utils.js +115 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/esm/utxo.js +491 -0
- package/lib/esm/utxo.js.map +1 -0
- package/lib/index.d.ts +18 -1439
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +53 -3042
- package/lib/index.js.map +1 -0
- package/lib/payment.d.ts +167 -0
- package/lib/payment.d.ts.map +1 -0
- package/lib/payment.js +704 -0
- package/lib/payment.js.map +1 -0
- package/lib/psbt.d.ts +834 -0
- package/lib/psbt.d.ts.map +1 -0
- package/lib/psbt.js +446 -0
- package/lib/psbt.js.map +1 -0
- package/lib/script.d.ts +154 -0
- package/lib/script.d.ts.map +1 -0
- package/lib/script.js +353 -0
- package/lib/script.js.map +1 -0
- package/lib/transaction.d.ts +223 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +1022 -0
- package/lib/transaction.js.map +1 -0
- package/lib/utils.d.ts +30 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +128 -0
- package/lib/utils.js.map +1 -0
- package/lib/utxo.d.ts +251 -0
- package/lib/utxo.d.ts.map +1 -0
- package/lib/utxo.js +501 -0
- package/lib/utxo.js.map +1 -0
- package/package.json +40 -10
- package/src/_type_test.ts +69 -0
- package/src/index.ts +28 -0
- package/src/package.json +3 -0
- package/src/payment.ts +749 -0
- package/src/psbt.ts +512 -0
- package/src/script.ts +236 -0
- package/src/transaction.ts +1065 -0
- package/src/utils.ts +118 -0
- package/src/utxo.ts +517 -0
- package/index.ts +0 -3067
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as btc from './index.js';
|
|
2
|
+
import { hex } from '@scure/base';
|
|
3
|
+
import { secp256k1 as secp } from '@noble/curves/secp256k1';
|
|
4
|
+
|
|
5
|
+
const privKey1 = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
|
|
6
|
+
const P1 = secp.getPublicKey(privKey1, true);
|
|
7
|
+
|
|
8
|
+
const wpkh = btc.p2wpkh(P1);
|
|
9
|
+
|
|
10
|
+
const tx = new btc.Transaction();
|
|
11
|
+
|
|
12
|
+
// Basic input test
|
|
13
|
+
tx.addInput({
|
|
14
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
15
|
+
index: 0,
|
|
16
|
+
...wpkh,
|
|
17
|
+
finalScriptSig: new Uint8Array(),
|
|
18
|
+
sequence: 1,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Doesn't force any fields on input addition (only on sign)
|
|
22
|
+
tx.addInput({
|
|
23
|
+
sequence: 1,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
tx.updateInput(0, {
|
|
27
|
+
sequence: 1,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const nonWitnessUtxo =
|
|
31
|
+
'0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000';
|
|
32
|
+
const nonWitnessUtxoB = hex.decode(nonWitnessUtxo);
|
|
33
|
+
|
|
34
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxo });
|
|
35
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxoB });
|
|
36
|
+
tx.addInput({
|
|
37
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
38
|
+
index: 0,
|
|
39
|
+
nonWitnessUtxo: nonWitnessUtxo,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
tx.addInput({
|
|
43
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
44
|
+
index: 0,
|
|
45
|
+
nonWitnessUtxo: nonWitnessUtxoB,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Should fail!
|
|
49
|
+
// tx.updateInput(0, {
|
|
50
|
+
// nonWitnessUtxo: 1,
|
|
51
|
+
// });
|
|
52
|
+
// Outputs
|
|
53
|
+
tx.addOutput({ amount: 123n });
|
|
54
|
+
// should fail
|
|
55
|
+
// tx.updateOutput(0, { amount: '1' });
|
|
56
|
+
// tx.updateOutput(0, { amount: 1 });
|
|
57
|
+
// should fail
|
|
58
|
+
// tx.addOutput({ amount: '123' });
|
|
59
|
+
// tx.addOutput({ amount: 123 });
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < tx.inputsLength; i++) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
console.log('I', tx.getInput(i));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < tx.outputsLength; i++) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
console.log('O', tx.getOutput(i));
|
|
69
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
import { isBytes, concatBytes, compareBytes, pubSchnorr, randomPrivateKeyBytes } from './utils.js';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
export {
|
|
5
|
+
p2pk, p2pkh, p2sh, p2ms, p2wsh, p2wpkh, p2tr, p2tr_ns, p2tr_ms, p2tr_pk,
|
|
6
|
+
multisig // => classicMultisig?
|
|
7
|
+
} from './payment.js';
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
export {
|
|
10
|
+
OP, RawTx, CompactSize,
|
|
11
|
+
Script, ScriptNum, ScriptType, MAX_SCRIPT_BYTE_LENGTH,
|
|
12
|
+
} from './script.js';
|
|
13
|
+
export { Transaction } from './transaction.js';
|
|
14
|
+
export { getInputType, selectUTXO } from './utxo.js';
|
|
15
|
+
export { NETWORK, TEST_NETWORK, TAPROOT_UNSPENDABLE_KEY } from './utils.js';
|
|
16
|
+
|
|
17
|
+
export const utils = { isBytes, concatBytes, compareBytes, pubSchnorr, randomPrivateKeyBytes };
|
|
18
|
+
|
|
19
|
+
// Utils
|
|
20
|
+
// prettier-ignore
|
|
21
|
+
export {
|
|
22
|
+
Address, getAddress, WIF,
|
|
23
|
+
OptScript, CustomScript,
|
|
24
|
+
taprootListToTree, OutScript, _sortPubkeys, sortedMultisig, combinations
|
|
25
|
+
} from './payment.js'; // remove
|
|
26
|
+
export { _DebugPSBT, TaprootControlBlock } from './psbt.js'; // remove
|
|
27
|
+
export { Decimal, bip32Path, SigHash, PSBTCombine, DEFAULT_SEQUENCE } from './transaction.js'; // remove
|
|
28
|
+
export { _cmpBig, _Estimator } from './utxo.js';
|
package/src/package.json
ADDED