Skip to content

Commit 89785be

Browse files
committed
Don't use constants for tag prefixes
Because the taggedHash API is typed, these are compile-time checked and it's more clear w/o the constants.
1 parent 37b0f1c commit 89785be

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/payments/taprootutils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const buffer_1 = require('buffer');
55
const bcrypto = require('../crypto');
66
const bufferutils_1 = require('../bufferutils');
77
const types_1 = require('../types');
8-
const TAP_LEAF_TAG = 'TapLeaf';
9-
const TAP_BRANCH_TAG = 'TapBranch';
10-
const TAP_TWEAK_TAG = 'TapTweak';
118
exports.LEAF_VERSION_TAPSCRIPT = 0xc0;
129
function rootHashFromPath(controlBlock, tapleafMsg) {
1310
const k = [tapleafMsg];
@@ -70,7 +67,7 @@ exports.findScriptPath = findScriptPath;
7067
function tapleafHash(leaf) {
7168
const version = leaf.version || exports.LEAF_VERSION_TAPSCRIPT;
7269
return bcrypto.taggedHash(
73-
TAP_LEAF_TAG,
70+
'TapLeaf',
7471
buffer_1.Buffer.concat([
7572
buffer_1.Buffer.from([version]),
7673
serializeScript(leaf.output),
@@ -80,13 +77,13 @@ function tapleafHash(leaf) {
8077
exports.tapleafHash = tapleafHash;
8178
function tapTweakHash(pubKey, h) {
8279
return bcrypto.taggedHash(
83-
TAP_TWEAK_TAG,
80+
'TapTweak',
8481
buffer_1.Buffer.concat(h ? [pubKey, h] : [pubKey]),
8582
);
8683
}
8784
exports.tapTweakHash = tapTweakHash;
8885
function tapBranchHash(a, b) {
89-
return bcrypto.taggedHash(TAP_BRANCH_TAG, buffer_1.Buffer.concat([a, b]));
86+
return bcrypto.taggedHash('TapBranch', buffer_1.Buffer.concat([a, b]));
9087
}
9188
function serializeScript(s) {
9289
const varintLen = bufferutils_1.varuint.encodingLength(s.length);

ts_src/payments/taprootutils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import * as bcrypto from '../crypto';
44
import { varuint } from '../bufferutils';
55
import { Tapleaf, Taptree, isTapleaf } from '../types';
66

7-
const TAP_LEAF_TAG = 'TapLeaf';
8-
const TAP_BRANCH_TAG = 'TapBranch';
9-
const TAP_TWEAK_TAG = 'TapTweak';
10-
117
export const LEAF_VERSION_TAPSCRIPT = 0xc0;
128

139
export function rootHashFromPath(
@@ -86,20 +82,20 @@ export function findScriptPath(node: HashTree, hash: Buffer): Buffer[] {
8682
export function tapleafHash(leaf: Tapleaf): Buffer {
8783
const version = leaf.version || LEAF_VERSION_TAPSCRIPT;
8884
return bcrypto.taggedHash(
89-
TAP_LEAF_TAG,
85+
'TapLeaf',
9086
NBuffer.concat([NBuffer.from([version]), serializeScript(leaf.output)]),
9187
);
9288
}
9389

9490
export function tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer {
9591
return bcrypto.taggedHash(
96-
TAP_TWEAK_TAG,
92+
'TapTweak',
9793
NBuffer.concat(h ? [pubKey, h] : [pubKey]),
9894
);
9995
}
10096

10197
function tapBranchHash(a: Buffer, b: Buffer): Buffer {
102-
return bcrypto.taggedHash(TAP_BRANCH_TAG, NBuffer.concat([a, b]));
98+
return bcrypto.taggedHash('TapBranch', NBuffer.concat([a, b]));
10399
}
104100

105101
function serializeScript(s: Buffer): Buffer {

0 commit comments

Comments
 (0)