feat(primitives)!: typed Swarm spec primitives + signing layout#40
Merged
Conversation
5eadcac to
d6ef3ba
Compare
d6ef3ba to
c7ce2d8
Compare
c0aecfa to
ad1563a
Compare
Adds the canonical Swarm spec/wire primitives so vertex, apiarist, and
future Swarm implementations consume them from one place instead of
duplicating consts.
Bundles:
- Typed newtypes (nonce, network_id, timestamp, proximity_order, bin):
Nonce(B256), NetworkId(u64), Timestamp(i64), ProximityOrder(u8), Bin(u8).
NetworkId::{MAINNET, TESTNET} consts; Timestamp::now + skew_check;
range-validated ProximityOrder/Bin with named thiserror enums.
- compute_overlay(eth, net, nonce) -> SwarmAddress in overlay.rs:
canonical keccak256(eth || net.to_le || nonce) per bee
crypto/crypto.go:45-57. Network ID is little-endian here; tests pin
the LE-vs-BE distinction.
- SwarmAddress proximity API typed: proximity() now returns
ProximityOrder (was u8). Adds xor() and bin(&anchor) -> Bin.
Breaking change to the primitives crate.
- SwarmSpec trait in spec.rs with default methods sourcing bee's
canonical knobs (saturation_peers=8, over_saturation=18,
bootnode_over_saturation=20, neighborhood_low_watermark=2,
clock_skew_tolerance=6h). StaticSpec, MAINNET, TESTNET.
- recompute_neighborhood_depth in neighborhood_depth.rs: pure function
port of bee kademlia.go:896-920. Routing-layer wrappers stay with
each downstream impl; nectar owns just the math.
- signing.rs: SIGN_DATA_PREFIX and sign_data(...) builder for the
canonical BzzAddress sign-data byte layout per bee
bzz/address.go:138-160. Transport-agnostic, caller passes
underlay_bytes as raw wire bytes. Signing and recovery are NOT wrapped;
callers use alloy's signer.sign_message_sync /
Signature::recover_address_from_msg directly.
ad1563a to
b08e09d
Compare
Member
Author
|
Follow-up: #42 tracks consolidating the bee source citations introduced here into a single reference doc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the canonical Swarm spec / wire primitives into nectar so vertex, apiarist, and future Swarm implementations consume one source of truth instead of duplicating consts.
Bundles
Nonce(B256),NetworkId(u64),Timestamp(i64),ProximityOrder(u8),Bin(u8). Range-validated.NetworkId::{MAINNET, TESTNET}consts.compute_overlay(eth, net, nonce)inoverlay.rs: canonicalkeccak256(eth || net.to_le || nonce)per beecrypto/crypto.go:45-57. Network ID is little-endian here; tests pin the LE-vs-BE distinction.SwarmAddressproximity API typed:proximity()now returnsProximityOrder(wasu8). Newxor()andbin(&anchor) -> Bin. Breaking change to the primitives crate public API.SwarmSpectrait inspec.rswith default methods sourcing bee's canonical knobs (saturation_peers=8, over_saturation=18, bootnode_over_saturation=20, neighborhood_low_watermark=2, clock_skew_tolerance=6h).StaticSpec,MAINNET,TESTNET.recompute_neighborhood_depth: pure function port of beekademlia.go:896-920. Routing-layer wrappers stay with each downstream impl; nectar owns the math.signing.rs:SIGN_DATA_PREFIXandsign_data(...)builder for the canonical BzzAddress sign-data byte layout per beebzz/address.go:138-160. Transport-agnostic (caller passesunderlay_bytesas raw bytes; no libp2p dep). Signing and recovery are not wrapped, callers use alloy'ssigner.sign_message_sync/Signature::recover_address_from_msgdirectly.Design notes
From/Into/AsRefwhere possible.Nonce::random()lives unconditionally (alloy'sgetrandomfeature added to non-wasm primitives deps).SwarmAddress::proximity()return type change is the only breaking surface; primitives version should bump.Test plan
cargo test -p nectar-primitives --all-features --no-fail-fast: 196 passed (180 lib + 16 doc + new module tests for nonce, network_id, timestamp, proximity_order, bin, overlay, spec, neighborhood_depth, signing).cargo clippy -p nectar-primitives --all-features --lib: no new lints from new modules (pre-existinggeneric_arraydeprecation in bmt remains; will be fixed in a separate deps-bump PR that this one rebases on).