Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps!: update to [email protected] deps #241

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@
"@ipld/dag-cbor": "^9.0.0",
"@ipld/dag-json": "^10.0.0",
"@ipld/dag-pb": "^4.0.0",
"@libp2p/interface": "^1.2.0",
"@libp2p/logger": "^4.0.10",
"@libp2p/peer-id": "^4.0.10",
"@libp2p/crypto": "^5.0.0",
"@libp2p/interface": "^2.0.0",
"@libp2p/logger": "^5.0.0",
"@libp2p/peer-id": "^5.0.0",
"@multiformats/multiaddr": "^12.2.1",
"@multiformats/multiaddr-to-uri": "^10.0.1",
"any-signal": "^4.1.1",
Expand Down Expand Up @@ -184,21 +185,19 @@
},
"devDependencies": {
"@ipld/car": "^5.0.3",
"@libp2p/crypto": "^4.0.6",
"@libp2p/peer-id-factory": "^4.0.10",
"@types/pako": "^2.0.3",
"@types/readable-stream": "^4.0.11",
"@types/sinon": "^17.0.3",
"@web-std/file": "^3.0.3",
"aegir": "^44.0.1",
"blockstore-core": "^4.4.1",
"blockstore-core": "^5.0.0",
"buffer": "^6.0.3",
"delay": "^6.0.0",
"did-jwt": "^8.0.4",
"interface-blockstore": "^5.2.10",
"ipfs-unixfs-importer": "^15.2.5",
"ipfsd-ctl": "^14.0.0",
"ipns": "^9.1.0",
"ipfsd-ctl": "^14.1.3",
"ipns": "^10.0.0",
"is-ipfs": "^8.0.1",
"iso-random-stream": "^2.0.2",
"it-buffer-stream": "^3.0.0",
Expand Down Expand Up @@ -237,5 +236,9 @@
"fs/promises": false,
"node:fs/promises": false
},
"sideEffects": false
"sideEffects": false,
"overrides": {
"@libp2p/interface": "^2.0.0",
"@libp2p/logger": "^5.0.0"
}
}
7 changes: 7 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
this.response = response
}
}

export class InvalidMtimeError extends Error {
constructor (message = 'Invalid mtime') {
super(message)
this.name = 'InvalidMtimeError'
}

Check warning on line 29 in src/lib/errors.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/errors.ts#L27-L29

Added lines #L27 - L29 were not covered by tests
}
4 changes: 2 additions & 2 deletions src/lib/files/normalise-content.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface'
import { InvalidParametersError } from '@libp2p/interface'
import browserStreamToIt from 'browser-readablestream-to-it'
import all from 'it-all'
import itPeekable from 'it-peekable'
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function normaliseContent (input: ToContent): Promise<Blob> {
}

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

async function itToBlob (stream: AsyncIterable<BlobPart> | Iterable<BlobPart>): Promise<Blob> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/files/normalise-content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface'
import { InvalidParametersError } from '@libp2p/interface'
import blobToIt from 'blob-to-it'
import browserStreamToIt from 'browser-readablestream-to-it'
import all from 'it-all'
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function normaliseContent (input: ToContent): Promise<AsyncIterable
}

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

function toBytes (chunk: ArrayBuffer | ArrayBufferView | string | InstanceType<typeof window.String> | number[]): Uint8Array {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/files/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface'
import { InvalidMtimeError } from '../errors.js'
import type { ImportCandidate } from '../../index.js'
import type { Mtime, MtimeLike } from 'ipfs-unixfs'

Expand Down Expand Up @@ -103,7 +103,7 @@
}

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

Check warning on line 106 in src/lib/files/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/files/utils.ts#L106

Added line #L106 was not covered by tests
}

return mtime
Expand Down
4 changes: 2 additions & 2 deletions src/lib/glob-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fsp from 'node:fs/promises'
import os from 'node:os'
import Path from 'node:path'
import { CodeError } from '@libp2p/interface'
import { InvalidParametersError } from '@libp2p/interface'
import glob from 'it-glob'
import type { MtimeLike } from 'ipfs-unixfs'
import type { Options as GlobOptions } from 'it-glob'
Expand Down Expand Up @@ -53,7 +53,7 @@
options = options ?? {}

