oydid 0.4.0 → 0.4.1

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/didcomm.rb +50 -0
  4. data/lib/oydid.rb +2 -0
  5. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e715e178b3d9ea7da5fe0a47421740fec4b6e22f8e3355c9fb7e43a704c6b56
4
- data.tar.gz: 8ba62acc964c24e22411a4e5e5287df54bdda9b1566f98c91a760d5853a3b826
3
+ metadata.gz: '080c68f559573f4402ed202c539848c9bdc72e173697061b8e8005c06b64d06b'
4
+ data.tar.gz: 5614b9dc152ff70f3f1e951f0db39a41a46dddaa17aa4088652e1d3c17cd8115
5
5
  SHA512:
6
- metadata.gz: d656097d2b8ab1d9d9b19788cdf5051e397c13580de470cbce0d9f0c917dc5a2a9a3ec8c7eb7cfaf8b3ef8755f37275f0fee39ad27d7e87fcba16fc2bd9dea59
7
- data.tar.gz: cb6ecf4797e57f43c15c401068966688be5fa1f84d8947f2fb5b65b75c96394b7d471cb5c2357f65f6734d0cb6e54f1ea1ded76a4bfa7eb4b2c251e98ba85898
6
+ metadata.gz: 7d594168b9e609882afff27e8b92e9740acb5500a328ecf9599a3c8ee848a4917921744117810263957585f6f3b8d742c5a00362d516b871ffe3f2dd73d4f494
7
+ data.tar.gz: '0571905fda5580900ecaea886909e951da2fe1636cb001e8984f95837733a4ce453aaae928525cf6521e8c50b9428afc7941aed1bd02855fd20e3a61e16d10d8'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ class Oydid
5
+
6
+ # DIDComm Plain Message ---------------------
7
+ def self.dcpm(payload, options)
8
+ dcDoc = {}
9
+ dcDoc["id"] = SecureRandom.random_number(10e14).to_i
10
+ dcDoc["type"] = options[:didcomm_type]
11
+ if !options[:didcomm_from_did].nil?
12
+ dcDoc["from"] = options[:didcomm_from_did]
13
+ end
14
+ dcDoc["to"] = [options[:didcomm_to_did]]
15
+ dcDoc["created_time"] = Time.now.utc.to_i
16
+ dcDoc["body"] = payload
17
+ return [dcDoc, ""]
18
+
19
+ end
20
+
21
+ # signing -----------------------------------
22
+ def self.msg_encrypt(payload, private_key_encoded)
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'
29
+ else
30
+ token = nil
31
+ error = "unsupported key codec"
32
+ end
33
+ return [token, error]
34
+ end
35
+
36
+ def self.msg_decrypt(token, public_key_encoded)
37
+ error = ""
38
+ code, length, digest = Oydid.decode(public_key_encoded).unpack('CCa*')
39
+ case Multicodecs[code].name
40
+ when 'ed25519-pub'
41
+ public_key = RbNaCl::Signatures::Ed25519::VerifyKey.new(digest)
42
+ payload = JWT.decode token.to_s, public_key, true, { algorithm: 'ED25519' }
43
+ else
44
+ payload = nil
45
+ error = "unsupported key codec"
46
+ end
47
+ return [payload, error]
48
+ end
49
+
50
+ end
data/lib/oydid.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'dag'
5
+ require 'jwt'
5
6
  require 'rbnacl'
6
7
  require 'ed25519'
7
8
  require 'httparty'
@@ -11,6 +12,7 @@ require 'multicodecs'
11
12
  require 'json/canonicalization'
12
13
  require 'oydid/basic'
13
14
  require 'oydid/log'
15
+ require 'oydid/didcomm'
14
16
 
15
17
  class Oydid
16
18
 
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.0
4
+ version: 0.4.1
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-13 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dag
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.4.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rbnacl
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +162,7 @@ files:
148
162
  - VERSION
149
163
  - lib/oydid.rb
150
164
  - lib/oydid/basic.rb
165
+ - lib/oydid/didcomm.rb
151
166
  - lib/oydid/log.rb
152
167
  - spec/input/basic/arrays.json
153
168
  - spec/input/basic/french.json