Crate strict_encoding[][src]

Expand description

Library implementing 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 (LMPBP-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.

Library defines two main traits, StrictEncode and StrictDecode, which should be implemented on each type that requires to be represented for client-side-validation. It also defines possible encoding error cases with [Error] and provides derivation macros #[derive(StrictEncode, StrictDecode)], which are a part of strict_encode_derive sub-crate and represented 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.

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

Re-exports

pub extern crate strict_encoding_derive as derive;
pub use strategies::Strategy;

Modules

Network addresses uniform encoding (LNPBP-42).

Strategies simplifying implementation of encoding traits.

Helping macros and functions for creating test coverage for strict-encoded data.

Macros

Macro simplifying decoding of a structure with a given list of fields

Macro simplifying encoding for a given list of items

Macro testing encodings of all enum variants.

Macro testing encodings of all enum variants for enums with assigned primitive integer values.

Macro testing encoding of all possible enum values, covering full range of u8 values, including enum out-of-range values.

Enums

Possible errors during strict encoding and decoding process

Traits

Binary decoding according to the strict rules that usually apply to consensus-critical data structures. May be used for network communications. MUST NOT be used for commitment verification: even if the commit procedure uses StrictEncode, the actual commit verification MUST be done with [CommitVerify], [TryCommitVerify] and [EmbedCommitVerify] traits, which, instead of deserializing (nonce operation for commitments) repeat the commitment procedure for the revealed message and verify it against the provided commitment.

Binary encoding according to the strict rules that usually apply to consensus-critical data structures. May be used for network communications; in some circumstances may be used for commitment procedures; however it must be kept in mind that sometime commitment may follow “fold” scheme (Merklization or nested commitments) and in such cases this trait can’t be applied. It is generally recommended for consensus-related commitments to utilize [CommitVerify], [TryCommitVerify] and [EmbedCommitVerify] traits
from [paradigms::commit_verify] module.

Functions

Convenience method for strict decoding of data structures implementing StrictDecode from any byt data source.

Convenience method for strict encoding of data structures implementing StrictEncode into a byte vector.

Derive Macros

Derives [::strict_encoding::StrictDncode] implementation for the type.

Derives [::strict_encoding::StrictEncode] implementation for the type.