Skip to content

PSBT responsibilities API according to BIP-174 #455

@dr-orlovsky

Description

@dr-orlovsky

BIP-174 defines not just a structure and serialization for PSBTs, but also responsibilities — a well-defined roles of how PSBT can be modified by different actors, which is required for correct workflow organization. Right now PSBT implementation in the current rust-bitcoin code does not address this part of the spec; neither there any other rust implementation of it. Even PSBT signers (Firma and MagicalBitcoin) misses validation parts that are required by BIP-174.

While this library is not a wallet library, it seems that implementation of well-defined API for the responsibilities will be beneficial; plus we can implement non-signing part of PSBT validation described in this section of BIP-174. I am planning to work on that and do it as a number of decorators+facades, one per responsibility, at the same time limiting possible PSBT operations (facade) and implementing common responsibility business logic (like validation of the internal structure) as methods (decorator).

pub trait Responsibility {
  fn from_psbt(psbt: PartiallySignedTransaction) -> Self;
  fn into_psbt(self) -> PartiallySignedTransaction;
}

pub struct PsbtSigner {
  psbt: PartiallySignedTransaction,
}

impl Responsibility for PsbtSigner { /* ... */ }

impl PsbtSigner {
  pub fn valdiate(&self) -> Result<(), ValidationError> {
     // ....
  }

  pub fn sign<F>(&mut self, signer: F) -> Result<PartiallySignedTransaction> 
      where F: FnMut(Message, Fingerprint, DerivationPath) -> Signature {
     // ....
  }
}

// ... other responsibilities

Related PR in miniscript: rust-bitcoin/rust-miniscript#119

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions