Skip to content

Conversation

ItoroD
Copy link
Collaborator

@ItoroD ItoroD commented Sep 3, 2025

Description

Since signing will soon be done with the PSBT type, I think its a good time to expose some of the other PSBT fields like Input.

This will allow easier access to the input in a PSBT. It might be specifically important because the sign method of PSBT can do interesting stuff like returning a map of input index and keys used to sign it.

I would like to take a pause here and see how this is looking on the bindings side before I go any further.

Changelog notice

  • Add input type for psbt

Checklists

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

@ItoroD ItoroD marked this pull request as draft September 3, 2025 18:46
@thunderbiscuit
Copy link
Member

Anything else you'd like to add to this PR or should we start reviewing now? No rush, just want to know where it's at.

@thunderbiscuit thunderbiscuit self-requested a review September 11, 2025 13:18
@ItoroD
Copy link
Collaborator Author

ItoroD commented Sep 11, 2025

Anything else you'd like to add to this PR or should we start reviewing now? No rush, just want to know where it's at.

A few more fields to add before this is good for review

@ItoroD ItoroD marked this pull request as ready for review September 15, 2025 16:29
@ItoroD
Copy link
Collaborator Author

ItoroD commented Sep 15, 2025

This is ready for review

Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

It's looking good!

I think a few of the Vec could be simply HashMap<K, V> as in the rust-bitcoin codebase, unless there is something I'm missing.

It's a lot of conversion between simple types, so I'm wondering if stealing one or two of the rust-bitcoin tests on this type would be good as well? I haven't looked at their tests so don't take that as a requirement. I don't know if they actually do a lot of tests just on this Input type.

Comment on lines +506 to +510
pub struct PartialSig {
pub pubkey: String,
pub signature: Vec<u8>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Since the rust-bitcoin type for this field is a map, I think we could use the uniffi equivalent here instead of a vector of structs. Let me know if you've tried this and it doesn't work for some reason!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are correct. I struggled with trying to use BTreeMap in a record this made me think maps are not just one of the Uniffi compatible type. HashMap is definitely closer and it works. I just checked. I did

pub bip32_derivation: HashMap<String, KeySource>

instead of

pub bip32_derivation: Vec<Bip32Derivation>

where keysource is

#[derive(Clone, Debug, uniffi::Record)]
pub struct KeySource {
    pub fingerprint: String,
    pub path: String,
}

Copy link
Collaborator Author

@ItoroD ItoroD Sep 28, 2025

Choose a reason for hiding this comment

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

I was thinking about this again, the only thing about collecting these into Hashmap is that we loose the ordering that the BTreeMap gave from the actual rust-bitcoin types. Should we care about the ordering ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I wondered that too. But looking at the fields, I do think the keys identify everything you need, and so the ordering doesn't matter. If anything devs would need an extra line of lookup to find the associated data instead of relying on the ordering, but even then I don't know if that's even how people use the BTreeMap for these fields. My hunch would be to use the HashMap.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, I will update. Thanks.

Comment on lines 512 to 519
pub struct Bip32Derivation {
/// hex-encoded public key (serialized)
pub pubkey: String,
/// master key fingerprint
pub fingerprint: String,
/// derivation path segments
pub path: String,
}
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. We might be able to use a map instead of a Vec of this struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing these out. BTreeMap not working threw me off. But I see now

Comment on lines 616 to 622
pub ripemd160_preimages: Vec<PreimagePair>,
/// SHA256 hash to preimage map.
pub sha256_preimages: Vec<PreimagePair>,
/// HASH160 hash to preimage map.
pub hash160_preimages: Vec<PreimagePair>,
/// HASH256 hash to preimage map.
pub hash256_preimages: Vec<PreimagePair>,
Copy link
Member

Choose a reason for hiding this comment

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

Same for these.

@ItoroD
Copy link
Collaborator Author

ItoroD commented Sep 26, 2025

It's looking good!

Thanks

It's a lot of conversion between simple types, so I'm wondering if stealing one or two of the rust-bitcoin tests on this type would be good as well? I haven't looked at their tests so don't take that as a requirement. I don't know if they actually do a lot of tests just on this Input type.

They do have a few test that concern input. Though they are not direct tests. The intention of some of the test are to validate correctness of an action performed, like signing. See here I am sure I can squeeze out a few good test like this from there. Will be a great idea to have them!

An additional thing I will have to perform is ensure whatever Psbt sample I create/use has values for the fields I will be checking/testing. Might take a while to do that for all fields. (Simulating different Psbt states, signed, unsigned, partially signed, finalized ). I could start with a few.

@ItoroD
Copy link
Collaborator Author

ItoroD commented Oct 6, 2025

Just an update on this. I will be pushing new changes today with some tests as well

This allows easier access to the inputs of our PSBT type
@ItoroD ItoroD force-pushed the expose-psbt-input branch from f1fa7be to 032a6c8 Compare October 6, 2025 15:36
@ItoroD ItoroD requested a review from thunderbiscuit October 6, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants