| 226 | } |
| 227 | |
| 228 | func removeKey(srvc *native.NativeService) ([]byte, error) { |
| 229 | source := common.NewZeroCopySource(srvc.Input) |
| 230 | // arg0: id |
| 231 | arg0, err := utils.DecodeVarBytes(source) |
| 232 | if err != nil { |
| 233 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: argument 0 error, %s", err) |
| 234 | } |
| 235 | |
| 236 | // arg1: public key |
| 237 | arg1, err := utils.DecodeVarBytes(source) |
| 238 | if err != nil { |
| 239 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: argument 1 error, %s", err) |
| 240 | } |
| 241 | |
| 242 | // arg2: operator's public key |
| 243 | arg2, err := utils.DecodeVarBytes(source) |
| 244 | if err != nil { |
| 245 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: argument 2 error, %s", err) |
| 246 | } |
| 247 | if err = checkWitness(srvc, arg2); err != nil { |
| 248 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: check witness failed, %s", err) |
| 249 | } |
| 250 | |
| 251 | key, err := encodeID(arg0) |
| 252 | if err != nil { |
| 253 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: %s", err) |
| 254 | } |
| 255 | if !isValid(srvc, key) { |
| 256 | return utils.BYTE_FALSE, errors.New("remove key failed: ID not registered") |
| 257 | } |
| 258 | var auth = false |
| 259 | rec, err := getOldRecovery(srvc, key) |
| 260 | if len(rec) > 0 { |
| 261 | auth = bytes.Equal(rec, arg2) |
| 262 | } |
| 263 | if !auth { |
| 264 | if !isOwner(srvc, key, arg2) { |
| 265 | return utils.BYTE_FALSE, errors.New("remove key failed: operator has no authorization") |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | keyID, err := revokePk(srvc, key, arg1) |
| 270 | if err != nil { |
| 271 | return utils.BYTE_FALSE, fmt.Errorf("remove key failed: %s", err) |
| 272 | } |
| 273 | |
| 274 | triggerPublicEvent(srvc, "remove", arg0, arg1, keyID) |
| 275 | |
| 276 | return utils.BYTE_TRUE, nil |
| 277 | } |
| 278 | |
| 279 | func addAttributes(srvc *native.NativeService) ([]byte, error) { |
| 280 | source := common.NewZeroCopySource(srvc.Input) |