A rust library to encode descriptors with a 30-40% size reduction

Jul 1 - Jul 1, 2025

  • The library discussed is inspired by a suggestion to reduce the size of QR codes used for wallets, as mentioned in a comment by @sjors on a Bitcoin pull request.

It builds upon an encoder developed for the descriptor-encrypt project, enhancing it with the capability to handle descriptors that include private keys, and aims to compactly encode these descriptors. This approach decreases the descriptor size by 30-40%, making it more suitable for QR codes and NFC communication, thereby facilitating easier sharing and storage of complex multisig configurations.

The library supports all kinds of descriptors, including those with miniscript and private keys, by utilizing tag-based and variable-length encoding. This method not only avoids traditional encodings like bech32 and base58 but also significantly enhances QR code reliability and fits within the NFC byte limits for hardware wallet communications. Its API is straightforward, offering encode and decode functions alongside a command-line interface for practical demonstrations.

Encoding is divided into two main components: a structural template and a data payload. The template outlines the descriptor's logical structure through single-byte tags representing script components and structural information, such as multisig parameters and derivation paths. Conversely, the payload comprises the raw data values referenced in the template, including public and private keys, key fingerprints, and timelock values. This separation ensures clarity and efficiency in encoding and decoding processes.

Furthermore, the library introduces variable-length encoding for several elements, such as timelocks and derivation path lengths, enhancing its compactness. Each aspect of a descriptor, from script operators to key types, is represented by specific tags, indicating a comprehensive coverage of possible descriptor components.

This library is designed with several use cases in mind, including the sharing of multisig configurations via QR codes, NFC communication with hardware wallets, reduction of bandwidth in wallet coordination protocols, and storing descriptors in memory-constrained environments. Future developments will focus on incorporating this encoder in the descriptor-encrypt tool and expanding support as new miniscript operators and descriptor types emerge.

For more information, the library is accessible on GitHub at https://github.com/joshdoman/descriptor-codec, with documentation available at https://docs.rs/descriptor-codec/latest/descriptor_codec.

Bitcoin Logo

TLDR

Join Our Newsletter

We’ll email you summaries of the latest discussions from authoritative bitcoin sources, like bitcoin-dev, lightning-dev, and Delving Bitcoin.

Explore all Products

ChatBTC imageBitcoin searchBitcoin TranscriptsSaving SatoshiBitcoin Transcripts Review
Built with 🧡 by the Bitcoin Dev Project
View our public visitor count

We'd love to hear your feedback on this project?

Give Feedback