Skip to content

Commit 244fd8d

Browse files
davidkaplanbitgollm-git
andcommitted
feat(utxo-core): add utility function to check for taproot chain
Add `isTaprootChain` utility function to extract duplicate code and improve maintainability. Issue: BTC-2373 Co-authored-by: llm-git <[email protected]>
1 parent ef13495 commit 244fd8d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

modules/utxo-core/src/bip322/toSpend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Hash } from 'fast-sha256';
22
import { Psbt, Transaction, bitgo, networks } from '@bitgo/utxo-lib';
33

4+
import { isTaprootChain } from './utils';
5+
46
export const BIP322_TAG = 'BIP0322-signed-message';
57

68
/**
@@ -74,8 +76,7 @@ export function buildToSpendTransactionFromChainAndIndex(
7476
message: string | Buffer,
7577
tag = BIP322_TAG
7678
): Transaction<bigint> {
77-
const taprootChains = [...bitgo.chainCodesP2tr, ...bitgo.chainCodesP2trMusig2];
78-
if (taprootChains.some((tc) => tc === chain)) {
79+
if (isTaprootChain(chain)) {
7980
throw new Error('BIP322 is not supported for Taproot script types.');
8081
}
8182

modules/utxo-core/src/bip322/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ export function getBip322ProofInputIndex(psbt: utxolib.Psbt): number | undefined
2828
export function psbtIsBip322Proof(psbt: utxolib.Psbt): boolean {
2929
return getBip322ProofInputIndex(psbt) !== undefined;
3030
}
31+
32+
export function isTaprootChain(chain: utxolib.bitgo.ChainCode): boolean {
33+
const taprootChains = [...utxolib.bitgo.chainCodesP2tr, ...utxolib.bitgo.chainCodesP2trMusig2];
34+
return taprootChains.some((tc) => tc === chain);
35+
}

0 commit comments

Comments
 (0)