#identifier

bin+lib said

Self-Addressing identifier library

8 releases

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

#183 in #identifier

Download history 113/week @ 2024-07-01 37/week @ 2024-07-08 121/week @ 2024-07-15 15/week @ 2024-07-22 142/week @ 2024-07-29 166/week @ 2024-08-05 58/week @ 2024-08-12 125/week @ 2024-08-19 158/week @ 2024-08-26 49/week @ 2024-09-02 51/week @ 2024-09-09 54/week @ 2024-09-16 124/week @ 2024-09-23 79/week @ 2024-09-30 47/week @ 2024-10-07 105/week @ 2024-10-14

356 downloads per month
Used in 21 crates (18 directly)

EUPL-1.2

29KB
627 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

~9.5MB
~174K SLoC