Skip to main content

newton_cli/
types.rs

1//! Local type definitions for CLI RPC communication
2//!
3//! These types are duplicated from newton-prover-gateway to avoid pulling in
4//! the gateway dependency which requires the eigensdk multichain fork.
5
6use alloy::primitives::{Address, Bytes, U256};
7use newton_prover_core::newton_prover_task_manager::NewtonMessage;
8use serde::{Deserialize, Serialize};
9
10/// Task intent representing a transaction to be executed
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct TaskIntent {
13    /// Sender address
14    pub from: Address,
15    /// Recipient address
16    pub to: Address,
17    /// Value to transfer
18    pub value: U256,
19    /// Transaction data (hex encoded)
20    pub data: String,
21    /// Chain ID
22    pub chain_id: U256,
23    /// Function signature (hex encoded)
24    pub function_signature: String,
25}
26
27impl From<TaskIntent> for NewtonMessage::Intent {
28    fn from(intent: TaskIntent) -> Self {
29        // Decode hex strings to Bytes
30        let data_bytes = hex::decode(intent.data.trim_start_matches("0x"))
31            .map(Bytes::from)
32            .unwrap_or_default();
33        let function_sig_bytes = hex::decode(intent.function_signature.trim_start_matches("0x"))
34            .map(Bytes::from)
35            .unwrap_or_default();
36
37        NewtonMessage::Intent {
38            from: intent.from,
39            to: intent.to,
40            value: intent.value,
41            data: data_bytes,
42            chainId: intent.chain_id,
43            functionSignature: function_sig_bytes,
44        }
45    }
46}
47
48type QuorumThresholdPercentage = u8;
49/// Request to create a task synchronously (waits for result)
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct CreateTaskRequest {
52    /// Policy client address
53    pub policy_client: Address,
54    /// Task intent specifying the transaction to execute
55    pub intent: TaskIntent,
56    /// Intent signature (hex encoded bytes)
57    pub intent_signature: Option<String>,
58    /// Quorum number override (hex encoded bytes array where each byte is a quorum number, e.g., "00" for quorum 0, "0001" for quorums 0 and 1)
59    pub quorum_number: Option<String>,
60    /// Quorum threshold percentage override for BLS aggregation
61    pub quorum_threshold_percentage: Option<QuorumThresholdPercentage>,
62    /// WASM plugin arguments (hex encoded bytes: Vec<u8>)
63    pub wasm_args: Option<String>,
64    /// Optional timeout in seconds (default: 30)
65    pub timeout: Option<u64>,
66    /// Enable Two-Phase Consensus Protocol for BLS aggregation (default: false)
67    /// Prepare phase: Collect unsigned policy data from operators
68    /// Evaluate phase: Compute median consensus, operators sign unified digest
69    /// This ensures all operators sign the same TaskResponse for successful BLS aggregation
70    pub use_two_phase: Option<bool>,
71    /// Encrypted data reference UUIDs for privacy-preserving evaluation
72    pub encrypted_data_refs: Option<Vec<String>>,
73    /// User Ed25519 signature over (policy_client + intent_hash + refs) (hex-encoded)
74    pub user_signature: Option<String>,
75    /// Application Ed25519 signature over (policy_client + intent_hash + user_sig) (hex-encoded)
76    pub app_signature: Option<String>,
77}