sidetree 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidetree/cas/fetch_result.rb +20 -0
- data/lib/sidetree/cas/ipfs.rb +101 -0
- data/lib/sidetree/cas.rb +6 -0
- data/lib/sidetree/did.rb +2 -2
- data/lib/sidetree/key.rb +28 -10
- data/lib/sidetree/model/cas_file_base.rb +40 -0
- data/lib/sidetree/model/chunk.rb +21 -0
- data/lib/sidetree/model/chunk_file.rb +72 -0
- data/lib/sidetree/model/core_index_file.rb +197 -0
- data/lib/sidetree/model/core_proof_file.rb +105 -0
- data/lib/sidetree/model/delta.rb +10 -1
- data/lib/sidetree/model/document.rb +6 -0
- data/lib/sidetree/model/provisional_index_file.rb +129 -0
- data/lib/sidetree/model/provisional_proof_file.rb +80 -0
- data/lib/sidetree/model/suffix.rb +2 -2
- data/lib/sidetree/model.rb +7 -0
- data/lib/sidetree/op/create.rb +36 -3
- data/lib/sidetree/op/deactivate.rb +73 -1
- data/lib/sidetree/op/recover.rb +11 -2
- data/lib/sidetree/op/updatable.rb +98 -0
- data/lib/sidetree/op/update.rb +19 -0
- data/lib/sidetree/op.rb +2 -0
- data/lib/sidetree/util/anchored_data_serializer.rb +41 -0
- data/lib/sidetree/util/compressor.rb +38 -0
- data/lib/sidetree/util/jwk.rb +47 -0
- data/lib/sidetree/util/jws.rb +52 -0
- data/lib/sidetree/util.rb +8 -0
- data/lib/sidetree/validator.rb +23 -0
- data/lib/sidetree/version.rb +1 -1
- data/lib/sidetree.rb +18 -1
- data/sidetree.gemspec +2 -1
- metadata +35 -4
@@ -0,0 +1,47 @@
|
|
1
|
+
module Sidetree
|
2
|
+
module Util
|
3
|
+
module JWK
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Parse jwk hash object.
|
7
|
+
# The returned jwk does not include the kid.
|
8
|
+
# @param [Hash] params
|
9
|
+
# @return [JSON::JWK]
|
10
|
+
def parse(params)
|
11
|
+
jwk = JSON::JWK.new(params)
|
12
|
+
jwk.delete("kid")
|
13
|
+
jwk
|
14
|
+
end
|
15
|
+
|
16
|
+
# Validate jwk object as sidetree jwk.
|
17
|
+
# @param [JSON::JWK] jwk
|
18
|
+
# @raise [Sidetree::Error]
|
19
|
+
def validate!(jwk)
|
20
|
+
raise Sidetree::Error unless jwk.is_a?(JSON::JWK)
|
21
|
+
jwk.keys.each do |k|
|
22
|
+
unless %w[kty crv x y].include?(k)
|
23
|
+
raise Sidetree::Error, "JWK Es256k has unknown property"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
unless jwk[:kty] == "EC"
|
27
|
+
raise Sidetree::Error, "JWK Es256k missing or invalid kty"
|
28
|
+
end
|
29
|
+
unless jwk[:crv] == "secp256k1"
|
30
|
+
raise Sidetree::Error, "JWK Es256k missing or invalid crv"
|
31
|
+
end
|
32
|
+
unless jwk[:x].is_a?(String)
|
33
|
+
raise Sidetree::Error, "JWK Es256k missing or invalid type x"
|
34
|
+
end
|
35
|
+
unless jwk[:y].is_a?(String)
|
36
|
+
raise Sidetree::Error, "JWK Es256k missing or invalid type y"
|
37
|
+
end
|
38
|
+
unless jwk[:x].length == 43
|
39
|
+
raise Sidetree::Error, "JWK Es256k has incorrect length of x"
|
40
|
+
end
|
41
|
+
unless jwk[:y].length == 43
|
42
|
+
raise Sidetree::Error, "JWK Es256k has incorrect length of y"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Sidetree
|
2
|
+
module Util
|
3
|
+
module JWS
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Sign to +claim+ by +private_key+.
|
7
|
+
# @param [Hash] claim
|
8
|
+
# @param [Sidetree::Key] private_key Private key used by sign.
|
9
|
+
# @return [JSON::JWS]
|
10
|
+
def sign(claim, private_key)
|
11
|
+
jwt = JSON::JWT.new(claim)
|
12
|
+
jwt.header.delete(:typ)
|
13
|
+
jwt.sign(private_key.jws_sign_key, :ES256K)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Parse +jws_string+ to JSON::JWS
|
17
|
+
# @param [String] jws_string JWS data string.
|
18
|
+
# @return [JSON::JWS]
|
19
|
+
# @raise [Sidetree::Error]
|
20
|
+
def parse(jws_string)
|
21
|
+
jws =
|
22
|
+
JSON::JWS.decode_compact_serialized(jws_string, :skip_verification)
|
23
|
+
validate!(jws)
|
24
|
+
jws
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check whether valid +jws+ or not as sidetree jws.
|
28
|
+
# @param [JSON::JWS] jws
|
29
|
+
# @return [Boolean]
|
30
|
+
def valid?(jws)
|
31
|
+
begin
|
32
|
+
validate!(jws)
|
33
|
+
true
|
34
|
+
rescue Sidetree::Error
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Validate +jws+ as sidetree jws.
|
40
|
+
# @param [JSON::JWS] jws
|
41
|
+
# @raise [Sidetree::Error]
|
42
|
+
def validate!(jws)
|
43
|
+
unless jws.header.length == 1
|
44
|
+
raise Sidetree::Error, "jws header missing or unknown property"
|
45
|
+
end
|
46
|
+
unless jws.header[:alg] == "ES256K"
|
47
|
+
raise Sidetree::Error, "jws header missing or incorrect alg"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sidetree/validator.rb
CHANGED
@@ -215,6 +215,18 @@ module Sidetree
|
|
215
215
|
end
|
216
216
|
end
|
217
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
|
+
|
218
230
|
def validate_did_type!(type)
|
219
231
|
return unless type
|
220
232
|
raise Error, "DID type must be a string." unless type.instance_of?(String)
|
@@ -245,5 +257,16 @@ module Sidetree
|
|
245
257
|
validate_encoded_multi_hash!(suffix[:deltaHash], "delta hash")
|
246
258
|
validate_did_type!(suffix[:type])
|
247
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
|
248
271
|
end
|
249
272
|
end
|
data/lib/sidetree/version.rb
CHANGED
data/lib/sidetree.rb
CHANGED
@@ -13,11 +13,13 @@ module Sidetree
|
|
13
13
|
class Error < StandardError
|
14
14
|
end
|
15
15
|
|
16
|
+
autoload :Util, "sidetree/util"
|
16
17
|
autoload :Key, "sidetree/key"
|
17
18
|
autoload :DID, "sidetree/did"
|
18
19
|
autoload :Model, "sidetree/model"
|
19
20
|
autoload :OP, "sidetree/op"
|
20
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
|
@@ -26,7 +28,22 @@ module Sidetree
|
|
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
48
|
DEFAULT_METHOD = "sidetree"
|
32
49
|
|
data/sidetree.gemspec
CHANGED
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
39
39
|
# For more information and examples about making a new gem, checkout our
|
40
40
|
# guide at: https://bundler.io/guides/creating_gem.html
|
41
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
|
-
spec.add_development_dependency 'prettier', '~> 3.
|
42
|
+
spec.add_development_dependency 'prettier', '~> 3.2.0'
|
43
|
+
spec.add_development_dependency 'webmock', '~> 3.14.0'
|
43
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecdsa
|
@@ -86,14 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 3.
|
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.
|
96
|
+
version: 3.2.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.14.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.14.0
|
97
111
|
description: Ruby implementation for Sidetree protocol.
|
98
112
|
email:
|
99
113
|
- azuchi@chaintope.com
|
@@ -116,11 +130,21 @@ files:
|
|
116
130
|
- bin/console
|
117
131
|
- bin/setup
|
118
132
|
- lib/sidetree.rb
|
133
|
+
- lib/sidetree/cas.rb
|
134
|
+
- lib/sidetree/cas/fetch_result.rb
|
135
|
+
- lib/sidetree/cas/ipfs.rb
|
119
136
|
- lib/sidetree/did.rb
|
120
137
|
- lib/sidetree/key.rb
|
121
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
|
122
144
|
- lib/sidetree/model/delta.rb
|
123
145
|
- lib/sidetree/model/document.rb
|
146
|
+
- lib/sidetree/model/provisional_index_file.rb
|
147
|
+
- lib/sidetree/model/provisional_proof_file.rb
|
124
148
|
- lib/sidetree/model/service.rb
|
125
149
|
- lib/sidetree/model/suffix.rb
|
126
150
|
- lib/sidetree/op.rb
|
@@ -128,6 +152,13 @@ files:
|
|
128
152
|
- lib/sidetree/op/create.rb
|
129
153
|
- lib/sidetree/op/deactivate.rb
|
130
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
|
131
162
|
- lib/sidetree/validator.rb
|
132
163
|
- lib/sidetree/version.rb
|
133
164
|
- sidetree.gemspec
|