class Chainpoint::Hash
Constants
- NUM_SERVERS
Attributes
hash[R]
proof_handles[R]
Public Class Methods
from_data(data)
click to toggle source
# File lib/chainpoint/hash.rb, line 11 def self.from_data(data) new(Digest::SHA256.hexdigest(data)) end
new(hash, proof_handles: [])
click to toggle source
# File lib/chainpoint/hash.rb, line 15 def initialize(hash, proof_handles: []) @hash = hash self.proof_handles = proof_handles end
Public Instance Methods
proof(anchor_type = nil)
click to toggle source
# File lib/chainpoint/hash.rb, line 30 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
proof_handles=(handles)
click to toggle source
# File lib/chainpoint/hash.rb, line 38 def proof_handles=(handles) @proof_handles = handles.map do |data| data.transform_keys!(&:to_sym) ProofHandle.new(data[:uri], data[:node_hash_id]) end end
submit()
click to toggle source
# File lib/chainpoint/hash.rb, line 20 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()
click to toggle source
# File lib/chainpoint/hash.rb, line 45 def to_h { hash: @hash, proof_handles: @proof_handles.map(&:to_h) } end
Private Instance Methods
post_hash(uri, hash)
click to toggle source
# File lib/chainpoint/hash.rb, line 54 def post_hash(uri, hash) uri = URI(uri + '/hashes') request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') request.body = { hashes: [hash] }.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end JSON.parse(response.body) end