Skip to content

Commit

Permalink
Fix isValidBtcAddress function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
r-czajkowski committed Jul 24, 2023
1 parent 2d46c38 commit 86b6375
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/threshold-ts/utils/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 86b6375

Please sign in to comment.