Skip to content

Add ability to retrieve private keys as bytes#199

Merged
thunderbiscuit merged 4 commits intobitcoindevkit:masterfrom
thunderbiscuit:feat/retrieve-private-keys
Oct 3, 2022
Merged

Add ability to retrieve private keys as bytes#199
thunderbiscuit merged 4 commits intobitcoindevkit:masterfrom
thunderbiscuit:feat/retrieve-private-keys

Conversation

@thunderbiscuit
Copy link
Copy Markdown
Member

@thunderbiscuit thunderbiscuit commented Sep 26, 2022

This feature is needed for compatibility with LDKLite, where the initial entropy given to LDK is the private key of the root of the BIP32 derivation tree.

Closes #188

Description

Changelog notice

APIs Added:
    - Add `secret_key_bytes()` method on the `DescriptorSecretKey` [#199]

[#199](https://github.com/bitcoindevkit/bdk-ffi/pull/199)

Notes to the reviewers

I just want to make sure I understand why the BdkDescriptorSecretKey::SinglePriv(_) is unreachable (will fix the code to add the unreachable!() if my understanding is correct. Is it because we currently only build the DescriptorSecretKey from mnemonics, and always make them extendable?

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@thunderbiscuit thunderbiscuit force-pushed the feat/retrieve-private-keys branch from 1d08b6a to 3585c0b Compare September 26, 2022 15:02
@thunderbiscuit thunderbiscuit self-assigned this Sep 26, 2022
@thunderbiscuit thunderbiscuit added this to the Release 0.10.0 milestone Sep 26, 2022
@thunderbiscuit thunderbiscuit force-pushed the feat/retrieve-private-keys branch from 3585c0b to 33c185f Compare September 26, 2022 15:05
@thunderbiscuit thunderbiscuit mentioned this pull request Sep 29, 2022
5 tasks
@thunderbiscuit thunderbiscuit force-pushed the feat/retrieve-private-keys branch 2 times, most recently from 403af63 to cdd2a64 Compare September 29, 2022 19:23
Comment thread src/bdk.udl Outdated

DescriptorPublicKey as_public();

sequence<u8> secret_key_bytes();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about shortening the name to secret_bytes() same as the internal bdk function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's do it. In this case I had made a deliberate choice because I actually don't like the API, (DescriptorSecretKey.secret_bytes? it's not explicit to me that it's about to return you the secret key). But I agree we should stick to the names we have in the Rust libs (and if I don't like it I should take it up with the upstream! haha).

Fixed.

@notmandatory
Copy link
Copy Markdown
Member

To answer your question in the descriptor, yes, since we're only internally storing extended keys there's no chance it will be a single key. My current thinking is to add a new construction for DescriptorSecretKey somethink like .fromWIF() that would create a secret key from a WIF. I think even starting with a WIF we could still use the derive and extend functions to convert a single key to an extended key.. but I need to think that through a little more.

Copy link
Copy Markdown
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 1b9bd6d

Up to you if you'd also like to shorten the function name to secret_bytes().

@thunderbiscuit thunderbiscuit force-pushed the feat/retrieve-private-keys branch from 390cd48 to 432e432 Compare September 30, 2022 23:45
@thunderbiscuit thunderbiscuit force-pushed the feat/retrieve-private-keys branch from 432e432 to 1cc9afa Compare October 3, 2022 18:56
@thunderbiscuit thunderbiscuit merged commit 1cc9afa into bitcoindevkit:master Oct 3, 2022
@notmandatory notmandatory mentioned this pull request Oct 19, 2022
13 tasks
@thunderbiscuit thunderbiscuit deleted the feat/retrieve-private-keys branch November 14, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project
Status: Done

Development

Successfully merging this pull request may close these issues.

Add ability to retrieve private master key from a BIP39 seed

2 participants