*Support strings in join with nobile blake2b hashing

This commit is contained in:
Derrick Hammer 2023-02-17 20:04:21 -05:00
parent 8061477c0b
commit 232f82d828
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 9 additions and 1 deletions

View File

@ -5,6 +5,7 @@
"main": "dist/index.js", "main": "dist/index.js",
"dependencies": { "dependencies": {
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git", "@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", "@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
"backoff.js": "^1.0.4", "backoff.js": "^1.0.4",
"eventemitter3": "^5.0.0" "eventemitter3": "^5.0.0"

View File

@ -1,12 +1,15 @@
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import { Client, factory } from "@lumeweb/libkernel-universal"; import { Client, factory } from "@lumeweb/libkernel-universal";
import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb"; import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb";
import { blake2b } from "@noble/hashes/blake2b";
import type { EventEmitter } from "eventemitter3"; import type { EventEmitter } from "eventemitter3";
// @ts-ignore // @ts-ignore
import Backoff from "backoff.js"; import Backoff from "backoff.js";
const PROTOCOL = "lumeweb.proxy.handshake";
export class SwarmClient extends Client { export class SwarmClient extends Client {
private useDefaultSwarm: boolean; private useDefaultSwarm: boolean;
private id: number = 0; private id: number = 0;
@ -103,7 +106,11 @@ export class SwarmClient extends Client {
return this.callModuleReturn("getRelays", { swarm: this.swarm }); return this.callModuleReturn("getRelays", { swarm: this.swarm });
} }
public async join(topic: Buffer | Uint8Array): Promise<void> { public async join(topic: Buffer | Uint8Array | string): Promise<void> {
if (typeof topic === "string") {
topic = blake2b(PROTOCOL);
}
this._topics.add(topic); this._topics.add(topic);
this.callModule("join", { id: this.id, topic }); this.callModule("join", { id: this.id, topic });
} }