if (typeof pattern !== 'string') {
throw new CodeError('Pattern must be a string', 'ERR_INVALID_PATH', { pattern })
throw new InvalidParametersError('Pattern must be a string')

Check warning on line 56 in src/lib/glob-source.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/glob-source.ts#L56

Added line #L56 was not covered by tests
}

if (!Path.isAbsolute(cwd)) {
Expand Down
12 changes: 6 additions & 6 deletions src/lib/pins/normalise-input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface'
import { InvalidParametersError } from '@libp2p/interface'
import { CID } from 'multiformats/cid'

export interface Pinnable {
Expand Down Expand Up @@ -56,7 +56,7 @@
export async function * normaliseInput (input: Source): AsyncGenerator<Pin> {
// must give us something
if (input === null || input === undefined) {
throw new CodeError(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT')
throw new InvalidParametersError(`Unexpected input: ${input}`)

Check warning on line 59 in src/lib/pins/normalise-input.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/pins/normalise-input.ts#L59

Added line #L59 was not covered by tests
}

// CID
Expand Down Expand Up @@ -115,7 +115,7 @@
return
}

throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)

Check warning on line 118 in src/lib/pins/normalise-input.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/pins/normalise-input.ts#L118

Added line #L118 was not covered by tests
}

// AsyncIterable<?>
Expand Down Expand Up @@ -151,17 +151,17 @@
return
}

throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)

Check warning on line 154 in src/lib/pins/normalise-input.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/pins/normalise-input.ts#L154

Added line #L154 was not covered by tests
}

throw new CodeError(`Unexpected input: ${typeof input}`, 'ERR_UNEXPECTED_INPUT')
throw new InvalidParametersError(`Unexpected input: ${typeof input}`)

Check warning on line 157 in src/lib/pins/normalise-input.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/pins/normalise-input.ts#L157

Added line #L157 was not covered by tests
}

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

if (path == null) {
throw new CodeError('Unexpected input: Please path either a CID or an IPFS path', 'ERR_UNEXPECTED_INPUT')
throw new InvalidParametersError('Unexpected input: Please path either a CID or an IPFS path')

Check warning on line 164 in src/lib/pins/normalise-input.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/pins/normalise-input.ts#L164

Added line #L164 was not covered by tests
}

