support serialization of psbts without non witness utxo input entries

This commit is contained in:
Craig Raw 2023-03-07 13:16:49 +02:00
parent 0f78efc373
commit 7eab644cec
2 changed files with 7 additions and 6 deletions

View file

@ -461,10 +461,10 @@ public class PSBT {
}
public byte[] serialize() {
return serialize(true);
return serialize(true, true);
}
public byte[] serialize(boolean includeXpubs) {
public byte[] serialize(boolean includeXpubs, boolean includeNonWitnessUtxos) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.writeBytes(Utils.hexToBytes(PSBT_MAGIC_HEX));
@ -481,8 +481,9 @@ public class PSBT {
for(PSBTInput psbtInput : getPsbtInputs()) {
List<PSBTEntry> inputEntries = psbtInput.getInputEntries();
for(PSBTEntry entry : inputEntries) {
if(includeXpubs || (entry.getKeyType() != PSBT_IN_BIP32_DERIVATION && entry.getKeyType() != PSBT_IN_PROPRIETARY
&& entry.getKeyType() != PSBT_IN_TAP_INTERNAL_KEY && entry.getKeyType() != PSBT_IN_TAP_BIP32_DERIVATION)) {
if((includeXpubs || (entry.getKeyType() != PSBT_IN_BIP32_DERIVATION && entry.getKeyType() != PSBT_IN_PROPRIETARY
&& entry.getKeyType() != PSBT_IN_TAP_INTERNAL_KEY && entry.getKeyType() != PSBT_IN_TAP_BIP32_DERIVATION))
&& (includeNonWitnessUtxos || entry.getKeyType() != PSBT_IN_NON_WITNESS_UTXO)) {
entry.serializeToStream(baos);
}
}
@ -630,7 +631,7 @@ public class PSBT {
}
public String toBase64String(boolean includeXpubs) {
return Base64.toBase64String(serialize(includeXpubs));
return Base64.toBase64String(serialize(includeXpubs, true));
}
public static boolean isPSBT(byte[] b) {

View file

@ -51,7 +51,7 @@ public enum WalletModel {
}
public boolean alwaysIncludeNonWitnessUtxo() {
if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT || this == KEYSTONE || this == GORDIAN_SEED_TOOL) {
if(this == COLDCARD || this == COBO_VAULT || this == PASSPORT || this == KEYSTONE || this == GORDIAN_SEED_TOOL || this == SEEDSIGNER) {
return false;
}