credify 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/credify.gemspec +29 -0
- data/lib/credify.rb +6 -0
- data/lib/credify/encryption.rb +169 -0
- data/lib/credify/signing.rb +77 -0
- data/lib/credify/version.rb +3 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2d00a170decb583685246f229dced080b4eb29399773680f0e8599ee8873af7
|
4
|
+
data.tar.gz: 12d6f970b75bd07c67cfa444e2c8ae7e7a2a5c70ed014cb52b375fb81a21cf20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a7b1682b30baffd0ef0c413ae6b26e9a24203323da32be9e59fc63f8a37c25c95b2dbc9ce4423ff9fb917429431693680d47a70275e9c12cb2cea41e70be470
|
7
|
+
data.tar.gz: '058461c70f4d213b42216407bd996237cfe207883e732bfb19d1cd1dd7b53bc35efc081c439312491c0e2780ea52277cace79e42a61e0c697546890baa77a0c5'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ngo38114@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
credify (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
ed25519 (1.2.4)
|
11
|
+
openssl-oaep (0.1.0)
|
12
|
+
openssl_pkcs8_pure (0.0.0.2)
|
13
|
+
rake (12.3.3)
|
14
|
+
rspec (3.10.0)
|
15
|
+
rspec-core (~> 3.10.0)
|
16
|
+
rspec-expectations (~> 3.10.0)
|
17
|
+
rspec-mocks (~> 3.10.0)
|
18
|
+
rspec-core (3.10.1)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-expectations (3.10.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-mocks (3.10.2)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-support (3.10.2)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
credify!
|
33
|
+
ed25519
|
34
|
+
openssl-oaep
|
35
|
+
openssl_pkcs8_pure
|
36
|
+
rake (~> 12.0)
|
37
|
+
rspec (~> 3.0)
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 ngo275
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Credify
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'credify'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install credify
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Signing
|
22
|
+
|
23
|
+
Signing is using EdDSA (curve: Ed25519). The key size is 32 bytes. This SDK uses 32 byte length seed data for importing an existing key.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'credify'
|
27
|
+
|
28
|
+
def new_key_is_generated
|
29
|
+
signing = Signing.new
|
30
|
+
signing.generate_key_pair
|
31
|
+
signature = signing.sign "message"
|
32
|
+
valid = signing.verify "message", signature
|
33
|
+
puts valid
|
34
|
+
end
|
35
|
+
|
36
|
+
def existing_key_is_used
|
37
|
+
signing = Signing.new
|
38
|
+
signing.import_seed "UseZb/HIOiqrYSLqVmMdbiILuLTdiGRA3hZ3QwiEiBU="
|
39
|
+
signature = signing.sign "message"
|
40
|
+
valid = signing.verify "message", signature
|
41
|
+
puts valid
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Encryption
|
46
|
+
|
47
|
+
Encryption is using RSA 4096 bit with OAEP padding. This SDK allows developers to use PKCS8 to deal with keys.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'credify'
|
51
|
+
|
52
|
+
def new_key_is_generated
|
53
|
+
encryption = Encryption.new
|
54
|
+
encryption.generate_key_pair
|
55
|
+
cipher_text = encryption.encrypt "secret message"
|
56
|
+
plain_text = encryption.decrypt cipher_text
|
57
|
+
end
|
58
|
+
|
59
|
+
def existing_key_is_used
|
60
|
+
encryption = Encryption.new
|
61
|
+
encryption.import_private_key "-----BEGIN PRIVATE KEY-----\nMI....."
|
62
|
+
cipher_text = encryption.encrypt "secret message"
|
63
|
+
plain_text = encryption.decrypt cipher_text
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
77
|
+
|
78
|
+
## Code of Conduct
|
79
|
+
|
80
|
+
Everyone interacting in the Credify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/credify/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "credify"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/credify.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/credify/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "credify"
|
5
|
+
spec.version = Credify::VERSION
|
6
|
+
spec.authors = ["credify-pte-ltd"]
|
7
|
+
spec.email = ["dev@credify.one"]
|
8
|
+
|
9
|
+
spec.summary = %q{Credify SDK for Ruby}
|
10
|
+
spec.description = %q{This is a Ruby SDK to integrate with Credify system.}
|
11
|
+
spec.homepage = "https://credify.one"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/credify-pte-ltd/CredifyRuby.git"
|
19
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
data/lib/credify.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'openssl/oaep'
|
3
|
+
require "base64"
|
4
|
+
require 'openssl_pkcs8_pure'
|
5
|
+
|
6
|
+
class Encryption
|
7
|
+
attr_reader :private_key, :public_key
|
8
|
+
|
9
|
+
#
|
10
|
+
# generate_key_pair
|
11
|
+
# @return [Boolean]
|
12
|
+
def generate_key_pair
|
13
|
+
key = OpenSSL::PKey::RSA.generate(4096, 17)
|
14
|
+
@private_key = key
|
15
|
+
@public_key = key.public_key
|
16
|
+
@private_key.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# import_private_key
|
21
|
+
# @param [String] pem
|
22
|
+
# @return [Boolean]
|
23
|
+
def import_private_key(pem)
|
24
|
+
key = OpenSSL::PKey::RSA.new pem
|
25
|
+
@private_key = key
|
26
|
+
@public_key = key.public_key
|
27
|
+
@private_key.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# import_public_key
|
32
|
+
# @param [String] pem
|
33
|
+
# @return [Boolean]
|
34
|
+
def import_public_key(pem)
|
35
|
+
key = OpenSSL::PKey::RSA.new pem
|
36
|
+
# @private_key = key
|
37
|
+
@public_key = key.public_key
|
38
|
+
@public_key.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# import_private_key_base64_url
|
43
|
+
# @param [String] payload - Base64 URL encoded string
|
44
|
+
# @return [Boolean]
|
45
|
+
def import_private_key_base64_url(payload)
|
46
|
+
bytes = short_urlsafe_decode64(payload)
|
47
|
+
base64 = Base64.encode64(bytes)
|
48
|
+
formatted = base64.scan(/.{1,64}/).join("\n")
|
49
|
+
pem = add_box('PRIVATE KEY', formatted)
|
50
|
+
import_private_key(pem)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# import_public_key_base64_url
|
55
|
+
# @param [String] payload - Base64 URL encoded string
|
56
|
+
# @return [Boolean]
|
57
|
+
def import_public_key_base64_url(payload)
|
58
|
+
bytes = short_urlsafe_decode64(payload)
|
59
|
+
base64 = Base64.encode64(bytes)
|
60
|
+
formatted = base64.scan(/.{1,64}/).join("\n")
|
61
|
+
pem = add_box('PUBLIC KEY', formatted)
|
62
|
+
import_public_key(pem)
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# encrypt
|
67
|
+
# @param [String] message
|
68
|
+
# @return [String] Base64 URL encoded string after encryption
|
69
|
+
def encrypt(message)
|
70
|
+
if @public_key.nil?
|
71
|
+
raise Exception.new 'Please pass public key'
|
72
|
+
end
|
73
|
+
label = ''
|
74
|
+
md = OpenSSL::Digest::SHA256
|
75
|
+
cipher_text = @public_key.public_encrypt_oaep(message, label, md)
|
76
|
+
short_urlsafe_encode64(cipher_text)
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# decrypt
|
81
|
+
# @param [String] cipher - Base64 URL encoded cipher text
|
82
|
+
# @return [String] Plain text
|
83
|
+
def decrypt(cipher)
|
84
|
+
if @private_key.nil?
|
85
|
+
raise Exception.new 'Please pass private key'
|
86
|
+
end
|
87
|
+
label = ''
|
88
|
+
md = OpenSSL::Digest::SHA256
|
89
|
+
raw_cipher = short_urlsafe_decode64(cipher)
|
90
|
+
raw_text = @private_key.private_decrypt_oaep(raw_cipher, label, md)
|
91
|
+
raw_text
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# export_private_key
|
96
|
+
# @param [Boolean] in_base64_url
|
97
|
+
# @return [Signing] - PCKS8 PEM or Base64 URL encoded string
|
98
|
+
def export_private_key(in_base64_url = false)
|
99
|
+
if @private_key.nil?
|
100
|
+
raise Exception.new 'Please pass private key'
|
101
|
+
end
|
102
|
+
pem = @private_key.to_pem_pkcs8.gsub(/#{$/}$/, "")
|
103
|
+
|
104
|
+
if in_base64_url
|
105
|
+
formatted = remove_box('PRIVATE KEY', pem)
|
106
|
+
short_urlsafe_encode64(Base64.decode64(formatted))
|
107
|
+
else
|
108
|
+
pem
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# export_public_key
|
114
|
+
# @param [Boolean] in_base64_url
|
115
|
+
# @return [Signing] - PCKS8 PEM or Base64 URL encoded string
|
116
|
+
def export_public_key(in_base64_url = false)
|
117
|
+
if @public_key.nil?
|
118
|
+
raise Exception.new 'Please pass public key'
|
119
|
+
end
|
120
|
+
|
121
|
+
pem = @public_key.to_pem_pkcs8.gsub(/#{$/}$/, "")
|
122
|
+
|
123
|
+
if in_base64_url
|
124
|
+
formatted = remove_box('PUBLIC KEY', pem)
|
125
|
+
short_urlsafe_encode64(Base64.decode64(formatted))
|
126
|
+
else
|
127
|
+
pem
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
protected
|
133
|
+
|
134
|
+
|
135
|
+
# remove_box
|
136
|
+
# @param [String] tag - Either 'PUBLIC KEY' or 'PRIVATE KEY'
|
137
|
+
# @param [String] pem - String value loaded from a PEM file
|
138
|
+
# @return [String] - Base64 encoded string in PEM file
|
139
|
+
def remove_box(tag, pem)
|
140
|
+
tmp = pem.gsub("-----BEGIN #{tag}-----", '')
|
141
|
+
tmp = tmp.gsub("-----END #{tag}-----", '')
|
142
|
+
tmp.gsub(/\n/, '')
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# add_box
|
147
|
+
# @param [String] tag - Either 'PUBLIC KEY' or 'PRIVATE KEY'
|
148
|
+
# @param [String] base64 - Base64 encoded string
|
149
|
+
# @return [String] - PEM
|
150
|
+
def add_box(tag, base64)
|
151
|
+
payload = base64.scan(/.{1,64}/).join("\n")
|
152
|
+
"-----BEGIN #{tag}-----\n" << payload << "\n-----END #{tag}-----"
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# short_urlsafe_encode64
|
157
|
+
# @param [Binary] - str
|
158
|
+
# @return [String] - Base64 URL encoded string without padding
|
159
|
+
def short_urlsafe_encode64(bytes)
|
160
|
+
Base64.urlsafe_encode64(bytes).delete('=')
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# short_urlsafe_decode64
|
165
|
+
# @return [Binary]
|
166
|
+
def short_urlsafe_decode64(str)
|
167
|
+
Base64.urlsafe_decode64(str + '=' * (-1 * str.size & 3))
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "ed25519"
|
2
|
+
require "base64"
|
3
|
+
require 'openssl_pkcs8_pure'
|
4
|
+
|
5
|
+
class Signing
|
6
|
+
attr_reader :signing_key
|
7
|
+
|
8
|
+
#
|
9
|
+
# generate_key_pair
|
10
|
+
# @return [Boolean]
|
11
|
+
def generate_key_pair
|
12
|
+
@signing_key = Ed25519::SigningKey.generate
|
13
|
+
@signing_key.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# import_seed
|
18
|
+
# @param [String] seed - Base64 encoded 32 byte seed data
|
19
|
+
# @return [Boolean]
|
20
|
+
def import_seed(seed)
|
21
|
+
@signing_key = Ed25519::SigningKey.new(Base64.decode64(seed))
|
22
|
+
@signing_key.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# sign
|
27
|
+
# @param [String] message - String value you want to sign
|
28
|
+
# @return [String] - Base64 URL encoded signature
|
29
|
+
def sign(message)
|
30
|
+
if @signing_key.nil?
|
31
|
+
raise Exception.new 'Please pass signing key'
|
32
|
+
end
|
33
|
+
signature = @signing_key.sign(message)
|
34
|
+
short_urlsafe_encode64(signature)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# verify
|
39
|
+
# @param [String] signature - Base64 URL encoded signature
|
40
|
+
# @param [String] message - Plain text to be signed
|
41
|
+
# @return [Boolean]
|
42
|
+
def verify(signature, message)
|
43
|
+
if @signing_key.nil?
|
44
|
+
raise Exception.new 'Please pass signing key'
|
45
|
+
end
|
46
|
+
raw_sign = short_urlsafe_decode64(signature)
|
47
|
+
@signing_key.verify_key.verify raw_sign, message
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# export_seed
|
52
|
+
# @return [String] - Base64 encoded 32 bytes seed data
|
53
|
+
def export_seed
|
54
|
+
if @signing_key.nil?
|
55
|
+
raise Exception.new 'Please pass signing key'
|
56
|
+
end
|
57
|
+
Base64.encode64(@signing_key.seed)
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
#
|
63
|
+
# short_urlsafe_encode64
|
64
|
+
# @param [Binary] - str
|
65
|
+
# @return [String] - Base64 URL encoded string without padding
|
66
|
+
def short_urlsafe_encode64(bytes)
|
67
|
+
Base64.urlsafe_encode64(bytes).delete('=')
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# short_urlsafe_decode64
|
72
|
+
# @return [Binary]
|
73
|
+
def short_urlsafe_decode64(str)
|
74
|
+
Base64.urlsafe_decode64(str + '=' * (-1 * str.size & 3))
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: credify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- credify-pte-ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a Ruby SDK to integrate with Credify system.
|
14
|
+
email:
|
15
|
+
- dev@credify.one
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- credify.gemspec
|
32
|
+
- lib/credify.rb
|
33
|
+
- lib/credify/encryption.rb
|
34
|
+
- lib/credify/signing.rb
|
35
|
+
- lib/credify/version.rb
|
36
|
+
homepage: https://credify.one
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://credify.one
|
41
|
+
source_code_uri: https://github.com/credify-pte-ltd/CredifyRuby.git
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.3.0
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Credify SDK for Ruby
|
61
|
+
test_files: []
|