sidetree 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module Sidetree
5
5
  # @param [Hash] delta delta object.
6
6
  # @return [Sidetree::Error]
7
7
  def validate_delta!(delta)
8
- raise Error, 'Delta does not defined.' unless delta
8
+ raise Error, "Delta does not defined." unless delta
9
9
  delta_size = delta.to_json_c14n.bytesize
10
10
  if delta_size > Sidetree::Params::MAX_DELTA_SIZE
11
11
  raise Error,
@@ -13,7 +13,7 @@ module Sidetree
13
13
  end
14
14
 
15
15
  if delta.instance_of?(Array)
16
- raise Error, 'Delta object cannot be an array.'
16
+ raise Error, "Delta object cannot be an array."
17
17
  end
18
18
  delta.keys.each do |k|
19
19
  unless %w[patches updateCommitment].include?(k.to_s)
@@ -22,11 +22,11 @@ module Sidetree
22
22
  end
23
23
 
24
24
  unless delta[:patches].instance_of?(Array)
25
- raise Error, 'Patches object in delta must be an array.'
25
+ raise Error, "Patches object in delta must be an array."
26
26
  end
27
27
  delta[:patches].each { |p| validate_patch!(p) }
28
28
 
29
- validate_encoded_multi_hash!(delta[:updateCommitment], 'updateCommitment')
29
+ validate_encoded_multi_hash!(delta[:updateCommitment], "updateCommitment")
30
30
  end
31
31
 
32
32
  # @param [Hash] patch patch object.
@@ -49,7 +49,7 @@ module Sidetree
49
49
  end
50
50
 
51
51
  def validate_document!(document)
52
- raise Error, 'Document object missing in patch object' unless document
52
+ raise Error, "Document object missing in patch object" unless document
53
53
  document.keys.each do |k|
54
54
  unless %w[publicKeys services].include?(k.to_s)
55
55
  raise Error, "Property '#{k}' is not allowed in document object."
@@ -61,7 +61,7 @@ module Sidetree
61
61
 
62
62
  def validate_add_public_keys_patch!(patch)
63
63
  unless patch.keys.length == 2
64
- raise Error, 'Patch missing or unknown property.'
64
+ raise Error, "Patch missing or unknown property."
65
65
  end
66
66
  validate_public_keys!(patch[:publicKeys])
67
67
  end
@@ -73,7 +73,7 @@ module Sidetree
73
73
  end
74
74
  end
75
75
  unless patch[:ids].instance_of?(Array)
76
- raise Error, 'Patch public key ids not an array.'
76
+ raise Error, "Patch public key ids not an array."
77
77
  end
78
78
 
79
79
  patch[:ids].each { |id| validate_id!(id) }
@@ -81,10 +81,10 @@ module Sidetree
81
81
 
82
82
  def validate_add_services_patch!(patch)
83
83
  unless patch.keys.length == 2
84
- raise Error, 'Patch missing or unknown property.'
84
+ raise Error, "Patch missing or unknown property."
85
85
  end
86
86
  unless patch[:services].instance_of?(Array)
87
- raise Error, 'Patch services not an array.'
87
+ raise Error, "Patch services not an array."
88
88
  end
89
89
  validate_services!(patch[:services])
90
90
  end
@@ -96,7 +96,7 @@ module Sidetree
96
96
  end
97
97
  end
98
98
  unless patch[:ids].instance_of?(Array)
99
- raise Error, 'Patch service ids not an array.'
99
+ raise Error, "Patch service ids not an array."
100
100
  end
101
101
 
102
102
  patch[:ids].each { |id| validate_id!(id) }
@@ -104,7 +104,7 @@ module Sidetree
104
104
 
105
105
  def validate_public_keys!(public_keys)
106
106
  unless public_keys.instance_of?(Array)
107
- raise Error, 'publicKeys must be an array.'
107
+ raise Error, "publicKeys must be an array."
108
108
  end
109
109
  pubkey_ids = []
110
110
  public_keys.each do |public_key|
@@ -114,7 +114,7 @@ module Sidetree
114
114
  end
115
115
  end
116
116
  if public_key[:publicKeyJwk].instance_of?(Array)
117
- raise Error, 'publicKeyJwk object cannot be an array.'
117
+ raise Error, "publicKeyJwk object cannot be an array."
118
118
  end
119
119
  if public_key[:type] && !public_key[:type].is_a?(String)
120
120
  raise Error, "Public key type #{public_key[:type]} is incorrect."
@@ -123,16 +123,16 @@ module Sidetree
123
123
  validate_id!(public_key[:id])
124
124
 
125
125
  if pubkey_ids.include?(public_key[:id])
126
- raise Error, 'Public key id is duplicated.'
126
+ raise Error, "Public key id is duplicated."
127
127
  end
