@elizaos/plugin-nostr 2.0.0-alpha.7 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +200 -0
  2. package/auto-enable.ts +20 -0
  3. package/dist/src/accounts.d.ts +15 -0
  4. package/dist/src/accounts.d.ts.map +1 -0
  5. package/dist/src/accounts.js +139 -0
  6. package/dist/src/accounts.js.map +1 -0
  7. package/dist/src/actions/index.d.ts +7 -0
  8. package/dist/src/actions/index.d.ts.map +1 -0
  9. package/dist/src/actions/index.js +7 -0
  10. package/dist/src/actions/index.js.map +1 -0
  11. package/dist/src/actions/publishProfile.d.ts +6 -0
  12. package/dist/src/actions/publishProfile.d.ts.map +1 -0
  13. package/dist/src/actions/publishProfile.js +157 -0
  14. package/dist/src/actions/publishProfile.js.map +1 -0
  15. package/dist/src/connector-account-provider.d.ts +20 -0
  16. package/dist/src/connector-account-provider.d.ts.map +1 -0
  17. package/dist/src/connector-account-provider.js +78 -0
  18. package/dist/src/connector-account-provider.js.map +1 -0
  19. package/dist/src/index.d.ts +19 -0
  20. package/dist/src/index.d.ts.map +1 -0
  21. package/dist/src/index.js +66 -0
  22. package/dist/src/index.js.map +1 -0
  23. package/dist/src/providers/identityContext.d.ts +6 -0
  24. package/dist/src/providers/identityContext.d.ts.map +1 -0
  25. package/dist/src/providers/identityContext.js +69 -0
  26. package/dist/src/providers/identityContext.js.map +1 -0
  27. package/dist/src/providers/index.d.ts +5 -0
  28. package/dist/src/providers/index.d.ts.map +1 -0
  29. package/dist/src/providers/index.js +5 -0
  30. package/dist/src/providers/index.js.map +1 -0
  31. package/dist/src/providers/senderContext.d.ts +6 -0
  32. package/dist/src/providers/senderContext.d.ts.map +1 -0
  33. package/dist/src/providers/senderContext.js +64 -0
  34. package/dist/src/providers/senderContext.js.map +1 -0
  35. package/dist/src/service.d.ts +116 -0
  36. package/dist/src/service.d.ts.map +1 -0
  37. package/dist/src/service.js +915 -0
  38. package/dist/src/service.js.map +1 -0
  39. package/dist/src/toon.d.ts +2 -0
  40. package/dist/src/toon.d.ts.map +1 -0
  41. package/dist/src/toon.js +18 -0
  42. package/dist/src/toon.js.map +1 -0
  43. package/dist/src/types.d.ts +125 -0
  44. package/dist/src/types.d.ts.map +1 -0
  45. package/dist/src/types.js +192 -0
  46. package/dist/src/types.js.map +1 -0
  47. package/package.json +26 -11
  48. package/dist/index.d.ts +0 -1
  49. package/dist/index.js +0 -876
  50. package/dist/index.js.map +0 -16
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Nostr ConnectorAccountManager provider.
3
+ *
4
+ * Adapts the multi-account scaffolding in `accounts.ts` to the
5
+ * `ConnectorAccountProvider` contract from
6
+ * `@elizaos/core/connectors/account-manager`.
7
+ *
8
+ * Source of truth for accounts is character settings (`character.settings.nostr`)
9
+ * + NOSTR_ACCOUNTS JSON env var + single-account env vars (NOSTR_PRIVATE_KEY,
10
+ * NOSTR_RELAYS, NOSTR_DM_POLICY).
11
+ *
12
+ * AccountKey is the nostr pubkey (hex). Role is `OWNER` since the private key
13
+ * is the user's identity. Public key is derived at service start time, so
14
+ * `externalId` may be empty until the service has resolved it; the manager
15
+ * tolerates this.
16
+ */
17
+ import { DEFAULT_NOSTR_ACCOUNT_ID, listNostrAccountIds, normalizeNostrAccountId, resolveNostrAccountSettings, } from "./accounts.js";
18
+ export const NOSTR_PROVIDER_ID = "nostr";
19
+ function accessGateForAccount(settings) {
20
+ if (settings.dmPolicy === "pairing")
21
+ return "pairing";
22
+ if (settings.dmPolicy === "disabled")
23
+ return "disabled";
24
+ return "open";
25
+ }
26
+ function toConnectorAccount(settings) {
27
+ const now = Date.now();
28
+ const configured = Boolean(settings.privateKey);
29
+ return {
30
+ id: normalizeNostrAccountId(settings.accountId),
31
+ provider: NOSTR_PROVIDER_ID,
32
+ label: settings.profile?.name ?? (settings.publicKey || settings.accountId),
33
+ role: "OWNER",
34
+ purpose: ["messaging"],
35
+ accessGate: accessGateForAccount(settings),
36
+ status: settings.enabled !== false && configured ? "connected" : "disabled",
37
+ externalId: settings.publicKey || undefined,
38
+ displayHandle: settings.profile?.name ?? (settings.publicKey || undefined),
39
+ createdAt: now,
40
+ updatedAt: now,
41
+ metadata: {
42
+ relays: settings.relays ?? [],
43
+ dmPolicy: settings.dmPolicy ?? "pairing",
44
+ hasProfile: Boolean(settings.profile),
45
+ },
46
+ };
47
+ }
48
+ export function createNostrConnectorAccountProvider(runtime) {
49
+ return {
50
+ provider: NOSTR_PROVIDER_ID,
51
+ label: "Nostr",
52
+ listAccounts: async (_manager) => {
53
+ const ids = listNostrAccountIds(runtime);
54
+ if (ids.length === 0) {
55
+ return [toConnectorAccount(resolveNostrAccountSettings(runtime, DEFAULT_NOSTR_ACCOUNT_ID))];
56
+ }
57
+ return ids.map((id) => toConnectorAccount(resolveNostrAccountSettings(runtime, id)));
58
+ },
59
+ createAccount: async (input, _manager) => {
60
+ return {
61
+ ...input,
62
+ provider: NOSTR_PROVIDER_ID,
63
+ role: input.role ?? "OWNER",
64
+ purpose: input.purpose ?? ["messaging"],
65
+ accessGate: input.accessGate ?? "open",
66
+ status: input.status ?? "pending",
67
+ };
68
+ },
69
+ patchAccount: async (_accountId, patch, _manager) => {
70
+ return { ...patch, provider: NOSTR_PROVIDER_ID };
71
+ },
72
+ deleteAccount: async (_accountId, _manager) => {
73
+ // No-op at provider layer — runtime credentials live in character
74
+ // settings; deletion of those is out of band.
75
+ },
76
+ };
77
+ }
78
+ //# sourceMappingURL=connector-account-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-account-provider.js","sourceRoot":"","sources":["../../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAGvB,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;A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via NIP-04 and profile management.
6
+ */
7
+ import type { Plugin } from "@elizaos/core";
8
+ import { identityContextProvider } from "./providers/index.js";
9
+ import { NostrService } from "./service.js";
10
+ export * from "./accounts.js";
11
+ export * from "./types.js";
12
+ export { identityContextProvider, NostrService };
13
+ export { publishProfile } from "./actions/index.js";
14
+ /**
15
+ * Nostr plugin definition
16
+ */
17
+ declare const nostrPlugin: Plugin;
18
+ export default nostrPlugin;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,eAAe,CAAC;AAE9B,cAAc,YAAY,CAAC;AAI3B,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,QAAA,MAAM,WAAW,EAAE,MAwDlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Nostr Plugin for ElizaOS
3
+ *
4
+ * Provides Nostr decentralized messaging integration for ElizaOS agents,
5
+ * supporting encrypted DMs via NIP-04 and profile management.
6
+ */
7
+ import { getConnectorAccountManager, logger } from "@elizaos/core";
8
+ import { createNostrConnectorAccountProvider } from "./connector-account-provider.js";
9
+ import { identityContextProvider } from "./providers/index.js";
10
+ import { NostrService } from "./service.js";
11
+ import { DEFAULT_NOSTR_RELAYS } from "./types.js";
12
+ export * from "./accounts.js";
13
+ // Export types
14
+ export * from "./types.js";
15
+ // Export service / providers / actions
16
+ // Nostr DMs route through MESSAGE. Public notes route through POST. Profile
17
+ // publishing is connector-owned identity metadata, not a planner action.
18
+ export { identityContextProvider, NostrService };
19
+ export { publishProfile } from "./actions/index.js";
20
+ /**
21
+ * Nostr plugin definition
22
+ */
23
+ const nostrPlugin = {
24
+ name: "nostr",
25
+ description: "Nostr decentralized messaging plugin for ElizaOS agents",
26
+ services: [NostrService],
27
+ actions: [],
28
+ providers: [identityContextProvider],
29
+ tests: [],
30
+ // Self-declared auto-enable: activate when the "nostr" connector is
31
+ // configured under config.connectors. The hardcoded CONNECTOR_PLUGINS map
32
+ // in plugin-auto-enable-engine.ts still serves as a fallback.
33
+ autoEnable: {
34
+ connectorKeys: ["nostr"],
35
+ },
36
+ /**
37
+ * Plugin initialization hook
38
+ */
39
+ init: async (config, runtime) => {
40
+ logger.info("Initializing Nostr plugin...");
41
+ try {
42
+ const manager = getConnectorAccountManager(runtime);
43
+ manager.registerProvider(createNostrConnectorAccountProvider(runtime));
44
+ }
45
+ catch (err) {
46
+ logger.warn({
47
+ src: "plugin:nostr",
48
+ err: err instanceof Error ? err.message : String(err),
49
+ }, "Failed to register Nostr provider with ConnectorAccountManager");
50
+ }
51
+ // Log configuration status
52
+ const hasPrivateKey = Boolean(config.NOSTR_PRIVATE_KEY || process.env.NOSTR_PRIVATE_KEY);
53
+ const relaysRaw = config.NOSTR_RELAYS || process.env.NOSTR_RELAYS || "";
54
+ const relays = relaysRaw ? relaysRaw.split(",").length : DEFAULT_NOSTR_RELAYS.length;
55
+ logger.info(`Nostr plugin configuration:`);
56
+ logger.info(` - Private key configured: ${hasPrivateKey ? "Yes" : "No"}`);
57
+ logger.info(` - Relays: ${relays} relay(s)`);
58
+ logger.info(` - DM policy: ${config.NOSTR_DM_POLICY || process.env.NOSTR_DM_POLICY || "pairing"}`);
59
+ if (!hasPrivateKey) {
60
+ logger.warn("Nostr private key not configured. Set NOSTR_PRIVATE_KEY (hex or nsec format).");
61
+ }
62
+ logger.info("Nostr plugin initialized");
63
+ },
64
+ };
65
+ export default nostrPlugin;
66
+ //# sourceMappingURL=index.js.map
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BACE,GAAG,EAAE,cAAc;gBACnB,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aACtD,EACD,gEAAgE,CACjE,CAAC;QACJ,CAAC;QAED,2BAA2B;QAC3B,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACzF,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;QACxE,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC;QAErF,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,+BAA+B,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3E,MAAM,CAAC,IAAI,CAAC,eAAe,MAAM,WAAW,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAI,CACT,kBAAkB,MAAM,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,CACvF,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;QAC/F,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Identity context provider for Nostr plugin.
3
+ */
4
+ import type { Provider } from "@elizaos/core";
5
+ export declare const identityContextProvider: Provider;
6
+ //# sourceMappingURL=identityContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityContext.d.ts","sourceRoot":"","sources":["../../../src/providers/identityContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAM5F,eAAO,MAAM,uBAAuB,EAAE,QAmErC,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Identity context provider for Nostr plugin.
3
+ */
4
+ import { NOSTR_SERVICE_NAME } from "../types.js";
5
+ const MAX_RELAYS_IN_STATE = 12;
6
+ export const identityContextProvider = {
7
+ name: "nostrIdentityContext",
8
+ description: "Provides information about the bot's Nostr identity",
9
+ descriptionCompressed: "provide information bot Nostr identity",
10
+ dynamic: true,
11
+ contextGate: { anyOf: ["social", "connectors"] },
12
+ cacheStable: false,
13
+ cacheScope: "turn",
14
+ contexts: ["social", "connectors"],
15
+ get: async (runtime, message, state) => {
16
+ // Only provide context for Nostr messages
17
+ if (message.content.source !== "nostr") {
18
+ return {
19
+ data: {},
20
+ values: {},
21
+ text: "",
22
+ };
23
+ }
24
+ const nostrService = runtime.getService(NOSTR_SERVICE_NAME);
25
+ if (!nostrService?.isConnected()) {
26
+ return {
27
+ data: { connected: false },
28
+ values: { connected: false },
29
+ text: "",
30
+ };
31
+ }
32
+ const agentName = state?.agentName || "The agent";
33
+ try {
34
+ const publicKey = nostrService.getPublicKey();
35
+ const npub = nostrService.getNpub();
36
+ const relays = nostrService.getRelays();
37
+ const shownRelays = relays.slice(0, MAX_RELAYS_IN_STATE);
38
+ const truncated = relays.length > shownRelays.length;
39
+ const responseText = `${agentName} is connected to Nostr with pubkey ${npub}. ` +
40
+ `Connected to ${relays.length} relay(s): ${shownRelays.join(", ")}${truncated ? " ..." : ""}. ` +
41
+ `Nostr is a decentralized social protocol using cryptographic keys for identity.`;
42
+ return {
43
+ data: {
44
+ publicKey,
45
+ npub,
46
+ relays: shownRelays,
47
+ relayCount: relays.length,
48
+ shownRelayCount: shownRelays.length,
49
+ truncated,
50
+ connected: true,
51
+ },
52
+ values: {
53
+ publicKey,
54
+ npub,
55
+ relayCount: relays.length,
56
+ },
57
+ text: responseText,
58
+ };
59
+ }
60
+ catch (error) {
61
+ return {
62
+ data: { connected: false, error: error instanceof Error ? error.message : String(error) },
63
+ values: { connected: false },
64
+ text: "",
65
+ };
66
+ }
67
+ },
68
+ };
69
+ //# sourceMappingURL=identityContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityContext.js","sourceRoot":"","sources":["../../../src/providers/identityContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,MAAM,uBAAuB,GAAa;IAC/C,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,qDAAqD;IAClE,qBAAqB,EAAE,wCAAwC;IAC/D,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;IAChD,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;IAClC,GAAG,EAAE,KAAK,EAAE,OAAsB,EAAE,OAAe,EAAE,KAAY,EAA2B,EAAE;QAC5F,0CAA0C;QAC1C,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YACvC,OAAO;gBACL,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,EAAE;gBACV,IAAI,EAAE,EAAE;aACT,CAAC;QACJ,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAe,kBAAkB,CAAC,CAAC;QAE1E,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,CAAC;YACjC,OAAO;gBACL,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC1B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AK,CAAC,EAAE;gBACzF,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC5B,IAAI,EAAE,EAAE;aACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Export all Nostr providers.
3
+ */
4
+ export { identityContextProvider } from "./identityContext.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Export all Nostr providers.
3
+ */
4
+ export { identityContextProvider } from "./identityContext.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sender context provider for Nostr plugin.
3
+ */
4
+ import type { Provider } from "@elizaos/core";
5
+ export declare const senderContextProvider: Provider;
6
+ //# sourceMappingURL=senderContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"senderContext.d.ts","sourceRoot":"","sources":["../../../src/providers/senderContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAI5F,eAAO,MAAM,qBAAqB,EAAE,QAmEnC,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Sender context provider for Nostr plugin.
3
+ */
4
+ import { getPubkeyDisplayName, NOSTR_SERVICE_NAME, pubkeyToNpub } from "../types.js";
5
+ export const senderContextProvider = {
6
+ name: "nostrSenderContext",
7
+ description: "Provides information about the Nostr user in the current conversation",
8
+ descriptionCompressed: "provide information Nostr user current conversation",
9
+ dynamic: true,
10
+ get: async (runtime, message, state) => {
11
+ // Only provide context for Nostr messages
12
+ if (message.content.source !== "nostr") {
13
+ return {
14
+ data: {},
15
+ values: {},
16
+ text: "",
17
+ };
18
+ }
19
+ const nostrService = runtime.getService(NOSTR_SERVICE_NAME);
20
+ if (!nostrService?.isConnected()) {
21
+ return {
22
+ data: { connected: false },
23
+ values: { connected: false },
24
+ text: "",
25
+ };
26
+ }
27
+ const agentName = state?.agentName || "The agent";
28
+ // Get sender pubkey from state if available
29
+ const senderPubkey = state?.data?.senderPubkey;
30
+ if (!senderPubkey) {
31
+ return {
32
+ data: { connected: true },
33
+ values: { connected: true },
34
+ text: "",
35
+ };
36
+ }
37
+ let senderNpub = "";
38
+ try {
39
+ senderNpub = pubkeyToNpub(senderPubkey);
40
+ }
41
+ catch {
42
+ // Use hex if npub conversion fails
43
+ }
44
+ const displayName = getPubkeyDisplayName(senderPubkey);
45
+ const responseText = `${agentName} is talking to ${displayName} on Nostr. ` +
46
+ `Their pubkey is ${senderNpub || senderPubkey}. ` +
47
+ `This is an encrypted direct message conversation using NIP-04.`;
48
+ return {
49
+ data: {
50
+ senderPubkey,
51
+ senderNpub,
52
+ displayName,
53
+ isEncrypted: true,
54
+ },
55
+ values: {
56
+ senderPubkey,
57
+ senderNpub,
58
+ displayName,
59
+ },
60
+ text: responseText,
61
+ };
62
+ },
63
+ };
64
+ //# sourceMappingURL=senderContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"senderContext.js","sourceRoot":"","sources":["../../../src/providers/senderContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,CAAC,MAAM,qBAAqB,GAAa;IAC7C,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,uEAAuE;IACpF,qBAAqB,EAAE,qDAAqD;IAC5E,OAAO,E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L,IAAI,EAAE;gBACJ,YAAY;gBACZ,UAAU;gBACV,WAAW;gBACX,WAAW,EAAE,IAAI;aAClB;YACD,MAAM,EAAE;gBACN,YAAY;gBACZ,UAAU;gBACV,WAAW;aACZ;YACD,IAAI,EAAE,YAAY;SACnB,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Nostr service implementation for ElizaOS.
3
+ */
4
+ import { type Content, type IAgentRuntime, type Memory, type MessageConnectorQueryContext, type MessageConnectorTarget, type MessageConnectorUserContext, Service, type TargetInfo, type UUID } from "@elizaos/core";
5
+ import { type INostrService, type NostrDmSendOptions, type NostrProfile, type NostrSendResult, type NostrSettings } from "./types.js";
6
+ interface PostConnectorQueryContext {
7
+ runtime: IAgentRuntime;
8
+ roomId?: UUID;
9
+ source?: string;
10
+ target?: TargetInfo;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ export declare class NostrService extends Service implements INostrService {
14
+ static serviceType: string;
15
+ capabilityDescription: string;
16
+ private settings;
17
+ private pool;
18
+ private privateKey;
19
+ private connected;
20
+ private seenEventIds;
21
+ private accountServices;
22
+ /**
23
+ * Start the Nostr service.
24
+ */
25
+ static start(runtime: IAgentRuntime): Promise<NostrService>;
26
+ static registerSendHandlers(runtime: IAgentRuntime, serviceInstance: NostrService): void;
27
+ private registerPostConnector;
28
+ /**
29
+ * Initialize the service.
30
+ */
31
+ private initialize;
32
+ private initializeAccount;
33
+ /**
34
+ * Stop the Nostr service.
35
+ */
36
+ stop(): Promise<void>;
37
+ private getAccountServiceList;
38
+ private getDefaultAccountService;
39
+ private getAccountService;
40
+ /**
41
+ * Load settings from runtime configuration.
42
+ */
43
+ private loadSettings;
44
+ /**
45
+ * Validate the settings.
46
+ */
47
+ private validateSettings;
48
+ /**
49
+ * Start the DM subscription.
50
+ */
51
+ private startSubscription;
52
+ /**
53
+ * Handle an incoming event.
54
+ */
55
+ private handleEvent;
56
+ /**
57
+ * Check if the service is connected.
58
+ */
59
+ isConnected(): boolean;
60
+ /**
61
+ * Get the bot's public key in hex format.
62
+ */
63
+ getPublicKey(): string;
64
+ getAccountId(runtime?: IAgentRuntime): string;
65
+ /**
66
+ * Get the bot's public key in npub format.
67
+ */
68
+ getNpub(): string;
69
+ /**
70
+ * Get connected relays.
71
+ */
72
+ getRelays(): string[];
73
+ handleSendMessage(_runtime: IAgentRuntime, target: TargetInfo, content: Content): Promise<void>;
74
+ handleSendPost(runtime: IAgentRuntime, content: Content): Promise<Memory>;
75
+ fetchConnectorFeed(context: PostConnectorQueryContext, params?: {
76
+ feed?: string;
77
+ target?: TargetInfo;
78
+ limit?: number;
79
+ cursor?: string;
80
+ }): Promise<Memory[]>;
81
+ searchConnectorPosts(context: PostConnectorQueryContext, params: {
82
+ query: string;
83
+ limit?: number;
84
+ cursor?: string;
85
+ }): Promise<Memory[]>;
86
+ fetchConnectorMessages(context: MessageConnectorQueryContext, params?: {
87
+ target?: TargetInfo;
88
+ limit?: number;
89
+ before?: string;
90
+ after?: string;
91
+ }): Promise<Memory[]>;
92
+ resolveConnectorTargets(query: string, _context: MessageConnectorQueryContext): Promise<MessageConnectorTarget[]>;
93
+ listRecentConnectorTargets(_context: MessageConnectorQueryContext): Promise<MessageConnectorTarget[]>;
94
+ getConnectorUserContext(entityId: string, _context: MessageConnectorQueryContext): Promise<MessageConnectorUserContext | null>;
95
+ private nostrEventToPostMemory;
96
+ private nostrEventToDmMemory;
97
+ private buildPubkeyTarget;
98
+ /**
99
+ * Send a DM to a pubkey.
100
+ */
101
+ sendDm(options: NostrDmSendOptions): Promise<NostrSendResult>;
102
+ /**
103
+ * Publish profile (kind:0).
104
+ */
105
+ publishProfile(profile: NostrProfile): Promise<NostrSendResult>;
106
+ /**
107
+ * Publish a text note (kind:1).
108
+ */
109
+ publishNote(text: string, tags?: string[][]): Promise<NostrSendResult>;
110
+ /**
111
+ * Get the settings.
112
+ */
113
+ getSettings(): NostrSettings | null;
114
+ }
115
+ export {};
116
+ //# source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