-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from statechannels/jie.pushmessage
Validate peer_update in rust code
- Loading branch information
Showing
13 changed files
with
410 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ authors = ["Jannis Pohlmann <[email protected]>"] | |
ethereum-types = "0.9" | ||
ethabi = { git = "https://github.com/graphprotocol/ethabi", rev = "fe7cab5" } | ||
hex = "0.4" | ||
libsecp256k1 = "0.3" | ||
libsecp256k1 = "0.3.5" | ||
serde_derive = "1.0" | ||
serde = "1.0" | ||
tiny-keccak = "2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use ethabi::{encode, Token}; | ||
use ethereum_types::{Address}; | ||
use serde_derive::*; | ||
|
||
use super::tokenize::*; | ||
use super::types::*; | ||
use super::utils::*; | ||
use super::state::*; | ||
|
||
//#[derive(Deserialize)] | ||
//#[serde(rename_all = "camelCase")] | ||
pub struct SignedStateVarsWithHash { | ||
pub turn_num: Uint48, | ||
pub is_final: bool, | ||
pub outcome: Outcome, | ||
pub app_data: Bytes, | ||
pub hash: Bytes32, | ||
pub signature: RecoverableSignature | ||
} | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Channel { | ||
pub chain_id: Uint256, | ||
pub channel_nonce: Uint256, | ||
pub participants: Vec<Address>, | ||
} | ||
|
||
impl Channel { | ||
pub fn id(&self) -> Bytes32 { | ||
keccak256( | ||
encode(&[ | ||
self.chain_id.tokenize(), | ||
Token::Array( | ||
self.participants | ||
.iter() | ||
.cloned() | ||
.map(Token::Address) | ||
.collect(), | ||
), | ||
self.channel_nonce.tokenize(), | ||
]) | ||
.as_slice(), | ||
) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
use hex; | ||
use secp256k1::{RecoveryId, Signature}; | ||
use serde::ser::*; | ||
use serde::ser::{Serialize, Serializer}; | ||
use serde::de::{Error, Deserialize, Deserializer}; | ||
|
||
pub fn serialize_signature<S>( | ||
(signature, recovery_id): &(Signature, RecoveryId), | ||
serializer: S, | ||
) -> Result<S::Ok, S::Error> | ||
where | ||
use super::state::RecoverableSignature; | ||
use super::types::*; | ||
|
||
impl Serialize for RecoverableSignature { | ||
fn serialize<S>( | ||
&self, | ||
serializer: S, | ||
) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
// A helper struct to go from `[u8; 64]` to `&[u8]` so that `hex::encode` | ||
// accepts it. | ||
struct RawBytes64([u8; 64]); | ||
{ | ||
// A helper struct to go from `[u8; 64]` to `&[u8]` so that `hex::encode` | ||
// accepts it. | ||
struct RawBytes64([u8; 64]); | ||
|
||
impl AsRef<[u8]> for RawBytes64 { | ||
fn as_ref(&self) -> &[u8] { | ||
&self.0 | ||
impl AsRef<[u8]> for RawBytes64 { | ||
fn as_ref(&self) -> &[u8] { | ||
&self.0 | ||
} | ||
} | ||
|
||
let bytes = self.0.serialize(); | ||
let s = hex::encode(RawBytes64(bytes)); | ||
serializer.serialize_str(format!("0x{}{:x}", s, self.1.serialize() + 27).as_str()) | ||
} | ||
} | ||
|
||
let bytes = signature.serialize(); | ||
let s = hex::encode(RawBytes64(bytes)); | ||
serializer.serialize_str(format!("0x{}{:x}", s, recovery_id.serialize() + 27).as_str()) | ||
impl<'de> Deserialize<'de> for RecoverableSignature { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let bytes: Bytes = Deserialize::deserialize(deserializer)?; | ||
Ok(RecoverableSignature::from_bytes(bytes).map_err(D::Error::custom)?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.