Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GetKey for KeyMap #765

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Oct 29, 2024

Create a KeyMap type to replace the current BTreeMap alias and implement bitcoin::psbt::GetKey for it.

Close: #709

@tcharding tcharding force-pushed the 10-29-key-map branch 2 times, most recently from ba5b2bf to 4a3bd7e Compare October 29, 2024 01:31
@tcharding
Copy link
Member Author

cc @LLFourn

Create a `KeyMay` type to replace the current `BTreeMap` alias and
implement `bitcoin::psbt::GetKey` for it.

Close: rust-bitcoin#709
@apoelstra
Copy link
Member

Nice! Yeah, this is probably the right approach.

In 00342a1 you have a bunch of unreachables because you assume that public keys map consistently to secret keys. I think this is a reasonable assumption, but you need to enforce it in the insert method. Or perhaps you could change insert to just take a secret key, and do the pubkey computation itself.

Alternately, you could make insert be non-pub so that the type can only be constructed by calling Descriptor::parse_descriptor. This might be the better approach. (Though in this case I'd still add an assertion to insert checking consistency of the public and secret keys.)i

@LLFourn
Copy link
Contributor

LLFourn commented Oct 30, 2024

Thanks @tcharding. It might be nice to be able to append your key maps onto each other so you keep one big jumble of secret keys across all your descriptors in the application. This is possible now but would be harder to do if you make the field private (which does seem like the right thing in general). So maybe an .extend with another keymap. If you make it private you probably want to make a way to iterate it too.

@tcharding
Copy link
Member Author

Yes I threw the pub inner field so as not to have to implement the whole BTreeMap API but private inner is probably better as you say - I can do this now we a have loose concept ack.

@ValuedMammal
Copy link

Concept ACK

@sanket1729
Copy link
Member

It might be nice to be able to append your key maps onto each other so you keep one big jumble of secret keys across all your descriptors in the application.

Maybe in the longer term, a cleaner solution is to implement rust-bitcoin to implement GetKey for a tuple, vec, set of things that already implement GetKey.

impl_get_key_tuple!((T1, T2))
impl GetKey for Vec<T> where T: GetKey {
}
impl GetKey for BtreeSet<T>...

@sanket1729
Copy link
Member

Concept ACK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement GetKey for KeyMap
5 participants