@scure/btc-signer 1.2.2 → 1.3.1

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.
Files changed (60) hide show
  1. package/README.md +30 -3
  2. package/lib/_type_test.d.ts +2 -0
  3. package/lib/_type_test.d.ts.map +1 -0
  4. package/lib/_type_test.js +59 -0
  5. package/lib/_type_test.js.map +1 -0
  6. package/lib/esm/_type_test.js +57 -0
  7. package/lib/esm/_type_test.js.map +1 -0
  8. package/lib/esm/index.js +13 -3007
  9. package/lib/esm/index.js.map +1 -1
  10. package/lib/esm/payment.js +681 -0
  11. package/lib/esm/payment.js.map +1 -0
  12. package/lib/esm/psbt.js +441 -0
  13. package/lib/esm/psbt.js.map +1 -0
  14. package/lib/esm/script.js +347 -0
  15. package/lib/esm/script.js.map +1 -0
  16. package/lib/esm/transaction.js +1013 -0
  17. package/lib/esm/transaction.js.map +1 -0
  18. package/lib/esm/utils.js +115 -0
  19. package/lib/esm/utils.js.map +1 -0
  20. package/lib/esm/utxo.js +528 -0
  21. package/lib/esm/utxo.js.map +1 -0
  22. package/lib/index.d.ts +18 -1439
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +53 -3042
  25. package/lib/index.js.map +1 -0
  26. package/lib/payment.d.ts +177 -0
  27. package/lib/payment.d.ts.map +1 -0
  28. package/lib/payment.js +704 -0
  29. package/lib/payment.js.map +1 -0
  30. package/lib/psbt.d.ts +834 -0
  31. package/lib/psbt.d.ts.map +1 -0
  32. package/lib/psbt.js +446 -0
  33. package/lib/psbt.js.map +1 -0
  34. package/lib/script.d.ts +154 -0
  35. package/lib/script.d.ts.map +1 -0
  36. package/lib/script.js +353 -0
  37. package/lib/script.js.map +1 -0
  38. package/lib/transaction.d.ts +223 -0
  39. package/lib/transaction.d.ts.map +1 -0
  40. package/lib/transaction.js +1022 -0
  41. package/lib/transaction.js.map +1 -0
  42. package/lib/utils.d.ts +30 -0
  43. package/lib/utils.d.ts.map +1 -0
  44. package/lib/utils.js +128 -0
  45. package/lib/utils.js.map +1 -0
  46. package/lib/utxo.d.ts +251 -0
  47. package/lib/utxo.d.ts.map +1 -0
  48. package/lib/utxo.js +538 -0
  49. package/lib/utxo.js.map +1 -0
  50. package/package.json +40 -10
  51. package/src/_type_test.ts +69 -0
  52. package/src/index.ts +28 -0
  53. package/src/package.json +3 -0
  54. package/src/payment.ts +755 -0
  55. package/src/psbt.ts +512 -0
  56. package/src/script.ts +236 -0
  57. package/src/transaction.ts +1065 -0
  58. package/src/utils.ts +118 -0
  59. package/src/utxo.ts +554 -0
  60. 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';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }