*Allow discover to take both a buffer and string
This commit is contained in:
parent
ad426dafb1
commit
48f9e8deb6
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue