Skip to content

Commit

Permalink
Correct address generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-kanodia committed Aug 14, 2023
1 parent 0028222 commit 801f8e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crypto_primitives/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto_primitives"
entry = "src/hash.nr"
entry = "src/address_generation.nr"
type = "bin"
authors = [""]
compiler_version = "0.9.0"
Expand Down
13 changes: 5 additions & 8 deletions crypto_primitives/src/address_generation.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
use dep::std;

fn address_from_public_key(pub_key: [u8; 64]) -> Field {
std::println(pub_key);
let hash_of_public_key = std::hash::keccak256(pub_key, 32);
std::println(hash_of_public_key);
let mut result: Field = 0;
let mut v: Field = 1;
let hashed_pub_key = std::hash::keccak256(pub_key, 64);

let mut addr: Field = 0;
for i in 0..20 {
result += hash_of_public_key[31 - i] as Field * v;
v *= 256;
addr = (addr * 256) + hashed_pub_key[i + 12] as Field;
}
result

addr
}

struct key {
Expand Down

0 comments on commit 801f8e8

Please sign in to comment.