vchain_client 1.0.19 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vchain_client.rb +162 -46
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10de221cf0aacee3a81893294d59c0130a9a15a2
4
- data.tar.gz: 70d5234b7a43295a03cd48ef89d43613fd6710f9
3
+ metadata.gz: 7d0643ce1c08e5014d3a479f4651d2d5975df222
4
+ data.tar.gz: 642a3199f3b8f94fe31368f634c26da0ebc1f960
5
5
  SHA512:
6
- metadata.gz: 24db1ae389d4221c1ba41ca9fa591d8c4f4b343b210e092ac5defe17c00da6e71bf045fc63ee8a505611b2182fcef42a6364ae3bf213cf78e87f9af6726263c0
7
- data.tar.gz: a4c9c63f6dca6323f45a80738d72145cc693b9fc9467f0516246de5d5349e9961dbf3cc9a490160f2df52cec45c0aa38408575ff0a798c08dfb1984ebf32af87
6
+ metadata.gz: 4b940cde7cb711e3b4e67c64183c381caf2f3066d122c88961445d73b021fd23102689d3e22c758595423d738c785a952417c5d79bb64996c4148bc1924f36ab
7
+ data.tar.gz: 372e92c6084f56262a11ded5d8f5e737b8c64bcdaefd19144ae503026978c4b2423c76ef54a9c8ef6908410dd17d7a07b9aa4046d9140bd19fe02453ec505162
data/lib/vchain_client.rb CHANGED
@@ -34,8 +34,12 @@ module VChainClient
34
34
  end
35
35
 
36
36
  def hash(arr)