const pin: Pin = {
Expand Down
4 changes: 3 additions & 1 deletion src/pubsub/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
import { logger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { textToUrlSafeRpc, rpcToText, rpcToBytes, rpcToBigInt } from '../lib/http-rpc-wire-format.js'
Expand Down Expand Up @@ -104,7 +105,8 @@ async function readMessages (response: ExtendedResponse, { onMessage, onEnd, onE
data: rpcToBytes(msg.data),
sequenceNumber: rpcToBigInt(msg.seqno),
topic: rpcToText(msg.topicIDs[0]),
key: rpcToBytes(msg.key ?? 'u'),
// @ts-expect-error kubo does not supply the key
key: msg.key != null ? publicKeyFromProtobuf(rpcToBytes(msg.key ?? 'u')) : undefined,
signature: rpcToBytes(msg.signature ?? 'u')
})
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/interface-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env mocha */

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

describe('kubo-rpc-client tests against kubo', function () {
void (async function () {
const { path } = await import('kubo')
/**
* @type {string|undefined}
*/
const commonFactory = factory({
type: 'kubo',
bin: path(),
bin: path?.(),
test: true
})
describe('kubo RPC client interface tests', function () {
Expand Down
10 changes: 2 additions & 8 deletions test/interface-tests/src/key/gen.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/* eslint-env mocha */

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

const { supportedKeys } = keys

interface KeyTest {
opts: {
type?: KeyType
size?: number
}
expectedType: any
}

export function testGen (factory: Factory<KuboNode>, options: MochaConfig): void {
Expand All @@ -25,12 +21,10 @@ export function testGen (factory: Factory<KuboNode>, options: MochaConfig): void
describe('.key.gen', () => {
const keyTypes: KeyTest[] = [
{
opts: { type: 'ed25519' },
expectedType: supportedKeys.ed25519.Ed25519PrivateKey
opts: { type: 'ed25519' }
},
{
opts: { },
expectedType: supportedKeys.ed25519.Ed25519PrivateKey
opts: { }
}
]

Expand Down
15 changes: 12 additions & 3 deletions test/interface-tests/src/key/import.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-env mocha */

import { keys } from '@libp2p/crypto'
import { AES_GCM } from '@libp2p/crypto/ciphers'
import { privateKeyToProtobuf, generateKeyPair } from '@libp2p/crypto/keys'
import { expect } from 'aegir/chai'
import { base64 } from 'multiformats/bases/base64'
import { nanoid } from 'nanoid'
import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
import type { KuboRPCClient } from '../../../../src/index.js'
import type { Factory, KuboNode } from 'ipfsd-ctl'
import type { Multibase } from 'multiformats/bases/interface'

export function testImport (factory: Factory<KuboNode>, options: MochaConfig): void {
const describe = getDescribe(options)
Expand All @@ -25,8 +28,8 @@
it('should import an exported key', async () => {
const password = nanoid()

const key = await keys.generateKeyPair('Ed25519')
const exported = await key.export(password)
const key = await generateKeyPair('Ed25519')
const exported = await exporter(privateKeyToProtobuf(key), password)

Check warning on line 32 in test/interface-tests/src/key/import.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/key/import.ts#L31-L32

Added lines #L31 - L32 were not covered by tests

const importedKey = await ipfs.key.import('clone', exported, password)
expect(importedKey).to.exist()
Expand All @@ -35,3 +38,9 @@
})
})
}

async function exporter (privateKey: Uint8Array, password: string): Promise<Multibase<'m'>> {
const cipher = AES_GCM.create()
const encryptedKey = await cipher.encrypt(privateKey, password)
return base64.encode(encryptedKey)
}

Check warning on line 46 in test/interface-tests/src/key/import.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/key/import.ts#L42-L46

Added lines #L42 - L46 were not covered by tests
5 changes: 3 additions & 2 deletions test/interface-tests/src/name-pubsub/cancel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env mocha */
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { generateKeyPair } from '@libp2p/crypto/keys'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import all from 'it-all'
import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
Expand Down Expand Up @@ -37,7 +38,7 @@
it('should cancel a subscription correctly returning true', async function () {
this.timeout(300 * 1000)

const peerId = await createEd25519PeerId()
const peerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))

Check warning on line 41 in test/interface-tests/src/name-pubsub/cancel.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/name-pubsub/cancel.ts#L41

Added line #L41 was not covered by tests
const id = peerId.toString()
const ipnsPath = `/ipns/${id}`

Expand Down
14 changes: 8 additions & 6 deletions test/interface-tests/src/name-pubsub/pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-env mocha */

import { peerIdFromKeys, peerIdFromString } from '@libp2p/peer-id'
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
import { peerIdFromPublicKey, peerIdFromString } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import delay from 'delay'
import * as ipns from 'ipns'
import { multihashToIPNSRoutingKey, unmarshalIPNSRecord } from 'ipns'
import { ipnsValidator } from 'ipns/validator'
import last from 'it-last'
import { base58btc } from 'multiformats/bases/base58'
Expand Down Expand Up @@ -80,7 +81,7 @@
return subscribed
}

const routingKey = ipns.peerIdToRoutingKey(idA.id)
const routingKey = multihashToIPNSRoutingKey(idA.id.toMultihash())

Check warning on line 84 in test/interface-tests/src/name-pubsub/pubsub.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/name-pubsub/pubsub.ts#L84

Added line #L84 was not covered by tests
const topic = `${namespace}${uint8ArrayToString(routingKey, 'base64url')}`

await expect(last(nodeB.name.resolve(idA.id)))
Expand Down Expand Up @@ -147,7 +148,7 @@
'ipns-base': 'b58mh'
})

const routingKey = ipns.peerIdToRoutingKey(peerIdFromString(testAccount.id))
const routingKey = multihashToIPNSRoutingKey(peerIdFromString(testAccount.id).toMultihash())

Check warning on line 151 in test/interface-tests/src/name-pubsub/pubsub.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/name-pubsub/pubsub.ts#L151

Added line #L151 was not covered by tests
const topic = `${namespace}${uint8ArrayToString(routingKey, 'base64url')}`

await nodeB.pubsub.subscribe(topic, checkMessage)
Expand All @@ -159,7 +160,7 @@
throw new Error('Pubsub handler not invoked')
}

const publishedMessageData = ipns.unmarshal(publishedMessage.data)
const publishedMessageData = unmarshalIPNSRecord(publishedMessage.data)

Check warning on line 163 in test/interface-tests/src/name-pubsub/pubsub.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/name-pubsub/pubsub.ts#L163

Added line #L163 was not covered by tests

if (publishedMessageData.pubKey == null) {
throw new Error('No public key found in message data')
Expand All @@ -170,7 +171,8 @@
}

const messageKey = publishedMessage.from
const pubKeyPeerId = await peerIdFromKeys(publishedMessageData.pubKey)
const publicKey = publicKeyFromProtobuf(publishedMessageData.pubKey)
const pubKeyPeerId = peerIdFromPublicKey(publicKey)

Check warning on line 175 in test/interface-tests/src/name-pubsub/pubsub.ts

View check run for this annotation

Codecov / codecov/patch

test/interface-tests/src/name-pubsub/pubsub.ts#L174-L175

Added lines #L174 - L175 were not covered by tests

expect(pubKeyPeerId.toString()).not.to.equal(messageKey.toString())
expect(pubKeyPeerId.toString()).to.equal(testAccount.id)
Expand Down
10 changes: 6 additions & 4 deletions test/interface-tests/src/name/publish.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-env mocha */

import { peerIdFromString } from '@libp2p/peer-id'
import { peerIdFromCID } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import last from 'it-last'
import { base36 } from 'multiformats/bases/base36'
import { CID } from 'multiformats/cid'
import { nanoid } from 'nanoid'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
Expand Down Expand Up @@ -53,7 +55,7 @@ export function testPublish (factory: Factory<KuboNode>, options: MochaConfig):
const res = await ipfs.name.publish(value, { allowOffline: true })
expect(res).to.exist()

expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString())
expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(self.id, base36)).toString())
expect(res.value).to.equal(`/ipfs/${value}`)
})

