chain-sdk 1.1.1 → 1.2.0.rc2

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
  SHA1:
3
- metadata.gz: 3a348719a289fcc08cad489af9b14a29c7881314
4
- data.tar.gz: 4fe43ec3cb47aec507adfc11c5a11defd87c9184
3
+ metadata.gz: c013135b3eeaa68f8b9ff51ce82c5605c8373bfb
4
+ data.tar.gz: 07dbf685e55001d5f69546ffa128b7923dc6eca1
5
5
  SHA512:
6
- metadata.gz: 52d194b3870c8dc07fb2a4be7866e4dd5e6a8106614ac5380c231a3845bd3bc3587e402ed8b132a1d6fbbd696e66db78e71b2ddb5cf53c13dc1ac5dbe2627124
7
- data.tar.gz: 90acba9d91d5061d1f0614787cd3703b4a31a3dab45247fa7a94dd42b9eb10a599d9b974a8f6bbdb75109663ff451624b1122ebff9139f1995c357f5acbb8e64
6
+ metadata.gz: 1945dea88d0fe6a69a43c34f0c582e0813a369301e6ca675ce0974118e5417d018c55acd7cc2bdeee6d438f5742edd43895e5feb2729a341d97f093f1935c6d5
7
+ data.tar.gz: 79b0b783a89ed29eb35cfcacf370a7673c5bca7d27870952fbdc1b123b4e31578e4b79abb04105dbd132116686bdea18ab7105ee52ea95ce4cffee1236307cfc
data/README.md CHANGED
@@ -11,7 +11,7 @@ Ruby 2.0 or greater is required. We strongly recommend upgrading to Ruby 2.1 or
11
11
  For most applications, you can simply add the following to your `Gemfile`:
12
12
 
13
13
  ```
14
- gem 'chain-sdk', '~> 1.1.1', require: 'chain'
14
+ gem 'chain-sdk', '~> 1.2.0.rc2', require: 'chain'
15
15
  ```
16
16
 
17
17
  ### In your code
@@ -15,8 +15,9 @@ module Chain
15
15
  # @return [String]
16
16
  attrib :token
17
17
 
18
+ # @deprecated
18
19
  # @!attribute [r] type
19
- # Either 'client' or 'network'.
20
+ # Either 'client' or 'network'. Ignore in 1.2 or greater.
20
21
  # @return [String]
21
22
  attrib :type
22
23
 
@@ -27,12 +28,11 @@ module Chain
27
28
 
28
29
  class ClientModule < Chain::ClientModule
29
30
 
30
- # Create client/network access token.
31
+ # Create an access token.
31
32
  # @param [Hash] opts
32
- # @option opts [String] :type Type specifiying the type of access token to be created.
33
- # You must specify either 'client' or 'network'.
34
33
  # @option opts [String] :id ID specifying the ID of newly created access token.
35
34
  # You must specify a unique ID for access token.
35
+ # @option opts [String] :type DEPRECATED. Do not use in 1.2 or greater.
36
36
  # @return [AccessToken]
37
37
  def create(opts = {})
38
38
  AccessToken.new(client.conn.request('create-access-token', opts))
@@ -41,7 +41,7 @@ module Chain
41
41
  # Get all access tokens sorted by descending creation time,
42
42
  # optionally filtered by type.
43
43
  # @param [Hash] opts Filtering information
44
- # @option opts [String] :type Type of access tokens to return; either 'client' or 'network'.
44
+ # @option opts [String] :type DEPRECATED. Do not use in 1.2 or greater.
45
45
  # @return [Query]
46
46
  def query(opts = {})
47
47
  Query.new(client, opts)
@@ -53,7 +53,7 @@ module Chain
53
53
  # @return [void]
54
54
  def delete(id)
55
55
  client.conn.request('delete-access-token', {id: id})
56
- return
56
+ nil
57
57
  end
58
58
 
59
59
  class Query < Chain::Query
@@ -1,5 +1,4 @@
1
1
  require_relative './client_module'
2
- require_relative './control_program'
3
2
  require_relative './errors'
4
3
  require_relative './query'
5
4
  require_relative './receiver'
@@ -53,20 +52,19 @@ module Chain
53
52
  client.conn.batch_request('create-account', opts) { |item| Account.new(item) }
54
53
  end
55
54
 
