Skip to content
Merged
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
18 changes: 13 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
[package]
name = "bitcoin-encrypted-backup"
version = "1.0.0"
version = "0.0.3"
edition = "2021"
readme = "README.md"
description = "Bitcoin Encrypted Backup"
description = "Bitcoin Encrypted Backup (deprecated, superseded by bip138)"
documentation = "https://docs.rs/bitcoin-encrypted-backup"
license-file = "LICENSE"
repository = "https://github.com/pythcoiner/bitcoin-encrypted-backup"

[badges]
maintenance = { status = "deprecated" }

[dependencies]
chacha20poly1305 = {version = "0.10.1", default-features = false, features = ["alloc"]}
rand = {version = "0.9.2", optional = true}
base64 = {version = "0.22", default-features = false, features = ["alloc"], optional = true}

# Old format (BEB magic, AES-256-GCM): used solely on the decrypt path
# as a transparent fallback for backups produced by 0.0.2.
bitcoin-encrypted-backup-v0 = { version = "0.0.2", package = "bitcoin-encrypted-backup", default-features = false, optional = true }

#miniscript
mscript_12_3_5 = { version = "12.3.5", default-features = false, features = ["serde", "no-std"], package = "miniscript" , optional = true}
mscript_12_0 = { version = "12.0", default-features = false, features = ["serde", "no-std"], package = "miniscript" , optional = true}
Expand All @@ -36,12 +43,13 @@ path = "src/bin/main.rs"
required-features = ["cli"]

