@@ -5,15 +5,13 @@ import { CodeError } from '@libp2p/interface/errors'
5
5
import { TypedEventEmitter , CustomEvent } from '@libp2p/interface/events'
6
6
import { peerDiscovery } from '@libp2p/interface/peer-discovery'
7
7
import { type PeerRouting , peerRouting } from '@libp2p/interface/peer-routing'
8
- import { DefaultKeyChain } from '@libp2p/keychain'
9
8
import { logger } from '@libp2p/logger'
10
9
import { PeerSet } from '@libp2p/peer-collections'
11
10
import { peerIdFromString } from '@libp2p/peer-id'
12
11
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
13
12
import { PersistentPeerStore } from '@libp2p/peer-store'
14
13
import { isMultiaddr , type Multiaddr } from '@multiformats/multiaddr'
15
14
import { MemoryDatastore } from 'datastore-core/memory'
16
- import mergeOptions from 'merge-options'
17
15
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
18
16
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
19
17
import { DefaultAddressManager } from './address-manager/index.js'
@@ -31,14 +29,12 @@ import type { Components } from './components.js'
31
29
import type { Libp2p , Libp2pInit , Libp2pOptions } from './index.js'
32
30
import type { Libp2pEvents , PendingDial , ServiceMap , AbortOptions } from '@libp2p/interface'
33
31
import type { Connection , NewStreamOptions , Stream } from '@libp2p/interface/connection'
34
- import type { KeyChain } from '@libp2p/interface/keychain'
35
32
import type { Metrics } from '@libp2p/interface/metrics'
36
33
import type { PeerId } from '@libp2p/interface/peer-id'
37
34
import type { PeerInfo } from '@libp2p/interface/peer-info'
38
35
import type { PeerStore } from '@libp2p/interface/peer-store'
39
36
import type { Topology } from '@libp2p/interface/topology'
40
37
import type { StreamHandler , StreamHandlerOptions } from '@libp2p/interface-internal/registrar'
41
- import type { Datastore } from 'interface-datastore'
42
38
43
39
const log = logger ( 'libp2p' )
44
40
@@ -47,7 +43,6 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
47
43
public peerStore : PeerStore
48
44
public contentRouting : ContentRouting
49
45
public peerRouting : PeerRouting
50
- public keychain : KeyChain
51
46
public metrics ?: Metrics
52
47
public services : T
53
48
@@ -133,13 +128,6 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
133
128
// Addresses {listen, announce, noAnnounce}
134
129
this . configureComponent ( 'addressManager' , new DefaultAddressManager ( this . components , init . addresses ) )
135
130
136
- // Create keychain
137
- const keychainOpts = DefaultKeyChain . generateOptions ( )
138
- this . keychain = this . configureComponent ( 'keyChain' , new DefaultKeyChain ( this . components , {
139
- ...keychainOpts ,
140
- ...init . keychain
141
- } ) )
142
-
143
131
// Peer routers
144
132
const peerRouters : PeerRouting [ ] = ( init . peerRouters ?? [ ] ) . map ( ( fn , index ) => this . configureComponent ( `peer-router-${ index } ` , fn ( this . components ) ) )
145
133
this . peerRouting = this . components . peerRouting = this . configureComponent ( 'peerRouting' , new DefaultPeerRouting ( this . components , {
@@ -222,13 +210,6 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
222
210
223
211
log ( 'libp2p is starting' )
224
212
225
- const keys = await this . keychain . listKeys ( )
226
-
227
- if ( keys . find ( key => key . name === 'self' ) == null ) {
228
- log ( 'importing self key into keychain' )
229
- await this . keychain . importPeer ( 'self' , this . components . peerId )
230
- }
231
-
232
213
try {
233
214
await this . components . beforeStart ?.( )
234
215
await this . components . start ( )
@@ -411,29 +392,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
411
392
* libp2p interface and is useful for testing and debugging.
412
393
*/
413
394
export async function createLibp2pNode < T extends ServiceMap = Record < string , unknown > > ( options : Libp2pOptions < T > ) : Promise < Libp2pNode < T > > {
414
- if ( options . peerId == null ) {
415
- const datastore = options . datastore as Datastore | undefined
416
-
417
- if ( datastore != null ) {
418
- try {
419
- // try load the peer id from the keychain
420
- const keyChain = new DefaultKeyChain ( {
421
- datastore
422
- } , mergeOptions ( DefaultKeyChain . generateOptions ( ) , options . keychain ) )
423
-
424
- options . peerId = await keyChain . exportPeerId ( 'self' )
425
- } catch ( err : any ) {
426
- if ( err . code !== 'ERR_NOT_FOUND' ) {
427
- throw err
428
- }
429
- }
430
- }
431
- }
432
-
433
- if ( options . peerId == null ) {
434
- // no peer id in the keychain, create a new peer id
435
- options . peerId = await createEd25519PeerId ( )
436
- }
395
+ options . peerId ??= await createEd25519PeerId ( )
437
396
438
397
return new Libp2pNode ( validateConfig ( options ) )
439
398
}
0 commit comments