didww-v3 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +5 -1
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +20 -2
  5. data/Gemfile +1 -0
  6. data/README.md +5 -1
  7. data/Rakefile +1 -0
  8. data/bin/console +1 -0
  9. data/didww-v3.gemspec +3 -1
  10. data/lib/didww/{middleware.rb → base_middleware.rb} +5 -4
  11. data/lib/didww/callback/request_validator.rb +68 -0
  12. data/lib/didww/client.rb +61 -13
  13. data/lib/didww/complex_objects/base.rb +1 -0
  14. data/lib/didww/complex_objects/capacity_order_item.rb +1 -0
  15. data/lib/didww/complex_objects/cdr_export_filter.rb +1 -0
  16. data/lib/didww/complex_objects/configurations/base.rb +1 -0
  17. data/lib/didww/complex_objects/configurations/const.rb +1 -0
  18. data/lib/didww/complex_objects/configurations/h323_configuration.rb +1 -0
  19. data/lib/didww/complex_objects/configurations/iax2_configuration.rb +1 -0
  20. data/lib/didww/complex_objects/configurations/pstn_configuration.rb +1 -0
  21. data/lib/didww/complex_objects/configurations/sip_configuration.rb +1 -0
  22. data/lib/didww/complex_objects/configurations.rb +1 -0
  23. data/lib/didww/complex_objects/did_order_item.rb +14 -12
  24. data/lib/didww/encrypt.rb +101 -0
  25. data/lib/didww/jsonapi_middleware.rb +21 -0
  26. data/lib/didww/resources/address.rb +37 -0
  27. data/lib/didww/resources/address_verification.rb +56 -0
  28. data/lib/didww/resources/area.rb +12 -0
  29. data/lib/didww/resources/available_did.rb +1 -0
  30. data/lib/didww/resources/balance.rb +1 -0
  31. data/lib/didww/resources/base.rb +2 -1
  32. data/lib/didww/resources/capacity_pool.rb +1 -0
  33. data/lib/didww/resources/cdr_export.rb +12 -1
  34. data/lib/didww/resources/city.rb +5 -0
  35. data/lib/didww/resources/country.rb +1 -0
  36. data/lib/didww/resources/did.rb +3 -1
  37. data/lib/didww/resources/did_group.rb +1 -4
  38. data/lib/didww/resources/did_group_type.rb +1 -0
  39. data/lib/didww/resources/did_reservation.rb +1 -0
  40. data/lib/didww/resources/encrypted_file.rb +58 -0
  41. data/lib/didww/resources/identity.rb +78 -0
  42. data/lib/didww/resources/order.rb +9 -0
  43. data/lib/didww/resources/permanent_supporting_document.rb +15 -0
  44. data/lib/didww/resources/pop.rb +1 -0
  45. data/lib/didww/resources/proof.rb +19 -0
  46. data/lib/didww/resources/proof_type.rb +14 -0
  47. data/lib/didww/resources/public_key.rb +12 -0
  48. data/lib/didww/resources/qty_based_pricing.rb +1 -0
  49. data/lib/didww/resources/region.rb +1 -0
  50. data/lib/didww/resources/requirement.rb +61 -0
  51. data/lib/didww/resources/requirement_validation.rb +10 -0
  52. data/lib/didww/resources/shared_capacity_group.rb +1 -0
  53. data/lib/didww/resources/stock_keeping_unit.rb +1 -0
  54. data/lib/didww/resources/supporting_document_template.rb +14 -0
  55. data/lib/didww/resources/trunk/const.rb +1 -0
  56. data/lib/didww/resources/trunk.rb +1 -0
  57. data/lib/didww/resources/trunk_group.rb +1 -0
  58. data/lib/didww/version.rb +2 -1
  59. data/lib/didww.rb +5 -1
  60. metadata +33 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67435ef42f0af2a8862a0951069af3d7a4ce4b3afedfeef02c89203fef215645
