constellation_sdk/lib.rs
1//! Constellation Metagraph SDK for Rust
2//!
3//! A toolkit for signing and verifying data on Constellation Network metagraphs.
4//!
5//! # Features
6//!
7//! - **ECDSA secp256k1 signing** — industry-standard elliptic curve signatures
8//! - **RFC 8785 canonicalization** — deterministic JSON serialization
9//! - **Cross-language compatibility** — interoperable with TypeScript, Python, Go implementations
10//! - **Multi-signature support** — create and verify objects signed by multiple parties
11//! - **Optional secp256r1 (P-256)** — TPM-native curve, behind the `r1` cargo feature
12//!
13//! # Quick Start
14//!
15//! ```rust
16//! use constellation_sdk::{
17//! wallet::generate_key_pair,
18//! signed_object::create_signed_object,
19//! verify::verify,
20//! };
21//! use serde_json::json;
22//!
23//! let key_pair = generate_key_pair();
24//! let data = json!({"action": "transfer", "amount": 100});
25//! let signed = create_signed_object(&data, &key_pair.private_key, false).unwrap();
26//! let result = verify(&signed, false);
27//! assert!(result.is_valid);
28//! ```
29//!
30//! # P-256 (R1) signing
31//!
32//! Enable the `r1` feature to access the parallel `crate::r1` namespace
33//! mirroring the K1 API:
34//!
35//! ```toml
36//! [dependencies]
37//! constellation-metagraph-sdk = { version = "0.2", features = ["r1"] }
38//! ```
39//!
40//! ```ignore
41//! use constellation_sdk::r1::wallet::generate_key_pair;
42//! use constellation_sdk::r1::sign::sign_hash;
43//! let kp = generate_key_pair();
44//! let sig = sign_hash(&"00".repeat(32), &kp.private_key)?;
45//! ```
46
47pub mod binary;
48pub mod canonicalize;
49pub mod codec;
50pub mod currency_transaction;
51pub mod currency_types;
52pub mod hash;
53pub mod sign;
54pub mod signed_object;
55pub mod types;
56pub mod verify;
57pub mod wallet;
58
59#[cfg(feature = "r1")]
60pub mod r1;
61
62#[cfg(feature = "network")]
63pub mod network;
64
65// ─── Crate-root re-exports ──────────────────────────────────────────────
66
67// Common types
68pub use types::{
69 Hash, KeyPair, Result, SdkError, SignatureProof, Signed, SigningOptions, SigningScheme,
70 VerificationResult, ALGORITHM, ALGORITHM_R1, CONSTELLATION_PREFIX,
71};
72
73// secp256k1 (K1) — always present
74pub use binary::{encode_data_update, to_bytes};
75pub use canonicalize::{canonicalize, canonicalize_bytes};
76pub use codec::decode_data_update;
77pub use hash::{compute_digest, hash_bytes, hash_data};
78pub use sign::{sign, sign_data_update, sign_hash};
79pub use signed_object::{add_signature, batch_sign, create_signed_object};
80pub use verify::{verify, verify_hash, verify_signature};
81pub use wallet::{
82 generate_key_pair, get_address, get_public_key_hex, get_public_key_id, is_valid_private_key,
83 is_valid_public_key, key_pair_from_private_key,
84};
85
86// Currency transactions (K1-only API).
87pub use currency_transaction::{
88 create_currency_transaction, create_currency_transaction_batch, encode_currency_transaction,
89 get_transaction_reference, hash_currency_transaction, is_valid_dag_address,
90 sign_currency_transaction, token_to_units, units_to_token, verify_currency_transaction,
91};
92pub use currency_types::{
93 CurrencyTransaction, CurrencyTransactionValue, TransactionReference, TransferParams,
94 TOKEN_DECIMALS,
95};