Skip to content

Commit

Permalink
feat: add sozo hash back
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Oct 30, 2024
1 parent 5075baf commit 58eed4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/sozo/src/commands/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ impl HashArgs {
if !self.input.contains(',') {
let felt = felt_from_str(&self.input)?;
let poseidon = format!("{:#066x}", poseidon_hash_single(felt));
let poseidon_array = format!("{:#066x}", poseidon_hash_many(&[felt]));
let snkeccak = format!("{:#066x}", starknet_keccak(&felt.to_bytes_le()));

println!("Poseidon: {}", poseidon);
println!("Poseidon single: {}", poseidon);
println!("Poseidon array 1 value: {}", poseidon_array);
println!("SnKeccak: {}", snkeccak);

return Ok(vec![poseidon.to_string(), snkeccak.to_string()]);
Expand Down
6 changes: 6 additions & 0 deletions bin/sozo/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) mod call;
pub(crate) mod calldata_decoder;
pub(crate) mod clean;
pub(crate) mod execute;
pub(crate) mod hash;
pub(crate) mod inspect;
pub(crate) mod migrate;
pub(crate) mod options;
Expand All @@ -19,6 +20,7 @@ use build::BuildArgs;
use call::CallArgs;
use clean::CleanArgs;
use execute::ExecuteArgs;
use hash::HashArgs;
use inspect::InspectArgs;
use migrate::MigrateArgs;
use test::TestArgs;
Expand All @@ -40,6 +42,8 @@ pub enum Commands {
Call(Box<CallArgs>),
#[command(about = "Runs cairo tests")]
Test(Box<TestArgs>),
#[command(about = "Computes hash with different hash functions")]
Hash(Box<HashArgs>),
}

impl fmt::Display for Commands {
Expand All @@ -52,6 +56,7 @@ impl fmt::Display for Commands {
Commands::Migrate(_) => write!(f, "Migrate"),
Commands::Call(_) => write!(f, "Call"),
Commands::Test(_) => write!(f, "Test"),
Commands::Hash(_) => write!(f, "Hash"),
}
}
}
Expand All @@ -72,6 +77,7 @@ pub fn run(command: Commands, config: &Config) -> Result<()> {
Commands::Clean(args) => args.run(config),
Commands::Call(args) => args.run(config),
Commands::Test(args) => args.run(config),
Commands::Hash(args) => args.run().map(|_| ()),
}
}

Expand Down

0 comments on commit 58eed4e

Please sign in to comment.