immudb 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e530750b846b9cbb85420fd917f44d965047526d4f3c2dd04105827d5e58b56
4
- data.tar.gz: e64b188ed24cecad8641bcb700911308c33c4ace0c5fcb48b4419f0d57ed7fcf
3
+ metadata.gz: 0200e6229a8e67d2592feb14e0375910e5c62bf358ee826357fc4b0b03b17751
4
+ data.tar.gz: dcb8aab1b18fd45882517b7a4aaa76801ec0fdd8881676084df490e57af354b6
5
5
  SHA512:
6
- metadata.gz: 3ccee301794025162563a425a08f758728b9971c88a35011dd4f6a11d9b7cf1cc98f5fdfedad0f5e978eb28089ec25334a64349d2366a8be6b486f8ad7b5be68
7
- data.tar.gz: 520659b836111fd48fc56143bac7b59ebb4360d070d307c6ba331e1fe169fe5f9ecaaba0b1578d8eacc41502ec6409b751c0bb9436c79551a2137df717283dcb
6
+ metadata.gz: a0b20a298d7deb3783b988486c414d7486e242709cbb7b13fbab8579159cdb757ff68f870233a38da5a0aa0813c6c98415967a07bf4f808fc4a48764bec4204b
7
+ data.tar.gz: 5d2f796fea4da4e067f197a47469ae6bb95ccb4a24b4e81982948e113c79c7244827be5e33e8010431268975854f6d5802b6610a1f65ccafe71b4b25a356e87e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.2.0 (2023-05-11)
2
+
3
+ - Dropped support for Ruby < 3
4
+
5
+ ## 0.1.1 (2022-06-12)
6
+
7
+ - Added support for verified methods with immudb 1.2.1+
8
+
1
9
  ## 0.1.0 (2021-12-31)
2
10
 
3
11
  - First release
data/lib/immudb/client.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2021 CodeNotary, Inc. All rights reserved.
1
+ # Copyright 2022 CodeNotary, Inc. All rights reserved.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -76,51 +76,61 @@ module Immudb
76
76
  nil
77
77
  end
78
78
 
79
- def verified_set(key, value)
79
+ def verified_set(key, value, metadata: nil)
80
+ schema_metadata = metadata_to_proto(metadata)
80
81
  state = @rs.get
81
- kv = Schema::KeyValue.new(key: key, value: value)
82
+ kv = Schema::KeyValue.new(key: key, value: value, metadata: schema_metadata)
82
83
 
83
84
  raw_request = Schema::VerifiableSetRequest.new(
84
85
  setRequest: Schema::SetRequest.new(KVs: [kv]),
85
86
  proveSinceTx: state.txId
86
87
  )
87
88
  verifiable_tx = grpc.verifiable_set(raw_request)
88
- tx = Store.tx_from(verifiable_tx.tx)
89
- inclusion_proof = tx.proof(SET_KEY_PREFIX + key)
90
- ekv = Store.encode_kv(key, value)
91
- verifies = Store.verify_inclusion(inclusion_proof, ekv.digest, tx.eh)
92
- unless verifies
89
+ if verifiable_tx.tx.header.nentries != 1 || verifiable_tx.tx.entries.length != 1
93
90
  raise VerificationError
94
91
  end
95
- if tx.eh != Store.digest_from(verifiable_tx.dualProof.targetTxMetadata.eH)
92
+ tx = Schema.tx_from_proto(verifiable_tx.tx)
93
+ entry_spec_digest = Store.entry_spec_digest_for(tx.header.version)
94
+ inclusion_proof = tx.proof(Database.encode_key(key))
95
+ md = tx.entries[0].metadata
96
+
97
+ if !md.nil? && md.deleted?
96
98
  raise VerificationError
97
99
  end
98
- if state.txId == 0
99
- source_id = tx.ID
100
- source_alh = tx.Alh
101
- else
102
- source_id = state.txId
103
- source_alh = Store.digest_from(state.txHash)
100
+
101
+ e = Database.encode_entry_spec(key, md, value)
102
+
103
+ verifies = Store.verify_inclusion(inclusion_proof, entry_spec_digest.call(e), tx.header.eh)
104
+ unless verifies
105
+ raise VerificationError
104
106
  end
