device_serializer.rb 928 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. class ActivityPub::DeviceSerializer < ActivityPub::Serializer
  3. context_extensions :olm
  4. include RoutingHelper
  5. class FingerprintKeySerializer < ActivityPub::Serializer
  6. attributes :type, :public_key_base64
  7. def type
  8. 'Ed25519Key'
  9. end
  10. def public_key_base64
  11. object.fingerprint_key
  12. end
  13. end
  14. class IdentityKeySerializer < ActivityPub::Serializer
  15. attributes :type, :public_key_base64
  16. def type
  17. 'Curve25519Key'
  18. end
  19. def public_key_base64
  20. object.identity_key
  21. end
  22. end
  23. attributes :device_id, :type, :name, :claim
  24. has_one :fingerprint_key, serializer: FingerprintKeySerializer
  25. has_one :identity_key, serializer: IdentityKeySerializer
  26. def type
  27. 'Device'
  28. end
  29. def claim
  30. account_claim_url(object.account, id: object.device_id)
  31. end
  32. def fingerprint_key
  33. object
  34. end
  35. def identity_key
  36. object
  37. end
  38. end