Class: Sidetree::Model::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/sidetree/model/document.rb

Overview

DID document class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_keys: [], services: []) ⇒ Document

Returns a new instance of Document.

Parameters:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sidetree/model/document.rb', line 10

def initialize(public_keys: [], services: [])
  public_keys.each do |public_key|
    unless public_key.is_a?(Sidetree::Key)
      raise Error, "public_keys should be array of Sidetree::Key objects."
    end
  end
  id_set = public_keys.map(&:id)
  if (id_set.count - id_set.uniq.count) > 0
    raise Error "Public key id has to be unique."
  end
  services.each do |service|
    unless service.is_a?(Sidetree::Model::Service)
      raise Error,
            "services should be array of Sidetree::Model::Service objects."
    end
  end
  id_set = services.map(&:id)
  if (id_set.count - id_set.uniq.count) > 0
    raise Error "Service id has to be unique."
  end

  @public_keys = public_keys
  @services = services
end

Instance Attribute Details

#public_keysObject (readonly)

Returns the value of attribute public_keys.



5
6
7
# File 'lib/sidetree/model/document.rb', line 5

def public_keys
  @public_keys
end

#servicesObject (readonly)

Returns the value of attribute services.



6
7
8
# File 'lib/sidetree/model/document.rb', line 6

def services
  @services
end

Instance Method Details

#to_hObject



35
36
37
# File 'lib/sidetree/model/document.rb', line 35

def to_h
  { publicKeys: public_keys.map(&:to_h), services: services.map(&:to_h) }
end

#to_replace_patchHash

Generate replace patch.

Returns:

  • (Hash)


41
42
43
# File 'lib/sidetree/model/document.rb', line 41

def to_replace_patch
  { action: OP::PatchAction::REPLACE, document: to_h }
end