Skip to content

Commit 32627c8

Browse files
authored
docs: update comments in interface module and elsewhere (#3107)
Fixes #2112
1 parent 213a54a commit 32627c8

File tree

26 files changed

+254
-41
lines changed

26 files changed

+254
-41
lines changed

packages/config/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ repo and examine the changes made.
2424
2525
-->
2626

27+
Utilities to make working with libp2p configuration simpler.
28+
2729
## Example - Load or create the "self" private key in a datastore
2830

2931
Most nodes will want to persist the same private key between restarts so this
@@ -33,7 +35,7 @@ will create a new one and save it in the keystore.
3335
The options you pass to this function should be the same as those passed to
3436
the `@libp2p/keychain` service you configure your node with.
3537

36-
```ts
38+
```TypeScript
3739
import { loadOrCreateSelfKey } from '@libp2p/config'
3840
import { keychain } from '@libp2p/keychain'
3941
import { LevelDatastore } from 'datastore-level'

packages/config/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* @packageDocumentation
33
*
4+
* Utilities to make working with libp2p configuration simpler.
5+
*
46
* @example Load or create the "self" private key in a datastore
57
*
68
* Most nodes will want to persist the same private key between restarts so this
@@ -10,7 +12,7 @@
1012
* The options you pass to this function should be the same as those passed to
1113
* the `@libp2p/keychain` service you configure your node with.
1214
*
13-
* ```ts
15+
* ```TypeScript
1416
* import { loadOrCreateSelfKey } from '@libp2p/config'
1517
* import { keychain } from '@libp2p/keychain'
1618
* import { LevelDatastore } from 'datastore-level'

packages/connection-encrypter-plaintext/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ repo and examine the changes made.
2424
2525
-->
2626

27-
A connection encrypter that does no connection encryption.
27+
A connection encrypter that does no connection encryption and trusts the
28+
remote peer to provide the correct PeerId.
2829

29-
This should not be used in production should be used for research purposes only.
30+
This should not be used in production and is for research purposes only.
3031

3132
## Example
3233

packages/connection-encrypter-plaintext/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* @packageDocumentation
33
*
4-
* A connection encrypter that does no connection encryption.
4+
* A connection encrypter that does no connection encryption and trusts the
5+
* remote peer to provide the correct PeerId.
56
*
6-
* This should not be used in production should be used for research purposes only.
7+
* This should not be used in production and is for research purposes only.
78
*
89
* @example
910
*

packages/crypto/src/ciphers/aes-gcm.browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { concat } from 'uint8arrays/concat'
22
import { fromString } from 'uint8arrays/from-string'
33
import webcrypto from '../webcrypto/index.js'
4-
import type { CreateOptions, AESCipher } from './interface.js'
4+
import type { CreateAESCipherOptions, AESCipher } from './interface.js'
55

66
// WebKit on Linux does not support deriving a key from an empty PBKDF2 key.
77
// So, as a workaround, we provide the generated key as a constant. We test that
@@ -24,7 +24,7 @@ export const derivedEmptyPasswordKey = {
2424

2525
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
2626

27-
export function create (opts?: CreateOptions): AESCipher {
27+
export function create (opts?: CreateAESCipherOptions): AESCipher {
2828
const algorithm = opts?.algorithm ?? 'AES-GCM'
2929
let keyLength = opts?.keyLength ?? 16
3030
const nonceLength = opts?.nonceLength ?? 12

packages/crypto/src/ciphers/aes-gcm.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import crypto from 'crypto'
22
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
33
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
4-
import type { CreateOptions, AESCipher } from './interface.js'
4+
import type { CreateAESCipherOptions, AESCipher } from './interface.js'
5+
6+
export type { AESCipher, CreateAESCipherOptions }
57

68
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
79

8-
export function create (opts?: CreateOptions): AESCipher {
10+
export function create (opts?: CreateAESCipherOptions): AESCipher {
911
const algorithm = opts?.algorithm ?? 'aes-128-gcm'
1012
const keyLength = opts?.keyLength ?? 16
1113
const nonceLength = opts?.nonceLength ?? 12

packages/crypto/src/ciphers/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface CreateOptions {
1+
export interface CreateAESCipherOptions {
22
algorithm?: string
33
nonceLength?: number
44
keyLength?: number
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import Sinon from 'sinon'
22
import type { PeerId } from '@libp2p/interface'
33
import type { Multiaddr } from '@multiformats/multiaddr'
4+
import type { SinonMatcher } from 'sinon'
45

56
/**
67
* @deprecated PeerIds can be passed to sinon matchers directly
78
*/
8-
export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher {
9+
export function matchPeerId (peerId: PeerId): SinonMatcher {
910
return Sinon.match(p => p.toString() === peerId.toString())
1011
}
1112

1213
/**
1314
* @deprecated Multiaddrs can be passed to sinon matchers directly
1415
*/
15-
export function matchMultiaddr (ma: Multiaddr): Sinon.SinonMatcher {
16+
export function matchMultiaddr (ma: Multiaddr): SinonMatcher {
1617
return Sinon.match(m => m.toString() === ma.toString())
1718
}

packages/interface/src/content-routing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CID } from 'multiformats/cid'
44

55
/**
66
* Any object that implements this Symbol as a property should return a
7-
* ContentRouting instance as the property value, similar to how
7+
* Partial<ContentRouting> instance as the property value, similar to how
88
* `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
99
*
1010
* @example
@@ -28,7 +28,7 @@ export const contentRoutingSymbol = Symbol.for('@libp2p/content-routing')
2828
* interested callers.
2929
*/
3030
export interface ContentRoutingProvider {
31-
[contentRoutingSymbol]: ContentRouting
31+
[contentRoutingSymbol]: Partial<ContentRouting>
3232
}
3333

3434
export interface ContentRouting {

packages/interface/src/errors.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export class TooManyOutboundProtocolStreamsError extends Error {
353353
}
354354

355355
/**
356-
* Thrown when and attempt to operate on an unsupported key was made
356+
* Thrown when an attempt to operate on an unsupported key was made
357357
*/
358358
export class UnsupportedKeyTypeError extends Error {
359359
static name = 'UnsupportedKeyTypeError'
@@ -363,3 +363,15 @@ export class UnsupportedKeyTypeError extends Error {
363363
this.name = 'UnsupportedKeyTypeError'
364364
}
365365
}
366+
367+
/**
368+
* Thrown when an operation has not been implemented
369+
*/
370+
export class NotImplementedError extends Error {
371+
static name = 'NotImplementedError'
372+
373+
constructor (message = 'Not implemented') {
374+
super(message)
375+
this.name = 'NotImplementedError'
376+
}
377+
}

0 commit comments

Comments
 (0)