128
128
  pubkey_ids << public_key[:id]
129
129
 
130
130
  if public_key[:purposes]
131
131
  unless public_key[:purposes].instance_of?(Array)
132
- raise Error, 'purposes must be an array.'
132
+ raise Error, "purposes must be an array."
133
133
  end
134
134
  unless public_key[:purposes].count == public_key[:purposes].uniq.count
135
- raise Error, 'purpose is duplicated.'
135
+ raise Error, "purpose is duplicated."
136
136
  end
137
137
  public_key[:purposes].each do |purpose|
138
138
  unless OP::PublicKeyPurpose.values.include?(purpose)
@@ -145,34 +145,33 @@ module Sidetree
145
145
 
146
146
  def validate_services!(services)
147
147
  unless services.instance_of?(Array)
148
- raise Error, 'services must be an array.'
148
+ raise Error, "services must be an array."
149
149
  end
150
150
 
151
151
  service_ids = []
152
152
  services.each do |service|
153
153
  unless service.keys.length == 3
154
- raise Error, 'Service has missing or unknown property.'
154
+ raise Error, "Service has missing or unknown property."
155
155
  end
156
156
 
157
157
  validate_id!(service[:id])
158
158
 
159
159
  if service_ids.include?(service[:id])
160
- raise Error, 'Service id has to be unique.'
160
+ raise Error, "Service id has to be unique."
161
161
  end
162
162
  service_ids << service[:id]
163
163
 
164
164
  unless service[:type].is_a?(String)
165
165
  raise Error, "Service type #{service[:type]} is incorrect."
166
166
  end
167
- raise Error, 'Service type too long.' if service[:type].length > 30
167
+ raise Error, "Service type too long." if service[:type].length > 30
168
168
 
169
169
  endpoint = service[:serviceEndpoint]
170
170
  if endpoint.instance_of?(String)
171
171
  validate_uri!(endpoint)
172
172
  elsif endpoint.instance_of?(Hash)
173
-
174
173
  else
175
- raise Error, 'ServiceEndpoint must be string or object.'
174
+ raise Error, "ServiceEndpoint must be string or object."
176
175
  end
177
176
  end
178
177
  end
@@ -196,10 +195,10 @@ module Sidetree
196
195
  end
197
196
 
198
197
  def validate_id!(id)
199
- raise Error, 'id does not string.' unless id.instance_of?(String)
200
- raise Error, 'id is too long.' if id.length > 50
198
+ raise Error, "id does not string." unless id.instance_of?(String)
199
+ raise Error, "id is too long." if id.length > 50
201
200
  unless valid_base64_encoding?(id)
202
- raise Error, 'id does not use base64url character set.'
201
+ raise Error, "id does not use base64url character set."
203
202
  end
204
203
  end
205
204
 
@@ -216,9 +215,21 @@ module Sidetree
216
215
  end
217
216
  end
218
217
 
218
+ # Verify that the Multihash of +content+ matches that of +multihash+.
219
+ # @param [String] content content to be hashed
220
+ # @param [String] multihash Hash value to be checked
221
+ # @param [String] target Name of the target object to include in the error message
222
+ # @raise [Sidetree::Error]
223
+ def validate_canonicalize_object_hash!(content, multihash, target)
224
+ unless Sidetree.to_hash(content) == multihash
225
+ raise Sidetree::Error,
226
+ "Canonicalized #{target} object hash does not match expected hash '#{multihash}'"
227
+ end
228
+ end
229
+
219
230
  def validate_did_type!(type)
220
231
  return unless type
221
- raise Error, 'DID type must be a string.' unless type.instance_of?(String)
232
+ raise Error, "DID type must be a string." unless type.instance_of?(String)
222
233
  if type.length > 4
223
234
  raise Error,
224
235
  "DID type string '#{type}' cannot be longer than 4 characters."
@@ -231,20 +242,31 @@ module Sidetree
231
242
 
232
243
  def validate_suffix_data!(suffix)
233
244
  if suffix.instance_of?(Array)
234
- raise Error, 'Suffix data can not be an array.'
245
+ raise Error, "Suffix data can not be an array."
235
246
  end
236
247
  suffix.keys.each do |k|
237
248
  unless %w[deltaHash recoveryCommitment type].include?(k.to_s)
238
249
  raise Error, "Property '#{k}' is not allowed in publicKeys object."
239
250
  end
240
251
  end
241
- validate_encoded_multi_hash!(suffix[:deltaHash], 'delta hash')
252
+ validate_encoded_multi_hash!(suffix[:deltaHash], "delta hash")
242
253
  validate_encoded_multi_hash!(
243
254
  suffix[:recoveryCommitment],
244
- 'recovery commitment'
255
+ "recovery commitment"
245
256
  )
