Skip to main content

SigningService

Struct SigningService 

Source
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

§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>

Source

pub const fn new(chain: C, policy: P, signer: S) -> Self

Create a new signing service with the given components.

§Arguments
  • chain - The chain parser for decoding raw transactions
  • policy - The policy engine for evaluating rules
  • signer - The signer for producing signatures
§Example
let service = SigningService::new(chain, policy, signer);
Source

pub const fn chain(&self) -> &C

Get a reference to the chain parser.

Source

pub const fn policy(&self) -> &P

Get a reference to the policy engine.

Source

pub const fn signer(&self) -> &S

Get a reference to the signer.

Source§

impl<C, P, S> SigningService<C, P, S>

Source

pub fn sign(&self, raw_tx: &[u8]) -> Result<SigningResult, SigningError>

Sign a raw transaction.

This method performs the complete signing flow:

  1. Parse - Transform raw bytes into a ParsedTx
  2. Check - Evaluate against policy rules
  3. 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:

§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();
Source

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:

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");
}

Trait Implementations§

Source§

impl<C, P, S> Debug for SigningService<C, P, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, P, S> Freeze for SigningService<C, P, S>
where C: Freeze, P: Freeze, S: Freeze,

§

impl<C, P, S> RefUnwindSafe for SigningService<C, P, S>

§

impl<C, P, S> Send for SigningService<C, P, S>
where C: Send, P: Send, S: Send,

§

impl<C, P, S> Sync for SigningService<C, P, S>
where C: Sync, P: Sync, S: Sync,

§

impl<C, P, S> Unpin for SigningService<C, P, S>
where C: Unpin, P: Unpin, S: Unpin,

§

impl<C, P, S> UnwindSafe for SigningService<C, P, S>
where C: UnwindSafe, P: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.