mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
add option to strip sensitive info from psbt serialization
This commit is contained in:
parent
428054d375
commit
b7038b19f9
2 changed files with 22 additions and 6 deletions
|
@ -31,8 +31,8 @@ tasks.withType(AbstractArchiveTask) {
|
|||
group 'com.sparrowwallet'
|
||||
version '0.9'
|
||||
|
||||
sourceCompatibility = 1.9
|
||||
targetCompatibility = 1.9
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -16,6 +16,8 @@ import java.nio.ByteBuffer;
|
|||
import java.util.*;
|
||||
|
||||
import static com.sparrowwallet.drongo.psbt.PSBTEntry.*;
|
||||
import static com.sparrowwallet.drongo.psbt.PSBTInput.PSBT_IN_BIP32_DERIVATION;
|
||||
import static com.sparrowwallet.drongo.psbt.PSBTOutput.*;
|
||||
|
||||
public class PSBT {
|
||||
public static final byte PSBT_GLOBAL_UNSIGNED_TX = 0x00;
|
||||
|
@ -432,6 +434,10 @@ public class PSBT {
|
|||
}
|
||||
|
||||
public byte[] serialize() {
|
||||
return serialize(true);
|
||||
}
|
||||
|
||||
public byte[] serialize(boolean includeXpubs) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
baos.writeBytes(Utils.hexToBytes(PSBT_MAGIC_HEX));
|
||||
|
@ -439,23 +445,29 @@ public class PSBT {
|
|||
|
||||
List<PSBTEntry> globalEntries = getGlobalEntries();
|
||||
for(PSBTEntry entry : globalEntries) {
|
||||
if(includeXpubs || (entry.getKeyType() != PSBT_GLOBAL_BIP32_PUBKEY && entry.getKeyType() != PSBT_GLOBAL_PROPRIETARY)) {
|
||||
entry.serializeToStream(baos);
|
||||
}
|
||||
}
|
||||
baos.writeBytes(new byte[] {(byte)0x00});
|
||||
|
||||
for(PSBTInput psbtInput : getPsbtInputs()) {
|
||||
List<PSBTEntry> inputEntries = psbtInput.getInputEntries();
|
||||
for(PSBTEntry entry : inputEntries) {
|
||||
if(includeXpubs || entry.getKeyType() != PSBT_IN_BIP32_DERIVATION) {
|
||||
entry.serializeToStream(baos);
|
||||
}
|
||||
}
|
||||
baos.writeBytes(new byte[] {(byte)0x00});
|
||||
}
|
||||
|
||||
for(PSBTOutput psbtOutput : getPsbtOutputs()) {
|
||||
List<PSBTEntry> outputEntries = psbtOutput.getOutputEntries();
|
||||
for(PSBTEntry entry : outputEntries) {
|
||||
if(includeXpubs || (entry.getKeyType() != PSBT_OUT_REDEEM_SCRIPT && entry.getKeyType() != PSBT_OUT_WITNESS_SCRIPT && entry.getKeyType() != PSBT_OUT_BIP32_DERIVATION && entry.getKeyType() != PSBT_OUT_PROPRIETARY)) {
|
||||
entry.serializeToStream(baos);
|
||||
}
|
||||
}
|
||||
baos.writeBytes(new byte[] {(byte)0x00});
|
||||
}
|
||||
|
||||
|
@ -584,7 +596,11 @@ public class PSBT {
|
|||
}
|
||||
|
||||
public String toBase64String() {
|
||||
return Base64.toBase64String(serialize());
|
||||
return toBase64String(true);
|
||||
}
|
||||
|
||||
public String toBase64String(boolean includeXpubs) {
|
||||
return Base64.toBase64String(serialize(includeXpubs));
|
||||
}
|
||||
|
||||
public static boolean isPSBT(byte[] b) {
|
||||
|
|
Loading…
Reference in a new issue