Skip to content

feat(signing)!: introduce pluggable ConsensusSignatureScheme trait - #16

Merged
seemenkina merged 1 commit into
mainfrom
feature/sign_trait
May 14, 2026
Merged

seemenkina merged 1 commit into
mainfrom
feature/sign_trait

Conversation

@seemenkina

Copy link
Copy Markdown
Collaborator

Summary

  • Decouple the consensus core from Ethereum-specific signing by introducing a single ConsensusSignatureScheme trait (identity + async sign + static verify) in src/signing.rs.
  • ConsensusService<Scope, Storage, Event, Signer> now carries the scheme as a generic param via PhantomData; validate_proposal, validate_vote, and ConsensusSession helpers are generic over Signer.
  • EthereumConsensusSigner wraps alloy::signers::local::PrivateKeySigner and is the default scheme used by DefaultConsensusService. Embedders can plug in Ed25519, HSM-backed signers, libchat accounts, or any other scheme.
  • Sign/verify errors collapse into a single ConsensusSchemeError thiserror enum (Sign / Verify variants). ConsensusError::MismatchedLength and InvalidSignature are removed; scheme-level failures surface via ConsensusError::SignatureScheme(_).
  • tests/custom_scheme_tests.rs exercises the generic path end-to-end with a non-Ethereum stub scheme, proving the abstraction holds.
  • Bumps the crate to 0.3.0 with CHANGELOG migration notes and refreshed README.

Breaking change

cast_vote, build_vote, and validate_proposal now require a ConsensusSignatureScheme. Migrate by wrapping existing signers:

// before
service.cast_vote(&scope, id, true, private_key_signer).await?;

// after
use hashgraph_like_consensus::signing::EthereumConsensusSigner;
service.cast_vote(&scope, id, true, EthereumConsensusSigner::new(private_key_signer)).await?;

validate_proposal::<EthereumConsensusSigner>(&proposal)?; for direct callers.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-features --tests -- -D warnings
  • cargo test --all-features --tests (all 91 tests pass, including the new custom_scheme_tests)
  • cargo test --doc
  • CI green

- Add `ConsensusSignatureScheme` (identity + async sign + static verify)
  in `src/signing.rs`; decouples the consensus core from Ethereum.
- `ConsensusService` gains a `Signer` generic param tracked via
  PhantomData; `validate_proposal`, `validate_vote`, and session helpers
  are generic over the scheme.
- `EthereumConsensusSigner` (wraps `alloy::signers::local::PrivateKeySigner`)
  is the default scheme used by `DefaultConsensusService`.
- Collapse sign/verify errors into a single `ConsensusSchemeError`
  thiserror enum (`Sign` / `Verify` variants); drop `MismatchedLength`
  and `InvalidSignature` from `ConsensusError`.
- Add `tests/custom_scheme_tests.rs` exercising the generic path with a
  non-Ethereum stub scheme.
- Bump to 0.3.0; refresh CHANGELOG, README, and lib docs.

BREAKING CHANGE: `cast_vote`, `build_vote`, and `validate_proposal` now
require a `ConsensusSignatureScheme`. Existing callers that passed a
`PrivateKeySigner` should wrap it in `EthereumConsensusSigner::new(...)`.
@seemenkina
seemenkina merged commit 3293b51 into main May 14, 2026
3 checks passed
@seemenkina
seemenkina deleted the feature/sign_trait branch May 14, 2026 07:35
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