oydid 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '080c68f559573f4402ed202c539848c9bdc72e173697061b8e8005c06b64d06b'
4
- data.tar.gz: 5614b9dc152ff70f3f1e951f0db39a41a46dddaa17aa4088652e1d3c17cd8115
3
+ metadata.gz: 20d91a8c36a05670346244339ea68ec0288c1550994a421e51d4eeb4c6906234
4
+ data.tar.gz: 32722af4d3ab83842ad7cc3428834bccecdf0a987c3cb5c86683c7b5208fabe8
5
5
  SHA512:
6
- metadata.gz: 7d594168b9e609882afff27e8b92e9740acb5500a328ecf9599a3c8ee848a4917921744117810263957585f6f3b8d742c5a00362d516b871ffe3f2dd73d4f494
7
- data.tar.gz: '0571905fda5580900ecaea886909e951da2fe1636cb001e8984f95837733a4ce453aaae928525cf6521e8c50b9428afc7941aed1bd02855fd20e3a61e16d10d8'
6
+ metadata.gz: 965132e50470d2423fce55a6f9cef44c34747585c3a46646f4ed1d546f9acfb25058bfe1cff3dcef1cd151e7ed40964f4f5f5cb55943872534c55610fc90ed1f
7
+ data.tar.gz: 06e4978da7ae725b69ae07e95fd92638b966c4ae3a111d5a18202739ba4bb0a9496c85f3cd4aae76041958f321d8a3337f94a5774d3df3600287677338442f76
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.3
data/lib/oydid/didcomm.rb CHANGED
@@ -18,8 +18,45 @@ class Oydid
18
18
 
19
19
  end
20
20
 
21
- # signing -----------------------------------
22
- def self.msg_encrypt(payload, private_key_encoded)
21
+ # DIDComm Signed Message --------------------
22
+ def self.dcsm(payload, private_key_encoded, options)
23
+ error = ""
24
+ code, length, digest = decode(private_key_encoded).unpack('SCa*')
25
+ case Multicodecs[code].name
26
+ when 'ed25519-priv'
27
+ private_key = RbNaCl::Signatures::Ed25519::SigningKey.new(digest)
28
+ token = JWT.encode payload, private_key, 'ED25519', { typ: 'JWM', kid: options[:sign_did].to_s, alg: 'ED25519' }
29
+ else
30
+ token = nil
31
+ error = "unsupported key codec"
32
+ end
33
+ return [token, error]
34
+ end
35
+
36
+ def self.dcsm_verify(token, options)
37
+ error = ""
38
+ decoded_payload = JWT.decode token, nil, false
39
+ pubkey_did = decoded_payload.last["kid"]
40
+ result, msg = Oydid.read(pubkey_did, options)
41
+ public_key_encoded = Oydid.w3c(result, options)["authentication"].first["publicKeyMultibase"]
42
+ begin
43
+ code, length, digest = Oydid.decode(public_key_encoded).unpack('CCa*')
44
+ case Multicodecs[code].name
45
+ when 'ed25519-pub'
46
+ public_key = RbNaCl::Signatures::Ed25519::VerifyKey.new(digest)
47
+ payload = JWT.decode token.to_s, public_key, true, { algorithm: 'ED25519' }
48
+ else
49
+ payload = nil
50
+ error = "unsupported key codec"
51
+ end
52
+ return [payload, error]
53
+ rescue
54
+ return [nil, "verification failed"]
55
+ end
56
+ end
57
+
58
+ # encryption -----------------------------------
59
+ def self.msg_encrypt(payload, private_key_encoded, did)
23
60
  error = ""
24
61
  code, length, digest = decode(private_key_encoded).unpack('SCa*')
25
62
  case Multicodecs[code].name
@@ -47,4 +84,18 @@ class Oydid
47
84
  return [payload, error]
48
85
  end
49
86
 
87
+ # signing for JWS ---------------------------
88
+ def self.msg_sign(payload, hmac_secret)
89
+ token = JWT.encode payload, hmac_secret, 'HS256'
90
+ return [token, ""]
91
+ end
92
+
93
+ def self.msg_verify_jws(token, hmac_secret)
94
+ begin
95
+ decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS256' }
96
+ return [decoded_token, ""]
97
+ rescue
98
+ return [nil, "verification failed"]
99
+ end
100
+ end
50
101
  end
data/lib/oydid/log.rb CHANGED
@@ -152,20 +152,23 @@ class Oydid
152
152
 
153
153
  def self.dag_update(currentDID, options)
154
154
  i = 0
155
- initial_did = currentDID["did"].to_s
155
+ doc_location = ""
156
+ initial_did = currentDID["did"].to_s.dup
156
157
  initial_did = initial_did.delete_prefix("did:oyd:")
157
- initial_did = initial_did.split("@").first
158
+ if initial_did.include?(LOCATION_PREFIX)
159
+ tmp = initial_did.split(LOCATION_PREFIX)
160
+ initial_did = tmp[0]
161
+ doc_location = tmp[1]
162
+ end
158
163
  current_public_doc_key = ""
159
164
  verification_output = false
160
165
  currentDID["log"].each do |el|
161
166
  case el["op"]
