oydid 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/oydid/vc.rb +59 -15
  4. data/lib/oydid.rb +32 -9
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 872454b12ba811fdab1ac25967a94f2555b3a3eb5e0b9e33128f671084c1c8ba
4
- data.tar.gz: ba79bd15b747a1ff8344bb0084184bdd6f810cc4f13dde5e2abda974459d6576
3
+ metadata.gz: 171ab373123506d42a8dd20b80df654ebd3cf35ac1d53e65f36580b4a3d92374
4
+ data.tar.gz: 2bab378e7f1d284f7e730f32acb52964f7c84456ae5a41a786429d0f6ff11134
5
5
  SHA512:
6
- metadata.gz: 6f365d7a094576d29cf1dc056a6c0ac6ff869b3f7ebe26d99817f439b369f7537caef79f170d1fbe8201eb7d44b36f29f0a0028f858d5ba0bace8de10f6972f6
7
- data.tar.gz: 6e7425342af56e8bb2139138ad3162a82fc5023af0db7ba8d005abf5231e098df5d9718af1ee144ca4d8100a69c57e448dd5a4c3c20bc10127be317e1e05eff5
6
+ metadata.gz: e3d84952f40b4b7680f1c49cb351516b25b901f696f4db73222a3a5f82a645ee23da62881f24237e29cac195da2857f4392ab289ba78d29f83a14332d970ea91
7
+ data.tar.gz: 555e144d9581d897b91eadd480267c9e76bfed1145077cf524537d13cc571be3efca39512aefdb7ce798390de22fc87ea922ac6e53db3e67dfba8dfa65cedd08
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
data/lib/oydid/vc.rb CHANGED
@@ -19,7 +19,7 @@ class Oydid
19
19
  exit
20
20
  end
21
21
 
22
- private_key = options[:doc_enc].to_s rescue nil
22
+ private_key = options[:holder_privateKey].to_s rescue nil
23
23
  if private_key.to_s == ""
24
24
  msg = "missing private document key information"
25
25
  return [nil, msg]
@@ -69,29 +69,70 @@ class Oydid
69
69
  def self.create_vc(content, options)
70
70
  vercred = {}
71
71
  # set the context, which establishes the special terms used
72
- vercred["@context"] = ["https://www.w3.org/2018/credentials/v1"]
73
- vercred["type"] = ["VerifiableCredential"]
74
- vercred["issuer"] = options[:issuer]
72
+ if content["@context"].nil?
73
+ vercred["@context"] = ["https://www.w3.org/ns/credentials/v2"]
74
+ else
75
+ vercred["@context"] = content["@context"]
76
+ end
77
+ if vercred["@context"].to_s == "" || vercred["@context"].to_s == "{}" || vercred["@context"].to_s == "[]"
78
+ return [nil, "invalid '@context'"]
79
+ end
80
+ if content["type"].nil?
81
+ vercred["type"] = ["VerifiableCredential"]
82
+ else
83
+ vercred["type"] = content["type"]
84
+ end
85
+ if vercred["type"].to_s == "" || vercred["type"].to_s == "{}" || vercred["type"].to_s == "[]"
86
+ return [nil, "invalid 'type'"]
87
+ end
88
+ if content["issuer"].nil?
89
+ vercred["issuer"] = options[:issuer]
90
+ else
91
+ vercred["issuer"] = content["issuer"]
92
+ end
93
+ if vercred["issuer"].to_s == "" || vercred["issuer"].to_s == "{}" || vercred["issuer"].to_s == "[]"
94
+ return [nil, "invalid 'issuer'"]
95
+ end
75
96
  if options[:ts].nil?
76
97
  vercred["issuanceDate"] = Time.now.utc.iso8601
77
98
  else
78
99
  vercred["issuanceDate"] = Time.at(options[:ts]).utc.iso8601
79
100
  end
80
- vercred["credentialSubject"] = {"id": options[:holder]}.merge(content)
101
+ if content["credentialSubject"].nil?
102
+ vercred["credentialSubject"] = {"id": options[:holder]}.merge(content)
103
+ else
104
+ vercred["credentialSubject"] = content["credentialSubject"]
105
+ end
106
+ if vercred["credentialSubject"].to_s == "" || vercred["credentialSubject"].to_s == "{}" || vercred["credentialSubject"].to_s == "[]"
107
+ return [nil, "invalid 'credentialSubject'"]
108
+ end
109
+ if content["proof"].nil?
110
+ proof = {}
111
+ proof["type"] = "Ed25519Signature2020"
112
+ proof["verificationMethod"] = options[:issuer].to_s
113
+ proof["proofPurpose"] = "assertionMethod"
114
+ proof["proofValue"] = sign(vercred["credentialSubject"].to_json_c14n, options[:issuer_privateKey], []).first
115
+ vercred["proof"] = proof
116
+ else
117
+ vercred["proof"] = content["proof"]
118
+ end
119
+ if vercred["proof"].to_s == "" || vercred["proof"].to_s == "{}" || vercred["proof"].to_s == "[]"
120
+ return [nil, "invalid 'proof'"]
121
+ end
81
122
 
123
+ # specify the identifier of the credential
124
+ vercred["identifier"] = hash(vercred.to_json)
125
+ return [vercred, ""]
126
+ end
127
+
128
+ def self.create_vc_proof(content, options)
82
129
  proof = {}
83
130
  proof["type"] = "Ed25519Signature2020"
84
131
  proof["verificationMethod"] = options[:issuer].to_s
85
132
  proof["proofPurpose"] = "assertionMethod"
