ElementsProject / ElementsProject/libwally-core

Infer relative derivation when parent key level > 0

Open
#326 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
307
Forks
159
Avg merge
2h 56m
Merged PRs (30d)
4

Description

The new `bip32_key_from_parent_path_str` function takes a `path_str` argument. When this starts with `m/` it should strip the first `depth` levels from the path string. Currently it just treats everything as a relative path.

This would help me avoid a string manipulation workaround like [this]( https://github.com/Sjors/libwally-swift/pull/68/files#diff-bcd043f6650c77d7e88bc7a918917574b15eb95f32f2da89fd0ddbe630dea98dR195-R199):

```swift
// Convert absolute path to relative:
var tmpPath = path
if path.split(separator: "/").first == "m" {
tmpPath = path.split(separator: "/").dropFirst(1 + Int(self.wally_ext_key.depth)).joined(separator: "/")
}
```

It's especially useful in de context of PSBT processing, where the PSBT will have absolute paths, but the wallet may want to derive from a (cached) xpub to see if it can sign something, as well as for change detection.

Perhaps a flag could be added to (dis)allow the use of absolute paths when deriving from `depth > 0` since that can lead to mistakes.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.