diff --git a/docs/core-api/PUBSUB.md b/docs/core-api/PUBSUB.md index 36b3ff2649..3a9674fd0b 100644 --- a/docs/core-api/PUBSUB.md +++ b/docs/core-api/PUBSUB.md @@ -32,7 +32,7 @@ | Name | Type | Description | | ---- | ---- | ----------- | | topic | `String` | The topic name | -| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, sequenceNumber: bigint, data: Uint8Array, topicIDs: Array}` | +| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: PeerId, sequenceNumber: bigint, data: Uint8Array, topicIDs: Array}` | ### Options diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 56cbfe8be9..c96b092024 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -66,6 +66,7 @@ "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.3", "@libp2p/crypto": "^0.22.9", + "@libp2p/interfaces": "^2.0.4", "@libp2p/peer-id": "^1.1.10", "@libp2p/peer-id-factory": "^1.0.10", "@libp2p/websockets": "^1.0.8", diff --git a/packages/interface-ipfs-core/src/pubsub/subscribe.js b/packages/interface-ipfs-core/src/pubsub/subscribe.js index c73b3d286c..f4093ac196 100644 --- a/packages/interface-ipfs-core/src/pubsub/subscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/subscribe.js @@ -13,6 +13,7 @@ import { isWebWorker, isNode } from 'ipfs-utils/src/env.js' import sinon from 'sinon' import defer from 'p-defer' import pWaitFor from 'p-wait-for' +import { isPeerId } from '@libp2p/interfaces/peer-id' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -87,6 +88,7 @@ export function testSubscribe (factory, options) { expect(msg).to.have.property('sequenceNumber') expect(msg.sequenceNumber).to.be.a('BigInt') expect(msg.topic).to.eq(topic) + expect(isPeerId(msg.from)).to.be.true() expect(msg.from.toString()).to.equal(ipfs1Id.id.toString()) }) diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index e685d63af3..80260ff352 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -75,7 +75,7 @@ "@libp2p/crypto": "^0.22.9", "@libp2p/delegated-content-routing": "^1.0.3", "@libp2p/delegated-peer-routing": "^1.0.3", - "@libp2p/interfaces": "^2.0.2", + "@libp2p/interfaces": "^2.0.4", "@libp2p/kad-dht": "^1.0.3", "@libp2p/logger": "^1.1.4", "@libp2p/mplex": "^1.0.5", diff --git a/packages/ipfs-grpc-client/package.json b/packages/ipfs-grpc-client/package.json index 6f11c70868..b672699190 100644 --- a/packages/ipfs-grpc-client/package.json +++ b/packages/ipfs-grpc-client/package.json @@ -51,6 +51,7 @@ "dependencies": { "@improbable-eng/grpc-web": "^0.15.0", "@libp2p/logger": "^1.1.4", + "@libp2p/peer-id": "^1.1.10", "change-case": "^4.1.1", "err-code": "^3.0.1", "ipfs-core-types": "^0.11.1", diff --git a/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js b/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js index 6b84f6c16f..64ae7a820d 100644 --- a/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js +++ b/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js @@ -3,6 +3,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { subscriptions } from './subscriptions.js' import defer from 'p-defer' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { peerIdFromString } from '@libp2p/peer-id' /** * @param {import('@improbable-eng/grpc-web').grpc} grpc @@ -37,7 +38,7 @@ export function grpcPubsubSubscribe (grpc, service, opts) { } else { /** @type {import('@libp2p/interfaces/pubsub').Message} */ const msg = { - from: result.from, + from: peerIdFromString(result.from), sequenceNumber: result.sequenceNumber == null ? undefined : BigInt(`0x${uint8ArrayToString(result.sequenceNumber, 'base16')}`), data: result.data, topic: result.topic diff --git a/packages/ipfs-http-client/src/pubsub/subscribe.js b/packages/ipfs-http-client/src/pubsub/subscribe.js index 853c47d4e0..8646747a2f 100644 --- a/packages/ipfs-http-client/src/pubsub/subscribe.js +++ b/packages/ipfs-http-client/src/pubsub/subscribe.js @@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { textToUrlSafeRpc, rpcToText, rpcToBytes, rpcToBigInt } from '../lib/http-rpc-wire-format.js' +import { peerIdFromString } from '@libp2p/peer-id' const log = logger('ipfs-http-client:pubsub:subscribe') /** @@ -107,7 +108,7 @@ async function readMessages (response, { onMessage, onEnd, onError }) { } onMessage({ - from: msg.from, + from: peerIdFromString(msg.from), data: rpcToBytes(msg.data), sequenceNumber: rpcToBigInt(msg.seqno), topic: rpcToText(msg.topicIDs[0]) diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 3b042b1fcb..30e0b2bdae 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -45,7 +45,7 @@ "@hapi/content": "^5.0.2", "@hapi/hapi": "^20.0.0", "@ipld/dag-pb": "^2.1.3", - "@libp2p/interfaces": "^2.0.2", + "@libp2p/interfaces": "^2.0.4", "@libp2p/logger": "^1.1.4", "@libp2p/peer-id": "^1.1.10", "any-signal": "^3.0.0",