4
- data.tar.gz: f5bcb5ea9069ef3b10a1ac6c9b714d315e3b0f55d80fc132e22e21cc076a24ac
3
+ metadata.gz: 9d736e9893b21ef96ef76993d6bb3da3e47c1dbb760edcc6ea13d0cf86d5e847
4
+ data.tar.gz: 9d641935ce36af938ea6641b7488835535ef4a01f6464b5c90f667dafac953c3
5
5
  SHA512:
6
- metadata.gz: 843ef3ddb29b72b09a7ef3b586169fe2f481463a0de49a8361642ff20c31973dee901f0c0d4f21bfa0c6aff60df2243e0e9e2e22b1e123168775bea200ecd6f0
7
- data.tar.gz: 842db8a8747dcfe7aa79fb363d45022d31a407ef2321e2599b770b7294c9eba890b4f1858a35735f77512d639a58948db44d25afddc69cfcad50f26f581820ec
6
+ metadata.gz: b2cef4993cda70bd45a3a1efd960ab26d9ba603de9a10c246c537ccdbbb3506e923f1628643fabcefcc7be8ca1f9a6a93342b996e6233b9eadadc77818d766fe
7
+ data.tar.gz: de556881b793c412ea2fb486bacd00f89a3c07ad3902e755f5a4140e2eb0fda10f1b748ea719ce9968e87e476797bed8b28ce3b032f1e107ed457946235f303f
@@ -1,5 +1,9 @@
1
1
  name: Tests
2
- on: [ 'pull_request' ]
2
+ on:
3
+ pull_request:
4
+ push:
5
+ branches:
6
+ - master
3
7
 
4
8
  jobs:
5
9
  test:
data/.rubocop.yml CHANGED
@@ -52,6 +52,9 @@ Style/StringLiterals:
52
52
  Style/StringLiteralsInInterpolation:
53
53
  Enabled: true
54
54
 
55
+ Style/FrozenStringLiteralComment:
56
+ Enabled: true
57
+
55
58
  ##################### Performance ############################
56
59
 
57
60
  # Use `casecmp` rather than `downcase ==`.
