Class: DIDKit::Document
- Inherits:
-
Object
- Object
- DIDKit::Document
- Defined in:
- lib/didkit/document.rb
Overview
Parsed DID document from a JSON file loaded from plc.directory or a did:web domain.
Use DIDKit::DID#document or Resolver#resolve_did to fetch a DID document and return this object.
Instance Attribute Summary collapse
-
#did ⇒ DID
readonly
The DID that this document describes.
-
#json ⇒ Hash
readonly
The complete JSON data of the DID document.
-
#services ⇒ Array<ServiceRecords>
readonly
Service records like PDS details assigned to the DID.
Attributes included from AtHandles
Instance Method Summary collapse
-
#get_verified_handle ⇒ String?
Returns the first verified handle assigned to the DID.
-
#initialize(did, json) ⇒ Document
constructor
Creates a DID document object.
Methods included from Services
#get_service, #labeler_endpoint, #labeler_host, #pds_endpoint, #pds_host
Constructor Details
#initialize(did, json) ⇒ Document
Creates a DID document object.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/didkit/document.rb', line 36 def initialize(did, json) raise FormatError, "Missing id field" if json['id'].nil? raise FormatError, "Invalid id field" unless json['id'].is_a?(String) raise FormatError, "id field doesn't match expected DID" unless json['id'] == did.to_s @did = did @json = json parse_services(json['service'] || []) parse_also_known_as(json['alsoKnownAs'] || []) end |
Instance Attribute Details
#did ⇒ DID (readonly)
Returns the DID that this document describes.
25 26 27 |
# File 'lib/didkit/document.rb', line 25 def did @did end |
#json ⇒ Hash (readonly)
Returns the complete JSON data of the DID document.
22 23 24 |
# File 'lib/didkit/document.rb', line 22 def json @json end |
#services ⇒ Array<ServiceRecords> (readonly)
Returns service records like PDS details assigned to the DID.
28 29 30 |
# File 'lib/didkit/document.rb', line 28 def services @services end |
Instance Method Details
#get_verified_handle ⇒ String?
Returns the first verified handle assigned to the DID.
Looks up the domain handles assigned to this DID in the DID document, checks if they are verified (i.e. assigned correctly to this DID using DNS TXT or .well-known) and returns the first handle that validates correctly, or nil if none matches.
56 57 58 |
# File 'lib/didkit/document.rb', line 56 def get_verified_handle Resolver.new.get_verified_handle(self) end |