pic/lib.rs
1/*
2 * Copyright Nitro Agility S.r.l.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! # PIC Protocol — Provenance Identity Continuity
18//!
19//! Rust implementation of the [PIC Protocol](https://www.pic-protocol.org):
20//! verifiable authority continuity across distributed and agentic execution
21//! chains, as defined by the
22//! [PIC Specification](https://github.com/pic-protocol/pic-spec).
23//!
24//! Where a bearer token proves *possession*, a PIC continuity state proves
25//! *provenance*: each hop of an execution chain carries a signed, verifiable
26//! lineage of how its authority was derived — and authority can only be
27//! attenuated along the way, never expanded.
28//!
29//! This crate is the facade over the protocol crates; today it re-exports
30//! one implementation crate:
31//!
32//! - [`continuity`] — PIC Profile 0.2: the artifact family (PIC Token JWT,
33//! PIC PCA COSE, PIC Continuity COSE, PIC Continuity Transition COSE),
34//! the canonical Indexed Authority Map, the Prover (candidate
35//! construction), and the Verifier (settled-state verification and the
36//! settlement procedure).
37//!
38//! # Quick start
39//!
40#![cfg_attr(feature = "ed25519", doc = "```")]
41#![cfg_attr(not(feature = "ed25519"), doc = "```ignore")]
42//! use pic::continuity::artifacts::PicPcaPayload;
43//! use pic::continuity::authority::{
44//! AuthorityValue, IndexedAuthorityMap, Invariant, LogicalAuthority,
45//! };
46//! use pic::continuity::trust::{Ed25519Signer, Ed25519Verifier};
47//! use pic::continuity::verifier::{issue_settled, verify_settled, SettlementContext};
48//! use std::collections::BTreeMap;
49//!
50//! // The realm signing key (settlement authority).
51//! let realm_key = ed25519_dalek::SigningKey::generate(&mut rand::rngs::OsRng);
52//! let realm = Ed25519Signer::new(realm_key, "https://pic-x.example.com/realms/acme#key-1");
53//!
54//! // A Logical Context of Authority, canonicalized deterministically.
55//! let mut contract = BTreeMap::new();
56//! contract.insert("corporation".into(), AuthorityValue::One("ACME".into()));
57//! let logical = LogicalAuthority::new(
58//! None,
59//! vec![Invariant::new(
60//! "documents:read:document-42", "read", "documents", "document-42",
61//! )],
62//! contract,
63//! );
64//! let authority = IndexedAuthorityMap::from_logical(&logical)?;
65//!
66//! // Checkpoint 0 (e.g. after an OAuth-to-PIC token exchange).
67//! let checkpoint = PicPcaPayload::new(0, authority, vec![0x7b; 32]);
68//! let issued = issue_settled(checkpoint, &realm, &SettlementContext {
69//! iss: "https://pic-x.example.com/realms/acme".into(),
70//! ..Default::default()
71//! })?;
72//!
73//! // Any workload with the realm public key verifies the settled token.
74//! let verifier = Ed25519Verifier::new(realm.verifying_key());
75//! let settled = verify_settled(&issued.token, &verifier)?;
76//! assert_eq!(settled.checkpoint.position, 0);
77//! # Ok::<(), pic::continuity::error::ContinuityError>(())
78//! ```
79//!
80//! See the [`continuity`] module documentation for the full role map
81//! (Prover, ordinary verifier, settlement authority) and feature flags.
82//!
83//! # Feature flags
84//!
85//! | Feature | Effect |
86//! |---------|--------|
87//! | `ed25519` *(default)* | Ed25519 signers/verifiers via `ed25519-dalek` |
88//! | `p256` | ECDSA P-256 (`ES256`) |
89//! | `p384` | ECDSA P-384 (`ES384`) |
90//! | `crypto-full` / `full` | All of the above |
91
92#![warn(missing_docs)]
93
94/// PIC Profile 0.2: continuity artifacts, Prover, and Verifier.
95pub mod continuity {
96 pub use pic_continuity::*;
97}