fireblocks 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15b2538f39f6a45074861bb3d3cc4dbcf807f22e5ad7c0ee567fa6aad15602a0
4
+ data.tar.gz: 37086db0987726cf43791a51c2437511b01c1bf7e3162a872f80fac7875ec141
5
+ SHA512:
6
+ metadata.gz: ec0d20c9477cc3f3f766f1007f51b9809b5cbdd78746e81ea61a6e5a9f753d958712fb641537686230f5ca5b55b5e0b337cbfe035e7b7c4adaaae3848185ac1b
7
+ data.tar.gz: bd855581aa015124ebcf58ef4b0c2755c7fa58138e9e98f8c5cc4aa9d3493fad10d0d18b8abdf5fc944a873d49c627e57a09787eafad715203991d5f94761235
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Bryam Noguera
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.
@@ -0,0 +1,55 @@
1
+ # Fireblocks
2
+
3
+ The Ruby gem wrapper for Fireblocks! This gem is actively being developed. **Be sure to check the branch for the version you're using.**
4
+
5
+ ## Installation
6
+
7
+ To install, type:
8
+
9
+ ```
10
+ gem install fireblocks
11
+ ```
12
+
13
+ Add to your `Gemfile`:
14
+
15
+ ```ruby
16
+ gem "fireblocks", "~> 0.1.0"
17
+ ```
18
+
19
+ Run `bundle install`
20
+
21
+ ## Configure
22
+
23
+ API keys *must* be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem.
24
+
25
+ ```ruby
26
+ Fireblocks.configure do |config|
27
+ config.api_key = 'api_key'
28
+ config.private_key = 'private_key'
29
+ config.base_url = 'url'
30
+ end
31
+ ```
32
+
33
+ `config.base_url` - the default is set to `'https://api.fireblocks.io'`
34
+
35
+ ## Usage
36
+
37
+ * Full API documentation for this gem go to [API reference](https://api.fireblocks.io/docs/v1/swagger-ui/).
38
+ * Fireblocks official SDKs can be found [here](https://github.com/fireblocks)
39
+
40
+ Available methods can be found in `Fireblocks::API`
41
+
42
+ ```
43
+ # To create a vault account
44
+ Fireblocks::API.create_vault_account(name: 'test_name')
45
+
46
+ # To get all vault accounts
47
+ Fireblocks::API.get_vault_accounts
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome.
53
+
54
+ * Please be sure to include tests with your PRs.
55
+ * Run `bundle exec rubocop` to ensure style with the rest of the project
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fireblocks/version'
4
+ require 'fireblocks/configuration'
5
+ require 'fireblocks/api/api'
6
+ require 'fireblocks/api/request'
7
+ require 'fireblocks/api/token'
8
+
9
+ # Parent module for all classes
10
+ module Fireblocks
11
+ class << self
12
+ def configure
13
+ yield(configuration)
14
+ end
15
+
16
+ def configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def reset
21
+ @configuration = Configuration.new
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireblocks
4
+ # Namespace to access Fireblocks api methods
5
+ class API
6
+ class << self
7
+ def get_vault_accounts
8
+ Request.get(path: '/v1/vault/accounts')
9
+ end
10
+
11
+ def create_vault_account(name:)
12
+ Request.post(body: { name: name }, path: '/v1/vault/accounts')
13
+ end
14
+
15
+ def get_vault_account(id)
16
+ Request.get(path: "/v1/vault/accounts/#{id}")
17
+ end
18
+
19
+ def update_vault_account(vault_account_id, name:)
20
+ Request.put(
21
+ body: { name: name },
22
+ path: "/v1/vault/accounts/#{vault_account_id}"
23
+ )
24
+ end
25
+
26
+ def get_vault_account_asset(vault_account_id, asset_id)
27
+ Request.get(path: "/v1/vault/accounts/#{vault_account_id}/#{asset_id}")
28
+ end
29
+
30
+ def create_vault_account_asset(vault_account_id, asset_id)
31
+ Request.post(path: "/v1/vault/accounts/#{vault_account_id}/#{asset_id}")
32
+ end
33
+
34
+ def create_deposit_address(vault_account_id, asset_id, description:)
35
+ Request.post(
36
+ body: { description: description },
37
+ path: "/v1/vault/accounts/#{vault_account_id}/#{asset_id}/addresses"
38
+ )
39
+ end
40
+
41
+ def get_deposit_addressess(vault_account_id, asset_id)
42
+ Request.get(
43
+ path: "/v1/vault/accounts/#{vault_account_id}/#{asset_id}/addresses"
44
+ )
45
+ end
46
+
47
+ def get_internal_wallet(wallet_id)
48
+ Request.get(path: "/v1/internal_wallets/#{wallet_id}")
49
+ end
50
+
51
+ def get_internal_wallets
52
+ Request.get(path: '/v1/internal_wallets')
53
+ end
54
+
55
+ def create_internal_wallet(name:)
56
+ Request.post(body: { name: name }, path: '/v1/internal_wallets')
57
+ end
58
+
59
+ def get_supported_assets
60
+ Request.get(path: '/v1/supported_assets')
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module Fireblocks
6
+ # Interface to GET, POST, PUT
7
+ class Request
8
+ Error = Class.new(StandardError)
9
+ class << self
10
+ def get(path:, body: '')
11
+ new(path: path).get(body)
12
+ end
13
+
14
+ def put(path:, body:)
15
+ new(path: path).put(body)
16
+ end
17
+
18
+ def post(path:, body:)
19
+ new(path: path).post(body)
20
+ end
21
+ end
22
+
23
+ attr_accessor :path, :uri
24
+
25
+ def initialize(path:)
26
+ @path = path
27
+ @uri = URI("#{Fireblocks.configuration.base_url}#{path}")
28
+ end
29
+
30
+ def get(body)
31
+ req = Net::HTTP::Get.new(uri)
32
+ request_headers(body).each { |rk, rv| req[rk] = rv }
33
+
34
+ valid_response!(send_request(req))
35
+ end
36
+
37
+ def put(body)
38
+ req = Net::HTTP::Put.new(uri)
39
+ request_headers(body).each { |rk, rv| req[rk] = rv }
40
+ req.body = body.to_json
41
+
42
+ valid_response!(send_request(req))
43
+ end
44
+
45
+ def post(body)
46
+ req = Net::HTTP::Post.new(uri)
47
+ request_headers(body).each { |rk, rv| req[rk] = rv }
48
+ req.body = body.to_json
49
+
50
+ valid_response!(send_request(req))
51
+ end
52
+
53
+ private
54
+
55
+ def request_headers(body)
56
+ {
57
+ 'X-API-Key' => Fireblocks.configuration.api_key,
58
+ 'Authorization' => "Bearer #{token(body)}",
59
+ 'Content-Type' => 'application/json'
60
+ }
61
+ end
62
+
63
+ def send_request(request)
64
+ Net::HTTP.start(
65
+ uri.hostname, uri.port, use_ssl: true
66
+ ) { |http| http.request(request) }
67
+ end
68
+
69
+ def token(body)
70
+ Token.call(body, uri)
71
+ end
72
+
73
+ def valid_response!(req_response)
74
+ resp = JSON.parse(req_response.body)
75
+ return resp if req_response.message == 'OK'
76
+
77
+ raise Error, resp
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'jwt'
5
+ require 'openssl'
6
+
7
+ module Fireblocks
8
+ # This class will issue a new Fireblocks token
9
+ class Token
10
+ class << self
11
+ def call(body, uri)
12
+ new(body, uri).call
13
+ end
14
+ end
15
+
16
+ attr_accessor :body, :uri
17
+
18
+ def initialize(body, uri)
19
+ @body = body
20
+ @uri = uri
21
+ end
22
+
23
+ def created_at
24
+ Time.now.to_i
25
+ end
26
+
27
+ def expire_at
28
+ Time.now.to_i + 60
29
+ end
30
+
31
+ def call
32
+ JWT.encode jwt_headers, rsa_private, 'RS256', typ: 'JWT'
33
+ end
34
+
35
+ def body_hash
36
+ Digest::SHA256.hexdigest(body.to_json)
37
+ end
38
+
39
+ def decode_token
40
+ JWT.decode token, rsa_private.public_key, true, algorithm: 'RS256'
41
+ end
42
+
43
+ def jwt_headers
44
+ {
45
+ uri: uri.request_uri,
46
+ nonce: nonce,
47
+ iat: created_at,
48
+ exp: expire_at,
49
+ sub: Fireblocks.configuration.api_key,
50
+ bodyHash: body_hash
51
+ }
52
+ end
53
+
54
+ def nonce
55
+ Time.now.to_i * 1000
56
+ end
57
+
58
+ def rsa_private
59
+ OpenSSL::PKey::RSA.new(Fireblocks.configuration.private_key)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Global configuration settings for the gem
4
+ module Fireblocks
5
+ #
6
+ # base_url is set to a default but can be configured
7
+ #
8
+ class Configuration
9
+ Error = Class.new(StandardError)
10
+ attr_writer :api_key, :private_key
11
+ attr_accessor :base_url
12
+
13
+ def initialize
14
+ @api_key = nil
15
+ @private_key = nil
16
+ @base_url = 'https://api.fireblocks.io'
17
+ end
18
+
19
+ def api_key
20
+ message =
21
+ 'Fireblocks api key not set. See Fireblocks documentation ' \
22
+ 'to get a hold of your api key'
23
+ raise Error, message unless @api_key
24
+
25
+ @api_key
26
+ end
27
+
28
+ def private_key
29
+ message =
30
+ 'Fireblocks private key not set. See Fireblocks documentation ' \
31
+ 'to get a hold of your private key'
32
+ raise Error, message unless @private_key
33
+
34
+ @private_key
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireblocks
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class FireblocksConfiguration < Minitest::Test
6
+ describe Fireblocks::Configuration do
7
+ let(:new_base_url) { 'example.com' }
8
+
9
+ describe 'with configuration block' do
10
+ before do
11
+ # To get unique jwt headers for fast requests, add a sleep
12
+ sleep(1)
13
+
14
+ Fireblocks.configure do |config|
15
+ config.api_key = ENV['FIREBLOCKS_API_KEY']
16
+ config.private_key = ENV['FIREBLOCKS_PRIVATE_KEY']
17
+ end
18
+ end
19
+
20
+ def test_it_returns_api_key
21
+ assert_equal Fireblocks.configuration.api_key, ENV['FIREBLOCKS_API_KEY']
22
+ end
23
+
24
+ def test_it_returns_private_key
25
+ assert_equal(
26
+ Fireblocks.configuration.private_key, ENV['FIREBLOCKS_PRIVATE_KEY']
27
+ )
28
+ end
29
+
30
+ def test_it_resassigns_base_url
31
+ Fireblocks.configure { |config| config.base_url = new_base_url }
32
+ assert_equal Fireblocks.configuration.base_url, new_base_url
33
+ end
34
+ end
35
+
36
+ describe 'without configuration keys' do
37
+ before do
38
+ Fireblocks.reset
39
+ end
40
+
41
+ def test_it_raises_api_key_error
42
+ assert_raises(Fireblocks::Configuration::Error) do
43
+ Fireblocks.configuration.api_key
44
+ end
45
+ end
46
+
47
+ def test_it_raises_private_key_error
48
+ assert_raises(Fireblocks::Configuration::Error) do
49
+ Fireblocks.configuration.private_key
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class FireblocksAPI < Minitest::Test
6
+ describe Fireblocks::API do
7
+ describe 'send GET Fireblocks requests' do
8
+ let(:vault_name) { 'test_vault' }
9
+
10
+ before do
11
+ # To get unique jwt headers for fast requests, add a sleep
12
+ sleep(1)
13
+
14
+ Fireblocks.reset
15
+ Fireblocks.configure do |config|
16
+ config.api_key = ENV['FIREBLOCKS_API_KEY']
17
+ config.private_key = ENV['FIREBLOCKS_PRIVATE_KEY']
18
+ end
19
+ end
20
+
21
+ def test_create_vault_account
22
+ vault_account = Fireblocks::API.create_vault_account(name: vault_name)
23
+ assert_equal vault_account['name'], vault_name
24
+ end
25
+
26
+ def test_get_vault_accounts
27
+ Fireblocks::API.create_vault_account(name: vault_name)
28
+ sleep(1)
29
+ vault_accounts = Fireblocks::API.get_vault_accounts
30
+ refute_empty vault_accounts
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'fireblocks'
6
+ require 'pry-byebug'
7
+
8
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fireblocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryam Noguera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.56'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.56'
97
+ description:
98
+ email:
99
+ - bryamnoguera@yahoo.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/fireblocks.rb
107
+ - lib/fireblocks/api/api.rb
108
+ - lib/fireblocks/api/request.rb
109
+ - lib/fireblocks/api/token.rb
110
+ - lib/fireblocks/configuration.rb
111
+ - lib/fireblocks/version.rb
112
+ - test/fireblocks/configuration_test.rb
113
+ - test/fireblocks/fireblocks_test.rb
114
+ - test/test_helper.rb
115
+ homepage: https://github.com/csebryam/fireblocks
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.3.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 3.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Ruby wrapper for Fireblocks API
138
+ test_files:
139
+ - test/fireblocks/fireblocks_test.rb
140
+ - test/fireblocks/configuration_test.rb
141
+ - test/test_helper.rb