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, ConfinedEncode and ConfinedDecode, which should be implemented on each type that requires to be represented for client-side-validation. It also defines possible encoding error cases with [derive@Error] and provides derivation macros #[derive(ConfinedEncode, ConfinedDecode)], which are a part of confined_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 confined_encoding_derive as derive;

Macros

Macro simplifying decoding of a structure with a given list of fields
Macro simplifying encoding for a given list of items
Implements confined encoding for a hash type

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 ConfinedEncode, 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 commit_verify module.
Re-exporting extended read and write functions from bitcoin consensus module so others may use semantic convenience confined_encode::ReadExt Extensions of Read to decode data as per Bitcoin consensus
Re-exporting extended read and write functions from bitcoin consensus module so others may use semantic convenience confined_encode::ReadExt Extensions of Write to encode data as per Bitcoin consensus

Derive Macros

Derives ConfinedDecode implementation for the type.
Derives ConfinedEncode implementation for the type.