Class: Chainpoint::Proof

Inherits:
Object
  • Object
show all
Defined in:
lib/chainpoint/proof.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proof, hash_id_node = nil, anchors_complete = []) ⇒ Proof

Returns a new instance of Proof



11
12
13
14
15
# File 'lib/chainpoint/proof.rb', line 11

def initialize(proof, hash_id_node = nil, anchors_complete = [])
  @proof = proof
  @hash_id_node = hash_id_node
  @anchors_complete = anchors_complete
end

Instance Attribute Details

#anchors_completeObject (readonly)

Returns the value of attribute anchors_complete



9
10
11
# File 'lib/chainpoint/proof.rb', line 9

def anchors_complete
  @anchors_complete
end

#hash_id_nodeObject (readonly)

Returns the value of attribute hash_id_node



9
10
11
# File 'lib/chainpoint/proof.rb', line 9

def hash_id_node
  @hash_id_node
end

#proofObject (readonly)

Returns the value of attribute proof



9
10
11
# File 'lib/chainpoint/proof.rb', line 9

def proof
  @proof
end

Instance Method Details

#decodeObject



17
18
19
20
21
22
23
# File 'lib/chainpoint/proof.rb', line 17

def decode
  MessagePack.unpack(
    Zlib::Inflate.inflate(
      Base64.decode64(@proof)
    )
  )
end

#verifyObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/chainpoint/proof.rb', line 25

def verify
  uri = URI(Chainpoint.select_nodes(1).first + '/verify')
  request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
  request.body = { proofs: [@proof] }.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).first
end