Skip to content

Network checking on DescriptorPublicKey and DefiniteDescriptorKey #844

@apoelstra

Description

@apoelstra

When working on descriptor support for stratum I realized that I would like to check for testnet keys and (attempt to) refuse to use them on mainnet, on the basis that mainnet coins sent to testnet addresses may wind up blackholed.

This isn't too hard for me to implement by iterating through all my DescriptorPublicKeys, looking at the xpubs (if they are xpubs) and looking at the network bytes.

But this raises a few questions:

  • At parsing time should we insist that xkeys have consistent network bytes?
  • Should we expose some sort of convenience method for obtaining these bytes?

I am thinking about adding an enum

enum XKeyNetwork {
    /// No xkeys are present
    NoXKeys,
    /// xkeys are present but have conflicting network prefixes
    Mixed,
    /// xkey(s)s are present and all have the same network prefix
    Single(bitcoin::Network),
}

and a helper method on Descriptor<DescriptorPublicKey> and Descriptor<DefiniteDescriptorKey> that returns this enum.

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