libp2p 0.42.2 → 0.43.0

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.
Files changed (295) hide show
  1. package/README.md +4 -4
  2. package/dist/index.min.js +29 -29
  3. package/dist/src/address-manager/index.d.ts +1 -10
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/address-manager/index.js +46 -29
  6. package/dist/src/address-manager/index.js.map +1 -1
  7. package/dist/src/autonat/constants.d.ts +4 -0
  8. package/dist/src/autonat/constants.d.ts.map +1 -0
  9. package/dist/src/autonat/constants.js +4 -0
  10. package/dist/src/autonat/constants.js.map +1 -0
  11. package/dist/src/autonat/index.d.ts +64 -0
  12. package/dist/src/autonat/index.d.ts.map +1 -0
  13. package/dist/src/autonat/index.js +417 -0
  14. package/dist/src/autonat/index.js.map +1 -0
  15. package/dist/src/autonat/pb/index.d.ts +57 -0
  16. package/dist/src/autonat/pb/index.d.ts.map +1 -0
  17. package/dist/src/autonat/pb/index.js +250 -0
  18. package/dist/src/autonat/pb/index.js.map +1 -0
  19. package/dist/src/circuit/constants.d.ts +31 -6
  20. package/dist/src/circuit/constants.d.ts.map +1 -1
  21. package/dist/src/circuit/constants.js +37 -7
  22. package/dist/src/circuit/constants.js.map +1 -1
  23. package/dist/src/circuit/index.d.ts +16 -61
  24. package/dist/src/circuit/index.d.ts.map +1 -1
  25. package/dist/src/circuit/index.js +2 -68
  26. package/dist/src/circuit/index.js.map +1 -1
  27. package/dist/src/circuit/pb/index.d.ts +83 -43
  28. package/dist/src/circuit/pb/index.d.ts.map +1 -1
  29. package/dist/src/circuit/pb/index.js +363 -127
  30. package/dist/src/circuit/pb/index.js.map +1 -1
  31. package/dist/src/circuit/server/advert-service.d.ts +43 -0
  32. package/dist/src/circuit/server/advert-service.d.ts.map +1 -0
  33. package/dist/src/circuit/server/advert-service.js +69 -0
  34. package/dist/src/circuit/server/advert-service.js.map +1 -0
  35. package/dist/src/circuit/server/index.d.ts +60 -0
  36. package/dist/src/circuit/server/index.d.ts.map +1 -0
  37. package/dist/src/circuit/server/index.js +287 -0
  38. package/dist/src/circuit/server/index.js.map +1 -0
  39. package/dist/src/circuit/server/reservation-store.d.ts +49 -0
  40. package/dist/src/circuit/server/reservation-store.d.ts.map +1 -0
  41. package/dist/src/circuit/server/reservation-store.js +57 -0
  42. package/dist/src/circuit/server/reservation-store.js.map +1 -0
  43. package/dist/src/circuit/server/reservation-voucher.d.ts +18 -0
  44. package/dist/src/circuit/server/reservation-voucher.d.ts.map +1 -0
  45. package/dist/src/circuit/server/reservation-voucher.js +33 -0
  46. package/dist/src/circuit/server/reservation-voucher.js.map +1 -0
  47. package/dist/src/circuit/transport/discovery.d.ts +45 -0
  48. package/dist/src/circuit/transport/discovery.d.ts.map +1 -0
  49. package/dist/src/circuit/transport/discovery.js +82 -0
  50. package/dist/src/circuit/transport/discovery.js.map +1 -0
  51. package/dist/src/circuit/transport/index.d.ts +33 -0
  52. package/dist/src/circuit/transport/index.d.ts.map +1 -0
  53. package/dist/src/circuit/transport/index.js +225 -0
  54. package/dist/src/circuit/transport/index.js.map +1 -0
  55. package/dist/src/circuit/transport/listener.d.ts +9 -0
  56. package/dist/src/circuit/transport/listener.d.ts.map +1 -0
  57. package/dist/src/circuit/transport/listener.js +76 -0
  58. package/dist/src/circuit/transport/listener.js.map +1 -0
  59. package/dist/src/circuit/transport/reservation-store.d.ts +60 -0
  60. package/dist/src/circuit/transport/reservation-store.d.ts.map +1 -0
  61. package/dist/src/circuit/transport/reservation-store.js +165 -0
  62. package/dist/src/circuit/transport/reservation-store.js.map +1 -0
  63. package/dist/src/circuit/utils.d.ts +7 -0
  64. package/dist/src/circuit/utils.d.ts.map +1 -1
  65. package/dist/src/circuit/utils.js +87 -0
  66. package/dist/src/circuit/utils.js.map +1 -1
  67. package/dist/src/components.d.ts +2 -1
  68. package/dist/src/components.d.ts.map +1 -1
  69. package/dist/src/components.js +13 -13
  70. package/dist/src/components.js.map +1 -1
  71. package/dist/src/config.d.ts.map +1 -1
  72. package/dist/src/config.js +21 -25
  73. package/dist/src/config.js.map +1 -1
  74. package/dist/src/connection/index.d.ts +2 -2
  75. package/dist/src/connection/index.d.ts.map +1 -1
  76. package/dist/src/connection/index.js +4 -4
  77. package/dist/src/connection/index.js.map +1 -1
  78. package/dist/src/connection-manager/auto-dialler.d.ts +0 -4
  79. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  80. package/dist/src/connection-manager/auto-dialler.js +18 -18
  81. package/dist/src/connection-manager/auto-dialler.js.map +1 -1
  82. package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
  83. package/dist/src/connection-manager/dialer/dial-request.js +13 -6
  84. package/dist/src/connection-manager/dialer/dial-request.js.map +1 -1
  85. package/dist/src/connection-manager/dialer/index.d.ts +10 -1
  86. package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
  87. package/dist/src/connection-manager/dialer/index.js +24 -9
  88. package/dist/src/connection-manager/dialer/index.js.map +1 -1
  89. package/dist/src/connection-manager/index.d.ts +1 -4
  90. package/dist/src/connection-manager/index.d.ts.map +1 -1
  91. package/dist/src/connection-manager/index.js +8 -5
  92. package/dist/src/connection-manager/index.js.map +1 -1
  93. package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
  94. package/dist/src/connection-manager/latency-monitor.js +1 -1
  95. package/dist/src/connection-manager/latency-monitor.js.map +1 -1
  96. package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
  97. package/dist/src/content-routing/index.d.ts +6 -4
  98. package/dist/src/content-routing/index.d.ts.map +1 -1
  99. package/dist/src/content-routing/index.js +9 -9
  100. package/dist/src/content-routing/index.js.map +1 -1
  101. package/dist/src/content-routing/utils.d.ts +3 -3
  102. package/dist/src/content-routing/utils.d.ts.map +1 -1
  103. package/dist/src/content-routing/utils.js +2 -2
  104. package/dist/src/content-routing/utils.js.map +1 -1
  105. package/dist/src/dht/dht-content-routing.d.ts +2 -1
  106. package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
  107. package/dist/src/dht/dht-content-routing.js +2 -2
  108. package/dist/src/dht/dht-content-routing.js.map +1 -1
  109. package/dist/src/dht/dht-peer-routing.d.ts +3 -2
  110. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  111. package/dist/src/dht/dht-peer-routing.js +2 -2
  112. package/dist/src/dht/dht-peer-routing.js.map +1 -1
  113. package/dist/src/dht/dummy-dht.d.ts +1 -1
  114. package/dist/src/dht/dummy-dht.d.ts.map +1 -1
  115. package/dist/src/dht/dummy-dht.js +12 -12
  116. package/dist/src/dht/dummy-dht.js.map +1 -1
  117. package/dist/src/errors.d.ts +2 -1
  118. package/dist/src/errors.d.ts.map +1 -1
  119. package/dist/src/errors.js +1 -0
  120. package/dist/src/errors.js.map +1 -1
  121. package/dist/src/fetch/index.d.ts.map +1 -1
  122. package/dist/src/fetch/index.js +6 -6
  123. package/dist/src/fetch/index.js.map +1 -1
  124. package/dist/src/fetch/pb/proto.d.ts +3 -3
  125. package/dist/src/fetch/pb/proto.d.ts.map +1 -1
  126. package/dist/src/fetch/pb/proto.js +4 -3
  127. package/dist/src/fetch/pb/proto.js.map +1 -1
  128. package/dist/src/get-peer.js +2 -2
  129. package/dist/src/get-peer.js.map +1 -1
  130. package/dist/src/identify/index.d.ts +3 -1
  131. package/dist/src/identify/index.d.ts.map +1 -1
  132. package/dist/src/identify/index.js +19 -14
  133. package/dist/src/identify/index.js.map +1 -1
  134. package/dist/src/identify/pb/message.d.ts +2 -2
  135. package/dist/src/identify/pb/message.d.ts.map +1 -1
  136. package/dist/src/identify/pb/message.js +1 -0
  137. package/dist/src/identify/pb/message.js.map +1 -1
  138. package/dist/src/index.d.ts +14 -8
  139. package/dist/src/index.d.ts.map +1 -1
  140. package/dist/src/index.js.map +1 -1
  141. package/dist/src/insecure/index.d.ts.map +1 -1
  142. package/dist/src/insecure/index.js.map +1 -1
  143. package/dist/src/insecure/pb/proto.d.ts +3 -3
  144. package/dist/src/insecure/pb/proto.d.ts.map +1 -1
  145. package/dist/src/insecure/pb/proto.js +4 -5
  146. package/dist/src/insecure/pb/proto.js.map +1 -1
  147. package/dist/src/libp2p.d.ts +7 -3
  148. package/dist/src/libp2p.d.ts.map +1 -1
  149. package/dist/src/libp2p.js +35 -35
  150. package/dist/src/libp2p.js.map +1 -1
  151. package/dist/src/nat-manager.d.ts.map +1 -1
  152. package/dist/src/nat-manager.js +5 -3
  153. package/dist/src/nat-manager.js.map +1 -1
  154. package/dist/src/peer-record-updater.d.ts.map +1 -1
  155. package/dist/src/peer-routing.d.ts.map +1 -1
  156. package/dist/src/peer-routing.js +5 -5
  157. package/dist/src/peer-routing.js.map +1 -1
  158. package/dist/src/ping/index.d.ts.map +1 -1
  159. package/dist/src/ping/index.js +2 -2
  160. package/dist/src/ping/index.js.map +1 -1
  161. package/dist/src/pnet/crypto.d.ts +1 -1
  162. package/dist/src/pnet/crypto.d.ts.map +1 -1
  163. package/dist/src/pnet/crypto.js +1 -1
  164. package/dist/src/pnet/crypto.js.map +1 -1
  165. package/dist/src/pnet/index.js +3 -3
  166. package/dist/src/pnet/index.js.map +1 -1
  167. package/dist/src/pnet/key-generator.d.ts.map +1 -1
  168. package/dist/src/pubsub/dummy-pubsub.js +9 -9
  169. package/dist/src/pubsub/dummy-pubsub.js.map +1 -1
  170. package/dist/src/registrar.d.ts.map +1 -1
  171. package/dist/src/registrar.js +4 -4
  172. package/dist/src/registrar.js.map +1 -1
  173. package/dist/src/transport-manager.d.ts.map +1 -1
  174. package/dist/src/transport-manager.js +8 -9
  175. package/dist/src/transport-manager.js.map +1 -1
  176. package/dist/src/upgrader.d.ts +2 -1
  177. package/dist/src/upgrader.d.ts.map +1 -1
  178. package/dist/src/upgrader.js +38 -33
  179. package/dist/src/upgrader.js.map +1 -1
  180. package/dist/typedoc-urls.json +19 -6
  181. package/package.json +36 -33
  182. package/src/address-manager/index.ts +62 -35
  183. package/src/autonat/constants.ts +4 -0
  184. package/src/autonat/index.ts +567 -0
  185. package/src/autonat/pb/index.proto +35 -0
  186. package/src/autonat/pb/index.ts +320 -0
  187. package/src/circuit/constants.ts +48 -7
  188. package/src/circuit/index.ts +17 -129
  189. package/src/circuit/pb/index.proto +57 -32
  190. package/src/circuit/pb/index.ts +448 -138
  191. package/src/circuit/server/advert-service.ts +108 -0
  192. package/src/circuit/server/index.ts +421 -0
  193. package/src/circuit/server/reservation-store.ts +111 -0
  194. package/src/circuit/server/reservation-voucher.ts +51 -0
  195. package/src/circuit/transport/discovery.ts +127 -0
  196. package/src/circuit/transport/index.ts +325 -0
  197. package/src/circuit/transport/listener.ts +99 -0
  198. package/src/circuit/transport/reservation-store.ts +249 -0
  199. package/src/circuit/utils.ts +108 -0
  200. package/src/components.ts +22 -21
  201. package/src/config.ts +21 -25
  202. package/src/connection/index.ts +10 -10
  203. package/src/connection-manager/auto-dialler.ts +36 -40
  204. package/src/connection-manager/dialer/dial-request.ts +13 -6
  205. package/src/connection-manager/dialer/index.ts +34 -15
  206. package/src/connection-manager/index.ts +22 -23
  207. package/src/connection-manager/latency-monitor.ts +9 -9
  208. package/src/connection-manager/visibility-change-emitter.ts +4 -4
  209. package/src/content-routing/index.ts +18 -16
  210. package/src/content-routing/utils.ts +5 -5
  211. package/src/dht/dht-content-routing.ts +5 -4
  212. package/src/dht/dht-peer-routing.ts +5 -4
  213. package/src/dht/dummy-dht.ts +13 -13
  214. package/src/errors.ts +2 -1
  215. package/src/fetch/index.ts +13 -13
  216. package/src/fetch/pb/proto.ts +8 -7
  217. package/src/get-peer.ts +3 -3
  218. package/src/identify/index.ts +29 -24
  219. package/src/identify/pb/message.ts +3 -2
  220. package/src/index.ts +15 -8
  221. package/src/insecure/index.ts +2 -1
  222. package/src/insecure/pb/proto.ts +8 -9
  223. package/src/libp2p.ts +52 -46
  224. package/src/nat-manager.ts +11 -9
  225. package/src/peer-record-updater.ts +4 -4
  226. package/src/peer-routing.ts +9 -9
  227. package/src/ping/index.ts +6 -6
  228. package/src/pnet/crypto.ts +3 -3
  229. package/src/pnet/index.ts +3 -3
  230. package/src/pnet/key-generator.ts +1 -1
  231. package/src/pubsub/dummy-pubsub.ts +9 -9
  232. package/src/registrar.ts +12 -12
  233. package/src/transport-manager.ts +17 -18
  234. package/src/upgrader.ts +43 -42
  235. package/src/version.ts +1 -1
  236. package/dist/src/circuit/auto-relay.d.ts +0 -46
  237. package/dist/src/circuit/auto-relay.d.ts.map +0 -1
  238. package/dist/src/circuit/auto-relay.js +0 -220
  239. package/dist/src/circuit/auto-relay.js.map +0 -1
  240. package/dist/src/circuit/circuit/hop.d.ts +0 -42
  241. package/dist/src/circuit/circuit/hop.d.ts.map +0 -1
  242. package/dist/src/circuit/circuit/hop.js +0 -142
  243. package/dist/src/circuit/circuit/hop.js.map +0 -1
  244. package/dist/src/circuit/circuit/stop.d.ts +0 -24
  245. package/dist/src/circuit/circuit/stop.d.ts.map +0 -1
  246. package/dist/src/circuit/circuit/stop.js +0 -51
  247. package/dist/src/circuit/circuit/stop.js.map +0 -1
  248. package/dist/src/circuit/circuit/stream-handler.d.ts +0 -40
  249. package/dist/src/circuit/circuit/stream-handler.d.ts.map +0 -1
  250. package/dist/src/circuit/circuit/stream-handler.js +0 -59
  251. package/dist/src/circuit/circuit/stream-handler.js.map +0 -1
  252. package/dist/src/circuit/circuit/utils.d.ts +0 -7
  253. package/dist/src/circuit/circuit/utils.d.ts.map +0 -1
  254. package/dist/src/circuit/circuit/utils.js +0 -43
  255. package/dist/src/circuit/circuit/utils.js.map +0 -1
  256. package/dist/src/circuit/listener.d.ts +0 -9
  257. package/dist/src/circuit/listener.d.ts.map +0 -1
  258. package/dist/src/circuit/listener.js +0 -62
  259. package/dist/src/circuit/listener.js.map +0 -1
  260. package/dist/src/circuit/multicodec.d.ts +0 -2
  261. package/dist/src/circuit/multicodec.d.ts.map +0 -1
  262. package/dist/src/circuit/multicodec.js +0 -2
  263. package/dist/src/circuit/multicodec.js.map +0 -1
  264. package/dist/src/circuit/transport.d.ts +0 -51
  265. package/dist/src/circuit/transport.d.ts.map +0 -1
  266. package/dist/src/circuit/transport.js +0 -223
  267. package/dist/src/circuit/transport.js.map +0 -1
  268. package/dist/src/keychain/cms.d.ts +0 -33
  269. package/dist/src/keychain/cms.d.ts.map +0 -1
  270. package/dist/src/keychain/cms.js +0 -129
  271. package/dist/src/keychain/cms.js.map +0 -1
  272. package/dist/src/keychain/index.d.ts +0 -151
  273. package/dist/src/keychain/index.d.ts.map +0 -1
  274. package/dist/src/keychain/index.js +0 -519
  275. package/dist/src/keychain/index.js.map +0 -1
  276. package/dist/src/keychain/util.d.ts +0 -21
  277. package/dist/src/keychain/util.d.ts.map +0 -1
  278. package/dist/src/keychain/util.js +0 -79
  279. package/dist/src/keychain/util.js.map +0 -1
  280. package/src/circuit/IMPLEMENTATION_NOTES.md +0 -128
  281. package/src/circuit/README.md +0 -111
  282. package/src/circuit/auto-relay.ts +0 -292
  283. package/src/circuit/circuit/hop.ts +0 -220
  284. package/src/circuit/circuit/stop.ts +0 -83
  285. package/src/circuit/circuit/stream-handler.ts +0 -87
  286. package/src/circuit/circuit/utils.ts +0 -44
  287. package/src/circuit/listener.ts +0 -83
  288. package/src/circuit/multicodec.ts +0 -2
  289. package/src/circuit/transport.ts +0 -278
  290. package/src/keychain/README.md +0 -55
  291. package/src/keychain/cms.ts +0 -150
  292. package/src/keychain/doc/private-key.png +0 -0
  293. package/src/keychain/doc/private-key.xml +0 -1
  294. package/src/keychain/index.ts +0 -629
  295. package/src/keychain/util.ts +0 -82