246
- validate_encoded_multi_hash!(suffix[:deltaHash], 'delta hash')
257
+ validate_encoded_multi_hash!(suffix[:deltaHash], "delta hash")
247
258
  validate_did_type!(suffix[:type])
248
259
  end
260
+
261
+ def validate_cas_file_uri!(uri, target)
262
+ unless uri.is_a?(String)
263
+ raise Sidetree::Error,
264
+ "Input #{target} CAS file URI '#{uri}' needs to be of string type"
265
+ end
266
+ if uri.bytesize > Sidetree::Params::MAX_CAS_URI_LENGTH
267
+ raise Sidetree::Error,
268
+ "Input #{target} CAS file URI byte size cannot exceed #{Sidetree::Params::MAX_CAS_URI_LENGTH}"
269
+ end
270
+ end
249
271
  end
250
272
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sidetree
4
- VERSION = '0.1.0'
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/sidetree.rb CHANGED
@@ -1,37 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'sidetree/version'
4
- require 'ecdsa'
5
- require 'json/jwt'
6
- require 'base64'
7
- require 'json'
8
- require 'json/canonicalization'
9
- require 'uri'
10
- require 'multihashes'
3
+ require_relative "sidetree/version"
4
+ require "ecdsa"
5
+ require "json/jwt"
6
+ require "base64"
7
+ require "json"
8
+ require "json/canonicalization"
9
+ require "uri"
10
+ require "multihashes"
11
11
 
12
12
  module Sidetree
13
13
  class Error < StandardError
14
14
  end
15
15
 
16
- autoload :Key, 'sidetree/key'
17
- autoload :DID, 'sidetree/did'
18
- autoload :Model, 'sidetree/model'
19
- autoload :OP, 'sidetree/op'
20
- autoload :Validator, 'sidetree/validator'
16
+ autoload :Util, "sidetree/util"
17
+ autoload :Key, "sidetree/key"
18
+ autoload :DID, "sidetree/did"
19
+ autoload :Model, "sidetree/model"
20
+ autoload :OP, "sidetree/op"
21
+ autoload :Validator, "sidetree/validator"
22
+ autoload :CAS, "sidetree/cas"
21
23
 
22
24
  module Params
23
25
  # Algorithm for generating hashes of protocol-related values. 0x12 = sha2-256
24
26
  HASH_ALGORITHM = [0x12]
25
- HASH_ALGORITH_STRING = 'sha2-256'
27
+ HASH_ALGORITH_STRING = "sha2-256"
26
28
 
27
29
  # Maximum canonicalized operation delta buffer size.
28
30
  MAX_DELTA_SIZE = 1000
29
-
31
+ # Maximum compressed chunk file size. 10MB.
32
+ MAX_CHUNK_FILE_SIZE = 10_000_000
33
+ # Maximum compressed Provisional Index File size. 1 MB (zipped)
34
+ MAX_PROVISIONAL_INDEX_FILE_SIZE = 1_000_000
35
+ # Maximum compressed Proof File size. 2.5 MB (zipped)
36
+ MAX_PROOF_FILE_SIZE = 2_500_000
37
+ # Maximum compressed Core Index File size. 1 MB (zipped)
38
+ MAX_CORE_INDEX_FILE_SIZE = 1_000_000
39
+ # Maximum writer lock ID size
40
+ MAX_WRITER_LOCK_ID_SIZE = 200
41
+ # Maximum length of CAS URIs. 100 bytes
42
+ MAX_CAS_URI_LENGTH = 100
43
+ # Maximum number of operations per batch. 10000 ops.
44
+ MAX_OPERATION_COUNT = 10_000
45
+ # Default public key type
46
+ DEFAULT_PUBKEY_TYPE = "EcdsaSecp256k1VerificationKey2019"
30
47
  # Default DID method
31
- DEFAULT_METHOD = 'sidetree'
48
+ DEFAULT_METHOD = "sidetree"
32
49
 
33
50
  # Supported did methods.
34
- METHODS = { default: DEFAULT_METHOD, ion: 'ion' }
51
+ METHODS = { default: DEFAULT_METHOD, ion: "ion" }
35
52
 
36
53
  @network = nil
37
54
 
@@ -48,8 +65,8 @@ module Sidetree
48
65
  end
49
66
 
50
67
  module Network
51
- MAINNET = 'mainnet'
52
- TESTNET = 'test'
68
+ MAINNET = "mainnet"
69
+ TESTNET = "test"
53
70
  end
54
71
  end
55
72
 
data/sidetree.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Ruby implementation for Sidetree protocol.'
13
13
  spec.homepage = 'https://github.com/azuchi/sidetreerb'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 2.6.0'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['source_code_uri'] = spec.homepage
