Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"spdk-wallet",
"silentpayments",
"scanners/local",
"bip392",
]
resolver = "3"

Expand All @@ -15,6 +16,7 @@ spdk-wallet = { path = "spdk-wallet" }
silentpayments = { path = "silentpayments" }
backend-blindbit-v1 = { path = "backends/blindbit-v1" }
local-scanner = { path = "scanners/local" }
bip392 = { path = "bip392" }

# Core dependencies - shared across crates
anyhow = "1.0"
Expand All @@ -23,7 +25,8 @@ serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
bip321 = { git = "https://gitlab.com/Sosthene00/bark.git", rev = "83ab79264159869503b16fa475e0ed61ffa33174", default-features = false }
bitcoin = { version = "0.32.8", features = ["serde", "rand", "base64"] }
bitcoin_hashes = "0.13.0"
miniscript = "13.0.0"
bitcoin_hashes = "0.14.101"
rayon = "1.10.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
futures = "0.3"
Expand Down
14 changes: 14 additions & 0 deletions bip392/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "bip392"
version = "0.1.0"
edition = "2024"
repository.workspace = true

[lib]
crate-type = ["lib"]

[dependencies]
secp256k1.workspace = true
silentpayments.workspace = true

miniscript.workspace = true
91 changes: 91 additions & 0 deletions bip392/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//! Errors for parsing and materializing `sp()` descriptors.

use core::fmt;

use miniscript::bitcoin::bip32;

use crate::keys::SpKeyError;

/// A descriptor key expression cannot be used as silent-payment key material.
///
/// These are the failures of turning a [`DescriptorSecretKey`] into a scalar,
/// and the same failures on a public spend key.
///
/// [`DescriptorSecretKey`]: miniscript::DescriptorSecretKey
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeyError {
/// The key is a BIP-389 multipath expression.
Multipath,
/// The derivation path contains a wildcard (`/*` or `/*h`).
Wildcard,
/// A single key is uncompressed.
Uncompressed,
/// BIP-32 child derivation failed.
Derivation(bip32::Error),
}

impl fmt::Display for KeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Multipath => f.write_str("must not be multipath"),
Self::Wildcard => f.write_str("must not contain a wildcard"),
Self::Uncompressed => f.write_str("must be compressed"),
Self::Derivation(err) => fmt::Display::fmt(err, f),
}
}
}

impl std::error::Error for KeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Derivation(err) => Some(err),
Self::Multipath | Self::Wildcard | Self::Uncompressed => None,
}
}
}

/// An error parsing or constructing an [`Sp`] descriptor.
///
/// [`Sp`]: crate::Sp
#[derive(Debug)]
pub enum Error {
/// The scan key cannot be materialized.
Scan(KeyError),
/// The spend key cannot be materialized.
Spend(KeyError),
/// The descriptor string is not a valid expression.
Parse(miniscript::Error),
/// An `spscan` or `spspend` encoding is invalid.
SpKey(SpKeyError),
/// A constraint that is not one of the key-material failures above.
Unexpected(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Scan(err) => write!(f, "sp() scan key: {err}"),
Self::Spend(err) => write!(f, "sp() spend key: {err}"),
Self::Parse(err) => fmt::Display::fmt(err, f),
Self::SpKey(err) => fmt::Display::fmt(err, f),
Self::Unexpected(message) => f.write_str(message),
}
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Scan(err) | Self::Spend(err) => Some(err),
Self::Parse(err) => Some(err),
Self::SpKey(err) => Some(err),
Self::Unexpected(_) => None,
}
}
}

impl From<miniscript::Error> for Error {
fn from(err: miniscript::Error) -> Self {
Self::Parse(err)
}
}
Loading
Loading