105
- target_id = tx.ID
106
- target_alh = tx.Alh
107
-
108
- verifies = Store.verify_dual_proof(
109
- HTree.dual_proof_from(verifiable_tx.dualProof),
110
- source_id,
111
- target_id,
112
- source_alh,
113
- target_alh
114
- )
115
- if !verifies
107
+ if tx.header.eh != Schema.digest_from_proto(verifiable_tx.dualProof.targetTxHeader.eH)
116
108
  raise VerificationError
117
109
  end
110
+ source_id = state.txId
111
+ source_alh = Schema.digest_from_proto(state.txHash)
112
+ target_id = tx.header.iD
113
+ target_alh = tx.header.alh
114
+
115
+ if state.txId > 0
116
+ verifies = Store.verify_dual_proof(
117
+ Schema.dual_proof_from_proto(verifiable_tx.dualProof),
118
+ source_id,
119
+ target_id,
120
+ source_alh,
121
+ target_alh
122
+ )
123
+ unless verifies
124
+ raise VerificationError
125
+ end
126
+ end
127
+
118
128
  newstate = State.new(
119
129
  db: state.db,
120
130
  txId: target_id,
121
131
  txHash: target_alh,
122
132
  publicKey: verifiable_tx.signature&.publicKey,
123
- signature: verifiable_tx.signature&.signature,
133
+ signature: verifiable_tx.signature&.signature
124
134
  )
125
135
  if !verifying_key.nil?
126
136
  newstate.verify(verifying_key)
@@ -142,43 +152,50 @@ module Immudb
142
152
  )
143
153
  ventry = grpc.verifiable_get(req)
144
154
 
145
- inclusion_proof = HTree.inclusion_proof_from(ventry.inclusionProof)
146
- dual_proof = HTree.dual_proof_from(ventry.verifiableTx.dualProof)
155
+ entry_spec_digest = Store.entry_spec_digest_for(ventry.verifiableTx.tx.header.version.to_i)
156
+ inclusion_proof = Schema.inclusion_proof_from_proto(ventry.inclusionProof)
157
+ dual_proof = Schema.dual_proof_from_proto(ventry.verifiableTx.dualProof)
147
158
 
148
159
  if ventry.entry.referencedBy.nil? || ventry.entry.referencedBy.key == ""
149
160
  vTx = ventry.entry.tx
150
- kv = Store.encode_kv(key, ventry.entry.value)
161
+ e = Database.encode_entry_spec(key, Schema.kv_metadata_from_proto(ventry.entry.metadata), ventry.entry.value)
151
162
  else
152
- vTx = ventry.entry.referencedBy.tx
153
- kv = store.encode_reference(ventry.entry.referencedBy.key, ventry.entry.key, ventry.entry.referencedBy.atTx)
163
+ ref = ventry.entry.referencedBy
164
+ vTx = ref.tx
165
+ e = Database.encode_reference(ref.key, Schema.kv_metadata_from_proto(ref.metadata), ventry.entry.key, ref.atTx)
154
166
  end
155
167
 
156
168
  if state.txId <= vTx
157
- eh = Store.digest_from(ventry.verifiableTx.dualProof.targetTxMetadata.eH)
169
+ eh = Schema.digest_from_proto(ventry.verifiableTx.dualProof.targetTxHeader.eH)
158
170
  source_id = state.txId
159
- source_alh = Store.digest_from(state.txHash)
171
+ source_alh = Schema.digest_from_proto(state.txHash)
160
172
  target_id = vTx
161
- target_alh = dual_proof.targetTxMetadata.alh
173
+ target_alh = dual_proof.targetTxHeader.alh
162
174
  else
163
- eh = Store.digest_from(ventry.verifiableTx.dualProof.sourceTxMetadata.eH)
175
+ eh = Schema.digest_from_proto(ventry.verifiableTx.dualProof.sourceTxHeader.eH)
164
176
  source_id = vTx
