-
Notifications
You must be signed in to change notification settings - Fork 2
Add api client #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
#[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, | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
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 :?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This PR aims to add api client to submit observations to aggregator server