7.0.16 • Published 1 day ago

@libp2p/peer-record v7.0.16

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
1 day ago

@libp2p/peer-record

libp2p.io Discuss codecov CI

Used to transfer signed peer data across the network

Table of contents

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>

Description

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 libp2p/specs#217.

Usage

  • create an envelope with an instance of an interface-record implementation and prepare it for being exchanged:
// interface-record implementation example with the "libp2p-example" namespace
import { PeerRecord } from '@libp2p/peer-record'
import { fromString } from 'uint8arrays/from-string'

class ExampleRecord extends PeerRecord {
  constructor () {
    super ('libp2p-example', fromString('0302', 'hex'))
  }

  marshal () {}

  equals (other) {}
}

ExampleRecord.createFromProtobuf = () => {}
import { PeerEnvelope } from '@libp2p/peer-record'
import { ExampleRecord } from './example-record.js'

const rec = new ExampleRecord()
const e = await PeerEnvelope.seal(rec, peerId)
const wireData = e.marshal()
  • consume a received envelope (wireData) and transform it back to a record:
import { PeerEnvelope } from '@libp2p/peer-record'
import { ExampleRecord } from './example-record.js'

const domain = 'libp2p-example'
let e

try {
  e = await PeerEnvelope.openAndCertify(wireData, domain)
} catch (err) {}

