8.0.10 • Published 8 months ago

@libp2p/peer-record v8.0.10

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
8 months ago

@libp2p/peer-record

libp2p.io Discuss codecov CI

Used to transfer signed peer data across the network

About

Libp2p nodes need to store data in a public location (e.g. a DHT), or rely on potentially untrustworthy intermediaries to relay information over its lifetime. Accordingly, libp2p nodes need to be able to verify that the data came from a specific peer and that it hasn't been tampered with.

Envelope

Libp2p provides an all-purpose data container called envelope. It was created to enable the distribution of verifiable records, which we can prove originated from the addressed peer itself. The envelope includes a signature of the data, so that its authenticity is verified.

This envelope stores a marshaled record implementing the interface-record. These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers.

You can read further about the envelope in RFC 0002 - Signed Envelopes. For the original discussion about it you can look at the PR that was used to create it: libp2p/specs#217.

Example - Creating a peer record

Create an envelope with an instance of an interface-record implementation and prepare it for being exchanged:

import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
import { generateKeyPair } from '@libp2p/crypto/keys'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'

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

const record = new PeerRecord({
   peerId,
  // ...other data
})

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

Example - Consuming a peer record

Consume a received envelope wireData and transform it back to a record:

import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'

const wireData = Uint8Array.from([0, 1, 2, 3, 4])
const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN)

const record = PeerRecord.createFromProtobuf(envelope.payload)

Peer Record

All libp2p nodes keep a PeerStore, that among other information stores a set of known addresses for each peer, which can come from a variety of sources.

Libp2p peer records were created to enable the distribution of verifiable address records, which we can prove originated from the addressed peer itself. With such guarantees, libp2p is able to prioritize addresses based on their authenticity, with the most strict strategy being to only dial certified addresses (no strategies have been implemented at the time of writing).

A peer record contains the peers' publicly reachable listen addresses, and may be extended in the future to contain additional metadata relevant to routing. It also contains a seqNumber field, a timestamp per the spec, so that we can verify the most recent record.

You can read further about the Peer Record in RFC 0003 - Peer Routing Records. For the original discussion about it you can view the PR that created the RFC: libp2p/specs#217.

Example

Create a new Peer Record

import { PeerRecord } from '@libp2p/peer-record'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { generateKeyPair } from '@libp2p/crypto/keys'
import { multiaddr } from '@multiformats/multiaddr'

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

const record = new PeerRecord({
  peerId: peerId,
  multiaddrs: [
    multiaddr('/ip4/...'),
    multiaddr('/ip4/...')
  ]
})

Example

Create a Peer Record from a protobuf

import { PeerRecord } from '@libp2p/peer-record'

const data = Uint8Array.from([0, 1, 2, 3, 4])
const record = PeerRecord.createFromProtobuf(data)

Libp2p Flows

Self Record

Once a libp2p node has started and is listening on a set of multiaddrs, its own peer record can be created.

The identify service is responsible for creating the self record when the identify protocol kicks in for the first time. This record will be stored for future needs of the identify protocol when connecting with other peers.

Self record Updates

While creating peer records is fairly trivial, addresses are not static and might be modified at arbitrary times. This can happen via an Address Manager API, or even through AutoRelay/AutoNAT.

When a libp2p node changes its listen addresses, the identify service will be informed. Once that happens, the identify service creates a new self record and stores it. With the new record, the identify push/delta protocol will be used to communicate this change to the connected peers.

Subsystem receiving a record

Considering that a node can discover other peers' addresses from a variety of sources, Libp2p Peerstore can differentiate the addresses that were obtained through a signed peer record.

Once a record is received and its signature properly validated, its envelope is stored in the AddressBook in its byte representation. The seqNumber remains unmarshalled so that we can quickly compare it against incoming records to determine the most recent record.

The AddressBook Addresses will be updated with the content of the envelope with a certified property. This allows other subsystems to identify the known certified addresses of a peer.

Subsystem providing a record

Libp2p subsystems that exchange other peers information will provide the envelope that they received by those peers. As a result, other peers can verify if the envelope was really created by the addressed peer.

When a subsystem wants to provide a record, it will get it from the AddressBook, if it exists. Other subsystems are also able to provide the self record, since it is also stored in the AddressBook.

