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](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.
-
#handles ⇒ Array<String>
readonly
Returns a list of handles assigned to this DID in its DID document.
-
#json ⇒ Hash
readonly
The complete JSON data of the DID document.
-
#services ⇒ Array<ServiceRecords>
readonly
Service records like PDS details assigned to the DID.
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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/didkit/document.rb', line 44 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 @services = parse_services(json['service'] || []) @handles = 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 |
#handles ⇒ Array<String> (readonly)
Returns a list of handles assigned to this DID in its DID document.
Note: the handles aren’t guaranteed to be verified (validated in the other direction). Use #get_verified_handle to find a handle that is correctly verified.
33 34 35 |
# File 'lib/didkit/document.rb', line 33 def handles @handles 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.
36 37 38 |
# File 'lib/didkit/document.rb', line 36 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.
64 65 66 |
# File 'lib/didkit/document.rb', line 64 def get_verified_handle Resolver.new.get_verified_handle(self) end |