Skip to content

Commit

Permalink
fix: links, typos, preludes...
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 committed Aug 8, 2024
1 parent e5467e4 commit ab91a31
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 312 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// ANCHOR: contract
use core::starknet::eth_address::EthAddress;
use starknet::secp256_trait::{Signature};

// How to Sign and Verify
// # Signing
// 1. Create message to sign
// 2. Hash the message
// 3. Sign the hash (off chain, keep your private key secret)

use core::starknet::eth_address::EthAddress;
use starknet::secp256_trait::{Signature};
#[starknet::interface]
trait IVerifySignature<TContractState> {
fn get_signature(self: @TContractState, r: u256, s: u256, v: u32,) -> Signature;
Expand All @@ -29,7 +30,6 @@ mod verifySignature {
Secp256Trait, Secp256PointTrait, Signature, signature_from_vrs, recover_public_key,
is_signature_entry_valid
};
use core::traits::{TryInto, Into};
use starknet::eth_signature::{verify_eth_signature, public_key_point_to_eth_address};

#[storage]
Expand Down Expand Up @@ -58,7 +58,6 @@ mod verifySignature {
signature
}


/// Verifies an Ethereum signature.
///
/// # Arguments
Expand Down Expand Up @@ -95,4 +94,41 @@ mod verifySignature {
}
}
}
// ANCHOR_END: contract

#[cfg(test)]
mod tests {
use starknet::secp256_trait::{
Secp256Trait, Secp256PointTrait, Signature, signature_from_vrs, recover_public_key,
is_signature_entry_valid
};
use starknet::EthAddress;
use starknet::secp256k1::{Secp256k1Point};
use starknet::eth_signature::{verify_eth_signature, public_key_point_to_eth_address};

fn get_message_and_signature() -> (u256, Signature, EthAddress) {
let msg_hash = 0x546ec3fa4f7d3308931816fafd47fa297afe9ac9a09651f77acc13c05a84734f;
let r = 0xc0f30bcef72974dedaf165cf7848a83b0b9eb6a65167a14643df96698d753efb;
let s = 0x7f189e3cb5eb992d8cd26e287a13e900326b87f58da2b7fb48fbd3977e3cab1c;
let v = 27;

let eth_address = 0x5F04693482cfC121FF244cB3c3733aF712F9df02_u256.into();
let signature: Signature = signature_from_vrs(v, r, s);

(msg_hash, signature, eth_address)
}

#[test]
fn test_verify_eth_signature() {
let (msg_hash, signature, eth_address) = get_message_and_signature();
verify_eth_signature(:msg_hash, :signature, :eth_address);
}

#[test]
fn test_secp256k1_recover_public_key() {
let (msg_hash, signature, eth_address) = get_message_and_signature();
let public_key_point = recover_public_key::<Secp256k1Point>(msg_hash, signature).unwrap();
let calculated_eth_address = public_key_point_to_eth_address(:public_key_point);
assert_eq!(calculated_eth_address, eth_address);
}
}
3 changes: 0 additions & 3 deletions listings/advanced-concepts/ecdsa_verification/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
mod ecdsa_verification;

#[cfg(test)]
mod tests;
41 changes: 0 additions & 41 deletions listings/advanced-concepts/ecdsa_verification/src/tests.cairo

This file was deleted.

2 changes: 1 addition & 1 deletion listings/applications/advanced_factory/src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait ICampaignFactory<TContractState> {

#[starknet::contract]
pub mod CampaignFactory {
use core::num::traits::zero::Zero;
use core::num::traits::Zero;
use starknet::{
ContractAddress, ClassHash, SyscallResultTrait, syscalls::deploy_syscall,
get_caller_address, get_contract_address
Expand Down
1 change: 0 additions & 1 deletion listings/applications/advanced_factory/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::traits::TryInto;
use core::clone::Clone;
use core::result::ResultTrait;
use advanced_factory::contract::{
Expand Down
1 change: 0 additions & 1 deletion listings/applications/components/src/ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ mod test {
use starknet::ContractAddress;
use starknet::{syscalls::deploy_syscall, SyscallResultTrait, contract_address_const};
use starknet::testing::{set_caller_address, set_contract_address};
use core::traits::TryInto;
use core::num::traits::Zero;

fn deploy() -> (IOwnableDispatcher, ContractAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub trait IConstantProductAmm<TContractState> {

#[starknet::contract]
pub mod ConstantProductAmm {
use core::traits::Into;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::{
ContractAddress, get_caller_address, get_contract_address, contract_address_const
Expand Down
2 changes: 1 addition & 1 deletion listings/applications/crowdfunding/src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait ICampaign<TContractState> {
#[starknet::contract]
pub mod Campaign {
use components::ownable::ownable_component::OwnableInternalTrait;
use core::num::traits::zero::Zero;
use core::num::traits::Zero;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::{
ClassHash, ContractAddress, SyscallResultTrait, get_block_timestamp, contract_address_const,
Expand Down
2 changes: 1 addition & 1 deletion listings/applications/crowdfunding/src/mock_upgrade.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[starknet::contract]
pub mod MockUpgrade {
use components::ownable::ownable_component::OwnableInternalTrait;
use core::num::traits::zero::Zero;
use core::num::traits::Zero;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::{
ClassHash, ContractAddress, SyscallResultTrait, get_block_timestamp, contract_address_const,
Expand Down
1 change: 0 additions & 1 deletion listings/applications/crowdfunding/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::traits::TryInto;
use core::clone::Clone;
use core::result::ResultTrait;
use starknet::{
Expand Down
3 changes: 1 addition & 2 deletions listings/applications/nft_dutch_auction/src/erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ mod ERC721 {
// library imports
////////////////////////////////
use starknet::{ContractAddress, get_caller_address};
use core::traits::TryInto;
use core::num::traits::zero::Zero;
use core::num::traits::Zero;

////////////////////////////////
// storage variables
Expand Down
3 changes: 0 additions & 3 deletions listings/applications/nft_dutch_auction/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
pub mod nft_dutch_auction;
pub mod erc721;

#[cfg(test)]
pub mod tests;
Loading

0 comments on commit ab91a31

Please sign in to comment.