-
Notifications
You must be signed in to change notification settings - Fork 204
feat(kad-dht): implement IPNS validator for DHT record validation #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add IPNS protobuf definition (IpnsEntry message) - Implement IPNSValidator class following IPNS spec - Integrate IPNS validator with DHT (apply_fallbacks, validate_config) - Add cbor2 dependency for DAG-CBOR decoding - Add comprehensive tests (19 test cases) Closes libp2p#1157 Signed-off-by: asmit27rai <raiasmit10@gmail.com>
|
@asmit27rai Please fix the CI CD issues. |
|
@asmit27rai the lint ci nonetype errors are fixed, The pyrefly type checker wasn't properly narrowing the type of self.validator after the isinstance check, because instance attributes can theoretically be reassigned between the check and usage. So I Assigned self.validator to a local variable after the type guard. This helps the type checker understand that the local variable validator is definitively a NamespacedValidator and cannot be modified, allowing safe access to _validators. # Use a local variable to help type checker narrow the type
validator = self.validator
# Add missing default validators
if "pk" not in validator._validators:
validator._validators["pk"] = PublicKeyValidator()
if "ipns" not in validator._validators:
validator._validators["ipns"] = IPNSValidator()The last remaining ci check is not related to yours it is already addressed and I'm currently working on a fix for that, For more info read this discussion #1166 |
|
@sumanjeet0012 You can review it. |
…ces" This reverts commit ae34859.
- Add ParsedIPNSRecord dataclass for structured record inspection - Add ValidityType enum for type-safe validity type constants - Add configurable expiration checking (check_expiration parameter) - Add validate_with_details() method returning parsed record data - Add comprehensive CBOR structure validation: - Required field checks (Value, Validity, ValidityType, Sequence) - Type validation for all CBOR fields - Range checks for sequence and TTL (non-negative, uint64 max) - Empty value detection - RFC3339 timestamp format validation with regex - Value prefix warnings for non-standard paths - Improve error messages with more descriptive context - Add constants for CBOR field names to reduce typos - Extract _parse_rfc3339() helper for reusable timestamp parsing - Improve select() method with proper datetime comparison
Summary
Implement IPNS (InterPlanetary Naming System) validator for the Kademlia DHT, enabling py-libp2p to validate IPNS records according to the IPNS Record Specification.
IPNS provides mutable pointers to content-addressed data, essential for interoperability with IPFS nodes using go-libp2p and js-libp2p.
Changes
New Files
libp2p/records/pb/ipns.proto- IPNS protobuf definitionlibp2p/records/pb/ipns_pb2.py- Generated protobuf codelibp2p/records/pb/__init__.py- Package exportslibp2p/records/ipns.py-IPNSValidatorclass implementationtests/core/records/test_ipns_validator.py- Comprehensive tests (19 cases)Modified Files
libp2p/kad_dht/kad_dht.py- DHT integrationpyproject.toml- Addedcbor2dependencyImplementation Details
IPNSValidator validates records per IPNS spec §5.3:
signatureV2anddataare presentpubKeyfield or inlined Ed25519 in IPNS name)dataas DAG-CBORpubkey.verify("ipns-signature:" + cbor_data, signatureV2)Validityexpiration (RFC3339 timestamp with nanosecond support)