Skip to content

Conversation

@danimhr
Copy link
Collaborator

@danimhr danimhr commented Jun 4, 2025

This PR aims to add api client to submit observations to aggregator server

@danimhr danimhr force-pushed the feat/api-client branch from 6c14bf8 to a5ab4b8 Compare June 4, 2025 12:31
Comment on lines +25 to +50
#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Observation<P> {
pub version: u8,
#[serde(with = "hex::serde")]
pub signature: [u8; 65],
pub body: Body<P>,
}

impl<P: Serialize> Observation<P> {
pub fn try_new(body: Body<P>, secret_key: SecretKey) -> Result<Self, anyhow::Error> {
let digest = body.digest()?;
let signature = Secp256k1::new()
.sign_ecdsa_recoverable(Message::from_digest(digest.secp256k_hash), &secret_key);
let (recovery_id, signature_bytes) = signature.serialize_compact();
let recovery_id: i32 = recovery_id.into();
let mut signature = [0u8; 65];
signature[..64].copy_from_slice(&signature_bytes);
signature[64] = recovery_id as u8;

Ok(Self {
version: 1,
signature,
body,
})
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add them to lib.rs :?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we should add it to lib.rs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nitpiky but boundary wise this doesn't belong to api client.

@danimhr danimhr merged commit 836c559 into main Jun 5, 2025
1 check passed
@danimhr danimhr deleted the feat/api-client branch June 5, 2025 12:07
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.

3 participants