@openclaw/nostr 2026.5.2 → 2026.5.3-beta.2
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.
- package/dist/api.js +532 -0
- package/dist/channel-DfEqBtUh.js +1466 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/config-schema-DIk4jlBg.js +64 -0
- package/dist/default-relays-DLwdWOTu.js +4 -0
- package/dist/inbound-direct-dm-runtime-22bZWcIW.js +2 -0
- package/dist/index.js +84 -0
- package/dist/runtime-api.js +2 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-plugin-api.js +165 -0
- package/dist/setup-surface-DxAaUTyC.js +336 -0
- package/dist/test-api.js +2 -0
- package/package.json +15 -6
- package/api.ts +0 -10
- package/channel-plugin-api.ts +0 -1
- package/index.ts +0 -97
- package/runtime-api.ts +0 -6
- package/setup-api.ts +0 -1
- package/setup-entry.ts +0 -9
- package/setup-plugin-api.ts +0 -3
- package/src/channel-api.ts +0 -15
- package/src/channel.inbound.test.ts +0 -176
- package/src/channel.outbound.test.ts +0 -128
- package/src/channel.setup.ts +0 -231
- package/src/channel.test.ts +0 -519
- package/src/channel.ts +0 -207
- package/src/config-schema.ts +0 -98
- package/src/default-relays.ts +0 -1
- package/src/gateway.ts +0 -302
- package/src/inbound-direct-dm-runtime.ts +0 -1
- package/src/metrics.ts +0 -458
- package/src/nostr-bus.fuzz.test.ts +0 -360
- package/src/nostr-bus.inbound.test.ts +0 -526
- package/src/nostr-bus.integration.test.ts +0 -472
- package/src/nostr-bus.test.ts +0 -190
- package/src/nostr-bus.ts +0 -789
- package/src/nostr-key-utils.ts +0 -94
- package/src/nostr-profile-core.ts +0 -134
- package/src/nostr-profile-http-runtime.ts +0 -6
- package/src/nostr-profile-http.test.ts +0 -632
- package/src/nostr-profile-http.ts +0 -594
- package/src/nostr-profile-import.test.ts +0 -119
- package/src/nostr-profile-import.ts +0 -262
- package/src/nostr-profile-url-safety.ts +0 -21
- package/src/nostr-profile.fuzz.test.ts +0 -430
- package/src/nostr-profile.test.ts +0 -412
- package/src/nostr-profile.ts +0 -144
- package/src/nostr-state-store.test.ts +0 -237
- package/src/nostr-state-store.ts +0 -223
- package/src/runtime.ts +0 -9
- package/src/seen-tracker.ts +0 -289
- package/src/session-route.ts +0 -25
- package/src/setup-surface.ts +0 -265
- package/src/test-fixtures.ts +0 -45
- package/src/types.ts +0 -117
- package/test/setup.ts +0 -5
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
package/src/seen-tracker.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LRU-based seen event tracker with TTL support.
|
|
3
|
-
* Prevents unbounded memory growth under high load or abuse.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
interface SeenTrackerOptions {
|
|
7
|
-
/** Maximum number of entries to track (default: 100,000) */
|
|
8
|
-
maxEntries?: number;
|
|
9
|
-
/** TTL in milliseconds (default: 1 hour) */
|
|
10
|
-
ttlMs?: number;
|
|
11
|
-
/** Prune interval in milliseconds (default: 10 minutes) */
|
|
12
|
-
pruneIntervalMs?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface SeenTracker {
|
|
16
|
-
/** Check if an ID has been seen (also marks it as seen if not) */
|
|
17
|
-
has: (id: string) => boolean;
|
|
18
|
-
/** Mark an ID as seen */
|
|
19
|
-
add: (id: string) => void;
|
|
20
|
-
/** Check if ID exists without marking */
|
|
21
|
-
peek: (id: string) => boolean;
|
|
22
|
-
/** Delete an ID */
|
|
23
|
-
delete: (id: string) => void;
|
|
24
|
-
/** Clear all entries */
|
|
25
|
-
clear: () => void;
|
|
26
|
-
/** Get current size */
|
|
27
|
-
size: () => number;
|
|
28
|
-
/** Stop the pruning timer */
|
|
29
|
-
stop: () => void;
|
|
30
|
-
/** Pre-seed with IDs (useful for restart recovery) */
|
|
31
|
-
seed: (ids: string[]) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface Entry {
|
|
35
|
-
seenAt: number;
|
|
36
|
-
// For LRU: track order via doubly-linked list
|
|
37
|
-
prev: string | null;
|
|
38
|
-
next: string | null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Create a new seen tracker with LRU eviction and TTL expiration.
|
|
43
|
-
*/
|
|
44
|
-
export function createSeenTracker(options?: SeenTrackerOptions): SeenTracker {
|
|
45
|
-
const maxEntries = options?.maxEntries ?? 100_000;
|
|
46
|
-
const ttlMs = options?.ttlMs ?? 60 * 60 * 1000; // 1 hour
|
|
47
|
-
const pruneIntervalMs = options?.pruneIntervalMs ?? 10 * 60 * 1000; // 10 minutes
|
|
48
|
-
|
|
49
|
-
// Main storage
|
|
50
|
-
const entries = new Map<string, Entry>();
|
|
51
|
-
|
|
52
|
-
// LRU tracking: head = most recent, tail = least recent
|
|
53
|
-
let head: string | null = null;
|
|
54
|
-
let tail: string | null = null;
|
|
55
|
-
|
|
56
|
-
// Move an entry to the front (most recently used)
|
|
57
|
-
function moveToFront(id: string): void {
|
|
58
|
-
const entry = entries.get(id);
|
|
59
|
-
if (!entry) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Already at front
|
|
64
|
-
if (head === id) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Remove from current position
|
|
69
|
-
if (entry.prev) {
|
|
70
|
-
const prevEntry = entries.get(entry.prev);
|
|
71
|
-
if (prevEntry) {
|
|
72
|
-
prevEntry.next = entry.next;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (entry.next) {
|
|
76
|
-
const nextEntry = entries.get(entry.next);
|
|
77
|
-
if (nextEntry) {
|
|
78
|
-
nextEntry.prev = entry.prev;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Update tail if this was the tail
|
|
83
|
-
if (tail === id) {
|
|
84
|
-
tail = entry.prev;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Move to front
|
|
88
|
-
entry.prev = null;
|
|
89
|
-
entry.next = head;
|
|
90
|
-
if (head) {
|
|
91
|
-
const headEntry = entries.get(head);
|
|
92
|
-
if (headEntry) {
|
|
93
|
-
headEntry.prev = id;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
head = id;
|
|
97
|
-
|
|
98
|
-
// If no tail, this is also the tail
|
|
99
|
-
if (!tail) {
|
|
100
|
-
tail = id;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Remove an entry from the linked list
|
|
105
|
-
function removeFromList(id: string): void {
|
|
106
|
-
const entry = entries.get(id);
|
|
107
|
-
if (!entry) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (entry.prev) {
|
|
112
|
-
const prevEntry = entries.get(entry.prev);
|
|
113
|
-
if (prevEntry) {
|
|
114
|
-
prevEntry.next = entry.next;
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
head = entry.next;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (entry.next) {
|
|
121
|
-
const nextEntry = entries.get(entry.next);
|
|
122
|
-
if (nextEntry) {
|
|
123
|
-
nextEntry.prev = entry.prev;
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
tail = entry.prev;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Evict the least recently used entry
|
|
131
|
-
function evictLRU(): void {
|
|
132
|
-
if (!tail) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const idToEvict = tail;
|
|
136
|
-
removeFromList(idToEvict);
|
|
137
|
-
entries.delete(idToEvict);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function insertAtFront(id: string, seenAt: number): void {
|
|
141
|
-
const newEntry: Entry = {
|
|
142
|
-
seenAt,
|
|
143
|
-
prev: null,
|
|
144
|
-
next: head,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
if (head) {
|
|
148
|
-
const headEntry = entries.get(head);
|
|
149
|
-
if (headEntry) {
|
|
150
|
-
headEntry.prev = id;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
entries.set(id, newEntry);
|
|
155
|
-
head = id;
|
|
156
|
-
if (!tail) {
|
|
157
|
-
tail = id;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Prune expired entries
|
|
162
|
-
function pruneExpired(): void {
|
|
163
|
-
const now = Date.now();
|
|
164
|
-
const toDelete: string[] = [];
|
|
165
|
-
|
|
166
|
-
for (const [id, entry] of entries) {
|
|
167
|
-
if (now - entry.seenAt > ttlMs) {
|
|
168
|
-
toDelete.push(id);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
for (const id of toDelete) {
|
|
173
|
-
removeFromList(id);
|
|
174
|
-
entries.delete(id);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Start pruning timer
|
|
179
|
-
let pruneTimer: ReturnType<typeof setInterval> | undefined;
|
|
180
|
-
if (pruneIntervalMs > 0) {
|
|
181
|
-
pruneTimer = setInterval(pruneExpired, pruneIntervalMs);
|
|
182
|
-
// Don't keep process alive just for pruning
|
|
183
|
-
if (pruneTimer.unref) {
|
|
184
|
-
pruneTimer.unref();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function add(id: string): void {
|
|
189
|
-
const now = Date.now();
|
|
190
|
-
|
|
191
|
-
// If already exists, update and move to front
|
|
192
|
-
const existing = entries.get(id);
|
|
193
|
-
if (existing) {
|
|
194
|
-
existing.seenAt = now;
|
|
195
|
-
moveToFront(id);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Evict if at capacity
|
|
200
|
-
while (entries.size >= maxEntries) {
|
|
201
|
-
evictLRU();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
insertAtFront(id, now);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function has(id: string): boolean {
|
|
208
|
-
const entry = entries.get(id);
|
|
209
|
-
if (!entry) {
|
|
210
|
-
add(id);
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Check if expired
|
|
215
|
-
if (Date.now() - entry.seenAt > ttlMs) {
|
|
216
|
-
removeFromList(id);
|
|
217
|
-
entries.delete(id);
|
|
218
|
-
add(id);
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Mark as recently used
|
|
223
|
-
entry.seenAt = Date.now();
|
|
224
|
-
moveToFront(id);
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function peek(id: string): boolean {
|
|
229
|
-
const entry = entries.get(id);
|
|
230
|
-
if (!entry) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Check if expired
|
|
235
|
-
if (Date.now() - entry.seenAt > ttlMs) {
|
|
236
|
-
removeFromList(id);
|
|
237
|
-
entries.delete(id);
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return true;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function deleteEntry(id: string): void {
|
|
245
|
-
if (entries.has(id)) {
|
|
246
|
-
removeFromList(id);
|
|
247
|
-
entries.delete(id);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function clear(): void {
|
|
252
|
-
entries.clear();
|
|
253
|
-
head = null;
|
|
254
|
-
tail = null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function size(): number {
|
|
258
|
-
return entries.size;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function stop(): void {
|
|
262
|
-
if (pruneTimer) {
|
|
263
|
-
clearInterval(pruneTimer);
|
|
264
|
-
pruneTimer = undefined;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function seed(ids: string[]): void {
|
|
269
|
-
const now = Date.now();
|
|
270
|
-
// Seed in reverse order so first IDs end up at front
|
|
271
|
-
for (let i = ids.length - 1; i >= 0; i--) {
|
|
272
|
-
const id = ids[i];
|
|
273
|
-
if (!entries.has(id) && entries.size < maxEntries) {
|
|
274
|
-
insertAtFront(id, now);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
has,
|
|
281
|
-
add,
|
|
282
|
-
peek,
|
|
283
|
-
delete: deleteEntry,
|
|
284
|
-
clear,
|
|
285
|
-
size,
|
|
286
|
-
stop,
|
|
287
|
-
seed,
|
|
288
|
-
};
|
|
289
|
-
}
|
package/src/session-route.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildChannelOutboundSessionRoute,
|
|
3
|
-
stripChannelTargetPrefix,
|
|
4
|
-
type ChannelOutboundSessionRouteParams,
|
|
5
|
-
} from "openclaw/plugin-sdk/core";
|
|
6
|
-
|
|
7
|
-
export function resolveNostrOutboundSessionRoute(params: ChannelOutboundSessionRouteParams) {
|
|
8
|
-
const target = stripChannelTargetPrefix(params.target, "nostr");
|
|
9
|
-
if (!target) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return buildChannelOutboundSessionRoute({
|
|
13
|
-
cfg: params.cfg,
|
|
14
|
-
agentId: params.agentId,
|
|
15
|
-
channel: "nostr",
|
|
16
|
-
accountId: params.accountId,
|
|
17
|
-
peer: {
|
|
18
|
-
kind: "direct",
|
|
19
|
-
id: target,
|
|
20
|
-
},
|
|
21
|
-
chatType: "direct",
|
|
22
|
-
from: `nostr:${target}`,
|
|
23
|
-
to: `nostr:${target}`,
|
|
24
|
-
});
|
|
25
|
-
}
|
package/src/setup-surface.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import type { ChannelSetupAdapter } from "openclaw/plugin-sdk/channel-setup";
|
|
2
|
-
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/routing";
|
|
3
|
-
import {
|
|
4
|
-
hasConfiguredSecretInput,
|
|
5
|
-
normalizeSecretInputString,
|
|
6
|
-
} from "openclaw/plugin-sdk/secret-input";
|
|
7
|
-
import type { ChannelSetupDmPolicy, ChannelSetupWizard, DmPolicy } from "openclaw/plugin-sdk/setup";
|
|
8
|
-
import {
|
|
9
|
-
createStandardChannelSetupStatus,
|
|
10
|
-
createTopLevelChannelDmPolicy,
|
|
11
|
-
createTopLevelChannelParsedAllowFromPrompt,
|
|
12
|
-
formatDocsLink,
|
|
13
|
-
mergeAllowFromEntries,
|
|
14
|
-
parseSetupEntriesWithParser,
|
|
15
|
-
patchTopLevelChannelConfigSection,
|
|
16
|
-
splitSetupEntries,
|
|
17
|
-
} from "openclaw/plugin-sdk/setup";
|
|
18
|
-
import { DEFAULT_RELAYS } from "./default-relays.js";
|
|
19
|
-
import { getPublicKeyFromPrivate, normalizePubkey } from "./nostr-key-utils.js";
|
|
20
|
-
import { resolveDefaultNostrAccountId, resolveNostrAccount } from "./types.js";
|
|
21
|
-
|
|
22
|
-
const channel = "nostr" as const;
|
|
23
|
-
|
|
24
|
-
const NOSTR_SETUP_HELP_LINES = [
|
|
25
|
-
"Use a Nostr private key in nsec or 64-character hex format.",
|
|
26
|
-
"Relay URLs are optional. Leave blank to keep the default relay set.",
|
|
27
|
-
"Env vars supported: NOSTR_PRIVATE_KEY (default account only).",
|
|
28
|
-
`Docs: ${formatDocsLink("/channels/nostr", "channels/nostr")}`,
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
const NOSTR_ALLOW_FROM_HELP_LINES = [
|
|
32
|
-
"Allowlist Nostr DMs by npub or hex pubkey.",
|
|
33
|
-
"Examples:",
|
|
34
|
-
"- npub1...",
|
|
35
|
-
"- nostr:npub1...",
|
|
36
|
-
"- 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
|
37
|
-
"Multiple entries: comma-separated.",
|
|
38
|
-
`Docs: ${formatDocsLink("/channels/nostr", "channels/nostr")}`,
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
function buildNostrSetupPatch(accountId: string, patch: Record<string, unknown>) {
|
|
42
|
-
return {
|
|
43
|
-
...(accountId !== DEFAULT_ACCOUNT_ID ? { defaultAccount: accountId } : {}),
|
|
44
|
-
...patch,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function parseRelayUrls(raw: string): { relays: string[]; error?: string } {
|
|
49
|
-
const entries = splitSetupEntries(raw);
|
|
50
|
-
const relays: string[] = [];
|
|
51
|
-
for (const entry of entries) {
|
|
52
|
-
try {
|
|
53
|
-
const parsed = new URL(entry);
|
|
54
|
-
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
55
|
-
return { relays: [], error: `Relay must use ws:// or wss:// (${entry})` };
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
return { relays: [], error: `Invalid relay URL: ${entry}` };
|
|
59
|
-
}
|
|
60
|
-
relays.push(entry);
|
|
61
|
-
}
|
|
62
|
-
return { relays: [...new Set(relays)] };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function parseNostrAllowFrom(raw: string): { entries: string[]; error?: string } {
|
|
66
|
-
return parseSetupEntriesWithParser(raw, (entry) => {
|
|
67
|
-
const cleaned = entry.replace(/^nostr:/i, "").trim();
|
|
68
|
-
try {
|
|
69
|
-
return { value: normalizePubkey(cleaned) };
|
|
70
|
-
} catch {
|
|
71
|
-
return { error: `Invalid Nostr pubkey: ${entry}` };
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const promptNostrAllowFrom = createTopLevelChannelParsedAllowFromPrompt({
|
|
77
|
-
channel,
|
|
78
|
-
defaultAccountId: resolveDefaultNostrAccountId,
|
|
79
|
-
noteTitle: "Nostr allowlist",
|
|
80
|
-
noteLines: NOSTR_ALLOW_FROM_HELP_LINES,
|
|
81
|
-
message: "Nostr allowFrom",
|
|
82
|
-
placeholder: "npub1..., 0123abcd...",
|
|
83
|
-
parseEntries: parseNostrAllowFrom,
|
|
84
|
-
mergeEntries: ({ existing, parsed }) => mergeAllowFromEntries(existing, parsed),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const nostrDmPolicy: ChannelSetupDmPolicy = createTopLevelChannelDmPolicy({
|
|
88
|
-
label: "Nostr",
|
|
89
|
-
channel,
|
|
90
|
-
policyKey: "channels.nostr.dmPolicy",
|
|
91
|
-
allowFromKey: "channels.nostr.allowFrom",
|
|
92
|
-
getCurrent: (cfg) => (cfg.channels?.nostr?.dmPolicy as DmPolicy | undefined) ?? "pairing",
|
|
93
|
-
promptAllowFrom: promptNostrAllowFrom,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
export const nostrSetupAdapter: ChannelSetupAdapter = {
|
|
97
|
-
resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultNostrAccountId(cfg),
|
|
98
|
-
applyAccountName: ({ cfg, accountId, name }) =>
|
|
99
|
-
patchTopLevelChannelConfigSection({
|
|
100
|
-
cfg,
|
|
101
|
-
channel,
|
|
102
|
-
patch: buildNostrSetupPatch(accountId, name?.trim() ? { name: name.trim() } : {}),
|
|
103
|
-
}),
|
|
104
|
-
validateInput: ({ input }) => {
|
|
105
|
-
const typedInput = input as {
|
|
106
|
-
useEnv?: boolean;
|
|
107
|
-
privateKey?: string;
|
|
108
|
-
relayUrls?: string;
|
|
109
|
-
};
|
|
110
|
-
if (!typedInput.useEnv) {
|
|
111
|
-
const privateKey = typedInput.privateKey?.trim();
|
|
112
|
-
if (!privateKey) {
|
|
113
|
-
return "Nostr requires --private-key or --use-env.";
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
getPublicKeyFromPrivate(privateKey);
|
|
117
|
-
} catch {
|
|
118
|
-
return "Nostr private key must be valid nsec or 64-character hex.";
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (typedInput.relayUrls?.trim()) {
|
|
122
|
-
return parseRelayUrls(typedInput.relayUrls).error ?? null;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
},
|
|
126
|
-
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
127
|
-
const typedInput = input as {
|
|
128
|
-
useEnv?: boolean;
|
|
129
|
-
privateKey?: string;
|
|
130
|
-
relayUrls?: string;
|
|
131
|
-
};
|
|
132
|
-
const relayResult = typedInput.relayUrls?.trim()
|
|
133
|
-
? parseRelayUrls(typedInput.relayUrls)
|
|
134
|
-
: { relays: [] };
|
|
135
|
-
return patchTopLevelChannelConfigSection({
|
|
136
|
-
cfg,
|
|
137
|
-
channel,
|
|
138
|
-
enabled: true,
|
|
139
|
-
clearFields: typedInput.useEnv ? ["privateKey"] : undefined,
|
|
140
|
-
patch: buildNostrSetupPatch(accountId, {
|
|
141
|
-
...(typedInput.useEnv ? {} : { privateKey: typedInput.privateKey?.trim() }),
|
|
142
|
-
...(relayResult.relays.length > 0 ? { relays: relayResult.relays } : {}),
|
|
143
|
-
}),
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export const nostrSetupWizard: ChannelSetupWizard = {
|
|
149
|
-
channel,
|
|
150
|
-
resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId }) =>
|
|
151
|
-
accountOverride?.trim() || defaultAccountId,
|
|
152
|
-
resolveShouldPromptAccountIds: () => false,
|
|
153
|
-
status: createStandardChannelSetupStatus({
|
|
154
|
-
channelLabel: "Nostr",
|
|
155
|
-
configuredLabel: "configured",
|
|
156
|
-
unconfiguredLabel: "needs private key",
|
|
157
|
-
configuredHint: "configured",
|
|
158
|
-
unconfiguredHint: "needs private key",
|
|
159
|
-
configuredScore: 1,
|
|
160
|
-
unconfiguredScore: 0,
|
|
161
|
-
includeStatusLine: true,
|
|
162
|
-
resolveConfigured: ({ cfg }) => resolveNostrAccount({ cfg }).configured,
|
|
163
|
-
resolveExtraStatusLines: ({ cfg }) => {
|
|
164
|
-
const account = resolveNostrAccount({ cfg });
|
|
165
|
-
return [`Relays: ${account.relays.length || DEFAULT_RELAYS.length}`];
|
|
166
|
-
},
|
|
167
|
-
}),
|
|
168
|
-
introNote: {
|
|
169
|
-
title: "Nostr setup",
|
|
170
|
-
lines: NOSTR_SETUP_HELP_LINES,
|
|
171
|
-
},
|
|
172
|
-
envShortcut: {
|
|
173
|
-
prompt: "NOSTR_PRIVATE_KEY detected. Use env var?",
|
|
174
|
-
preferredEnvVar: "NOSTR_PRIVATE_KEY",
|
|
175
|
-
isAvailable: ({ cfg, accountId }) =>
|
|
176
|
-
accountId === DEFAULT_ACCOUNT_ID &&
|
|
177
|
-
Boolean(process.env.NOSTR_PRIVATE_KEY?.trim()) &&
|
|
178
|
-
!hasConfiguredSecretInput(resolveNostrAccount({ cfg, accountId }).config.privateKey),
|
|
179
|
-
apply: async ({ cfg, accountId }) =>
|
|
180
|
-
patchTopLevelChannelConfigSection({
|
|
181
|
-
cfg,
|
|
182
|
-
channel,
|
|
183
|
-
enabled: true,
|
|
184
|
-
clearFields: ["privateKey"],
|
|
185
|
-
patch: buildNostrSetupPatch(accountId, {}),
|
|
186
|
-
}),
|
|
187
|
-
},
|
|
188
|
-
credentials: [
|
|
189
|
-
{
|
|
190
|
-
inputKey: "privateKey",
|
|
191
|
-
providerHint: channel,
|
|
192
|
-
credentialLabel: "private key",
|
|
193
|
-
preferredEnvVar: "NOSTR_PRIVATE_KEY",
|
|
194
|
-
helpTitle: "Nostr private key",
|
|
195
|
-
helpLines: NOSTR_SETUP_HELP_LINES,
|
|
196
|
-
envPrompt: "NOSTR_PRIVATE_KEY detected. Use env var?",
|
|
197
|
-
keepPrompt: "Nostr private key already configured. Keep it?",
|
|
198
|
-
inputPrompt: "Nostr private key (nsec... or hex)",
|
|
199
|
-
allowEnv: ({ accountId }) => accountId === DEFAULT_ACCOUNT_ID,
|
|
200
|
-
inspect: ({ cfg, accountId }) => {
|
|
201
|
-
const account = resolveNostrAccount({ cfg, accountId });
|
|
202
|
-
return {
|
|
203
|
-
accountConfigured: account.configured,
|
|
204
|
-
hasConfiguredValue: hasConfiguredSecretInput(account.config.privateKey),
|
|
205
|
-
resolvedValue: normalizeSecretInputString(account.config.privateKey),
|
|
206
|
-
envValue: process.env.NOSTR_PRIVATE_KEY?.trim(),
|
|
207
|
-
};
|
|
208
|
-
},
|
|
209
|
-
applyUseEnv: async ({ cfg, accountId }) =>
|
|
210
|
-
patchTopLevelChannelConfigSection({
|
|
211
|
-
cfg,
|
|
212
|
-
channel,
|
|
213
|
-
enabled: true,
|
|
214
|
-
clearFields: ["privateKey"],
|
|
215
|
-
patch: buildNostrSetupPatch(accountId, {}),
|
|
216
|
-
}),
|
|
217
|
-
applySet: async ({ cfg, accountId, resolvedValue }) =>
|
|
218
|
-
patchTopLevelChannelConfigSection({
|
|
219
|
-
cfg,
|
|
220
|
-
channel,
|
|
221
|
-
enabled: true,
|
|
222
|
-
patch: buildNostrSetupPatch(accountId, { privateKey: resolvedValue }),
|
|
223
|
-
}),
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
textInputs: [
|
|
227
|
-
{
|
|
228
|
-
inputKey: "relayUrls",
|
|
229
|
-
message: "Relay URLs (comma-separated, optional)",
|
|
230
|
-
placeholder: DEFAULT_RELAYS.join(", "),
|
|
231
|
-
required: false,
|
|
232
|
-
applyEmptyValue: true,
|
|
233
|
-
helpTitle: "Nostr relays",
|
|
234
|
-
helpLines: ["Use ws:// or wss:// relay URLs.", "Leave blank to keep the default relay set."],
|
|
235
|
-
currentValue: ({ cfg, accountId }) => {
|
|
236
|
-
const account = resolveNostrAccount({ cfg, accountId });
|
|
237
|
-
const configuredRelays = cfg.channels?.nostr?.relays as string[] | undefined;
|
|
238
|
-
const relays = configuredRelays && configuredRelays.length > 0 ? account.relays : [];
|
|
239
|
-
return relays.join(", ");
|
|
240
|
-
},
|
|
241
|
-
keepPrompt: (value) => `Relay URLs set (${value}). Keep them?`,
|
|
242
|
-
validate: ({ value }) => parseRelayUrls(value).error,
|
|
243
|
-
applySet: async ({ cfg, accountId, value }) => {
|
|
244
|
-
const relayResult = parseRelayUrls(value);
|
|
245
|
-
return patchTopLevelChannelConfigSection({
|
|
246
|
-
cfg,
|
|
247
|
-
channel,
|
|
248
|
-
enabled: true,
|
|
249
|
-
clearFields: relayResult.relays.length > 0 ? undefined : ["relays"],
|
|
250
|
-
patch: buildNostrSetupPatch(
|
|
251
|
-
accountId,
|
|
252
|
-
relayResult.relays.length > 0 ? { relays: relayResult.relays } : {},
|
|
253
|
-
),
|
|
254
|
-
});
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
dmPolicy: nostrDmPolicy,
|
|
259
|
-
disable: (cfg) =>
|
|
260
|
-
patchTopLevelChannelConfigSection({
|
|
261
|
-
cfg,
|
|
262
|
-
channel,
|
|
263
|
-
patch: { enabled: false },
|
|
264
|
-
}),
|
|
265
|
-
};
|
package/src/test-fixtures.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ResolvedNostrAccount } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export const TEST_HEX_PRIVATE_KEY =
|
|
4
|
-
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
|
5
|
-
|
|
6
|
-
export const TEST_HEX_PUBLIC_KEY =
|
|
7
|
-
"abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789";
|
|
8
|
-
|
|
9
|
-
export const TEST_NSEC = "nsec1qypqxpq9qtpqscx7peytzfwtdjmcv0mrz5rjpej8vjppfkqfqy8skqfv3l";
|
|
10
|
-
|
|
11
|
-
export const TEST_RELAY_URL = "wss://relay.example.com";
|
|
12
|
-
export const TEST_SETUP_RELAY_URLS = ["wss://relay.damus.io", "wss://relay.primal.net"];
|
|
13
|
-
export const TEST_RESOLVED_PRIVATE_KEY = "resolved-nostr-private-key";
|
|
14
|
-
|
|
15
|
-
export const TEST_HEX_PRIVATE_KEY_BYTES = new Uint8Array(
|
|
16
|
-
TEST_HEX_PRIVATE_KEY.match(/.{2}/g)!.map((byte) => Number.parseInt(byte, 16)),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export function createConfiguredNostrCfg(overrides: Record<string, unknown> = {}): {
|
|
20
|
-
channels: { nostr: Record<string, unknown> };
|
|
21
|
-
} {
|
|
22
|
-
return {
|
|
23
|
-
channels: {
|
|
24
|
-
nostr: {
|
|
25
|
-
privateKey: TEST_HEX_PRIVATE_KEY,
|
|
26
|
-
...overrides,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function buildResolvedNostrAccount(
|
|
33
|
-
overrides: Partial<ResolvedNostrAccount> = {},
|
|
34
|
-
): ResolvedNostrAccount {
|
|
35
|
-
return {
|
|
36
|
-
accountId: "default",
|
|
37
|
-
enabled: true,
|
|
38
|
-
configured: true,
|
|
39
|
-
privateKey: TEST_HEX_PRIVATE_KEY,
|
|
40
|
-
publicKey: TEST_HEX_PUBLIC_KEY,
|
|
41
|
-
relays: [TEST_RELAY_URL],
|
|
42
|
-
config: {},
|
|
43
|
-
...overrides,
|
|
44
|
-
};
|
|
45
|
-
}
|