56
- # @deprecated (as of version 1.1) Use {#create_receiver} instead.
57
- # @param [Hash] opts
58
- # @return [ControlProgram]
59
- def create_control_program(opts = {})
60
- # We don't use keyword params here because 'alias' is a Ruby reserverd
61
- # word.
62
- params = {}
63
- params[:account_alias] = opts[:alias] if opts.key?(:alias)
64
- params[:account_id] = opts[:id] if opts.key?(:id)
65
-
66
- client.conn.singleton_batch_request(
67
- 'create-control-program',
68
- [{type: :account, params: params}]
69
- ) { |item| ControlProgram.new(item) }
55
+ # @param [Hash] opts Options hash specifiying account creation details.
56
+ # @option opts [String] id The ID of the account. Either an ID or alias should be provided, but not both.
57
+ # @option opts [String] alias The alias of the account. Either an ID or alias should be provided, but not both.
58
+ # @option opts [Hash] tags A new set of tags, which will replace the existing tags.
59
+ # @return [Hash] a success message.
60
+ def update_tags(opts)
61
+ client.conn.singleton_batch_request('update-account-tags', [opts])
62
+ end
63
+
64
+ # @param [Array<Hash>] opts An array of options hashes. See {#update_tags} for a description of the hash structure.
65
+ # @return [BatchResponse<Hash>]
66
+ def update_tags_batch(opts)
67
+ client.conn.batch_request('update-account-tags', opts)
70
68
  end
71
69
 
72
70
  # Creates a new receiver under the specified account.
@@ -70,6 +70,21 @@ module Chain
70
70
  client.conn.batch_request('create-asset', opts) { |item| Asset.new(item) }
71
71
  end
72
72
 
73
+ # @param [Hash] opts Options hash specifiying asset creation details.
74
+ # @option opts [String] id The ID of the asset. Either an ID or alias should be provided, but not both.
75
+ # @option opts [String] alias The alias of the asset. Either an ID or alias should be provided, but not both.
76
+ # @option opts [Hash] tags A new set of tags, which will replace the existing tags.
77
+ # @return [Hash] a success message.
78
+ def update_tags(opts)
79
+ client.conn.singleton_batch_request('update-asset-tags', [opts])
80
+ end
81
+
82
+ # @param [Array<Hash>] opts An array of options hashes. See {#update_tags} for a description of the hash structure.
83
+ # @return [BatchResponse<Hash>]
84
+ def update_tags_batch(opts)
85
+ client.conn.batch_request('update-asset-tags', opts)
86
+ end
87
+
73
88
  # @param [Hash] opts Filtering information
74
89
  # @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
75
90
  # @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
