@libp2p/peer-record 7.0.9 → 7.0.10-28e51652a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # @libp2p/peer-record
2
+
1
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
5
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
@@ -7,6 +9,21 @@
7
9
 
8
10
  # About
9
11
 
12
+ <!--
13
+
14
+ !IMPORTANT!
15
+
16
+ Everything in this README between "# About" and "# Install" is automatically
17
+ generated and will be overwritten the next time the doc generator is run.
18
+
19
+ To make changes to this section, please update the @packageDocumentation section
20
+ of src/index.js or src/index.ts
21
+
22
+ To experiment with formatting, please run "npm run docs" from the root of this
23
+ repo and examine the changes made.
24
+
25
+ -->
26
+
10
27
  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.
11
28
 
12
29
  ## Envelope
@@ -15,55 +32,38 @@ Libp2p provides an all-purpose data container called **envelope**. It was create
15
32
 
16
33
  This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers.
17
34
 
18
- You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
35
+ You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
19
36
 
20
37
  ## Example - Creating a peer record
21
38
 
22
39
  Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged:
23
40
 
24
- ```js
25
- // interface-record implementation example with the "libp2p-example" namespace
26
- import { PeerRecord } from '@libp2p/peer-record'
27
- import { fromString } from 'uint8arrays/from-string'
41
+ ```TypeScript
42
+ import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
43
+ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
28
44
 
29
- class ExampleRecord extends PeerRecord {
30
- constructor () {
31
- super ('libp2p-example', fromString('0302', 'hex'))
32
- }
45
+ const peerId = await createEd25519PeerId()
33
46
 
34
- marshal () {}
35
-
36
- equals (other) {}
37
- }
38
-
39
- ExampleRecord.createFromProtobuf = () => {}
40
- ```
41
-
42
- ```js
43
- import { PeerEnvelope } from '@libp2p/peer-record'
44
- import { ExampleRecord } from './example-record.js'
47
+ const record = new PeerRecord({
48
+ peerId,
49
+ // ...other data
50
+ })
45
51
 
46
- const rec = new ExampleRecord()
47
- const e = await PeerEnvelope.seal(rec, peerId)
48
- const wireData = e.marshal()
52
+ const envelope = await RecordEnvelope.seal(record, peerId)
53
+ const wireData = envelope.marshal()
49
54
  ```
50
55
 
51
56
  ## Example - Consuming a peer record
52
57
 
53
- Consume a received envelope (`wireData`) and transform it back to a record:
54
-
55
- ```js
56
- import { PeerEnvelope } from '@libp2p/peer-record'
57
- import { ExampleRecord } from './example-record.js'
58
+ Consume a received envelope `wireData` and transform it back to a record:
58
59
 
59
- const domain = 'libp2p-example'
60
- let e
60
+ ```TypeScript
61
+ import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
61
62
 
62
- try {
63
- e = await PeerEnvelope.openAndCertify(wireData, domain)
64
- } catch (err) {}
63
+ const wireData = Uint8Array.from([0, 1, 2, 3, 4])
64
+ const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN)
65
65
 
66
- const rec = ExampleRecord.createFromProtobuf(e.payload)
66
+ const record = PeerRecord.createFromProtobuf(envelope.payload)
67
67
  ```
68
68
 
69
69
  ## Peer Record
@@ -74,18 +74,25 @@ Libp2p peer records were created to enable the distribution of verifiable addres
74
74
 
75
75
  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.
76
76
 
77
- You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
77
+ You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
78
78
 
79
79
  ## Example
80
80
 
81
81
  Create a new Peer Record
82
82
 
83
- ```js
83
+ ```TypeScript
84
84
  import { PeerRecord } from '@libp2p/peer-record'
85
+ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
86
+ import { multiaddr } from '@multiformats/multiaddr'
87
+
88
+ const peerId = await createEd25519PeerId()
85
89
 