37
- arr.each { |k, v|
38
- arr[k] = Digest::SHA512.hexdigest(v.downcase)
37
+ arr.each { |k, v|
38
+ if k != "surname" && k != "given_names"
39
+ arr[k] = Digest::SHA512.hexdigest(v.downcase)
40
+ else
41
+ arr[k] = Digest::SHA512.hexdigest(v)
42
+ end
39
43
  }
40
44
  end
41
45
 
@@ -56,7 +60,7 @@ module VChainClient
56
60
  def cut(arr)
57
61
  arr.each { |k, v|
58
62
  if arr["type"] == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
59
- if k == "type" || k == "citizenship" || k == "first_name" || k == "last_name" || k == "birthdate" || k == "number" || k == "sex"
63
+ if k == "type" || k == "country_code" || k == "number" || k == "surname" || k == "given_names" || k == "birthdate" || k == "nationality" || k == "sex" || k == "birthplace" || k == "issue_date" || k == "expiry_date" || k == "authority"
60
64
  arr[k] = v
61
65
  else
62
66
  arr.delete(k)
@@ -76,13 +80,31 @@ module VChainClient
76
80
  def get_doc_hash(arr)
77
81
  if arr["type"] == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
78
82
 
79
- what_to_hash = arr["type"] + arr["citizenship"] + arr["number"] + arr["first_name"] + arr["last_name"] + arr["birthdate"] + arr["sex"]
83
+ what_to_hash = ""
84
+ what_to_hash += arr["type"] if arr.key?("type")
85
+ what_to_hash += arr["country_code"] if arr.key?("country_code")
86
+ what_to_hash += arr["number"] if arr.key?("number")
87
+ what_to_hash += arr["surname"] if arr.key?("surname")
88
+ what_to_hash += arr["given_names"] if arr.key?("given_names")
89
+ what_to_hash += arr["birthdate"] if arr.key?("birthdate")
90
+ what_to_hash += arr["nationality"] if arr.key?("nationality")
91
+ what_to_hash += arr["sex"] if arr.key?("sex")
92
+ what_to_hash += arr["birthplace"] if arr.key?("birthplace")
93
+ what_to_hash += arr["issue_date"] if arr.key?("issue_date")
94
+ what_to_hash += arr["expiry_date"] if arr.key?("expiry_date")
95
+ what_to_hash += arr["authority"] if arr.key?("authority")
80
96
 
81
97
  return Digest::SHA512.hexdigest(what_to_hash)
82
98
 
83
99
  elsif arr["type"] == FIELD_TYPE_TEST_DOCUMENT_HASHED
84
100
 
85
- what_to_hash = arr["type"] + arr["a"] + arr["b"] + arr["c"] + arr["d"] + arr["e"]
101
+ what_to_hash = ""
102
+ what_to_hash += arr["type"] if arr.key?("type")
103
+ what_to_hash += arr["a"] if arr.key?("a")
104
+ what_to_hash += arr["b"] if arr.key?("b")
105
+ what_to_hash += arr["c"] if arr.key?("c")
106
+ what_to_hash += arr["d"] if arr.key?("d")
107
+ what_to_hash += arr["e"] if arr.key?("e")
86
108
 
87
109
  return Digest::SHA512.hexdigest(what_to_hash)
88
110
 
@@ -91,7 +113,7 @@ module VChainClient
91
113
 
92
114
  def get_credentials_fields(type)
93
115
  if type == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
94
- return ["type", "citizenship", "number", "first_name", "last_name", "birthdate"]
116
+ return ["type", "number", "given_names", "surname", "birthdate"]
95
117
 
96
118
  elsif type == FIELD_TYPE_TEST_DOCUMENT_HASHED
97
119
  return ["type", "a", "b", "c"]
@@ -108,16 +130,13 @@ module VChainClient
108
130
  def get_similar_credential_sets(type)
109
131
  if type == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
110
132
  output = []
111
- output.push(["type", "last_name", "birthdate", "number", "citizenship"])
112
- output.push(["type", "first_name", "birthdate", "number", "citizenship"])
113
- output.push(["type", "first_name", "last_name", "birthdate", "number"])
114
- output.push(["type", "first_name", "last_name", "birthdate", "citizenship"])
115
- output.push(["type", "first_name", "last_name", "number", "citizenship"])
116
- output.push(["type", "last_name", "number", "citizenship"])
117
- output.push(["type", "first_name", "number", "citizenship"])
118
- output.push(["type", "birthdate", "number", "citizenship"])
119
- output.push(["type", "first_name", "last_name", "birthdate"])
120
- output.push(["type", "number", "citizenship"])
133
+ output.push(["type", "number", "surname", "birthdate"])
134
+ output.push(["type", "number", "given_names", "birthdate"])
135
+ output.push(["type", "given_names", "surname", "birthdate"])
136
+ output.push(["type", "number", "given_names", "surname"])
137
+ output.push(["type", "number", "surname"])
138
+ output.push(["type", "number", "given_names"])
139
+ output.push(["type", "number", "birthdate"])
121
140
  return output
122
141
 
123
142
  elsif type == FIELD_TYPE_TEST_DOCUMENT_HASHED
@@ -138,7 +157,7 @@ module VChainClient
138
157
 
139
158
  def get_credentials_hash(document)
140
159
  if document["type"] == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
141
- what_to_hash = document["type"] + document["citizenship"] + document["number"] + document["first_name"] + document["last_name"] + document["birthdate"]
160
+ what_to_hash = document["type"] + document["number"] + document["given_names"] + document["surname"] + document["birthdate"]
142
161
 
143
162
  return Digest::SHA512.hexdigest(what_to_hash)
144
163
 
@@ -205,9 +224,32 @@ module VChainClient
205
224
  timestamp = time.to_i
206
225
 
207
226
  document = input
227
+
228
+ # work with names before hashing
229
+ surnames_arr = document["surname"].split
230
+ given_names_arr = document["given_names"].split
231
+
232
+ hashed_surname = ""
233
+ sep = ""
234
+ surnames_arr.each { |surname_part|
235
+ hashed_surname += sep
236
+ hashed_surname += Digest::SHA512.hexdigest(surname_part.downcase)
237
+ sep = " "
238
+ }
239
+
240
+ hashed_given_names = ""
241
+ sep = ""
242
+ given_names_arr.each { |given_names_part|
243
+ hashed_given_names += sep
244
+ hashed_given_names += Digest::SHA512.hexdigest(given_names_part.downcase)
245
+ sep = " "
246
+ }
247
+
248
+ document["given_names"] = hashed_given_names
249
+ document["surname"] = hashed_surname
208
250
 
209
251
  document = self.hash(document)
210
-
252
+
211
253
  document = self.cut(document)
212
254
 
213
255
  doc_hash = self.get_doc_hash(document)
@@ -398,12 +440,25 @@ module VChainClient
398
440
 
399
441
  document = input
400
442
 
443
+ names = {}
444
+ if document["type"] == FIELD_TYPE_TRAVEL_DOCUMENT
445
+ names = document["names"]
446
+ document.delete("names")
447
+ end
448
+
401
449
  if (!is_already_hashed)
402
450
  document = self.hash(document)
403
451
  end
404
452
 
405
453
  document = self.cut(document)
406
454
 
455
+ if document["type"] == FIELD_TYPE_TRAVEL_DOCUMENT_HASHED
456
+ document["names"] = []
457
+ names.each { |name|
458
+ document["names"].push(Digest::SHA512.hexdigest(name.downcase))
459
+ }
460
+ end
461
+
407
462
  sent_document = document.clone
408
463
 
409
464
  document["client_id"] = client_id
@@ -470,18 +525,37 @@ module VChainClient
470
525
 
471
526
  # success result
472
527
 
473
- res_docs_index = {}
528
+ if sent_document.key?("names")
474
529
 
475
- res["docs"].each { |res_doc|
530
+ real_surname = ""
476
531
 
477
- res_doc_credentials_hash = self.get_credentials_hash(res_doc)
532
+ real_given_name = ""
533
+
534
+ if res.key?("names") && res["names"].is_a?(Hash)
535
+
536
+ if res["names"].key?("given_names")
537
+ sep = "";
538
+ res["names"]["given_names"].each { |found_given_name|
539
+ real_given_name += sep + found_given_name
540
+ sep = " "
541
+ }
542
+ end
543
+
544
+ if res["names"].key?("surname")
545
+ sep = "";
546
+ res["names"]["surname"].each { |found_surname|
547
+ real_surname += sep + found_surname
548
+ sep = " "
549
+ }
550
+ end
478
551
 
479
- if !res_docs_index.key?(res_doc_credentials_hash)
480
- res_docs_index[res_doc_credentials_hash] = []
481
552
  end
482
553
 
483
- res_docs_index[res_doc_credentials_hash].push(res_doc)
484
- }
554
+ sent_document["given_names"] = Digest::SHA512.hexdigest(real_given_name)
555
+ sent_document["surname"] = Digest::SHA512.hexdigest(real_surname)
556
+
557
+ sent_document.delete("names")
558
+ end
485
559
 
486
560
  validated_data_points = self.validate_data_points(res["data_points"], res["docs"])
487
561
 
@@ -504,6 +578,40 @@ module VChainClient
504
578
 
505
579
  # analyse
506
580
 
581
+ new_res_docs = []
582
+
583
+ res_docs_index = {}
584
+
585
+ # cut and index
586
+ res["docs"].each { |res_doc|
587
+
588
+ full_doc_hash = self.get_doc_hash(res_doc)
589
+
590
+ play_doc = {}
591
+ res_doc.each { |field, value|
592
+ if sent_document.key?(field)
593
+ play_doc[field] = value
594
+ end
595
+ }
596
+
597
+ res_doc_credentials_hash = self.get_credentials_hash(play_doc)
598
+
599
+ if !res_docs_index.key?(res_doc_credentials_hash)
600
+ res_docs_index[res_doc_credentials_hash] = []
601
+ end
602
+
603
+ play_doc["doc_hash"] = self.get_doc_hash(play_doc)
604
+
605
+ play_doc["full_doc_hash"] = full_doc_hash
606
+
607
+ res_docs_index[res_doc_credentials_hash].push(play_doc)
608
+
609
+ new_res_docs.push(play_doc)
610
+ }
611
+
612
+ res["docs"] = new_res_docs
613
+
614
+
507
615
  sent_doc_hash = self.get_doc_hash(sent_document)
508
616
 
509
617
  sent_credentials_hash = self.get_credentials_hash(sent_document)
@@ -566,7 +674,7 @@ module VChainClient
566
674
 
567
675
  found_docs.each { |cred_doc|
568
676
 
569
- cred_doc_hash = self.get_doc_hash(cred_doc)
677
+ cred_doc_hash = cred_doc["full_doc_hash"]#self.get_doc_hash(cred_doc)
570
678
  cred_doc_hash = Digest::SHA512.hexdigest(cred_doc_hash)
571
679
 
572
680
  cred_doc_exact_match = validated_data_points[cred_doc_hash]
@@ -613,18 +721,22 @@ module VChainClient
613
721
 
614
722
  non_cred_fields_index.each { |field, values|
615
723
 
616
- if values.length == 1
724
+ if sent_document.key?(field)
617
725
 
618
- values.take(1).each { |value, validated_count|
619
- if value == sent_document[field]
620
- result[field] = validated_count
621
- else
622
- possible_mistakes.push(field)
623
- end
624
- }
726
+ if values.length == 1
727
+
728
+ values.take(1).each { |value, validated_count|
729
+ if value == sent_document[field]
730
+ result[field] = validated_count
731
+ else
732
+ possible_mistakes.push(field)
733
+ end
734
+ }
735
+
736
+ else
737
+ possible_mistakes.push(field)
738
+ end
625
739
 
626
- else
627
- possible_mistakes.push(field)
628
740
  end
629
741
 
630
742
  }
@@ -711,18 +823,22 @@ module VChainClient
711
823
 
712
824
  other_fields_index.each { |field, values|
713
825
 
714
- if values.length == 1
826
+ if sent_document.key?(field)
715
827
 
716
- values.take(1).each { |value, validated_count|
717
- if value == sent_document[field]
718
- result[field] = validated_count
719
- else
720
- possible_mistakes.push(field)
721
- end
722
- }
828
+ if values.length == 1
829
+
830
+ values.take(1).each { |value, validated_count|
831
+ if value == sent_document[field]
832
+ result[field] = validated_count
833
+ else
834
+ possible_mistakes.push(field)
835
+ end
836
+ }
837
+
838
+ else
839
+ possible_mistakes.push(field)
840
+ end
723
841
 
724
- else
725
- possible_mistakes.push(field)
726
842
  end
727
843
 
728
844
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vchain_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Gorelik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-25 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: log4r