7 unstable releases (3 breaking)

0.4.0 Jan 19, 2024
0.3.0 Jul 4, 2023
0.2.1 Dec 14, 2022
0.2.0 Nov 9, 2022
0.1.2 Aug 23, 2021

#1475 in Encoding

Download history 2/week @ 2023-12-11 6/week @ 2023-12-18 1/week @ 2023-12-25 134/week @ 2024-01-01 113/week @ 2024-01-08 53/week @ 2024-01-15 1/week @ 2024-01-29 12/week @ 2024-02-12 18/week @ 2024-02-19 56/week @ 2024-02-26 75/week @ 2024-03-04 23/week @ 2024-03-11 66/week @ 2024-03-18 128/week @ 2024-03-25

296 downloads per month
Used in 14 crates (11 directly)

EUPL-1.2

25KB
539 lines

Self-Addressing Identifier

A Rust implementation of the IETF Draft SAID specification.

Self-Addressing Identifier (SAID) provides a compact text representation of digests of data. It supports multiple hash algorithms (see below).

License

EUPL 1.2

We have distilled the most crucial license specifics to make your adoption seamless: see here for details.

Example

let data = "hello there";
let code: HashFunction = HashFunctionCode::Blake3_256.into();
let sai = code.derive(data.as_bytes());

assert_eq!(format!("{}", sai), "ENmwqnqVxonf_bNZ0hMipOJJY25dxlC8eSY5BbyMCfLJ");
assert!(sai.verify_binding(data.as_bytes()));
assert!(!sai.verify_binding("wrong data".as_bytes()));

See https://github.com/THCLab/cesrox/blob/master/said/tests/ for full fledged examples.

Supported hash functions

derivation code digest type code length identifier length
E Blake3-256 Digest 1 44
F Blake2b-256 Digest 1 44
G Blake2s-256 Digest 1 44
H SHA3-256 Digest 1 44
I SHA2-256 Digest 1 44
0D Blake3-512 Digest 2 88
0E Blake2b-512 Digest 2 88
0F SHA3-512 Digest 2 88
0G SHA2-512 Digest 2 88

Self Addressing Data

Module sad provides trait SAD that has functions:

  • compute_digest - computes the Self Addressing Identifier of a data structure, places it in a chosen field,
  • derivation_data - returns data that are used for SAID computation.

The SAD trait can be implemented for structures using the provided derive macro. It allows users to select which fields will be replaced by the computed Self Addressing Identifier. To use macro, feature macros need to be enabled. It works only for structures that implement Serialize using the #[derive(Serialize)] attribute, rather than a custom implementation.

Attributes

Macro uses with following attributes:

  • version - adds version field while computing derivation data. Version string contains compact representation of field map, serialization format, and size of a serialized message body. Attribute let user specify protocol code and its major and minor version. When attribute is used, the structure automatically implements the Encode trait, which provides the encode function for serializing the element according to the chosen serialization format.
  • said - this attribute allows users to choose the hash function for computing Self Addressing Identifier and serialization format. The hash function can be specified using the derivation code from the table above. The available serialization formats are JSON, CBOR, and MGPK. By default, JSON and Blake3-256 are used.

Field attributes:

  • said - marks field that should be replaced by computed digest during compute_digest.

Example:

#[derive(SAD, Serialize)]
#[version(protocol = "KERI", major = 1, minor = 0)]
struct Something {
	pub text: String,
	#[said]
	pub d: Option<SelfAddressingIdentifier>,
}

Releasing new version

cargo-release is required

To release new version run cargo release

Due to release config it will bump version, create new git tag and push it to remote.

Dependencies

~9MB
~165K SLoC