Future Work

  • Persistence only considering certified addresses?
  • Peers may not know their own addresses. It's often impossible to automatically infer one's own public address, and peers may need to rely on third party peers to inform them of their observed public addresses.
  • A peer may inadvertently or maliciously sign an address that they do not control. In other words, a signature isn't a guarantee that a given address is valid.
  • Some addresses may be ambiguous. For example, addresses on a private subnet are valid within that subnet but are useless on the public internet.
  • Once all these pieces are in place, we will also need a way to prioritize addresses based on their authenticity, that is, the dialer can prioritize self-certified addresses over addresses from an unknown origin.
  • Modular dialer? (taken from go PR notes)
    • With the modular dialer, users should easily be able to configure precedence. With dialer v1, anything we do to prioritise dials is gonna be spaghetti and adhoc. With the modular dialer, you’d be able to specify the order of dials when instantiating the pipeline.
    • Multiple parallel dials. We already have the issue where new addresses aren't added to existing dials.

Install

$ npm i @libp2p/peer-record

Browser <script> tag

Loading this module through a script tag will make it's exports available as Libp2pPeerRecord in the global namespace.

<script src="https://unpkg.com/@libp2p/peer-record/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

8.0.10-c2ff2e454

8 months ago

8.0.10-0a3406a05

8 months ago

8.0.9-7383821e1

9 months ago

8.0.10

9 months ago

8.0.9-d34642db1

9 months ago

8.0.9-a657bbd2e

9 months ago

8.0.10-a5cd8cfbe

9 months ago

8.0.10-ad5cfd66a

9 months ago

8.0.9-717731e49

9 months ago

8.0.8-aa8de9fd3

9 months ago

8.0.8-3bc9769b8

9 months ago

8.0.8-3244ed086

9 months ago

8.0.8-4521cf1f7

9 months ago

8.0.9

9 months ago

8.0.8-e6b4158c6

9 months ago

8.0.8-75301ac7d

9 months ago

8.0.5-dad979f9b

10 months ago

8.0.8-5d199f9b6

9 months ago

8.0.6-58784abf7

10 months ago

8.0.7-d7a818e8e

9 months ago

8.0.6-661d6586a

9 months ago

8.0.7-0d326d102

9 months ago

8.0.7-d4da56961

9 months ago

8.0.6-d9c7e0f7e

10 months ago

8.0.6-35b48025c

10 months ago

8.0.7-e99e8f448

9 months ago

8.0.5-a390db4a4

10 months ago

8.0.6-80e798cdc

9 months ago

8.0.7-934a891f9

9 months ago

8.0.6-24fa1d5af

10 months ago

8.0.5-82bd42bcf

10 months ago

8.0.6-b4f02a637

9 months ago

8.0.8

9 months ago

8.0.7

9 months ago

8.0.6

10 months ago

8.0.6-32c176fd5

10 months ago

8.0.6-27b2fa6b6

9 months ago

8.0.4-c5988cce8

10 months ago

8.0.4-0c5957836

10 months ago

8.0.4-980038477

10 months ago

8.0.5

10 months ago

8.0.4-fa83ee1c7

10 months ago

8.0.3-c258b35af

10 months ago

8.0.2-7f7ec82ae

10 months ago

8.0.2-b3272cfce

10 months ago

8.0.4

10 months ago

8.0.3

10 months ago

8.0.1-c628c44c5

10 months ago

8.0.1-21fe841f2

10 months ago

8.0.2

10 months ago

8.0.1-4fd7eb2e1

10 months ago

8.0.1-6ccbb06f0

10 months ago

8.0.1-34455b5f2

10 months ago

8.0.0-1210884ed

10 months ago

8.0.0-18dd3cb26

10 months ago

8.0.1

10 months ago

8.0.0-d101aac4b

10 months ago

7.0.25-71e5f7a5b

10 months ago

7.0.25-b6681bd25

10 months ago

7.0.25-c010d575c

10 months ago

7.0.25-81ebe4e47

10 months ago

7.0.25-e1ca9cced

10 months ago

8.0.0-7cd984569

10 months ago

7.0.25-5214dec4a

10 months ago

7.0.25-2bbaf4361

10 months ago

7.0.25-a142bb642

10 months ago

8.0.0

10 months ago

7.0.25-df330695a

10 months ago

7.0.25-dd7b329c4

10 months ago

7.0.25-2265e59ba

10 months ago

7.0.25-737b3ea5b

10 months ago

7.0.25-1675adee2

11 months ago

7.0.25-e211b46cc

11 months ago

7.0.25-7655e5200

11 months ago

7.0.25-50b897139

11 months ago

7.0.24-c5dba70a9

11 months ago

7.0.19

1 year ago

7.0.24-7939dbd5c

11 months ago

7.0.23-944935f8d

12 months ago

7.0.21-e9b6a242a

12 months ago

7.0.24-1dfb74e79

11 months ago

7.0.22-8b3114292

12 months ago

7.0.22-a82ff8221

12 months ago

7.0.22-73f2b6b6d

