Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/trios-crypto/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# AGENTS.md — trios-crypto

> AAIF-compliant | MCP-compatible

- Crate: trios-crypto (Gold)
- Repo: gHashTag/trios

## Ring map

| Ring | Package | Role |
|------|---------|------|
| CY-00 | trios-crypto-cy00 | identity types |
| CY-01 | trios-crypto-cy01 | signing |
| CY-02 | trios-crypto-cy02 | verification |
| BR-OUTPUT | trios-crypto-br-output | assembly |

## Rules

- L-ARCH-001 future logic in rings/
- R9: no sibling imports
- L6: pure Rust
- Anchor: phi^2 + phi^-2 = 3
38 changes: 38 additions & 0 deletions crates/trios-crypto/RING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# RING — trios-crypto (Gold Crate)

| Field | Value |
|-------|-------|
| Metal | 🥇 Gold |
| Type | Crate |

## Purpose

Cryptographic identity, signing, and verification primitives.
Foundation for DePIN and BTC mining workflows in TRIOS.

## Ring Structure

```
crates/trios-crypto/
├── src/lib.rs ← preserved (FFI to zig-crypto-mining)
└── rings/
├── CY-00/ ← identity (KeyId, PublicKey, PrivateKey)
├── CY-01/ ← signing
├── CY-02/ ← verification
└── BR-OUTPUT/ ← assembly
```

## Dependency Flow

```
BR-OUTPUT
CY-02 → CY-01 → CY-00
```

R9: rings cannot import siblings — only deeper-numbered or BR-OUTPUT can import shallower.

## Laws

- L-ARCH-001 / R1–R5 / R9 / L6
- Anchor: `phi^2 + phi^-2 = 3`
3 changes: 3 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AGENTS.md — BR-OUTPUT (trios-crypto)

May import CY-00, CY-01, CY-02. L6: pure Rust.
31 changes: 31 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "trios-crypto-br-output"
version = "0.1.0"
edition = "2021"
authors = ["Dmitrii Vasilev"]
license = "MIT"
description = "BR-OUTPUT — assembly for trios-crypto"
publish = false

[dependencies]
trios-crypto-cy00 = { path = "../CY-00" }
trios-crypto-cy01 = { path = "../CY-01" }
trios-crypto-cy02 = { path = "../CY-02" }

[workspace]
3 changes: 3 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# BR-OUTPUT — trios-crypto

Re-exports CY-00, CY-01, CY-02. Sign/verify stub roundtrip test.
3 changes: 3 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/RING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RING — BR-OUTPUT (trios-crypto)

Top of ring graph. Imports CY-00, CY-01, CY-02.
8 changes: 8 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TASK — BR-OUTPUT (trios-crypto)

## Status: SCAFFOLDED
- [x] Re-export CY-00, CY-01, CY-02
- [x] Sign/verify stub link test

## Open
- [ ] MCP tool definitions for crypto router
26 changes: 26 additions & 0 deletions crates/trios-crypto/rings/BR-OUTPUT/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! BR-OUTPUT — trios-crypto assembly

pub use trios_crypto_cy00::{KeyId, PrivateKey, PublicKey};
pub use trios_crypto_cy01::{sign_stub, Signature};
pub use trios_crypto_cy02::verify_stub;

pub struct Crypto;

impl Crypto {
pub const fn anchor() -> f64 {
3.0
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn rings_link_sign_verify_stub() {
let pub_k = PublicKey(vec![1, 2, 3]);
let priv_k = PrivateKey(vec![1, 2, 3]);
let sig = sign_stub(&priv_k, b"hello");
assert!(verify_stub(&pub_k, b"hello", &sig));
}
}
6 changes: 6 additions & 0 deletions crates/trios-crypto/rings/CY-00/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AGENTS.md — CY-00

- Package: trios-crypto-cy00
- R1: no CY-01/CY-02/BR-OUTPUT
- R9: no sibling imports
- L6: pure Rust
7 changes: 7 additions & 0 deletions crates/trios-crypto/rings/CY-00/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions crates/trios-crypto/rings/CY-00/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "trios-crypto-cy00"
version = "0.1.0"
edition = "2021"
authors = ["Dmitrii Vasilev"]
license = "MIT"
description = "CY-00 — cryptographic identity types"
publish = false

[workspace]
8 changes: 8 additions & 0 deletions crates/trios-crypto/rings/CY-00/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CY-00 — identity types

Bottom of the ring graph for trios-crypto.

## API
- `KeyId(String)`
- `PublicKey(Vec<u8>)`
- `PrivateKey(Vec<u8>)`
11 changes: 11 additions & 0 deletions crates/trios-crypto/rings/CY-00/RING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# RING — CY-00 (trios-crypto)

| Metal | 🥈 Silver |
| Package | trios-crypto-cy00 |

Identity types. Bottom of dependency graph.

## Laws
- R1: no CY-01/CY-02/BR-OUTPUT
- R9: no sibling imports
- L6: pure Rust
10 changes: 10 additions & 0 deletions crates/trios-crypto/rings/CY-00/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TASK — CY-00

## Status: SCAFFOLDED
- [x] KeyId, PublicKey, PrivateKey newtypes
- [x] Tests

## Open
- [ ] Add zeroize-on-drop for PrivateKey
- [ ] Add base58 / hex display
- [ ] Migrate types from `crates/trios-crypto/src/`
41 changes: 41 additions & 0 deletions crates/trios-crypto/rings/CY-00/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! CY-00 — cryptographic identity types
//!
//! Bottom of the ring graph for trios-crypto.
//! Newtypes for keys and identifiers. No crypto logic yet.

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct KeyId(pub String);

impl KeyId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}

