Skip to content

Commit

Permalink
Verified Bitcoin recovery address type
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Oct 25, 2023
1 parent adca21f commit 2c4e326
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions typescript/src/services/deposits/deposits-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BitcoinClient,
BitcoinHashUtils,
BitcoinLocktimeUtils,
BitcoinScriptUtils,
} from "../../lib/bitcoin"
import { Hex } from "../../lib/utils"
import { Deposit } from "./deposit"
Expand Down Expand Up @@ -80,9 +81,17 @@ export class DepositsService {

const bitcoinNetwork = await this.bitcoinClient.getNetwork()

// TODO: Only P2(W)PKH addresses can be used for recovery. The below conversion
// function ensures that but, it would be good to check it here as well
// in case the converter implementation changes.
const recoveryOutputScript = BitcoinAddressConverter.addressToOutputScript(
bitcoinRecoveryAddress,
bitcoinNetwork
)
if (
!BitcoinScriptUtils.isP2PKHScript(recoveryOutputScript) &&
!BitcoinScriptUtils.isP2WPKHScript(recoveryOutputScript)
) {
throw new Error("Bitcoin recovery address must be P2PKH or P2WPKH")
}

const refundPublicKeyHash = BitcoinAddressConverter.addressToPublicKeyHash(
bitcoinRecoveryAddress,
bitcoinNetwork
Expand Down

0 comments on commit 2c4e326

Please sign in to comment.