forked from starknet-edu/starknet-accounts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature_2.cairo
64 lines (54 loc) · 1.86 KB
/
signature_2.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin
from starkware.starknet.common.syscalls import call_contract, get_tx_info
from starkware.cairo.common.signature import verify_ecdsa_signature
from starkware.cairo.common.alloc import alloc
####################
# STORAGE VARIABLES
####################
@storage_var
func public_key() -> (res : felt):
end
####################
# CONSTRUCTOR
####################
@constructor
func constructor{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(pub_key : felt):
public_key.write(pub_key)
return ()
end
####################
# GETTERS
####################
#
# ACTION ITEM 1: verify the provided signature with std library `verify_ecdsa_signature`
# - reference: https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/signature.cairo
#
@view
func is_valid_signature{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr, ecdsa_ptr : SignatureBuiltin*
}(hash : felt, signature_len : felt, signature : felt*) -> ():
let (_public_key) = public_key.read()
#
# <CODE>
#
return ()
end
####################
# EXTERNAL FUNCTIONS
####################
@external
func __execute__{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
contract_address : felt, selector : felt, calldata_len : felt, calldata : felt*
) -> (retdata_len : felt, retdata : felt*):
let (tx_info) = get_tx_info()
let (vec : felt*) = alloc()
assert [vec] = calldata[0]
assert [vec + 1] = tx_info.signature[0]
assert [vec + 2] = tx_info.signature[1]
assert [vec + 3] = calldata[2]
let (retdata_len : felt, retdata : felt*) = call_contract(
contract_address=contract_address, function_selector=selector, calldata_size=4, calldata=vec
)
return (retdata_len=retdata_len, retdata=retdata)
end