12 months ago

7.0.22-a130993ed

12 months ago

7.0.24-0edbfe7af

11 months ago

7.0.22-a8ec2bcb7

12 months ago

7.0.25-359265a3a

11 months ago

7.0.25-3c8dd5bbf

11 months ago

7.0.22-4a994c5ef

12 months ago

7.0.22-928801a80

12 months ago

7.0.23

12 months ago

7.0.24

11 months ago

7.0.21

1 year ago

7.0.22

12 months ago

7.0.20

1 year ago

7.0.19-44791342

1 year ago

7.0.25

11 months ago

7.0.23-f30e2ee8d

11 months ago

7.0.22-40902d99b

12 months ago

7.0.22-34cf1f7cd

12 months ago

7.0.18

1 year ago

7.0.17

1 year ago

7.0.16

1 year ago

7.0.15

1 year ago

7.0.14

1 year ago

7.0.13

1 year ago

7.0.12

1 year ago

7.0.11

1 year ago

7.0.10

1 year ago

7.0.9-f0d2b52d0

1 year ago

7.0.9-e1c01370b

1 year ago

7.0.9-bedfd0aa2

1 year ago

7.0.9-8072a2e59

1 year ago

7.0.9-b1b77adb4

1 year ago

7.0.9-fb7c51c3c

1 year ago

7.0.7-03ff9fd82

1 year ago

7.0.7-1cb2408ac

1 year ago

7.0.7-9891ecd73

1 year ago

7.0.7-2370d1c39

1 year ago

7.0.7-0321812e7

1 year ago

7.0.8-0c7bbbb07

1 year ago

7.0.8

1 year ago

7.0.9

1 year ago

7.0.7-dab5cf724

1 year ago

7.0.7-e1db332a4

1 year ago

7.0.7-6f323de7d

1 year ago

7.0.7-c9ed1c7d6

1 year ago

7.0.6-dbc92ab74

1 year ago

7.0.6-2e464c099

1 year ago

7.0.7

1 year ago

7.0.6-74fb5671d

1 year ago

7.0.6-f4dda4a3c

1 year ago

7.0.6-72f0e09f7

1 year ago

7.0.6-8c6654c3a

1 year ago

7.0.6-f27138ca1

1 year ago

7.0.6-08f6f607d

1 year ago

7.0.6-74477f6ea

1 year ago

7.0.6-9376e61a1

1 year ago

7.0.6-3e47d88fd

1 year ago

7.0.6

1 year ago

7.0.5-092861e23

1 year ago

7.0.5-8bbd43628

1 year ago

7.0.5

2 years ago

7.0.4-ddaa59a60

2 years ago

7.0.4-856ccd708

2 years ago

7.0.4-4691f4173

2 years ago

7.0.4-ee7ffe9b9

2 years ago

7.0.4-900236724

2 years ago

7.0.4-821a38e24

2 years ago

7.0.3-528d73781

2 years ago

7.0.3-d011f6130

2 years ago

7.0.3-581574d6d

2 years ago

7.0.4

2 years ago

7.0.3-444d83751

2 years ago

7.0.3-388d02b33

2 years ago

7.0.3-ba7089984

2 years ago

7.0.3

2 years ago

7.0.2-28587d24f

2 years ago

7.0.2-5d1f68e92

2 years ago

7.0.2-4e0135c7d

2 years ago

7.0.2-6fd681d09

2 years ago

7.0.2-cd8cafcd5

2 years ago

7.0.2-c00378909

2 years ago

7.0.2-178fe2671

2 years ago

7.0.2-83dfc7dc8

2 years ago

7.0.1-07f3afe2d

2 years ago

7.0.1-ad6f70bf3

2 years ago

7.0.1-f71f2e14e

2 years ago

7.0.1-984f13e42

2 years ago

7.0.2

2 years ago

7.0.1-a7c6a93c6

2 years ago

7.0.1-230afea4b

2 years ago

7.0.1-9eff7eff0

2 years ago

7.0.1-f81be145a

2 years ago

7.0.1-01e9a5fe4

2 years ago

7.0.1

2 years ago

7.0.1-742915567

2 years ago

7.0.0-341581166

2 years ago

7.0.0-6d11e8268

2 years ago

7.0.0-d10506189

2 years ago

7.0.0-64a915ae9

2 years ago

7.0.0-3bf6387ff

2 years ago

7.0.0-93890c8f9

2 years ago

7.0.0-16588d27c

2 years ago

7.0.0-887c6ffe1

2 years ago

6.0.8-70d5efc2e

2 years ago

6.0.6-cf3ae893

2 years ago

6.0.8-dfbe0cc0

