Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ libp2p = { version = "0.56.1", path = "libp2p" }
libp2p-allow-block-list = { version = "0.6.0", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.15.0", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.6.0", path = "misc/connection-limits" }
libp2p-core = { version = "0.43.1", path = "core" }
libp2p-core = { version = "0.44.0", path = "core" }
libp2p-dcutr = { version = "0.14.0", path = "protocols/dcutr" }
libp2p-dns = { version = "0.44.0", path = "transports/dns" }
libp2p-floodsub = { version = "0.47.0", path = "protocols/floodsub" }
Expand Down
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.44.0
- Update `libp2p::core::peer_record` Fix peer record domain and payload type to match Go/JS implementations.
See [PR 6205](https://github.com/libp2p/rust-libp2p/pull/6205).

## 0.43.1
- Remove `once_cell` dependency.
See [PR 5913](https://github.com/libp2p/rust-libp2p/pull/5913)
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-core"
edition.workspace = true
rust-version = { workspace = true }
description = "Core traits and structs of libp2p"
version = "0.43.1"
version = "0.44.0"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
16 changes: 11 additions & 5 deletions core/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ use web_time::SystemTime;

use crate::{proto, signed_envelope, signed_envelope::SignedEnvelope, DecodeError, Multiaddr};

const PAYLOAD_TYPE: &str = "/libp2p/routing-state-record";
const DOMAIN_SEP: &str = "libp2p-routing-state";
// The type hint used to identify peer records in an Envelope.
// Defined in https://github.com/multiformats/multicodec/blob/master/table.csv
// with name "libp2p-peer-record"
const PAYLOAD_TYPE: &[u8] = &[0x03, 0x01];

// The domain string used for peer records contained in a Envelope.
// See https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md
const DOMAIN_SEP: &str = "libp2p-peer-record";

/// Represents a peer routing record.
///
Expand Down Expand Up @@ -33,7 +39,7 @@ impl PeerRecord {
use quick_protobuf::MessageRead;

let (payload, signing_key) =
envelope.payload_and_signing_key(String::from(DOMAIN_SEP), PAYLOAD_TYPE.as_bytes())?;
envelope.payload_and_signing_key(String::from(DOMAIN_SEP), PAYLOAD_TYPE)?;
let mut reader = BytesReader::from_bytes(payload);
let record = proto::PeerRecord::from_reader(&mut reader, payload).map_err(DecodeError)?;

Expand Down Expand Up @@ -95,7 +101,7 @@ impl PeerRecord {
let envelope = SignedEnvelope::new(
key,
String::from(DOMAIN_SEP),
PAYLOAD_TYPE.as_bytes().to_vec(),
PAYLOAD_TYPE.to_vec(),
payload,
)?;

Expand Down Expand Up @@ -196,7 +202,7 @@ mod tests {
SignedEnvelope::new(
&identity_b,
String::from(DOMAIN_SEP),
PAYLOAD_TYPE.as_bytes().to_vec(),
PAYLOAD_TYPE.to_vec(),
payload,
)
.unwrap()
Expand Down
117 changes: 117 additions & 0 deletions core/tests/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Test Fixtures for Cross-Implementation Interoperability



These fixtures are signed peer records generated by Go and JavaScript libp2p implementations,

used to test that Rust can verify records from other implementations.



## Directory Structure



```

fixtures/

├── README.md # This file

├── js/ # JavaScript fixture generator

│ ├── generate-fixture.js # Generation script

│ ├── package.json # Dependencies

│ └── js-signed-peer-record.bin # Generated fixture

└── go/ # Go fixture generator

├── generate-fixture.go # Generation script

├── go.mod # Dependencies

└── go-signed-peer-record.bin # Generated fixture

```



## Constants Used



Both implementations use the standard peer record constants:

- Domain: `"libp2p-peer-record"`

- Payload Type: `[0x03, 0x01]`



## How to Regenerate



### JavaScript Fixture



```bash

# Navigate to fixtures directory

cd core/tests/fixtures



# Install dependencies

npm install



# Generate fixture

node generate-js-fixture.js

```



This will create/update `js-signed-peer-record.bin`.



### Go Fixture



```bash

# Navigate to fixtures directory

cd core/tests/fixtures



# Generate fixture

go run generate-go-fixture.go

```



This will create/update `go-signed-peer-record.bin`.



## Purpose



These fixtures demonstrate that Rust libp2p can verify signed peer records created by

other libp2p implementations (JavaScript and Go), ensuring cross-implementation compatibility.
56 changes: 56 additions & 0 deletions core/tests/fixtures/go/generate-go-fixture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"fmt"
"os"

"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/record"
ma "github.com/multiformats/go-multiaddr"
)

func main() {
// Generate key
priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, -1)
if err != nil {
panic(err)
}

pid, err := peer.IDFromPrivateKey(priv)
if err != nil {
panic(err)
}

// Create multiaddr
addr, _ := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/4001")

// Create peer record
rec := &peer.PeerRecord{
PeerID: pid,
Addrs: []ma.Multiaddr{addr},
}

// Sign it
envelope, err := record.Seal(rec, priv)
if err != nil {
panic(err)
}

// Marshal to bytes
data, err := envelope.Marshal()
if err != nil {
panic(err)
}

// Write to file
err = os.WriteFile("go-signed-peer-record.bin", data, 0644)
if err != nil {
panic(err)
}

fmt.Println("Generated go-signed-peer-record.bin")
fmt.Println("PeerID:", pid.String())
fmt.Println("Domain:", peer.PeerRecordEnvelopeDomain)
fmt.Println("Payload Type:", peer.PeerRecordEnvelopePayloadType)
}
Binary file added core/tests/fixtures/go/go-signed-peer-record.bin
Binary file not shown.
28 changes: 28 additions & 0 deletions core/tests/fixtures/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module peer-record-fixtures

go 1.24.6

toolchain go1.24.10

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/ipfs/go-cid v0.5.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p/core v0.43.0-rc2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.16.1 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.1 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
golang.org/x/sys v0.33.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
)
42 changes: 42 additions & 0 deletions core/tests/fixtures/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/ipfs/go-cid v0.5.0 h1:goEKKhaGm0ul11IHA7I6p1GmKz8kEYniqFopaB5Otwg=
github.com/ipfs/go-cid v0.5.0/go.mod h1:0L7vmeNXpQpUS9vt+yEARkJ8rOg43DF3iPgn4GIN0mk=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-libp2p/core v0.43.0-rc2 h1:1X1aDJNWhMfodJ/ynbaGLkgnC8f+hfBIqQDrzxFZOqI=
github.com/libp2p/go-libp2p/core v0.43.0-rc2/go.mod h1:NYeJ9lvyBv9nbDk2IuGb8gFKEOkIv/W5YRIy1pAJB2Q=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE=
github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI=
github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0=
github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
github.com/multiformats/go-multiaddr v0.16.0 h1:oGWEVKioVQcdIOBlYM8BH1rZDWOGJSqr9/BKl6zQ4qc=
github.com/multiformats/go-multiaddr v0.16.0/go.mod h1:JSVUmXDjsVFiW7RjIFMP7+Ev+h1DTbiJgVeTV/tcmP0=
github.com/multiformats/go-multiaddr v0.16.1 h1:fgJ0Pitow+wWXzN9do+1b8Pyjmo8m5WhGfzpL82MpCw=
github.com/multiformats/go-multiaddr v0.16.1/go.mod h1:JSVUmXDjsVFiW7RjIFMP7+Ev+h1DTbiJgVeTV/tcmP0=
github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multicodec v0.9.1 h1:x/Fuxr7ZuR4jJV4Os5g444F7xC4XmyUaT/FWtE+9Zjo=
github.com/multiformats/go-multicodec v0.9.1/go.mod h1:LLWNMtyV5ithSBUo3vFIMaeDy+h3EbkMTek1m+Fybbo=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 h1:bsqhLWFR6G6xiQcb+JoGqdKdRU6WzPWmK8E0jxTjzo4=
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg=
lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo=
Binary file added core/tests/fixtures/js-signed-peer-record.bin
Binary file not shown.
25 changes: 25 additions & 0 deletions core/tests/fixtures/js/generate-js-fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// generate-js-fixture.js
import { generateKeyPair } from '@libp2p/crypto/keys';
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record';
import { multiaddr } from '@multiformats/multiaddr';
import fs from 'fs';

const privateKey = await generateKeyPair('Ed25519');
const peerId = peerIdFromPrivateKey(privateKey);

const record = new PeerRecord({
peerId,
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/4001')]
});

const envelope = await RecordEnvelope.seal(record, privateKey);
const wireData = envelope.marshal();

// Save to file
fs.writeFileSync('js-signed-peer-record.bin', wireData);

console.log('Generated js-signed-peer-record.bin');
console.log('PeerID:', peerId.toString());
console.log('Domain:', PeerRecord.DOMAIN);
console.log('Payload Type:', Array.from(PeerRecord.CODEC));
Binary file added core/tests/fixtures/js/js-signed-peer-record.bin
Binary file not shown.
Loading
Loading