Skip to content

Commit ea07f0b

Browse files
authored
deps!: update to [email protected] deps (#241)
Updates all libp2p deps. BREAKING CHANGE: can only be used with the latest versions of `@libp2p/peer-id`, `@libp2p/interface` etc
1 parent 4caa5c6 commit ea07f0b

File tree

16 files changed

+72
-52
lines changed

16 files changed

+72
-52
lines changed

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@
152152
"@ipld/dag-cbor": "^9.0.0",
153153
"@ipld/dag-json": "^10.0.0",
154154
"@ipld/dag-pb": "^4.0.0",
155-
"@libp2p/interface": "^1.2.0",
156-
"@libp2p/logger": "^4.0.10",
157-
"@libp2p/peer-id": "^4.0.10",
155+
"@libp2p/crypto": "^5.0.0",
156+
"@libp2p/interface": "^2.0.0",
157+
"@libp2p/logger": "^5.0.0",
158+
"@libp2p/peer-id": "^5.0.0",
158159
"@multiformats/multiaddr": "^12.2.1",
159160
"@multiformats/multiaddr-to-uri": "^10.0.1",
160161
"any-signal": "^4.1.1",
@@ -184,21 +185,19 @@
184185
},
185186
"devDependencies": {
186187
"@ipld/car": "^5.0.3",
187-
"@libp2p/crypto": "^4.0.6",
188-
"@libp2p/peer-id-factory": "^4.0.10",
189188
"@types/pako": "^2.0.3",
190189
"@types/readable-stream": "^4.0.11",
191190
"@types/sinon": "^17.0.3",
192191
"@web-std/file": "^3.0.3",
193192
"aegir": "^44.0.1",
194-
"blockstore-core": "^4.4.1",
193+
"blockstore-core": "^5.0.0",
195194
"buffer": "^6.0.3",
196195
"delay": "^6.0.0",
197196
"did-jwt": "^8.0.4",
198197
"interface-blockstore": "^5.2.10",
199198
"ipfs-unixfs-importer": "^15.2.5",
200-
"ipfsd-ctl": "^14.0.0",
201-
"ipns": "^9.1.0",
199+
"ipfsd-ctl": "^14.1.3",
200+
"ipns": "^10.0.0",
202201
"is-ipfs": "^8.0.1",
203202
"iso-random-stream": "^2.0.2",
204203
"it-buffer-stream": "^3.0.0",
@@ -237,5 +236,9 @@
237236
"fs/promises": false,
238237
"node:fs/promises": false
239238
},
240-
"sideEffects": false
239+
"sideEffects": false,
240+
"overrides": {
241+
"@libp2p/interface": "^2.0.0",
242+
"@libp2p/logger": "^5.0.0"
243+
}
241244
}

src/lib/errors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ export class HTTPError extends Error {
2121
this.response = response
2222
}
2323
}
24+
25+
export class InvalidMtimeError extends Error {
26+
constructor (message = 'Invalid mtime') {
27+
super(message)
28+
this.name = 'InvalidMtimeError'
29+
}
30+
}

src/lib/files/normalise-content.browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError } from '@libp2p/interface'
1+
import { InvalidParametersError } from '@libp2p/interface'
22
import browserStreamToIt from 'browser-readablestream-to-it'
33
import all from 'it-all'
44
import itPeekable from 'it-peekable'
@@ -59,7 +59,7 @@ export async function normaliseContent (input: ToContent): Promise<Blob> {
5959
}
6060

6161
// eslint-disable-next-line @typescript-eslint/no-base-to-string
62-
throw new CodeError(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT')
62+
throw new InvalidParametersError(`Unexpected input: ${input}`)
6363
}
6464

6565
async function itToBlob (stream: AsyncIterable<BlobPart> | Iterable<BlobPart>): Promise<Blob> {

src/lib/files/normalise-content.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError } from '@libp2p/interface'
1+
import { InvalidParametersError } from '@libp2p/interface'
22
import blobToIt from 'blob-to-it'
33
import browserStreamToIt from 'browser-readablestream-to-it'
44
import all from 'it-all'
@@ -66,7 +66,7 @@ export async function normaliseContent (input: ToContent): Promise<AsyncIterable
6666
}
6767

6868
// eslint-disable-next-line @typescript-eslint/no-base-to-string
69-
throw new CodeError(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT')
69+
throw new InvalidParametersError(`Unexpected input: ${input}`)
7070
}
7171

7272
function toBytes (chunk: ArrayBuffer | ArrayBufferView | string | InstanceType<typeof window.String> | number[]): Uint8Array {

src/lib/files/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError } from '@libp2p/interface'
1+
import { InvalidMtimeError } from '../errors.js'
22
import type { ImportCandidate } from '../../index.js'
33
import type { Mtime, MtimeLike } from 'ipfs-unixfs'
44

@@ -103,7 +103,7 @@ export function parseMtime (mtime?: MtimeLike): Mtime | undefined {
103103
}
104104

105105
if (mtime.nsecs != null && (mtime.nsecs < 0 || mtime.nsecs > 999999999)) {
106-
throw new CodeError('mtime-nsecs must be within the range [0,999999999]', 'ERR_INVALID_MTIME_NSECS')
106+
throw new InvalidMtimeError('mtime-nsecs must be within the range [0,999999999]')
107107
}
108108

109109
return mtime