165
- source_alh = dual_proof.sourceTxMetadata.alh
177
+ source_alh = dual_proof.sourceTxHeader.alh
166
178
  target_id = state.txId
167
- target_alh = store.digest_from(state.txHash)
179
+ target_alh = Schema.digest_from_proto(state.txHash)
168
180
  end
169
181
 
170
- verifies = Store.verify_inclusion(inclusion_proof, kv.digest, eh)
182
+ verifies = Store.verify_inclusion(inclusion_proof, entry_spec_digest.call(e), eh)
171
183
  if !verifies
172
184
  raise VerificationError
173
185
  end
174
- verifies = Store.verify_dual_proof(
175
- dual_proof,
176
- source_id,
177
- target_id,
178
- source_alh,
179
- target_alh)
180
- if !verifies
181
- raise VerificationError
186
+
187
+ if state.txId > 0
188
+ verifies =
189
+ Store.verify_dual_proof(
190
+ dual_proof,
191
+ source_id,
192
+ target_id,
193
+ source_alh,
194
+ target_alh
195
+ )
196
+ if !verifies
197
+ raise VerificationError
198
+ end
182
199
  end
183
200
  newstate = State.new(
184
201
  db: state.db,
@@ -362,5 +379,22 @@ module Immudb
362
379
  name
363
380
  end
364
381
  end
382
+
383
+ def metadata_to_proto(metadata)
384
+ schema_metadata = nil
385
+ if metadata
386
+ schema_metadata = Schema::KVMetadata.new
387
+ if metadata.deleted?
388
+ schema_metadata.deleted = true
389
+ end
390
+ if metadata.expirable?
391
+ schema_metadata.expiration = Schema::Expiration.new(expiresAt: metadata.expiration_time.to_i)
392
+ end
393
+ if metadata.non_indexable?
394
+ schema_metadata.nonIndexable = true
395
+ end
396
+ end
397
+ schema_metadata
398
+ end
365
399
  end
366
400
  end
@@ -0,0 +1,33 @@
1
+ # Copyright 2022 CodeNotary, Inc. All rights reserved.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ module Immudb
14
+ module Database
15
+ class << self
16
+ def wrap_with_prefix(b, prefix)
17
+ prefix + b
18
+ end
19
+
20
+ def encode_key(key)
21
+ wrap_with_prefix(key, SET_KEY_PREFIX)
22
+ end
23
+
24
+ def encode_entry_spec(key, md, value)
25
+ EntrySpec.new(
26
+ key: wrap_with_prefix(key, SET_KEY_PREFIX),
27
+ md: md,
28
+ value: wrap_with_prefix(value, PLAIN_VALUE_PREFIX)
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -12,6 +12,6 @@
12
12
 
13
13
  module Immudb
14
14
  class DualProof
15
- attr_accessor :sourceTxMetadata, :targetTxMetadata, :inclusionProof, :consistencyProof, :targetBlTxAlh, :lastInclusionProof, :linearProof
15
+ attr_accessor :sourceTxHeader, :targetTxHeader, :inclusionProof, :consistencyProof, :targetBlTxAlh, :lastInclusionProof, :linearProof
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2021 CodeNotary, Inc. All rights reserved.
1
+ # Copyright 2022 CodeNotary, Inc. All rights reserved.
2
2
 
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -11,17 +11,13 @@
11
11
  # limitations under the License.
12
12
 
13
13
  module Immudb
14
- class TXe
15
- attr_accessor :key_len, :key, :value_len, :h_value, :v_off
14
+ class EntrySpec
15
+ attr_reader :key, :metadata, :value
16
16
 
17
- def set_key(key)
18
- @key = key.dup
19
- @key_len = key.length
20
- end
21
-
22
- def digest
23
- b = @key + @h_value
24
- Digest::SHA256.digest(b)
17
+ def initialize(key:, md:, value:)
18
+ @key = key
19
+ @metadata = md
20
+ @value = value
25
21
  end
26
22
  end
27
23
  end