From cc8d327ea531c961731f869746cf548d8e948af5 Mon Sep 17 00:00:00 2001 From: benthecarman <15256660+benthecarman@users.noreply.github.com> Date: Sat, 12 Nov 2022 12:49:38 -0600 Subject: [PATCH] Support bip32 paths with 'h' instead of an apostrophe (#4881) --- .../org/bitcoins/core/crypto/bip32/BIP32PathTest.scala | 6 ++++++ core/src/main/scala/org/bitcoins/core/hd/BIP32Path.scala | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala index 89cba9e0a6..de67495cd9 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala @@ -90,6 +90,12 @@ class BIP32PathTest extends BitcoinSUnitTest { assert(fromString.path.head.toUInt32 == ExtKey.hardenedIdx) } + it must "parse a hardened path without an apostrophe" in { + val fromString = BIP32Path.fromString("m/0h") + assert(fromString.path.length == 1) + assert(fromString.path.head.toUInt32 == ExtKey.hardenedIdx) + } + it must "parse a hardened path from bytes" in { val fromString = BIP32Path.fromBytes(hex"0x80000000") assert(fromString.path.length == 1) diff --git a/core/src/main/scala/org/bitcoins/core/hd/BIP32Path.scala b/core/src/main/scala/org/bitcoins/core/hd/BIP32Path.scala index 0828bcb05e..93e1929b4d 100644 --- a/core/src/main/scala/org/bitcoins/core/hd/BIP32Path.scala +++ b/core/src/main/scala/org/bitcoins/core/hd/BIP32Path.scala @@ -136,7 +136,7 @@ object BIP32Path extends Factory[BIP32Path] with StringFactory[BIP32Path] { val path = rest.map { str => val (index: String, hardened: Boolean) = - if (str.endsWith("'")) { + if (str.endsWith("'") || str.endsWith("h")) { (str.dropRight(1), true) } else { (str, false)