#protobuf #serialization #serde #gadt #binary-encoding #byte-string #strict-types

strict_encoding

Strict encoding: deterministic & confined binary serialization for strict types

98 releases (60 stable)

new 2.8.1 Nov 16, 2024
2.7.0 Aug 30, 2024
2.7.0-beta.4 May 24, 2024
2.7.0-beta.1 Feb 15, 2024
0.8.1 Jul 9, 2022

#360 in Magic Beans

Download history 1716/week @ 2024-07-29 1100/week @ 2024-08-05 1777/week @ 2024-08-12 1834/week @ 2024-08-19 1543/week @ 2024-08-26 1824/week @ 2024-09-02 754/week @ 2024-09-09 2030/week @ 2024-09-16 706/week @ 2024-09-23 471/week @ 2024-09-30 1497/week @ 2024-10-07 2018/week @ 2024-10-14 628/week @ 2024-10-21 1521/week @ 2024-10-28 1102/week @ 2024-11-04 1101/week @ 2024-11-11

4,404 downloads per month
Used in 96 crates (70 directly)

Apache-2.0

185KB
5K SLoC

Strict encoding library

Build Tests Lints codecov

crates.io Docs Apache-2 licensed

Deterministic binary serialization for client-side-validation.

This library implements strict encoding standard, defined by LNPBP-7. Strict encoding is a binary conservative encoding extensively used in client-side-validation for deterministic portable (platform-independent) serialization of data with a known internal data structure. Strict encoding is a schema-less encoding.

As a part of strict encoding, crate also includes implementation of network address uniform encoding standard (LNPBP-42), which allows representation of any kind of network address as a fixed-size byte string occupying 37 bytes. This standard is used for the strict encoding of networking addresses.

Client-side-validation is a paradigm for distributed computing, based on top of proof-of-publication/commitment medium layer, which may be a bitcoin blockchain or other type of distributed consensus system.

The development of the library is supported by LNP/BP Standards Association.

The library is designed after Peter Todd concepts of proofmarshall and serialization principles for client-side-validated data and Dr Maxim Orlovsky idea of universal network encodings. Both were shaped into the standards and implemented as a part of this library by Dr Maxim Orlovsky.

Documentation

Detailed developer & API documentation for the library can be accessed at https://docs.rs/strict_encoding/

To learn about the technologies enabled by the library please check slides from our tech presentations and LNP/BP tech talks videos

Usage

To use the library, you just need to reference a latest version, in [dependencies] section of your project Cargo.toml.

strict_encoding = "2.5"

If you are using other client-side-validation libraries, consider importing just a single client_side_validation library which re-exports all of them, including the current one.

Library defines two main traits, StrictEncode and StrictDecode, which should be implemented on each type that requires to be represented for client-side-validation.

Library exports derivation macros #[derive(StrictEncode, StrictDecode)], which are a part of strict_encoding_derive sub-crate and controlled by a default feature derive. Finally, it implements strict encoding traits for main data types defined by rust standard library and frequently used crates; the latter increases the number of dependencies and thus can be controlled with feature flags:

  • chrono (used by default): date & time types from chrono crate
  • miniscript: types defined in bitcoin Miniscript
  • crypto: non-bitcoin cryptographic primitives, which include Ed25519 curve, X25519 signatures from ed25519-dalek library and pedersen commitments + bulletproofs from grin_secp256k1zkp library. Encodings for other cryptography-related types, such as Secp256k1 and hashes, are always included as a part of the library - see NB below.

This crate requires bitcoin as an upstream dependency since many of strict-encoded formats are standardized as using bitcoin consensus encoding.

Contributing

Contribution guidelines can be found in CONTRIBUTING

Licensing

The libraries are distributed on the terms of Apache 2.0 opensource license. See LICENCE file for the license details.

Dependencies

~2–2.6MB
~58K SLoC