affinidi-data-integrity
An implementation of the W3C Data Integrity specification, integrated with the Affinidi Trust Development Kit. Create and verify cryptographic proofs over JSON and JSON-LD documents using Ed25519.
Supported Cryptosuites
| Cryptosuite | Canonicalization | Use Case |
|---|---|---|
eddsa-jcs-2022 |
JSON Canonicalization Scheme (JCS) | General JSON documents |
eddsa-rdfc-2022 |
RDF Dataset Canonicalization (RDFC-1.0) | JSON-LD / Verifiable Credentials |
Prefer JCS unless you specifically need RDFC. JCS is ~4x faster as it canonicalizes JSON directly, while RDFC must expand JSON-LD into RDF.
Installation
[]
= "0.5"
Usage
Sign a JSON Document (JCS)
Signing methods are async and accept any implementation of the Signer trait.
The Secret type implements Signer directly, so existing code only needs to add .await:
use DataIntegrityProof;
use Secret;
use json;
let document = json!;
let secret = from_multibase.expect;
let proof = sign_jcs_data.await.expect;
Sign a Verifiable Credential (RDFC)
let credential = json!;
let proof = sign_rdfc_data.await.expect;
Custom Signer (KMS/HSM)
Implement the Signer trait to use external signing backends:
use Signer;
use KeyType;
use async_trait;
let proof = sign_jcs_data.await.expect;
Verify a Proof
Verification auto-dispatches based on the cryptosuite field:
use verify_data_with_public_key;
let public_key_bytes = decode_multikey.expect;
let result = verify_data_with_public_key.expect;
assert!;
Performance
Benchmarks on the W3C vc-di-eddsa B.1 Alumni Credential (Apple M4 Pro, --release):
| Operation | JCS | RDFC | Ratio |
|---|---|---|---|
| Sign | ~46 us | ~199 us | ~4.3x slower |
| Verify | ~61 us | ~212 us | ~3.5x slower |
Run benchmarks:
Related Crates
affinidi-crypto— Cryptographic primitives (dependency)affinidi-rdf-encoding— RDFC-1.0 canonicalization (dependency)affinidi-secrets-resolver— Secret management (dependency)