Class: Chainpoint::Hash
- Inherits:
-
Object
- Object
- Chainpoint::Hash
- Defined in:
- lib/chainpoint/hash.rb
Constant Summary collapse
- NUM_SERVERS =
3
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#proof_handles ⇒ Object
readonly
Returns the value of attribute proof_handles.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash, proof_handles: []) ⇒ Hash
constructor
A new instance of Hash.
- #proof(anchor_type = nil) ⇒ Object
- #submit ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(hash, proof_handles: []) ⇒ Hash
Returns a new instance of Hash
15 16 17 18 19 20 21 |
# File 'lib/chainpoint/hash.rb', line 15 def initialize(hash, proof_handles: []) @hash = hash @proof_handles = proof_handles.map do |data| ProofHandle.new(data[:uri], data[:node_hash_id]) end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash
9 10 11 |
# File 'lib/chainpoint/hash.rb', line 9 def hash @hash end |
#proof_handles ⇒ Object (readonly)
Returns the value of attribute proof_handles
9 10 11 |
# File 'lib/chainpoint/hash.rb', line 9 def proof_handles @proof_handles end |
Class Method Details
.from_data(data) ⇒ Object
11 12 13 |
# File 'lib/chainpoint/hash.rb', line 11 def self.from_data(data) new(Digest::SHA256.hexdigest(data)) end |
Instance Method Details
#proof(anchor_type = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/chainpoint/hash.rb', line 33 def proof(anchor_type = nil) return nil unless @proof_handles.any? proofs = @proof_handles.map(&:proof).compact anchor_type ? proofs.find { |p| p.anchors_complete.include?(anchor_type) } : proofs.first end |
#submit ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/chainpoint/hash.rb', line 23 def submit @proof_handles = Chainpoint.select_nodes(NUM_SERVERS).flat_map do |uri| post_hash(uri, hash)['hashes'].map do |hash| Chainpoint::ProofHandle.new(uri, hash['hash_id_node']) end end @proof_handles.map(&:to_h) end |
#to_h ⇒ Object
41 42 43 44 45 46 |
# File 'lib/chainpoint/hash.rb', line 41 def to_h { hash: @hash, proof_handles: @proof_handles.map(&:to_h) } end |