86
-
87
- # private_key = generate_private_key(options[:issuer_privateKey], "ed25519-priv", []).first
88
133
  proof["proofValue"] = sign(content.to_json_c14n, options[:issuer_privateKey], []).first
89
134
 
90
- vercred["proof"] = proof
91
-
92
- # specify the identifier of the credential
93
- vercred["identifier"] = hash(vercred.to_json)
94
- return [vercred, ""]
135
+ return [proof, ""]
95
136
  end
96
137
 
97
138
  def self.publish_vc(vc, options)
@@ -101,8 +142,11 @@ class Oydid
101
142
  return [nil, "invalid format (missing identifier"]
102
143
  exit
103
144
  end
104
-
105
- cs = vc["credentialSubject"].transform_keys(&:to_s) rescue nil
145
+ if vc["credentialSubject"].is_a?(Array)
146
+ cs = vc["credentialSubject"].last.transform_keys(&:to_s) rescue nil
147
+ else
148
+ cs = vc["credentialSubject"].transform_keys(&:to_s) rescue nil
149
+ end
106
150
  holder = cs["id"] rescue nil
107
151
  if holder.nil?
108
152
  return [nil, "invalid format (missing holder)"]
@@ -155,7 +199,7 @@ class Oydid
155
199
  def self.create_vp(content, options)
156
200
  verpres = {}
157
201
  # set the context, which establishes the special terms used
158
- verpres["@context"] = ["https://www.w3.org/2018/credentials/v1"]
202
+ verpres["@context"] = ["https://www.w3.org/ns/credentials/v2"]
159
203
  verpres["type"] = ["VerifiablePresentation"]
160
204
  verpres["verifiableCredential"] = [content].flatten
161
205
 
data/lib/oydid.rb CHANGED
@@ -201,7 +201,18 @@ class Oydid
201
201
  end
202
202
  end
203
203
  else # mode == "update" => read information
204
+ # if a location is provided this is only relevant for writing the DID
205
+ update_location = options[:location]
206
+ update_doc_location = options[:doc_location]
207
+ update_log_location = options[:log_location]
208
+ options[:location] = nil
209
+ options[:doc_location] = nil
210
+ options[:log_location] = nil
204
211
  did_info, msg = read(did, options)
212
+ options[:location] = options[:location]
213
+ options[:doc_location] = options[:doc_location]
214
+ options[:log_location] = options[:log_location]
215
+
205
216
  if did_info.nil?
206
217
  return [nil, nil, nil, "cannot resolve DID (on updating DID)"]
207
218
  end
@@ -314,6 +325,13 @@ class Oydid
314
325
  pubRevoKey = public_key(revocationKey, options).first
315
326
  did_key = publicKey + ":" + pubRevoKey
316
327
 
328
+ # check if pubKeys matches with existing DID Document
329
+ if mode == "update"
330
+ if did_key_old.to_s != did_info["doc"]["key"].to_s
331
+ return [nil, nil, nil, "keys from original DID don't match"]
332
+ end
333
+ end
334
+
317
335
  # build new revocation document
318
336
  subDid = {"doc": did_doc, "key": did_key}.to_json
319
337
  retVal = multi_hash(canonical(subDid), LOG_HASH_OPTIONS)
@@ -406,7 +424,6 @@ class Oydid
406
424
  :privateKey => privateKey,
407
425
  :revocationKey => revocationKey
408
426
  }
409
-
410
427
  return [did_doc, did_key, did_log, ""]
411
428
  # return [did, didDocument, revoc_log, l1, l2, r1, privateKey, revocationKey, did_old, log_old, ""]
412
429
  end
@@ -455,6 +472,9 @@ class Oydid
455
472
 
456
473
  def self.write(content, did, mode, options)
457
474
  did_doc, did_key, did_log, msg = generate_base(content, did, mode, options)
475
+ if msg != ""
476
+ return [nil, msg]
477
+ end
458
478
  did = did_doc[:did]
459
479
  didDocument = did_doc[:didDocument]
460
480
  did_old = did_doc[:did_old]
@@ -467,9 +487,6 @@ class Oydid
467
487
  revocationKey = did_key[:revocationKey]
468
488
  # did, didDocument, revoc_log, l1, l2, r1, privateKey, revocationKey, did_old, log_old, msg = generate_base(content, did, mode, options)
469
489
 
470
- if msg != ""
471
- return [nil, msg]
472
- end
473
490
  did_hash = did.delete_prefix("did:oyd:")
474
491
  did10 = did_hash[0,10]
475
492
  did_old_hash = did_old.delete_prefix("did:oyd:") rescue nil
@@ -776,11 +793,17 @@ class Oydid
776
793
  location = get_location(did_info["did"].to_s)
777
794
  end
778
795
  wd = wd.merge(didDoc["doc"])
779
- wdf = wd["service"].first
780
- wdf = { "id": did + "#payload",
781
- "type": "Custom",
782
- "serviceEndpoint": location }.merge(wdf)
783
- wd["service"] = [wdf] + wd["service"].drop(1)
796
+ if wd["service"] != []
797
+ if wd["service"].is_a?(Array)
798
+ wdf = wd["service"].first
799
+ else
800
+ wdf = wd["service"]
801
+ end
802
+ wdf = { "id": did + "#payload",
803
+ "type": "Custom",
804
+ "serviceEndpoint": location }.merge(wdf)
805
+ wd["service"] = [wdf] + wd["service"].drop(1)
806
+ end
784
807
  else
785
808
  payload = nil
786
809
  if didDoc["doc"].is_a?(Hash)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oydid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Fabianek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dag