2 years ago

6.0.3-725f5df1

2 years ago

6.0.8-051154dd

2 years ago

5.0.4-c2232166

2 years ago

6.0.3-9a69e6f7

2 years ago

5.0.4-5315f7bc

2 years ago

6.0.5-e9099d40

2 years ago

6.0.0-72e81dc1

2 years ago

6.0.3-10cbc8fa

2 years ago

6.0.4-d9159dd5

2 years ago

6.0.3-32825633

2 years ago

6.0.5-b57bca44

2 years ago

6.0.3-0634e3b7

2 years ago

6.0.2-18567b7c

2 years ago

6.0.1-446fff87

2 years ago

6.0.3-6abcd22f

2 years ago

6.0.6-68504939

2 years ago

6.0.0-e66f4891

2 years ago

6.0.8-8b82e68e8

2 years ago

6.0.9-4a474d54d

2 years ago

6.0.6-b5a808af

2 years ago

6.0.5-f09ac4a7

2 years ago

6.0.7-b686fb5a

2 years ago

6.0.0-8f855a3c

2 years ago

6.0.0-58421e11

2 years ago

5.0.4-eabf6f36

2 years ago

6.0.9-68db79f6b

2 years ago

6.0.12

2 years ago

6.0.11

2 years ago

6.0.10

2 years ago

6.0.2-5e85154b

2 years ago

5.0.4-7debe031

2 years ago

6.0.2-a31b420f

2 years ago

6.0.5-f1053159

2 years ago

6.0.3-24a5edae

2 years ago

6.0.7-16a87076

2 years ago

6.0.6-ab2c1f67

2 years ago

6.0.0-5ffa7a74

2 years ago

6.0.9-9ad8f8686

2 years ago

6.0.2-123ded59

2 years ago

6.0.3-24c1c248

2 years ago

6.0.3-f3fd7b62

2 years ago

5.0.4-562f9b08

2 years ago

6.0.8-fdcb801e

2 years ago

6.0.3-6a02d765

2 years ago

6.0.3-46dc3ce9

2 years ago

6.0.11-cf963694f

2 years ago

6.0.5-28794fe4

2 years ago

5.0.4-a41d25d4

2 years ago

6.0.2-32212959

2 years ago

6.0.7-7903d7a5

2 years ago

6.0.3-b599905c

2 years ago

6.0.5-c97dea04

2 years ago

6.0.7-025c082a

2 years ago

6.0.3-87dc7e9f

2 years ago

6.0.5-6640116d

2 years ago

6.0.9-8f921ee97

2 years ago

6.0.5-e3ab1929

2 years ago

6.0.9-c960eb659

2 years ago

6.0.4-122f1e67

2 years ago

6.0.3-7b2ddc17

2 years ago

6.0.11-8c169db1b

2 years ago

6.0.9-8bb6d5333

2 years ago

6.0.9-3dee5df4d

2 years ago

6.0.5-7d8b1551

2 years ago

6.0.8-d25d9510

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

6.0.2-e26848b0

2 years ago

6.0.9

2 years ago

6.0.8

2 years ago

6.0.2-364e0592

2 years ago

6.0.4-4db2f5f5

2 years ago

5.0.4-5eee70a4

2 years ago

6.0.3-a6be8f0f

2 years ago

6.0.2-a1fbb7e2

2 years ago

6.0.4-0ee4f784

2 years ago

6.0.5-ae36e86b

2 years ago

7.0.0-bcfa15993

2 years ago

6.0.4-0ce318ec

2 years ago

6.0.9-74e84bc29

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.5-6cb80f7d

2 years ago

6.0.2

2 years ago

6.0.5

2 years ago

6.0.0-a4a10fd4

2 years ago

6.0.4

2 years ago

6.0.2-eaac8943

2 years ago

5.0.4-7f60b579

2 years ago

6.0.11-6c1f0ee81

2 years ago

6.0.8-78db573f9

2 years ago

6.0.10-06e6d235f

2 years ago

6.0.5-96166ada

2 years ago

6.0.2-3345f28b

2 years ago

6.0.9-bb6ceb192

2 years ago

6.0.9-97ab31c0c

2 years ago

7.0.0-10ea19700

2 years ago

5.0.4-57c32721

2 years ago

6.0.10-a32e70bac

2 years ago

6.0.10-273d8177c

2 years ago

6.0.9-7877a50e0

2 years ago

6.0.0-c858ca7f

2 years ago

6.0.9-0f5c305af

2 years ago

5.0.4-1f7e18b0

2 years ago

6.0.8-f4fac961

2 years ago

6.0.9-05b52d69c

