diff --git a/src/client.ts b/src/client.ts index 5aa405b..20af533 100644 --- a/src/client.ts +++ b/src/client.ts @@ -31,7 +31,11 @@ import { ExecuteRequestError, Headers, } from "./request.js"; -import { publishEntry, subscribeToEntry } from "./methods/registry.js"; +import { + createEntry, + publishEntry, + subscribeToEntry, +} from "./methods/registry.js"; /** * Custom client options. @@ -138,6 +142,7 @@ export class S5Client { // Registry subscribeToEntry = subscribeToEntry; publishEntry = publishEntry; + createEntry = createEntry; /** * The S5 Client which can be used to access S5-net. diff --git a/src/methods/registry.ts b/src/methods/registry.ts index d71e286..a513237 100644 --- a/src/methods/registry.ts +++ b/src/methods/registry.ts @@ -4,9 +4,16 @@ import { ensureBytes } from "@noble/curves/abstract/utils"; import WS from "isomorphic-ws"; import { buildRequestUrl } from "#request.js"; -import { Packer, SignedRegistryEntry } from "@lumeweb/libs5"; +import { + CID, + createKeyPair, + KeyPairEd25519, + Packer, + SignedRegistryEntry, +} from "@lumeweb/libs5"; import { deserializeRegistryEntry, + signRegistryEntry, verifyRegistryEntry, } from "@lumeweb/libs5/lib/service/registry.js"; import { Buffer } from "buffer"; @@ -115,3 +122,22 @@ export async function publishEntry( }, }); } + +export async function createEntry( + this: S5Client, + sk: Uint8Array | KeyPairEd25519, + cid: CID, + revision = 0, +) { + if (sk instanceof Uint8Array) { + sk = createKeyPair(sk); + } + + const entry = { + kp: sk, + data: cid.toBytes(), + revision, + }; + + return this.publishEntry(signRegistryEntry(entry)); +}