Skip to content

Commit 00e3569

Browse files
zhangfengcdtclaude
andauthored
Add comprehensive type stubs for VersionedKvStore proof and merge functionality (#102)
* Add generate_proof and verify_proof methods to VersionedKvStore Expose cryptographic proof functionality from ProllyTree to VersionedKvStore in both Rust and Python APIs for consistent proof generation and verification across versioned key-value operations. ## Changes ### Rust Implementation - Add `generate_proof(&self, key: &[u8]) -> Proof<N>` to VersionedKvStore - Add `verify(&self, proof: Proof<N>, key: &[u8], expected_value: Option<&[u8]>) -> bool` - Both methods delegate to underlying ProllyTree implementation - Add comprehensive unit test `test_versioned_store_proof_methods` ### Python Bindings - Add `generate_proof(key: bytes) -> bytes` to PyVersionedKvStore - Add `verify_proof(proof_bytes: bytes, key: bytes, expected_value: Optional[bytes]) -> bool` - Handle proof serialization/deserialization with bincode - Thread-safe implementation with proper GIL handling ## API Usage ```python store = VersionedKvStore.open("/path/to/repo") proof = store.generate_proof(b"key1") is_valid = store.verify_proof(proof, b"key1", b"value1") ``` 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Update Python README to document VersionedKvStore proof methods Add documentation for the newly added generate_proof and verify_proof methods in the VersionedKvStore example section. Also update the cryptographic verification feature description to clarify it's available for both trees and versioned storage. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Add comprehensive type stubs for VersionedKvStore proof and merge functionality Update Python type stubs (.pyi) to include the newly added proof methods and previously missing merge functionality for better IDE support and type checking. ## Added Type Stubs ### VersionedKvStore Methods - `generate_proof(key: bytes) -> bytes` - Generate cryptographic proofs - `verify_proof(proof: bytes, key: bytes, expected_value: Optional[bytes]) -> bool` - Verify proofs - `get_commits_for_key(key: bytes) -> List[Dict[str, Union[str, int]]]` - Get key history - `get_commit_history() -> List[Dict[str, Union[str, int]]]` - Get repository history - `merge(source_branch: str, conflict_resolution: Optional[ConflictResolution]) -> str` - Merge branches - `try_merge(source_branch: str) -> Tuple[bool, List[MergeConflict]]` - Attempt merge with conflict detection ### New Classes - `MergeConflict` - Represents merge conflicts with key, base_value, source_value, destination_value properties - `ConflictResolution` - Enum with IgnoreAll, TakeSource, TakeDestination strategies These additions ensure comprehensive IDE support and type checking for all VersionedKvStore functionality including the newly added proof methods. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 4393ba6 commit 00e3569

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

python/prollytree/prollytree.pyi

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,35 @@ class StorageBackend:
289289

290290
def __str__(self) -> str: ...
291291

292+
class MergeConflict:
293+
"""Represents a merge conflict between branches"""
294+
295+
@property
296+
def key(self) -> bytes:
297+
"""The key that has a conflict"""
298+
...
299+
300+
@property
301+
def base_value(self) -> Optional[bytes]:
302+
"""The value in the common base commit"""
303+
...
304+
305+
@property
306+
def source_value(self) -> Optional[bytes]:
307+
"""The value in the source branch"""
308+
...
309+
310+
@property
311+
def destination_value(self) -> Optional[bytes]:
312+
"""The value in the destination branch"""
313+
...
314+
315+
class ConflictResolution:
316+
"""Enum representing different conflict resolution strategies"""
317+
IgnoreAll: "ConflictResolution"
318+
TakeSource: "ConflictResolution"
319+
TakeDestination: "ConflictResolution"
320+
292321
class VersionedKvStore:
293322
"""A versioned key-value store backed by Git and ProllyTree"""
294323

@@ -442,6 +471,61 @@ class VersionedKvStore:
442471
"""
443472
...
444473

474+
def get_commits_for_key(self, key: bytes) -> List[Dict[str, Union[str, int]]]:
475+
"""
476+
Get all commits that contain changes to a specific key.
477+
478+
Args:
479+
key: The key to search for
480+
481+
Returns:
482+
List of commit dictionaries with id, author, committer, message, and timestamp
483+
"""
484+
...
485+
486+
def get_commit_history(self) -> List[Dict[str, Union[str, int]]]:
487+
"""
488+
Get the commit history for the repository.
489+
490+
Returns:
491+
List of commit dictionaries with id, author, committer, message, and timestamp
492+
"""
493+
...
494+
495+
def merge(
496+
self,
497+
source_branch: str,
498+
conflict_resolution: Optional[ConflictResolution] = None
499+
) -> str:
500+
"""
501+
Merge another branch into the current branch.
502+
503+
Args:
504+
source_branch: Name of the branch to merge from
505+
conflict_resolution: Strategy for resolving conflicts (default: IgnoreAll)
506+
507+
Returns:
508+
The commit ID of the merge commit
509+
510+
Raises:
511+
ValueError: If merge fails or has unresolved conflicts
512+
"""
513+
...
514+
515+
def try_merge(self, source_branch: str) -> Tuple[bool, List[MergeConflict]]:
516+
"""
517+
Attempt to merge another branch and return any conflicts.
518+
519+
Args:
520+
source_branch: Name of the branch to merge from
521+
522+
Returns:
523+
Tuple of (success, conflicts) where:
524+
- success: True if merge succeeded, False if there were conflicts
525+
- conflicts: List of MergeConflict objects if success is False
526+
"""
527+
...
528+
445529
def storage_backend(self) -> StorageBackend:
446530
"""
447531
Get the current storage backend type.
@@ -450,3 +534,34 @@ class VersionedKvStore:
450534
Storage backend enum value
451535
"""
452536
...
537+
538+
def generate_proof(self, key: bytes) -> bytes:
539+
"""
540+
Generate a cryptographic proof for a key's existence and value in the versioned store.
541+
542+
Args:
543+
key: The key to generate proof for
544+
545+
Returns:
546+
Serialized proof as bytes
547+
"""
548+
...
549+
550+
def verify_proof(
551+
self,
552+
proof: bytes,
553+
key: bytes,
554+
expected_value: Optional[bytes] = None
555+
) -> bool:
556+
"""
557+
Verify a cryptographic proof for a key-value pair in the versioned store.
558+
559+
Args:
560+
proof: The serialized proof to verify
561+
key: The key that the proof claims to prove
562+
expected_value: Optional expected value to verify against
563+
564+
Returns:
565+
True if the proof is valid, False otherwise
566+
"""
567+
...

0 commit comments

Comments
 (0)