From f34ce07f78961e0881736e6ce6ab150a73c5d8f9 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Tue, 19 Sep 2023 13:55:34 +0800 Subject: [PATCH] Hardened path verification / validation - Added addtional regex check to the path validation string - Exposed ChildNumber class in the API --- lib/dartsv.dart | 1 + lib/src/crypto/hdutils.dart | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/dartsv.dart b/lib/dartsv.dart index 68ff5c4..8e90782 100644 --- a/lib/dartsv.dart +++ b/lib/dartsv.dart @@ -49,5 +49,6 @@ export 'src/encoding/utils.dart'; export 'src/encoding/base58check.dart'; export 'src/crypto/ecies.dart'; export 'src/crypto/hdutils.dart'; +export 'src/crypto/childnumber.dart'; diff --git a/lib/src/crypto/hdutils.dart b/lib/src/crypto/hdutils.dart index 2d418d5..97d8479 100644 --- a/lib/src/crypto/hdutils.dart +++ b/lib/src/crypto/hdutils.dart @@ -68,7 +68,11 @@ class HDUtils { static List parsePath(String path) { if (!(path.startsWith("m") || path.startsWith("M"))) - throw new InvalidPathException("Valid paths start with an 'm' or an 'M'"); + throw InvalidPathException("Valid paths start with an 'm' or an 'M'"); + + final regex = RegExp(r"^([mM]\/)?(\d+'?\/)*\d+'?$"); + if (!regex.hasMatch(path)) throw InvalidPathException("Invalid path expression"); + path = path.toUpperCase(); path = path.replaceAll("'", "H");