From 3a2344f1297e25a9c691ddad66264e00c391af44 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 19 Apr 2024 09:59:36 +0200 Subject: [PATCH] parse output descriptors with missing fingerprints in key origin information --- src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java index 8476e9f..188341b 100644 --- a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java +++ b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java @@ -25,7 +25,7 @@ public class OutputDescriptor { private static final Pattern XPUB_PATTERN = Pattern.compile("(\\[[^\\]]+\\])?(.(?:pub|prv)[^/\\,)]{100,112})(/[/\\d*'hH<>;]+)?"); private static final Pattern PUBKEY_PATTERN = Pattern.compile("(\\[[^\\]]+\\])?(0[23][0-9a-fA-F]{32})"); private static final Pattern MULTI_PATTERN = Pattern.compile("multi\\(([\\d+])"); - private static final Pattern KEY_ORIGIN_PATTERN = Pattern.compile("\\[([A-Fa-f0-9]{8})([/\\d'hH]+)\\]"); + private static final Pattern KEY_ORIGIN_PATTERN = Pattern.compile("\\[([A-Fa-f0-9]{8})?([/\\d'hH]+)\\]"); private static final Pattern MULTIPATH_PATTERN = Pattern.compile("<([\\d*'hH;]+)>"); private static final Pattern CHECKSUM_PATTERN = Pattern.compile("#([" + CHECKSUM_CHARSET + "]{8})$"); @@ -414,7 +414,7 @@ public class OutputDescriptor { String keyOrigin = matcher.group(1); Matcher keyOriginMatcher = KEY_ORIGIN_PATTERN.matcher(keyOrigin); if(keyOriginMatcher.matches()) { - byte[] masterFingerprintBytes = Utils.hexToBytes(keyOriginMatcher.group(1)); + byte[] masterFingerprintBytes = keyOriginMatcher.group(1) != null ? Utils.hexToBytes(keyOriginMatcher.group(1)) : new byte[4]; if(masterFingerprintBytes.length != 4) { throw new IllegalArgumentException("Master fingerprint must be 4 bytes: " + Utils.bytesToHex(masterFingerprintBytes)); }