@@ -1,10 +1,10 @@
1
1
  import { logger } from '@libp2p/logger'
2
- import errCode from 'err-code'
2
+ import { CodeError } from '@libp2p/interfaces/errors'
3
3
  import * as lp from 'it-length-prefixed'
4
4
  import { pipe } from 'it-pipe'
5
5
  import first from 'it-first'
6
6
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
7
- import { multiaddr, protocols } from '@multiformats/multiaddr'
7
+ import { Multiaddr, multiaddr, protocols } from '@multiformats/multiaddr'
8
8
  import { Identify } from './pb/message.js'
9
9
  import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
10
10
  import {
@@ -65,6 +65,7 @@ export interface IdentifyServiceInit {
65
65
 
66
66
  maxPushIncomingStreams: number
67
67
  maxPushOutgoingStreams: number
68
+ maxObservedAddresses?: number
68
69
  }
69
70
 
70
71
  export interface IdentifyServiceComponents {
@@ -112,7 +113,7 @@ export class IdentifyService implements Startable {
112
113
  const { peerId } = evt.detail
113
114
 
114
115
  if (this.components.peerId.equals(peerId)) {
115
- void this.pushToPeerStore().catch(err => log.error(err))
116
+ void this.pushToPeerStore().catch(err => { log.error(err) })
116
117
  }
117
118
  })
118
119
 
@@ -121,16 +122,16 @@ export class IdentifyService implements Startable {
121
122
  const { peerId } = evt.detail
122
123
 
123
124
  if (this.components.peerId.equals(peerId)) {
124
- void this.pushToPeerStore().catch(err => log.error(err))
125
+ void this.pushToPeerStore().catch(err => { log.error(err) })
125
126
  }
126
127
  })
