Skip to content

Commit

Permalink
Added publisher_signature to offchain entries (#53)
Browse files Browse the repository at this point in the history
* feat(store_publisher_signature): Added publisher_signature

* feat(store_publisher_signature): Revert compose change 🤡🤡🤡🤡

* feat(store_publisher_signature): Down SQL

* feat(store_publisher_signature): publisher_signature can be NULL
  • Loading branch information
akhercha authored Jun 7, 2024
1 parent 14f6182 commit 5073e69
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE entries
DROP COLUMN publisher_signature;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE entries
ADD COLUMN publisher_signature VARCHAR;
3 changes: 3 additions & 0 deletions pragma-entities/src/models/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Entry {
pub publisher: String,
pub source: String,
pub timestamp: NaiveDateTime,
pub publisher_signature: Option<String>,
pub price: BigDecimal,
}

Expand All @@ -30,6 +31,7 @@ pub struct NewEntry {
pub publisher: String,
pub source: String,
pub timestamp: NaiveDateTime,
pub publisher_signature: String,
pub price: BigDecimal,
}

Expand All @@ -51,6 +53,7 @@ impl Entry {
entries::pair_id.eq(excluded(entries::pair_id)),
entries::publisher.eq(excluded(entries::publisher)),
entries::source.eq(excluded(entries::source)),
entries::publisher_signature.eq(excluded(entries::publisher_signature)),
entries::timestamp.eq(excluded(entries::timestamp)),
entries::price.eq(excluded(entries::price)),
))
Expand Down
1 change: 1 addition & 0 deletions pragma-entities/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ diesel::table! {
timestamp -> Timestamptz,
price -> Numeric,
source -> Varchar,
publisher_signature -> Nullable<Varchar>,
}
}

Expand Down
17 changes: 7 additions & 10 deletions pragma-node/src/handlers/entries/create_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,12 @@ pub async fn create_entries(
);

let message_hash = build_publish_message(&new_entries.entries)?.message_hash(account_address);

if !ecdsa_verify(
&public_key,
&message_hash,
&Signature {
r: new_entries.signature[0],
s: new_entries.signature[1],
},
)
.map_err(EntryError::InvalidSignature)?
let signature = Signature {
r: new_entries.signature[0],
s: new_entries.signature[1],
};
if !ecdsa_verify(&public_key, &message_hash, &signature)
.map_err(EntryError::InvalidSignature)?
{
tracing::error!("Invalid signature for message hash {:?}", &message_hash);
return Err(EntryError::Unauthorized);
Expand All @@ -154,6 +150,7 @@ pub async fn create_entries(
publisher: entry.base.publisher.clone(),
source: entry.base.source.clone(),
timestamp: dt,
publisher_signature: format!("0x{}", signature),
price: entry.price.into(),
})
})
Expand Down

0 comments on commit 5073e69

Please sign in to comment.