diff --git a/Cargo.lock b/Cargo.lock index 4f21bd30..c2522c72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1671,7 +1671,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "starknet" -version = "0.9.0" +version = "0.10.0" dependencies = [ "serde_json", "starknet-accounts", @@ -1681,14 +1681,13 @@ dependencies = [ "starknet-macros", "starknet-providers", "starknet-signers", - "starknet-types-core", "tokio", "url", ] [[package]] name = "starknet-accounts" -version = "0.8.0" +version = "0.9.0" dependencies = [ "async-trait", "auto_impl", @@ -1705,7 +1704,7 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.8.0" +version = "0.9.0" dependencies = [ "rand", "serde", @@ -1723,7 +1722,7 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.9.0" +version = "0.10.0" dependencies = [ "base64 0.21.7", "criterion", @@ -1743,7 +1742,7 @@ dependencies = [ [[package]] name = "starknet-crypto" -version = "0.6.1" +version = "0.6.2" dependencies = [ "bitvec", "criterion", @@ -1767,16 +1766,15 @@ dependencies = [ [[package]] name = "starknet-crypto-codegen" -version = "0.3.2" +version = "0.3.3" dependencies = [ "starknet-curve", - "starknet-types-core", "syn 2.0.55", ] [[package]] name = "starknet-curve" -version = "0.4.1" +version = "0.4.2" dependencies = [ "bitvec", "starknet-types-core", @@ -1795,7 +1793,7 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.1.6" +version = "0.1.7" dependencies = [ "starknet-core", "starknet-types-core", @@ -1804,7 +1802,7 @@ dependencies = [ [[package]] name = "starknet-providers" -version = "0.9.0" +version = "0.10.0" dependencies = [ "async-trait", "auto_impl", @@ -1825,7 +1823,7 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.7.0" +version = "0.8.0" dependencies = [ "async-trait", "auto_impl", diff --git a/Cargo.toml b/Cargo.toml index ee31a17a..00ada836 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet" -version = "0.9.0" +version = "0.10.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -33,14 +33,13 @@ members = [ all-features = true [dependencies] -starknet-crypto = { version = "0.6.1", path = "./starknet-crypto" } -starknet-core = { version = "0.9.0", path = "./starknet-core", default-features = false } -starknet-providers = { version = "0.9.0", path = "./starknet-providers" } -starknet-contract = { version = "0.8.0", path = "./starknet-contract" } -starknet-signers = { version = "0.7.0", path = "./starknet-signers" } -starknet-accounts = { version = "0.8.0", path = "./starknet-accounts" } -starknet-macros = { version = "0.1.6", path = "./starknet-macros" } -starknet-types-core = "0.0.10" +starknet-crypto = { version = "0.6.2", path = "./starknet-crypto" } +starknet-core = { version = "0.10.0", path = "./starknet-core", default-features = false } +starknet-providers = { version = "0.10.0", path = "./starknet-providers" } +starknet-contract = { version = "0.9.0", path = "./starknet-contract" } +starknet-signers = { version = "0.8.0", path = "./starknet-signers" } +starknet-accounts = { version = "0.9.0", path = "./starknet-accounts" } +starknet-macros = { version = "0.1.7", path = "./starknet-macros" } [dev-dependencies] serde_json = "1.0.74" diff --git a/examples/starknet-wasm/Cargo.toml b/examples/starknet-wasm/Cargo.toml index d63db39a..3ca94c73 100644 --- a/examples/starknet-wasm/Cargo.toml +++ b/examples/starknet-wasm/Cargo.toml @@ -19,7 +19,7 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -starknet-crypto = { version = "0.6.1", path = "../../starknet-crypto" } +starknet-crypto = { version = "0.6.2", path = "../../starknet-crypto" } console_error_panic_hook = { version = "0.1.7", optional = true } wasm-bindgen = "0.2.84" starknet-types-core = "0.0.10" diff --git a/starknet-accounts/Cargo.toml b/starknet-accounts/Cargo.toml index da41032f..2029da68 100644 --- a/starknet-accounts/Cargo.toml +++ b/starknet-accounts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-accounts" -version = "0.8.0" +version = "0.9.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -14,9 +14,9 @@ keywords = ["ethereum", "starknet", "web3"] exclude = ["test-data/**"] [dependencies] -starknet-core = { version = "0.9.0", path = "../starknet-core" } -starknet-providers = { version = "0.9.0", path = "../starknet-providers" } -starknet-signers = { version = "0.7.0", path = "../starknet-signers" } +starknet-core = { version = "0.10.0", path = "../starknet-core" } +starknet-providers = { version = "0.10.0", path = "../starknet-providers" } +starknet-signers = { version = "0.8.0", path = "../starknet-signers" } async-trait = "0.1.68" auto_impl = "1.0.1" thiserror = "1.0.40" diff --git a/starknet-contract/Cargo.toml b/starknet-contract/Cargo.toml index 592a1dcc..d987ec7b 100644 --- a/starknet-contract/Cargo.toml +++ b/starknet-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-contract" -version = "0.8.0" +version = "0.9.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -14,9 +14,9 @@ keywords = ["ethereum", "starknet", "web3"] exclude = ["test-data/**"] [dependencies] -starknet-core = { version = "0.9.0", path = "../starknet-core" } -starknet-providers = { version = "0.9.0", path = "../starknet-providers" } -starknet-accounts = { version = "0.8.0", path = "../starknet-accounts" } +starknet-core = { version = "0.10.0", path = "../starknet-core" } +starknet-providers = { version = "0.10.0", path = "../starknet-providers" } +starknet-accounts = { version = "0.9.0", path = "../starknet-accounts" } serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.96" serde_with = "2.3.2" @@ -25,6 +25,6 @@ starknet-types-core = "0.0.10" [dev-dependencies] rand = { version = "0.8.5", features=["std_rng"] } -starknet-signers = { version = "0.7.0", path = "../starknet-signers" } +starknet-signers = { version = "0.8.0", path = "../starknet-signers" } tokio = { version = "1.27.0", features = ["full"] } url = "2.3.1" diff --git a/starknet-core/Cargo.toml b/starknet-core/Cargo.toml index db1b31ef..dff59636 100644 --- a/starknet-core/Cargo.toml +++ b/starknet-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-core" -version = "0.9.0" +version = "0.10.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -17,7 +17,7 @@ exclude = ["test-data/**"] all-features = true [dependencies] -starknet-crypto = { version = "0.6.1", path = "../starknet-crypto", default-features = false, features = ["alloc"] } +starknet-crypto = { version = "0.6.2", path = "../starknet-crypto", default-features = false, features = ["alloc"] } base64 = { version = "0.21.0", default-features = false, features = ["alloc"] } flate2 = { version = "1.0.25", optional = true } hex = { version = "0.4.3", default-features = false, features = ["alloc"] } diff --git a/starknet-crypto-codegen/Cargo.toml b/starknet-crypto-codegen/Cargo.toml index 182c0140..259857fc 100644 --- a/starknet-crypto-codegen/Cargo.toml +++ b/starknet-crypto-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-crypto-codegen" -version = "0.3.2" +version = "0.3.3" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -16,6 +16,5 @@ keywords = ["ethereum", "starknet", "web3", "no_std"] proc-macro = true [dependencies] -starknet-curve = { version = "0.4.1", path = "../starknet-curve" } -syn = { version = "2.0.15", default-features = true } -starknet-types-core = "0.0.10" +starknet-curve = { version = "0.4.2", path = "../starknet-curve" } +syn = { version = "2.0.15", default-features = false } diff --git a/starknet-crypto/Cargo.toml b/starknet-crypto/Cargo.toml index d57089a2..fa071c9f 100644 --- a/starknet-crypto/Cargo.toml +++ b/starknet-crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-crypto" -version = "0.6.1" +version = "0.6.2" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -14,8 +14,8 @@ keywords = ["ethereum", "starknet", "web3", "no_std"] exclude = ["test-data/**"] [dependencies] -starknet-crypto-codegen = { version = "0.3.2", path = "../starknet-crypto-codegen" } -starknet-curve = { version = "0.4.1", path = "../starknet-curve" } +starknet-crypto-codegen = { version = "0.3.3", path = "../starknet-crypto-codegen" } +starknet-curve = { version = "0.4.2", path = "../starknet-curve" } crypto-bigint = { version = "0.5.1", default-features = false, features = ["generic-array", "zeroize"] } hmac = { version = "0.12.1", default-features = false } num-bigint = { version = "0.4.3", default-features = false } diff --git a/starknet-crypto/src/ecdsa.rs b/starknet-crypto/src/ecdsa.rs index d513a747..5c8af532 100644 --- a/starknet-crypto/src/ecdsa.rs +++ b/starknet-crypto/src/ecdsa.rs @@ -203,6 +203,11 @@ fn mul_by_bits(x: &AffinePoint, y: &Felt) -> AffinePoint { #[cfg(test)] mod tests { + #[cfg(not(feature = "std"))] + use alloc::collections::BTreeMap; + #[cfg(feature = "std")] + use std::collections::BTreeMap; + use super::*; use crate::test_utils::field_element_from_be_hex; @@ -215,11 +220,11 @@ mod tests { let private_key = field_element_from_be_hex( "03c1e9550e66958296d11b60f8e8e7a7ad990d07fa65d5f7652c4a6c87d4e3cc", ); - let expected_key = field_element_from_be_hex( + let expected_public_key = field_element_from_be_hex( "077a3b314db07c45076d11f62b6f9e748a39790441823307743cf00d6597ea43", ); - assert_eq!(get_public_key(&private_key), expected_key); + assert_eq!(get_public_key(&private_key), expected_public_key); } #[test] @@ -228,11 +233,48 @@ mod tests { let private_key = field_element_from_be_hex( "0000000000000000000000000000000000000000000000000000000000000012", ); - let expected_key = field_element_from_be_hex( + let expected_public_key = field_element_from_be_hex( "019661066e96a8b9f06a1d136881ee924dfb6a885239caa5fd3f87a54c6b25c4", ); - assert_eq!(get_public_key(&private_key), expected_key); + assert_eq!(get_public_key(&private_key), expected_public_key); + } + + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + fn test_get_public_keys_from_json() { + // Precomputed keys can be found here: + // https://github.com/starkware-libs/starkex-for-spot-trading/blob/607f0b4ce507e1d95cd018d206a2797f6ba4aab4/src/starkware/crypto/starkware/crypto/signature/src/config/keys_precomputed.json + + // Reading the JSON file + let json_data = include_str!("../test-data/keys_precomputed.json"); + + // Parsing the JSON + let key_map: BTreeMap = + serde_json::from_str(json_data).expect("Unable to parse the JSON"); + + // Iterating over each element in the JSON + for (private_key, expected_public_key) in key_map.into_iter() { + let private_key = if private_key.len() % 2 != 0 { + format!("0{}", private_key.trim_start_matches("0x")) + } else { + private_key.trim_start_matches("0x").to_owned() + }; + + let expected_public_key = if expected_public_key.len() % 2 != 0 { + format!("0{}", expected_public_key.trim_start_matches("0x")) + } else { + expected_public_key.trim_start_matches("0x").to_owned() + }; + + // Assertion + assert_eq!( + get_public_key(&field_element_from_be_hex( + private_key.trim_start_matches("0x") + )), + field_element_from_be_hex(expected_public_key.trim_start_matches("0x")) + ); + } } #[test] diff --git a/starknet-crypto/src/pedersen_hash.rs b/starknet-crypto/src/pedersen_hash.rs index 06c74a5c..d8a98e38 100644 --- a/starknet-crypto/src/pedersen_hash.rs +++ b/starknet-crypto/src/pedersen_hash.rs @@ -37,9 +37,6 @@ pub fn pedersen_hash(x: &Felt, y: &Felt) -> Felt { add_points(&mut acc, &y[..248], &CURVE_CONSTS_P2); // Add b_low * P3 add_points(&mut acc, &y[248..252], &CURVE_CONSTS_P3); // Add b_high * P4 - // Convert to affine - let result = AffinePoint::from(&acc); - // Return x-coordinate result.x } @@ -61,21 +58,30 @@ mod tests { use crate::test_utils::field_element_from_be_hex; // Test case ported from: - // https://github.com/starkware-libs/crypto-cpp/blob/95864fbe11d5287e345432dbe1e80dea3c35fc58/src/starkware/crypto/ffi/crypto_lib_test.go + // https://github.com/starkware-libs/starkex-for-spot-trading/blob/607f0b4ce507e1d95cd018d206a2797f6ba4aab4/src/starkware/crypto/starkware/crypto/signature/test/config/signature_test_data.json #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] fn test_pedersen_hash() { - let in1 = field_element_from_be_hex( - "03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb", - ); - let in2 = field_element_from_be_hex( - "0208a0a10250e382e1e4bbe2880906c2791bf6275695e02fbbc6aeff9cd8b31a", - ); - let expected_hash = field_element_from_be_hex( - "030e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662", - ); + let test_data = [ + ( + "03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb", + "0208a0a10250e382e1e4bbe2880906c2791bf6275695e02fbbc6aeff9cd8b31a", + "030e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662", + ), + ( + "058f580910a6ca59b28927c08fe6c43e2e303ca384badc365795fc645d479d45", + "078734f65a067be9bdb39de18434d71e79f7b6466a4b66bbd979ab9e7515fe0b", + "068cc0b76cddd1dd4ed2301ada9b7c872b23875d5ff837b3a87993e0d9996b87", + ), + ]; + + for (in1, in2, expected_hash) in test_data.into_iter() { + let in1 = field_element_from_be_hex(in1); + let in2 = field_element_from_be_hex(in2); + let expected_hash = field_element_from_be_hex(expected_hash); - assert_eq!(pedersen_hash(&in1, &in2), expected_hash); + assert_eq!(pedersen_hash(&in1, &in2), expected_hash); + } } } diff --git a/starknet-crypto/test-data/keys_precomputed.json b/starknet-crypto/test-data/keys_precomputed.json new file mode 100644 index 00000000..75278bc4 --- /dev/null +++ b/starknet-crypto/test-data/keys_precomputed.json @@ -0,0 +1,32 @@ +{ + "0x1": "0x1ef15c18599971b7beced415a40f0c7deacfd9b0d1819e03d723d8bc943cfca", + "0x2": "0x759ca09377679ecd535a81e83039658bf40959283187c654c5416f439403cf5", + "0x3": "0x411494b501a98abd8262b0da1351e17899a0c4ef23dd2f96fec5ba847310b20", + "0x4": "0xa7da05a4d664859ccd6e567b935cdfbfe3018c7771cb980892ef38878ae9bc", + "0x5": "0x788435d61046d3eec54d77d25bd194525f4fa26ebe6575536bc6f656656b74c", + "0x6": "0x1efc3d7c9649900fcbd03f578a8248d095bc4b6a13b3c25f9886ef971ff96fa", + "0x7": "0x743829e0a179f8afe223fc8112dfc8d024ab6b235fd42283c4f5970259ce7b7", + "0x8": "0x6eeee2b0c71d681692559735e08a2c3ba04e7347c0c18d4d49b83bb89771591", + "0x9": "0x216b4f076ff47e03a05032d1c6ee17933d8de8b2b4c43eb5ad5a7e1b25d3849", + "0x800000000000000000000000000000000000000000000000000000000000000": "0x5c79074e7f7b834c12c81a9bb0d46691a5e7517767a849d9d98cb84e2176ed2", + "0x800000000000000000000000000000000000000000000000000000000000001": "0x1c4f24e3bd16db0e2457bc005a9d61965105a535554c6b338871e34cb8e2d3a", + "0x800000000000000000000000000000000000000000000000000000000000002": "0xdfbb89b39288a9ddacf3942b4481b04d4fa2f8ed3c424757981cc6357f27ac", + "0x800000000000000000000000000000000000000000000000000000000000003": "0x41bef28265fd750b102f4f2d1e0231de7f4a33900a214f191a63d4fec4e72f4", + "0x800000000000000000000000000000000000000000000000000000000000004": "0x24de66eb164797d4b414e81ded0cfa1a592ef0a9363ebbcb440d4d03cb18af1", + "0x800000000000000000000000000000000000000000000000000000000000005": "0x5efb18c3bc9b69003746acc85fb6ee0cfbdc6adfb982f089cc63e1e5495daad", + "0x800000000000000000000000000000000000000000000000000000000000006": "0x10dc71f00918a8ebfe4085c834d41dd22b251b9f81eef8b9a4fab77e7e1afe9", + "0x800000000000000000000000000000000000000000000000000000000000007": "0x4267ebfd379b1c8caae73febc5920b0c95bd6f9f3536f47c5ddad1259c332ff", + "0x800000000000000000000000000000000000000000000000000000000000008": "0x6da515118c8e01fd5b2e96b814ee95bad7d60be4d2ba6b47e0d283f579d9671", + "0x800000000000000000000000000000000000000000000000000000000000009": "0x7a5b4797f4e56ed1473876bc2693fbe3f2fef7e050717cbae924ff23d426052", + "0x2e9c99d8382fa004dcbbee720aef8a97002de0e991f6a8344e6dc636a71b59e": "0x1ff6803ae740e7e596504ac5c6afbea472e53679361e214f12be0155b13e25d", + "0x8620458785138df8722214e073a91b8f55076ea78197cf41007692dd27fd90": "0x5967da40b90d7ca1e36dc4024381d7d4b403c6ac1a0ab358b0743984934a805", + "0x1b920e7dfb49ba5ada673882af5342e7448d3e9335e0ac37feb6280cd7289ce": "0x78c7ab46333968fbde3201cf512c1eeb5529360259072c459a158dee4449b57", + "0x704170dbfd5dc63caef69d2ce6dfc2b2dbb2af6e75851242bbe79fb6e62a118": "0x534bd8d6ebe4bb2f6992e2d7c19ef3146247e10c2849f357e44eddd283b2af6", + "0x4b58bf4228f39550eca59b5c96a0cb606036cc9495eef9a546f24f01b1b7829": "0x1097a8c5a46d94596f1c8e70ca66941f2bb11e3c8d4fd58fdc4589f09965be8", + "0x2e93226c90fb7a2381a24e940a94b98433e3553dcbf745d3f54d62963c75604": "0x369f0e8c8e984f244290267393a004dba435a4df091767ad5063fece7b1884c", + "0x4615f94598cd756ad1a551d7e57fd725916adfd0054eb773ceb482eef87d0b2": "0x1ee5b8d612102a2408cde59ce52a6498d2e38fe8789bb26d400dea310684ec9", + "0x6ade54b7debd7ca1d4e8e932f9545f8fa4024d73be1efcc86df86367fc333f8": "0x37de3bf52412b2fb9b0030d232ca9dd921cd8f71fd67975cdc62546826e121", + "0x618e7467dd24c2a3449c4df640439c12cdd0f8ea779afcee6e252b2cf494354": "0x71c2b578c432f2d305d3808bb645ecc46dd670cb43d4f4a076f75ccbff74fbc", + "0x7eae185e1f41ec76d214d763f0592f194933622a9dd5f3d52d0209f71619c1a": "0x2b0160052e70176e5b0ff2a6eff90896ae07b732fc27219e36e077735abd57e", + "0x178047D3869489C055D7EA54C014FFB834A069C9595186ABE04EA4D1223A03F": "0x1895a6a77ae14e7987b9cb51329a5adfb17bd8e7c638f92d6892d76e51cebcf" +} diff --git a/starknet-curve/Cargo.toml b/starknet-curve/Cargo.toml index cd61bfa4..44b2d0eb 100644 --- a/starknet-curve/Cargo.toml +++ b/starknet-curve/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-curve" -version = "0.4.1" +version = "0.4.2" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" diff --git a/starknet-macros/Cargo.toml b/starknet-macros/Cargo.toml index fac91e01..b8d1f59d 100644 --- a/starknet-macros/Cargo.toml +++ b/starknet-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-macros" -version = "0.1.6" +version = "0.1.7" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -16,7 +16,7 @@ keywords = ["ethereum", "starknet", "web3"] proc-macro = true [dependencies] -starknet-core = { version = "0.9.0", path = "../starknet-core" } +starknet-core = { version = "0.10.0", path = "../starknet-core" } syn = "2.0.15" starknet-types-core = "0.0.10" diff --git a/starknet-providers/Cargo.toml b/starknet-providers/Cargo.toml index cf8551e9..7e8351db 100644 --- a/starknet-providers/Cargo.toml +++ b/starknet-providers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-providers" -version = "0.9.0" +version = "0.10.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -14,7 +14,7 @@ keywords = ["ethereum", "starknet", "web3"] exclude = ["test-data/**"] [dependencies] -starknet-core = { version = "0.9.0", path = "../starknet-core" } +starknet-core = { version = "0.10.0", path = "../starknet-core" } async-trait = "0.1.68" auto_impl = "1.0.1" ethereum-types = "0.14.1" diff --git a/starknet-signers/Cargo.toml b/starknet-signers/Cargo.toml index 7f4c7c2f..a2aeeb3a 100644 --- a/starknet-signers/Cargo.toml +++ b/starknet-signers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starknet-signers" -version = "0.7.0" +version = "0.8.0" authors = ["Jonathan LEI "] license = "MIT OR Apache-2.0" edition = "2021" @@ -13,8 +13,8 @@ Starknet signer implementations keywords = ["ethereum", "starknet", "web3"] [dependencies] -starknet-core = { version = "0.9.0", path = "../starknet-core" } -starknet-crypto = { version = "0.6.1", path = "../starknet-crypto" } +starknet-core = { version = "0.10.0", path = "../starknet-core" } +starknet-crypto = { version = "0.6.2", path = "../starknet-crypto" } async-trait = "0.1.68" auto_impl = "1.0.1" thiserror = "1.0.40"