Skip to content

Commit

Permalink
feat: add service capabilities definition (#429)
Browse files Browse the repository at this point in the history
The latest libp2p release allows services to declare their
capabilities (what they provide to the node) and their
dependencies (the capabilities they require other services to
provide for the config to be "valid").

Adds the `serviceCapabilities` symbol property that says Noise
provides the `@libp2p/connection-encryption` capability and also
that it provides noise encryption as some transports (WebTransport,
WebRTC) now require this module to be configured alongside them.
  • Loading branch information
achingbrain authored Jun 20, 2024
1 parent cd2910a commit a3b517b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@chainsafe/as-chacha20poly1305": "^0.1.0",
"@chainsafe/as-sha256": "^0.4.1",
"@libp2p/crypto": "^4.0.0",
"@libp2p/interface": "^1.0.0",
"@libp2p/interface": "^1.5.0",
"@libp2p/peer-id": "^4.0.0",
"@noble/ciphers": "^0.5.1",
"@noble/curves": "^1.1.0",
Expand Down
9 changes: 8 additions & 1 deletion src/noise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { unmarshalPrivateKey } from '@libp2p/crypto/keys'
import { type MultiaddrConnection, type SecuredConnection, type PeerId, CodeError, type PrivateKey } from '@libp2p/interface'
import { type MultiaddrConnection, type SecuredConnection, type PeerId, CodeError, type PrivateKey, serviceCapabilities } from '@libp2p/interface'
import { peerIdFromKeys } from '@libp2p/peer-id'
import { decode } from 'it-length-prefixed'
import { lpStream, type LengthPrefixedStream } from 'it-length-prefixed-stream'
Expand Down Expand Up @@ -58,6 +58,13 @@ export class Noise implements INoiseConnection {
this.prologue = prologueBytes ?? uint8ArrayAlloc(0)
}

readonly [Symbol.toStringTag] = '@chainsafe/libp2p-noise'

readonly [serviceCapabilities]: string[] = [
'@libp2p/connection-encryption',
'@chainsafe/libp2p-noise'
]

/**
* Encrypt outgoing data to the remote party (handshake as initiator)
*
Expand Down

0 comments on commit a3b517b

Please sign in to comment.