Skip to content

feat: implement coz cli#1

Merged
nrdxp merged 14 commits intomasterfrom
cli
Jan 6, 2026
Merged

feat: implement coz cli#1
nrdxp merged 14 commits intomasterfrom
cli

Conversation

@nrdxp
Copy link
Copy Markdown
Member

@nrdxp nrdxp commented Jan 6, 2026

Add Rust CLI for Coz (coz-cli)

This PR introduces a complete command-line interface for Coz operations, built as a new crate within the repository.

Changes

Repository Structure

  • Converted repository to Cargo workspace with coz-rs (library) and coz-cli (binary)
  • Shared Cargo.lock for consistent dependency resolution

CLI Commands

Command Description
coz newkey [ALG] Generate key (default: Ed25519)
coz tmb <KEY> Calculate thumbprint
coz signpay <PAY> <KEY> Sign payload, return Coz message
coz sign <COZ> <KEY> Re-sign existing message with new key
coz verify <COZ> <KEY> Verify signature
coz meta <COZ> Compute cad/czd/can
coz revoke <KEY> Generate self-revocation

Library Enhancements (coz-rs)

  • Runtime dispatch functions: sign_json(), verify_json(), revoke_json()
  • Key reconstruction: signing_key_from_bytes(), verifying_key_from_bytes()
  • Canonical hash helpers: canonical_hash_for_alg(), czd_for_alg()
  • Made ops::KeyOps trait public for downstream trait bounds
  • Added documentation for public API

Testing

  • 12 integration tests covering all commands
  • All algorithms roundtrip verified (ES256, ES384, ES512, Ed25519)
  • File input and inline JSON input tested

Documentation

  • README updated with CLI installation and usage examples

Dependencies

  • clap (derive) - Argument parsing
  • anyhow - Error handling
  • base64ct - Base64 encoding
  • assert_cmd, predicates, tempfile - Testing

Usage Example

coz newkey > key.json
coz signpay '{"msg":"Hello, Coz!"}' key.json > msg.json
coz verify msg.json key.json  # Output: true

nrdxp added 13 commits January 6, 2026 15:44
Move library code into `coz-rs/` subdirectory to prepare for
adding a CLI crate. Creates workspace root Cargo.toml with
coz-rs as the first member.

- Move src/ → coz-rs/src/
- Move Cargo.toml → coz-rs/Cargo.toml
- Add workspace root Cargo.toml with resolver = "2"
Scaffold CLI crate with clap derive-based argument parsing.
All commands stubbed with todo!() for Phase 4 implementation.

Commands: newkey, tmb, sign, signpay, verify, meta, revoke
Replace String arguments with KeyInput, CozInput, and PayInput types.
These implement FromStr for clap integration and provide file-or-JSON
detection via the .load() method.

- Add input.rs module with three input wrapper types
- Update Command enum to use typed inputs
- Update command handlers to accept typed inputs
Add key generation with algorithm dispatch (ES256, ES384, ES512, Ed25519).
Output is Coz JSON format: {"alg":"...","prv":"...","pub":"...","tmb":"..."}

Library changes:
- Add private_key_bytes() to KeyOps trait and SigningKey
- Make ops module public for downstream trait bounds

CLI changes:
- Implement cmd_newkey with algorithm match dispatch
- Add base64ct dependency for encoding
Add thumbprint calculation from key JSON input.

Library changes:
- Add compute_thumbprint_for_alg() for runtime algorithm dispatch
- Export from lib.rs

CLI changes:
- Parse key JSON for alg and pub fields
- Compute and print thumbprint
Add signature verification with runtime algorithm dispatch.

Library changes:
- Add verifying_key_from_bytes to KeyOps trait (all 4 algorithms)
- Add verify_json() for runtime verification without type parameters
- Export verify_json from lib.rs

CLI changes:
- Parse coz JSON for pay and sig fields
- Parse key JSON for alg and pub fields
- Call verify_json and print result (true/false)
Add payload signing with runtime algorithm dispatch.

Library changes:
- Add signing_key_from_bytes to KeyOps trait (all 4 algorithms)
- Add sign_json() for runtime signing

CLI changes:
- Parse key JSON for alg, prv, pub, tmb fields
- Augment pay with alg and tmb
- Sign and output complete Coz message JSON
Add metadata display and key revocation support.

Library changes:
- Add canonical_hash_for_alg() for runtime cad computation
- Add czd_for_alg() for runtime czd computation
- Add revoke_json() for runtime revocation generation

CLI changes:
- meta: compute and display can, cad, czd
- revoke: generate self-revocation Coz message
Add re-signing of existing Coz messages with a different key.

CLI changes:
- Extract pay from existing Coz message
- Update alg and tmb to match new key
- Sign with new key and output updated Coz
Library changes:
- Add documentation to ops module and KeyOps trait

CLI changes:
- Remove unused raw() methods from input types
Add end-to-end tests for all CLI commands:
- Key generation for all algorithms
- Sign/verify roundtrip
- Re-signing with different key
- Meta computation
- Key revocation
- File path input handling

Dev dependencies: assert_cmd, predicates, tempfile
Add comprehensive CLI documentation:
- Installation via cargo install
- All commands with examples
- Complete example workflow
- Update Related Projects section
Add docs/PUBLISHING.md with:
- Crate links
- Publishing order (coz-rs before coz-cli)
- Step-by-step workflow
- Version coordination guide
@nrdxp nrdxp merged commit ba7ae27 into master Jan 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant