xpi-ts 0.2.22 → 0.2.24
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/dist/cjs/lib/bitcore/crypto/point.js +2 -2
- package/dist/cjs/lib/bitcore/index.js +162 -162
- package/dist/esm/lib/bitcore/crypto/point.js +2 -2
- package/dist/esm/lib/bitcore/index.js +42 -42
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/address.d.ts +116 -0
- package/dist/types/lib/bitcore/address.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/block.d.ts +214 -0
- package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/blockheader.d.ts +220 -0
- package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/merkleblock.d.ts +206 -0
- package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/bn.d.ts +224 -0
- package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +122 -0
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/hash.d.ts +56 -0
- package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/index.d.ts +4 -0
- package/dist/types/lib/bitcore/crypto/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/musig2.d.ts +282 -0
- package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/point.d.ts +87 -0
- package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/random.d.ts +48 -0
- package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts +203 -0
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/signature.d.ts +452 -0
- package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts +46 -0
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58.d.ts +68 -0
- package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58check.d.ts +58 -0
- package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +112 -0
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +144 -0
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/varint.d.ts +86 -0
- package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
- package/dist/types/lib/bitcore/errors.d.ts +4 -0
- package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdprivatekey.d.ts +59 -0
- package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdpublickey.d.ts +145 -0
- package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/index.d.ts +58 -54
- package/dist/types/lib/bitcore/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/message.d.ts +63 -0
- package/dist/types/lib/bitcore/message.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/errors.d.ts +4 -0
- package/dist/types/lib/bitcore/mnemonic/errors.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/index.d.ts +4 -0
- package/dist/types/lib/bitcore/mnemonic/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +106 -0
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +13 -0
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/words/english.d.ts +4 -0
- package/dist/types/lib/bitcore/mnemonic/words/english.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +5 -0
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +4 -0
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/index.d.ts +14 -0
- package/dist/types/lib/bitcore/musig2/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/session.d.ts +254 -0
- package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/signer.d.ts +212 -0
- package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/networks.d.ts +17 -0
- package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
- package/dist/types/lib/bitcore/opcode.d.ts +151 -0
- package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
- package/dist/types/lib/bitcore/privatekey.d.ts +80 -0
- package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/publickey.d.ts +195 -0
- package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/chunk.d.ts +51 -0
- package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +60 -0
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts +23 -0
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +86 -0
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +115 -0
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts +119 -0
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script/taproot.d.ts +297 -0
- package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -1
- package/dist/types/lib/bitcore/script.d.ts +510 -0
- package/dist/types/lib/bitcore/script.d.ts.map +1 -1
- package/dist/types/lib/bitcore/taproot/musig2.d.ts +153 -0
- package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +8 -0
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +8 -0
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +8 -0
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +14 -0
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +22 -0
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input.d.ts +418 -0
- package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts +110 -0
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/output.d.ts +83 -0
- package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/sighash.d.ts +69 -0
- package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/signature.d.ts +98 -0
- package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/transaction.d.ts +379 -0
- package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +61 -0
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
- package/dist/types/lib/bitcore/unit.d.ts +140 -0
- package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
- package/dist/types/lib/bitcore/uri.d.ts +34 -0
- package/dist/types/lib/bitcore/uri.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/base32.d.ts +55 -0
- package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/bits.d.ts +76 -0
- package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/buffer.d.ts +135 -0
- package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/convertBits.d.ts +15 -0
- package/dist/types/lib/bitcore/util/convertBits.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/js.d.ts +19 -0
- package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/merkle.d.ts +85 -0
- package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/preconditions.d.ts +29 -0
- package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util.d.ts +7 -0
- package/dist/types/lib/bitcore/util.d.ts.map +1 -1
- package/dist/types/lib/bitcore/xaddress.d.ts +117 -0
- package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
- package/dist/types/lib/lokad.d.ts +292 -0
- package/dist/types/lib/lokad.d.ts.map +1 -1
- package/dist/types/lib/nft.d.ts +434 -0
- package/dist/types/lib/nft.d.ts.map +1 -1
- package/dist/types/lib/rank/api.d.ts +13 -0
- package/dist/types/lib/rank/api.d.ts.map +1 -1
- package/dist/types/lib/rank/index.d.ts +153 -0
- package/dist/types/lib/rank/index.d.ts.map +1 -1
- package/dist/types/lib/rank/opcode.d.ts +6 -2
- package/dist/types/lib/rank/opcode.d.ts.map +1 -1
- package/dist/types/lib/rank/script.d.ts +10 -0
- package/dist/types/lib/rank/script.d.ts.map +1 -1
- package/dist/types/lib/rank/transaction.d.ts +11 -0
- package/dist/types/lib/rank/transaction.d.ts.map +1 -1
- package/dist/types/lib/rpc.d.ts +176 -0
- package/dist/types/lib/rpc.d.ts.map +1 -1
- package/dist/types/utils/constants.d.ts +27 -0
- package/dist/types/utils/constants.d.ts.map +1 -1
- package/dist/types/utils/env.d.ts +15 -0
- package/dist/types/utils/env.d.ts.map +1 -1
- package/dist/types/utils/string.d.ts +57 -0
- package/dist/types/utils/string.d.ts.map +1 -1
- package/dist/types/utils/wallet.d.ts +43 -1
- package/dist/types/utils/wallet.d.ts.map +1 -1
- package/package.json +1 -1
- package/tsconfig.types.json +2 -1
|
@@ -2,77 +2,374 @@ import { PublicKey } from '../publickey';
|
|
|
2
2
|
import { PrivateKey } from '../privatekey';
|
|
3
3
|
import { Script } from '../script';
|
|
4
4
|
import type { Buffer } from 'buffer/';
|
|
5
|
+
/**
|
|
6
|
+
* Taproot Leaf Node
|
|
7
|
+
*
|
|
8
|
+
* Represents a leaf node in the Taproot script tree, holding a script and an optional leaf version.
|
|
9
|
+
*
|
|
10
|
+
* @property script - The script for this leaf node. Can be a Script object or a BufferUtil.
|
|
11
|
+
* @property [leafVersion] - Optional leaf version byte (defaults to 0xc0 for tapscript if not provided).
|
|
12
|
+
*/
|
|
5
13
|
export interface TapLeafNode {
|
|
14
|
+
/** Script for this leaf (Script object or Buffer) */
|
|
6
15
|
script: Script | Buffer;
|
|
16
|
+
/** Optional leaf version (defaults to 0xc0 for tapscript) */
|
|
7
17
|
leafVersion?: number;
|
|
8
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Taproot Script Tree Branch Node
|
|
21
|
+
*
|
|
22
|
+
* Represents a branch node in the Taproot Merkle tree, consisting of two children.
|
|
23
|
+
* Each child can itself be either a leaf node ({@link TapLeafNode}) or another branch node.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Branch node combining two leaves
|
|
27
|
+
* const branch: TapBranchNode = {
|
|
28
|
+
* left: { script: script1 },
|
|
29
|
+
* right: { script: script2 }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Branch node combining a branch and a leaf
|
|
33
|
+
* const nestedBranch: TapBranchNode = {
|
|
34
|
+
* left: {
|
|
35
|
+
* left: { script: script1 },
|
|
36
|
+
* right: { script: script2 }
|
|
37
|
+
* },
|
|
38
|
+
* right: { script: script3 }
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
9
41
|
export interface TapBranchNode {
|
|
42
|
+
/** Left child node (can be leaf or branch) */
|
|
10
43
|
left: TapNode;
|
|
44
|
+
/** Right child node (can be leaf or branch) */
|
|
11
45
|
right: TapNode;
|
|
12
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Union type for Taproot script tree nodes
|
|
49
|
+
*
|
|
50
|
+
* Can be either a leaf node ({@link TapLeafNode}) or a branch node ({@link TapBranchNode})
|
|
51
|
+
*/
|
|
13
52
|
export type TapNode = TapLeafNode | TapBranchNode;
|
|
53
|
+
/**
|
|
54
|
+
* Individual leaf in the Taproot tree with its Merkle path
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Individual leaf in the Taproot tree with its Merkle path
|
|
58
|
+
*
|
|
59
|
+
* Represents a fully processed leaf node including its computed hash
|
|
60
|
+
* and the Merkle path needed to prove inclusion in the tree.
|
|
61
|
+
*/
|
|
14
62
|
export interface TapLeaf {
|
|
63
|
+
/** The script for this leaf */
|
|
15
64
|
script: Script;
|
|
65
|
+
/** Leaf version byte (e.g., 0xc0 for tapscript) */
|
|
16
66
|
leafVersion: number;
|
|
67
|
+
/** Computed tapleaf hash (32 bytes) */
|
|
17
68
|
leafHash: Buffer;
|
|
69
|
+
/** Array of sibling hashes for Merkle proof */
|
|
18
70
|
merklePath: Buffer[];
|
|
19
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Result of building a Taproot tree
|
|
74
|
+
*/
|
|
20
75
|
export interface TapTreeBuildResult {
|
|
76
|
+
/** Merkle root of the tree */
|
|
21
77
|
merkleRoot: Buffer;
|
|
78
|
+
/** Array of leaf scripts with their merkle paths */
|
|
22
79
|
leaves: TapLeaf[];
|
|
23
80
|
}
|
|
81
|
+
/** Mask for extracting leaf version from control block first byte (clears parity bit) */
|
|
24
82
|
export declare const TAPROOT_LEAF_MASK = 254;
|
|
83
|
+
/** Default leaf version for tapscript (0xc0) */
|
|
25
84
|
export declare const TAPROOT_LEAF_TAPSCRIPT = 192;
|
|
85
|
+
/** Base size of control block: 1 byte control + 32 bytes internal pubkey */
|
|
26
86
|
export declare const TAPROOT_CONTROL_BASE_SIZE = 33;
|
|
87
|
+
/** Size of each Merkle path node in control block */
|
|
27
88
|
export declare const TAPROOT_CONTROL_NODE_SIZE = 32;
|
|
89
|
+
/** Maximum number of Merkle path nodes allowed in control block */
|
|
28
90
|
export declare const TAPROOT_CONTROL_MAX_NODE_COUNT = 128;
|
|
91
|
+
/** Maximum control block size: base + max nodes (33 + 32 * 128 = 4129 bytes) */
|
|
29
92
|
export declare const TAPROOT_CONTROL_MAX_SIZE: number;
|
|
30
93
|
export declare const TAPROOT_SCRIPTTYPE = 81;
|
|
31
94
|
export declare const TAPROOT_INTRO_SIZE = 3;
|
|
32
95
|
export declare const PUBKEY_COMPRESSED_SIZE = 33;
|
|
33
96
|
export declare const PUBKEY_UNCOMPRESSED_SIZE = 65;
|
|
34
97
|
export declare const PUBKEY_XCOORD_SIZE = 32;
|
|
98
|
+
/** SHA256 hash size in bytes (used for merkle nodes, tweaks, and state commitments) */
|
|
35
99
|
export declare const SHA256_HASH_SIZE = 32;
|
|
100
|
+
/** State push opcode size: 0x20 (32) for pushing 32-byte state */
|
|
36
101
|
export declare const TAPROOT_STATE_PUSH_SIZE = 32;
|
|
102
|
+
/** Size of P2TR output without state: intro (3) + pubkey (33) = 36 bytes */
|
|
37
103
|
export declare const TAPROOT_SIZE_WITHOUT_STATE: number;
|
|
104
|
+
/**
|
|
105
|
+
* Size of P2TR output with state:
|
|
106
|
+
* intro (3) + pubkey (33) + state_push (1) + state (32) = 69 bytes
|
|
107
|
+
*/
|
|
38
108
|
export declare const TAPROOT_SIZE_WITH_STATE: number;
|
|
109
|
+
/** SIGHASH_ALL | SIGHASH_LOTUS */
|
|
39
110
|
export declare const TAPROOT_SIGHASH_TYPE: number;
|
|
111
|
+
/** Annex tag byte for Taproot witness stack (0x50). Reference: lotusd/src/script/interpreter.cpp */
|
|
40
112
|
export declare const TAPROOT_ANNEX_TAG = 80;
|
|
113
|
+
/**
|
|
114
|
+
* Tag for TapLeaf hash calculation
|
|
115
|
+
* Used in: tapleaf_hash = SHA256_Tag("TapLeaf", leaf_version || compact_size(script) || script)
|
|
116
|
+
* @see {@link calculateTapLeaf}
|
|
117
|
+
*/
|
|
41
118
|
export declare const TAPROOT_TAG_TAPLEAF = "TapLeaf";
|
|
119
|
+
/**
|
|
120
|
+
* Tag for TapBranch hash calculation
|
|
121
|
+
* Used in: tapbranch_hash = SHA256_Tag("TapBranch", left || right) where left < right lexicographically
|
|
122
|
+
* @see {@link calculateTapBranch}
|
|
123
|
+
*/
|
|
42
124
|
export declare const TAPROOT_TAG_TAPBRANCH = "TapBranch";
|
|
125
|
+
/**
|
|
126
|
+
* Tag for TapTweak hash calculation
|
|
127
|
+
* Used in: tweak = SHA256_Tag("TapTweak", internal_pubkey || merkle_root)
|
|
128
|
+
* @see {@link calculateTapTweak}
|
|
129
|
+
*/
|
|
43
130
|
export declare const TAPROOT_TAG_TAPTWEAK = "TapTweak";
|
|
131
|
+
/**
|
|
132
|
+
* Tagged hash for Taproot
|
|
133
|
+
*
|
|
134
|
+
* Implements BIP340-style tagged hashing:
|
|
135
|
+
* tag_hash = SHA256(tag)
|
|
136
|
+
* tagged_hash = SHA256(tag_hash || tag_hash || data)
|
|
137
|
+
*
|
|
138
|
+
* @param tag - Tag string (e.g., "TapTweak", "TapLeaf", "TapBranch")
|
|
139
|
+
* @param data - Data to hash
|
|
140
|
+
* @returns SHA256_HASH_SIZE-byte hash
|
|
141
|
+
*/
|
|
44
142
|
export declare function taggedHash(tag: string, data: Buffer): Buffer;
|
|
143
|
+
/**
|
|
144
|
+
* Calculate TapTweak hash
|
|
145
|
+
*
|
|
146
|
+
* tweak = SHA256_Tag("TapTweak", internal_pubkey || merkle_root)
|
|
147
|
+
*
|
|
148
|
+
* @param internalPubKey - PUBKEY_COMPRESSED_SIZE-byte internal public key
|
|
149
|
+
* @param merkleRoot - SHA256_HASH_SIZE-byte merkle root (or empty buffer for key-only)
|
|
150
|
+
* @returns SHA256_HASH_SIZE-byte tweak hash
|
|
151
|
+
*/
|
|
45
152
|
export declare function calculateTapTweak(internalPubKey: PublicKey, merkleRoot?: Buffer): Buffer;
|
|
153
|
+
/**
|
|
154
|
+
* Calculate TapLeaf hash for a Taproot script tree leaf
|
|
155
|
+
*
|
|
156
|
+
* This function computes the leaf hash used in Taproot's Merkle tree construction.
|
|
157
|
+
* Each leaf in a Taproot script tree represents a spending condition (script),
|
|
158
|
+
* and its hash commits to both the script content and the leaf version.
|
|
159
|
+
*
|
|
160
|
+
* The leaf hash is used to:
|
|
161
|
+
* 1. Build the Merkle tree structure via {@link calculateTapBranch}
|
|
162
|
+
* 2. Compute the Merkle root that gets tweaked into the output pubkey
|
|
163
|
+
* 3. Verify script path spends by reconstructing the commitment
|
|
164
|
+
*
|
|
165
|
+
* Formula: tapleaf_hash = SHA256_Tag("TapLeaf", leaf_version || compact_size(script) || script)
|
|
166
|
+
*
|
|
167
|
+
* The leaf version allows for future upgrades to the Tapscript rules while
|
|
168
|
+
* maintaining backward compatibility. Currently, 0xc0 is used for standard tapscript.
|
|
169
|
+
*
|
|
170
|
+
* @param script - The spending condition script (Tapscript)
|
|
171
|
+
* @param leafVersion - Leaf version byte (default: 0xc0 for tapscript per BIP342)
|
|
172
|
+
* @returns SHA256_HASH_SIZE-byte tapleaf hash used in Merkle tree construction
|
|
173
|
+
*
|
|
174
|
+
* @see {@link calculateTapBranch} - Combines leaf hashes into branch hashes
|
|
175
|
+
* @see {@link buildTapTree} - Builds complete Taproot tree using leaf hashes
|
|
176
|
+
* @see {@link verifyTaprootCommitment} - Verifies leaf inclusion in commitment
|
|
177
|
+
*/
|
|
46
178
|
export declare function calculateTapLeaf(script: Script | Buffer, leafVersion?: number): Buffer;
|
|
179
|
+
/**
|
|
180
|
+
* Calculate TapBranch hash
|
|
181
|
+
*
|
|
182
|
+
* tapbranch_hash = SHA256_Tag("TapBranch", left || right)
|
|
183
|
+
* where left and right are ordered lexicographically
|
|
184
|
+
*
|
|
185
|
+
* @param left - Left branch hash
|
|
186
|
+
* @param right - Right branch hash
|
|
187
|
+
* @returns SHA256_HASH_SIZE-byte tapbranch hash
|
|
188
|
+
*/
|
|
47
189
|
export declare function calculateTapBranch(left: Buffer, right: Buffer): Buffer;
|
|
190
|
+
/**
|
|
191
|
+
* Tweak a public key for Taproot
|
|
192
|
+
*
|
|
193
|
+
* tweaked_pubkey = internal_pubkey + tweak * G
|
|
194
|
+
*
|
|
195
|
+
* @param internalPubKey - Internal public key
|
|
196
|
+
* @param merkleRoot - Merkle root of script tree (or empty for key-only)
|
|
197
|
+
* @returns Tweaked public key
|
|
198
|
+
*/
|
|
48
199
|
export declare function tweakPublicKey(internalPubKey: PublicKey, merkleRoot?: Buffer): PublicKey;
|
|
200
|
+
/**
|
|
201
|
+
* Tweak a private key for Taproot
|
|
202
|
+
*
|
|
203
|
+
* tweaked_privkey = (internal_privkey + tweak) mod n
|
|
204
|
+
*
|
|
205
|
+
* @param internalPrivKey - Internal private key
|
|
206
|
+
* @param merkleRoot - Merkle root of script tree (or empty for key-only)
|
|
207
|
+
* @returns Tweaked private key
|
|
208
|
+
*/
|
|
49
209
|
export declare function tweakPrivateKey(internalPrivKey: PrivateKey, merkleRoot?: Buffer): PrivateKey;
|
|
210
|
+
/**
|
|
211
|
+
* Type guard to check if a node is a leaf
|
|
212
|
+
*/
|
|
50
213
|
export declare function isTapLeafNode(node: TapNode): node is TapLeafNode;
|
|
214
|
+
/**
|
|
215
|
+
* Type guard to check if a node is a branch
|
|
216
|
+
*/
|
|
51
217
|
export declare function isTapBranchNode(node: TapNode): node is TapBranchNode;
|
|
218
|
+
/**
|
|
219
|
+
* Build a Taproot script tree
|
|
220
|
+
*
|
|
221
|
+
* @param tree - Tree structure (leaf or branch)
|
|
222
|
+
* @returns Tree build result with merkle root and paths
|
|
223
|
+
*/
|
|
52
224
|
export declare function buildTapTree(tree: TapNode): TapTreeBuildResult;
|
|
225
|
+
/**
|
|
226
|
+
* Create a Taproot control block
|
|
227
|
+
*
|
|
228
|
+
* Control block format:
|
|
229
|
+
* - 1 byte: leaf_version | parity_bit
|
|
230
|
+
* - SHA256_HASH_SIZE bytes: internal public key X-coordinate (without PUBKEY_PREFIX_EVEN/PUBKEY_PREFIX_ODD prefix)
|
|
231
|
+
* - SHA256_HASH_SIZE*n bytes: merkle path
|
|
232
|
+
*
|
|
233
|
+
* Total size: PUBKEY_COMPRESSED_SIZE + SHA256_HASH_SIZE*n bytes
|
|
234
|
+
*
|
|
235
|
+
* The parity bit (bit 0 of first byte) indicates if the internal pubkey's
|
|
236
|
+
* Y-coordinate is even (0) or odd (1), allowing reconstruction of the full
|
|
237
|
+
* 33-byte compressed public key during verification.
|
|
238
|
+
*
|
|
239
|
+
* Reference: lotusd/src/script/taproot.cpp lines 43-54
|
|
240
|
+
*
|
|
241
|
+
* @param internalPubKey - Internal public key (PUBKEY_COMPRESSED_SIZE-byte compressed)
|
|
242
|
+
* @param leafIndex - Index of the leaf being spent
|
|
243
|
+
* @param tree - Taproot tree structure
|
|
244
|
+
* @returns Control block buffer
|
|
245
|
+
*/
|
|
53
246
|
export declare function createControlBlock(internalPubKey: PublicKey, leafIndex: number, tree: TapNode): Buffer;
|
|
247
|
+
/**
|
|
248
|
+
* Apply a tweak scalar directly to a public key
|
|
249
|
+
*
|
|
250
|
+
* This is used internally by verifyTaprootCommitment where we already have the tweak hash
|
|
251
|
+
* and need to add it as a scalar to the public key without re-hashing.
|
|
252
|
+
*
|
|
253
|
+
* @param internalPubKey - Internal public key
|
|
254
|
+
* @param tweak - The tweak scalar (already computed hash)
|
|
255
|
+
* @returns Tweaked public key
|
|
256
|
+
*/
|
|
54
257
|
export declare function applyTweakToPublicKey(internalPubKey: PublicKey, tweak: Buffer): PublicKey;
|
|
258
|
+
/**
|
|
259
|
+
* Verify a Taproot commitment
|
|
260
|
+
*
|
|
261
|
+
* Verifies that the control block proves that script is part of the commitment.
|
|
262
|
+
* Matches lotusd/src/script/taproot.cpp VerifyTaprootCommitment().
|
|
263
|
+
*
|
|
264
|
+
* @param controlBlock - Control block (TAPROOT_CONTROL_BASE_SIZE + SHA256_HASH_SIZE*n bytes)
|
|
265
|
+
* @param commitment - Public key that has been committed to (PUBKEY_COMPRESSED_SIZE bytes)
|
|
266
|
+
* @param script - Script we are proving inclusion in commitment for
|
|
267
|
+
* @returns Object containing tapleafHash and success boolean
|
|
268
|
+
*/
|
|
55
269
|
export declare function verifyTaprootCommitment(controlBlock: Buffer, commitment: Buffer, script: Script): {
|
|
56
270
|
tapleafHash: Buffer;
|
|
57
271
|
success: boolean;
|
|
58
272
|
};
|
|
273
|
+
/**
|
|
274
|
+
* Extract the commitment public key from a Taproot script
|
|
275
|
+
*
|
|
276
|
+
* @param script - P2TR script
|
|
277
|
+
* @returns Commitment public key
|
|
278
|
+
* @throws Error if not a valid P2TR script
|
|
279
|
+
*/
|
|
59
280
|
export declare function extractTaprootCommitment(script: Script): PublicKey;
|
|
281
|
+
/**
|
|
282
|
+
* Extract the state from a Taproot script (if present)
|
|
283
|
+
|
|
284
|
+
* @param script - P2TR script to extract state from
|
|
285
|
+
* @returns State buffer (32 bytes) or null if script has no state
|
|
286
|
+
*/
|
|
60
287
|
export declare function extractTaprootState(script: Script): Buffer | null;
|
|
288
|
+
/**
|
|
289
|
+
* Build a Pay-To-Taproot script
|
|
290
|
+
*
|
|
291
|
+
* @deprecated Use Script.buildPayToTaproot instead
|
|
292
|
+
* @param commitment - Commitment public key (tweaked)
|
|
293
|
+
* @param state - Optional 32-byte state (only for script-path spending)
|
|
294
|
+
* @returns P2TR script
|
|
295
|
+
*/
|
|
61
296
|
export declare function buildPayToTaproot(_commitment: PublicKey, _state?: Buffer): Script;
|
|
297
|
+
/**
|
|
298
|
+
* Build a simple key-path-only Taproot output
|
|
299
|
+
*
|
|
300
|
+
* @param internalPubKey - Internal public key
|
|
301
|
+
* @returns P2TR script (key-path has no state)
|
|
302
|
+
*/
|
|
62
303
|
export declare function buildKeyPathTaproot(internalPubKey: PublicKey): Script;
|
|
304
|
+
/**
|
|
305
|
+
* Build a script-path Taproot output
|
|
306
|
+
*
|
|
307
|
+
* @param internalPubKey - Internal public key
|
|
308
|
+
* @param tree - Taproot script tree
|
|
309
|
+
* @param state - Optional 32-byte state
|
|
310
|
+
* @returns P2TR script and tree info
|
|
311
|
+
*/
|
|
63
312
|
export declare function buildScriptPathTaproot(internalPubKey: PublicKey, tree: TapNode, state?: Buffer): {
|
|
64
313
|
script: Script;
|
|
65
314
|
commitment: PublicKey;
|
|
66
315
|
merkleRoot: Buffer;
|
|
67
316
|
leaves: TapLeaf[];
|
|
68
317
|
};
|
|
318
|
+
/**
|
|
319
|
+
* Verify Taproot script path spending
|
|
320
|
+
*
|
|
321
|
+
* Verifies that a script is correctly committed to in a Taproot output
|
|
322
|
+
* by validating the merkle proof in the control block.
|
|
323
|
+
*
|
|
324
|
+
* @param internalPubKey - Internal public key X-coordinate (SHA256_HASH_SIZE bytes, without prefix)
|
|
325
|
+
* @param script - Script being revealed
|
|
326
|
+
* @param commitmentPubKey - Commitment public key from scriptPubKey (PUBKEY_COMPRESSED_SIZE bytes)
|
|
327
|
+
* @param leafVersion - Leaf version from control block
|
|
328
|
+
* @param merklePath - Merkle path nodes from control block
|
|
329
|
+
* @param parity - Parity bit from control block (0=even Y, 1=odd Y)
|
|
330
|
+
* @returns true if verification succeeds
|
|
331
|
+
*/
|
|
69
332
|
export declare function verifyTaprootScriptPath(internalPubKey: Buffer, script: Script, commitmentPubKey: Buffer, leafVersion: number, merklePath: Buffer[], parity: number): boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Verify Taproot script path spending using control block
|
|
335
|
+
*
|
|
336
|
+
* Convenience wrapper that uses the new verifyTaprootCommitment function.
|
|
337
|
+
*
|
|
338
|
+
* @param controlBlock - Control block (33 + 32*n bytes)
|
|
339
|
+
* @param commitment - Commitment public key from scriptPubKey (33 bytes)
|
|
340
|
+
* @param script - Script being revealed
|
|
341
|
+
* @returns true if verification succeeds
|
|
342
|
+
*/
|
|
70
343
|
export declare function verifyTaprootScriptPathFromControlBlock(controlBlock: Buffer, commitment: Buffer, script: Script): boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Result of Taproot spend verification
|
|
346
|
+
*/
|
|
71
347
|
export interface TaprootVerifyResult {
|
|
348
|
+
/** Whether verification succeeded */
|
|
72
349
|
success: boolean;
|
|
350
|
+
/** Error message if verification failed */
|
|
73
351
|
error?: string;
|
|
352
|
+
/** Script to execute (for script path spending) */
|
|
74
353
|
scriptToExecute?: Script;
|
|
354
|
+
/** Stack after verification (for script path spending) */
|
|
75
355
|
stack?: Buffer[];
|
|
76
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Verify Taproot spending (key path or script path)
|
|
359
|
+
*
|
|
360
|
+
* This is the main entry point for Taproot verification, handling both:
|
|
361
|
+
* - Key path spending: Single Schnorr signature
|
|
362
|
+
* - Script path spending: Script + control block + merkle proof
|
|
363
|
+
*
|
|
364
|
+
* Reference: lotusd/src/script/interpreter.cpp VerifyTaprootSpend() lines 2074-2165
|
|
365
|
+
*
|
|
366
|
+
* @param scriptPubkey - The Taproot scriptPubKey being spent
|
|
367
|
+
* @param stack - Stack from scriptSig execution
|
|
368
|
+
* @param tx - Transaction being verified
|
|
369
|
+
* @param nin - Input index
|
|
370
|
+
* @param flags - Script verification flags
|
|
371
|
+
* @param satoshisBN - Amount being spent (for sighash)
|
|
372
|
+
* @returns Verification result with error or script to execute
|
|
373
|
+
*/
|
|
77
374
|
export declare function verifyTaprootSpend(scriptPubkey: Script, stack: Buffer[], flags: number): TaprootVerifyResult;
|
|
78
375
|
//# sourceMappingURL=taproot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taproot.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/script/taproot.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAyC,SAAS,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAMlC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"taproot.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/script/taproot.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAyC,SAAS,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAMlC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,aAAa;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