mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-10 16:43:14 +00:00
handle import of samourai wallet backup file with extraneous appended data
This commit is contained in:
@@ -29,10 +29,7 @@ public class Samourai implements KeystoreFileImport {
|
||||
try {
|
||||
String input = CharStreams.toString(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
|
||||
Gson gson = new Gson();
|
||||
Type stringStringMap = new TypeToken<Map<String, JsonElement>>() {
|
||||
}.getType();
|
||||
Map<String, JsonElement> map = gson.fromJson(input, stringStringMap);
|
||||
Map<String, JsonElement> map = this.parseJsonInput(input);
|
||||
|
||||
String payload = input;
|
||||
if(map.containsKey("payload")) {
|
||||
@@ -53,7 +50,7 @@ public class Samourai implements KeystoreFileImport {
|
||||
throw new ImportException("Unsupported backup version: " + version);
|
||||
}
|
||||
|
||||
SamouraiBackup backup = gson.fromJson(decrypted, SamouraiBackup.class);
|
||||
SamouraiBackup backup = new Gson().fromJson(decrypted, SamouraiBackup.class);
|
||||
DeterministicSeed seed = new DeterministicSeed(Utils.hexToBytes(backup.wallet.seed), password, 0);
|
||||
Keystore keystore = Keystore.fromSeed(seed, scriptType.getDefaultDerivation());
|
||||
keystore.setLabel(getWalletModel().toDisplayString());
|
||||
@@ -67,6 +64,24 @@ public class Samourai implements KeystoreFileImport {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, JsonElement> parseJsonInput(String input) {
|
||||
Gson gson = new Gson();
|
||||
Type stringStringMap = new TypeToken<Map<String, JsonElement>>() {
|
||||
}.getType();
|
||||
|
||||
try {
|
||||
return gson.fromJson(input, stringStringMap);
|
||||
} catch (JsonParseException e) {
|
||||
int closingBracket = input.indexOf('}');
|
||||
if (closingBracket < 0) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
String fixedInput = input.substring(0, closingBracket + 1);
|
||||
return gson.fromJson(fixedInput, stringStringMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeystoreImportScannable() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user