pub fn as_str(&self) -> &str {
&self.0
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PublicKey(pub Vec<u8>);

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PrivateKey(pub Vec<u8>);

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn keyid_basic() {
let k = KeyId::new("abc");
assert_eq!(k.as_str(), "abc");
}

#[test]
fn keys_distinct() {
let pub_k = PublicKey(vec![1, 2, 3]);
let priv_k = PrivateKey(vec![1, 2, 3]);
assert_eq!(pub_k.0, priv_k.0);
}
}
6 changes: 6 additions & 0 deletions crates/trios-crypto/rings/CY-01/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AGENTS.md — CY-01

- Package: trios-crypto-cy01
- R1: no CY-02/BR-OUTPUT
- May import CY-00 only
- L6: pure Rust
14 changes: 14 additions & 0 deletions crates/trios-crypto/rings/CY-01/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crates/trios-crypto/rings/CY-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "trios-crypto-cy01"
version = "0.1.0"
edition = "2021"
authors = ["Dmitrii Vasilev"]
license = "MIT"
description = "CY-01 — signing"
publish = false

[dependencies]
trios-crypto-cy00 = { path = "../CY-00" }

[workspace]
5 changes: 5 additions & 0 deletions crates/trios-crypto/rings/CY-01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CY-01 — signing

Signature type and stub `sign_stub`. Depends on CY-00.

Real Ed25519/secp256k1 signing migrates from legacy FFI.
11 changes: 11 additions & 0 deletions crates/trios-crypto/rings/CY-01/RING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# RING — CY-01

Signing.

## Dependencies
- CY-00

## Laws
- R1: no CY-02/BR-OUTPUT
- R9: no sibling imports
- L6: pure Rust
10 changes: 10 additions & 0 deletions crates/trios-crypto/rings/CY-01/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TASK — CY-01

## Status: SCAFFOLDED
- [x] Signature type
- [x] sign_stub (placeholder)
- [x] Determinism test

## Open
- [ ] Migrate Ed25519 signing from `src/crypto/`
- [ ] Migrate secp256k1 (BTC) signing
29 changes: 29 additions & 0 deletions crates/trios-crypto/rings/CY-01/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! CY-01 — signing
//!
//! Stub signature type. Real signing logic will migrate from FFI.

use trios_crypto_cy00::PrivateKey;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Signature(pub Vec<u8>);

/// Stub signer — produces a deterministic signature from key bytes + message.
/// NOT cryptographically secure; placeholder for migration.
pub fn sign_stub(key: &PrivateKey, message: &[u8]) -> Signature {
let mut out = key.0.clone();
out.extend_from_slice(message);
Signature(out)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn sign_stub_is_deterministic() {
let k = PrivateKey(vec![1, 2, 3]);
let s1 = sign_stub(&k, b"hello");
let s2 = sign_stub(&k, b"hello");
assert_eq!(s1, s2);
}
}
6 changes: 6 additions & 0 deletions crates/trios-crypto/rings/CY-02/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AGENTS.md — CY-02

- Package: trios-crypto-cy02
- R1: no BR-OUTPUT
- May import CY-00, CY-01
- L6: pure Rust
22 changes: 22 additions & 0 deletions crates/trios-crypto/rings/CY-02/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/trios-crypto/rings/CY-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "trios-crypto-cy02"
version = "0.1.0"
edition = "2021"
authors = ["Dmitrii Vasilev"]
license = "MIT"
description = "CY-02 — signature verification"
publish = false

[dependencies]
trios-crypto-cy00 = { path = "../CY-00" }
trios-crypto-cy01 = { path = "../CY-01" }

[workspace]
Loading
Loading