From bb144977e02cb130804851444a25fef0590a850e Mon Sep 17 00:00:00 2001 From: Tomasz Slabon Date: Wed, 25 Oct 2023 17:00:54 +0200 Subject: [PATCH] Verify Bitcoin redeemer script --- .../src/services/redemptions/redemptions-service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/typescript/src/services/redemptions/redemptions-service.ts b/typescript/src/services/redemptions/redemptions-service.ts index 363f0454a..03673ce8b 100644 --- a/typescript/src/services/redemptions/redemptions-service.ts +++ b/typescript/src/services/redemptions/redemptions-service.ts @@ -7,6 +7,7 @@ import { BitcoinAddressConverter, BitcoinClient, BitcoinNetwork, + BitcoinScriptUtils, BitcoinTxOutput, BitcoinUtxo, } from "../../lib/bitcoin" @@ -58,7 +59,14 @@ export class RedemptionsService { bitcoinNetwork ) - // TODO: Validate the given script is supported for redemption. + if ( + !BitcoinScriptUtils.isP2PKHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2WPKHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2SHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2WSHScript(redeemerOutputScript) + ) { + throw new Error("Redeemer output script must be of standard type") + } const { walletPublicKey, mainUtxo } = await this.findWalletForRedemption( redeemerOutputScript,