From d156d4e67b4e6a026a6405039e1849fbc408e2fb Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 12 Nov 2020 11:25:29 +0000 Subject: [PATCH 1/6] feat: allow passing the id of a network peer to ipfs.id Adds parity with go-IPFS and allows looking up known peer IDs using the `ipfs.id` command. --- docs/core-api/MISCELLANEOUS.md | 3 +- .../src/miscellaneous/id.js | 11 ++++ packages/ipfs-cli/src/commands/id.js | 11 +++- packages/ipfs-cli/test/id.js | 18 ++++++ packages/ipfs-core/src/components/id.js | 62 +++++++++++++++---- packages/ipfs-http-client/src/id.js | 5 +- .../ipfs-http-server/src/api/resources/id.js | 13 +++- packages/ipfs-http-server/test/inject/id.js | 23 +++++++ 8 files changed, 125 insertions(+), 21 deletions(-) diff --git a/docs/core-api/MISCELLANEOUS.md b/docs/core-api/MISCELLANEOUS.md index 6aafaefe2d..f63245106f 100644 --- a/docs/core-api/MISCELLANEOUS.md +++ b/docs/core-api/MISCELLANEOUS.md @@ -47,6 +47,7 @@ An optional object which may have the following keys: | ---- | ---- | ------- | ----------- | | timeout | `Number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | +| peerId | `String|PeerId` | `undefined` | Look up the identity for this peer instead of the current node | ### Returns @@ -300,4 +301,4 @@ A great source of [examples](https://github.com/ipfs/js-ipfs/blob/master/package [rs]: https://www.npmjs.com/package/readable-stream [ps]: https://www.npmjs.com/package/pull-stream [cid]: https://www.npmjs.com/package/cids -[AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal \ No newline at end of file +[AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal diff --git a/packages/interface-ipfs-core/src/miscellaneous/id.js b/packages/interface-ipfs-core/src/miscellaneous/id.js index edbf65f4c9..4befcd831b 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/id.js +++ b/packages/interface-ipfs-core/src/miscellaneous/id.js @@ -73,5 +73,16 @@ module.exports = (common, options) => { await expect(ipfs.id()).to.eventually.have.property('addresses').that.is.not.empty() }) + + it('should get the id of another node in the swarm', async function () { + const ipfsB = (await common.spawn()).api + await ipfs.swarm.connect(ipfsB.peerId.addresses[0]) + + const result = await ipfs.id({ + peerId: ipfsB.peerId.id + }) + + expect(result).to.deep.equal(ipfsB.peerId) + }) }) } diff --git a/packages/ipfs-cli/src/commands/id.js b/packages/ipfs-cli/src/commands/id.js index b4868227a2..b7b9ba9ad2 100644 --- a/packages/ipfs-cli/src/commands/id.js +++ b/packages/ipfs-cli/src/commands/id.js @@ -3,11 +3,15 @@ const parseDuration = require('parse-duration').default module.exports = { - command: 'id', + command: 'id [peerid]', describe: 'Shows IPFS Node ID info', builder: { + peerid: { + type: 'string', + describe: 'Peer.ID of node to look up' + }, format: { alias: 'f', type: 'string', @@ -19,9 +23,10 @@ module.exports = { } }, - async handler ({ ctx: { ipfs, print }, format, timeout }) { + async handler ({ ctx: { ipfs, print }, format, timeout, peerid: peerId }) { const id = await ipfs.id({ - timeout + timeout, + peerId }) if (format) { diff --git a/packages/ipfs-cli/test/id.js b/packages/ipfs-cli/test/id.js index e92a5967dc..bf36c4a717 100644 --- a/packages/ipfs-cli/test/id.js +++ b/packages/ipfs-cli/test/id.js @@ -4,6 +4,7 @@ const { expect } = require('aegir/utils/chai') const cli = require('./utils/cli') const sinon = require('sinon') +const PeerId = require('peer-id') const defaultOptions = { timeout: undefined @@ -54,4 +55,21 @@ describe('id', () => { expect(res).to.have.property('id', 'id') expect(res).to.have.property('publicKey', 'publicKey') }) + + it('get the id of another peer', async () => { + const peerId = PeerId.createFromB58String('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D') + + ipfs.id.withArgs({ + ...defaultOptions, + peerId: peerId.toString() + }).resolves({ + id: 'id', + publicKey: 'publicKey' + }) + + const out = await cli(`id ${peerId}`, { ipfs }) + const res = JSON.parse(out) + expect(res).to.have.property('id', 'id') + expect(res).to.have.property('publicKey', 'publicKey') + }) }) diff --git a/packages/ipfs-core/src/components/id.js b/packages/ipfs-core/src/components/id.js index 226dcc239e..a4bfa64c2c 100644 --- a/packages/ipfs-core/src/components/id.js +++ b/packages/ipfs-core/src/components/id.js @@ -4,6 +4,8 @@ const pkgversion = require('../../package.json').version const multiaddr = require('multiaddr') const { withTimeoutOption } = require('../utils') const uint8ArrayToString = require('uint8arrays/to-string') +const PeerId = require('peer-id') +const { NotStartedError } = require('../errors') /** * @param {Object} config @@ -14,7 +16,7 @@ module.exports = ({ peerId, libp2p }) => { /** * Returns the identity of the Peer * - * @param {import('../utils').AbortOptions} [_options] + * @param {IdOptions} [options] * @returns {Promise} * @example * ```js @@ -22,36 +24,63 @@ module.exports = ({ peerId, libp2p }) => { * console.log(identity) * ``` */ - async function id (_options) { // eslint-disable-line require-await - const id = peerId.toB58String() + async function id (options = {}) { // eslint-disable-line require-await + options = options || {} + + let id = peerId + let publicKey = id.pubKey let addresses = [] let protocols = [] + let agentVersion = `js-ipfs/${pkgversion}` + let protocolVersion = '9000' + + if (options.peerId) { + if (PeerId.isPeerId(options.peerId)) { + id = options.peerId + } else { + id = PeerId.createFromB58String(options.peerId.toString()) + } + + if (!libp2p) { + throw new NotStartedError() + } - if (libp2p) { - // only available while the node is running - addresses = libp2p.transportManager.getAddrs() - protocols = Array.from(libp2p.upgrader.protocols.keys()) + publicKey = libp2p.peerStore.keyBook.get(id) + addresses = libp2p.peerStore.addressBook.getMultiaddrsForPeer(id) || [] + protocols = libp2p.peerStore.protoBook.get(id) || [] + + const meta = libp2p.peerStore.metadataBook.get(id) || {} + agentVersion = meta.agentVersion + protocolVersion = meta.protocolVersion + } else { + if (libp2p) { + // only available while the node is running + addresses = libp2p.transportManager.getAddrs() + protocols = Array.from(libp2p.upgrader.protocols.keys()) + } } + const idStr = id.toB58String() + return { - id, - publicKey: uint8ArrayToString(peerId.pubKey.bytes, 'base64pad'), + id: idStr, + publicKey: publicKey ? uint8ArrayToString(publicKey.bytes, 'base64pad') : undefined, addresses: addresses .map(ma => { const str = ma.toString() // some relay-style transports add our peer id to the ma for us // so don't double-add - if (str.endsWith(`/p2p/${id}`)) { + if (str.endsWith(`/p2p/${idStr}`)) { return str } - return `${str}/p2p/${id}` + return `${str}/p2p/${idStr}` }) .sort() .map(ma => multiaddr(ma)), - agentVersion: `js-ipfs/${pkgversion}`, - protocolVersion: '9000', + agentVersion, + protocolVersion, protocols: protocols.sort() } } @@ -67,4 +96,11 @@ module.exports = ({ peerId, libp2p }) => { * @property {string} agentVersion - The agent version * @property {string} protocolVersion - The supported protocol version * @property {string[]} protocols - The supported protocols + * + * @typedef {IdSettings & AbortOptions} IdOptions + * + * @typedef {Object} IdSettings + * @property {string|PeerId} [peerId] - The address of a remote peer + * + * @typedef {import('../utils').AbortOptions} AbortOptions */ diff --git a/packages/ipfs-http-client/src/id.js b/packages/ipfs-http-client/src/id.js index 28b2e3ff98..bb509ec434 100644 --- a/packages/ipfs-http-client/src/id.js +++ b/packages/ipfs-http-client/src/id.js @@ -13,7 +13,10 @@ module.exports = configure(api => { const res = await api.post('id', { timeout: options.timeout, signal: options.signal, - searchParams: toUrlSearchParams(options), + searchParams: toUrlSearchParams({ + arg: options.peerId ? options.peerId.toString() : undefined, + ...options + }), headers: options.headers }) const data = await res.json() diff --git a/packages/ipfs-http-server/src/api/resources/id.js b/packages/ipfs-http-server/src/api/resources/id.js index bdece8a0f6..c26d0eb86a 100644 --- a/packages/ipfs-http-server/src/api/resources/id.js +++ b/packages/ipfs-http-server/src/api/resources/id.js @@ -10,8 +10,13 @@ module.exports = { stripUnknown: true }, query: Joi.object().keys({ - timeout: Joi.timeout() + timeout: Joi.timeout(), + peerId: Joi.peerId() }) + .rename('arg', 'peerId', { + override: true, + ignoreUndefined: true + }) } }, handler: async (request, h) => { @@ -25,13 +30,15 @@ module.exports = { } }, query: { - timeout + timeout, + peerId } } = request const id = await ipfs.id({ signal, - timeout + timeout, + peerId }) return h.response({ ID: id.id, diff --git a/packages/ipfs-http-server/test/inject/id.js b/packages/ipfs-http-server/test/inject/id.js index 1342611d9d..cc45e58b0d 100644 --- a/packages/ipfs-http-server/test/inject/id.js +++ b/packages/ipfs-http-server/test/inject/id.js @@ -6,6 +6,7 @@ const testHttpMethod = require('../utils/test-http-method') const http = require('../utils/http') const sinon = require('sinon') const { AbortSignal } = require('native-abort-controller') +const PeerId = require('peer-id') const defaultOptions = { signal: sinon.match.instanceOf(AbortSignal), @@ -65,4 +66,26 @@ describe('/id', () => { expect(res).to.have.property('statusCode', 200) }) + + it('get the id of another peer', async () => { + const peerId = PeerId.createFromB58String('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D') + + ipfs.id.withArgs({ + ...defaultOptions, + peerId: peerId.toString() + }).returns({ + id: 'id', + publicKey: 'publicKey', + addresses: 'addresses', + agentVersion: 'agentVersion', + protocolVersion: 'protocolVersion' + }) + + const res = await http({ + method: 'POST', + url: `/api/v0/id?peerId=${peerId}` + }, { ipfs }) + + expect(res).to.have.property('statusCode', 200) + }) }) From d281dc88f5f61d31d22f7b18392e91b3273f4dff Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 12 May 2021 17:04:11 +0100 Subject: [PATCH 2/6] chore: merge master, add extra test --- docs/core-api/MISCELLANEOUS.md | 2 +- packages/interface-ipfs-core/package.json | 1 + .../src/miscellaneous/id.js | 18 ++++++- packages/ipfs-core-types/src/root.d.ts | 6 ++- packages/ipfs-core/src/components/id.js | 52 ++++++++----------- packages/ipfs-core/src/components/libp2p.js | 4 ++ .../ipfs-http-server/src/api/resources/id.js | 2 +- 7 files changed, 51 insertions(+), 34 deletions(-) diff --git a/docs/core-api/MISCELLANEOUS.md b/docs/core-api/MISCELLANEOUS.md index f63245106f..61b74fab61 100644 --- a/docs/core-api/MISCELLANEOUS.md +++ b/docs/core-api/MISCELLANEOUS.md @@ -47,7 +47,7 @@ An optional object which may have the following keys: | ---- | ---- | ------- | ----------- | | timeout | `Number` | `undefined` | A timeout in ms | | signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call | -| peerId | `String|PeerId` | `undefined` | Look up the identity for this peer instead of the current node | +| peerId | `string` | `undefined` | Look up the identity for this peer instead of the current node | ### Returns diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 0fa02f2be6..acbbf3d329 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -70,6 +70,7 @@ "nanoid": "^3.1.12", "native-abort-controller": "^1.0.3", "p-map": "^4.0.0", + "p-retry": "^4.5.0", "peer-id": "^0.14.1", "readable-stream": "^3.4.0", "uint8arrays": "^2.1.3" diff --git a/packages/interface-ipfs-core/src/miscellaneous/id.js b/packages/interface-ipfs-core/src/miscellaneous/id.js index ec71950dcb..e4433c3889 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/id.js +++ b/packages/interface-ipfs-core/src/miscellaneous/id.js @@ -5,6 +5,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { Multiaddr } = require('multiaddr') const CID = require('cids') const { isWebWorker } = require('ipfs-utils/src/env') +const retry = require('p-retry') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -71,11 +72,24 @@ module.exports = (common, options) => { const ipfsB = (await common.spawn()).api await ipfs.swarm.connect(ipfsB.peerId.addresses[0]) + // have to wait for identify to complete before protocols etc are available for remote hosts + await retry(async () => { + const result = await ipfs.id({ + peerId: ipfsB.peerId.id + }) + + expect(result).to.deep.equal(ipfsB.peerId) + }, {retries: 5}) + }) + + it('should get our own id when passed as an option', async function () { + const res = await ipfs.id() + const result = await ipfs.id({ - peerId: ipfsB.peerId.id + peerId: res.id }) - expect(result).to.deep.equal(ipfsB.peerId) + expect(result).to.deep.equal(res) }) }) } diff --git a/packages/ipfs-core-types/src/root.d.ts b/packages/ipfs-core-types/src/root.d.ts index f33ceb08f8..f6607d431e 100644 --- a/packages/ipfs-core-types/src/root.d.ts +++ b/packages/ipfs-core-types/src/root.d.ts @@ -40,7 +40,7 @@ export interface API { * console.log(identity) * ``` */ - id: (options?: AbortOptions & OptionExtension) => Promise + id: (options?: IDOptions & OptionExtension) => Promise /** * Returns the implementation version @@ -289,6 +289,10 @@ export interface ListOptions extends AbortOptions, PreloadOptions { includeContent?: boolean } +export interface IDOptions extends AbortOptions { + peerId?: string +} + export interface IDResult { id: string publicKey: string diff --git a/packages/ipfs-core/src/components/id.js b/packages/ipfs-core/src/components/id.js index 066cb9af7b..0cfbf49ee0 100644 --- a/packages/ipfs-core/src/components/id.js +++ b/packages/ipfs-core/src/components/id.js @@ -17,49 +17,43 @@ module.exports = ({ peerId, network }) => { * @type {import('ipfs-core-types/src/root').API["id"]} */ async function id (options = {}) { // eslint-disable-line require-await - /** @type {Multiaddr[]} */ - let addresses = [] - /** @type {string[]} */ - let protocols = [] - let agentVersion = `js-ipfs/${pkgversion}` - let protocolVersion = '9000' - let id = peerId - let publicKey = id.pubKey + if (options.peerId === peerId.toB58String()) { + delete options.peerId + } const net = network.try() - if (options.peerId) { - if (!net) { + if (!net) { + if (options.peerId) { throw new NotStartedError() } - const { libp2p } = net - - id = PeerId.createFromB58String(options.peerId.toString()) - - publicKey = libp2p.peerStore.keyBook.get(id) - addresses = libp2p.peerStore.addressBook.getMultiaddrsForPeer(id) || [] - protocols = libp2p.peerStore.protoBook.get(id) || [] + const idStr = peerId.toB58String() - const meta = libp2p.peerStore.metadataBook.get(id) || {} - agentVersion = meta.agentVersion - protocolVersion = meta.protocolVersion + return { + id: idStr, + publicKey: uint8ArrayToString(peerId.pubKey.bytes, 'base64pad'), + addresses: [], + agentVersion: `js-ipfs/${pkgversion}`, + protocolVersion: '9000', + protocols: [] + } } - if (net) { - const { libp2p } = net - - // only available while the node is running - addresses = libp2p.multiaddrs - protocols = Array.from(libp2p.upgrader.protocols.keys()) - } + const id = options.peerId ? PeerId.createFromB58String(options.peerId.toString()) : peerId + const { libp2p } = net + const publicKey = options.peerId ? libp2p.peerStore.keyBook.get(id) : id.pubKey + const addresses = options.peerId ? libp2p.peerStore.addressBook.getMultiaddrsForPeer(id) : libp2p.multiaddrs + const protocols = options.peerId ? libp2p.peerStore.protoBook.get(id) : Array.from(libp2p.upgrader.protocols.keys()) + const agentVersion = uint8ArrayToString(libp2p.peerStore.metadataBook.getValue(id, 'AgentVersion') || new Uint8Array()) + const protocolVersion = uint8ArrayToString(libp2p.peerStore.metadataBook.getValue(id, 'ProtocolVersion') || new Uint8Array()) const idStr = id.toB58String() return { id: idStr, publicKey: uint8ArrayToString(publicKey.bytes, 'base64pad'), - addresses: addresses + addresses: (addresses || []) .map(ma => { const str = ma.toString() @@ -75,7 +69,7 @@ module.exports = ({ peerId, network }) => { .map(ma => new Multiaddr(ma)), agentVersion, protocolVersion, - protocols: protocols.sort() + protocols: (protocols || []).sort() } } return withTimeoutOption(id) diff --git a/packages/ipfs-core/src/components/libp2p.js b/packages/ipfs-core/src/components/libp2p.js index e7167009cd..de7098ba09 100644 --- a/packages/ipfs-core/src/components/libp2p.js +++ b/packages/ipfs-core/src/components/libp2p.js @@ -4,6 +4,7 @@ const get = require('dlv') const mergeOptions = require('merge-options') const errCode = require('err-code') const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs') +const pkgversion = require('../../package.json').version /** * @typedef {Object} KeychainConfig @@ -134,6 +135,9 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p keychain: { datastore: keys, ...keychainConfig + }, + host: { + agentVersion: `js-ipfs/${pkgversion}` } } diff --git a/packages/ipfs-http-server/src/api/resources/id.js b/packages/ipfs-http-server/src/api/resources/id.js index 38b3a573a6..389b0e2064 100644 --- a/packages/ipfs-http-server/src/api/resources/id.js +++ b/packages/ipfs-http-server/src/api/resources/id.js @@ -11,7 +11,7 @@ module.exports = { }, query: Joi.object().keys({ timeout: Joi.timeout(), - peerId: Joi.peerId() + peerId: Joi.string() }) .rename('arg', 'peerId', { override: true, From 2ce71ff34520b714f3a3d1d8646e37599c064d35 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 13 May 2021 10:46:08 +0100 Subject: [PATCH 3/6] chore: update libp2p version --- examples/custom-libp2p/package.json | 2 +- packages/ipfs-core/package.json | 2 +- packages/ipfs-daemon/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 5c68f936c7..97b35f9bd9 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "ipfs": "^0.55.1", - "libp2p": "^0.31.0", + "libp2p": "^0.31.5", "libp2p-bootstrap": "^0.12.3", "libp2p-kad-dht": "^0.22.0", "libp2p-mdns": "^0.16.0", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 5c34784ace..f41e89366f 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -94,7 +94,7 @@ "it-map": "^1.0.4", "it-pipe": "^1.1.0", "just-safe-set": "^2.2.1", - "libp2p": "^0.31.2", + "libp2p": "^0.31.5", "libp2p-bootstrap": "^0.12.3", "libp2p-crypto": "^0.19.3", "libp2p-floodsub": "^0.25.1", diff --git a/packages/ipfs-daemon/package.json b/packages/ipfs-daemon/package.json index 62f13f8bc3..d646e37e6e 100644 --- a/packages/ipfs-daemon/package.json +++ b/packages/ipfs-daemon/package.json @@ -40,7 +40,7 @@ "ipfs-http-server": "^0.4.0", "ipfs-utils": "^7.0.0", "just-safe-set": "^2.2.1", - "libp2p": "^0.31.2", + "libp2p": "^0.31.5", "libp2p-delegated-content-routing": "^0.10.0", "libp2p-delegated-peer-routing": "^0.9.0", "libp2p-webrtc-star": "^0.22.2", From bfdd40c905da8ae4686b2c3a4a353fc796fda270 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 13 May 2021 10:58:54 +0100 Subject: [PATCH 4/6] chore: fix tests --- packages/ipfs-http-server/test/inject/id.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ipfs-http-server/test/inject/id.js b/packages/ipfs-http-server/test/inject/id.js index cc45e58b0d..db9686e1c0 100644 --- a/packages/ipfs-http-server/test/inject/id.js +++ b/packages/ipfs-http-server/test/inject/id.js @@ -10,7 +10,8 @@ const PeerId = require('peer-id') const defaultOptions = { signal: sinon.match.instanceOf(AbortSignal), - timeout: undefined + timeout: undefined, + peerId: undefined } describe('/id', () => { From ecff36c43ac03cb7274961e27968bce8d9cbd23d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 13 May 2021 12:36:49 +0100 Subject: [PATCH 5/6] chore: fix more tests --- packages/interface-ipfs-core/src/miscellaneous/id.js | 2 +- packages/ipfs-cli/test/id.js | 3 ++- packages/ipfs-http-server/test/inject/id.js | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/interface-ipfs-core/src/miscellaneous/id.js b/packages/interface-ipfs-core/src/miscellaneous/id.js index e4433c3889..33f1b8ea08 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/id.js +++ b/packages/interface-ipfs-core/src/miscellaneous/id.js @@ -79,7 +79,7 @@ module.exports = (common, options) => { }) expect(result).to.deep.equal(ipfsB.peerId) - }, {retries: 5}) + }, { retries: 5 }) }) it('should get our own id when passed as an option', async function () { diff --git a/packages/ipfs-cli/test/id.js b/packages/ipfs-cli/test/id.js index bf36c4a717..47b85b7222 100644 --- a/packages/ipfs-cli/test/id.js +++ b/packages/ipfs-cli/test/id.js @@ -7,7 +7,8 @@ const sinon = require('sinon') const PeerId = require('peer-id') const defaultOptions = { - timeout: undefined + timeout: undefined, + peerId: undefined } describe('id', () => { diff --git a/packages/ipfs-http-server/test/inject/id.js b/packages/ipfs-http-server/test/inject/id.js index db9686e1c0..d8b001496e 100644 --- a/packages/ipfs-http-server/test/inject/id.js +++ b/packages/ipfs-http-server/test/inject/id.js @@ -6,7 +6,6 @@ const testHttpMethod = require('../utils/test-http-method') const http = require('../utils/http') const sinon = require('sinon') const { AbortSignal } = require('native-abort-controller') -const PeerId = require('peer-id') const defaultOptions = { signal: sinon.match.instanceOf(AbortSignal), @@ -69,11 +68,11 @@ describe('/id', () => { }) it('get the id of another peer', async () => { - const peerId = PeerId.createFromB58String('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D') + const peerId = 'QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D' ipfs.id.withArgs({ ...defaultOptions, - peerId: peerId.toString() + peerId }).returns({ id: 'id', publicKey: 'publicKey', From e2610b23fcf843362a1540a31a047c5852b8f436 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 13 May 2021 13:50:48 +0100 Subject: [PATCH 6/6] chore: disable webworker test because it cannot dial anything local --- packages/interface-ipfs-core/src/miscellaneous/id.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/interface-ipfs-core/src/miscellaneous/id.js b/packages/interface-ipfs-core/src/miscellaneous/id.js index 33f1b8ea08..cd6148fd6a 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/id.js +++ b/packages/interface-ipfs-core/src/miscellaneous/id.js @@ -69,6 +69,11 @@ module.exports = (common, options) => { }) it('should get the id of another node in the swarm', async function () { + if (isWebWorker) { + // TODO: https://github.com/libp2p/js-libp2p-websockets/issues/129 + return this.skip() + } + const ipfsB = (await common.spawn()).api await ipfs.swarm.connect(ipfsB.peerId.addresses[0])