use the bip352 derivation for silent payment wallets imported from a mnemonic or device, created in the terminal, scanned from a seedqr or added at another account
What changed, and why it matters
This commit changes how Sparrow Wallet picks the derivation path when creating or importing wallets. It makes the wallet choose BIP-352 (silent payments) paths when the wallet policy is a single-key silent-payment wallet, instead of always using the older script-type defaults. The change is broad but mechanical: many import paths now pass the wallet's policy type into the derivation lookup. There is no direct evidence in the commit of a security vulnerability being fixed; it reads more like a correctness/consistency improvement for silent-payment support.
Review the drongo submodule commit (99f978f5f434f1704fa5e2996b7daa671797d3b6) to confirm the new getDefaultDerivation(PolicyType) logic correctly maps SINGLE_SP to BIP-352 paths and does not introduce regressions for multi-sig or other policy types. Test wallet import/creation flows for silent-payment wallets to ensure the expected BIP-352 derivation is used and that existing non-silent wallets are unaffected.
Security signals we found
Derivation-path selection now depends on policy type, which can change wallet fingerprint/address generation for silent-payment wallets
Broad surface area (12 files) increases risk of an import path being missed or behaving differently
Submodule bump (drongo) likely contains the actual ScriptType.getDefaultDerivation(PolicyType) implementation, but its diff is not supplied
No explicit bounds checks, cryptographic operations, or input validation changes are visible in the supplied diff
Evidence from the diff
The diff updates the drongo submodule and touches 12 Java files. The core change is replacing calls like scriptType.getDefaultDerivation() with scriptType.getDefaultDerivation(policyType) or scriptType.getDefaultDerivation(wallet.getPolicyType()). This lets the wallet select BIP-352 derivations (m/352’/0’ etc.) for PolicyType.SINGLE_SP silent-payment wallets, while keeping legacy script-type derivations for other policies. KeystoreController also removes an explicit SINGLE_SP branch in favor of the unified default-derivation method. The change affects mnemonic, device, xprv, seedqr, terminal, descriptor, and watch-only import flows.
Changed components
drongo submoduleCardImportPaneCodexKeystoreImportPaneDevicePaneMnemonicKeystoreImportPaneMnemonicShareKeystoreImportPaneMnemonicWalletKeystoreImportPaneXprvKeystoreImportPaneDescriptor parserKeystoreImportDialogBip39Dialog (terminal)KeystoreControllerInspect captured patch +41 / −30
### drongo
@@ -1 +1 @@
-Subproject commit 482bdce1bf0604cfb3d7eaced55970688aae52af
+Subproject commit 99f978f5f434f1704fa5e2996b7daa671797d3b6
### src/main/java/com/sparrowwallet/sparrow/control/CardImportPane.java
@@ -62,7 +62,7 @@ private static List<ChildNumber> getDefaultDerivation(Wallet wallet, KeyDerivati
return defaultDerivation.getDerivation();
}
- return wallet.getScriptType() == null ? ScriptType.P2WPKH.getDefaultDerivation() : wallet.getScriptType().getDefaultDerivation();
+ return wallet.getScriptType() == null ? ScriptType.P2WPKH.getDefaultDerivation() : wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType());
}
@Override
### src/main/java/com/sparrowwallet/sparrow/control/CodexKeystoreImportPane.java
@@ -108,7 +108,7 @@ private void createImportButton() {
int scriptAccountsLength = ScriptType.P2SH.equals(wallet.getScriptType()) ? 1 : accounts.length;
for(int i = 0; i < scriptAccountsLength; i++) {
MenuItem item = new MenuItem(accounts[i]);
- final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(i);
+ final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType(), i);
item.setOnAction(event -> {
importButton.setDisable(true);
importKeystore(derivation);
@@ -121,7 +121,8 @@ private void createImportButton() {
}
private List<ChildNumber> getDefaultDerivation() {
- return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation() : defaultDerivation.getDerivation();
+ return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType())
+ : defaultDerivation.getDerivation();
}
private void onInputChange(boolean empty, boolean validChecksum) {
### src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java
@@ -318,7 +318,7 @@ private void createImportButton() {
}
for(PolicyAndScriptType type : types) {
MenuItem item = new MenuItem(type.getDescription());
- final List<ChildNumber> derivation = type.scriptType().getDefaultDerivation();
+ final List<ChildNumber> derivation = type.scriptType().getDefaultDerivation(type.policyType());
item.setOnAction(event -> {
importMenuButton.setDisable(true);
wallet.setPolicyType(type.policyType());
@@ -330,7 +330,7 @@ private void createImportButton() {
List<ScriptType> scriptTypes = ScriptType.getScriptTypesForPolicyType(wallet.getPolicyType()).stream().filter(device::supportsScriptType).toList();
for(ScriptType scriptType : scriptTypes) {
MenuItem item = new MenuItem(scriptType.getDescription());
- final List<ChildNumber> derivation = scriptType.getDefaultDerivation();
+ final List<ChildNumber> derivation = scriptType.getDefaultDerivation(wallet.getPolicyType());
item.setOnAction(event -> {
importMenuButton.setDisable(true);
importKeystore(derivation);
@@ -348,7 +348,7 @@ private void createImportButton() {
int scriptAccountsLength = ScriptType.P2SH.equals(wallet.getScriptType()) ? 1 : accounts.length;
for(int i = 0; i < scriptAccountsLength; i++) {
MenuItem item = new MenuItem(accounts[i]);
- final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(i);
+ final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType(), i);
item.setOnAction(event -> {
importMenuButton.setDisable(true);
importKeystore(derivation);
@@ -466,7 +466,7 @@ private List<ChildNumber> getDefaultDerivation() {
return defaultDerivation.getDerivation();
}
- return wallet == null || wallet.getScriptType() == null ? ScriptType.P2WPKH.getDefaultDerivation() : wallet.getScriptType().getDefaultDerivation();
+ return wallet == null || wallet.getScriptType() == null ? ScriptType.P2WPKH.getDefaultDerivation() : wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType());
}
private void unlock(Device device) {
@@ -858,8 +858,10 @@ private void importSpscan(List<ChildNumber> derivation) {
private void importKeystore(List<ChildNumber> derivation, Keystore keystore) {
if(wallet.getScriptType() == null) {
- ScriptType scriptType = Arrays.stream(ScriptType.ADDRESSABLE_TYPES).filter(type -> type.getDefaultDerivation().getFirst().equals(derivation.getFirst())).findFirst().orElse(ScriptType.P2PKH);
PolicyType policyType = wallet.getPolicyType() != null ? wallet.getPolicyType() : PolicyType.SINGLE_HD;
+ List<ScriptType> scriptTypes = ScriptType.getAddressableScriptTypes(policyType);
+ ScriptType scriptType = scriptTypes.stream().filter(type -> type.getDefaultDerivation(policyType).getFirst().equals(derivation.getFirst())).findFirst()
+ .orElse(scriptTypes.getFirst());
wallet.setName(device.getModel().toDisplayString());
wallet.setPolicyType(policyType);
wallet.setScriptType(scriptType);
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystoreImportPane.java
@@ -69,7 +69,7 @@ private void createImportButton() {
int scriptAccountsLength = ScriptType.P2SH.equals(wallet.getScriptType()) ? 1 : accounts.length;
for(int i = 0; i < scriptAccountsLength; i++) {
MenuItem item = new MenuItem(accounts[i]);
- final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(i);
+ final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType(), i);
item.setOnAction(event -> {
importButton.setDisable(true);
importKeystore(derivation, false);
@@ -82,7 +82,8 @@ private void createImportButton() {
}
private List<ChildNumber> getDefaultDerivation() {
- return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation() : defaultDerivation.getDerivation();
+ return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType())
+ : defaultDerivation.getDerivation();
}
protected void enterMnemonic(int numWords) {
@@ -143,7 +144,8 @@ protected List<Node> createRightButtons() {
protected void onWordChange(boolean empty, boolean validWords, boolean validChecksum) {
if(!empty && validWords) {
try {
- importer.getKeystore(wallet.getPolicyType(), wallet.getScriptType().getDefaultDerivation(), wordEntriesProperty.get(), passphraseProperty.get());
+ importer.getKeystore(wallet.getPolicyType(), wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType()), wordEntriesProperty.get(),
+ passphraseProperty.get());
validChecksum = true;
} catch(ImportException e) {
if(e.getCause() instanceof MnemonicException.MnemonicTypeException) {
@@ -245,7 +247,7 @@ private void prepareImport() {
return;
}
- if(importKeystore(wallet.getScriptType().getDefaultDerivation(), true)) {
+ if(importKeystore(wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType()), true)) {
setExpanded(true);
enterMnemonicButton.setVisible(false);
importButton.setVisible(true);
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicShareKeystoreImportPane.java
@@ -164,7 +164,8 @@ protected void onWordChange(boolean empty, boolean validWords, boolean validChec
existing.add(wordEntriesProperty.get());
}
- importer.getKeystore(wallet.getPolicyType(), wallet.getScriptType().getDefaultDerivation(), existing, passphraseProperty.get());
+ importer.getKeystore(wallet.getPolicyType(), wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType()), existing,
+ passphraseProperty.get());
validSet = true;
complete = true;
} catch(MnemonicException e) {
@@ -209,7 +210,7 @@ private void createImportButton() {
int scriptAccountsLength = ScriptType.P2SH.equals(wallet.getScriptType()) ? 1 : accounts.length;
for(int i = 0; i < scriptAccountsLength; i++) {
MenuItem item = new MenuItem(accounts[i]);
- final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(i);
+ final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType(), i);
item.setOnAction(event -> {
importButton.setDisable(true);
importKeystore(derivation, false);
@@ -222,14 +223,15 @@ private void createImportButton() {
}
private List<ChildNumber> getDefaultDerivation() {
- return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation() : defaultDerivation.getDerivation();
+ return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType())
+ : defaultDerivation.getDerivation();
}
private void prepareImport() {
nextShare();
backButton.setVisible(false);
- if(importKeystore(wallet.getScriptType().getDefaultDerivation(), true)) {
+ if(importKeystore(wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType()), true)) {
setExpanded(true);
enterMnemonicButton.setVisible(false);
importButton.setVisible(true);
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicWalletKeystoreImportPane.java
@@ -222,7 +222,7 @@ public PolicyAndScriptType fromString(String string) {
setExpanded(false);
try {
PolicyAndScriptType type = comboBox.getValue();
- Wallet wallet = getWallet(type.policyType(), type.scriptType(), type.scriptType().getDefaultDerivation());
+ Wallet wallet = getWallet(type.policyType(), type.scriptType(), type.scriptType().getDefaultDerivation(type.policyType()));
if(passphraseProperty.get() != null && !passphraseProperty.get().isEmpty()) {
KeystorePassphraseDialog keystorePassphraseDialog = new KeystorePassphraseDialog(null, wallet.getKeystores().getFirst(), true);
keystorePassphraseDialog.initOwner(this.getScene().getWindow());
### src/main/java/com/sparrowwallet/sparrow/control/XprvKeystoreImportPane.java
@@ -91,7 +91,7 @@ private void createImportButton() {
int scriptAccountsLength = ScriptType.P2SH.equals(wallet.getScriptType()) ? 1 : accounts.length;
for(int i = 0; i < scriptAccountsLength; i++) {
MenuItem item = new MenuItem(accounts[i]);
- final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(i);
+ final List<ChildNumber> derivation = wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType(), i);
item.setOnAction(event -> {
importButton.setDisable(true);
importKeystore(derivation);
@@ -104,7 +104,8 @@ private void createImportButton() {
}
private List<ChildNumber> getDefaultDerivation() {
- return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation() : defaultDerivation.getDerivation();
+ return defaultDerivation == null || defaultDerivation.getDerivation().isEmpty() ? wallet.getScriptType().getDefaultDerivation(wallet.getPolicyType())
+ : defaultDerivation.getDerivation();
}
private void enterXprv() {
### src/main/java/com/sparrowwallet/sparrow/io/Descriptor.java
@@ -151,7 +151,7 @@ private static List<String> getParagraphs(InputStream inputStream) {
private static Wallet ensureKeyDerivations(Wallet wallet) {
for(Keystore keystore : wallet.getKeystores()) {
if(keystore.getKeyDerivation().getMasterFingerprint() == null || keystore.getKeyDerivation().getDerivationPath() == null) {
- keystore.setKeyDerivation(new KeyDerivation(KeyDerivation.DEFAULT_WATCH_ONLY_FINGERPRINT, wallet.getScriptType().getDefaultDerivationPath()));
+ keystore.setKeyDerivation(new KeyDerivation(KeyDerivation.DEFAULT_WATCH_ONLY_FINGERPRINT, wallet.getScriptType().getDefaultDerivationPath(wallet.getPolicyType())));
}
}
### src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java
@@ -3,6 +3,7 @@
import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.KeyDerivation;
import com.sparrowwallet.drongo.Network;
+import com.sparrowwallet.drongo.policy.PolicyType;
import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
@@ -23,6 +24,7 @@ public class KeystoreImportDialog extends Dialog<Keystore> {
private final KeystoreImportController keystoreImportController;
private Keystore keystore;
private final ScriptType scriptType;
+ private final PolicyType policyType;
private final String existingLabel;
public KeystoreImportDialog(Wallet wallet, KeystoreSource initialSource, KeyDerivation currentDerivation, WalletModel currentModel, String currentLabel, boolean restrictImport) {
@@ -35,6 +37,7 @@ public KeystoreImportDialog(Wallet wallet, KeystoreSource initialSource, KeyDeri
AppServices.setStageIcon(dialogPane.getScene().getWindow());
setTitle("Import Keystore");
scriptType = wallet.getScriptType();
+ policyType = wallet.getPolicyType();
existingLabel = currentLabel;
try {
@@ -75,7 +78,7 @@ private Keystore getWatchOnlyKeystore() {
keystore.setLabel(existingLabel);
keystore.setSource(KeystoreSource.SW_WATCH);
keystore.setWalletModel(WalletModel.SPARROW);
- keystore.setKeyDerivation(new KeyDerivation(KeyDerivation.DEFAULT_WATCH_ONLY_FINGERPRINT, scriptType.getDefaultDerivationPath()));
+ keystore.setKeyDerivation(new KeyDerivation(KeyDerivation.DEFAULT_WATCH_ONLY_FINGERPRINT, scriptType.getDefaultDerivationPath(policyType)));
return keystore;
}
### src/main/java/com/sparrowwallet/sparrow/terminal/wallet/Bip39Dialog.java
@@ -108,7 +108,7 @@ protected void createWallet() {
if(!passphrase.getText().isEmpty()) {
try {
PolicyAndScriptType type = scriptType.getSelectedItem();
- Keystore keystore = importer.getKeystore(type.policyType(), type.scriptType().getDefaultDerivation(), getWords(), passphrase.getText());
+ Keystore keystore = importer.getKeystore(type.policyType(), type.scriptType().getDefaultDerivation(type.policyType()), getWords(), passphrase.getText());
PassphraseDialog passphraseDialog = new PassphraseDialog(walletName, keystore, true);
String confirmation = passphraseDialog.showDialog(SparrowTerminal.get().getGui());
if(confirmation == null || !confirmation.equals(passphrase.getText())) {
@@ -185,7 +185,7 @@ protected List<Wallet> getWallets() throws ImportException {
Wallet wallet = new Wallet(walletName);
wallet.setPolicyType(type.policyType());
wallet.setScriptType(type.scriptType());
- Keystore keystore = importer.getKeystore(type.policyType(), wallet.getScriptType().getDefaultDerivation(), getWords(), passphrase.getText());
+ Keystore keystore = importer.getKeystore(type.policyType(), wallet.getScriptType().getDefaultDerivation(type.policyType()), getWords(), passphrase.getText());
wallet.getKeystores().add(keystore);
wallet.setDefaultPolicy(Policy.getPolicy(type.policyType(), wallet.getScriptType(), wallet.getKeystores(), 1));
if(type.policyType() == PolicyType.SINGLE_SP) {
### src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java
@@ -165,7 +165,7 @@ public void initializeView() {
label.setText(keystore.getLabel());
- derivation.setPromptText(getWalletForm().getWallet().getScriptType().getDefaultDerivationPath());
+ derivation.setPromptText(getWalletForm().getWallet().getScriptType().getDefaultDerivationPath(getWalletForm().getWallet().getPolicyType()));
xpubField.managedProperty().bind(xpubField.visibleProperty());
spScanField.managedProperty().bind(spScanField.visibleProperty());
@@ -312,8 +312,7 @@ public void selectSource(ActionEvent event) {
launchImportDialog(keystoreSource);
} else {
fingerprint.setText(KeyDerivation.DEFAULT_WATCH_ONLY_FINGERPRINT);
- derivation.setText(getWalletForm().getWallet().getPolicyType() == PolicyType.SINGLE_SP ? KeyDerivation.writePath(KeyDerivation.getBip352Derivation(0))
- : getWalletForm().getWallet().getScriptType().getDefaultDerivationPath());
+ derivation.setText(getWalletForm().getWallet().getScriptType().getDefaultDerivationPath(getWalletForm().getWallet().getPolicyType()));
selectSourcePane.setVisible(false);
label.requestFocus();
}
@@ -693,7 +692,8 @@ public void scanXpubQR(ActionEvent event) {
}
}
- Keystore keystore = Keystore.fromSeed(result.seed, getWalletForm().getWallet().getPolicyType(), getWalletForm().getWallet().getScriptType().getDefaultDerivation());
+ Keystore keystore = Keystore.fromSeed(result.seed, getWalletForm().getWallet().getPolicyType(),
+ getWalletForm().getWallet().getScriptType().getDefaultDerivation(getWalletForm().getWallet().getPolicyType()));
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
xpub.setText(keystore.getExtendedPublicKey().toString());
@@ -766,9 +766,9 @@ public void update(SettingsChangedEvent event) {
if(walletForm.getWallet().equals(event.getWallet())) {
if(event.getType().equals(SettingsChangedEvent.Type.SCRIPT_TYPE)) {
if(keystore.getSource() == KeystoreSource.SW_WATCH && derivation.getPromptText().equals(derivation.getText())) {
- derivation.setText(event.getWallet().getScriptType().getDefaultDerivationPath());
+ derivation.setText(event.getWallet().getScriptType().getDefaultDerivationPath(event.getWallet().getPolicyType()));
}
- derivation.setPromptText(event.getWallet().getScriptType().getDefaultDerivationPath());
+ derivation.setPromptText(event.getWallet().getScriptType().getDefaultDerivationPath(event.getWallet().getPolicyType()));
if(derivation.getText() != null && !derivation.getText().isEmpty()) {
String derivationPath = derivation.getText();
derivation.setText(derivationPath + " ");Why this scored 33/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.