Support bip32 paths with 'h' instead of an apostrophe (#4881)

This commit is contained in:
benthecarman 2022-11-12 12:49:38 -06:00 committed by GitHub
parent 7a64accd69
commit cc8d327ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -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)

View file

@ -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)