127
128
  }
128
129
 
129
- isStarted () {
130
+ isStarted (): boolean {
130
131
  return this.started
131
132
  }
132
133
 
133
- async start () {
134
+ async start (): Promise<void> {
134
135
  if (this.started) {
135
136
  return
136
137
  }
@@ -158,7 +159,7 @@ export class IdentifyService implements Startable {
158
159
  this.started = true
159
160
  }
160
161
 
161
- async stop () {
162
+ async stop (): Promise<void> {
162
163
  await this.components.registrar.unhandle(this.identifyProtocolStr)
163
164
  await this.components.registrar.unhandle(this.identifyPushProtocolStr)
164
165
 
@@ -216,7 +217,7 @@ export class IdentifyService implements Startable {
216
217
  /**
217
218
  * Calls `push` on all peer connections
218
219
  */
219
- async pushToPeerStore () {
220
+ async pushToPeerStore (): Promise<void> {
220
221
  // Do not try to push if we are not running
221
222
  if (!this.isStarted()) {
222
223
  return
@@ -272,13 +273,13 @@ export class IdentifyService implements Startable {
272
273
  )
273
274
 
274
275
  if (data == null) {
275
- throw errCode(new Error('No data could be retrieved'), codes.ERR_CONNECTION_ENDED)
276
+ throw new CodeError('No data could be retrieved', codes.ERR_CONNECTION_ENDED)
276
277
  }
277
278
 
278
279
  try {
279
280
  return Identify.decode(data)
280
281
  } catch (err: any) {
281
- throw errCode(err, codes.ERR_INVALID_MESSAGE)
282
+ throw new CodeError(String(err), codes.ERR_INVALID_MESSAGE)
282
283
  }
283
284
  } finally {
284
285
  if (timeoutController != null) {
@@ -310,17 +311,17 @@ export class IdentifyService implements Startable {
310
311
  } = message
311
312
 
312
313
  if (publicKey == null) {
313
- throw errCode(new Error('public key was missing from identify message'), codes.ERR_MISSING_PUBLIC_KEY)
314
+ throw new CodeError('public key was missing from identify message', codes.ERR_MISSING_PUBLIC_KEY)
314
315
  }
315
316
 
316
317
  const id = await peerIdFromKeys(publicKey)
317
318
 
318
319
  if (!connection.remotePeer.equals(id)) {
319
- throw errCode(new Error('identified peer does not match the expected peer'), codes.ERR_INVALID_PEER)
320
+ throw new CodeError('identified peer does not match the expected peer', codes.ERR_INVALID_PEER)
320
321
  }
321
322
 
322
323
  if (this.components.peerId.equals(id)) {
323
- throw errCode(new Error('identified peer is our own peer id?'), codes.ERR_INVALID_PEER)
324
+ throw new CodeError('identified peer is our own peer id?', codes.ERR_INVALID_PEER)
324
325
  }
325
326
 
326
327
  // Get the observedAddr if there is one
@@ -333,7 +334,7 @@ export class IdentifyService implements Startable {
333
334
  const envelope = await RecordEnvelope.openAndCertify(signedPeerRecord, PeerRecord.DOMAIN)
334
335
 
335
336
  if (!envelope.peerId.equals(id)) {
336
- throw errCode(new Error('identified peer does not match the expected peer'), codes.ERR_INVALID_PEER)
337
+ throw new CodeError('identified peer does not match the expected peer', codes.ERR_INVALID_PEER)
337
338
  }
338
339
 
339
340
  if (await this.components.peerStore.addressBook.consumePeerRecord(envelope)) {
@@ -378,17 +379,20 @@ export class IdentifyService implements Startable {
378
379
  }
379
380
 
380
381
  log('identify completed for peer %p and protocols %o', id, protocols)
382
+ log('our observed address is %s', cleanObservedAddr)
381
383
 
382
- // TODO: Add and score our observed addr
383
- log('received observed address of %s', cleanObservedAddr?.toString())
384
- // this.components.addressManager.addObservedAddr(observedAddr)
384
+ if (cleanObservedAddr != null &&
385
+ this.components.addressManager.getObservedAddrs().length < (this.init.maxObservedAddresses ?? Infinity)) {
386
+ log('storing our observed address %s', cleanObservedAddr?.toString())
387
+ this.components.addressManager.addObservedAddr(cleanObservedAddr)
388
+ }
385
389
  }
386
390
 
387
391
  /**
388
392
  * Sends the `Identify` response with the Signed Peer Record
389
393
  * to the requesting peer over the given `connection`
390
394
  */
391
- async _handleIdentify (data: IncomingStreamData) {
395
+ async _handleIdentify (data: IncomingStreamData): Promise<void> {
392
396
  const { connection, stream } = data
393
397
  const timeoutController = new TimeoutController(this.init.timeout)
394
398
 
@@ -440,7 +444,7 @@ export class IdentifyService implements Startable {
440
444
  /**
441
445
  * Reads the Identify Push message from the given `connection`
442
446
  */
443
- async _handlePush (data: IncomingStreamData) {
447
+ async _handlePush (data: IncomingStreamData): Promise<void> {
444
448
  const { connection, stream } = data
445
449
  const timeoutController = new TimeoutController(this.init.timeout)
446
450
 
@@ -467,14 +471,16 @@ export class IdentifyService implements Startable {
467
471
  message = Identify.decode(data)
468
472
  }
469
473
  } catch (err: any) {
470
- return log.error('received invalid message', err)
474
+ log.error('received invalid message', err)
475
+ return
471
476
  } finally {
472
477
  stream.close()
473
478
  timeoutController.clear()
474
479
  }
475
480
 
476
481
  if (message == null) {
477
- return log.error('received invalid message')
482
+ log.error('received invalid message')
483
+ return
478
484
  }
479
485
 
480
486
  const id = connection.remotePeer
@@ -509,8 +515,7 @@ export class IdentifyService implements Startable {
509
515
 
510
516
  // LEGACY: Update peers data in PeerStore
511
517
  try {
512
- await this.components.peerStore.addressBook.set(id,
513
- message.listenAddrs.map((addr) => multiaddr(addr)))
518
+ await this.components.peerStore.addressBook.set(id, message.listenAddrs.map((addr) => multiaddr(addr)))
514
519
  } catch (err: any) {
515
520
  log.error('received invalid addrs', err)
516
521
  }
@@ -528,7 +533,7 @@ export class IdentifyService implements Startable {
528
533
  /**
529
534
  * Takes the `addr` and converts it to a Multiaddr if possible
530
535
  */
531
- static getCleanMultiaddr (addr: Uint8Array | string | null | undefined) {
536
+ static getCleanMultiaddr (addr: Uint8Array | string | null | undefined): Multiaddr | undefined {
532
537
  if (addr != null && addr.length > 0) {
533
538
  try {
534
539
  return multiaddr(addr)
@@ -2,10 +2,11 @@
2
2
  /* eslint-disable complexity */
3
3
  /* eslint-disable @typescript-eslint/no-namespace */
4
4
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
5
6
 
6
7
  import { encodeMessage, decodeMessage, message } from 'protons-runtime'
7
- import type { Uint8ArrayList } from 'uint8arraylist'
8
8
  import type { Codec } from 'protons-runtime'
9
+ import type { Uint8ArrayList } from 'uint8arraylist'
9
10
 
10
11
  export interface Identify {
11
12
  protocolVersion?: string
@@ -115,7 +116,7 @@ export namespace Identify {
115
116
  return _codec
116
117
  }
117
118
 
118
- export const encode = (obj: Identify): Uint8Array => {
119
+ export const encode = (obj: Partial<Identify>): Uint8Array => {
119
120
  return encodeMessage(obj, Identify.codec())
120
121
  }
121
122
 
package/src/index.ts CHANGED
@@ -22,9 +22,9 @@ import type { DualDHT } from '@libp2p/interface-dht'
22
22
  import type { Datastore } from 'interface-datastore'
23
23
  import type { PeerStoreInit } from '@libp2p/interface-peer-store'
24
24
  import type { PeerId } from '@libp2p/interface-peer-id'
25
- import type { RelayConfig } from './circuit/index.js'
26
25
  import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
27
- import type { ConnectionGater, ConnectionProtector } from '@libp2p/interface-connection'
26
+ import type { ConnectionProtector } from '@libp2p/interface-connection'
27
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater'
28
28
  import type { Transport } from '@libp2p/interface-transport'
29
29
  import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
30
30
  import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
@@ -35,13 +35,15 @@ import type { Metrics } from '@libp2p/interface-metrics'
35
35
  import type { PeerInfo } from '@libp2p/interface-peer-info'
36
36
  import type { PingServiceInit } from './ping/index.js'
37
37
  import type { FetchServiceInit } from './fetch/index.js'
38
+ import type { AutonatServiceInit } from './autonat/index.js'
38
39
  import type { Components } from './components.js'
39
40
  import type { Libp2p } from '@libp2p/interface-libp2p'
40
- import type { KeyChainInit } from './keychain/index.js'
41
+ import type { KeyChainInit } from '@libp2p/keychain'
41
42
  import type { NatManagerInit } from './nat-manager.js'
42
43
  import type { AddressManagerInit } from './address-manager/index.js'
43
44
  import type { PeerRoutingInit } from './peer-routing.js'
44
45
  import type { ConnectionManagerInit } from './connection-manager/index.js'
46
+ import type { CircuitRelayService } from './circuit/index.js'
45
47
 
46
48
  /**
47
49
  * For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
@@ -65,7 +67,7 @@ export interface Libp2pInit {
65
67
  /**
66
68
  * A connection gater can deny new connections based on user criteria
67
69
  */
68
- connectionGater: Partial<ConnectionGater>
70
+ connectionGater: ConnectionGater
69
71
 
70
72
  /**
71
73
  * libp2p transport manager configuration
@@ -103,23 +105,28 @@ export interface Libp2pInit {
103
105
  * If configured as a relay this node will relay certain
104
106
  * types of traffic for other peers
105
107
  */
106
- relay: RelayConfig
108
+ relay: (components: Components) => CircuitRelayService
107
109
 
108
110
  /**
109
- * libp2p identify protocol options
111
+ * identify protocol options
110
112
  */
111
113
  identify: IdentifyServiceInit
112
114
 
113
115
  /**
114
- * libp2p ping protocol options
116
+ * ping protocol options
115
117
  */
116
118
  ping: PingServiceInit
117
119
 
118
120
  /**
119
- * libp2p fetch protocol options
121
+ * fetch protocol options
120
122
  */
121
123
  fetch: FetchServiceInit
122
124
 
125
+ /**
126
+ * autonat protocol options
127
+ */
128
+ autonat: AutonatServiceInit
129
+
123
130
  /**
124
131
  * An array that must include at least 1 compliant transport
125
132
  */
@@ -32,11 +32,12 @@ import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
32
32
  import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
33
33
  import type { Duplex } from 'it-stream-types'
34
34
  import map from 'it-map'
35
+ import type { Uint8ArrayList } from 'uint8arraylist'
35
36
 
36
37
  const log = logger('libp2p:plaintext')
37
38
  const PROTOCOL = '/plaintext/2.0.0'
38
39
 
39
- function lpEncodeExchange (exchange: Exchange) {
40
+ function lpEncodeExchange (exchange: Exchange): Uint8ArrayList {
40
41
  const pb = Exchange.encode(exchange)
41
42
 
42
43
  return lp.encode.single(pb)
@@ -2,10 +2,11 @@
2
2
  /* eslint-disable complexity */
3
3
  /* eslint-disable @typescript-eslint/no-namespace */
4
4
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
5
6
 
6
7
  import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
7
- import type { Uint8ArrayList } from 'uint8arraylist'
8
8
  import type { Codec } from 'protons-runtime'
9
+ import type { Uint8ArrayList } from 'uint8arraylist'
9
10
 
10
11
  export interface Exchange {
11
12
  id?: Uint8Array
@@ -29,9 +30,7 @@ export namespace Exchange {
29
30
 
30
31
  if (obj.pubkey != null) {
31
32
  w.uint32(18)
32
- PublicKey.codec().encode(obj.pubkey, w, {
33
- writeDefaults: false
34
- })
33
+ PublicKey.codec().encode(obj.pubkey, w)
35
34
  }
36
35
 
37
36
  if (opts.lengthDelimited !== false) {
@@ -65,7 +64,7 @@ export namespace Exchange {
65
64
  return _codec
66
65
  }
67
66
 
68
- export const encode = (obj: Exchange): Uint8Array => {
67
+ export const encode = (obj: Partial<Exchange>): Uint8Array => {
69
68
  return encodeMessage(obj, Exchange.codec())
70
69
  }
71
70
 
@@ -89,7 +88,7 @@ enum __KeyTypeValues {
89
88
  }
90
89
 
91
90
  export namespace KeyType {
92
- export const codec = () => {
91
+ export const codec = (): Codec<KeyType> => {
93
92
  return enumeration<KeyType>(__KeyTypeValues)
94
93
  }
95
94
  }
@@ -108,12 +107,12 @@ export namespace PublicKey {
108
107
  w.fork()
109
108
  }
110
109
 
111
- if (opts.writeDefaults === true || (obj.Type != null && __KeyTypeValues[obj.Type] !== 0)) {
110
+ if (obj.Type != null && __KeyTypeValues[obj.Type] !== 0) {
112
111
  w.uint32(8)
113
112
  KeyType.codec().encode(obj.Type, w)
114
113
  }
115
114
 
116
- if (opts.writeDefaults === true || (obj.Data != null && obj.Data.byteLength > 0)) {
115
+ if ((obj.Data != null && obj.Data.byteLength > 0)) {
117
116
  w.uint32(18)
118
117
  w.bytes(obj.Data)
119
118
  }
@@ -152,7 +151,7 @@ export namespace PublicKey {
152
151
  return _codec
153
152
  }
154
153
 
155
- export const encode = (obj: PublicKey): Uint8Array => {
154
+ export const encode = (obj: Partial<PublicKey>): Uint8Array => {
156
155
  return encodeMessage(obj, PublicKey.codec())
157
156
  }
158
157
 
package/src/libp2p.ts CHANGED
@@ -10,9 +10,7 @@ import { codes } from './errors.js'
10
10
  import { DefaultAddressManager } from './address-manager/index.js'
11
11
  import { DefaultConnectionManager } from './connection-manager/index.js'
12
12
  import { AutoDialler } from './connection-manager/auto-dialler.js'
13
- import { Circuit } from './circuit/transport.js'
14
- import { Relay } from './circuit/index.js'
15
- import { KeyChain } from './keychain/index.js'
13
+ import { DefaultKeyChain } from '@libp2p/keychain'
16
14
  import { DefaultTransportManager } from './transport-manager.js'
17
15
  import { DefaultUpgrader } from './upgrader.js'
18
16
  import { DefaultRegistrar } from './registrar.js'
@@ -24,10 +22,11 @@ import { PeerRecordUpdater } from './peer-record-updater.js'
24
22
  import { DHTPeerRouting } from './dht/dht-peer-routing.js'
25
23
  import { PersistentPeerStore } from '@libp2p/peer-store'
26
24
  import { DHTContentRouting } from './dht/dht-content-routing.js'
25
+ import { AutonatService } from './autonat/index.js'
27
26
  import { DefaultComponents } from './components.js'
28
27
  import type { Components } from './components.js'
29
28
  import type { PeerId } from '@libp2p/interface-peer-id'
30
- import type { Connection } from '@libp2p/interface-connection'
29
+ import type { Connection, Stream } from '@libp2p/interface-connection'
31
30
  import type { PeerRouting } from '@libp2p/interface-peer-routing'
32
31
  import type { ContentRouting } from '@libp2p/interface-content-routing'
33
32
  import type { PubSub } from '@libp2p/interface-pubsub'
@@ -41,7 +40,7 @@ import type { PeerStore } from '@libp2p/interface-peer-store'
41
40
  import type { DualDHT } from '@libp2p/interface-dht'
42
41
  import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
43
42
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
44
- import errCode from 'err-code'
43
+ import { CodeError } from '@libp2p/interfaces/errors'
45
44
  import { unmarshalPublicKey } from '@libp2p/crypto/keys'
46
45
  import type { Metrics } from '@libp2p/interface-metrics'
47
46
  import { DummyDHT } from './dht/dummy-dht.js'
@@ -50,6 +49,9 @@ import { PeerSet } from '@libp2p/peer-collections'
50
49
  import { DefaultDialer } from './connection-manager/dialer/index.js'
51
50
  import { peerIdFromString } from '@libp2p/peer-id'
52
51
  import type { Datastore } from 'interface-datastore'
52
+ import type { KeyChain } from '@libp2p/interface-keychain'
53
+ import mergeOptions from 'merge-options'
54
+ import type { CircuitRelayService } from './circuit/index.js'
53
55
 
54
56
  const log = logger('libp2p')
55
57
 
@@ -58,8 +60,10 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
58
60
  public dht: DualDHT
59
61
  public pubsub: PubSub
60
62
  public identifyService: IdentifyService
63
+ public circuitService?: CircuitRelayService
61
64
  public fetchService: FetchService
62
65
  public pingService: PingService
66
+ public autonatService: AutonatService
63
67
  public components: Components
64
68
  public peerStore: PeerStore
65
69
  public contentRouting: ContentRouting
@@ -153,15 +157,9 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
153
157
  // update our peer record when addresses change
154
158
  this.configureComponent(new PeerRecordUpdater(this.components))
155
159
 
156
- this.configureComponent(new AutoDialler(this.components, {
157
- enabled: init.connectionManager.autoDial,
158
- minConnections: init.connectionManager.minConnections,
159
- autoDialInterval: init.connectionManager.autoDialInterval
160
- }))
161
-
162
160
  // Create keychain
163
- const keychainOpts = KeyChain.generateOptions()
164
- this.keychain = this.configureComponent(new KeyChain(this.components, {
161
+ const keychainOpts = DefaultKeyChain.generateOptions()
162
+ this.keychain = this.configureComponent(new DefaultKeyChain(this.components, {
165
163
  ...keychainOpts,
166
164
  ...init.keychain
167
165
  }))
@@ -169,10 +167,6 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
169
167
  // Create the Nat Manager
170
168
  this.services.push(new NatManager(this.components, init.nat))
171
169
 
172
- init.transports.forEach((fn) => {
173
- this.components.transportManager.add(this.configureComponent(fn(this.components)))
174
- })
175
-
176
170
  // Add the identify service
177
171
  this.identifyService = new IdentifyService(this.components, {
178
172
  ...init.identify
@@ -224,15 +218,6 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
224
218
  routers: contentRouters
225
219
  }))
226
220
 
227
- if (init.relay.enabled) {
228
- this.components.transportManager.add(this.configureComponent(new Circuit(this.components, init.relay)))
229
-
230
- this.configureComponent(new Relay(this.components, {
231
- addressSorter: init.connectionManager.addressSorter,
232
- ...init.relay
233
- }))
234
- }
235
-
236
221
  this.fetchService = this.configureComponent(new FetchService(this.components, {
237
222
  ...init.fetch
238
223
  }))
@@ -241,6 +226,19 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
241
226
  ...init.ping
242
227
  }))
243
228
 
229
+ this.autonatService = this.configureComponent(new AutonatService(this.components, {
230
+ ...init.autonat
231
+ }))
232
+
233
+ this.configureComponent(new AutoDialler(this.components, {
234
+ minConnections: init.connectionManager.minConnections,
235
+ autoDialInterval: init.connectionManager.autoDialInterval
236
+ }))
237
+
238
+ if (init.relay != null) {
239
+ this.circuitService = this.configureComponent(init.relay(this.components))
240
+ }
241
+
244
242
  // Discovery modules
245
243
  for (const fn of init.peerDiscovery ?? []) {
246
244
  const service = this.configureComponent(fn(this.components))
@@ -249,6 +247,11 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
249
247
  this.onDiscoveryPeer(evt)
250
248
  })
251
249
  }
250
+
251
+ // Transport modules
252
+ init.transports.forEach((fn) => {
253
+ this.components.transportManager.add(this.configureComponent(fn(this.components)))
254
+ })
252
255
  }
253
256
 
254
257
  private configureComponent <T> (component: T): T {
@@ -262,7 +265,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
262
265
  /**
263
266
  * Starts the libp2p node and all its subsystems
264
267
  */
265
- async start () {
268
+ async start (): Promise<void> {
266
269
  if (this.started) {
267
270
  return
268
271
  }
@@ -271,6 +274,13 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
271
274
 
272
275
  log('libp2p is starting')
273
276
 
277
+ const keys = await this.keychain.listKeys()
278
+
279
+ if (keys.find(key => key.name === 'self') == null) {
280
+ log('importing self key into keychain')
281
+ await this.keychain.importPeer('self', this.components.peerId)
282
+ }
283
+
274
284
  try {
275
285
  await Promise.all(
276
286
  this.services.map(async service => {
@@ -282,7 +292,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
282
292
 
283
293
  // start any startables
284
294
  await Promise.all(
285
- this.services.map(service => service.start())
295
+ this.services.map(async service => { await service.start() })
286
296
  )
287
297
 
288
298
  await Promise.all(
@@ -304,7 +314,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
304
314
  /**
305
315
  * Stop the libp2p node by closing its listeners and open connections
306
316
  */
307
- async stop () {
317
+ async stop (): Promise<void> {
308
318
  if (!this.started) {
309
319
  return
310
320
  }
@@ -322,7 +332,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
322
332
  )
323
333
 
324
334
  await Promise.all(
325
- this.services.map(service => service.stop())
335
+ this.services.map(async service => { await service.stop() })
326
336
  )
327
337
 
328
338
  await Promise.all(
@@ -336,7 +346,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
336
346
  log('libp2p has stopped')
337
347
  }
338
348
 
339
- isStarted () {
349
+ isStarted (): boolean {
340
350
  return this.started
341
351
  }
342
352
 
@@ -358,15 +368,15 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
358
368
  return await this.components.connectionManager.openConnection(peer, options)
359
369
  }
360
370
 
361
- async dialProtocol (peer: PeerId | Multiaddr, protocols: string | string[], options: AbortOptions = {}) {
371
+ async dialProtocol (peer: PeerId | Multiaddr, protocols: string | string[], options: AbortOptions = {}): Promise<Stream> {
362
372
  if (protocols == null) {
363
- throw errCode(new Error('no protocols were provided to open a stream'), codes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
373
+ throw new CodeError('no protocols were provided to open a stream', codes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
364
374
  }
365
375
 
366
376
  protocols = Array.isArray(protocols) ? protocols : [protocols]
367
377
 
368
378
  if (protocols.length === 0) {
369
- throw errCode(new Error('no protocols were provided to open a stream'), codes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
379
+ throw new CodeError('no protocols were provided to open a stream', codes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
370
380
  }
371
381
 
372
382
  const connection = await this.dial(peer, options)
@@ -407,7 +417,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
407
417
  }
408
418
 
409
419
  if (this.dht == null) {
410
- throw errCode(new Error('Public key was not in the peer store and the DHT is not enabled'), codes.ERR_NO_ROUTERS_AVAILABLE)
420
+ throw new CodeError('Public key was not in the peer store and the DHT is not enabled', codes.ERR_NO_ROUTERS_AVAILABLE)
411
421
  }
412
422
 
413
423
  const peerKey = uint8ArrayConcat([
@@ -426,7 +436,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
426
436
  }
427
437
  }
428
438
 
429
- throw errCode(new Error(`Node not responding with its public key: ${peer.toString()}`), codes.ERR_INVALID_RECORD)
439
+ throw new CodeError(`Node not responding with its public key: ${peer.toString()}`, codes.ERR_INVALID_RECORD)
430
440
  }
431
441
 
432
442
  async fetch (peer: PeerId | Multiaddr, key: string, options: AbortOptions = {}): Promise<Uint8Array | null> {
@@ -477,7 +487,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
477
487
  return await this.registrar.register(protocol, topology)
478
488
  }
479
489
 
480
- unregister (id: string) {
490
+ unregister (id: string): void {
481
491
  this.registrar.unregister(id)
482
492
  }
483
493
 
@@ -485,7 +495,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
485
495
  * Called whenever peer discovery services emit `peer` events.
486
496
  * Known peers may be emitted.
487
497
  */
488
- onDiscoveryPeer (evt: CustomEvent<PeerInfo>) {
498
+ onDiscoveryPeer (evt: CustomEvent<PeerInfo>): void {
489
499
  const { detail: peer } = evt
490
500
 
491
501
  if (peer.id.toString() === this.peerId.toString()) {
@@ -494,11 +504,11 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
494
504
  }
495
505
 
496
506
  if (peer.multiaddrs.length > 0) {
497
- void this.components.peerStore.addressBook.add(peer.id, peer.multiaddrs).catch(err => log.error(err))
507
+ void this.components.peerStore.addressBook.add(peer.id, peer.multiaddrs).catch(err => { log.error(err) })
498
508
  }
499
509
 
500
510
  if (peer.protocols.length > 0) {
501
- void this.components.peerStore.protoBook.set(peer.id, peer.protocols).catch(err => log.error(err))
511
+ void this.components.peerStore.protoBook.set(peer.id, peer.protocols).catch(err => { log.error(err) })
502
512
  }
503
513
 
504
514
  this.dispatchEvent(new CustomEvent<PeerInfo>('peer:discovery', { detail: peer }))
@@ -516,13 +526,9 @@ export async function createLibp2pNode (options: Libp2pOptions): Promise<Libp2pN
516
526
  if (datastore != null) {
517
527
  try {
518
528
  // try load the peer id from the keychain
519
- // @ts-expect-error missing the peer id property
520
- const keyChain = new KeyChain({
529
+ const keyChain = new DefaultKeyChain({
521
530
  datastore
522
- }, {
523
- ...KeyChain.generateOptions(),
524
- ...(options.keychain ?? {})
525
- })
531
+ }, mergeOptions(DefaultKeyChain.generateOptions(), options.keychain))
526
532
 
527
533
  options.peerId = await keyChain.exportPeerId('self')
528
534
  } catch (err: any) {