@@ -0,0 +1,139 @@
1
+ require_relative './client_module'
2
+ require_relative './query'
3
+ require_relative './response_object'
4
+
5
+ module Chain
6
+ class AuthorizationGrant < ResponseObject
7
+
8
+ # @!attribute [r] guard_type
9
+ # The type of credential that the guard matches against. Only "access_token"
10
+ # and "x509" are allowed.
11
+ # @return [String]
12
+ attrib :guard_type
13
+
14
+ # @!attribute [r] guard_data
15
+ # A list of parameters that match specific credentials.
16
+ # @return [Hash]
17
+ attrib :guard_data
18
+
19
+ # @!attribute [r] policy
20
+ # @return [String]
21
+ attrib :policy
22
+
23
+ # @!attribute [r] protected
24
+ # @return [Boolean]
25
+ # Whether the grant can be deleted. Only used for internal purposes.
26
+ attrib :protected
27
+
28
+ # @!attribute [r] created_at
29
+ # Timestamp of token creation.
30
+ # @return [Time]
31
+ attrib :created_at, rfc3339_time: true
32
+
33
+ class ClientModule < Chain::ClientModule
34
+
35
+ # Create an authorization grant, which provides the specified
36
+ # credential with access to the given policy. Credentials are identified
37
+ # using predicates called guards. Guards identify credentials by type
38
+ # and by patterns specific to that type.
39
+ #
40
+ # @param [Hash] opts
41
+ # @option opts [String] :guard_type Either "access_token" or "x509".
42
+ # @option opts [Hash] :guard_data Parameters that describe a credential.
43
+ #
44
+ # For guards of type "access_token", provide a Hash with a single key,
45
+ # "id", whose value is the unique ID of the access token.
46
+ #
47
+ # For guards of type "x509", there should be a single top-level key,
48
+ # "subject", which maps to a hash of Subject attributes. Valid
49
+ # keys include:
50
+ # - "C" (Country, string or array of strings)
51
+ # - "O" (Organization, string or array of strings)
52
+ # - "OU" (Organizational Unit, string or array of strings)
53
+ # - "L" (Locality, string or array of strings)
54
+ # - "ST" (State or Province, string or array of strings)
55
+ # - "STREET" (Street Address, string or array of strings)
56
+ # - "POSTALCODE" (Postal Code, string or array of strings)
57
+ # - "SERIALNUMBER" (Serial Number, string)
58
+ # - "CN" (Common Name, string)
59
+ #
60
+ # @option opts [String] :policy One of the following:
61
+ #
62
+ # - "client-readwrite": full access to the Client API, including
63
+ # accounts, assets, transactions, access tokens, MockHSM, etc.
64
+ # - "client-readonly": read-only access to the Client API.
65
+ # - "monitoring": read-only access to diagnostic components of the API,
66
+ # including fetching configuration info.
67
+ # - "crosscore": access to the cross-core API, including fetching blocks
68
+ # and submitting transactions, but not including block signing.
69
+ # - "crosscore-signblock": access to the cross-core API's block-signing
70
+ # API call.
71
+ # @return [AuthorizationGrant]
72
+ def create(opts)
73
+ # Copy input and stringify keys
74
+ opts = opts.reduce({}) do |memo, (k, v)|
75
+ memo[k.to_s] = v
76
+ memo
77
+ end
78
+
79
+ if opts['guard_type'].to_s == 'x509'
80
+ opts['guard_data'] = self.class.sanitize_x509(opts['guard_data'])
81
+ end
82
+
83
+ AuthorizationGrant.new(client.conn.request('create-authorization-grant', opts))
84
+ end
85
+
86
+ # List all authorization grants. The sort order is not defined.
87
+ # @return [Array<AuthorizationGrant>]
88
+ def list_all
89
+ client.conn.request('list-authorization-grants')['items'].map { |item| AuthorizationGrant.new(item) }
90
+ end
91
+
92
+ # Delete the specified authorization grant.
93
+ # @param opts Identical to {#create}.
94
+ # @return [void]
95
+ def delete(opts)
96
+ client.conn.request('delete-authorization-grant', opts)
97
+ nil
98
+ end
99
+
100
+ SUBJECT_ATTRIBUTES = {
101
+ 'C' => {array: true},
102
+ 'O' => {array: true},
103
+ 'OU' => {array: true},
104
+ 'L' => {array: true},
105
+ 'ST' => {array: true},
106
+ 'STREET' => {array: true},
107
+ 'POSTALCODE' => {array: true},
108
+ 'SERIALNUMBER' => {array: false},
109
+ 'CN' => {array: false},
110
+ }
111
+
112
+ def self.sanitize_x509(guard_data)
113
+ first_key = guard_data.keys.first
114
+ if guard_data.size != 1 || first_key.to_s.downcase != 'subject'
115
+ raise ArgumentError.new('Guard data must contain exactly one key, "subject"')
116
+ end
117
+
118
+ res = {}
119
+ res[first_key] = guard_data.values.first.reduce({}) do |memo, (k, v)|
120
+ attrib = SUBJECT_ATTRIBUTES[k.to_s.upcase]
121
+ raise ArgumentError.new("Invalid subject attrib: #{k}") unless attrib
122
+
123
+ if attrib[:array] && !v.is_a?(Array)
124
+ memo[k] = [v]
125
+ elsif !attrib[:array] && v.is_a?(Array)
126
+ raise ArgumentError.new("Invalid array value for #{k}: #{v}")
127
+ else
128
+ memo[k] = v
129
+ end
130
+
131
+ memo
132
+ end
133
+ res
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+ end
@@ -1,4 +1,5 @@
1
1
  require_relative './access_token'
2
+ require_relative './authorization_grant'
2
3
  require_relative './account'
3
4
  require_relative './asset'
4
5
  require_relative './balance'
@@ -31,6 +32,11 @@ module Chain
31
32
  @access_tokens ||= AccessToken::ClientModule.new(self)
32
33
  end
33
34
 
35
+ # @return [AuthorizationGrant::ClientModule]
36
+ def authorization_grants
37
+ @authorization_grants ||= AuthorizationGrant::ClientModule.new(self)
38
+ end
39
+
34
40
  # @return [Account::ClientModule]
35
41
  def accounts
36
42
  @accounts ||= Account::ClientModule.new(self)
@@ -5,6 +5,30 @@ module Chain
5
5
  module Config
6
6
 
7
7
  class Info < ResponseObject
