show the wrong network error when a coldcard multisig keystore import fails, instead of the singlesig fallback derivation not found error
What changed, and why it matters
This commit fixes an error-message bug when importing a Coldcard hardware wallet into Sparrow for multisig (multi-signature) setups. Previously, if the multisig import failed because the wallet file was for the wrong Bitcoin network (for example, a testnet file imported while Sparrow is set to mainnet), the app would silently fall back to a single-signature import path and then report a confusing 'derivation not found' error. After the change, the app surfaces the real 'wrong network' error instead. It is a user-experience and diagnostic fix, not a vulnerability that lets an attacker steal funds or run code.
Treat as a routine bug-fix / UX improvement. Reviewers can verify the new unit test passes and that no other import paths hide similar exception causes. No urgent security response is indicated by the diff alone.
Security signals we found
Error-handling path changed to preserve original exception cause
Unit test added for wrong-network import failure case
No cryptographic, memory-safety, or trust-boundary changes observed
Evidence from the diff
ColdcardMultisig.getKeystore() first tries to parse the supplied JSON as a multisig keystore and, on any exception, falls back to parsing it as a singlesig keystore. The fallback could succeed or fail with its own ImportException. When the multisig data was present but invalid for the current network, the fallback singlesig parse would throw a misleading ‘derivation not found’ ImportException, hiding the underlying IllegalArgumentException (‘wrong network’). The patch wraps the singlesig fallback in a try/catch and, if the original multisig failure was an IllegalArgumentException, rethrows an ImportException that chains the original multisig cause. A unit test verifies that importing a multisig keystore with the wrong network now produces an exception whose cause mentions ‘mainnet’.
Changed components
src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.javasrc/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.javaInspect captured patch +17 / −1
### src/main/java/com/sparrowwallet/sparrow/io/ColdcardMultisig.java
@@ -43,7 +43,15 @@ public Keystore getKeystore(PolicyType policyType, ScriptType scriptType, InputS
try {
keystore = getKeystoreMultisig(policyType, scriptType, firstClone, password);
} catch(Exception e) {
- keystore = getKeystoreSinglesig(policyType, scriptType, secondClone, password);
+ try {
+ keystore = getKeystoreSinglesig(policyType, scriptType, secondClone, password);
+ } catch(ImportException singlesigException) {
+ //The multisig fields for this script type were present but invalid, so the multisig error is the relevant one
+ if(e instanceof IllegalArgumentException) {
+ throw new ImportException("Error importing keystore for " + scriptType, e);
+ }
+ throw singlesigException;
+ }
}
return keystore;
### src/test/java/com/sparrowwallet/sparrow/io/ColdcardMultisigTest.java
@@ -57,6 +57,14 @@ public void importKeystore2b() throws ImportException {
Assertions.assertTrue(keystore.isValid());
}
+ @Test
+ public void importKeystoreWrongNetwork() {
+ Network.set(Network.MAINNET);
+ ColdcardMultisig ccMultisig = new ColdcardMultisig();
+ ImportException e = Assertions.assertThrows(ImportException.class, () -> ccMultisig.getKeystore(PolicyType.MULTI_HD, ScriptType.P2WSH, getInputStream("cc-multisig-keystore-2.json"), null));
+ Assertions.assertTrue(e.getCause().getMessage().contains("mainnet"));
+ }
+
@Test
public void importWallet1() throws ImportException {
ColdcardMultisig ccMultisig = new ColdcardMultisig();Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.