Class: AtprotoAuth::Identity::Document
- Inherits:
-
Object
- Object
- AtprotoAuth::Identity::Document
- Defined in:
- lib/atproto_auth/identity/document.rb
Overview
Represents and validates a DID Document in the AT Protocol.
DID Documents contain critical service information about user accounts, including:
-
The Personal Data Server (PDS) hosting the account
-
Associated handles for the account
-
Key material for identity verification
-
Service endpoints for various protocols
This class handles both current and legacy DID document formats, providing a consistent interface for accessing and validating document data.
Instance Attribute Summary collapse
-
#also_known_as ⇒ Object
readonly
Returns the value of attribute also_known_as.
-
#did ⇒ Object
readonly
Returns the value of attribute did.
-
#pds ⇒ Object
readonly
Returns the value of attribute pds.
-
#rotation_keys ⇒ Object
readonly
Returns the value of attribute rotation_keys.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
-
#has_handle?(handle) ⇒ Boolean
Checks if this document contains a specific handle.
-
#initialize(data) ⇒ Document
constructor
Creates a new Document from parsed JSON.
Constructor Details
#initialize(data) ⇒ Document
Creates a new Document from parsed JSON
44 45 46 47 48 49 50 51 52 |
# File 'lib/atproto_auth/identity/document.rb', line 44 def initialize(data) validate_document!(data) @did = data["id"] @rotation_keys = data["verificationMethod"]&.map { |m| m["publicKeyMultibase"] } || [] @also_known_as = data["alsoKnownAs"] || [] @services = data["service"] || [] @pds = extract_pds!(data) end |
Instance Attribute Details
#also_known_as ⇒ Object (readonly)
Returns the value of attribute also_known_as.
39 40 41 |
# File 'lib/atproto_auth/identity/document.rb', line 39 def also_known_as @also_known_as end |
#did ⇒ Object (readonly)
Returns the value of attribute did.
39 40 41 |
# File 'lib/atproto_auth/identity/document.rb', line 39 def did @did end |
#pds ⇒ Object (readonly)
Returns the value of attribute pds.
39 40 41 |
# File 'lib/atproto_auth/identity/document.rb', line 39 def pds @pds end |
#rotation_keys ⇒ Object (readonly)
Returns the value of attribute rotation_keys.
39 40 41 |
# File 'lib/atproto_auth/identity/document.rb', line 39 def rotation_keys @rotation_keys end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
39 40 41 |
# File 'lib/atproto_auth/identity/document.rb', line 39 def services @services end |
Instance Method Details
#has_handle?(handle) ⇒ Boolean
Checks if this document contains a specific handle
57 58 59 60 61 62 |
# File 'lib/atproto_auth/identity/document.rb', line 57 def has_handle?(handle) # rubocop:disable Naming/PredicateName normalized = handle.start_with?("@") ? handle[1..] : handle @also_known_as.any? do |aka| aka.start_with?("at://") && aka.delete_prefix("at://") == normalized end end |