86
- const pr = new PeerRecord({
87
- peerId: node.peerId,
88
- multiaddrs: node.multiaddrs
90
+ const record = new PeerRecord({
91
+ peerId: peerId,
92
+ multiaddrs: [
93
+ multiaddr('/ip4/...'),
94
+ multiaddr('/ip4/...')
95
+ ]
89
96
  })
90
97
  ```
91
98
 
@@ -93,10 +100,11 @@ const pr = new PeerRecord({
93
100
 
94
101
  Create a Peer Record from a protobuf
95
102
 
96
- ```js
103
+ ```TypeScript
97
104
  import { PeerRecord } from '@libp2p/peer-record'
98
105
 
99
- const pr = PeerRecord.createFromProtobuf(data)
106
+ const data = Uint8Array.from([0, 1, 2, 3, 4])
107
+ const record = PeerRecord.createFromProtobuf(data)
100
108
  ```
101
109
 
102
110
  ## Libp2p Flows
@@ -9,55 +9,38 @@
9
9
  *
10
10
  * This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers.
11
11
  *
12
- * You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
12
+ * You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
13
13
  *
14
14
  * @example Creating a peer record
15
15
  *
16
16
  * Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged:
17
17
  *
18
- * ```js
19
- * // interface-record implementation example with the "libp2p-example" namespace
20
- * import { PeerRecord } from '@libp2p/peer-record'
21
- * import { fromString } from 'uint8arrays/from-string'
22
- *
23
- * class ExampleRecord extends PeerRecord {
24
- * constructor () {
25
- * super ('libp2p-example', fromString('0302', 'hex'))
26
- * }
27
- *
28
- * marshal () {}
29
- *
30
- * equals (other) {}
31
- * }
18
+ * ```TypeScript
19
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
20
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
32
21
  *
33
- * ExampleRecord.createFromProtobuf = () => {}
34
- * ```
22
+ * const peerId = await createEd25519PeerId()
35
23
  *
36
- * ```js
37
- * import { PeerEnvelope } from '@libp2p/peer-record'
38
- * import { ExampleRecord } from './example-record.js'
24
+ * const record = new PeerRecord({
25
+ * peerId,
26
+ * // ...other data
27
+ * })
39
28
  *
40
- * const rec = new ExampleRecord()
41
- * const e = await PeerEnvelope.seal(rec, peerId)
42
- * const wireData = e.marshal()
29
+ * const envelope = await RecordEnvelope.seal(record, peerId)
30
+ * const wireData = envelope.marshal()
43
31
  * ```
44
32
  *
45
33
  * @example Consuming a peer record
46
34
  *
47
- * Consume a received envelope (`wireData`) and transform it back to a record:
35
+ * Consume a received envelope `wireData` and transform it back to a record:
48
36
  *
49
- * ```js
50
- * import { PeerEnvelope } from '@libp2p/peer-record'
51
- * import { ExampleRecord } from './example-record.js'
37
+ * ```TypeScript
38
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
52
39
  *
53
- * const domain = 'libp2p-example'
54
- * let e
40
+ * const wireData = Uint8Array.from([0, 1, 2, 3, 4])
41
+ * const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN)
55
42
  *
56
- * try {
57
- * e = await PeerEnvelope.openAndCertify(wireData, domain)
58
- * } catch (err) {}
59
- *
60
- * const rec = ExampleRecord.createFromProtobuf(e.payload)
43
+ * const record = PeerRecord.createFromProtobuf(envelope.payload)
61
44
  * ```
62
45
  *
63
46
  * ## Peer Record
@@ -68,18 +51,25 @@
68
51
  *
69
52
  * 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.
70
53
  *
71
- * You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
54
+ * You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
72
55
  *
73
56
  * @example
74
57
  *
75
58
  * Create a new Peer Record
76
59
  *
77
- * ```js
60
+ * ```TypeScript
78
61
  * import { PeerRecord } from '@libp2p/peer-record'
62
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
63
+ * import { multiaddr } from '@multiformats/multiaddr'
64
+ *
65
+ * const peerId = await createEd25519PeerId()
79
66
  *
80
- * const pr = new PeerRecord({
81
- * peerId: node.peerId,
82
- * multiaddrs: node.multiaddrs
67
+ * const record = new PeerRecord({
68
+ * peerId: peerId,
69
+ * multiaddrs: [
70
+ * multiaddr('/ip4/...'),
71
+ * multiaddr('/ip4/...')
72
+ * ]
83
73
  * })
84
74
  * ```
85
75
  *
@@ -87,10 +77,11 @@
87
77
  *
88
78
  * Create a Peer Record from a protobuf
89
79
  *
90
- * ```js
80
+ * ```TypeScript
91
81
  * import { PeerRecord } from '@libp2p/peer-record'
92
82
  *
93
- * const pr = PeerRecord.createFromProtobuf(data)
83
+ * const data = Uint8Array.from([0, 1, 2, 3, 4])
84
+ * const record = PeerRecord.createFromProtobuf(data)
94
85
  * ```
95
86
  *
96
87
  * ## Libp2p Flows
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4HG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA"}
package/dist/src/index.js CHANGED
@@ -9,55 +9,38 @@
9
9
  *
10
10
  * This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers.
11
11
  *
12
- * You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
12
+ * You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
13
13
  *
14
14
  * @example Creating a peer record
15
15
  *
16
16
  * Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged:
17
17
  *
18
- * ```js
19
- * // interface-record implementation example with the "libp2p-example" namespace
20
- * import { PeerRecord } from '@libp2p/peer-record'
21
- * import { fromString } from 'uint8arrays/from-string'
22
- *
23
- * class ExampleRecord extends PeerRecord {
24
- * constructor () {
25
- * super ('libp2p-example', fromString('0302', 'hex'))
26
- * }
27
- *
28
- * marshal () {}
29
- *
30
- * equals (other) {}
31
- * }
18
+ * ```TypeScript
19
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
20
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
32
21
  *
33
- * ExampleRecord.createFromProtobuf = () => {}
34
- * ```
22
+ * const peerId = await createEd25519PeerId()
35
23
  *
36
- * ```js
37
- * import { PeerEnvelope } from '@libp2p/peer-record'
38
- * import { ExampleRecord } from './example-record.js'
24
+ * const record = new PeerRecord({
25
+ * peerId,
26
+ * // ...other data
27
+ * })
39
28
  *
40
- * const rec = new ExampleRecord()
41
- * const e = await PeerEnvelope.seal(rec, peerId)
42
- * const wireData = e.marshal()
29
+ * const envelope = await RecordEnvelope.seal(record, peerId)
30
+ * const wireData = envelope.marshal()
43
31
  * ```
44
32
  *
45
33
  * @example Consuming a peer record
46
34
  *
47
- * Consume a received envelope (`wireData`) and transform it back to a record:
35
+ * Consume a received envelope `wireData` and transform it back to a record:
48
36
  *
49
- * ```js
50
- * import { PeerEnvelope } from '@libp2p/peer-record'
51
- * import { ExampleRecord } from './example-record.js'
37
+ * ```TypeScript
38
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
52
39
  *
53
- * const domain = 'libp2p-example'
54
- * let e
40
+ * const wireData = Uint8Array.from([0, 1, 2, 3, 4])
41
+ * const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN)
55
42
  *
56
- * try {
57
- * e = await PeerEnvelope.openAndCertify(wireData, domain)
58
- * } catch (err) {}
59
- *
60
- * const rec = ExampleRecord.createFromProtobuf(e.payload)
43
+ * const record = PeerRecord.createFromProtobuf(envelope.payload)
61
44
  * ```
62
45
  *
63
46
  * ## Peer Record
@@ -68,18 +51,25 @@
68
51
  *
69
52
  * 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.
70
53
  *
71
- * You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
54
+ * You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
72
55
  *
73
56
  * @example
74
57
  *
75
58
  * Create a new Peer Record
76
59
  *
77
- * ```js
60
+ * ```TypeScript
78
61
  * import { PeerRecord } from '@libp2p/peer-record'
62
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
63
+ * import { multiaddr } from '@multiformats/multiaddr'
64
+ *
65
+ * const peerId = await createEd25519PeerId()
79
66
  *
80
- * const pr = new PeerRecord({
81
- * peerId: node.peerId,
82
- * multiaddrs: node.multiaddrs
67
+ * const record = new PeerRecord({
68
+ * peerId: peerId,
69
+ * multiaddrs: [
70
+ * multiaddr('/ip4/...'),
71
+ * multiaddr('/ip4/...')
72
+ * ]
83
73
  * })
84
74
  * ```
85
75
  *
@@ -87,10 +77,11 @@
87
77
  *
88
78
  * Create a Peer Record from a protobuf
89
79
  *
90
- * ```js
80
+ * ```TypeScript
91
81
  * import { PeerRecord } from '@libp2p/peer-record'
92
82
  *
93
- * const pr = PeerRecord.createFromProtobuf(data)
83
+ * const data = Uint8Array.from([0, 1, 2, 3, 4])
84
+ * const record = PeerRecord.createFromProtobuf(data)
94
85
  * ```
95
86
  *
96
87
  * ## Libp2p Flows
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4HG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-record",
3
- "version": "7.0.9",
3
+ "version": "7.0.10-28e51652a",
4
4
  "description": "Used to transfer signed peer data across the network",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-record#readme",
@@ -49,6 +49,7 @@
49
49
  "clean": "aegir clean",
50
50
  "lint": "aegir lint",
51
51
  "dep-check": "aegir dep-check",
52
+ "doc-check": "aegir doc-check",
52
53
  "generate": "protons src/envelope/envelope.proto src/peer-record/peer-record.proto",
53
54
  "build": "aegir build",
54
55
  "test": "aegir test",
@@ -60,19 +61,19 @@
60
61
  "test:electron-main": "aegir test -t electron-main"
61
62
  },
62
63
  "dependencies": {
63
- "@libp2p/crypto": "^4.0.2",
64
- "@libp2p/interface": "^1.1.3",
65
- "@libp2p/peer-id": "^4.0.6",
66
- "@libp2p/utils": "^5.2.5",
64
+ "@libp2p/crypto": "4.0.3-28e51652a",
65
+ "@libp2p/interface": "1.1.4-28e51652a",
66
+ "@libp2p/peer-id": "4.0.7-28e51652a",
67
+ "@libp2p/utils": "5.2.6-28e51652a",
67
68
  "@multiformats/multiaddr": "^12.1.14",
68
69
  "protons-runtime": "^5.4.0",
69
70
  "uint8-varint": "^2.0.4",
70
71
  "uint8arraylist": "^2.4.8",
71
- "uint8arrays": "^5.0.1"
72
+ "uint8arrays": "^5.0.2"
72
73
  },
73
74
  "devDependencies": {
74
- "@libp2p/peer-id-factory": "^4.0.6",
75
- "aegir": "^42.2.3",
75
+ "@libp2p/peer-id-factory": "4.0.7-28e51652a",
76
+ "aegir": "^42.2.4",
76
77
  "protons": "^7.5.0"
77
78
  },
78
79
  "sideEffects": false
package/src/index.ts CHANGED
@@ -9,55 +9,38 @@
9
9
  *
10
10
  * This envelope stores a marshaled record implementing the [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts). These Records are designed to be serialized to bytes and placed inside of the envelopes before being shared with other peers.
11
11
  *
12
- * You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
12
+ * You can read further about the envelope in [RFC 0002 - Signed Envelopes](https://github.com/libp2p/specs/blob/master/RFC/0002-signed-envelopes.md). For the original discussion about it you can look at the PR that was used to create it: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
13
13
  *
14
14
  * @example Creating a peer record
15
15
  *
16
16
  * Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged:
17
17
  *
18
- * ```js
19
- * // interface-record implementation example with the "libp2p-example" namespace
20
- * import { PeerRecord } from '@libp2p/peer-record'
21
- * import { fromString } from 'uint8arrays/from-string'
22
- *
23
- * class ExampleRecord extends PeerRecord {
24
- * constructor () {
25
- * super ('libp2p-example', fromString('0302', 'hex'))
26
- * }
27
- *
28
- * marshal () {}
29
- *
30
- * equals (other) {}
31
- * }
18
+ * ```TypeScript
19
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
20
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
32
21
  *
33
- * ExampleRecord.createFromProtobuf = () => {}
34
- * ```
22
+ * const peerId = await createEd25519PeerId()
35
23
  *
36
- * ```js
37
- * import { PeerEnvelope } from '@libp2p/peer-record'
38
- * import { ExampleRecord } from './example-record.js'
24
+ * const record = new PeerRecord({
25
+ * peerId,
26
+ * // ...other data
27
+ * })
39
28
  *
40
- * const rec = new ExampleRecord()
41
- * const e = await PeerEnvelope.seal(rec, peerId)
42
- * const wireData = e.marshal()
29
+ * const envelope = await RecordEnvelope.seal(record, peerId)
30
+ * const wireData = envelope.marshal()
43
31
  * ```
44
32
  *
45
33
  * @example Consuming a peer record
46
34
  *
47
- * Consume a received envelope (`wireData`) and transform it back to a record:
35
+ * Consume a received envelope `wireData` and transform it back to a record:
48
36
  *
49
- * ```js
50
- * import { PeerEnvelope } from '@libp2p/peer-record'
51
- * import { ExampleRecord } from './example-record.js'
37
+ * ```TypeScript
38
+ * import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
52
39
  *
53
- * const domain = 'libp2p-example'
54
- * let e
40
+ * const wireData = Uint8Array.from([0, 1, 2, 3, 4])
41
+ * const envelope = await RecordEnvelope.openAndCertify(wireData, PeerRecord.DOMAIN)
55
42
  *
56
- * try {
57
- * e = await PeerEnvelope.openAndCertify(wireData, domain)
58
- * } catch (err) {}
59
- *
60
- * const rec = ExampleRecord.createFromProtobuf(e.payload)
43
+ * const record = PeerRecord.createFromProtobuf(envelope.payload)
61
44
  * ```
62
45
  *
63
46
  * ## Peer Record
@@ -68,18 +51,25 @@
68
51
  *
69
52
  * 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.
70
53
  *
71
- * You can read further about the Peer Record in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
54
+ * You can read further about the Peer Record in [RFC 0003 - Peer Routing Records](https://github.com/libp2p/specs/blob/master/RFC/0003-routing-records.md). For the original discussion about it you can view the PR that created the RFC: [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
72
55
  *
73
56
  * @example
74
57
  *
75
58
  * Create a new Peer Record
76
59
  *
77
- * ```js
60
+ * ```TypeScript
78
61
  * import { PeerRecord } from '@libp2p/peer-record'
62
+ * import { createEd25519PeerId } from '@libp2p/peer-id-factory'
63
+ * import { multiaddr } from '@multiformats/multiaddr'
64
+ *
65
+ * const peerId = await createEd25519PeerId()
79
66
  *
80
- * const pr = new PeerRecord({
81
- * peerId: node.peerId,
82
- * multiaddrs: node.multiaddrs
67
+ * const record = new PeerRecord({
68
+ * peerId: peerId,
69
+ * multiaddrs: [
70
+ * multiaddr('/ip4/...'),
71
+ * multiaddr('/ip4/...')
72
+ * ]
83
73
  * })
84
74
  * ```
85
75
  *
@@ -87,10 +77,11 @@
87
77
  *
88
78
  * Create a Peer Record from a protobuf
89
79
  *
90
- * ```js
80
+ * ```TypeScript
91
81
  * import { PeerRecord } from '@libp2p/peer-record'
92
82
  *
93
- * const pr = PeerRecord.createFromProtobuf(data)
83
+ * const data = Uint8Array.from([0, 1, 2, 3, 4])
84
+ * const record = PeerRecord.createFromProtobuf(data)
94
85
  * ```
95
86
  *
96
87
  * ## Libp2p Flows
@@ -1,6 +0,0 @@
1
- {
2
- "PeerRecord": "https://libp2p.github.io/js-libp2p/classes/_libp2p_peer_record.PeerRecord.html",
3
- "RecordEnvelope": "https://libp2p.github.io/js-libp2p/classes/_libp2p_peer_record.RecordEnvelope.html",
4
- "PeerRecordInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_peer_record.PeerRecordInit.html",
5
- "RecordEnvelopeInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_peer_record.RecordEnvelopeInit.html"
6
- }