8
+ class BuildConfig < ResponseObject
9
+ # @!attribute [r] is_localhost_auth
10
+ # @return [Boolean]
11
+ # Whether any request from the loopback device (localhost) should be
12
+ # automatically authenticated and authorized, without additional
13
+ # credentials.
14
+ attrib :is_localhost_auth
15
+
16
+ # @!attribute [r] is_mockhsm
17
+ # @return [Boolean]
18
+ # Whether the MockHSM API is enabled.
19
+ attrib :is_mockhsm
20
+
21
+ # @!attribute [r] is_reset
22
+ # @return [Boolean]
23
+ # Whether the core reset API call is enabled.
24
+ attrib :is_reset
25
+
26
+ # @!attribute [r] is_http_ok
27
+ # @return [Boolean]
28
+ # Whether non-TLS HTTP requests (http://...) are allowed.
29
+ attrib :is_http_ok
30
+ end
31
+
8
32
  class Snapshot < ResponseObject
9
33
  # @!attribute [r] attempt
10
34
  # @return [Integer]
@@ -71,8 +95,14 @@ module Chain
71
95
  # @return [Boolean]
72
96
  attrib :is_production
73
97
 
98
+ # @!attribute [r] crosscore_rpc_version
99
+ # @return [Integer]
100
+ attrib :crosscore_rpc_version
101
+
102
+ # @deprecated
74
103
  # @!attribute [r] network_rpc_version
75
104
  # @return [Integer]
105
+ # Ignore in 1.2 or greater. Superseded by crosscore_rpc_version.
76
106
  attrib :network_rpc_version
77
107
 
78
108
  # @!attribute [r] core_id
@@ -95,6 +125,10 @@ module Chain
95
125
  # @return [String]
96
126
  attrib :build_date
97
127
 
128
+ # @!attribute [r] build_config
129
+ # @return [BuildConfig]
130
+ attrib(:build_config) { |raw| BuildConfig.new(raw) }
131
+
98
132
  # @!attribute [r] health
99
133
  # @return [Hash]
100
134
  attrib :health
@@ -116,7 +150,7 @@ module Chain
116
150
  # @param [Hash] opts Options for configuring Chain Core.
117
151
  # @option opts [Boolean] is_generator Whether the local core will be a block generator for the blockchain; i.e., you are starting a new blockchain on the local core. `false` if you are connecting to a pre-existing blockchain.
118
152
  # @option opts [String] generator_url A URL for the block generator. Required if `isGenerator` is false.
119
- # @option opts [String] generator_access_token A network access token provided by administrators of the block generator. Required if `isGenerator` is false.
153
+ # @option opts [String] generator_access_token An access token provided by administrators of the block generator. Required if `isGenerator` is false.
120
154
  # @option opts [String] blockchain_id The unique ID of the generator's blockchain. Required if `isGenerator` is false.
121
155
  # @return [void]
122
156
  def configure(opts)
@@ -57,7 +57,11 @@ module Chain
57
57
  if !!item['code']
58
58
  errors[i] = APIError.new(item, response)
59
59
  else
60
- successes[i] = translate.call(item)
60
+ if translate
61
+ successes[i] = translate.call(item)
62
+ else
63
+ successes[i] = item
64
+ end
61
65
  end
62
66
  end
63
67
 
@@ -182,6 +186,18 @@ module Chain
182
186
  if @url.scheme == 'https'
183
187
  @http.use_ssl = true
184
188
  @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
189
+ if @opts.key?(:ssl_params)
190
+ ssl_params = @opts[:ssl_params]
191
+ if ssl_params.key?(:ca_file)
192
+ @http.ca_file = ssl_params[:ca_file]
193
+ end
194
+ if ssl_params.key?(:cert)
195
+ @http.cert = ssl_params[:cert]
196
+ end
197
+ if ssl_params.key?(:key)
198
+ @http.key = ssl_params[:key]
199
+ end
200
+ end
185
201
  end
186
202
 
187
203
  @http
@@ -164,12 +164,6 @@ module Chain
164
164
  # @return [String]
165
165
  attrib :spent_output_id
166
166
 
167
- # @deprecated (as of version 1.1) Use {#spent_output_id} instead.
168
- # @!attribute [r] spent_output
169
- # The output consumed by this input.
170
- # @return [SpentOutput]
171
- attrib(:spent_output) { |raw| SpentOutput.new(raw) }
172
-
173
167
  # @!attribute [r] account_id
174
168
  # The id of the account transferring the asset (possibly null if the
175
169
  # input is an issuance or an unspent output is specified).
