2026-03-16 23:51:41 -07:00
|
|
|
import { defineChannelPluginEntry } from "openclaw/plugin-sdk/core";
|
2026-02-18 01:29:02 +00:00
|
|
|
import { nostrPlugin } from "./src/channel.js";
|
2026-02-18 01:34:35 +00:00
|
|
|
import type { NostrProfile } from "./src/config-schema.js";
|
2026-01-20 20:14:44 +00:00
|
|
|
import { createNostrProfileHttpHandler } from "./src/nostr-profile-http.js";
|
2026-03-16 23:51:41 -07:00
|
|
|
import { getNostrRuntime, setNostrRuntime } from "./src/runtime.js";
|
2026-01-20 20:14:44 +00:00
|
|
|
import { resolveNostrAccount } from "./src/types.js";
|
|
|
|
|
|
2026-03-17 09:33:17 -07:00
|
|
|
export { nostrPlugin } from "./src/channel.js";
|
|
|
|
|
export { setNostrRuntime } from "./src/runtime.js";
|
|
|
|
|
|
2026-03-16 23:51:41 -07:00
|
|
|
export default defineChannelPluginEntry({
|
2026-01-20 20:14:44 +00:00
|
|
|
id: "nostr",
|
|
|
|
|
name: "Nostr",
|
|
|
|
|
description: "Nostr DM channel plugin via NIP-04",
|
2026-03-16 23:51:41 -07:00
|
|
|
plugin: nostrPlugin,
|
|
|
|
|
setRuntime: setNostrRuntime,
|
|
|
|
|
registerFull(api) {
|
2026-01-20 20:14:44 +00:00
|
|
|
const httpHandler = createNostrProfileHttpHandler({
|
|
|
|
|
getConfigProfile: (accountId: string) => {
|
|
|
|
|
const runtime = getNostrRuntime();
|
2026-01-31 22:13:48 +09:00
|
|
|
const cfg = runtime.config.loadConfig();
|
2026-01-20 20:14:44 +00:00
|
|
|
const account = resolveNostrAccount({ cfg, accountId });
|
|
|
|
|
return account.profile;
|
|
|
|
|
},
|
|
|
|
|
updateConfigProfile: async (accountId: string, profile: NostrProfile) => {
|
|
|
|
|
const runtime = getNostrRuntime();
|
2026-01-31 22:13:48 +09:00
|
|
|
const cfg = runtime.config.loadConfig();
|
2026-01-20 20:14:44 +00:00
|
|
|
|
|
|
|
|
const channels = (cfg.channels ?? {}) as Record<string, unknown>;
|
|
|
|
|
const nostrConfig = (channels.nostr ?? {}) as Record<string, unknown>;
|
|
|
|
|
|
|
|
|
|
await runtime.config.writeConfigFile({
|
|
|
|
|
...cfg,
|
2026-03-16 23:51:41 -07:00
|
|
|
channels: {
|
|
|
|
|
...channels,
|
|
|
|
|
nostr: {
|
|
|
|
|
...nostrConfig,
|
|
|
|
|
profile,
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-01-20 20:14:44 +00:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getAccountInfo: (accountId: string) => {
|
|
|
|
|
const runtime = getNostrRuntime();
|
2026-01-31 22:13:48 +09:00
|
|
|
const cfg = runtime.config.loadConfig();
|
2026-01-20 20:14:44 +00:00
|
|
|
const account = resolveNostrAccount({ cfg, accountId });
|
|
|
|
|
if (!account.configured || !account.publicKey) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
pubkey: account.publicKey,
|
|
|
|
|
relays: account.relays,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
log: api.logger,
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-02 16:22:31 +00:00
|
|
|
api.registerHttpRoute({
|
|
|
|
|
path: "/api/channels/nostr",
|
|
|
|
|
auth: "gateway",
|
|
|
|
|
match: "prefix",
|
|
|
|
|
handler: httpHandler,
|
|
|
|
|
});
|
2026-01-20 20:14:44 +00:00
|
|
|
},
|
2026-03-16 23:51:41 -07:00
|
|
|
});
|