src/lib/glob-source.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs'
22
import fsp from 'node:fs/promises'
33
import os from 'node:os'
44
import Path from 'node:path'
5-
import { CodeError } from '@libp2p/interface'
5+
import { InvalidParametersError } from '@libp2p/interface'
66
import glob from 'it-glob'
77
import type { MtimeLike } from 'ipfs-unixfs'
88
import type { Options as GlobOptions } from 'it-glob'
@@ -53,7 +53,7 @@ export async function * globSource (cwd: string, pattern: string, options?: Glob
5353
options = options ?? {}
5454

5555
if (typeof pattern !== 'string') {
56-
throw new CodeError('Pattern must be a string', 'ERR_INVALID_PATH', { pattern })
56+
throw new InvalidParametersError('Pattern must be a string')
5757
}
5858

5959
if (!Path.isAbsolute(cwd)) {

src/lib/pins/normalise-input.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError } from '@libp2p/interface'
1+
import { InvalidParametersError } from '@libp2p/interface'
22
import { CID } from 'multiformats/cid'
33

44
export interface Pinnable {
@@ -56,7 +56,7 @@ function isCID (thing: any): thing is CID {
5656
export async function * normaliseInput (input: Source): AsyncGenerator<Pin> {
5757
// must give us something
5858
if (input === null || input === undefined) {
59-
throw new CodeError(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT')
59+
throw new InvalidParametersError(`Unexpected input: ${input}`)
6060
}
6161

6262
// CID
@@ -115,7 +115,7 @@ export async function * normaliseInput (input: Source): AsyncGenerator<Pin> {
115115
return
116116
}
117117

118-
throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
118+
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)
119119
}
120120

121121
// AsyncIterable<?>
@@ -151,17 +151,17 @@ export async function * normaliseInput (input: Source): AsyncGenerator<Pin> {
151151
return
152152
}
153153

154-
throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
154+
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)
155155
}
156156

157-
throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
157+
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)
158158
}
159159

160160
function toPin (input: Pinnable): Pin {
161161
const path = input.cid ?? `${input.path}`
162162

163163
if (path == null) {
164-
throw new CodeError('Unexpected input: Please path either a CID or an IPFS path', 'ERR_UNEXPECTED_INPUT')
164+
throw new InvalidParametersError('Unexpected input: Please path either a CID or an IPFS path')
165165
}
166166

167167
const pin: Pin = {

src/pubsub/subscribe.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
12
import { logger } from '@libp2p/logger'
23
import { peerIdFromString } from '@libp2p/peer-id'
34
import { textToUrlSafeRpc, rpcToText, rpcToBytes, rpcToBigInt } from '../lib/http-rpc-wire-format.js'
@@ -104,7 +105,8 @@ async function readMessages (response: ExtendedResponse, { onMessage, onEnd, onE
104105
data: rpcToBytes(msg.data),
105106
sequenceNumber: rpcToBigInt(msg.seqno),
106107
topic: rpcToText(msg.topicIDs[0]),
107-
key: rpcToBytes(msg.key ?? 'u'),
108+
// @ts-expect-error kubo does not supply the key
109+
key: msg.key != null ? publicKeyFromProtobuf(rpcToBytes(msg.key ?? 'u')) : undefined,
108110
signature: rpcToBytes(msg.signature ?? 'u')
109111
})
110112
} else {

test/interface-tests.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env mocha */
22

3+
import { path } from 'kubo'
34
import { isWindows, isFirefox, isChrome } from './constants.js'
45
import * as tests from './interface-tests/src/index.js'
56
import { factory } from './utils/factory.js'
@@ -261,13 +262,12 @@ function executeTests (commonFactory: Factory<KuboNode>): void {
261262

262263
describe('kubo-rpc-client tests against kubo', function () {
263264
void (async function () {
264-
const { path } = await import('kubo')
265265
/**
266266
* @type {string|undefined}
267267
*/
268268
const commonFactory = factory({
269269
type: 'kubo',
270-
bin: path(),
270+
bin: path?.(),
271271
test: true
272272
})
273273
describe('kubo RPC client interface tests', function () {

test/interface-tests/src/key/gen.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
/* eslint-env mocha */
22

3-
import { keys } from '@libp2p/crypto'
43
import { expect } from 'aegir/chai'
54
import { nanoid } from 'nanoid'
65
import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
76
import type { KuboRPCClient } from '../../../../src/index.js'
87
import type { KeyType } from '../../../../src/key/index.js'
98
import type { Factory, KuboNode } from 'ipfsd-ctl'
109

11-
const { supportedKeys } = keys
12-
1310
interface KeyTest {
1411
opts: {
1512
type?: KeyType
1613
size?: number
1714
}
18-
expectedType: any
1915
}
2016

2117
export function testGen (factory: Factory<KuboNode>, options: MochaConfig): void {
@@ -25,12 +21,10 @@ export function testGen (factory: Factory<KuboNode>, options: MochaConfig): void
2521
describe('.key.gen', () => {
2622
const keyTypes: KeyTest[] = [
2723
{
28-
opts: { type: 'ed25519' },
29-
expectedType: supportedKeys.ed25519.Ed25519PrivateKey
24+
opts: { type: 'ed25519' }
3025
},
3126
{
32-
opts: { },
33-
expectedType: supportedKeys.ed25519.Ed25519PrivateKey
27+
opts: { }
3428
}
3529
]
3630

0 commit comments

Comments
 (0)