From 3d85b2550f9d747cd00eff0faa9516767695d6fd Mon Sep 17 00:00:00 2001 From: Tomasz Slabon Date: Wed, 25 Oct 2023 17:00:54 +0200 Subject: [PATCH] Verify Bitcoin redeemer output script --- .../src/services/redemptions/redemptions-service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/typescript/src/services/redemptions/redemptions-service.ts b/typescript/src/services/redemptions/redemptions-service.ts index 363f0454a..690037877 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" @@ -57,8 +58,14 @@ export class RedemptionsService { bitcoinRedeemerAddress, 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,