6
6
7
7
enum {
8
8
TAG_STRUCT_VERSION = 0x00 ,
9
- TAG_DERIVATION_IDX = 0x01 ,
10
- TAG_DELEGATE_ADDR = 0x02 ,
11
- TAG_CHAIN_ID = 0x03 ,
12
- TAG_NONCE = 0x04 ,
9
+ TAG_DELEGATE_ADDR = 0x01 ,
10
+ TAG_CHAIN_ID = 0x02 ,
11
+ TAG_NONCE = 0x03 ,
13
12
};
14
13
15
14
enum {
16
15
BIT_VERSION ,
17
- BIT_DERIVATION_IDX ,
18
16
BIT_DELEGATE_ADDR ,
19
17
BIT_CHAIN_ID ,
20
18
BIT_NONCE ,
21
19
};
22
20
23
21
#define STRUCT_VERSION 0x01
24
- #define MASK_ALL \
25
- (SET_BIT(BIT_VERSION) | SET_BIT(BIT_DERIVATION_IDX) | SET_BIT(BIT_DELEGATE_ADDR) | \
26
- SET_BIT(BIT_CHAIN_ID) | SET_BIT(BIT_NONCE))
22
+ #define MASK_ALL \
23
+ (SET_BIT(BIT_VERSION) | SET_BIT(BIT_DELEGATE_ADDR) | SET_BIT(BIT_CHAIN_ID) | SET_BIT(BIT_NONCE))
27
24
28
25
static bool handle_version (const s_tlv_data * data , s_auth_7702_ctx * context ) {
29
26
if (data -> length != sizeof (uint8_t )) {
30
27
return false;
31
28
}
32
29
context -> mask_parsed |= SET_BIT (BIT_VERSION );
33
- return (data -> value [0 ] == STRUCT_VERSION );
34
- }
35
-
36
- static bool handle_derivation_idx (const s_tlv_data * data , s_auth_7702_ctx * context ) {
37
- uint32_t idx ;
38
- if (data -> length != sizeof (uint32_t )) {
39
- return false;
40
- }
41
- if (context -> auth_7702 .bip32 .length == MAX_BIP32_PATH ) {
42
- return false;
43
- }
44
- idx = read_u32_be (data -> value , 0 );
45
- context -> auth_7702 .bip32 .path [context -> auth_7702 .bip32 .length ] = idx ;
46
- context -> auth_7702 .bip32 .length ++ ;
47
- context -> mask_parsed |= SET_BIT (BIT_DERIVATION_IDX );
30
+ context -> version = data -> value [0 ];
48
31
return true;
49
32
}
50
33
51
34
static bool handle_delegate_addr (const s_tlv_data * data , s_auth_7702_ctx * context ) {
52
- if (data -> length != sizeof (context -> auth_7702 .delegate )) {
35
+ uint8_t buf [sizeof (context -> auth_7702 .delegate )];
36
+
37
+ if (data -> length > sizeof (buf )) {
53
38
return false;
54
39
}
55
- memmove (context -> auth_7702 .delegate , data -> value , sizeof (context -> auth_7702 .delegate ));
40
+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
41
+ memmove (context -> auth_7702 .delegate , buf , sizeof (buf ));
56
42
context -> mask_parsed |= SET_BIT (BIT_DELEGATE_ADDR );
57
43
return true;
58
44
}
59
45
60
46
static bool handle_chain_id (const s_tlv_data * data , s_auth_7702_ctx * context ) {
61
- if (data -> length != sizeof (uint64_t )) {
47
+ uint8_t buf [sizeof (context -> auth_7702 .chainId )];
48
+
49
+ if (data -> length > sizeof (buf )) {
62
50
return false;
63
51
}
64
- context -> auth_7702 .chainId = read_u64_be (data -> value , 0 );
52
+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
53
+ context -> auth_7702 .chainId = read_u64_be (buf , 0 );
65
54
context -> mask_parsed |= SET_BIT (BIT_CHAIN_ID );
66
55
return true;
67
56
}
68
57
69
58
static bool handle_nonce (const s_tlv_data * data , s_auth_7702_ctx * context ) {
70
- if (data -> length != sizeof (uint64_t )) {
59
+ uint8_t buf [sizeof (context -> auth_7702 .nonce )];
60
+
61
+ if (data -> length > sizeof (buf )) {
71
62
return false;
72
63
}
73
- context -> auth_7702 .nonce = read_u64_be (data -> value , 0 );
64
+ buf_shrink_expand (data -> value , data -> length , buf , sizeof (buf ));
65
+ context -> auth_7702 .nonce = read_u64_be (buf , 0 );
74
66
context -> mask_parsed |= SET_BIT (BIT_NONCE );
75
67
return true;
76
68
}
@@ -82,9 +74,6 @@ bool handle_auth_7702_struct(const s_tlv_data *data, s_auth_7702_ctx *context) {
82
74
case TAG_STRUCT_VERSION :
83
75
ret = handle_version (data , context );
84
76
break ;
85
- case TAG_DERIVATION_IDX :
86
- ret = handle_derivation_idx (data , context );
87
- break ;
88
77
case TAG_DELEGATE_ADDR :
89
78
ret = handle_delegate_addr (data , context );
90
79
break ;
@@ -101,8 +90,8 @@ bool handle_auth_7702_struct(const s_tlv_data *data, s_auth_7702_ctx *context) {
101
90
return ret ;
102
91
}
103
92
104
- bool verify_auth_7702_struct (s_auth_7702_ctx * context ) {
105
- return ((context -> mask_parsed & MASK_ALL ) == MASK_ALL );
93
+ bool verify_auth_7702_struct (const s_auth_7702_ctx * context ) {
94
+ return ((context -> mask_parsed & MASK_ALL ) == MASK_ALL ) && ( context -> version == STRUCT_VERSION ) ;
106
95
}
107
96
108
- #endif // HAVE_EIP7702
97
+ #endif // HAVE_EIP7702
0 commit comments