const rec = ExampleRecord.createFromProtobuf(e.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 libp2p/specs#217.

Usage

  • create a new Peer Record
import { PeerRecord } from '@libp2p/peer-record'

const pr = new PeerRecord({
  peerId: node.peerId,
  multiaddrs: node.multiaddrs
})
  • create a Peer Record from a protobuf
import { PeerRecord } from '@libp2p/peer-record'

const pr = 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

NOT_YET_IMPLEMENTED

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.

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.

7.0.16

8 days ago

7.0.15-e1923b0a7

12 days ago

7.0.15-998fcaf94

12 days ago

7.0.15-90cfd25e2

13 days ago

7.0.14-2281f802b

15 days ago

7.0.14-c2181f0cf

14 days ago

7.0.15

14 days ago

7.0.14-fd1f8343d

15 days ago

7.0.14-eaf8ac7cf

16 days ago

7.0.14-acef72613

17 days ago

7.0.14

22 days ago

7.0.14-ea4f26285

22 days ago

7.0.13-31c78f4ed

23 days ago

7.0.13-08dabd390

23 days ago

7.0.12-2c56203f9

26 days ago

7.0.13

26 days ago

7.0.12-b17824a1d

26 days ago

7.0.12-936dbba10

29 days ago

7.0.12-732c436d4

29 days ago

7.0.12-2b2958fe6

1 month ago

7.0.12

1 month ago

7.0.11-3e515f007

1 month ago

7.0.11-d446c6c31

1 month ago

7.0.11-a2b41f793

1 month ago

7.0.11-80278b36b

1 month ago

7.0.11-afe15f669

1 month ago

7.0.11-1f589c822

1 month ago

7.0.11-4fc0a7d30

1 month ago

7.0.11-ab5f05763

1 month ago

7.0.11-3ffecc5bf

1 month ago

7.0.10-59a97b61b

1 month ago

7.0.10-82901e785

1 month ago

7.0.11

1 month ago

7.0.10-bf720c045

1 month ago

7.0.10-1fc929c1c

1 month ago

7.0.10-330a5ed72

1 month ago

7.0.10-fad3074b8

2 months ago

7.0.10-f39ce5f13

2 months ago

7.0.10-e1798aa26

2 months ago

7.0.10-cad9cf007

2 months ago

7.0.10-83ef3717e

2 months ago

7.0.10-ab466004b

2 months ago

7.0.10-a9cc0ee49

2 months ago

7.0.10-28e51652a

2 months ago

7.0.10-2122a713d

2 months ago

7.0.10-f71bc49bd

2 months ago

7.0.10

2 months ago

7.0.9-f0d2b52d0

2 months ago

7.0.9-e1c01370b

3 months ago

7.0.9-bedfd0aa2

3 months ago

7.0.9-8072a2e59

3 months ago

7.0.9-b1b77adb4

3 months ago

7.0.9-fb7c51c3c

3 months ago

7.0.7-03ff9fd82

3 months ago

7.0.7-1cb2408ac

3 months ago

7.0.7-9891ecd73

3 months ago

7.0.7-2370d1c39

3 months ago

7.0.7-0321812e7

3 months ago

7.0.8-0c7bbbb07

3 months ago

7.0.8

3 months ago

7.0.9

3 months ago

7.0.7-dab5cf724

3 months ago

7.0.7-e1db332a4

3 months ago

7.0.7-6f323de7d

3 months ago

7.0.7-c9ed1c7d6

3 months ago

7.0.6-dbc92ab74

4 months ago

7.0.6-2e464c099

4 months ago

7.0.7

4 months ago

7.0.6-74fb5671d

4 months ago

7.0.6-f4dda4a3c

4 months ago

7.0.6-72f0e09f7

4 months ago

7.0.6-8c6654c3a

4 months ago

7.0.6-f27138ca1

4 months ago

7.0.6-08f6f607d

4 months ago

7.0.6-74477f6ea

4 months ago

7.0.6-9376e61a1

4 months ago

7.0.6-3e47d88fd

4 months ago

7.0.6

4 months ago

7.0.5-092861e23

4 months ago

7.0.5-8bbd43628

4 months ago

7.0.5

4 months ago

7.0.4-ddaa59a60

4 months ago

7.0.4-856ccd708

4 months ago

7.0.4-4691f4173

4 months ago

7.0.4-ee7ffe9b9

4 months ago

7.0.4-900236724

4 months ago

7.0.4-821a38e24

4 months ago

7.0.3-528d73781

4 months ago

7.0.3-d011f6130

4 months ago

7.0.3-581574d6d

4 months ago

7.0.4

4 months ago

7.0.3-444d83751

4 months ago

7.0.3-388d02b33

4 months ago

7.0.3-ba7089984

4 months ago

7.0.3

4 months ago

7.0.2-28587d24f

4 months ago

7.0.2-5d1f68e92

4 months ago

7.0.2-4e0135c7d

4 months ago

7.0.2-6fd681d09

5 months ago

7.0.2-cd8cafcd5

5 months ago

7.0.2-c00378909

5 months ago

7.0.2-178fe2671

5 months ago

7.0.2-83dfc7dc8

5 months ago

7.0.1-07f3afe2d

5 months ago

7.0.1-ad6f70bf3

5 months ago

7.0.1-f71f2e14e

5 months ago

7.0.1-984f13e42

5 months ago

7.0.2

5 months ago

7.0.1-a7c6a93c6

5 months ago

7.0.1-230afea4b

5 months ago

7.0.1-9eff7eff0

5 months ago

7.0.1-f81be145a

5 months ago

7.0.1-01e9a5fe4

5 months ago

7.0.1

5 months ago

7.0.1-742915567

5 months ago

7.0.0-341581166

5 months ago

7.0.0-6d11e8268

5 months ago

7.0.0-d10506189

5 months ago

7.0.0-64a915ae9

5 months ago

7.0.0-3bf6387ff

5 months ago

7.0.0-93890c8f9

5 months ago

7.0.0-16588d27c

5 months ago

7.0.0-887c6ffe1

5 months ago

6.0.8-70d5efc2e

6 months ago

6.0.6-cf3ae893

7 months ago

6.0.8-dfbe0cc0

6 months ago

6.0.3-725f5df1

9 months ago

6.0.8-051154dd

6 months ago

5.0.4-c2232166

10 months ago

6.0.3-9a69e6f7

8 months ago

5.0.4-5315f7bc

10 months ago

6.0.5-e9099d40

7 months ago

6.0.0-72e81dc1

9 months ago

6.0.3-10cbc8fa

8 months ago

6.0.4-d9159dd5

8 months ago

6.0.3-32825633

8 months ago

6.0.5-b57bca44

7 months ago

6.0.3-0634e3b7

8 months ago

6.0.2-18567b7c

9 months ago

6.0.1-446fff87

9 months ago

6.0.3-6abcd22f

9 months ago

6.0.6-68504939

7 months ago

6.0.0-e66f4891

9 months ago

6.0.8-8b82e68e8

6 months ago

6.0.9-4a474d54d

6 months ago

6.0.6-b5a808af

7 months ago

6.0.5-f09ac4a7

8 months ago

6.0.7-b686fb5a

6 months ago

6.0.0-8f855a3c

9 months ago

6.0.0-58421e11

9 months ago

5.0.4-eabf6f36

9 months ago

6.0.9-68db79f6b

5 months ago

6.0.12

5 months ago

6.0.11

5 months ago

6.0.10

5 months ago

6.0.2-5e85154b

9 months ago

5.0.4-7debe031

10 months ago

6.0.2-a31b420f

9 months ago

6.0.5-f1053159

7 months ago

6.0.3-24a5edae

8 months ago

6.0.7-16a87076

6 months ago

6.0.6-ab2c1f67

7 months ago

6.0.0-5ffa7a74

9 months ago

6.0.9-9ad8f8686

6 months ago

6.0.2-123ded59

9 months ago

6.0.3-24c1c248

9 months ago

6.0.3-f3fd7b62

9 months ago

5.0.4-562f9b08

10 months ago

6.0.8-fdcb801e

6 months ago

6.0.3-6a02d765

9 months ago

6.0.3-46dc3ce9

8 months ago

6.0.11-cf963694f

5 months ago

6.0.5-28794fe4

7 months ago

5.0.4-a41d25d4

9 months ago

6.0.2-32212959

9 months ago

6.0.7-7903d7a5

6 months ago

6.0.3-b599905c

9 months ago

6.0.5-c97dea04

7 months ago

6.0.7-025c082a

6 months ago

6.0.3-87dc7e9f

9 months ago

6.0.5-6640116d

8 months ago

6.0.9-8f921ee97

5 months ago

6.0.5-e3ab1929

8 months ago

6.0.9-c960eb659

6 months ago

6.0.4-122f1e67

8 months ago

6.0.3-7b2ddc17

9 months ago

6.0.11-8c169db1b

5 months ago

6.0.9-8bb6d5333

5 months ago

6.0.9-3dee5df4d

6 months ago

6.0.5-7d8b1551

7 months ago

6.0.8-d25d9510

6 months ago

6.0.7

7 months ago

6.0.6

7 months ago

6.0.2-e26848b0

9 months ago

6.0.9

6 months ago

6.0.8

6 months ago

6.0.2-364e0592

9 months ago

6.0.4-4db2f5f5

8 months ago

5.0.4-5eee70a4

10 months ago

6.0.3-a6be8f0f

8 months ago

6.0.2-a1fbb7e2

9 months ago

6.0.4-0ee4f784

8 months ago

6.0.5-ae36e86b

7 months ago

7.0.0-bcfa15993

5 months ago

6.0.4-0ce318ec

8 months ago

6.0.9-74e84bc29

5 months ago

6.0.1

9 months ago

6.0.0

9 months ago

6.0.3

9 months ago

6.0.5-6cb80f7d

8 months ago

6.0.2

9 months ago

6.0.5

8 months ago

6.0.0-a4a10fd4

9 months ago

6.0.4

8 months ago

6.0.2-eaac8943

9 months ago

5.0.4-7f60b579

10 months ago

6.0.11-6c1f0ee81

5 months ago

6.0.8-78db573f9

6 months ago

6.0.10-06e6d235f

5 months ago

6.0.5-96166ada

7 months ago

6.0.2-3345f28b

9 months ago

6.0.9-bb6ceb192

6 months ago

6.0.9-97ab31c0c

6 months ago

7.0.0-10ea19700

5 months ago

5.0.4-57c32721

9 months ago

6.0.10-a32e70bac

5 months ago

6.0.10-273d8177c

5 months ago

6.0.9-7877a50e0

5 months ago

6.0.0-c858ca7f

9 months ago

6.0.9-0f5c305af

6 months ago

5.0.4-1f7e18b0

9 months ago

6.0.8-f4fac961

6 months ago

6.0.9-05b52d69c

6 months ago

6.0.11-f537b3731

5 months ago

6.0.11-9197f10ba

5 months ago

6.0.7-69581367

6 months ago

6.0.10-7682861f9

5 months ago

6.0.3-87165551

9 months ago

6.0.3-d30f09f2

9 months ago

7.0.0-09dd02987

5 months ago

6.0.10-8e4fbe13a

5 months ago

6.0.0-fdd80820

9 months ago

5.0.4-791f56f0

10 months ago

6.0.9-9c67c5b3d

6 months ago

5.0.4-e9cafd3d

10 months ago

6.0.9-effcfaa8e

6 months ago

6.0.7-50442d7a

6 months ago

6.0.11-53224004f

5 months ago

6.0.9-d8f5bc211

6 months ago

5.0.4-6eab9c5e

10 months ago

6.0.3-a533cc39

8 months ago

6.0.3-5294f14c

8 months ago

6.0.3-2b755a82

8 months ago

6.0.0-ef83dd1d

9 months ago

6.0.5-5a6a4379

7 months ago

5.0.4-69c93ac5

10 months ago

6.0.11-561797a89

5 months ago

7.0.0

5 months ago

6.0.3-7517082d

8 months ago

5.0.4-a1ec46b5

10 months ago

6.0.0-8d49602f

9 months ago

6.0.4-20d5f220

8 months ago

6.0.8-1d141331a

6 months ago

6.0.3-89778624

9 months ago

6.0.7-d5ef1c91

6 months ago

6.0.0-8f681db3

9 months ago

6.0.5-980857c3

7 months ago

6.0.5-91842c93

7 months ago

6.0.11-738dd40f1

5 months ago

6.0.3-13f5b48e

8 months ago

6.0.9-adea7bbbf

6 months ago

6.0.4-88c47f51

8 months ago

7.0.0-5a9362e21

5 months ago

6.0.5-972b10a9

8 months ago

5.0.4-b1024c6c

10 months ago

6.0.6-62a56b54

7 months ago

6.0.6-77e3cbc3

7 months ago

6.0.8-fb8a6f188

6 months ago

6.0.5-72319fe6

8 months ago

6.0.3-4559a624

8 months ago

6.0.3-73b87c5a

8 months ago

5.0.4-06f4901a

10 months ago

5.0.4-b36ec7f2

10 months ago

6.0.9-e2267d437

5 months ago

6.0.2-02b89323

9 months ago

6.0.3-d9948596

9 months ago

6.0.2-4c1a33b3

9 months ago

6.0.9-6625a27fc

6 months ago

6.0.3-4ef9c79c

9 months ago

5.0.4-7b5c54dd

10 months ago

6.0.7-346ff5a2

6 months ago

6.0.3-0d228f9f

8 months ago

6.0.3-28d6722f

8 months ago

6.0.3-e664d14f

9 months ago

6.0.11-7861ed882

5 months ago

6.0.3-63041afe

8 months ago

6.0.9-13a870cbe

6 months ago

6.0.6-50f912c2

7 months ago

6.0.11-e7167fe52

5 months ago

6.0.3-098ba082

9 months ago

6.0.5-c88de8e1

7 months ago

6.0.2-9c0353cf

9 months ago

6.0.5-e8123d3f

7 months ago

5.0.4-daeb43d8

10 months ago

6.0.10-bcf18265e

5 months ago

6.0.3-01acccef

8 months ago

6.0.9-0b4a2ee79

6 months ago

6.0.10-551622a96

5 months ago

6.0.11-bca8d6e68

5 months ago

6.0.6-f9d1c072

7 months ago

6.0.9-d729d66a5

6 months ago

5.0.4-c999d6a7

10 months ago

6.0.5-f670307a

7 months ago

6.0.2-6b839807

9 months ago

6.0.9-6b6ba9ab7

6 months ago

6.0.6-7534ae7b

7 months ago

6.0.3-c4eff4c5

8 months ago

5.0.4-3dfc236e

11 months ago

5.0.4

11 months ago

5.0.4-8b0e6bef

11 months ago

5.0.4-879f4794

11 months ago

5.0.4-7fb23cd3

11 months ago

5.0.4-f427cfc9

11 months ago

5.0.4-ea8a0637

11 months ago

5.0.4-d853d124

11 months ago

5.0.4-05abd49f

11 months ago

5.0.4-42c1c097

11 months ago

5.0.4-ab0e3980

11 months ago

5.0.4-2e561fe9

11 months ago

5.0.4-85a317bb

11 months ago

5.0.4-6fdaa7dc

11 months ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.0.5

1 year ago

4.0.4

2 years ago

4.0.3

2 years ago

3.0.0

2 years ago

2.0.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.0

2 years ago