github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/merkletree2/interfaces.go (about) 1 package merkletree2 2 3 import "github.com/keybase/client/go/logger" 4 5 // StorageEngine specifies how to store and lookup merkle tree nodes, roots and 6 // KeyEncodedValuePairs. You can use a DB like Dynamo or SQL to do this. 7 type StorageEngine interface { 8 ExecTransaction(ctx logger.ContextInterface, txFn func(logger.ContextInterface, Transaction) error) error 9 10 // StoreKVPairs stores the []KeyEncodedValuePair in the tree. 11 StoreKEVPairs(logger.ContextInterface, Transaction, Seqno, []KeyEncodedValuePair) error 12 13 // StoreNode stores the Hash (of a tree node) at the provided Position, 14 // Seqno in the tree. 15 StoreNode(logger.ContextInterface, Transaction, Seqno, *Position, Hash) error 16 17 // StoreNode takes multiple pairs of a position and a hash, and stores each 18 // hash (of a tree node) at the corresponding position and at the supplied 19 // Seqno in the tree. 20 StoreNodes(logger.ContextInterface, Transaction, Seqno, []PositionHashPair) error 21 22 // StoreRootMetadata stores the supplied RootMetadata, along with the 23 // corresponding Hash. 24 StoreRootMetadata(logger.ContextInterface, Transaction, RootMetadata, Hash) error 25 26 // LookupLatestRoot returns the latest root metadata and sequence number in 27 // the tree. If no root is found, then a NoLatestRootFound error is returned. 28 LookupLatestRoot(logger.ContextInterface, Transaction) (Seqno, RootMetadata, error) 29 30 // If there is no root for the specified Seqno, an InvalidSeqnoError is returned. 31 LookupRoot(logger.ContextInterface, Transaction, Seqno) (RootMetadata, error) 32 33 // Returns a RootMetadata given its Hash. 34 LookupRootFromHash(logger.ContextInterface, Transaction, Hash) (RootMetadata, error) 35 36 // LookupRoots returns the RootMetadata objects in the tree at the 37 // supplied Seqnos, ordered by seqno. 38 LookupRoots(logger.ContextInterface, Transaction, []Seqno) ([]RootMetadata, error) 39 40 // LookupRootHashes returns hashes of the RootMetadata in the tree at the 41 // corresponding Seqnos, ordered by seqno. 42 LookupRootHashes(logger.ContextInterface, Transaction, []Seqno) ([]Hash, error) 43 44 // LookupNode returns, for any position, the hash of the node with the 45 // highest Seqno s' <= s which was stored at position p. For example, if 46 // StoreNode(ctx, t, 5, p, hash5) and StoreNode(ctx, 6, p, hash6) and 47 // StoreNode(ctx, t, 8, p, hash8) were called for a specific position p, 48 // then LookupNode(ctx, t, 7, p) would return hash6. It returns an error if 49 // no such node was stored in the tree. 50 LookupNode(c logger.ContextInterface, t Transaction, s Seqno, p *Position) (Hash, error) 51 52 // LookupNodes is analogous to LookupNode, but it takes more than one 53 // position and returns pairs of a Position and the corresponding node Hash 54 // only for the nodes which are found in the tree. No error is returned if 55 // some of the positions are not found. 56 LookupNodes(c logger.ContextInterface, t Transaction, s Seqno, positions []Position) ([]PositionHashPair, error) 57 58 // LookupKVPair returns the KeyEncodedValuePair with the highest Seqno s1 <= 59 // s which was stored at position p (similarly to LookupNode). 60 LookupKEVPair(c logger.ContextInterface, t Transaction, s Seqno, k Key) (val EncodedValue, s1 Seqno, err error) 61 62 // LookupKeyHashPairsUnderPosition returns all KeyEncodedValuePairs (ordered by 63 // Key) which were stored at a position p' which is a descendent of p and at 64 // the maximum Seqno s' <= s (similarly to LookupNode). For each such pair, 65 // it returns the Seqno at which it was stored (in the same order). 66 LookupKEVPairsUnderPosition(ctx logger.ContextInterface, t Transaction, s Seqno, p *Position) ([]KeyEncodedValuePair, []Seqno, error) 67 68 // LookupAllKEVPairs returns all the keys and encoded values at the specified Seqno. 69 LookupAllKEVPairs(ctx logger.ContextInterface, t Transaction, s Seqno) ([]KeyEncodedValuePair, error) 70 } 71 72 // StorageEngineWithBlinding extends the StorageEngine interface with methods to 73 // support storing and retrieving the blinding secrets. 74 type StorageEngineWithBlinding interface { 75 StorageEngine 76 77 StoreMasterSecret(ctx logger.ContextInterface, t Transaction, s Seqno, ms MasterSecret) error 78 LookupMasterSecrets(ctx logger.ContextInterface, t Transaction, s []Seqno) (map[Seqno]MasterSecret, error) 79 } 80 81 // Transaction references a DB transaction. 82 type Transaction interface{} 83 84 type GetValueWithProofResponse struct { 85 _struct struct{} `codec:",toarray"` //nolint 86 Value EncodedValue `codec:"v"` 87 Proof MerkleInclusionProof `codec:"r,omitempty"` 88 }