diff --git a/src/modules/rpc.ts b/src/modules/rpc.ts index d527d07..ac0fec1 100644 --- a/src/modules/rpc.ts +++ b/src/modules/rpc.ts @@ -7,6 +7,7 @@ import { errorExit } from "../lib/error.js"; import stringify from "json-stable-stringify"; import { getRpcServer, RPC_PROTOCOL_SYMBOL } from "./rpc/server.js"; import { get as getSwarm, SecretStream } from "./swarm.js"; +import b4a from "b4a"; export async function start() { if (!config.str("pocket-app-id") || !config.str("pocket-app-key")) { @@ -18,8 +19,9 @@ export async function start() { ); } -export async function getRpcByPeer(peer: string) { +export async function getRpcByPeer(peer: Buffer | string) { const swarm = getSwarm(); + peer = b4a.from(peer) as Buffer; if (swarm._allConnections.has(peer)) { return swarm._allConnections.get(peer)[RPC_PROTOCOL_SYMBOL]; @@ -28,7 +30,7 @@ export async function getRpcByPeer(peer: string) { return new Promise((resolve) => { const listener = () => {}; swarm.on("connection", (peer: any, info: any) => { - if (info.publicKey.toString("hex") !== peer) { + if (info.publicKey.toString("hex") !== peer.toString("hex")) { return; } swarm.removeListener("connection", listener);