mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-01-30 00:51:11 +00:00
add support for parsing compactseedqr without header or ec bytes
This commit is contained in:
parent
e15eb7c7f3
commit
d7b97c99dc
1 changed files with 24 additions and 16 deletions
|
@ -31,25 +31,33 @@ public class SeedQR {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeterministicSeed getSeed(byte[] compactSeedQr) {
|
public static DeterministicSeed getSeed(byte[] compactSeedQr) {
|
||||||
if(compactSeedQr[0] != 0x41 && compactSeedQr[0] != 0x42) {
|
byte[] seed;
|
||||||
throw new IllegalArgumentException("Invalid CompactSeedQR header");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(compactSeedQr.length < 19) {
|
if(compactSeedQr.length == 16 || compactSeedQr.length == 32) {
|
||||||
throw new IllegalArgumentException("Invalid CompactSeedQR length");
|
//Assume scan contains seed only
|
||||||
}
|
seed = compactSeedQr;
|
||||||
|
|
||||||
String qrHex = Utils.bytesToHex(compactSeedQr);
|
|
||||||
String seedHex;
|
|
||||||
if(qrHex.endsWith("0ec11ec11")) {
|
|
||||||
seedHex = qrHex.substring(3, qrHex.length() - 9); //12 word, high EC
|
|
||||||
} else if(qrHex.endsWith("0ec")) {
|
|
||||||
seedHex = qrHex.substring(3, qrHex.length() - 3); //12 word, low EC
|
|
||||||
} else {
|
} else {
|
||||||
seedHex = qrHex.substring(3, qrHex.length() - 1); //24 word
|
//Assume scan contains header, seed and EC bytes
|
||||||
}
|
if(compactSeedQr[0] != 0x41 && compactSeedQr[0] != 0x42) {
|
||||||
|
throw new IllegalArgumentException("Invalid CompactSeedQR header");
|
||||||
|
}
|
||||||
|
|
||||||
byte[] seed = Utils.hexToBytes(seedHex);
|
if(compactSeedQr.length < 19) {
|
||||||
|
throw new IllegalArgumentException("Invalid CompactSeedQR length");
|
||||||
|
}
|
||||||
|
|
||||||
|
String qrHex = Utils.bytesToHex(compactSeedQr);
|
||||||
|
String seedHex;
|
||||||
|
if(qrHex.endsWith("0ec11ec11")) {
|
||||||
|
seedHex = qrHex.substring(3, qrHex.length() - 9); //12 word, high EC
|
||||||
|
} else if(qrHex.endsWith("0ec")) {
|
||||||
|
seedHex = qrHex.substring(3, qrHex.length() - 3); //12 word, low EC
|
||||||
|
} else {
|
||||||
|
seedHex = qrHex.substring(3, qrHex.length() - 1); //24 word
|
||||||
|
}
|
||||||
|
|
||||||
|
seed = Utils.hexToBytes(seedHex);
|
||||||
|
}
|
||||||
|
|
||||||
if(seed.length < 16 || seed.length > 32 || seed.length % 4 > 0) {
|
if(seed.length < 16 || seed.length > 32 || seed.length % 4 > 0) {
|
||||||
throw new IllegalArgumentException("Invalid CompactSeedQR length: " + compactSeedQr.length);
|
throw new IllegalArgumentException("Invalid CompactSeedQR length: " + compactSeedQr.length);
|
||||||
|
|
Loading…
Reference in a new issue