*Allow discover to take both a buffer and string

This commit is contained in:
Derrick Hammer 2023-01-31 07:18:45 -05:00
parent ad426dafb1
commit 48f9e8deb6
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 13 additions and 1 deletions

View File

@ -18,6 +18,7 @@
"@hyperswarm/dht-relay": "^0.3.0",
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
"@lumeweb/peer-discovery": "git+https://git.lumeweb.com/LumeWeb/peer-discovery.git",
"@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
"hyperswarm": "^4.3.7",
"libkernel": "^0.1.48",
"libkmodule": "^0.2.53"

View File

@ -4,6 +4,7 @@ specifiers:
'@hyperswarm/dht-relay': ^0.3.0
'@lumeweb/libkernel-universal': git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git
'@lumeweb/peer-discovery': git+https://git.lumeweb.com/LumeWeb/peer-discovery.git
'@siaweb/libweb': git+https://git.lumeweb.com/LumeWeb/libsiaweb.git
'@types/random-number-csprng': ^1.0.0
'@types/ws': ^8.5.4
esbuild: ^0.14.54
@ -18,6 +19,7 @@ dependencies:
'@hyperswarm/dht-relay': 0.3.0
'@lumeweb/libkernel-universal': git.lumeweb.com/LumeWeb/libkernel-universal/ae9c6eeb60cd5e350012c3e393ff8b846326e468
'@lumeweb/peer-discovery': git.lumeweb.com/LumeWeb/peer-discovery/d2bd926275103d60fdd3c7c432eae5c278f49261
'@siaweb/libweb': git.lumeweb.com/LumeWeb/libsiaweb/5e6cdba3e7d9a4b94e21ddcd5f2b5138fb440ee8
hyperswarm: 4.3.7
libkernel: 0.1.48
libkmodule: 0.2.53

View File

@ -1,5 +1,6 @@
import { Client, factory } from "@lumeweb/libkernel-universal";
import type { Peer } from "@lumeweb/peer-discovery";
import { hexToBuf } from "@siaweb/libweb/dist";
export class PeerDiscoveryClient extends Client {
public async register(source: string): Promise<void> {
const bag = await this.loadBound(source);
@ -18,7 +19,15 @@ export class PeerDiscoveryClient extends Client {
public async exists(name: string): Promise<boolean> {
return await this.callModuleReturn("remove", { name });
}
public async discover(pubkey: string): Promise<Peer | boolean> {
public async discover(pubkey: string | Uint8Array): Promise<Peer | boolean> {
if (typeof pubkey === "string") {
let buf = hexToBuf(pubkey);
if (buf[1]) {
throw new Error(buf[1]);
}
pubkey = buf[0];
}
return await this.callModuleReturn("discover", { pubkey });
}
}