@elizaos/plugin-nostr 2.0.0-beta.1 → 2.0.3-beta.3

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -164
  3. package/auto-enable.ts +1 -1
  4. package/package.json +23 -6
  5. package/registry-entry.json +71 -0
  6. package/dist/src/accounts.d.ts +0 -15
  7. package/dist/src/accounts.d.ts.map +0 -1
  8. package/dist/src/accounts.js +0 -139
  9. package/dist/src/accounts.js.map +0 -1
  10. package/dist/src/actions/index.d.ts +0 -7
  11. package/dist/src/actions/index.d.ts.map +0 -1
  12. package/dist/src/actions/index.js +0 -7
  13. package/dist/src/actions/index.js.map +0 -1
  14. package/dist/src/actions/publishProfile.d.ts +0 -6
  15. package/dist/src/actions/publishProfile.d.ts.map +0 -1
  16. package/dist/src/actions/publishProfile.js +0 -157
  17. package/dist/src/actions/publishProfile.js.map +0 -1
  18. package/dist/src/connector-account-provider.d.ts +0 -20
  19. package/dist/src/connector-account-provider.d.ts.map +0 -1
  20. package/dist/src/connector-account-provider.js +0 -78
  21. package/dist/src/connector-account-provider.js.map +0 -1
  22. package/dist/src/index.d.ts +0 -19
  23. package/dist/src/index.d.ts.map +0 -1
  24. package/dist/src/index.js +0 -66
  25. package/dist/src/index.js.map +0 -1
  26. package/dist/src/providers/identityContext.d.ts +0 -6
  27. package/dist/src/providers/identityContext.d.ts.map +0 -1
  28. package/dist/src/providers/identityContext.js +0 -69
  29. package/dist/src/providers/identityContext.js.map +0 -1
  30. package/dist/src/providers/index.d.ts +0 -5
  31. package/dist/src/providers/index.d.ts.map +0 -1
  32. package/dist/src/providers/index.js +0 -5
  33. package/dist/src/providers/index.js.map +0 -1
  34. package/dist/src/providers/senderContext.d.ts +0 -6
  35. package/dist/src/providers/senderContext.d.ts.map +0 -1
  36. package/dist/src/providers/senderContext.js +0 -64
  37. package/dist/src/providers/senderContext.js.map +0 -1
  38. package/dist/src/service.d.ts +0 -116
  39. package/dist/src/service.d.ts.map +0 -1
  40. package/dist/src/service.js +0 -915
  41. package/dist/src/service.js.map +0 -1
  42. package/dist/src/toon.d.ts +0 -2
  43. package/dist/src/toon.d.ts.map +0 -1
  44. package/dist/src/toon.js +0 -18
  45. package/dist/src/toon.js.map +0 -1
  46. package/dist/src/types.d.ts +0 -125
  47. package/dist/src/types.d.ts.map +0 -1
  48. package/dist/src/types.js +0 -192
  49. package/dist/src/types.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,42 +1,23 @@
1
1
  # @elizaos/plugin-nostr
2
2
 
3
- Nostr decentralized messaging plugin for ElizaOS agents. Enables secure, encrypted direct messaging (NIP-04) over the Nostr protocol.
3
+ Nostr decentralized messaging plugin for elizaOS agents. Gives an Eliza agent a Nostr identity and connects it to one or more relays, enabling encrypted direct messages (NIP-04), public note publishing (kind:1), and profile management (kind:0).
4
4
 
5
- ## Features
5
+ ## What it adds
6
6
 
7
- - **Encrypted Direct Messages (NIP-04)**: Send and receive encrypted DMs using the Nostr protocol
8
- - **Multi-relay Support**: Connect to multiple Nostr relays for redundancy
9
- - **Profile Management**: Publish and update your agent's Nostr profile (kind:0)
10
- - **DM Policy Control**: Configure who can message your agent (open, pairing, allowlist, disabled)
7
+ - **Encrypted DMs (NIP-04)** receive and send encrypted direct messages; routes through the `MESSAGE` connector action so the agent's planner needs no plugin-specific actions.
8
+ - **Public notes (kind:1)** — publish notes to connected relays; routes through the `POST` connector action. Supports relay feed reading and NIP-50 relay search where the relay implements it.
9
+ - **Profile publishing (kind:0)** publish agent profile metadata (name, picture, nip05, etc.) to relays.
10
+ - **Multi-relay redundancy** publishes to all configured relays; succeeds when at least one accepts the event.
11
+ - **Multi-account support** — run the agent under multiple Nostr identities simultaneously.
11
12
 
