feat: add createEntry

This commit is contained in:
Derrick Hammer 2023-12-11 22:44:43 -05:00
parent 5c19245b4b
commit 02eefe442c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 33 additions and 2 deletions

View File

@ -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.

View File

@ -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));
}