*Support strings in join with nobile blake2b hashing
This commit is contained in:
parent
8061477c0b
commit
232f82d828
|
@ -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"
|
||||||
|
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue