Class: Immudb::Store
- Inherits:
-
Object
- Object
- Immudb::Store
- Defined in:
- lib/immudb/store.rb
Class Method Summary collapse
- .digest_from(sliced_digest) ⇒ Object
- .digests_from(sliced_terms) ⇒ Object
- .encode_key(key) ⇒ Object
- .encode_kv(key, value) ⇒ Object
- .encode_reference(key, referencedKey, atTx) ⇒ Object
- .linear_proof_from(lp) ⇒ Object
- .tx_from(stx) ⇒ Object
- .tx_metadata_from(txmFrom) ⇒ Object
- .verify_dual_proof(proof, sourceTxID, targetTxID, sourceAlh, targetAlh) ⇒ Object
- .verify_inclusion(proof, digest, root) ⇒ Object
Class Method Details
.digest_from(sliced_digest) ⇒ Object
66 67 68 |
# File 'lib/immudb/store.rb', line 66 def digest_from(sliced_digest) sliced_digest[0, 32] end |
.digests_from(sliced_terms) ⇒ Object
70 71 72 |
# File 'lib/immudb/store.rb', line 70 def digests_from(sliced_terms) sliced_terms.map(&:dup) end |
.encode_key(key) ⇒ Object
49 50 51 |
# File 'lib/immudb/store.rb', line 49 def encode_key(key) SET_KEY_PREFIX + key end |
.encode_kv(key, value) ⇒ Object
53 54 55 |
# File 'lib/immudb/store.rb', line 53 def encode_kv(key, value) KV.new(SET_KEY_PREFIX + key, PLAIN_VALUE_PREFIX + value) end |
.encode_reference(key, referencedKey, atTx) ⇒ Object
57 58 59 60 |
# File 'lib/immudb/store.rb', line 57 def encode_reference(key, referencedKey, atTx) refVal = REFERENCE_VALUE_PREFIX + [atTx].pack("Q>") + SET_KEY_PREFIX + referencedKey KV.new(SET_KEY_PREFIX + key, refVal) end |
.linear_proof_from(lp) ⇒ Object
62 63 64 |
# File 'lib/immudb/store.rb', line 62 def linear_proof_from(lp) LinearProof.new(lp.sourceTxId, lp.TargetTxId, lp.terms) end |
.tx_from(stx) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/immudb/store.rb', line 16 def tx_from(stx) entries = [] stx.entries.each do |e| i = TXe.new i.h_value = digest_from(e.hValue) i.v_off = e.vOff i.value_len = e.vLen.to_i i.set_key(e.key) entries << i end tx = new_tx_with_entries(entries) tx.ID = stx..id tx.PrevAlh = digest_from(stx..prevAlh) tx.Ts = stx..ts tx.BlTxID = stx..blTxId tx.BlRoot = digest_from(stx..blRoot) tx.build_hash_tree tx.calc_alh tx end |
.tx_metadata_from(txmFrom) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/immudb/store.rb', line 37 def (txmFrom) txm = TxMetadata.new txm.iD = txmFrom.id txm.prevAlh = digest_from(txmFrom.prevAlh) txm.ts = txmFrom.ts txm.nEntries = txmFrom.nentries.to_i txm.eh = digest_from(txmFrom.eH) txm.blTxID = txmFrom.blTxId txm.blRoot = digest_from(txmFrom.blRoot) txm end |
.verify_dual_proof(proof, sourceTxID, targetTxID, sourceAlh, targetAlh) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/immudb/store.rb', line 94 def verify_dual_proof(proof, sourceTxID, targetTxID, sourceAlh, targetAlh) if proof.nil? || proof.sourceTxMetadata.nil? || proof.targetTxMetadata.nil? || proof.sourceTxMetadata.iD != sourceTxID || proof.targetTxMetadata.iD != targetTxID return false end if proof.sourceTxMetadata.iD == 0 || proof.sourceTxMetadata.iD > proof.targetTxMetadata.iD return false end if sourceAlh != proof.sourceTxMetadata.alh return false end if targetAlh != proof.targetTxMetadata.alh return false end if sourceTxID < proof.targetTxMetadata.blTxID && !verify_inclusion_aht(proof.inclusionProof, sourceTxID, proof.targetTxMetadata.blTxID, leaf_for(sourceAlh), proof.targetTxMetadata.blRoot) return false end if proof.sourceTxMetadata.blTxID > 0 && !verify_consistency(proof.consistencyProof, proof.sourceTxMetadata.blTxID, proof.targetTxMetadata.blTxID, proof.sourceTxMetadata.blRoot, proof.targetTxMetadata.blRoot) return false end if proof.targetTxMetadata.blTxID > 0 && !verify_last_inclusion(proof.lastInclusionProof, proof.targetTxMetadata.blTxID, leaf_for(proof.targetBlTxAlh), proof.targetTxMetadata.blRoot) return false end if sourceTxID < proof.targetTxMetadata.blTxID verify_linear_proof(proof.linearProof, proof.targetTxMetadata.blTxID, targetTxID, proof.targetBlTxAlh, targetAlh) else verify_linear_proof(proof.linearProof, sourceTxID, targetTxID, sourceAlh, targetAlh) end end |
.verify_inclusion(proof, digest, root) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/immudb/store.rb', line 74 def verify_inclusion(proof, digest, root) return false if proof.nil? leaf = LEAF_PREFIX + digest calc_root = Digest::SHA256.digest(leaf) i = proof.leaf r = proof.width - 1 proof.terms.to_a.each do |t| b = NODE_PREFIX if i % 2 == 0 && i != r b = b + calc_root + t else b = b + t + calc_root end calc_root = Digest::SHA256.digest(b) i = i.div(2) r = r.div(2) end i == r && root == calc_root end |