Expand Down Expand Up @@ -84,7 +86,7 @@ export function testPublish (factory: Factory<KuboNode>, options: MochaConfig):

const res = await ipfs.name.publish(value, options)
expect(res).to.exist()
expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString())
expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(self.id, base36)).toString())
expect(res.value).to.equal(`/ipfs/${value}`)
})

Expand All @@ -104,7 +106,7 @@ export function testPublish (factory: Factory<KuboNode>, options: MochaConfig):
const res = await ipfs.name.publish(value, options)

expect(res).to.exist()
expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(key.id).toString())
expect(peerIdFromCID(CID.parse(res.name, base36)).toString()).to.equal(peerIdFromCID(CID.parse(key.id, base36)).toString())
expect(res.value).to.equal(`/ipfs/${value}`)
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/interface-tests/src/name/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function testResolve (factory: Factory<KuboNode>, options: MochaConfig):

// Represent Peer ID as CIDv1 Base32
// https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md
const keyCid = CID.createV1(0x72, Digest.decode(peerIdFromString(peerId.toString()).toBytes()))
const keyCid = CID.createV1(0x72, Digest.decode(peerIdFromString(peerId.toString()).toMultihash().bytes))
const resolvedPath = await last(ipfs.name.resolve(`/ipns/${keyCid}`))

expect(resolvedPath).to.equal(`/ipfs/${cid}`)
Expand Down
Loading
Loading