@@ -57,9 +57,21 @@ exports.taggedHash = taggedHash;
5757const ripemd160_1 = require ( '@noble/hashes/ripemd160' ) ;
5858const sha256_1 = require ( '@noble/hashes/sha256' ) ;
5959const tools = __importStar ( require ( 'uint8array-tools' ) ) ;
60+ /**
61+ * Computes the HASH160 (RIPEMD-160 after SHA-256) of the given buffer.
62+ *
63+ * @param buffer - The input data to be hashed.
64+ * @returns The HASH160 of the input buffer.
65+ */
6066function hash160 ( buffer ) {
6167 return ( 0 , ripemd160_1 . ripemd160 ) ( ( 0 , sha256_1 . sha256 ) ( buffer ) ) ;
6268}
69+ /**
70+ * Computes the double SHA-256 hash of the given buffer.
71+ *
72+ * @param buffer - The input data to be hashed.
73+ * @returns The double SHA-256 hash of the input buffer.
74+ */
6375function hash256 ( buffer ) {
6476 return ( 0 , sha256_1 . sha256 ) ( ( 0 , sha256_1 . sha256 ) ( buffer ) ) ;
6577}
@@ -74,9 +86,22 @@ exports.TAGS = [
7486 'KeyAgg list' ,
7587 'KeyAgg coefficient' ,
7688] ;
77- /** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
7889/**
79- * Defines the tagged hash prefixes used in the crypto module.
90+ * A collection of tagged hash prefixes used in various BIP (Bitcoin Improvement Proposals)
91+ * and Taproot-related operations. Each prefix is represented as a `Uint8Array`.
92+ *
93+ * @constant
94+ * @type {TaggedHashPrefixes }
95+ *
96+ * @property {'BIP0340/challenge' } - Prefix for BIP0340 challenge.
97+ * @property {'BIP0340/aux' } - Prefix for BIP0340 auxiliary data.
98+ * @property {'BIP0340/nonce' } - Prefix for BIP0340 nonce.
99+ * @property {TapLeaf } - Prefix for Taproot leaf.
100+ * @property {TapBranch } - Prefix for Taproot branch.
101+ * @property {TapSighash } - Prefix for Taproot sighash.
102+ * @property {TapTweak } - Prefix for Taproot tweak.
103+ * @property {'KeyAgg list' } - Prefix for key aggregation list.
104+ * @property {'KeyAgg coefficient' } - Prefix for key aggregation coefficient.
80105 */
81106exports . TAGGED_HASH_PREFIXES = {
82107 'BIP0340/challenge' : Uint8Array . from ( [
@@ -134,6 +159,13 @@ exports.TAGGED_HASH_PREFIXES = {
134159 78 , 214 , 66 , 114 , 129 , 192 , 145 , 0 , 249 , 77 , 205 , 82 , 201 , 129 ,
135160 ] ) ,
136161} ;
162+ /**
163+ * Computes a tagged hash using the specified prefix and data.
164+ *
165+ * @param prefix - The prefix to use for the tagged hash. This should be one of the values from the `TaggedHashPrefix` enum.
166+ * @param data - The data to hash, provided as a `Uint8Array`.
167+ * @returns The resulting tagged hash as a `Uint8Array`.
168+ */
137169function taggedHash ( prefix , data ) {
138170 return ( 0 , sha256_1 . sha256 ) (
139171 tools . concat ( [ exports . TAGGED_HASH_PREFIXES [ prefix ] , data ] ) ,
0 commit comments