12
- ## Installation
13
+ ## Enabling the plugin
13
14
 
14
- ```bash
15
- # npm
16
- npm install @elizaos/plugin-nostr
17
-
18
- # bun
19
- bun add @elizaos/plugin-nostr
20
- ```
21
-
22
- ## Configuration
23
-
24
- ### Environment Variables
25
-
26
- | Variable | Description | Required |
27
- |----------|-------------|----------|
28
- | `NOSTR_PRIVATE_KEY` | Private key (hex or nsec format) | Yes |
29
- | `NOSTR_RELAYS` | Comma-separated relay URLs | No |
30
- | `NOSTR_DM_POLICY` | DM policy: open, pairing, allowlist, disabled | No |
31
- | `NOSTR_ALLOW_FROM` | Comma-separated pubkeys for allowlist | No |
32
- | `NOSTR_ENABLED` | Enable/disable the plugin | No |
33
-
34
- ### Agent Configuration
15
+ Add `@elizaos/plugin-nostr` to the `plugins` array in the agent character file, or let the auto-enable engine activate it automatically when a `connectors.nostr` block is present in the agent config.
35
16
 
36
17
  ```json
37
18
  {
38
19
  "plugins": ["@elizaos/plugin-nostr"],
39
- "pluginParameters": {
20
+ "settings": {
40
21
  "NOSTR_PRIVATE_KEY": "your-private-key-hex-or-nsec",
41
22
  "NOSTR_RELAYS": "wss://relay.damus.io,wss://nos.lol,wss://relay.nostr.band",
42
23
  "NOSTR_DM_POLICY": "pairing"
@@ -44,157 +25,84 @@ bun add @elizaos/plugin-nostr
44
25
  }
45
26
  ```
46
27
 
47
- ## Usage
48
-
49
- ### Actions
50
-
51
- Nostr DMs and public notes are exposed through canonical connector actions. Use
52
- `source: "nostr"` when a request needs to target Nostr explicitly.
28
+ ## Configuration
53
29
 
54
- | Primary action | Operation | Description |
55
- |----------------|-----------|-------------|
56
- | `MESSAGE` | `send` | Send an encrypted direct message to a Nostr pubkey |
57
- | `MESSAGE` | `read` | Read recent direct messages where the connector can fetch them |
58
- | `POST` | `send` | Publish a public Nostr note |
59
- | `POST` | `read` | Read recent relay feed posts |
60
- | `POST` | `search` | Search relay posts where supported |
30
+ ### Environment variables
61
31
 
62
- Profile updates remain a Nostr-specific profile capability outside the
63
- MESSAGE/POST connector action set.
32
+ | Variable | Required | Default | Description |
33
+ |---|---|---|---|
34
+ | `NOSTR_PRIVATE_KEY` | Yes | — | Private key in hex (64 chars) or `nsec1` bech32 format |
35
+ | `NOSTR_RELAYS` | No | damus.io, nos.lol, relay.nostr.band | Comma-separated relay WebSocket URLs |
36
+ | `NOSTR_DM_POLICY` | No | `pairing` | DM acceptance policy (see below) |
37
+ | `NOSTR_ALLOW_FROM` | No | — | Comma-separated pubkeys allowed to DM (required for `allowlist` policy) |
38
+ | `NOSTR_ENABLED` | No | `true` | Set to `false` to disable without removing config |
39
+ | `NOSTR_ACCOUNTS` | No | — | JSON array or object for multi-account configuration |
40
+ | `NOSTR_DEFAULT_ACCOUNT_ID` | No | `"default"` | Default account when multiple are configured |
64
41
 
65
- ### Providers
42
+ ### Character file override
66
43
 
67
- #### nostrIdentityContext
44
+ Settings can be embedded directly in the character file under `settings.nostr`:
68
45
 
