···11export { LabelerServer, type LabelerOptions } from "./LabelerServer.js";
22export type { SignedLabel } from "./util/types.js";
33-export { formatLabel, signLabel, labelIsSigned } from "./util/labels.js";
44-55-export * as scripts from "./scripts/index.js";33+export { formatLabel, signLabel, labelIsSigned } from "./util/labels.js";
+21
src/scripts/declareLabeler.ts
···7171 });
7272 return policies.labelValueDefinitions;
7373}
7474+7575+/**
7676+ * Delete the labeler declaration for this account, removing all label definitions.
7777+ * @param credentials The credentials of the labeler account.
7878+ */
7979+export async function deleteLabelerDeclaration(
8080+ credentials: { pds?: string; identifier: string; password: string },
8181+): Promise<void>;
8282+/**
8383+ * Delete the labeler declaration for this account, removing all label definitions.
8484+ * @param agent The agent logged into the labeler account.
8585+ */
8686+export async function deleteLabelerDeclaration(
8787+ agent: AtpAgent,
8888+): Promise<void>;
8989+export async function deleteLabelerDeclaration(
9090+ agentOrCredentials: AtpAgent | { pds?: string; identifier: string; password: string },
9191+) {
9292+ const agent = await loginAgentOrCredentials(agentOrCredentials);
9393+ await agent.app.bsky.labeler.service.delete({ repo: agent.accountDid });
9494+}
+1-1
src/scripts/index.ts
···11export * from "./declareLabeler.js";
22export * from "./plc.js";
33-export { LoginCredentials } from "./util.js";
33+export type { LoginCredentials } from "./util.js";
+67
src/scripts/plc.ts
···3232 overwriteExistingKey?: boolean;
3333}
34343535+/** Options for the {@link plcClearLabeler} function. */
3636+export interface PlcClearLabelerOptions {
3737+ /**
3838+ * The token to use to sign the PLC operation.
3939+ * If you don't have a token, first call {@link plcRequestToken} to receive one via email.
4040+ */
4141+ plcToken: string;
4242+4343+ /** The URL of the PDS where the labeler account is located, if different from bsky.social. */
4444+ pds?: string;
4545+ /** The DID of the labeler account. */
4646+ did: string;
4747+ /** The password of the labeler account. You must provide either `password` or `agent`. */
4848+ password?: string;
4949+ /** An agent logged into the labeler account. You must provide either `password` or `agent`. */
5050+ agent?: AtpAgent;
5151+}
5252+3553/**
3654 * This function will update the labeler account's DID document to include the
3755 * provided labeler endpoint and signing key. If no private key is provided, a
3856 * new keypair will be generated, and the private key will be printed to the
3957 * console. This private key will be needed to sign any labels created.
5858+ * To set up a labeler, call this function followed by {@link declareLabeler}.
4059 * @param options Options for the function.
4160 */
4261export async function plcSetupLabeler(options: PlcSetupLabelerOptions) {
···114133 );
115134 console.log("Signing key:", privateKey);
116135 }
136136+}
137137+138138+/**
139139+ * This function will remove the labeler endpoint and signing key from the labeler account's DID document.
140140+ * To restore a labeler to a regular account, call this function followed by {@link deleteLabelerDeclaration}.
141141+ * @param options Options for the function.
142142+ */
143143+export async function plcClearLabeler(options: PlcClearLabelerOptions) {
144144+ if (!options.agent && !options.password) {
145145+ throw new Error(
146146+ "Either a logged-in agent or a password must be provided for the labeler account.",
147147+ );
148148+ }
149149+150150+ const agent = options.agent ?? new AtpAgent({ service: options.pds || "https://bsky.social" });
151151+ if (!agent.hasSession) {
152152+ if (!options.password) {
153153+ throw new Error("A password must be provided to log in to the labeler account.");
154154+ }
155155+ await agent.login({ identifier: options.did, password: options.password });
156156+ }
157157+158158+ const credentials = await agent.com.atproto.identity.getRecommendedDidCredentials();
159159+ if (!credentials.success) {
160160+ throw new Error("Failed to fetch DID document.");
161161+ }
162162+163163+ if (
164164+ credentials.data.verificationMethods
165165+ && "atproto_label" in credentials.data.verificationMethods
166166+ ) {
167167+ delete credentials.data.verificationMethods.atproto_label;
168168+ }
169169+170170+ if (
171171+ credentials.data.services
172172+ && "atproto_label" in credentials.data.services
173173+ && credentials.data.services["atproto_label"]
174174+ ) {
175175+ delete credentials.data.services.atproto_label;
176176+ }
177177+178178+ const plcOp = await agent.com.atproto.identity.signPlcOperation({
179179+ token: options.plcToken,
180180+ ...credentials.data,
181181+ });
182182+183183+ await agent.com.atproto.identity.submitPlcOperation({ operation: plcOp.data.operation });
117184}
118185119186/**