2 years ago

6.0.11-f537b3731

2 years ago

6.0.11-9197f10ba

2 years ago

6.0.7-69581367

2 years ago

6.0.10-7682861f9

2 years ago

6.0.3-87165551

2 years ago

6.0.3-d30f09f2

2 years ago

7.0.0-09dd02987

2 years ago

6.0.10-8e4fbe13a

2 years ago

6.0.0-fdd80820

2 years ago

5.0.4-791f56f0

2 years ago

6.0.9-9c67c5b3d

2 years ago

5.0.4-e9cafd3d

2 years ago

6.0.9-effcfaa8e

2 years ago

6.0.7-50442d7a

2 years ago

6.0.11-53224004f

2 years ago

6.0.9-d8f5bc211

2 years ago

5.0.4-6eab9c5e

2 years ago

6.0.3-a533cc39

2 years ago

6.0.3-5294f14c

2 years ago

6.0.3-2b755a82

2 years ago

6.0.0-ef83dd1d

2 years ago

6.0.5-5a6a4379

2 years ago

5.0.4-69c93ac5

2 years ago

6.0.11-561797a89

2 years ago

7.0.0

2 years ago

6.0.3-7517082d

2 years ago

5.0.4-a1ec46b5

2 years ago

6.0.0-8d49602f

2 years ago

6.0.4-20d5f220

2 years ago

6.0.8-1d141331a

2 years ago

6.0.3-89778624

2 years ago

6.0.7-d5ef1c91

2 years ago

6.0.0-8f681db3

2 years ago

6.0.5-980857c3

2 years ago

6.0.5-91842c93

2 years ago

6.0.11-738dd40f1

2 years ago

6.0.3-13f5b48e

2 years ago

6.0.9-adea7bbbf

2 years ago

6.0.4-88c47f51

2 years ago

7.0.0-5a9362e21

2 years ago

6.0.5-972b10a9

2 years ago

5.0.4-b1024c6c

2 years ago

6.0.6-62a56b54

2 years ago

6.0.6-77e3cbc3

2 years ago

6.0.8-fb8a6f188

2 years ago

6.0.5-72319fe6

2 years ago

6.0.3-4559a624

2 years ago

6.0.3-73b87c5a

2 years ago

5.0.4-06f4901a

2 years ago

5.0.4-b36ec7f2

2 years ago

6.0.9-e2267d437

2 years ago

6.0.2-02b89323

2 years ago

6.0.3-d9948596

2 years ago

6.0.2-4c1a33b3

2 years ago

6.0.9-6625a27fc

2 years ago

6.0.3-4ef9c79c

2 years ago

5.0.4-7b5c54dd

2 years ago

6.0.7-346ff5a2

2 years ago

6.0.3-0d228f9f

2 years ago

6.0.3-28d6722f

2 years ago

6.0.3-e664d14f

2 years ago

6.0.11-7861ed882

2 years ago

6.0.3-63041afe

2 years ago

6.0.9-13a870cbe

2 years ago

6.0.6-50f912c2

2 years ago

6.0.11-e7167fe52

2 years ago

6.0.3-098ba082

2 years ago

6.0.5-c88de8e1

2 years ago

6.0.2-9c0353cf

2 years ago

6.0.5-e8123d3f

2 years ago

5.0.4-daeb43d8

2 years ago

6.0.10-bcf18265e

2 years ago

6.0.3-01acccef

2 years ago

6.0.9-0b4a2ee79

2 years ago

6.0.10-551622a96

2 years ago

6.0.11-bca8d6e68

2 years ago

6.0.6-f9d1c072

2 years ago

6.0.9-d729d66a5

2 years ago

5.0.4-c999d6a7

2 years ago

6.0.5-f670307a

2 years ago

6.0.2-6b839807

2 years ago

6.0.9-6b6ba9ab7

2 years ago

6.0.6-7534ae7b

2 years ago

6.0.3-c4eff4c5

2 years ago

5.0.4-3dfc236e

2 years ago

5.0.4

2 years ago

5.0.4-8b0e6bef

2 years ago

5.0.4-879f4794

2 years ago

5.0.4-7fb23cd3

2 years ago

5.0.4-f427cfc9

2 years ago

5.0.4-ea8a0637

2 years ago

5.0.4-d853d124

2 years ago

5.0.4-05abd49f

2 years ago

5.0.4-42c1c097

2 years ago

5.0.4-ab0e3980

2 years ago

5.0.4-2e561fe9

2 years ago

5.0.4-85a317bb

2 years ago

5.0.4-6fdaa7dc

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

3 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

3.0.0

3 years ago

2.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.9

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.0

3 years ago