Skip to content

Commit ab9fbb8

Browse files
authored
Merge pull request #985 from PhilippeR26/ETHsignerContract
Ethereum account
2 parents 9610f2a + 878ba0d commit ab9fbb8

25 files changed

+25035
-123
lines changed

__mocks__/cairo/ethSigner/dummy1ForEth.casm

Lines changed: 724 additions & 0 deletions
Large diffs are not rendered by default.

__mocks__/cairo/ethSigner/dummy1ForEth.sierra.json

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.

__mocks__/cairo/ethSigner/dummy2ForEth.casm

Lines changed: 724 additions & 0 deletions
Large diffs are not rendered by default.

__mocks__/cairo/ethSigner/dummy2ForEth.sierra.json

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.

__mocks__/cairo/ethSigner/openzeppelin_EthAccount090.casm

Lines changed: 11683 additions & 0 deletions
Large diffs are not rendered by default.

__mocks__/cairo/ethSigner/openzeppelin_EthAccount090.sierra.json

Lines changed: 6365 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Cairo 2.5.3
2+
use openzeppelin::account::interface::EthPublicKey;
3+
use starknet::SyscallResultTrait;
4+
use starknet::secp256_trait::Secp256PointTrait;
5+
use starknet::secp256k1::{
6+
Secp256k1Point, secp256k1_get_point_from_x_syscall, secp256k1_new_syscall
7+
};
8+
9+
impl Secp256k1PointSerde of Serde<EthPublicKey> {
10+
fn serialize(self: @Secp256k1Point, ref output: Array<felt252>) {
11+
let point = (*self).get_coordinates().unwrap();
12+
point.serialize(ref output)
13+
}
14+
fn deserialize(ref serialized: Span<felt252>) -> Option<Secp256k1Point> {
15+
let (x, y) = Serde::<(u256, u256)>::deserialize(ref serialized)?;
16+
secp256k1_new_syscall(x, y).unwrap_syscall()
17+
}
18+
}
19+
20+
#[starknet::interface]
21+
trait IEthPub<TContractState> {
22+
fn get_public_key(self: @TContractState) -> EthPublicKey;
23+
fn set_public_key(ref self: TContractState, new_public_key: EthPublicKey);
24+
fn test_public_key(self: @TContractState, my_pub_key:EthPublicKey) -> EthPublicKey;
25+
}
26+
#[starknet::contract]
27+
mod Eth_pub_key {
28+
use openzeppelin::account::interface::EthPublicKey;
29+
use openzeppelin::account::utils::secp256k1::{Secp256k1PointSerde, Secp256k1PointStorePacking};
30+
use core::starknet::secp256_trait::Secp256PointTrait;
31+
use core::starknet::secp256k1::Secp256k1Point;
32+
33+
#[storage]
34+
struct Storage {
35+
pubK: EthPublicKey,
36+
}
37+
38+
#[abi(embed_v0)]
39+
impl InteractEthPub of super::IEthPub<ContractState> {
40+
fn get_public_key(self: @ContractState) -> EthPublicKey {
41+
self.pubK.read()
42+
}
43+
44+
fn set_public_key(ref self: ContractState, new_public_key: EthPublicKey) {
45+
self.pubK.write(new_public_key)
46+
}
47+
48+
fn test_public_key(self: @ContractState, my_pub_key:EthPublicKey) -> EthPublicKey {
49+
my_pub_key
50+
}
51+
}
52+
}
53+
54+
55+
56+
// to compile with scarb 2.5.3 :
57+
// Scarb.toml :
58+
// [package]
59+
// name = "pub_eth"
60+
// version = "0.1.0"
61+
// edition = "2023_10"
62+
63+
// [dependencies]
64+
// starknet = "2.5.3"
65+
// openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.9.0" }
66+
67+
// [lib]
68+
69+
// [[target.starknet-contract]]
70+
// sierra = true
71+
// casm = true

0 commit comments

Comments
 (0)