File tree Expand file tree Collapse file tree 10 files changed +76
-0
lines changed Expand file tree Collapse file tree 10 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ const isHashBranch = (ht: HashTree): ht is HashBranch =>
3434 */
3535export type HashTree = HashLeaf | HashBranch ;
3636
37+ /**
38+ * Calculates the root hash from a given control block and leaf hash.
39+ * @param controlBlock - The control block buffer.
40+ * @param leafHash - The leaf hash buffer.
41+ * @returns The root hash buffer.
42+ * @throws {TypeError } If the control block length is less than 33.
43+ */
3744export function rootHashFromPath (
3845 controlBlock : Buffer ,
3946 leafHash : Buffer ,
Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
1515}
1616
1717// output: OP_RETURN ...
18+ /**
19+ * Embeds data in a Bitcoin payment.
20+ * @param a - The payment object.
21+ * @param opts - Optional payment options.
22+ * @returns The modified payment object.
23+ * @throws {TypeError } If there is not enough data or if the output is invalid.
24+ */
1825export function p2data ( a : Payment , opts ?: PaymentOpts ) : Payment {
1926 if ( ! a . data && ! a . output ) throw new TypeError ( 'Not enough data' ) ;
2027 opts = Object . assign ( { validate : true } , opts || { } ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Represents a payment object, which is used to create a payment.
3+ *
4+ * Supports P2PKH、P2SH、P2WPKH、P2WSH、P2TR and so on
5+ *
6+ * @packageDocumentation
7+ */
18import { Network } from '../networks' ;
29import { Taptree } from '../types' ;
310import { p2data as embed } from './embed' ;
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
1717
1818// input: OP_0 [signatures ...]
1919// output: m [pubKeys ...] n OP_CHECKMULTISIG
20+ /**
21+ * Represents a function that creates a Pay-to-Multisig (P2MS) payment object.
22+ * @param a - The payment object.
23+ * @param opts - Optional payment options.
24+ * @returns The created payment object.
25+ * @throws {TypeError } If the provided data is not valid.
26+ */
2027export function p2ms ( a : Payment , opts ?: PaymentOpts ) : Payment {
2128 if (
2229 ! a . input &&
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ const OPS = bscript.OPS;
77
88// input: {signature}
99// output: {pubKey} OP_CHECKSIG
10+ /**
11+ * Creates a pay-to-public-key (P2PK) payment object.
12+ *
13+ * @param a - The payment object containing the necessary data.
14+ * @param opts - Optional payment options.
15+ * @returns The P2PK payment object.
16+ * @throws {TypeError } If the required data is not provided or if the data is invalid.
17+ */
1018export function p2pk ( a : Payment , opts ?: PaymentOpts ) : Payment {
1119 if ( ! a . input && ! a . output && ! a . pubkey && ! a . input && ! a . signature )
1220 throw new TypeError ( 'Not enough data' ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ const OPS = bscript.OPS;
99
1010// input: {signature} {pubkey}
1111// output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG
12+ /**
13+ * Creates a Pay-to-Public-Key-Hash (P2PKH) payment object.
14+ *
15+ * @param a - The payment object containing the necessary data.
16+ * @param opts - Optional payment options.
17+ * @returns The P2PKH payment object.
18+ * @throws {TypeError } If the required data is not provided or if the data is invalid.
19+ */
1220export function p2pkh ( a : Payment , opts ?: PaymentOpts ) : Payment {
1321 if ( ! a . address && ! a . hash && ! a . output && ! a . pubkey && ! a . input )
1422 throw new TypeError ( 'Not enough data' ) ;
Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
2424// input: [redeemScriptSig ...] {redeemScript}
2525// witness: <?>
2626// output: OP_HASH160 {hash160(redeemScript)} OP_EQUAL
27+ /**
28+ * Creates a Pay-to-Script-Hash (P2SH) payment object.
29+ *
30+ * @param a - The payment object containing the necessary data.
31+ * @param opts - Optional payment options.
32+ * @returns The P2SH payment object.
33+ * @throws {TypeError } If the required data is not provided or if the data is invalid.
34+ */
2735export function p2sh ( a : Payment , opts ?: PaymentOpts ) : Payment {
2836 if ( ! a . address && ! a . hash && ! a . output && ! a . redeem && ! a . input )
2937 throw new TypeError ( 'Not enough data' ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ const OPS = bscript.OPS;
1919const TAPROOT_WITNESS_VERSION = 0x01 ;
2020const ANNEX_PREFIX = 0x50 ;
2121
22+ /**
23+ * Creates a Pay-to-Taproot (P2TR) payment object.
24+ *
25+ * @param a - The payment object containing the necessary data for P2TR.
26+ * @param opts - Optional payment options.
27+ * @returns The P2TR payment object.
28+ * @throws {TypeError } If the provided data is invalid or insufficient.
29+ */
2230export function p2tr ( a : Payment , opts ?: PaymentOpts ) : Payment {
2331 if (
2432 ! a . address &&
Original file line number Diff line number Diff line change @@ -12,6 +12,14 @@ const EMPTY_BUFFER = Buffer.alloc(0);
1212// witness: {signature} {pubKey}
1313// input: <>
1414// output: OP_0 {pubKeyHash}
15+ /**
16+ * Creates a pay-to-witness-public-key-hash (p2wpkh) payment object.
17+ *
18+ * @param a - The payment object containing the necessary data.
19+ * @param opts - Optional payment options.
20+ * @returns The p2wpkh payment object.
21+ * @throws {TypeError } If the required data is missing or invalid.
22+ */
1523export function p2wpkh ( a : Payment , opts ?: PaymentOpts ) : Payment {
1624 if ( ! a . address && ! a . hash && ! a . output && ! a . pubkey && ! a . witness )
1725 throw new TypeError ( 'Not enough data' ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ function chunkHasUncompressedPubkey(chunk: StackElement): boolean {
3333// input: <>
3434// witness: [redeemScriptSig ...] {redeemScript}
3535// output: OP_0 {sha256(redeemScript)}
36+ /**
37+ * Creates a Pay-to-Witness-Script-Hash (P2WSH) payment object.
38+ *
39+ * @param a - The payment object containing the necessary data.
40+ * @param opts - Optional payment options.
41+ * @returns The P2WSH payment object.
42+ * @throws {TypeError } If the required data is missing or invalid.
43+ */
3644export function p2wsh ( a : Payment , opts ?: PaymentOpts ) : Payment {
3745 if ( ! a . address && ! a . hash && ! a . output && ! a . redeem && ! a . witness )
3846 throw new TypeError ( 'Not enough data' ) ;
You can’t perform that action at this time.
0 commit comments