pub struct SigningService<C, P, S> { /* private fields */ }Expand description
Orchestrates the signing flow: parsing, policy checking, and signing.
The SigningService combines a chain parser, policy engine, and signer
into a unified interface for processing transaction signing requests.
§Type Parameters
C- Chain parser implementing theChainParsertraitP- Policy engine implementing thePolicyEngineExttraitS- Signer implementing theSignerExttrait
§Thread Safety
This struct is Send + Sync when all type parameters are, allowing
it to be safely shared across threads and async tasks.
§Example
use txgate_core::signing::SigningService;
// Create with concrete implementations
let service = SigningService::new(ethereum_parser, policy_engine, secp256k1_signer);
// Sign a transaction (includes policy check)
let result = service.sign(&raw_tx)?;
if result.is_allowed() {
let sig = result.signature.expect("signature present");
println!("Signature: 0x{}", hex::encode(sig));
}
// Or just check without signing
let check_result = service.check(&raw_tx)?;
if check_result.is_allowed() {
println!("Transaction would be allowed");
}Implementations§
Source§impl<C, P, S> SigningService<C, P, S>
impl<C, P, S> SigningService<C, P, S>
Source§impl<C, P, S> SigningService<C, P, S>
impl<C, P, S> SigningService<C, P, S>
Sourcepub fn sign(&self, raw_tx: &[u8]) -> Result<SigningResult, SigningError>
pub fn sign(&self, raw_tx: &[u8]) -> Result<SigningResult, SigningError>
Sign a raw transaction.
This method performs the complete signing flow:
- Parse - Transform raw bytes into a
ParsedTx - Check - Evaluate against policy rules
- Sign - If allowed, sign the transaction hash
§Arguments
raw_tx- The raw transaction bytes to sign
§Returns
A SigningResult containing the parsed transaction, policy result,
and signature (if allowed).
§Errors
Returns SigningError if:
- Transaction parsing fails (
SigningError::ParseError) - Policy evaluation fails (
SigningError::PolicyError) - Transaction is denied by policy (
SigningError::PolicyDenied) - Signing operation fails (
SigningError::SignError)
§Example
let result = service.sign(&raw_tx)?;
// Access the signature
let sig = result.signature.expect("signature present");
let recovery_id = result.recovery_id.expect("recovery ID present");
// Or get as 65-byte array
let full_sig = result.signature_with_recovery_id().unwrap();Sourcepub fn check(&self, raw_tx: &[u8]) -> Result<SigningResult, SigningError>
pub fn check(&self, raw_tx: &[u8]) -> Result<SigningResult, SigningError>
Parse and check policy without signing (dry run).
This method performs the parsing and policy check steps without actually signing the transaction. Useful for validating transactions before committing to sign them.
§Arguments
raw_tx- The raw transaction bytes to check
§Returns
A SigningResult containing the parsed transaction and policy result.
The signature and recovery_id fields will be None.
§Errors
Returns SigningError if:
- Transaction parsing fails (
SigningError::ParseError) - Policy evaluation fails (
SigningError::PolicyError)
Note: This method does NOT return an error if the policy denies the
transaction. Instead, check result.is_allowed() or result.policy_result.
§Example
let result = service.check(&raw_tx)?;
if result.is_allowed() {
println!("Transaction would be allowed");
// Optionally proceed to sign
let sign_result = service.sign(&raw_tx)?;
} else {
println!("Transaction would be denied");
}