From 86b63759ca6b892908294a4bb488ba94d92764d3 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Mon, 24 Jul 2023 20:45:10 +0200 Subject: [PATCH] Fix `isValidBtcAddress` function Pass correct value to the `validate` function from `bitcoin-address-validation` package. The `toBcoinNetwork` function from `tbtc-v2.ts` lib returns the network as string expected by the `bcoin` lib(meaning `main` or `testnet`). The `bitcoin-address-validation` package expects `mainnet` or `testnet` that match the enumerated `BitcoinNetwork` values from `tbtc-v2.ts` lib. Here we call `valuesOf` on the `BitcoinNetwork` enum to get the expected network as string by the `bitcoin-address-validation` package. --- src/threshold-ts/utils/bitcoin.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/threshold-ts/utils/bitcoin.ts b/src/threshold-ts/utils/bitcoin.ts index b7bcdef51..1a5953ef5 100644 --- a/src/threshold-ts/utils/bitcoin.ts +++ b/src/threshold-ts/utils/bitcoin.ts @@ -5,7 +5,6 @@ export { createOutputScriptFromAddress, createAddressFromOutputScript, } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" -import { toBcoinNetwork } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin-network" import { AddressType, getAddressInfo, @@ -19,7 +18,7 @@ export const isValidBtcAddress = ( address: string, network: BitcoinNetwork = BitcoinNetwork.Mainnet ): boolean => { - return validate(address, toBcoinNetwork(network) as Network) + return validate(address, network.valueOf() as Network) } // P2PKH, P2WPKH, P2SH, or P2WSH