Skip to content

Commit

Permalink
refactor!: remove libp2p.keychain (#2084)
Browse files Browse the repository at this point in the history
Extract the keychain into it's own package.
  • Loading branch information
wemeetagain authored and achingbrain committed Nov 15, 2023
1 parent 511359a commit 125c84b
Show file tree
Hide file tree
Showing 12 changed files with 769 additions and 886 deletions.
48 changes: 47 additions & 1 deletion doc/migrations/v0.46-v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,57 @@ A migration guide for refactoring your application code from libp2p `v0.46` to `

- [New features](#new-features)
- [Breaking changes](#breaking-changes)
- [KeyChain](#keychain)
- [Metrics](#metrics)

## New features

...

## Breaking changes

...
```ts
import { autoNATService } from 'libp2p/autonat'
```

**After**

```ts
import { autoNATService } from '@libp2p/autonat'
```

## KeyChain

The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.

**Before**

```ts
import type { KeyChain } from '@libp2p/interface/keychain'

const libp2p = await createLibp2p(...)

const keychain: KeyChain = libp2p.keychain
```

**After**

```ts
import { keychain, type Keychain } from '@libp2p/keychain'

const libp2p = await createLibp2p({
...
services: {
keychain: keychain()
}
})

const keychain: Keychain = libp2p.services.keychain
```

## Metrics

The following metrics were renamed:

`libp2p_dialler_pending_dials` => `libp2p_dial_queue_pending_dials`
`libp2p_dialler_in_progress_dials` => `libp2p_dial_queue_in_progress_dials`
32 changes: 32 additions & 0 deletions doc/migrations/v0.46-v1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ __Describe__
-->

### KeyChain

The KeyChain object is no longer included on Libp2p and must be instantiated explicitly if desired.

**Before**

```ts
import type { KeyChain } from '@libp2p/interface/keychain'

const libp2p = await createLibp2p(...)

const keychain: KeyChain = libp2p.keychain
```

***After***

```ts
import { DefaultKeyChain } from '@libp2p/keychain'
import type { KeyChain } from '@libp2p/interface/keychain'

const libp2p = await createLibp2p({
...
services: {
keychain: (components) => new DefaultKeyChain(components, {
...DefaultKeyChain.generateOptions()
})
}
})

const keychain: KeyChain = libp2p.services.keychain
```

## Module Updates

With this release you should update the following libp2p modules if you are relying on them:
Expand Down
15 changes: 0 additions & 15 deletions packages/interface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import type { Connection, NewStreamOptions, Stream } from './connection/index.js'
import type { ContentRouting } from './content-routing/index.js'
import type { TypedEventTarget } from './events.js'
import type { KeyChain } from './keychain/index.js'
import type { Metrics } from './metrics/index.js'
import type { PeerId } from './peer-id/index.js'
import type { PeerInfo } from './peer-info/index.js'
Expand Down Expand Up @@ -394,20 +393,6 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
*/
contentRouting: ContentRouting

/**
* The keychain contains the keys used by the current node, and can create new
* keys, export them, import them, etc.
*
* @example
*
* ```js
* const keyInfo = await libp2p.keychain.createKey('new key')
* console.info(keyInfo)
* // { id: '...', name: 'new key' }
* ```
*/
keychain: KeyChain

/**
* The metrics subsystem allows recording values to assess the health/performance
* of the running node.
Expand Down
167 changes: 0 additions & 167 deletions packages/interface/src/keychain/index.ts

This file was deleted.

Loading

0 comments on commit 125c84b

Please sign in to comment.