data/CHANGELOG.md CHANGED
@@ -4,15 +4,33 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [1.3.1] - 2021-10-26
7
+ ## [2.0.0] - 2021-10-26
8
+ ### Breaking Changes
9
+ - upgrade `json_api_client` version to `1.18.0` [#9](https://github.com/didww/didww-v3-ruby/pull/9)
10
+ Handling of 4XX responses was changed - it now raises JsonApiClient::Errors::ClientError with `detail` as error message instead of adding it into base errors.
11
+ - /v3/dids in request and response attributes pending_removal being removed in favor of billing_cycles_count.
12
+ - /v3/did_groups restriction message removed in favor of requirements relationship.
13
+
8
14
  ### Changes
9
15
  - replace travis with github actions [#7](https://github.com/didww/didww-v3-ruby/pull/7) [#9](https://github.com/didww/didww-v3-ruby/pull/9)
10
16
  - use rubocop 1.9.X version [#7](https://github.com/didww/didww-v3-ruby/pull/7)
11
17
  - add bundle-audit [#7](https://github.com/didww/didww-v3-ruby/pull/7)
18
+ - /v3/orders request attribute items of type DID Order Item Attributes can have billing_cycles_count.
19
+ - /v3/dids added address_verification relationship.
20
+ - callbacks attributes added to /v3/orders, /v3/cdr_exports.
21
+ - /v3/proof_types read endpoints being added.
22
+ - /v3/supporting_document_templates read endpoints being added.
23
+ - /v3/requirements read endpoints being added.
24
+ - /v3/identities read, write, and delete endpoints being added.
25
+ - /v3/addresses read, write, and delete endpoints being added.
26
+ - /v3/encrypted_files read, write, and delete endpoints being added.
27
+ - /v3/proofs write, delete endpoint being added.
28
+ - /v3/permanent_supporting_documents write, delete endpoint being added.
29
+ - /v3/address_verifications read and write endpoints being added.
30
+ - /v3/requirement_validations write endpoint being added.
12
31
 
13
32
  ### Bugfixes
14
33
  - fix order purchase when activesupport 6.X.X is used.
15
- - fix BigDecimal 2 support for ruby 2.7+.
16
34
 
17
35
  ## [1.3.0] - 2018-09-03
18
36
  ### Changes
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Ruby client for DIDWW API v3.
2
2
 
3
- [![Build Status](https://github.com/didww/didww-v3-ruby/workflows/tests/badge.svg?branch=master)](https://github.com/didww/didww-v3-ruby/actions)
3
+ ![Tests](https://github.com/didww/didww-v3-ruby/workflows/Tests/badge.svg)
4
4
 
5
5
  About DIDWW API v3
6
6
  -----
@@ -11,6 +11,10 @@ The DIDWW API v3 is a fully compliant implementation of the [JSON API specificat
11
11
 
12
12
  Read more https://doc.didww.com/api
13
13
 
14
+ Gem Versions **2.X.X** are intended to use with DIDWW API 3 version [2021-04-19](https://doc.didww.com/api3/2021-04-19/index.html).
15
+
16
+ Gem Versions **1.X.X** are intended to use with DIDWW API 3 version [2017-09-18](https://doc.didww.com/api3/2017-09-18/index.html).
17
+
14
18
  ## Installation
15
19
 
16
20
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
3
4
  require 'bundler/audit/task'
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'didww'
data/didww-v3.gemspec CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -23,7 +24,8 @@ Gem::Specification.new do |spec|
23
24
 
24
25
  spec.add_dependency 'activesupport'
25
26
  spec.add_dependency 'faraday'
26
- spec.add_dependency 'json_api_client', '1.5.3'
27
+ spec.add_dependency 'json_api_client', '1.18.0'
27
28
  spec.add_dependency 'http'
28
29
  spec.add_dependency 'down'
30
+ spec.add_dependency 'openssl-oaep'
29
31
  end
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  # :nodoc:
3
- class Middleware < Faraday::Middleware
4
+ class BaseMiddleware < Faraday::Middleware
4
5
  def call(request_env)
5
6
  headers = {}
6
- headers['Content-Type'] = 'application/vnd.api+json'
7
- headers['Api-Key'] = DIDWW::Client.api_key
8
- headers['User-Agent'] = "didww-v3 Ruby gem v#{VERSION}"
7
+ headers['Api-Key'] = DIDWW::Client.api_key
8
+ headers['User-Agent'] = "didww-v3 Ruby gem v#{VERSION}"
9
+ headers['x-didww-api-version'] = DIDWW::Client.api_version unless DIDWW::Client.api_version.blank?
9
10
 
10
11
  request_env[:request_headers].merge!(headers)
11
12
  request_env.url.host = URI(DIDWW::Client.api_base_url).host
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ require 'openssl'
3
+
4
+ module DIDWW
5
+ module Callback
6
+ # @example
7
+ # validator = DIDWW::Callback::RequestValidator.new(api_key)
8
+ # uri = request.original_url
9
+ # if request.post?
10
+ # # Collect all parameters passed from DIDWW.
11
+ # params = env['rack.request.form_hash']
12
+ # else
13
+ # params = env['rack.request.query_hash']
14
+ # end
15
+ #
16
+ # signature = env['HTTP_X_DIDWW_SIGNATURE']
17
+ # validator.validate(uri, params, signature) #=> true if the request is from DIDWW
18
+ # # or with rails
19
+ class RequestValidator
20
+ DIGEST_ALGO = 'SHA1'
21
+ HEADER = 'X-DIDWW-Signature'
22
+
23
+ def initialize(api_key)
24
+ @api_key = api_key
25
+ end
26
+
27
+ # @param url [String]
28
+ # @param payload [Hash]
29
+ # @param signature [String]
30
+ # @return [Boolean] whether signature valid or not.
31
+ def validate(url, payload, signature)
32
+ return false if signature.blank?
33
+
34
+ signature == valid_signature(url, payload)
35
+ end
36
+
37
+ private
38
+
39
+ # @param url [String]
40
+ # @param payload [Hash]
41
+ # @return [String] generated signature in URL safe format.
42
+ def valid_signature(url, payload)
43
+ normalized_url = normalize_url(url)
44
+ data = normalized_url + payload.sort.join
45
+ OpenSSL::HMAC.hexdigest(DIGEST_ALGO, @api_key, data)
46
+ end
47
+
48
+ # @return [String] normalized URL.
49
+ def normalize_url(url)
50
+ parsed_url = URI ensure_protocol_url(url)
51
+ url = "#{parsed_url.scheme || 'http'}://"
52
+ url += "#{parsed_url.userinfo}@" if parsed_url.userinfo
53
+ url += "#{parsed_url.host}:#{parsed_url.port || parsed_url.default_port}#{parsed_url.path}"
54
+ url += "?#{parsed_url.query}" if parsed_url.query
55
+ url += "##{parsed_url.fragment}" if parsed_url.fragment
56
+ url
57
+ end
58
+
59
+ def ensure_protocol_url(url)
60
+ if url[%r{\A[a-zA-Z]+://}i]
61
+ url
62
+ else
63
+ 'http://' + url
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
data/lib/didww/client.rb CHANGED
@@ -1,18 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_support/core_ext/module/attribute_accessors'
3
+ require 'active_support/core_ext/object/blank'
2
4
  require 'json_api_client'
3
5
 
4
6
  require 'didww/resources/base'
5
7
 
6
- # Fixes BigDecimal 2 support for ruby 2.7+ without introducing json_api_client breaking changes.
7
- # https://github.com/JsonApiClient/json_api_client/commit/ac372b8bab3b71bb0aa5c4dcc6ced1d9c3fe8d14
8
- class JsonApiClient::Schema::Types::FixedDecimal
9
- def self.cast(value, _)
10
- BigDecimal(value)
11
- end
12
- end
13
-
14
- JsonApiClient::Schema.register decimal: JsonApiClient::Schema::Types::FixedDecimal
15
-
16
8
  module DIDWW
17
9
  module Client
18
10
  BASE_URLS = {
@@ -21,7 +13,7 @@ module DIDWW
21
13
  }.freeze
22
14
  DEFAULT_MODE = :sandbox
23
15
 
24
- mattr_accessor :api_key, :api_mode, :http_verbose
16
+ mattr_accessor :api_key, :api_mode, :http_verbose, :api_version
25
17
 
26
18
  class << self
27
19
  def configure
@@ -39,8 +31,20 @@ module DIDWW
39
31
  @@api_key
40
32
  end
41
33
 
34
+ def api_version
35
+ @@api_version
36
+ end
37
+
38
+ def with_api_version(api_version)
39
+ old_api_version = self.api_version
40
+ self.api_version = api_version
41
+ yield
42
+ ensure
43
+ self.api_version = old_api_version
44
+ end
45
+
42
46
  def api_base_url
43
- BASE_URLS[api_mode]
47
+ ENV['DIDWW_API_URL'].presence || BASE_URLS[api_mode]
44
48
  end
45
49
 
46
50
  def balance
@@ -107,6 +111,38 @@ module DIDWW
107
111
  Resource::DidReservation
108
112
  end
109
113
 
114
+ def requirements
115
+ Resource::Requirement
116
+ end
117
+
118
+ def identities
119
+ Resource::Identity
120
+ end
121
+
122
+ def proofs
123
+ Resource::Proof
124
+ end
125
+
126
+ def addresses
127
+ Resource::Address
128
+ end
129
+
130
+ def permanent_supporting_documents
131
+ Resource::PermanentSupportingDocument
132
+ end
133
+
134
+ def encrypted_file
135
+ Resource::EncryptedFile
136
+ end
137
+
138
+ def address_verifications
139
+ Resource::AddressVerification
140
+ end
141
+
142
+ def requirement_validation
143
+ Resource::RequirementValidation
144
+ end
145
+
110
146
  def api_mode=(arg)
111
147
  unless BASE_URLS.keys.include?(arg)
112
148
  raise ArgumentError.new("Mode should be in #{BASE_URLS.keys} (given '#{arg}').")
@@ -124,7 +160,7 @@ module DIDWW
124
160
  DIDWW::Resource::Base.site = api_base_url
125
161
  DIDWW::Resource::Base.connection do |connection|
126
162
  connection.use Faraday::Response::Logger if http_verbose?
127
- connection.use DIDWW::Middleware
163
+ connection.use DIDWW::JsonapiMiddleware
128
164
  end
129
165
  JsonApiClient::Paginating::Paginator.page_param = 'number'
130
166
  JsonApiClient::Paginating::Paginator.per_page_param = 'size'
@@ -149,6 +185,18 @@ module DIDWW
149
185
  require 'didww/resources/trunk'
150
186
  require 'didww/resources/available_did'
151
187
  require 'didww/resources/did_reservation'
188
+ require 'didww/resources/requirement'
189
+ require 'didww/resources/proof_type'
190
+ require 'didww/resources/supporting_document_template'
191
+ require 'didww/resources/identity'
192
+ require 'didww/resources/proof'
193
+ require 'didww/resources/address'
194
+ require 'didww/resources/permanent_supporting_document'
195
+ require 'didww/resources/encrypted_file'
196
+ require 'didww/resources/address_verification'
197
+ require 'didww/resources/requirement_validation'
198
+ require 'didww/resources/public_key'
199
+ require 'didww/resources/area'
152
200
  end
153
201
 
154
202
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'json_api_client/schema'
2
3
 
3
4
  module DIDWW
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  class CapacityOrderItem < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'json_api_client/schema'
2
3
 
3
4
  module DIDWW
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/configurations/const'
2
3
 
3
4
  module DIDWW
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  module Configuration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  module Configuration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  module Configuration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  module Configuration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  module Configuration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/configurations/base'
2
3
  require 'didww/complex_objects/configurations/sip_configuration'
3
4
  require 'didww/complex_objects/configurations/iax2_configuration'
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module ComplexObject
3
4
  class DidOrderItem < Base
4
5
  # passed at order creation
5
- property :qty, type: :int
6
- property :available_did_id, type: :string
7
- property :did_reservation_id, type: :string
8
- property :sku_id, type: :string
6
+ property :qty, type: :int
7
+ property :available_did_id, type: :string
8
+ property :did_reservation_id, type: :string
9
+ property :sku_id, type: :string
10
+ property :billing_cycles_count, type: :string
9
11
 
10
12
  # returned
11
- property :setup_price, type: :decimal
12
- property :monthly_price, type: :decimal
13
- property :nrc, type: :decimal
14
- property :mrc, type: :decimal
15
- property :propated_mrc, type: :boolean
16
- property :billed_from, type: :string
17
- property :billed_to, type: :string
18
- property :did_group_id, type: :string
13
+ property :setup_price, type: :decimal
14
+ property :monthly_price, type: :decimal
15
+ property :nrc, type: :decimal
16
+ property :mrc, type: :decimal
17
+ property :propated_mrc, type: :boolean
18
+ property :billed_from, type: :string
19
+ property :billed_to, type: :string
20
+ property :did_group_id, type: :string
19
21
  end
20
22
  end
21
23
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+ require 'openssl'
3
+ require 'openssl/oaep'
4
+ require 'net/http'
5
+
6
+ module DIDWW
7
+ # Allows to encrypt file on Ruby-side before uploading to `/v3/encrypted_files`.
8
+ # @example
9
+ # file_content_1 = File.read('file_to_send_1.jpg', mode: 'rb')
10
+ # file_content_2 = File.read('file_to_send_1.pdf', mode: 'rb')
11
+ # enc = DIDWW::Encrypt.new
12
+ # enc_data_1 = enc.encrypt(file_content_1)
13
+ # enc_data_2 = enc.encrypt(file_content_2)
14
+ # enc_io_1 = Faraday::UploadIO.new(StringIO.new(enc_data_1), 'application/octet-stream')
15
+ # enc_io_2 = Faraday::UploadIO.new(StringIO.new(enc_data_2), 'application/octet-stream')
16
+ # DIDWW::Resource::EncryptedFile.upload(
17
+ # encryption_fingerprint: enc.encryption_fingerprint,
18
+ # items: [
19
+ # { file: enc_io_1, description: 'file_to_send_1.jpg' },
20
+ # { file: enc_io_2, description: 'file_to_send_2.pdf' }
21
+ # ]
22
+ # ) # => Array if IDs
23
+ #
24
+ class Encrypt
25
+ AES_ALGO = [256, :CBC]
26
+ AES_KEY_LEN = 32
27
+ AES_IV_LEN = 16
28
+ LABEL = ''
29
+ SEPARATOR = ':::'
30
+
31
+ class << self
32
+ # @param binary [String]
33
+ # @return [String]
34
+ def encrypt(binary)
35
+ new.encrypt(binary)
36
+ end
37
+ end
38
+
39
+ attr_reader :public_keys, :encryption_fingerprint
40
+
41
+ def initialize
42
+ reset!
43
+ end
44
+
45
+ # @param binary [String] binary content of a file.
46
+ # @return [String] binary content of an encrypted file.
47
+ def encrypt(binary)
48
+ aes_key, aes_iv, encrypted_aes = encrypt_aes(binary)
49
+ aes_credentials = aes_key + aes_iv
50
+ encrypted_rsa_a = encrypt_rsa_oaep(public_keys[0], aes_credentials)
51
+ encrypted_rsa_b = encrypt_rsa_oaep(public_keys[1], aes_credentials)
52
+ encrypted_rsa_a + encrypted_rsa_b + encrypted_aes
53
+ end
54
+
55
+ # Resets public keys and fingerprint.
56
+ def reset!
57
+ @public_keys = fetch_public_keys
58
+ @encryption_fingerprint = calculate_fingerprint
59
+ end
60
+
61
+ private
62
+
63
+ # @return [Array(String,String)] public keys.
64
+ def fetch_public_keys
65
+ DIDWW::Resource::PublicKey.find.map(&:key)
66
+ end
67
+
68
+ def calculate_fingerprint
69
+ public_keys.map { |pub_key| fingerprint_for(pub_key) }.join(SEPARATOR)
70
+ end
71
+
72
+ # @param public_key [String] PEM public key.
73
+ # @return [String] hexstring digest SHA1 for public key binary.
74
+ def fingerprint_for(public_key)
75
+ public_key += "\n" unless public_key[-1] == "\n"
76
+ public_key_base64 = public_key.split("\n")[1..-2].join
77
+ public_key_bin = Base64.decode64(public_key_base64)
78
+ OpenSSL::Digest::SHA1.hexdigest(public_key_bin)
79
+ end
80
+
81
+ # @param public_key [String]
82
+ # @param text [String]
83
+ def encrypt_rsa_oaep(public_key, text)
84
+ rsa = OpenSSL::PKey::RSA.new(public_key)
85
+ rsa.public_encrypt_oaep(text, LABEL, OpenSSL::Digest::SHA256)
86
+ end
87
+
88
+ # @param binary [String]
89
+ # @return [Array(String,String,String)] binaries key, vector, encrypted data.
90
+ def encrypt_aes(binary)
91
+ key = SecureRandom.random_bytes(AES_KEY_LEN)
92
+ iv = SecureRandom.random_bytes(AES_IV_LEN)
93
+ cipher = OpenSSL::Cipher::AES.new(*AES_ALGO)
94
+ cipher.encrypt
95
+ cipher.key = key
96
+ cipher.iv = iv
97
+ encrypted = cipher.update(binary) + cipher.final
98
+ [key, iv, encrypted]
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ # :nodoc:
4
+ class JsonapiMiddleware < Faraday::Middleware
5
+ def call(request_env)
6
+ headers = {}
7
+ headers['Content-Type'] = 'application/vnd.api+json'
8
+ headers['Api-Key'] = DIDWW::Client.api_key
9
+ headers['User-Agent'] = "didww-v3 Ruby gem v#{VERSION}"
10
+ headers['x-didww-api-version'] = DIDWW::Client.api_version unless DIDWW::Client.api_version.blank?
11
+
12
+ request_env[:request_headers].merge!(headers)
13
+ request_env.url.host = URI(DIDWW::Client.api_base_url).host
14
+
15
+ @app.call(request_env).on_complete do |response_env|
16
+ # do something with the response
17
+ # response_env[:response_headers].merge!(...)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class Address < Base
5
+
6
+ has_one :identity, class_name: 'Identity'
7
+ has_one :country, class_name: 'Country'
8
+ has_many :proofs, class_name: 'Proof'
9
+ has_many :city, class_name: 'City'
10
+ has_many :area, class_name: 'Area'
11
+
12
+ property :city_name, type: :string
13
+ # Type: String
14
+ # Description:
15
+
16
+ property :postal_code, type: :string
17
+ # Type: String
18
+ # Description:
19
+
20
+ property :address, type: :string
21
+ # Type: String
22
+ # Description:
23
+
24
+ property :description, type: :string
25
+ # Type: String
26
+ # Description:
27
+
28
+ property :created_at, type: :date
29
+ # Type: Date
30
+ # Description:
31
+
32
+ property :verified, type: :boolean
33
+ # Type: Boolean
34
+ # Description:
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class AddressVerification < Base
5
+ STATUS_PENDING = 'Pending'
6
+ STATUS_APPROVED = 'Approved'
7
+ STATUS_REJECTED = 'Rejected'
8
+ STATUSES = [
9
+ STATUS_PENDING,
10
+ STATUS_APPROVED,
11
+ STATUS_REJECTED
12
+ ].freeze
13
+
14
+ has_one :address, class_name: 'Address'
15
+ has_many :dids, class_name: 'Did'
16
+ has_many :onetime_files, class_name: 'EncryptedFile'
17
+
18
+ property :service_description, type: :string
19
+ # Type: String
20
+ # Description:
21
+
22
+ property :status, type: :string
23
+ # Type: String
24
+ # Description:
25
+
26
+ property :reject_reasons, type: :string
27
+ # Type: String
28
+ # Description:
29
+
30
+ property :created_at, type: :date
31
+ # Type: Date
32
+ # Description:
33
+
34
+ property :callback_url, type: :string
35
+ # Type: String
36
+ # Description: valid URI for callbacks
37
+
38
+ property :callback_method, type: :string
39
+ # Type: String
40
+ # Description: GET or POST
41
+
42
+ def pending?
43
+ status == STATUS_PENDING
44
+ end
45
+
46
+ def approved?
47
+ status == STATUS_APPROVED
48
+ end
49
+
50
+ def rejected?
51
+ status == STATUS_REJECTED
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class Area < Base
5
+ has_one :country, class_name: 'Country'
6
+
7
+ property :name, type: :string
8
+ # Type: String
9
+ # Description: Regulatory Area name
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class AvailableDid < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Balance < Base