@@ -187,22 +181,12 @@ module Chain
187
181
  # @return [String]
188
182
  attrib :account_tags
189
183
 
190
- # @deprecated (as of version 1.1) Do not use this field.
191
- # @!attribute [r] input_witness
192
- # @return [String]
193
- attrib :input_witness
194
-
195
184
  # @!attribute [r] issuance_program
196
185
  # A program specifying a predicate for issuing an asset (possibly null
197
186
  # if input is not an issuance).
198
187
  # @return [String]
199
188
  attrib :issuance_program
200
189
 
201
- # @deprecated (as of version 1.1) Do not use this field.
202
- # @!attribute [r] control_program
203
- # @return [String]
204
- attrib :control_program
205
-
206
190
  # @!attribute [r] reference_data
207
191
  # User specified, unstructured data embedded within an input
208
192
  # (possibly null).
@@ -213,19 +197,6 @@ module Chain
213
197
  # A flag indicating if the input is local.
214
198
  # @return [Boolean]
215
199
  attrib :is_local
216
-
217
- # @deprecated (as of version 1.1)
218
- class SpentOutput < ResponseObject
219
- # @!attribute [r] transaction_id
220
- # Unique transaction identifier.
221
- # @return [String]
222
- attrib :transaction_id
223
-
224
- # @!attribute [r] position
225
- # Position of an output within the transaction.
226
- # @return [Integer]
227
- attrib :position
228
- end
229
200
  end
230
201
 
231
202
  class Output < ResponseObject
@@ -418,8 +389,6 @@ module Chain
418
389
  # Add a spend action taken on a particular unspent output.
419
390
  # @param [Hash] params Action parameters
420
391
  # @option params [String] :output_id Output ID specifying the transaction output to spend.
421
- # @option params [String] :transaction_id DEPRECATED (as of version 1.1) Transaction ID specifying the transaction to select an output from.
422
- # @option params [Integer] :position DEPRECATED (as of version 1.1) Position of the output within the transaction to be spent.
423
392
  # @return [Builder]
424
393
  def spend_account_unspent_output(params)
425
394
  add_action(params.merge(type: :spend_account_unspent_output))
@@ -455,20 +424,6 @@ module Chain
455
424
  add_action(params.merge(type: :control_receiver))
456
425
  end
457
426
 
458
- # @deprecated (as of version 1.1) Use {#control_with_receiver} instead.
459
- # Add a control action taken on a control program.
460
- # @param [Hash] params Action parameters
461
- # @option params [String] :asset_id Asset ID specifying the asset to be controlled.
462
- # You must specify either an ID or an alias.
463
- # @option params [String] :asset_alias Asset alias specifying the asset to be controlled.
464
- # You must specify either an ID or an alias.
465
- # @option params [String] :control_program The control program to be used
466
- # @option params [Integer] :amount amount of the asset to be controlled.
467
- # @return [Builder]
468
- def control_with_program(params)
469
- add_action(params.merge(type: :control_program))
470
- end
471
-
472
427
  # Add a retire action.
473
428
  # @param [Hash] params Action parameters
474
429
  # @option params [String] :asset_id Asset ID specifying the asset to be retired.
@@ -1,3 +1,3 @@
1
1
  module Chain
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0.rc2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chain-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chain Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - lib/chain/access_token.rb
91
91
  - lib/chain/account.rb
92
92
  - lib/chain/asset.rb
93
+ - lib/chain/authorization_grant.rb
93
94
  - lib/chain/balance.rb
94
95
  - lib/chain/batch_response.rb
95
96
  - lib/chain/client.rb
@@ -97,7 +98,6 @@ files:
97
98
  - lib/chain/config.rb
98
99
  - lib/chain/connection.rb
99
100
  - lib/chain/constants.rb
100
- - lib/chain/control_program.rb
101
101
  - lib/chain/errors.rb
102
102
  - lib/chain/hsm_signer.rb
103
103
  - lib/chain/mock_hsm.rb
@@ -123,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '2.0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - ">="
126
+ - - ">"
127
127
  - !ruby/object:Gem::Version
128
- version: '0'
128
+ version: 1.3.1
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 2.6.8
@@ -1,11 +0,0 @@
1
- require_relative './response_object'
2
-
3
- module Chain
4
- # @deprecated (as of version 1.1) Use {Receiver} instead.
5
- class ControlProgram < ResponseObject
6
- # @!attribute [r] control_program
7
- # Hex-encoded string representation of the control program.
8
- # @return [String]
9
- attrib :control_program
10
- end
11
- end