69
- Provides information about the bot's Nostr identity:
70
- - Public key (hex and npub)
71
- - Connected relays
72
- - Connection status
46
+ ```json
47
+ {
48
+ "settings": {
49
+ "nostr": {
50
+ "privateKey": "...",
51
+ "relays": ["wss://relay.damus.io", "wss://nos.lol"],
52
+ "dmPolicy": "allowlist",
53
+ "allowFrom": ["npub1...", "deadbeef..."],
54
+ "profile": {
55
+ "name": "my-agent",
56
+ "nip05": "agent@example.com"
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
73
62
 
74
- #### nostrSenderContext
63
+ For multiple accounts, use `settings.nostr.accounts`:
75
64
 
76
- Provides information about the current conversation partner:
77
- - Sender's pubkey (hex and npub)
78
- - Display name
79
- - Encryption status
65
+ ```json
66
+ {
67
+ "settings": {
68
+ "nostr": {
69
+ "accounts": {
70
+ "main": { "privateKey": "...", "relays": ["wss://relay.damus.io"] },
71
+ "alt": { "privateKey": "...", "relays": ["wss://nos.lol"] }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ```
80
77
 
81
- ## DM Policies
78
+ ## DM policies
82
79
 
83
80
  | Policy | Description |
84
- |--------|-------------|
85
- | `open` | Accept DMs from anyone |
86
- | `pairing` | Accept DMs and remember senders for future conversations |
87
- | `allowlist` | Only accept DMs from pubkeys in NOSTR_ALLOW_FROM |
88
- | `disabled` | Don't accept any DMs |
81
+ |---|---|
82
+ | `open` | Accept DMs from any pubkey |
83
+ | `pairing` | Accept DMs and remember senders |
84
+ | `allowlist` | Only accept DMs from pubkeys in `NOSTR_ALLOW_FROM` |
85
+ | `disabled` | Ignore all incoming DMs |
89
86
 
90
- ## Nostr Concepts
87
+ ## Nostr concepts
91
88
 
92
- ### Keys
89
+ - **Private key** — signs events and decrypts messages. Never commit to version control; use env vars or a secrets manager.
90
+ - **Public key** — derived automatically from the private key. This is the agent's Nostr identity.
91
+ - **npub / nsec** — bech32-encoded formats for public/private keys. Both formats are accepted as input.
92
+ - **kind:0** — profile metadata event.
93
+ - **kind:1** — public text note.
94
+ - **kind:4** — NIP-04 encrypted DM.
93
95
 
94
- - **Private Key**: Used to sign events and decrypt messages. Keep this secret!
95
- - **Public Key**: Your identity on Nostr. Can be shared freely.
96
- - **npub/nsec**: Bech32-encoded formats for public/private keys
96
+ ## Security
97
97
 
98
- ### Events
99
-
100
- - **kind:0**: Profile metadata
101
- - **kind:4**: Encrypted DMs (NIP-04)
102
-
103
- ### Relays
104
-
105
- Nostr relays are servers that store and forward events. Your agent connects to multiple relays for redundancy.
106
-
107
- ## Example
108
-
109
- ```typescript
110
- import { createAgent } from "@elizaos/core";
111
- import nostrPlugin from "@elizaos/plugin-nostr";
112
-
113
- const agent = await createAgent({
114
- plugins: [nostrPlugin],
115
- settings: {
116
- NOSTR_PRIVATE_KEY: process.env.NOSTR_PRIVATE_KEY,
117
- NOSTR_RELAYS: "wss://relay.damus.io,wss://nos.lol",
118
- NOSTR_DM_POLICY: "pairing",
119
- },
120
- });
121
-
122
- // The agent can now receive DMs and respond
123
- ```
124
-
125
- ## Security Considerations
126
-
127
- 1. **Private Key Storage**: Never commit your private key to version control. Use environment variables or secure secret management.
128
-
129
- 2. **Key Generation**: Generate keys using a reputable tool like `nip-06` or the `nostr-tools` library.
130
-
131
- 3. **Relay Selection**: Choose relays carefully. Consider running your own relay for sensitive applications.
132
-
133
- 4. **DM Policy**: Start with a restrictive policy and relax as needed.
98
+ - Generate keys with a trusted tool such as `nostr-tools` (`generateSecretKey` + `getPublicKey`).
99
+ - Start with a restrictive DM policy (`allowlist`) and relax as needed.
100
+ - Consider running a private relay for sensitive agent deployments.
134
101
 
135
102
  ## Development
136
103
 
137
- ### Building
138
-
139
104
  ```bash
140
- cd typescript && npm run build
105
+ bun run --cwd plugins/plugin-nostr build
106
+ bun run --cwd plugins/plugin-nostr test
107
+ bun run --cwd plugins/plugin-nostr typecheck
141
108
  ```
142
-
143
- ### Testing
144
-
145
- ```bash
146
- npm test
147
- ```
148
-
149
- ## API Reference
150
-
151
- ### NostrService
152
-
153
- #### Methods
154
-
155
- - `isConnected()`: Check if connected to relays
156
- - `getPublicKey()`: Get the bot's public key (hex)
157
- - `getNpub()`: Get the bot's npub
158
- - `getRelays()`: Get connected relay URLs
159
- - `sendDm(options)`: Send an encrypted DM
160
- - `publishProfile(profile)`: Publish profile metadata
161
-
162
- ### Types
163
-
164
- ```typescript
165
- interface NostrSettings {
166
- privateKey: string;
167
- publicKey: string;
168
- relays: string[];
169
- dmPolicy: "open" | "pairing" | "allowlist" | "disabled";
170
- allowFrom: string[];
171
- enabled: boolean;
172
- }
173
-
174
- interface NostrProfile {
175
- name?: string;
176
- displayName?: string;
177
- about?: string;
178
- picture?: string;
179
- banner?: string;
180
- nip05?: string;
181
- lud16?: string;
182
- website?: string;
183
- }
184
-
185
- interface NostrDmSendOptions {
186
- toPubkey: string;
187
- text: string;
188
- }
189
-
190
- interface NostrSendResult {
191
- success: boolean;
192
- eventId?: string;
193
- relays: string[];
194
- error?: string;
195
- }
196
- ```
197
-
198
- ## License
199
-
200
- MIT
package/auto-enable.ts CHANGED
@@ -8,7 +8,7 @@ import type { PluginAutoEnableContext } from "@elizaos/core";
8
8
 
9
9
  /** Enable when a `nostr` connector block is present and not explicitly disabled. */
10
10
  export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
11
- const c = (ctx.config?.connectors as Record<string, unknown> | undefined)?.nostr;
11
+ const c = (ctx.config.connectors as Record<string, unknown> | undefined)?.nostr;
12
12
  if (!c || typeof c !== "object") return false;
13
13
  const config = c as Record<string, unknown>;
14
14
  if (config.enabled === false) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-nostr",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.3-beta.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -9,11 +9,28 @@
9
9
  "./package.json": "./package.json",
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
+ "eliza-source": {
13
+ "types": "./src/index.ts",
14
+ "import": "./src/index.ts",
15
+ "default": "./src/index.ts"
16
+ },
12
17
  "import": "./dist/index.js",
13
18
  "default": "./dist/index.js"
19
+ },
20
+ "./*.css": "./dist/*.css",
21
+ "./*": {
22
+ "types": "./dist/*.d.ts",
23
+ "eliza-source": {
24
+ "types": "./src/*.ts",
25
+ "import": "./src/*.ts",
26
+ "default": "./src/*.ts"
27
+ },
28
+ "import": "./dist/*.js",
29
+ "default": "./dist/*.js"
14
30
  }
15
31
  },
16
32
  "files": [
33
+ "registry-entry.json",
17
34
  "dist",
18
35
  "auto-enable.ts"
19
36
  ],
@@ -35,12 +52,11 @@
35
52
  "lint:check": "bunx @biomejs/biome check .",
36
53
  "format": "bunx @biomejs/biome format --write .",
37
54
  "format:check": "bunx @biomejs/biome format .",
38
- "typecheck": "tsc --noEmit"
55
+ "typecheck": "tsgo --noEmit"
39
56
  },
40
57
  "dependencies": {
41
- "@elizaos/core": "2.0.0-beta.1",
42
- "nostr-tools": "^2.0.0",
43
- "zod": "^4.4.3"
58
+ "@elizaos/core": "2.0.3-beta.3",
59
+ "nostr-tools": "^2.0.0"
44
60
  },
45
61
  "devDependencies": {
46
62
  "@biomejs/biome": "^2.4.14",
@@ -93,5 +109,6 @@
93
109
  "sensitive": false
94
110
  }
95
111
  }
96
- }
112
+ },
113
+ "gitHead": "f54b0f4eaed317d59fa7dbcdce20f4cdb0734420"
97
114
  }
@@ -0,0 +1,71 @@
1
+ {
2
+ "id": "nostr",
3
+ "name": "Nostr",
4
+ "description": "Nostr connector for relay-based social posting and conversation handling.",
5
+ "npmName": "@elizaos/plugin-nostr",
6
+ "version": "2.0.0-beta.0",
7
+ "source": "bundled",
8
+ "tags": ["connector", "social", "nostr", "relays", "social-feed"],
9
+ "config": {
10
+ "NOSTR_RELAYS": {
11
+ "type": "string",
12
+ "required": false,
13
+ "sensitive": false,
14
+ "label": "Relays",
15
+ "help": "Comma-separated list of relay URLs",
16
+ "advanced": false
17
+ },
18
+ "NOSTR_ENABLED": {
19
+ "type": "boolean",
20
+ "required": false,
21
+ "sensitive": false,
22
+ "label": "Enabled",
23
+ "help": "Enable or disable this feature",
24
+ "advanced": false
25
+ },
26
+ "NOSTR_DM_POLICY": {
27
+ "type": "string",
28
+ "required": false,
29
+ "sensitive": false,
30
+ "label": "Dm Policy",
31
+ "help": "DM policy (e.g. allow, deny, allowlist)",
32
+ "advanced": false
33
+ },
34
+ "NOSTR_ALLOW_FROM": {
35
+ "type": "string",
36
+ "required": false,
37
+ "sensitive": false,
38
+ "label": "Allow From",
39
+ "help": "Comma-separated allowed user list",
40
+ "advanced": false
41
+ },
42
+ "NOSTR_PRIVATE_KEY": {
43
+ "type": "secret",
44
+ "required": true,
45
+ "sensitive": true,
46
+ "label": "Private Key",
47
+ "help": "Private key for Nostr",
48
+ "advanced": false
49
+ }
50
+ },
51
+ "render": {
52
+ "visible": false,
53
+ "pinTo": [],
54
+ "style": "setup-panel",
55
+ "icon": "Fingerprint",
56
+ "group": "connector",
57
+ "groupOrder": 1,
58
+ "actions": ["enable", "configure", "setup-guide"]
59
+ },
60
+ "resources": {
61
+ "setupGuideUrl": "https://docs.eliza.ai/plugin-setup-guide#nostr"
62
+ },
63
+ "dependsOn": [],
64
+ "kind": "connector",
65
+ "subtype": "messaging",
66
+ "auth": {
67
+ "kind": "token",
68
+ "credentialKeys": []
69
+ },
70
+ "channels": ["nostr"]
71
+ }
@@ -1,15 +0,0 @@
1
- import type { IAgentRuntime } from "@elizaos/core";
2
- import { type NostrSettings } from "./types.js";
3
- export declare const DEFAULT_NOSTR_ACCOUNT_ID = "default";
4
- export type NostrAccountConfig = Partial<Omit<NostrSettings, "relays" | "allowFrom" | "publicKey" | "accountId">> & {
5
- accountId?: string;
6
- id?: string;
7
- relays?: string[] | string;
8
- allowFrom?: string[] | string;
9
- };
10
- export declare function normalizeNostrAccountId(accountId?: unknown): string;
11
- export declare function listNostrAccountIds(runtime: IAgentRuntime): string[];
12
- export declare function resolveDefaultNostrAccountId(runtime: IAgentRuntime): string;
13
- export declare function readNostrAccountId(...sources: unknown[]): string | undefined;
14
- export declare function resolveNostrAccountSettings(runtime: IAgentRuntime, requestedAccountId?: string | null): NostrSettings;
15
- //# sourceMappingURL=accounts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1F,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAElD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC,CACxE,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CAC/B,CAAC;AAoEF,wBAAgB,uBAAuB,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAInE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAepE;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAQ3E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CA2B5E;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,aAAa,EACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,aAAa,CAqCf"}
@@ -1,139 +0,0 @@
1
- import { DEFAULT_NOSTR_RELAYS } from "./types.js";
2
- export const DEFAULT_NOSTR_ACCOUNT_ID = "default";
3
- function stringSetting(runtime, key) {
4
- const value = runtime.getSetting(key);
5
- if (typeof value === "string" && value.trim())
6
- return value.trim();
7
- return process.env[key];
8
- }
9
- function characterConfig(runtime) {
10
- const settings = runtime.character?.settings;
11
- const raw = settings?.nostr;
12
- return raw && typeof raw === "object" ? raw : {};
13
- }
14
- function parseAccountsJson(runtime) {
15
- const raw = stringSetting(runtime, "NOSTR_ACCOUNTS");
16
- if (!raw)
17
- return {};
18
- try {
19
- const parsed = JSON.parse(raw);
20
- if (Array.isArray(parsed)) {
21
- return Object.fromEntries(parsed
22
- .filter((item) => Boolean(item) && typeof item === "object")
23
- .map((item) => [normalizeNostrAccountId(item.accountId ?? item.id), item]));
24
- }
25
- return parsed && typeof parsed === "object"
26
- ? parsed
27
- : {};
28
- }
29
- catch {
30
- return {};
31
- }
32
- }
33
- function allAccountConfigs(runtime) {
34
- return {
35
- ...(characterConfig(runtime).accounts ?? {}),
36
- ...parseAccountsJson(runtime),
37
- };
38
- }
39
- function accountConfig(runtime, accountId) {
40
- const accounts = allAccountConfigs(runtime);
41
- return accounts[accountId] ?? accounts[normalizeNostrAccountId(accountId)] ?? {};
42
- }
43
- function boolValue(value, fallback = true) {
44
- if (typeof value === "boolean")
45
- return value;
46
- if (typeof value === "string")
47
- return value.trim().toLowerCase() !== "false";
48
- return fallback;
49
- }
50
- function stringList(value) {
51
- if (Array.isArray(value))
52
- return value.map((item) => String(item).trim()).filter(Boolean);
53
- if (typeof value === "string") {
54
- return value
55
- .split(",")
56
- .map((item) => item.trim())
57
- .filter(Boolean);
58
- }
59
- return [];
60
- }
61
- export function normalizeNostrAccountId(accountId) {
62
- if (typeof accountId !== "string")
63
- return DEFAULT_NOSTR_ACCOUNT_ID;
64
- const trimmed = accountId.trim();
65
- return trimmed || DEFAULT_NOSTR_ACCOUNT_ID;
66
- }
67
- export function listNostrAccountIds(runtime) {
68
- const ids = new Set();
69
- const config = characterConfig(runtime);
70
- if (stringSetting(runtime, "NOSTR_PRIVATE_KEY") || config.privateKey) {
71
- ids.add(DEFAULT_NOSTR_ACCOUNT_ID);
72
- }
73
- for (const id of Object.keys(allAccountConfigs(runtime))) {
74
- ids.add(normalizeNostrAccountId(id));
75
- }
76
- return Array.from(ids.size ? ids : new Set([DEFAULT_NOSTR_ACCOUNT_ID])).sort((a, b) => a.localeCompare(b));
77
- }
78
- export function resolveDefaultNostrAccountId(runtime) {
79
- const requested = stringSetting(runtime, "NOSTR_DEFAULT_ACCOUNT_ID") ??
80
- stringSetting(runtime, "NOSTR_ACCOUNT_ID");
81
- if (requested)
82
- return normalizeNostrAccountId(requested);
83
- const ids = listNostrAccountIds(runtime);
84
- return ids.includes(DEFAULT_NOSTR_ACCOUNT_ID) ? DEFAULT_NOSTR_ACCOUNT_ID : ids[0];
85
- }
86
- export function readNostrAccountId(...sources) {
87
- for (const source of sources) {
88
- if (!source || typeof source !== "object")
89
- continue;
90
- const record = source;
91
- const parameters = record.parameters && typeof record.parameters === "object"
92
- ? record.parameters
93
- : {};
94
- const data = record.data && typeof record.data === "object"
95
- ? record.data
96
- : {};
97
- const metadata = record.metadata && typeof record.metadata === "object"
98
- ? record.metadata
99
- : {};
100
- const nostr = data.nostr && typeof data.nostr === "object" ? data.nostr : {};
101
- const value = record.accountId ??
102
- parameters.accountId ??
103
- data.accountId ??
104
- nostr.accountId ??
105
- metadata.accountId;
106
- if (typeof value === "string" && value.trim())
107
- return normalizeNostrAccountId(value);
108
- }
109
- return undefined;
110
- }
111
- export function resolveNostrAccountSettings(runtime, requestedAccountId) {
112
- const accountId = normalizeNostrAccountId(requestedAccountId ?? resolveDefaultNostrAccountId(runtime));
113
- const base = characterConfig(runtime);
114
- const account = accountConfig(runtime, accountId);
115
- const allowEnv = accountId === DEFAULT_NOSTR_ACCOUNT_ID;
116
- const relays = stringList(account.relays ?? base.relays ?? (allowEnv ? stringSetting(runtime, "NOSTR_RELAYS") : undefined));
117
- const allowFrom = stringList(account.allowFrom ??
118
- base.allowFrom ??
119
- (allowEnv ? stringSetting(runtime, "NOSTR_ALLOW_FROM") : undefined));
120
- return {
121
- accountId,
122
- privateKey: account.privateKey ??
123
- base.privateKey ??
124
- (allowEnv ? stringSetting(runtime, "NOSTR_PRIVATE_KEY") : undefined) ??
125
- "",
126
- publicKey: "",
127
- relays: relays.length ? relays : DEFAULT_NOSTR_RELAYS,
128
- dmPolicy: (account.dmPolicy ??
129
- base.dmPolicy ??
130
- (allowEnv ? stringSetting(runtime, "NOSTR_DM_POLICY") : undefined) ??
131
- "pairing"),
132
- allowFrom,
133
- profile: account.profile ?? base.profile,
134
- enabled: boolValue(account.enabled ??
135
- base.enabled ??
136
- (allowEnv ? stringSetting(runtime, "NOSTR_ENABLED") : undefined)),
137
- };
138
- }
139
- //# sourceMappingURL=accounts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/accounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAA0C,MAAM,YAAY,CAAC;AAE1F,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAelD,SAAS,aAAa,CAAC,OAAsB,EAAE,GAAW;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACnE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,OAAsB;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,QAA+C,CAAC;IACpF,MAAM,GAAG,GAAG,QAAQ,EAAE,KAAK,CAAC;IAC5B,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAE,GAA+B,CAAC,CAAC,CAAC,EAAE,CAAC;AAChF,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAsB;IAC/C,MAAM,GAAG,GAAG,aAAa,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CAAC,SAAS;QACd,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CACtE,CAAC;IAEF,OAAO;QACL,SAAS;QACT,UAAU,EACR,OAAO,CAAC,UAAU;YAClB,IAAI,CAAC,UAAU;YACf,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACpE,EAAE;QACJ,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB;QACrD,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ;YACzB,IAAI,CAAC,QAAQ;YACb,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAClE,SAAS,CAAkB;QAC7B,SAAS;QACT,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;QACxC,OAAO,EAAE,SAAS,CAChB,OAAO,CAAC,OAAO;YACb,IAAI,CAAC,OAAO;YACZ,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CACnE;KACF,CAAC;AACJ,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Export all Nostr actions.
3
- *
4
- * Nostr DMs route through MESSAGE. Public notes route through POST.
5
- */
6
- export { publishProfile } from "./publishProfile.js";
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Export all Nostr actions.
3
- *
4
- * Nostr DMs route through MESSAGE. Public notes route through POST.
5
- */
6
- export { publishProfile } from "./publishProfile.js";
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Publish profile action for Nostr plugin.
3
- */
4
- import { type Action } from "@elizaos/core";
5
- export declare const publishProfile: Action;
6
- //# sourceMappingURL=publishProfile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"publishProfile.d.ts","sourceRoot":"","sources":["../../../src/actions/publishProfile.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,MAAM,EAQZ,MAAM,eAAe,CAAC;AAiCvB,eAAO,MAAM,cAAc,EAAE,MAoJ5B,CAAC"}