[features]
default = ["miniscript_latest", "rand", "base64"]
default = ["miniscript_latest", "rand", "base64", "v0"]
rand = ["dep:rand"]
base64 = ["dep:base64"]
v0 = ["dep:bitcoin-encrypted-backup-v0"]
miniscript_latest = ["miniscript_12_3_5"]
miniscript_12_3_5 = ["mscript_12_3_5"]
miniscript_12_0 = ["mscript_12_0"]
miniscript_12_3_5 = ["mscript_12_3_5", "bitcoin-encrypted-backup-v0?/miniscript_12_3_5"]
miniscript_12_0 = ["mscript_12_0", "bitcoin-encrypted-backup-v0?/miniscript_12_0"]
tokio = ["dep:tokio"]
devices = ["dep:async-hwi", "tokio"]
cli = ["dep:clap", "tokio", "miniscript_latest", "rand"]
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
> [!WARNING]
> This crate is deprecated. The spec has evolved into
> [BIP138](https://github.com/bitcoin/bips/blob/346008db8943cb90c1e091eaac8277066d4dbee7/bip-0138.md), implemented by the
> [`bip138`](https://crates.io/crates/bip138) crate.
>
> This crate must only be used for backward compatibility, to decrypt existing backups. No new
> backup should be exported with this format. The encryption API is deprecated.

Command-line tool & Rust crate that lets you **encrypt descriptors (or arbitrary
data)** with a set of **public** keys (or xpubs) and later decrypt when **at least
one** of them is physically present—either via a local file containing the key or
Expand Down Expand Up @@ -32,7 +40,6 @@ $ beb --help
Usage: beb <COMMAND>

Commands:
encrypt Encrypt some descriptor
decrypt Decrypt an encrypted descriptor with a given xpub
help Print this message or the help of the given subcommand(s)

Expand All @@ -41,18 +48,6 @@ Options:
-V, --version Print version
```
```
$ beb encrypt --help
Encrypt some descriptor

Usage: beb encrypt [OPTIONS]

Options:
-f, --file <FILE> Input file containing the descriptor
-o, --output <OUTPUT> Optional output to encrypted descriptor
-h, --help Print help

```
```
$ beb decrypt --help
Decrypt an encrypted descriptor with a given xpub

Expand All @@ -67,7 +62,7 @@ Options:
```
## Library usage

### Encryption
### Encryption (deprecated)
```rust
let descriptor = Descriptor::<DescriptorPublicKey>::from_str("<descriptor
string>").unwrap();
Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/encode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_main]
#![allow(deprecated)]

extern crate bitcoin_encrypted_backup;
use bitcoin_encrypted_backup::{
Expand Down
67 changes: 0 additions & 67 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ use clap::Subcommand;
use bitcoin_encrypted_backup::Decrypted;
use bitcoin_encrypted_backup::EncryptedBackup;
use miniscript::descriptor::DescriptorKeyParseError;
use miniscript::Descriptor;
use miniscript::DescriptorPublicKey;

use std::env;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;

Expand All @@ -28,15 +25,12 @@ struct Cli {

#[derive(Debug)]
pub enum CliError {
CantConvertToDescriptor(miniscript::Error),
CantConvertToXpub(DescriptorKeyParseError),
EmptyDescriptor,
CwdError(std::io::Error),
CreateError(std::io::Error),
OpenError(std::io::Error),
WriteError(std::io::Error),
ReadError(std::io::Error),
FailedToEncrypt(bitcoin_encrypted_backup::Error),
FailedToDecrypt(bitcoin_encrypted_backup::Error),
Content,
NoKeys,
Expand All @@ -45,19 +39,14 @@ pub enum CliError {
impl std::fmt::Display for CliError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CliError::CantConvertToDescriptor(err) => {
write!(f, "Can't convert to a descriptor: {err:?}")
}
CliError::CantConvertToXpub(err) => {
write!(f, "Can't convert to master public key: {err:?}")
}
CliError::EmptyDescriptor => write!(f, "Empty descriptor"),
CliError::CwdError(err) => write!(f, "Cant find current working directiory: {err:?}"),
CliError::CreateError(err) => write!(f, "Cannot create file: {err:?}"),
CliError::OpenError(err) => write!(f, "Cannot open file: {err:?}"),
CliError::WriteError(err) => write!(f, "Cannot write file: {err:?}"),
CliError::ReadError(err) => write!(f, "Cannot read file: {err:?}"),
CliError::FailedToEncrypt(err) => write!(f, "Cannot encrypt: {err:?}"),
CliError::FailedToDecrypt(err) => write!(f, "Cannot decrypt: {err:?}"),
CliError::Content => write!(f, "Decryption succeed but content is not a descriptor"),
CliError::NoKeys => write!(f, "No decryption key found"),
Expand All @@ -67,17 +56,6 @@ impl std::fmt::Display for CliError {

#[derive(Debug, Subcommand)]
enum Commands {
/// Encrypt some descriptor
Encrypt {
/// Input file containing the descriptor
#[arg(short, long)]
file: Option<String>,

/// Optional output to encrypted descriptor
#[arg(short, long)]
output: Option<String>,
},

/// Decrypt an encrypted descriptor with a given xpub
Decrypt {
/// Input file to be decrypted
Expand All @@ -100,51 +78,6 @@ async fn main() -> Result<(), CliError> {

// Handle the specific subcommand
match &cli.command {
Commands::Encrypt { file, output } => {
let input_path = match file {
Some(path) => {
let mut descriptor_path = PathBuf::new();
descriptor_path.push(path);
descriptor_path
}
None => {
let mut descriptor_path = env::current_dir().map_err(CliError::CwdError)?;
descriptor_path.push("descriptor.txt");
descriptor_path
}
};

let output_path = match output {
Some(path) => {
let mut output_path = PathBuf::new();
output_path.push(path);
output_path
}
None => {
let mut output_path = env::current_dir().map_err(CliError::CwdError)?;
output_path.push("descriptor.bin");
output_path
}
};

let data = fs::read_to_string(&input_path).map_err(CliError::ReadError)?;

// The read descritor need to be readed with a trimmed white space
let descriptor = Descriptor::<DescriptorPublicKey>::from_str(data.trim())
.map_err(CliError::CantConvertToDescriptor)?;

// encrypt the descriptor
let bytes = EncryptedBackup::new()
.set_payload(&descriptor)
.map_err(CliError::FailedToEncrypt)?
.encrypt()
.map_err(CliError::FailedToEncrypt)?;

// pass the byte vector to a file
let mut output = File::create(&output_path).map_err(CliError::CreateError)?;
output.write(&bytes).map_err(CliError::WriteError)?;
println!("descriptor written to {output_path:?}");
}
Commands::Decrypt { file, key, output } => {
let input_path = match file {
Some(path) => {
Expand Down
Loading
Loading