Class: DIDKit::Document

Inherits:
Object
  • Object
show all
Includes:
AtHandles, Services
Defined in:
lib/didkit/document.rb

Defined Under Namespace

Classes: FormatError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Services

#get_service, #labeler_endpoint, #labeler_host, #pds_endpoint, #pds_host

Methods included from AtHandles

#parse_also_known_as

Constructor Details

#initialize(did, json) ⇒ Document

Returns a new instance of Document.

Raises:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/didkit/document.rb', line 16

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

#didObject (readonly)

Returns the value of attribute did.



14
15
16
# File 'lib/didkit/document.rb', line 14

def did
  @did
end

#handlesObject (readonly)

Returns the value of attribute handles.



14
15
16
# File 'lib/didkit/document.rb', line 14

def handles
  @handles
end

#jsonObject (readonly)

Returns the value of attribute json.



14
15
16
# File 'lib/didkit/document.rb', line 14

def json
  @json
end

#servicesObject (readonly)

Returns the value of attribute services.



14
15
16
# File 'lib/didkit/document.rb', line 14

def services
  @services
end

Instance Method Details

#get_verified_handleObject



28
29
30
# File 'lib/didkit/document.rb', line 28

def get_verified_handle
  Resolver.new.get_verified_handle(self)
end