fix npe on null p2sh redeem script

This commit is contained in:
Craig Raw 2025-09-12 15:42:05 +02:00
parent 1623f923b3
commit 9c826d7819
2 changed files with 14 additions and 2 deletions

View file

@ -16,6 +16,14 @@ public class SilentPaymentScanAddress extends SilentPaymentAddress {
}
}
public ECKey getChangeTweakKey() {
return SilentPaymentUtils.getLabelledTweakKey(getScanKey(), 0);
}
public ECKey getLabelledTweakKey(int labelIndex) {
return SilentPaymentUtils.getLabelledTweakKey(getScanKey(), labelIndex);
}
public SilentPaymentScanAddress getChangeAddress() {
return getLabelledAddress(0);
}

View file

@ -89,7 +89,7 @@ public class SilentPaymentUtils {
break;
case P2SH:
Script redeemScript = input.getScriptSig().getFirstNestedScript();
if(ScriptType.P2WPKH.isScriptType(redeemScript)) {
if(redeemScript != null && ScriptType.P2WPKH.isScriptType(redeemScript)) {
if(input.getWitness() != null && input.getWitness().getPushCount() == 2) {
byte[] pubKey = input.getWitness().getPushes().getLast();
if(pubKey != null && pubKey.length == 33) {
@ -270,8 +270,12 @@ public class SilentPaymentUtils {
}
public static ECKey getLabelledSpendKey(ECKey scanPrivateKey, ECKey spendPublicKey, int labelIndex) {
return spendPublicKey.add(getLabelledTweakKey(scanPrivateKey, labelIndex), true);
}
public static ECKey getLabelledTweakKey(ECKey scanPrivateKey, int labelIndex) {
BigInteger labelTweak = new BigInteger(1, Utils.taggedHash(BIP_0352_LABEL_TAG,
Utils.concat(scanPrivateKey.getPrivKeyBytes(), ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(labelIndex).array())));
return spendPublicKey.add(ECKey.fromPublicOnly(ECKey.publicPointFromPrivate(labelTweak).getEncoded(true)), true);
return ECKey.fromPublicOnly(ECKey.publicPointFromPrivate(labelTweak).getEncoded(true));
}
}