feat: add createEntry
This commit is contained in:
parent
5c19245b4b
commit
02eefe442c
|
@ -31,7 +31,11 @@ import {
|
||||||
ExecuteRequestError,
|
ExecuteRequestError,
|
||||||
Headers,
|
Headers,
|
||||||
} from "./request.js";
|
} from "./request.js";
|
||||||
import { publishEntry, subscribeToEntry } from "./methods/registry.js";
|
import {
|
||||||
|
createEntry,
|
||||||
|
publishEntry,
|
||||||
|
subscribeToEntry,
|
||||||
|
} from "./methods/registry.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom client options.
|
* Custom client options.
|
||||||
|
@ -138,6 +142,7 @@ export class S5Client {
|
||||||
// Registry
|
// Registry
|
||||||
subscribeToEntry = subscribeToEntry;
|
subscribeToEntry = subscribeToEntry;
|
||||||
publishEntry = publishEntry;
|
publishEntry = publishEntry;
|
||||||
|
createEntry = createEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The S5 Client which can be used to access S5-net.
|
* The S5 Client which can be used to access S5-net.
|
||||||
|
|
|
@ -4,9 +4,16 @@ import { ensureBytes } from "@noble/curves/abstract/utils";
|
||||||
|
|
||||||
import WS from "isomorphic-ws";
|
import WS from "isomorphic-ws";
|
||||||
import { buildRequestUrl } from "#request.js";
|
import { buildRequestUrl } from "#request.js";
|
||||||
import { Packer, SignedRegistryEntry } from "@lumeweb/libs5";
|
import {
|
||||||
|
CID,
|
||||||
|
createKeyPair,
|
||||||
|
KeyPairEd25519,
|
||||||
|
Packer,
|
||||||
|
SignedRegistryEntry,
|
||||||
|
} from "@lumeweb/libs5";
|
||||||
import {
|
import {
|
||||||
deserializeRegistryEntry,
|
deserializeRegistryEntry,
|
||||||
|
signRegistryEntry,
|
||||||
verifyRegistryEntry,
|
verifyRegistryEntry,
|
||||||
} from "@lumeweb/libs5/lib/service/registry.js";
|
} from "@lumeweb/libs5/lib/service/registry.js";
|
||||||
import { Buffer } from "buffer";
|
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));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue