From efc9d9d554fdce15ed9a9eb7a2417ea239622019 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 15 Nov 2024 16:31:50 +0200 Subject: [PATCH] allow hardened character selection when writing key --- .../java/com/sparrowwallet/drongo/OutputDescriptor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java index 490dc69..fb380dd 100644 --- a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java +++ b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java @@ -623,12 +623,17 @@ public class OutputDescriptor { } public static String writeKey(ExtendedKey pubKey, KeyDerivation keyDerivation, String childDerivation, boolean addKeyOrigin, boolean addKey) { + return writeKey(pubKey, keyDerivation, childDerivation, addKeyOrigin, addKey, false); + } + + public static String writeKey(ExtendedKey pubKey, KeyDerivation keyDerivation, String childDerivation, boolean addKeyOrigin, boolean addKey, boolean useApostrophes) { StringBuilder keyBuilder = new StringBuilder(); if(keyDerivation != null && keyDerivation.getMasterFingerprint() != null && keyDerivation.getMasterFingerprint().length() == 8 && Utils.isHex(keyDerivation.getMasterFingerprint()) && addKeyOrigin) { keyBuilder.append("["); keyBuilder.append(keyDerivation.getMasterFingerprint()); if(!keyDerivation.getDerivation().isEmpty()) { - keyBuilder.append(keyDerivation.getDerivationPath().replaceFirst("^m?/", "/").replace('\'', 'h')); + String path = keyDerivation.getDerivationPath().replaceFirst("^m?/", "/"); + keyBuilder.append(useApostrophes ? path : path.replace('\'', 'h')); } keyBuilder.append("]"); }