Skip to content

Commit 836cf6c

Browse files
committed
extract tapleaf identification function
1 parent baa15b7 commit 836cf6c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

client/src/lib/elements.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ const getControlBlock = witness => {
4040
return witness[witness.length - 1]
4141
}
4242

43+
export const isSimplicityTapleafVersion = (controlBlock) => {
44+
return controlBlock && (controlBlock.startsWith('be') || controlBlock.startsWith('bf'))
45+
}
46+
4347
// Check if a vin is a P2TR Simplicity spend
4448
// A P2TR Simplicity spend has:
4549
// - 4 witness elements (or 5 with optional annex)
46-
// - Control block starts with 'be' or 'bf' (leaf version for Simplicity)
50+
// - is a simplicity Tapleaf
4751
export const isSimplicitySpend = (vin) => {
4852
if (!process.env.IS_ELEMENTS || !vin.witness) return false
4953

@@ -54,7 +58,7 @@ export const isSimplicitySpend = (vin) => {
5458
if (witnessLen !== 4 && !(witnessLen === 5 && hasAnnexBlock)) return false
5559

5660
const controlBlock = getControlBlock(vin.witness)
57-
return controlBlock && (controlBlock.startsWith('be') || controlBlock.startsWith('bf'))
61+
return isSimplicityTapleafVersion(controlBlock)
5862
}
5963

6064
// Extract Simplicity witness components from a vin

0 commit comments

Comments
 (0)