162
167
  when 2,3 # CREATE, UPDATE
163
168
  currentDID["doc_log_id"] = i
164
-
165
169
  doc_did = el["doc"]
166
- doc_location = get_location(doc_did)
167
170
  did_hash = doc_did.delete_prefix("did:oyd:")
168
- did_hash = did_hash.split("@").first
171
+ did_hash = did_hash.split(LOCATION_PREFIX).first
169
172
  did10 = did_hash[0,10]
170
173
  doc = retrieve_document_raw(doc_did, did10 + ".doc", doc_location, {})
171
174
  if doc.first.nil?
@@ -217,9 +220,8 @@ class Oydid
217
220
  currentDID["termination_log_id"] = i
218
221
 
219
222
  doc_did = currentDID["did"]
220
- doc_location = get_location(doc_did)
221
223
  did_hash = doc_did.delete_prefix("did:oyd:")
222
- did_hash = did_hash.split("@").first
224
+ did_hash = did_hash.split(LOCATION_PREFIX).first
223
225
  did10 = did_hash[0,10]
224
226
  doc = retrieve_document_raw(doc_did, did10 + ".doc", doc_location, {})
225
227
  # since it retrieves a DID that previously existed, this test is not necessary
@@ -230,11 +232,11 @@ class Oydid
230
232
  # end
231
233
  doc = doc.first["doc"]
232
234
  term = doc["log"]
233
- log_location = term.split("@")[1] rescue ""
235
+ log_location = term.split(LOCATION_PREFIX)[1] rescue ""
234
236
  if log_location.to_s == ""
235
237
  log_location = DEFAULT_LOCATION
236
238
  end
237
- term = term.split("@").first
239
+ term = term.split(LOCATION_PREFIX).first
238
240
  if hash(canonical(el)) != term
239
241
  currentDID["error"] = 1
240
242
  currentDID["message"] = "Log reference and record don't match"
@@ -256,7 +258,7 @@ class Oydid
256
258
  # check if there is a revocation entry
257
259
  revocation_record = {}
258
260
  revoc_term = el["doc"]
259
- revoc_term = revoc_term.split("@").first
261
+ revoc_term = revoc_term.split(LOCATION_PREFIX).first
260
262
  revoc_term_found = false
261
263
  log_array, msg = retrieve_log(did_hash, did10 + ".log", log_location, options)
262
264
  log_array.each do |log_el|
@@ -321,9 +323,9 @@ class Oydid
321
323
  currentDID["verification"] += "of next DID Document (Details: https://ownyourdata.github.io/oydid/#verify_signature)" + "\n"
322
324
 
323
325
  next_doc_did = log_el["doc"].to_s
324
- next_doc_location = get_location(next_doc_did)
326
+ next_doc_location = doc_location
325
327
  next_did_hash = next_doc_did.delete_prefix("did:oyd:")
326
- next_did_hash = next_did_hash.split("@").first
328
+ next_did_hash = next_did_hash.split(LOCATION_PREFIX).first
327
329
  next_did10 = next_did_hash[0,10]
328
330
  next_doc = retrieve_document_raw(next_doc_did, next_did10 + ".doc", next_doc_location, {})
329
331
  if next_doc.first.nil?
@@ -342,9 +344,9 @@ class Oydid
342
344
  currentDID["message"] = "Signature does not match"
343
345
  if verification_output
344
346
  new_doc_did = log_el["doc"].to_s
345
- new_doc_location = get_location(new_doc_did)
347
+ new_doc_location = doc_location
346
348
  new_did_hash = new_doc_did.delete_prefix("did:oyd:")
347
- new_did_hash = new_did_hash.split("@").first
349
+ new_did_hash = new_did_hash.split(LOCATION_PREFIX).first
348
350
  new_did10 = new_did_hash[0,10]
349
351
  new_doc = retrieve_document(new_doc_did, new_did10 + ".doc", new_doc_location, {}).first
350
352
  currentDID["verification"] += "found UPDATE log record:" + "\n"
data/lib/oydid.rb CHANGED
@@ -149,7 +149,7 @@ class Oydid
149
149
  log_old = nil
150
150
  prev_hash = []
151
151
  revoc_log = nil
152
- doc_location = options[:doc_location]
152
+ doc_location = options[:location]
153
153
  if options[:ts].nil?
154
154
  ts = Time.now.to_i
155
155
  else
@@ -672,14 +672,13 @@ class Oydid
672
672
  wd = {}
673
673
  wd["@context"] = "https://www.w3.org/ns/did/v1"
674
674
  wd["id"] = did
675
- wd["assertionMethod"] = [{
676
- "id": did,
675
+ wd["verificationMethod"] = [{
676
+ "id": did + "#key-doc",
677
677
  "type": "Ed25519VerificationKey2020",
678
678
  "controller": did,
679
679
  "publicKeyMultibase": pubDocKey
680
- }]
681
- wd["keyAgreement"] = [{
682
- "id": did,
680
+ },{
681
+ "id": did + "#key-rev",
683
682
  "type": "Ed25519VerificationKey2020",
684
683
  "controller": did,
685
684
  "publicKeyMultibase": pubRevKey
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.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Fabianek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-14 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dag