mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 10:06:45 +00:00
test for psbt in bytes form
This commit is contained in:
parent
3d292b9dcc
commit
314ee075c2
1 changed files with 12 additions and 5 deletions
|
@ -22,7 +22,8 @@ public class PSBT {
|
||||||
public static final byte PSBT_GLOBAL_VERSION = (byte)0xfb;
|
public static final byte PSBT_GLOBAL_VERSION = (byte)0xfb;
|
||||||
public static final byte PSBT_GLOBAL_PROPRIETARY = (byte)0xfc;
|
public static final byte PSBT_GLOBAL_PROPRIETARY = (byte)0xfc;
|
||||||
|
|
||||||
public static final String PSBT_MAGIC = "70736274";
|
public static final String PSBT_MAGIC_HEX = "70736274";
|
||||||
|
public static final int PSBT_MAGIC_INT = 1886610036;
|
||||||
|
|
||||||
private static final int STATE_GLOBALS = 1;
|
private static final int STATE_GLOBALS = 1;
|
||||||
private static final int STATE_INPUTS = 2;
|
private static final int STATE_INPUTS = 2;
|
||||||
|
@ -59,7 +60,7 @@ public class PSBT {
|
||||||
|
|
||||||
byte[] magicBuf = new byte[4];
|
byte[] magicBuf = new byte[4];
|
||||||
psbtByteBuffer.get(magicBuf);
|
psbtByteBuffer.get(magicBuf);
|
||||||
if (!PSBT_MAGIC.equalsIgnoreCase(Hex.toHexString(magicBuf))) {
|
if (!PSBT_MAGIC_HEX.equalsIgnoreCase(Hex.toHexString(magicBuf))) {
|
||||||
throw new PSBTParseException("PSBT has invalid magic value");
|
throw new PSBTParseException("PSBT has invalid magic value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +315,7 @@ public class PSBT {
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
// magic
|
// magic
|
||||||
baos.write(Hex.decode(PSBT_MAGIC), 0, Hex.decode(PSBT_MAGIC).length);
|
baos.write(Hex.decode(PSBT_MAGIC_HEX), 0, Hex.decode(PSBT_MAGIC_HEX).length);
|
||||||
// separator
|
// separator
|
||||||
baos.write((byte) 0xff);
|
baos.write((byte) 0xff);
|
||||||
|
|
||||||
|
@ -517,11 +518,17 @@ public class PSBT {
|
||||||
return bip32buf;
|
return bip32buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPSBT(byte[] b) {
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(b);
|
||||||
|
int header = buffer.getInt();
|
||||||
|
return header == PSBT_MAGIC_INT;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isPSBT(String s) {
|
public static boolean isPSBT(String s) {
|
||||||
if (Utils.isHex(s) && s.startsWith(PSBT_MAGIC)) {
|
if (Utils.isHex(s) && s.startsWith(PSBT_MAGIC_HEX)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return Utils.isBase64(s) && Hex.toHexString(Base64.decode(s)).startsWith(PSBT_MAGIC);
|
return Utils.isBase64(s) && Hex.toHexString(Base64.decode(s)).startsWith(PSBT_MAGIC_HEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue