@@ -102,21 +102,21 @@ impl LogEntry for AddAssociation {
102
102
103
103
let new_member_address = self . new_member_signature . recover_signer ( ) ?;
104
104
let existing_member_address = self . existing_member_signature . recover_signer ( ) ?;
105
+ let recovery_address = & existing_state. recovery_address ;
106
+
107
+ // You cannot add yourself
105
108
if new_member_address == existing_member_address {
106
109
return Err ( AssociationError :: Generic ( "tried to add self" . to_string ( ) ) ) ;
107
110
}
108
111
109
- if self . new_member_role == EntityRole :: LegacyKey {
112
+ // Only allow LegacyDelegated signatures on XIDs with a nonce of 0
113
+ // Otherwise the client should use the regular wallet signature to create
114
+ if self . new_member_signature . signature_kind ( ) == SignatureKind :: LegacyDelegated {
110
115
if existing_state. xid != generate_xid ( & existing_member_address, & 0 ) {
111
116
return Err ( AssociationError :: LegacySignatureReuse ) ;
112
117
}
113
118
}
114
119
115
- // Find the existing entity that authorized this add
116
- let existing_entity = existing_state
117
- . get ( & existing_member_address)
118
- . ok_or ( AssociationError :: MissingExistingMember ) ?;
119
-
120
120
// Make sure that the signature type lines up with the role
121
121
if !allowed_signature_for_role (
122
122
& self . new_member_role ,
@@ -128,10 +128,30 @@ impl LogEntry for AddAssociation {
128
128
) ) ;
129
129
}
130
130
131
+ let existing_member = existing_state. get ( & existing_member_address) ;
132
+
133
+ let existing_entity_id = match existing_member {
134
+ // If there is an existing member of the XID, use that member's ID
135
+ Some ( member) => member. id . clone ( ) ,
136
+ None => {
137
+ // Check if it is a signature from the recovery address, which is allowed to add members
138
+ if existing_member_address. ne ( recovery_address) {
139
+ return Err ( AssociationError :: MissingExistingMember ) ;
140
+ }
141
+ // BUT, the recovery address has to be used with a real wallet signature, can't be delegated
142
+ if self . existing_member_signature . signature_kind ( ) == SignatureKind :: LegacyDelegated
143
+ {
144
+ return Err ( AssociationError :: LegacySignatureReuse ) ;
145
+ }
146
+ // If it is a real wallet signature, then it is allowed to add members
147
+ recovery_address. clone ( )
148
+ }
149
+ } ;
150
+
131
151
let new_member = Entity :: new (
132
152
self . new_member_role . clone ( ) ,
133
153
new_member_address,
134
- Some ( existing_entity . id ) ,
154
+ Some ( existing_entity_id ) ,
135
155
) ;
136
156
137
157
println ! (
@@ -166,6 +186,13 @@ impl LogEntry for RevokeAssociation {
166
186
maybe_existing_state : Option < AssociationState > ,
167
187
) -> Result < AssociationState , AssociationError > {
168
188
let existing_state = maybe_existing_state. ok_or ( AssociationError :: NotCreated ) ?;
189
+
190
+ if self . recovery_address_signature . signature_kind ( ) == SignatureKind :: LegacyDelegated {
191
+ return Err ( AssociationError :: SignatureNotAllowed (
192
+ EntityRole :: Address ,
193
+ SignatureKind :: LegacyDelegated ,
194
+ ) ) ;
195
+ }
169
196
// Don't need to check for replay here since revocation is idempotent
170
197
let recovery_signer = self . recovery_address_signature . recover_signer ( ) ?;
171
198
// Make sure there is a recovery address set on the state
@@ -239,19 +266,13 @@ pub fn allowed_signature_for_role(role: &EntityRole, signature_kind: &SignatureK
239
266
SignatureKind :: Erc191 => true ,
240
267
SignatureKind :: Erc1271 => true ,
241
268
SignatureKind :: InstallationKey => false ,
242
- SignatureKind :: LegacyKey => false ,
243
- } ,
244
- EntityRole :: LegacyKey => match signature_kind {
245
- SignatureKind :: Erc191 => false ,
246
- SignatureKind :: Erc1271 => false ,
247
- SignatureKind :: InstallationKey => false ,
248
- SignatureKind :: LegacyKey => true ,
269
+ SignatureKind :: LegacyDelegated => true ,
249
270
} ,
250
271
EntityRole :: Installation => match signature_kind {
251
272
SignatureKind :: Erc191 => false ,
252
273
SignatureKind :: Erc1271 => false ,
253
274
SignatureKind :: InstallationKey => true ,
254
- SignatureKind :: LegacyKey => false ,
275
+ SignatureKind :: LegacyDelegated => false ,
255
276
} ,
256
277
}
257
278
}
0 commit comments