import { factory, NetworkClient } from "@lumeweb/libkernel/module"; import type { SignedRegistryEntry } from "@lumeweb/libs5"; export const MODULE = "zdiT6quMF8gh8BhQdXE7CZYhp8S1BxSgsucSS48WuTGdars1noejvak6Qo"; export interface RegistryEntry { key: Uint8Array; data: Uint8Array; revision: number; } export class S5Client extends NetworkClient { public async getRegistryEntry(pubkey: Uint8Array | Buffer | string) { return this.callModuleReturn("getRegistryEntry", { pubkey }); } public async setRegistryEntry({ key, data, revision, }: RegistryEntry): Promise { return this.callModuleReturn("setRegistryEntry", { key, data, revision }); } public registrySubscription( pubkey: Uint8Array, cb: (sre: SignedRegistryEntry) => void, ): () => void { let done = false; const [end, ret] = this.connectModule( "registrySubscription", { pubkey }, cb, ); ret.then((ret) => { this.handleError(ret); }); return () => { if (done) { return; } done = true; end(); }; } } export const createClient = factory(S5Client, MODULE);