Crate descriptor_codec

Crate descriptor_codec 

Source
Expand description

§Descriptor Codec

Efficiently encode and decode Bitcoin wallet descriptors with a 30-40% size reduction.

§Overview

Bitcoin wallet descriptors encode the spending conditions for Bitcoin outputs, including keys, scripts, and other requirements. Descriptors are typically represented as human-readable strings, but this adds unnecessary overhead, which is not ideal for QR codes and other forms of machine-to-machine communication.

This library efficiently encodes descriptors using tag-based and variable-length encoding, reducing the number of bytes by 30-40%. It supports all descriptors, including those with private keys.

§Usage

use std::str::FromStr;
use descriptor_codec::{encode, decode};
use miniscript::descriptor::{Descriptor, DescriptorPublicKey};

// Create a descriptor - a 2-of-3 multisig in this example
let descriptor = "wsh(sortedmulti(2,\
    03a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7,\
    036d2b085e9e382ed10b69fc311a03f8641ccfff21574de0927513a49d9a688a00,\
    02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29\
))#hfj7wz7l";

// Encode the descriptor
let encoded_descriptor = encode(descriptor).unwrap();

// Recover the original descriptor
let decoded_descriptor = decode(&encoded_descriptor).unwrap();
assert_eq!(descriptor.to_string(), decoded_descriptor);

Re-exports§

pub use decoder::Error;

Modules§

decoder
Descriptor Decode
encoder
Descriptor Encode

Functions§

decode
Decodes a Bitcoin descriptor
encode
Parses and encodes a Bitcoin descriptor