Crate atlas_signer_store

Crate atlas_signer_store 

Source
Expand description

Provides a space-efficient encoding scheme for one or two boolean vectors, primarily used to compactly encode the set of signers in an aggregate signature.

This module implements compression algorithms to encode boolean vectors into a single byte vector (Vec<u8>). It currently supports two distinct schemes based on the number of input vectors.

§Encoding Schemes

§Base2 Encoding (Single Vector)

When a single boolean vector is provided, it is encoded directly. The format is:

  1. Version Byte (1 byte): Version::Base2 as a u8.
  2. Length Prefix (2 bytes): A u16 in little-endian format storing the original number of bits in the input vector (not length of the final vector).
  3. Data Payload: The raw byte data of the boolean vector.

§Base3 Encoding (Two Vectors)

When two boolean vectors of the same length are provided, they are compressed together. This scheme assumes that for any given index, the bits in both vectors will not both be 1.

The pairs of booleans are mapped to a single ternary (base-3) digit:

  • (false, false) -> 0
  • (true, false) -> 1
  • (false, true) -> 2

The combination (true, true) is considered invalid. These ternary digits are packed five at a time into a single u8, since 3^5 < 2^8.

The format is:

  1. Version Byte (1 byte): Version::Base3 as a u8.
  2. Length Prefix (2 bytes): A u16 in little-endian format storing the original number of bits (i.e., the length of the input vectors; not the length of the final vector).
  3. Data Payload: A sequence of bytes containing the packed base-3 digits.

Enums§

DecodeError
An error that can occur during the decoding process.
Decoded
Represents the result of a decoding operation.
EncodeError
An error that can occur during the encoding process.
Version
Represents the encoding version, used as the first byte in the output.

Functions§

decode
Decodes an encoded byte slice into one or two boolean vectors.
encode_base2
Encodes a single boolean vector using Base2 encoding.
encode_base3
Encodes two boolean vectors using Base3 encoding.