Class: Chainpoint
- Inherits:
-
Object
- Object
- Chainpoint
- Defined in:
- lib/chainpoint.rb,
lib/chainpoint/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
- .get_proof(hash_id_node) ⇒ Object
- .submit(hash) ⇒ Object
- .submit_data(data) ⇒ Object
- .verify(proof) ⇒ Object
Instance Method Summary collapse
- #get_proof(hash_id_node) ⇒ Object
-
#initialize(server_url = nil) ⇒ Chainpoint
constructor
A new instance of Chainpoint.
- #submit(hash) ⇒ Object
- #submit_data(data) ⇒ Object
- #verify(proof) ⇒ Object
Constructor Details
#initialize(server_url = nil) ⇒ Chainpoint
Returns a new instance of Chainpoint.
7 8 9 10 11 12 13 |
# File 'lib/chainpoint.rb', line 7 def initialize(server_url = nil) if server_url.nil? @server_url = self.class.pickup_server return end @server_url = server_url end |
Class Method Details
.get_proof(hash_id_node) ⇒ Object
40 41 42 |
# File 'lib/chainpoint.rb', line 40 def self.get_proof(hash_id_node) self.new().get_proof(hash_id_node) end |
.submit(hash) ⇒ Object
24 25 26 |
# File 'lib/chainpoint.rb', line 24 def self.submit(hash) self.new().submit(hash) end |
.submit_data(data) ⇒ Object
15 16 17 |
# File 'lib/chainpoint.rb', line 15 def self.submit_data(data) self.new().submit_data(data) end |
.verify(proof) ⇒ Object
50 51 52 |
# File 'lib/chainpoint.rb', line 50 def self.verify(proof) self.new().verify(proof) end |
Instance Method Details
#get_proof(hash_id_node) ⇒ Object
44 45 46 47 48 |
# File 'lib/chainpoint.rb', line 44 def get_proof(hash_id_node) uri = URI(@server_url + '/proofs/' + hash_id_node) r = Net::HTTP.get(uri) return JSON.parse(r) end |
#submit(hash) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chainpoint.rb', line 28 def submit(hash) uri = URI(@server_url + "/hashes") req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') req.body = {hashes: [hash]}.to_json res = Net::HTTP.start( uri.hostname, uri.port, use_ssl: uri.scheme == "https" ) do |http| http.request(req) end return JSON.parse(res.body) end |
#submit_data(data) ⇒ Object
19 20 21 22 |
# File 'lib/chainpoint.rb', line 19 def submit_data(data) hash = Digest::SHA256.digest(data).unpack('H*')[0] return submit(hash) end |
#verify(proof) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chainpoint.rb', line 54 def verify(proof) uri = URI(@server_url + "/verify") req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') req.body = {proofs: [proof]}.to_json res = Net::HTTP.start( uri.hostname, uri.port, use_ssl: uri.scheme == "https" ) do |http| http.request(req) end return JSON.parse(res.body) end |