@@ -35,10 +35,10 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency 'json-jwt', '~> 1.13.0'
36
36
  spec.add_dependency 'json-canonicalization', '~> 0.3.0'
37
37
  spec.add_dependency 'multihashes', '~> 0.2.0'
38
- spec.add_runtime_dependency 'thor'
39
38
 
40
39
  # For more information and examples about making a new gem, checkout our
41
40
  # guide at: https://bundler.io/guides/creating_gem.html
42
41
  spec.add_development_dependency 'rspec', '~> 3.0'
43
- spec.add_development_dependency 'prettier'
42
+ spec.add_development_dependency 'prettier', '~> 3.2.0'
43
+ spec.add_development_dependency 'webmock', '~> 3.14.0'
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidetree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa
@@ -67,52 +67,51 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.2.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: thor
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
75
+ version: '3.0'
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: prettier
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: 3.2.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: 3.2.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: prettier
98
+ name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 3.14.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 3.14.0
111
111
  description: Ruby implementation for Sidetree protocol.
112
112
  email:
113
113
  - azuchi@chaintope.com
114
- executables:
115
- - ion
114
+ executables: []
116
115
  extensions: []
117
116
  extra_rdoc_files: []
118
117
  files:
@@ -130,18 +129,36 @@ files:
130
129
  - Rakefile
131
130
  - bin/console
132
131
  - bin/setup
133
- - exe/ion
134
132
  - lib/sidetree.rb
133
+ - lib/sidetree/cas.rb
134
+ - lib/sidetree/cas/fetch_result.rb
135
+ - lib/sidetree/cas/ipfs.rb
135
136
  - lib/sidetree/did.rb
136
137
  - lib/sidetree/key.rb
137
138
  - lib/sidetree/model.rb
139
+ - lib/sidetree/model/cas_file_base.rb
140
+ - lib/sidetree/model/chunk.rb
141
+ - lib/sidetree/model/chunk_file.rb
142
+ - lib/sidetree/model/core_index_file.rb
143
+ - lib/sidetree/model/core_proof_file.rb
138
144
  - lib/sidetree/model/delta.rb
139
145
  - lib/sidetree/model/document.rb
146
+ - lib/sidetree/model/provisional_index_file.rb
147
+ - lib/sidetree/model/provisional_proof_file.rb
140
148
  - lib/sidetree/model/service.rb
141
149
  - lib/sidetree/model/suffix.rb
142
150
  - lib/sidetree/op.rb
143
151
  - lib/sidetree/op/base.rb
144
152
  - lib/sidetree/op/create.rb
153
+ - lib/sidetree/op/deactivate.rb
154
+ - lib/sidetree/op/recover.rb
155
+ - lib/sidetree/op/updatable.rb
156
+ - lib/sidetree/op/update.rb
157
+ - lib/sidetree/util.rb
158
+ - lib/sidetree/util/anchored_data_serializer.rb
159
+ - lib/sidetree/util/compressor.rb
160
+ - lib/sidetree/util/jwk.rb
161
+ - lib/sidetree/util/jws.rb
145
162
  - lib/sidetree/validator.rb
146
163
  - lib/sidetree/version.rb
147
164
  - sidetree.gemspec
@@ -160,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
177
  requirements:
161
178
  - - ">="
162
179
  - !ruby/object:Gem::Version
163
- version: 2.6.0
180
+ version: 2.7.0
164
181
  required_rubygems_version: !ruby/object:Gem::Requirement
165
182
  requirements:
166
183
  - - ">="
data/exe/ion DELETED
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'thor'
3
- require 'sidetree'
4
-
5
- class ION < Thor
6
- class << self
7
- def exit_on_failure?
8
- true
9
- end
10
- end
11
-
12
- desc 'create', 'Create ION DID.'
13
- def create
14
- recovery_key = Sidetree::Key.generate
15
- update_key = Sidetree::Key.generate
16
- signing_key = Sidetree::Key.generate(id: 'signing-key')
17
- document = Sidetree::Model::Document.new(public_keys: [signing_key])
18
- did = Sidetree::DID.create(document, update_key, recovery_key, method: Sidetree::Params::METHODS[:ion])
19
-
20
- puts "DID: #{did.short_form}"
21
- puts
22
- puts "Recovery key: #{recovery_key.encoded_private_key}"
23
- puts "Update key: #{update_key.encoded_private_key}"
24
- puts "Signing key: #{signing_key.encoded_private_key}"
25
- puts
26
-
27
- puts "Long-Form DID: #{did.to_s}"
28
- op = did.create_op
29
- puts "DID suffix data: #{op.suffix.to_h.to_json}"
30
- puts "Document delta: #{op.delta.to_h.to_json}"
31
- end
32
- end
33
-
34
- ION.start(ARGV)