kernel-peer-discovery-client/dist/index.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-01-31 10:07:55 +00:00
import { Client, factory } from "@lumeweb/libkernel-universal";
2023-01-31 13:14:50 +00:00
import { hexToBuf } from "@siaweb/libweb/dist";
2023-01-31 10:07:55 +00:00
export class PeerDiscoveryClient extends Client {
async register(source) {
const bag = await this.loadBound(source);
const ret = await bag.callModule("register");
this.handleError(ret);
}
2023-01-31 14:02:07 +00:00
async registerSelf() {
return await this.callModuleReturn("register");
}
2023-01-31 10:07:55 +00:00
async remove(name) {
return await this.callModuleReturn("remove", { name });
}
async removeAll() {
await this.callModuleReturn("removeAll");
}
async exists(name) {
return await this.callModuleReturn("remove", { name });
}
async discover(pubkey) {
2023-01-31 13:14:50 +00:00
if (typeof pubkey === "string") {
let buf = hexToBuf(pubkey);
if (buf[1]) {
throw new Error(buf[1]);
}
pubkey = buf[0];
}
2023-01-31 10:07:55 +00:00
return await this.callModuleReturn("discover", { pubkey });
}
}
2023-02-01 19:20:00 +00:00
export const createClient = factory(PeerDiscoveryClient, "FAC1RHsjGT8DcmOvnBVd8CekuuzE_qpMCRJ4oT_7Tql8bg");