forked from ethereum/fe
-
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.
Closes ethereum#186
- Loading branch information
Showing
21 changed files
with
172 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
[package] | ||
name = "fe-common" | ||
version = "0.0.1" | ||
authors = ["Ethereum Foundation <snakecharmers@ethereum.org>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tiny-keccak = { version = "2.0", features = ["keccak"] } | ||
hex = "0.4" |
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 @@ | ||
pub mod utils; |
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,18 @@ | ||
use tiny_keccak::{ | ||
Hasher, | ||
Keccak, | ||
}; | ||
|
||
pub fn get_full_signature(content: &[u8]) -> String { | ||
get_partial_signature(content, 32) | ||
} | ||
|
||
pub fn get_partial_signature(content: &[u8], size: usize) -> String { | ||
let mut keccak = Keccak::v256(); | ||
let mut selector = [0u8; 32]; | ||
|
||
keccak.update(content); | ||
keccak.finalize(&mut selector); | ||
|
||
format!("0x{}", hex::encode(&selector[0..size])) | ||
} |
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 @@ | ||
pub mod keccak; |
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,27 +1,17 @@ | ||
use tiny_keccak::{ | ||
Hasher, | ||
Keccak, | ||
}; | ||
use fe_common::utils::keccak::get_partial_signature; | ||
|
||
/// Formats the name and fields and calculates the 32 byte keccak256 value of | ||
/// the signature. | ||
pub fn event_topic(name: String, fields: Vec<String>) -> String { | ||
sig_keccak256(name, fields, 32) | ||
sign_event_or_func(name, fields, 32) | ||
} | ||
/// Formats the name and params and calculates the 4 byte keccak256 value of the | ||
/// signature. | ||
pub fn func_selector(name: String, params: Vec<String>) -> String { | ||
sig_keccak256(name, params, 4) | ||
sign_event_or_func(name, params, 4) | ||
} | ||
|
||
fn sig_keccak256(name: String, params: Vec<String>, size: usize) -> String { | ||
fn sign_event_or_func(name: String, params: Vec<String>, size: usize) -> String { | ||
let signature = format!("{}({})", name, params.join(",")); | ||
|
||
let mut keccak = Keccak::v256(); | ||
let mut selector = [0u8; 32]; | ||
|
||
keccak.update(signature.as_bytes()); | ||
keccak.finalize(&mut selector); | ||
|
||
format!("0x{}", hex::encode(&selector[0..size])) | ||
get_partial_signature(signature.as_bytes(), size) | ||
} |
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
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
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
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,11 @@ | ||
Add support for string literals. | ||
|
||
Example: | ||
|
||
``` | ||
def get_ticker_symbol() -> string3: | ||
return "ETH" | ||
``` | ||
|
||
String literals are stored in and loaded from the compiled bytecode. | ||
|
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 |
---|---|---|
|
@@ -48,8 +48,8 @@ x | |
), | ||
Spanned( | ||
node: Str([ | ||
"\"asdf\"", | ||
"\"foo\"", | ||
"asdf", | ||
"foo", | ||
]), | ||
span: Span( | ||
start: 14, | ||
|
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
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.