Skip to content

Commit 4c601eb

Browse files
wemeetagainachingbrain
authored andcommitted
refactor!: remove libp2p.keychain (#2084)
Extract the keychain into it's own package.
1 parent 9681b9c commit 4c601eb

File tree

12 files changed

+769
-886
lines changed

12 files changed

+769
-886
lines changed

doc/migrations/v0.46-v1.0.0.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,57 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `
66

77
- [New features](#new-features)
88
- [Breaking changes](#breaking-changes)
9+
- [KeyChain](#keychain)
10+
- [Metrics](#metrics)
911

1012
## New features
1113

1214
...
1315

1416
## Breaking changes
1517

16-
...
18+
```ts
19+
import { autoNATService } from 'libp2p/autonat'
20+
```
21+
22+
**After**
23+
24+
```ts
25+
import { autoNATService } from '@libp2p/autonat'
26+
```
27+
28+
## KeyChain
29+
30+
The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.
31+
32+
**Before**
33+
34+
```ts
35+
import type { KeyChain } from '@libp2p/interface/keychain'
36+
37+
const libp2p = await createLibp2p(...)
38+
39+
const keychain: KeyChain = libp2p.keychain
40+
```
41+
42+
**After**
43+
44+
```ts
45+
import { keychain, type Keychain } from '@libp2p/keychain'
46+
47+
const libp2p = await createLibp2p({
48+
...
49+
services: {
50+
keychain: keychain()
51+
}
52+
})
53+
54+
const keychain: Keychain = libp2p.services.keychain
55+
```
56+
57+
## Metrics
58+
59+
The following metrics were renamed:
60+
61+
`libp2p_dialler_pending_dials` => `libp2p_dial_queue_pending_dials`
62+
`libp2p_dialler_in_progress_dials` => `libp2p_dial_queue_in_progress_dials`

doc/migrations/v0.46-v1.0.md

+32
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ __Describe__
3232
3333
-->
3434

35+
### KeyChain
36+
37+
The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.
38+
39+
**Before**
40+
41+
```ts
42+
import type { KeyChain } from '@libp2p/interface/keychain'
43+
44+
const libp2p = await createLibp2p(...)
45+
46+
const keychain: KeyChain = libp2p.keychain
47+
```
48+
49+
***After***
50+
51+
```ts
52+
import { DefaultKeyChain } from '@libp2p/keychain'
53+
import type { KeyChain } from '@libp2p/interface/keychain'
54+
55+
const libp2p = await createLibp2p({
56+
...
57+
services: {
58+
keychain: (components) => new DefaultKeyChain(components, {
59+
...DefaultKeyChain.generateOptions()
60+
})
61+
}
62+
})
63+
64+
const keychain: KeyChain = libp2p.services.keychain
65+
```
66+
3567
## Module Updates
3668

3769
With this release you should update the following libp2p modules if you are relying on them:

packages/interface/src/index.ts

-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import type { Connection, NewStreamOptions, Stream } from './connection/index.js'
1818
import type { ContentRouting } from './content-routing/index.js'
1919
import type { TypedEventTarget } from './events.js'
20-
import type { KeyChain } from './keychain/index.js'
2120
import type { Metrics } from './metrics/index.js'
2221
import type { PeerId } from './peer-id/index.js'
2322
import type { PeerInfo } from './peer-info/index.js'
@@ -394,20 +393,6 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
394393
*/
395394
contentRouting: ContentRouting
396395

397-
/**
398-
* The keychain contains the keys used by the current node, and can create new
399-
* keys, export them, import them, etc.
400-
*
401-
* @example
402-
*
403-
* ```js
404-
* const keyInfo = await libp2p.keychain.createKey('new key')
405-
* console.info(keyInfo)
406-
* // { id: '...', name: 'new key' }
407-
* ```
408-
*/
409-
keychain: KeyChain
410-
411396
/**
412397
* The metrics subsystem allows recording values to assess the health/performance
413398
* of the running node.

packages/interface/src/keychain/index.ts

-167
This file was deleted.

0 commit comments

Comments
 (0)