graphops / graphcast-sdk

Graphcast SDK allows you to build gossip-powered Radios
https://docs.graphops.xyz/graphcast/intro
Apache License 2.0
17 stars 3 forks source link

Improve GraphcastMessage typing and signing #245

Closed hopeyen closed 1 year ago

hopeyen commented 1 year ago

Problem statement

Expectation proposal

Current Graphcast Message is structured as below such that only payload:T is signed by the signature

pub struct GraphcastMessage<T>
where
    T: Message
        + ethers::types::transaction::eip712::Eip712
        + Default
        + Clone
        + 'static
        + async_graphql::OutputType,
{
    pub identifier: String,                // not necessary as included in payload: T
    pub payload: T,                        // EIP712 signed
    pub nonce: i64,                        // not EIP712 signed, secure Graphcast level
    pub network: String,                   // not EIP712 signed, optional for radios
    pub block_number: u64,                 // not EIP712 signed, secure Graphcast level, may not be available for message sender
    pub block_hash: String,                // not EIP712 signed, secure Graphcast level, may not be available for message sender
    pub graph_account: String,             // not EIP712 signed, secure Graphcast level
    pub signature: String,                 // Signature field after signing over payload: T
}

Two options for Message layered structure 1.

Alternative consideration

pete-eiger commented 1 year ago

Love it. Also think the first approach is better, it's cleaner in the sense that it doesn't leave the Optional fields in the top-level message and enables more freedom when defining the Radio-specific message types.