diff --git a/package.json b/package.json index d593f07..36b67ec 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/index.js", "dependencies": { "@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git", + "@noble/hashes": "^1.2.0", "@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git", "backoff.js": "^1.0.4", "eventemitter3": "^5.0.0" diff --git a/src/index.ts b/src/index.ts index 55c98b3..0dad892 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,15 @@ import { Buffer } from "buffer"; import { Client, factory } from "@lumeweb/libkernel-universal"; import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb"; +import { blake2b } from "@noble/hashes/blake2b"; import type { EventEmitter } from "eventemitter3"; // @ts-ignore import Backoff from "backoff.js"; +const PROTOCOL = "lumeweb.proxy.handshake"; + export class SwarmClient extends Client { private useDefaultSwarm: boolean; private id: number = 0; @@ -103,7 +106,11 @@ export class SwarmClient extends Client { return this.callModuleReturn("getRelays", { swarm: this.swarm }); } - public async join(topic: Buffer | Uint8Array): Promise { + public async join(topic: Buffer | Uint8Array | string): Promise { + if (typeof topic === "string") { + topic = blake2b(PROTOCOL); + } + this._topics.add(topic); this.callModule("join", { id: this.id, topic }); }