@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
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@ Audited & minimal library for creating, signing & decoding Bitcoin transactions.
|
|
|
9
9
|
- 🎻 Classic & SegWit: P2PK, P2PKH, P2WPKH, P2SH, P2WSH, P2MS
|
|
10
10
|
- 🧪 Schnorr & Taproot BIP340/BIP341: P2TR, P2TR-NS, P2TR-MS
|
|
11
11
|
- 📨 BIP174 PSBT
|
|
12
|
-
-
|
|
12
|
+
- 🗳️ Easy ordinals and inscriptions
|
|
13
|
+
- 🪶 3300 lines
|
|
13
14
|
|
|
14
15
|
Initial development has been funded by [Ryan Shea](https://shea.io).
|
|
15
16
|
|
|
@@ -17,7 +18,7 @@ For discussions, questions and support, visit
|
|
|
17
18
|
[GitHub Discussions](https://github.com/paulmillr/scure-btc-signer/discussions)
|
|
18
19
|
section of the repository.
|
|
19
20
|
|
|
20
|
-
_Check out all web3 utility libraries:_ [ETH](https://github.com/paulmillr/micro-eth-signer), [BTC](https://github.com/paulmillr/scure-btc-signer), [SOL](https://github.com/paulmillr/micro-sol-signer)
|
|
21
|
+
_Check out all web3 utility libraries:_ [ETH](https://github.com/paulmillr/micro-eth-signer), [BTC](https://github.com/paulmillr/scure-btc-signer), [SOL](https://github.com/paulmillr/micro-sol-signer)
|
|
21
22
|
|
|
22
23
|
### This library belongs to _scure_
|
|
23
24
|
|
|
@@ -65,6 +66,7 @@ import * as btc from '@scure/btc-signer';
|
|
|
65
66
|
- [Basic transaction sign](#basic-transaction-sign)
|
|
66
67
|
- [BIP174 PSBT multi-sig example](#bip174-psbt-multi-sig-example)
|
|
67
68
|
- [UTXO selection](#utxo-selection)
|
|
69
|
+
- [Ordinals and custom scripts](#ordinals-and-custom-scripts)
|
|
68
70
|
- [Utils](#utils)
|
|
69
71
|
- [getAddress](#getaddress)
|
|
70
72
|
- [WIF](#wif)
|
|
@@ -876,6 +878,19 @@ deepStrictEqual(tx.id, 'b702078d65edd65a84b2a97a669df5631b06f42a67b0d7090e540b02
|
|
|
876
878
|
deepStrictEqual(tx.fee, 394n);
|
|
877
879
|
```
|
|
878
880
|
|
|
881
|
+
## Ordinals and custom scripts
|
|
882
|
+
|
|
883
|
+
We support custom scripts. You can pass it as last argument to `p2tr`.
|
|
884
|
+
|
|
885
|
+
Ordinals, inscriptions, runes and others are handled by a separate package for now:
|
|
886
|
+
[micro-ordinals](https://github.com/paulmillr/micro-ordinals).
|
|
887
|
+
|
|
888
|
+
The package contains:
|
|
889
|
+
|
|
890
|
+
- Real code for ordinals / inscriptions
|
|
891
|
+
- CLI tool that allows to upload files as inscriptions
|
|
892
|
+
- Example usage of custom scripts
|
|
893
|
+
|
|
879
894
|
## Utils
|
|
880
895
|
|
|
881
896
|
### getAddress
|
|
@@ -986,7 +1001,8 @@ The library has been independently audited:
|
|
|
986
1001
|
- [Changes since audit](https://github.com/paulmillr/scure-btc-signer/compare/0.3.0..main).
|
|
987
1002
|
- The audit has been funded by [Ryan Shea](https://shea.io)
|
|
988
1003
|
|
|
989
|
-
UTXO selection functionality has not been audited yet.
|
|
1004
|
+
UTXO selection functionality has not been audited yet. Commit [58d4554](58d455480919e968aabff132503560effb2f8eaf)
|
|
1005
|
+
split the library from one into several files to ease future maintainability.
|
|
990
1006
|
|
|
991
1007
|
### Supply chain security
|
|
992
1008
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_type_test.d.ts","sourceRoot":"","sources":["../src/_type_test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const btc = require("./index.js");
|
|
4
|
+
const base_1 = require("@scure/base");
|
|
5
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
6
|
+
const privKey1 = base_1.hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
|
|
7
|
+
const P1 = secp256k1_1.secp256k1.getPublicKey(privKey1, true);
|
|
8
|
+
const wpkh = btc.p2wpkh(P1);
|
|
9
|
+
const tx = new btc.Transaction();
|
|
10
|
+
// Basic input test
|
|
11
|
+
tx.addInput({
|
|
12
|
+
txid: base_1.hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
13
|
+
index: 0,
|
|
14
|
+
...wpkh,
|
|
15
|
+
finalScriptSig: new Uint8Array(),
|
|
16
|
+
sequence: 1,
|
|
17
|
+
});
|
|
18
|
+
// Doesn't force any fields on input addition (only on sign)
|
|
19
|
+
tx.addInput({
|
|
20
|
+
sequence: 1,
|
|
21
|
+
});
|
|
22
|
+
tx.updateInput(0, {
|
|
23
|
+
sequence: 1,
|
|
24
|
+
});
|
|
25
|
+
const nonWitnessUtxo = '0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000';
|
|
26
|
+
const nonWitnessUtxoB = base_1.hex.decode(nonWitnessUtxo);
|
|
27
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxo });
|
|
28
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxoB });
|
|
29
|
+
tx.addInput({
|
|
30
|
+
txid: base_1.hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
31
|
+
index: 0,
|
|
32
|
+
nonWitnessUtxo: nonWitnessUtxo,
|
|
33
|
+
});
|
|
34
|
+
tx.addInput({
|
|
35
|
+
txid: base_1.hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
36
|
+
index: 0,
|
|
37
|
+
nonWitnessUtxo: nonWitnessUtxoB,
|
|
38
|
+
});
|
|
39
|
+
// Should fail!
|
|
40
|
+
// tx.updateInput(0, {
|
|
41
|
+
// nonWitnessUtxo: 1,
|
|
42
|
+
// });
|
|
43
|
+
// Outputs
|
|
44
|
+
tx.addOutput({ amount: 123n });
|
|
45
|
+
// should fail
|
|
46
|
+
// tx.updateOutput(0, { amount: '1' });
|
|
47
|
+
// tx.updateOutput(0, { amount: 1 });
|
|
48
|
+
// should fail
|
|
49
|
+
// tx.addOutput({ amount: '123' });
|
|
50
|
+
// tx.addOutput({ amount: 123 });
|
|
51
|
+
for (let i = 0; i < tx.inputsLength; i++) {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
console.log('I', tx.getInput(i));
|
|
54
|
+
}
|
|
55
|
+
for (let i = 0; i < tx.outputsLength; i++) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
console.log('O', tx.getOutput(i));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=_type_test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_type_test.js","sourceRoot":"","sources":["../src/_type_test.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,sCAAkC;AAClC,uDAA4D;AAE5D,MAAM,QAAQ,GAAG,UAAG,CAAC,MAAM,CAAC,kEAAkE,CAAC,CAAC;AAChG,MAAM,EAAE,GAAG,qBAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAE7C,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE5B,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;AAEjC,mBAAmB;AACnB,EAAE,CAAC,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AE,CAAC,EAAE,EAAE,CAAC;IACzC,aAAa;IACb,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC,EAAE,EAAE,CAAC;IAC1C,aAAa;IACb,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as btc from './index.js';
|
|
2
|
+
import { hex } from '@scure/base';
|
|
3
|
+
import { secp256k1 as secp } from '@noble/curves/secp256k1';
|
|
4
|
+
const privKey1 = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
|
|
5
|
+
const P1 = secp.getPublicKey(privKey1, true);
|
|
6
|
+
const wpkh = btc.p2wpkh(P1);
|
|
7
|
+
const tx = new btc.Transaction();
|
|
8
|
+
// Basic input test
|
|
9
|
+
tx.addInput({
|
|
10
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
11
|
+
index: 0,
|
|
12
|
+
...wpkh,
|
|
13
|
+
finalScriptSig: new Uint8Array(),
|
|
14
|
+
sequence: 1,
|
|
15
|
+
});
|
|
16
|
+
// Doesn't force any fields on input addition (only on sign)
|
|
17
|
+
tx.addInput({
|
|
18
|
+
sequence: 1,
|
|
19
|
+
});
|
|
20
|
+
tx.updateInput(0, {
|
|
21
|
+
sequence: 1,
|
|
22
|
+
});
|
|
23
|
+
const nonWitnessUtxo = '0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000';
|
|
24
|
+
const nonWitnessUtxoB = hex.decode(nonWitnessUtxo);
|
|
25
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxo });
|
|
26
|
+
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxoB });
|
|
27
|
+
tx.addInput({
|
|
28
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
29
|
+
index: 0,
|
|
30
|
+
nonWitnessUtxo: nonWitnessUtxo,
|
|
31
|
+
});
|
|
32
|
+
tx.addInput({
|
|
33
|
+
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
34
|
+
index: 0,
|
|
35
|
+
nonWitnessUtxo: nonWitnessUtxoB,
|
|
36
|
+
});
|
|
37
|
+
// Should fail!
|
|
38
|
+
// tx.updateInput(0, {
|
|
39
|
+
// nonWitnessUtxo: 1,
|
|
40
|
+
// });
|
|
41
|
+
// Outputs
|
|
42
|
+
tx.addOutput({ amount: 123n });
|
|
43
|
+
// should fail
|
|
44
|
+
// tx.updateOutput(0, { amount: '1' });
|
|
45
|
+
// tx.updateOutput(0, { amount: 1 });
|
|
46
|
+
// should fail
|
|
47
|
+
// tx.addOutput({ amount: '123' });
|
|
48
|
+
// tx.addOutput({ amount: 123 });
|
|
49
|
+
for (let i = 0; i < tx.inputsLength; i++) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
console.log('I', tx.getInput(i));
|
|
52
|
+
}
|
|
53
|
+
for (let i = 0; i < tx.outputsLength; i++) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
console.log('O', tx.getOutput(i));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=_type_test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_type_test.js","sourceRoot":"","sources":["../../src/_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