Skip to content

Commit

Permalink
derivekey: don't require --neuter for xpub input
Browse files Browse the repository at this point in the history
Previously, if xpub was passed, the tool crashed without --neuter option.
Now it is optional if the input is an xpub.
  • Loading branch information
starius committed Jan 12, 2025
1 parent d3e14a4 commit 6e4a076
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/chantools/derivekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func deriveKey(extendedKey *hdkeychain.ExtendedKey, path string,
}

privKey, xPriv := na, na
if !neuter {
if !neuter && wif != nil {
privKey, xPriv = wif.String(), child.String()
}

Expand Down
20 changes: 20 additions & 0 deletions cmd/chantools/derivekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,23 @@ func TestDeriveKeyXpub(t *testing.T) {
h.assertLogContains("03dc8655d58bd4fd4326863fe34bd5cdddbefaa3b042571" +
"05eb1ab99aa05e01c2a")
}

func TestDeriveKeyXpubNoNeuter(t *testing.T) {
h := newHarness(t)

// Derive a specific key from xpub.
derive := &deriveKeyCommand{
Path: "m/5/6",
rootKey: &rootKey{
RootKey: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap" +
"9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqse" +
"fD265TMg7usUDFdp6W1EGMcet8",
},
}

err := derive.Execute(nil, nil)
require.NoError(t, err)

h.assertLogContains("03dc8655d58bd4fd4326863fe34bd5cdddbefaa3b042571" +
"05eb1ab99aa05e01c2a")
}

0 comments on commit 6e4a076

Please sign in to comment.