From ff48003dd546de8f448382f6d336144a890b2bff Mon Sep 17 00:00:00 2001 From: claude-agent Date: Wed, 29 Apr 2026 11:05:56 +0000 Subject: [PATCH] =?UTF-8?q?feat(#238):=20scaffold=20rings/=20for=20trios-c?= =?UTF-8?q?rypto=20=E2=80=94=20CY-00,=20CY-01,=20CY-02,=20BR-OUTPUT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ring architecture per issue #238 alongside existing src/. Rings: - CY-00: identity (KeyId, PublicKey, PrivateKey) - CY-01: signing (Signature, sign_stub) - CY-02: verification (verify_stub) - BR-OUTPUT: assembly + Crypto::anchor() All rings green. Existing FFI to zig-crypto-mining preserved. Anchor: phi^2 + phi^-2 = 3 Refs #238 --- crates/trios-crypto/AGENTS.md | 22 ++++++++++ crates/trios-crypto/RING.md | 38 +++++++++++++++++ crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md | 3 ++ .../trios-crypto/rings/BR-OUTPUT/Cargo.lock | 31 ++++++++++++++ .../trios-crypto/rings/BR-OUTPUT/Cargo.toml | 15 +++++++ crates/trios-crypto/rings/BR-OUTPUT/README.md | 3 ++ crates/trios-crypto/rings/BR-OUTPUT/RING.md | 3 ++ crates/trios-crypto/rings/BR-OUTPUT/TASK.md | 8 ++++ .../trios-crypto/rings/BR-OUTPUT/src/lib.rs | 26 ++++++++++++ crates/trios-crypto/rings/CY-00/AGENTS.md | 6 +++ crates/trios-crypto/rings/CY-00/Cargo.lock | 7 ++++ crates/trios-crypto/rings/CY-00/Cargo.toml | 10 +++++ crates/trios-crypto/rings/CY-00/README.md | 8 ++++ crates/trios-crypto/rings/CY-00/RING.md | 11 +++++ crates/trios-crypto/rings/CY-00/TASK.md | 10 +++++ crates/trios-crypto/rings/CY-00/src/lib.rs | 41 +++++++++++++++++++ crates/trios-crypto/rings/CY-01/AGENTS.md | 6 +++ crates/trios-crypto/rings/CY-01/Cargo.lock | 14 +++++++ crates/trios-crypto/rings/CY-01/Cargo.toml | 13 ++++++ crates/trios-crypto/rings/CY-01/README.md | 5 +++ crates/trios-crypto/rings/CY-01/RING.md | 11 +++++ crates/trios-crypto/rings/CY-01/TASK.md | 10 +++++ crates/trios-crypto/rings/CY-01/src/lib.rs | 29 +++++++++++++ crates/trios-crypto/rings/CY-02/AGENTS.md | 6 +++ crates/trios-crypto/rings/CY-02/Cargo.lock | 22 ++++++++++ crates/trios-crypto/rings/CY-02/Cargo.toml | 14 +++++++ crates/trios-crypto/rings/CY-02/README.md | 5 +++ crates/trios-crypto/rings/CY-02/RING.md | 12 ++++++ crates/trios-crypto/rings/CY-02/TASK.md | 9 ++++ crates/trios-crypto/rings/CY-02/src/lib.rs | 26 ++++++++++++ 30 files changed, 424 insertions(+) create mode 100644 crates/trios-crypto/AGENTS.md create mode 100644 crates/trios-crypto/RING.md create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/Cargo.lock create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/Cargo.toml create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/README.md create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/RING.md create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/TASK.md create mode 100644 crates/trios-crypto/rings/BR-OUTPUT/src/lib.rs create mode 100644 crates/trios-crypto/rings/CY-00/AGENTS.md create mode 100644 crates/trios-crypto/rings/CY-00/Cargo.lock create mode 100644 crates/trios-crypto/rings/CY-00/Cargo.toml create mode 100644 crates/trios-crypto/rings/CY-00/README.md create mode 100644 crates/trios-crypto/rings/CY-00/RING.md create mode 100644 crates/trios-crypto/rings/CY-00/TASK.md create mode 100644 crates/trios-crypto/rings/CY-00/src/lib.rs create mode 100644 crates/trios-crypto/rings/CY-01/AGENTS.md create mode 100644 crates/trios-crypto/rings/CY-01/Cargo.lock create mode 100644 crates/trios-crypto/rings/CY-01/Cargo.toml create mode 100644 crates/trios-crypto/rings/CY-01/README.md create mode 100644 crates/trios-crypto/rings/CY-01/RING.md create mode 100644 crates/trios-crypto/rings/CY-01/TASK.md create mode 100644 crates/trios-crypto/rings/CY-01/src/lib.rs create mode 100644 crates/trios-crypto/rings/CY-02/AGENTS.md create mode 100644 crates/trios-crypto/rings/CY-02/Cargo.lock create mode 100644 crates/trios-crypto/rings/CY-02/Cargo.toml create mode 100644 crates/trios-crypto/rings/CY-02/README.md create mode 100644 crates/trios-crypto/rings/CY-02/RING.md create mode 100644 crates/trios-crypto/rings/CY-02/TASK.md create mode 100644 crates/trios-crypto/rings/CY-02/src/lib.rs diff --git a/crates/trios-crypto/AGENTS.md b/crates/trios-crypto/AGENTS.md new file mode 100644 index 0000000000..893eb3ca47 --- /dev/null +++ b/crates/trios-crypto/AGENTS.md @@ -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 diff --git a/crates/trios-crypto/RING.md b/crates/trios-crypto/RING.md new file mode 100644 index 0000000000..f009c48c18 --- /dev/null +++ b/crates/trios-crypto/RING.md @@ -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` diff --git a/crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md b/crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md new file mode 100644 index 0000000000..02fcd0baa4 --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/AGENTS.md @@ -0,0 +1,3 @@ +# AGENTS.md — BR-OUTPUT (trios-crypto) + +May import CY-00, CY-01, CY-02. L6: pure Rust. diff --git a/crates/trios-crypto/rings/BR-OUTPUT/Cargo.lock b/crates/trios-crypto/rings/BR-OUTPUT/Cargo.lock new file mode 100644 index 0000000000..f5974e10cf --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/Cargo.lock @@ -0,0 +1,31 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "trios-crypto-br-output" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", + "trios-crypto-cy01", + "trios-crypto-cy02", +] + +[[package]] +name = "trios-crypto-cy00" +version = "0.1.0" + +[[package]] +name = "trios-crypto-cy01" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", +] + +[[package]] +name = "trios-crypto-cy02" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", + "trios-crypto-cy01", +] diff --git a/crates/trios-crypto/rings/BR-OUTPUT/Cargo.toml b/crates/trios-crypto/rings/BR-OUTPUT/Cargo.toml new file mode 100644 index 0000000000..2a291dc44b --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/Cargo.toml @@ -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] diff --git a/crates/trios-crypto/rings/BR-OUTPUT/README.md b/crates/trios-crypto/rings/BR-OUTPUT/README.md new file mode 100644 index 0000000000..99cd386cbf --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/README.md @@ -0,0 +1,3 @@ +# BR-OUTPUT — trios-crypto + +Re-exports CY-00, CY-01, CY-02. Sign/verify stub roundtrip test. diff --git a/crates/trios-crypto/rings/BR-OUTPUT/RING.md b/crates/trios-crypto/rings/BR-OUTPUT/RING.md new file mode 100644 index 0000000000..d6f747edf4 --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/RING.md @@ -0,0 +1,3 @@ +# RING — BR-OUTPUT (trios-crypto) + +Top of ring graph. Imports CY-00, CY-01, CY-02. diff --git a/crates/trios-crypto/rings/BR-OUTPUT/TASK.md b/crates/trios-crypto/rings/BR-OUTPUT/TASK.md new file mode 100644 index 0000000000..f531ade93a --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/TASK.md @@ -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 diff --git a/crates/trios-crypto/rings/BR-OUTPUT/src/lib.rs b/crates/trios-crypto/rings/BR-OUTPUT/src/lib.rs new file mode 100644 index 0000000000..cedfafdaa3 --- /dev/null +++ b/crates/trios-crypto/rings/BR-OUTPUT/src/lib.rs @@ -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)); + } +} diff --git a/crates/trios-crypto/rings/CY-00/AGENTS.md b/crates/trios-crypto/rings/CY-00/AGENTS.md new file mode 100644 index 0000000000..9763382a71 --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/AGENTS.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-00/Cargo.lock b/crates/trios-crypto/rings/CY-00/Cargo.lock new file mode 100644 index 0000000000..e9fac46d59 --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "trios-crypto-cy00" +version = "0.1.0" diff --git a/crates/trios-crypto/rings/CY-00/Cargo.toml b/crates/trios-crypto/rings/CY-00/Cargo.toml new file mode 100644 index 0000000000..d6e886e666 --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/Cargo.toml @@ -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] diff --git a/crates/trios-crypto/rings/CY-00/README.md b/crates/trios-crypto/rings/CY-00/README.md new file mode 100644 index 0000000000..50c91dba3b --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/README.md @@ -0,0 +1,8 @@ +# CY-00 — identity types + +Bottom of the ring graph for trios-crypto. + +## API +- `KeyId(String)` +- `PublicKey(Vec)` +- `PrivateKey(Vec)` diff --git a/crates/trios-crypto/rings/CY-00/RING.md b/crates/trios-crypto/rings/CY-00/RING.md new file mode 100644 index 0000000000..971fa1a53a --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/RING.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-00/TASK.md b/crates/trios-crypto/rings/CY-00/TASK.md new file mode 100644 index 0000000000..2706735648 --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/TASK.md @@ -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/` diff --git a/crates/trios-crypto/rings/CY-00/src/lib.rs b/crates/trios-crypto/rings/CY-00/src/lib.rs new file mode 100644 index 0000000000..c59200b7a8 --- /dev/null +++ b/crates/trios-crypto/rings/CY-00/src/lib.rs @@ -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) -> Self { + Self(id.into()) + } + + pub fn as_str(&self) -> &str { + &self.0 + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct PublicKey(pub Vec); + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct PrivateKey(pub Vec); + +#[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); + } +} diff --git a/crates/trios-crypto/rings/CY-01/AGENTS.md b/crates/trios-crypto/rings/CY-01/AGENTS.md new file mode 100644 index 0000000000..d2b8c76333 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/AGENTS.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-01/Cargo.lock b/crates/trios-crypto/rings/CY-01/Cargo.lock new file mode 100644 index 0000000000..f6df3fd8d0 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "trios-crypto-cy00" +version = "0.1.0" + +[[package]] +name = "trios-crypto-cy01" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", +] diff --git a/crates/trios-crypto/rings/CY-01/Cargo.toml b/crates/trios-crypto/rings/CY-01/Cargo.toml new file mode 100644 index 0000000000..6ba7abf932 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/Cargo.toml @@ -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] diff --git a/crates/trios-crypto/rings/CY-01/README.md b/crates/trios-crypto/rings/CY-01/README.md new file mode 100644 index 0000000000..1e3a111663 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/README.md @@ -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. diff --git a/crates/trios-crypto/rings/CY-01/RING.md b/crates/trios-crypto/rings/CY-01/RING.md new file mode 100644 index 0000000000..98601c6808 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/RING.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-01/TASK.md b/crates/trios-crypto/rings/CY-01/TASK.md new file mode 100644 index 0000000000..0fb84e3966 --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/TASK.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-01/src/lib.rs b/crates/trios-crypto/rings/CY-01/src/lib.rs new file mode 100644 index 0000000000..db93db847d --- /dev/null +++ b/crates/trios-crypto/rings/CY-01/src/lib.rs @@ -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); + +/// 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); + } +} diff --git a/crates/trios-crypto/rings/CY-02/AGENTS.md b/crates/trios-crypto/rings/CY-02/AGENTS.md new file mode 100644 index 0000000000..28009328a3 --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/AGENTS.md @@ -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 diff --git a/crates/trios-crypto/rings/CY-02/Cargo.lock b/crates/trios-crypto/rings/CY-02/Cargo.lock new file mode 100644 index 0000000000..d422c2b3cd --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/Cargo.lock @@ -0,0 +1,22 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "trios-crypto-cy00" +version = "0.1.0" + +[[package]] +name = "trios-crypto-cy01" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", +] + +[[package]] +name = "trios-crypto-cy02" +version = "0.1.0" +dependencies = [ + "trios-crypto-cy00", + "trios-crypto-cy01", +] diff --git a/crates/trios-crypto/rings/CY-02/Cargo.toml b/crates/trios-crypto/rings/CY-02/Cargo.toml new file mode 100644 index 0000000000..1460b846a5 --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/Cargo.toml @@ -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] diff --git a/crates/trios-crypto/rings/CY-02/README.md b/crates/trios-crypto/rings/CY-02/README.md new file mode 100644 index 0000000000..b799384d7e --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/README.md @@ -0,0 +1,5 @@ +# CY-02 — verification + +Stub `verify_stub`. Depends on CY-00 + CY-01. + +Real Ed25519/secp256k1 verification migrates from legacy FFI. diff --git a/crates/trios-crypto/rings/CY-02/RING.md b/crates/trios-crypto/rings/CY-02/RING.md new file mode 100644 index 0000000000..2903c7037f --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/RING.md @@ -0,0 +1,12 @@ +# RING — CY-02 + +Signature verification. + +## Dependencies +- CY-00, CY-01 + +## Laws +- R1: no BR-OUTPUT +- R9: no sibling imports +- May import shallower rings (CY-00, CY-01) +- L6: pure Rust diff --git a/crates/trios-crypto/rings/CY-02/TASK.md b/crates/trios-crypto/rings/CY-02/TASK.md new file mode 100644 index 0000000000..811f45d61a --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/TASK.md @@ -0,0 +1,9 @@ +# TASK — CY-02 + +## Status: SCAFFOLDED +- [x] verify_stub +- [x] Tests + +## Open +- [ ] Migrate Ed25519 verify +- [ ] Migrate BTC ECDSA verify diff --git a/crates/trios-crypto/rings/CY-02/src/lib.rs b/crates/trios-crypto/rings/CY-02/src/lib.rs new file mode 100644 index 0000000000..082a6c8599 --- /dev/null +++ b/crates/trios-crypto/rings/CY-02/src/lib.rs @@ -0,0 +1,26 @@ +//! CY-02 — signature verification +//! +//! Stub verifier. Real verification migrates from FFI. + +use trios_crypto_cy00::PublicKey; +use trios_crypto_cy01::Signature; + +/// Stub verifier — accepts any signature whose first bytes match the pubkey. +/// NOT cryptographically secure; placeholder for migration. +pub fn verify_stub(pub_key: &PublicKey, _message: &[u8], sig: &Signature) -> bool { + sig.0.starts_with(&pub_key.0) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn verify_stub_matches_prefix() { + let pub_key = PublicKey(vec![1, 2, 3]); + let good = Signature(vec![1, 2, 3, 99]); + let bad = Signature(vec![9, 9, 9]); + assert!(verify_stub(&pub_key, b"msg", &good)); + assert!(!verify_stub(&pub_key, b"msg", &bad)); + } +}