@kehto/paja 0.3.1 → 0.3.4

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.
@@ -1,4 +1,4 @@
1
- // ../acl/dist/chunk-6GH7LZSY.js
1
+ // ../acl/dist/chunk-ZI6GTKYN.js
2
2
  var ALL_CAPABILITIES = [
3
3
  // v1.1 kept:
4
4
  "relay:read",
@@ -34,7 +34,11 @@ var ALL_CAPABILITIES = [
34
34
  // handlers introspection (and receipt of shell pushes); write = invoke (the
35
35
  // focus-stealing cross-napplet dispatch op).
36
36
  "intent:read",
37
- "intent:write"
37
+ "intent:write",
38
+ // NAP-DM — runtime-mediated direct messages: read = status/conversations/
39
+ // messages/subscribe/unsubscribe and receive pushes; write = send.
40
+ "dm:read",
41
+ "dm:write"
38
42
  ];
39
43
 
40
44
  // ../acl/dist/index.js
@@ -224,7 +228,7 @@ function configMap(action) {
224
228
  return { senderCap: "config:read", recipientCap: null };
225
229
  }
226
230
  function resourceMap(action) {
227
- if (action === "bytes.result" || action === "bytes.error" || action === "bytesMany.result" || action === "bytesMany.error") {
231
+ if (action === "info.result" || action === "info.error" || action === "bytes.result" || action === "bytes.error" || action === "bytesMany.result" || action === "bytesMany.error") {
228
232
  return { senderCap: null, recipientCap: "resource:fetch" };
229
233
  }
230
234
  return { senderCap: "resource:fetch", recipientCap: null };
@@ -255,6 +259,13 @@ function intentMap(action) {
255
259
  if (action === "invoke") return { senderCap: "intent:write", recipientCap: null };
256
260
  return { senderCap: "intent:read", recipientCap: null };
257
261
  }
262
+ function dmMap(action) {
263
+ if (action === "message" || action.endsWith(".result") || action.endsWith(".error")) {
264
+ return { senderCap: null, recipientCap: "dm:read" };
265
+ }
266
+ if (action === "send") return { senderCap: "dm:write", recipientCap: null };
267
+ return { senderCap: "dm:read", recipientCap: null };
268
+ }
258
269
  function themeMap(action) {
259
270
  if (action === "changed") return { senderCap: null, recipientCap: "theme:read" };
260
271
  return { senderCap: "theme:read", recipientCap: null };
@@ -298,6 +309,9 @@ function resolveCapabilitiesNap(msg) {
298
309
  case "intent":
299
310
  return intentMap(action);
300
311
  // NAP-INTENT archetype intent dispatch
312
+ case "dm":
313
+ return dmMap(action);
314
+ // NAP-DM runtime-mediated direct messages
301
315
  default:
302
316
  return { senderCap: null, recipientCap: null };
303
317
  }
@@ -593,7 +607,7 @@ function deserialize2(json) {
593
607
  return defaultConfig();
594
608
  }
595
609
 
596
- // ../../node_modules/.pnpm/@napplet+core@0.21.0/node_modules/@napplet/core/dist/index.js
610
+ // ../../node_modules/.pnpm/@napplet+core@0.23.0/node_modules/@napplet/core/dist/index.js
597
611
  function createDispatch() {
598
612
  const handlers = /* @__PURE__ */ new Map();
599
613
  function registerNap2(domain, handler) {
@@ -734,6 +748,8 @@ var CAP_OUTBOX_WRITE2 = 1 << 19;
734
748
  var CAP_UPLOAD_WRITE2 = 1 << 20;
735
749
  var CAP_INTENT_READ2 = 1 << 21;
736
750
  var CAP_INTENT_WRITE2 = 1 << 22;
751
+ var CAP_DM_READ2 = 1 << 23;
752
+ var CAP_DM_WRITE2 = 1 << 24;
737
753
  var CAP_MAP = {
738
754
  "relay:read": CAP_RELAY_READ,
739
755
  "relay:write": CAP_RELAY_WRITE,
@@ -756,7 +772,9 @@ var CAP_MAP = {
756
772
  "outbox:write": CAP_OUTBOX_WRITE2,
757
773
  "upload:write": CAP_UPLOAD_WRITE2,
758
774
  "intent:read": CAP_INTENT_READ2,
759
- "intent:write": CAP_INTENT_WRITE2
775
+ "intent:write": CAP_INTENT_WRITE2,
776
+ "dm:read": CAP_DM_READ2,
777
+ "dm:write": CAP_DM_WRITE2
760
778
  };
761
779
  var RUNTIME_CAP_ALL = Object.values(CAP_MAP).reduce((bits, bit) => bits | bit, 0);
762
780
  function capToBit(cap) {
@@ -1299,13 +1317,128 @@ function publishSignedEncrypted(context, windowId, id, signed, replyPe) {
1299
1317
  }
1300
1318
  }
1301
1319
  function handleRelayQuery(context, windowId, m) {
1320
+ const { hooks, serviceRegistry, eventBuffer } = context;
1302
1321
  const id = m.id ?? "";
1303
1322
  const filters = m.filters ?? [];
1304
- let count = 0;
1305
- for (const event of context.eventBuffer.getBufferedEvents()) {
1306
- if (matchesAnyFilter(event, filters)) count++;
1323
+ const seenIds = /* @__PURE__ */ new Set();
1324
+ const events = [];
1325
+ for (const event of eventBuffer.getBufferedEvents()) {
1326
+ if (matchesAnyFilter(event, filters) && !seenIds.has(event.id)) {
1327
+ seenIds.add(event.id);
1328
+ events.push(event);
1329
+ }
1330
+ }
1331
+ let settled = false;
1332
+ let fallbackTimer;
1333
+ function settle6() {
1334
+ if (settled) return;
1335
+ settled = true;
1336
+ clearTimeout(fallbackTimer);
1337
+ hooks.sendToNapplet(windowId, { type: "relay.query.result", id, events });
1338
+ }
1339
+ if (isShellKindQuery(filters)) {
1340
+ settle6();
1341
+ return;
1342
+ }
1343
+ const relayService = relayServiceFrom(context);
1344
+ const cacheService = !serviceRegistry["relay"] ? serviceRegistry["cache"] : void 0;
1345
+ if (relayService) {
1346
+ let onBackendEose2 = function() {
1347
+ openBackends--;
1348
+ if (openBackends <= 0) {
1349
+ const closeMsg = { type: "relay.close", id, subId };
1350
+ svc.handleMessage(windowId, closeMsg, () => {
1351
+ });
1352
+ if (cacheService) {
1353
+ cacheService.handleMessage(windowId, closeMsg, () => {
1354
+ });
1355
+ }
1356
+ settle6();
1357
+ }
1358
+ }, makeCollector2 = function() {
1359
+ return function collector(resp) {
1360
+ const r = resp;
1361
+ if (r.type === "relay.event" && r.event && !seenIds.has(r.event.id)) {
1362
+ seenIds.add(r.event.id);
1363
+ events.push(r.event);
1364
+ } else if (r.type === "relay.eose") {
1365
+ onBackendEose2();
1366
+ }
1367
+ };
1368
+ };
1369
+ var onBackendEose = onBackendEose2, makeCollector = makeCollector2;
1370
+ const svc = relayService;
1371
+ const subId = "__query__:" + id;
1372
+ const subscribeMsg = {
1373
+ type: "relay.subscribe",
1374
+ id,
1375
+ subId,
1376
+ filters
1377
+ };
1378
+ if (typeof m.relay === "string" && m.relay.length > 0) {
1379
+ subscribeMsg.relay = m.relay;
1380
+ }
1381
+ let openBackends = cacheService ? 2 : 1;
1382
+ fallbackTimer = setTimeout(() => {
1383
+ const closeMsg = { type: "relay.close", id, subId };
1384
+ svc.handleMessage(windowId, closeMsg, () => {
1385
+ });
1386
+ if (cacheService) {
1387
+ cacheService.handleMessage(windowId, closeMsg, () => {
1388
+ });
1389
+ }
1390
+ settle6();
1391
+ }, 15e3);
1392
+ svc.handleMessage(windowId, subscribeMsg, makeCollector2());
1393
+ if (cacheService) {
1394
+ cacheService.handleMessage(windowId, subscribeMsg, makeCollector2());
1395
+ }
1396
+ return;
1397
+ }
1398
+ const cache2 = hooks.cache;
1399
+ const pool = hooks.relayPool;
1400
+ if (cache2?.isAvailable()) {
1401
+ cache2.query(filters).then((cachedEvents) => {
1402
+ for (const event of cachedEvents) {
1403
+ if (!seenIds.has(event.id)) {
1404
+ seenIds.add(event.id);
1405
+ events.push(event);
1406
+ }
1407
+ }
1408
+ }).catch(() => {
1409
+ });
1410
+ }
1411
+ if (!pool?.isAvailable()) {
1412
+ settle6();
1413
+ return;
1307
1414
  }
1308
- context.hooks.sendToNapplet(windowId, { type: "relay.query.result", id, count });
1415
+ const relayHint = typeof m.relay === "string" && m.relay.length > 0 ? m.relay : void 0;
1416
+ const relayUrls = relayHint ? [relayHint] : pool.selectRelayTier(filters);
1417
+ let poolSubscription;
1418
+ fallbackTimer = setTimeout(() => {
1419
+ poolSubscription?.unsubscribe();
1420
+ settle6();
1421
+ }, 15e3);
1422
+ poolSubscription = pool.subscribe(filters, (item) => {
1423
+ if (item === "EOSE") {
1424
+ clearTimeout(fallbackTimer);
1425
+ poolSubscription?.unsubscribe();
1426
+ settle6();
1427
+ return;
1428
+ }
1429
+ const event = item;
1430
+ if (!seenIds.has(event.id)) {
1431
+ seenIds.add(event.id);
1432
+ events.push(event);
1433
+ }
1434
+ if (cache2?.isAvailable()) {
1435
+ try {
1436
+ cache2.store(event);
1437
+ } catch {
1438
+ return;
1439
+ }
1440
+ }
1441
+ }, relayUrls);
1309
1442
  }
1310
1443
  function createIdentityHandler(context) {
1311
1444
  return function handleIdentityMessage(windowId, msg) {
@@ -1710,7 +1843,8 @@ function createRuntimeDomainHandlers(context) {
1710
1843
  lists: (windowId, msg) => handleServiceOnlyMessage(context, "lists", windowId, msg),
1711
1844
  serial: (windowId, msg) => handleServiceOnlyMessage(context, "serial", windowId, msg),
1712
1845
  ble: (windowId, msg) => handleServiceOnlyMessage(context, "ble", windowId, msg),
1713
- webrtc: (windowId, msg) => handleServiceOnlyMessage(context, "webrtc", windowId, msg)
1846
+ webrtc: (windowId, msg) => handleServiceOnlyMessage(context, "webrtc", windowId, msg),
1847
+ dm: (windowId, msg) => handleServiceOnlyMessage(context, "dm", windowId, msg)
1714
1848
  };
1715
1849
  }
1716
1850
  function handleStorageMessage(context, windowId, msg) {
@@ -1857,6 +1991,7 @@ function createNapEnvelopeDispatcher(handlers) {
1857
1991
  napDispatch.registerNap("serial", adapt(handlers.serial));
1858
1992
  napDispatch.registerNap("ble", adapt(handlers.ble));
1859
1993
  napDispatch.registerNap("webrtc", adapt(handlers.webrtc));
1994
+ napDispatch.registerNap("dm", adapt(handlers.dm));
1860
1995
  return (windowId, envelope) => {
1861
1996
  currentWindowId = windowId;
1862
1997
  try {
@@ -2426,6 +2561,7 @@ function adaptHooks(shellHooks, deps) {
2426
2561
  };
2427
2562
  }
2428
2563
  var registry = /* @__PURE__ */ new Map();
2564
+ var nextRegistrationId = 0;
2429
2565
  var originRegistry = {
2430
2566
  /**
2431
2567
  * Register a window reference with a windowId and optional identity metadata.
@@ -2435,10 +2571,16 @@ var originRegistry = {
2435
2571
  * @param identity - Optional NIP-5D identity metadata (dTag and aggregateHash)
2436
2572
  */
2437
2573
  register(win, windowId, identity) {
2574
+ for (const [registeredWin, entry] of registry.entries()) {
2575
+ if (registeredWin === win || entry.windowId === windowId) {
2576
+ registry.delete(registeredWin);
2577
+ }
2578
+ }
2438
2579
  registry.set(win, {
2439
2580
  windowId,
2440
2581
  dTag: identity?.dTag,
2441
- aggregateHash: identity?.aggregateHash
2582
+ aggregateHash: identity?.aggregateHash,
2583
+ registrationId: ++nextRegistrationId
2442
2584
  });
2443
2585
  },
2444
2586
  /**
@@ -2493,6 +2635,15 @@ var originRegistry = {
2493
2635
  if (!entry?.dTag || !entry?.aggregateHash) return void 0;
2494
2636
  return { dTag: entry.dTag, aggregateHash: entry.aggregateHash };
2495
2637
  },
2638
+ /**
2639
+ * Look up the monotonically increasing registration id for a Window.
2640
+ *
2641
+ * @param win - The Window reference to look up
2642
+ * @returns The registration id, or undefined if the Window is not registered
2643
+ */
2644
+ getRegistrationId(win) {
2645
+ return registry.get(win)?.registrationId;
2646
+ },
2496
2647
  /** Clear all registrations. */
2497
2648
  clear() {
2498
2649
  registry.clear();
@@ -3100,6 +3251,7 @@ function buildShellCapabilities(hooks) {
3100
3251
  if (hooks.serial?.isAvailable()) domains.push("serial");
3101
3252
  if (hooks.ble?.isAvailable()) domains.push("ble");
3102
3253
  if (hooks.webrtc?.isAvailable()) domains.push("webrtc");
3254
+ if (hooks.dm) domains.push("dm");
3103
3255
  const sandbox = [];
3104
3256
  domains.push(...sandbox);
3105
3257
  const protocols = {};
@@ -3116,6 +3268,7 @@ function buildShellCapabilities(hooks) {
3116
3268
  if (hooks.serial?.isAvailable()) naps.push("serial");
3117
3269
  if (hooks.ble?.isAvailable()) naps.push("ble");
3118
3270
  if (hooks.webrtc?.isAvailable()) naps.push("webrtc");
3271
+ if (hooks.dm) naps.push("dm");
3119
3272
  return applyCapabilityOverrides(
3120
3273
  { domains, protocols, naps, sandbox },
3121
3274
  hooks.capabilities?.disabledDomains ?? []
@@ -3135,20 +3288,29 @@ function applyCapabilityOverrides(capabilities, disabledDomains) {
3135
3288
  sandbox: capabilities.sandbox
3136
3289
  };
3137
3290
  }
3138
- var initSent = /* @__PURE__ */ new Set();
3291
+ var initSent = /* @__PURE__ */ new WeakMap();
3139
3292
  function handleShellReady({
3140
3293
  hooks,
3141
3294
  origin,
3142
3295
  runtime,
3296
+ sourceRegistrationId,
3297
+ sourceWindow,
3143
3298
  windowId
3144
3299
  }) {
3145
- registerNip5dSessionIfNeeded({ hooks, origin, runtime, windowId });
3146
- if (initSent.has(windowId)) {
3300
+ registerNip5dSessionIfNeeded({
3301
+ hooks,
3302
+ origin,
3303
+ runtime,
3304
+ sourceRegistrationId,
3305
+ sourceWindow,
3306
+ windowId
3307
+ });
3308
+ if (initSent.get(sourceWindow) === sourceRegistrationId) {
3147
3309
  return;
3148
3310
  }
3149
3311
  const capabilities = buildShellCapabilities(hooks);
3150
- postShellInit(windowId, capabilities, Object.keys(hooks.services ?? {}));
3151
- initSent.add(windowId);
3312
+ postShellInit(sourceWindow, capabilities, Object.keys(hooks.services ?? {}));
3313
+ initSent.set(sourceWindow, sourceRegistrationId);
3152
3314
  }
3153
3315
  function registerNip5dSessionIfNeeded({
3154
3316
  hooks,
@@ -3197,14 +3359,13 @@ function resolveNip5dIdentity(hooks, windowId) {
3197
3359
  aggregateHash: originIdentity.aggregateHash
3198
3360
  };
3199
3361
  }
3200
- function postShellInit(windowId, capabilities, services) {
3362
+ function postShellInit(win, capabilities, services) {
3201
3363
  const initMsg = {
3202
3364
  type: "shell.init",
3203
3365
  capabilities,
3204
3366
  services
3205
3367
  };
3206
- const win = originRegistry.getIframeWindow(windowId);
3207
- if (win) win.postMessage(initMsg, "*");
3368
+ win.postMessage(initMsg, "*");
3208
3369
  }
3209
3370
  function reportUnrouted(hooks, event, reason) {
3210
3371
  if (!hooks.onUnroutedMessage) return;
@@ -3264,7 +3425,14 @@ function createShellBridge(hooks) {
3264
3425
  const msg = event.data;
3265
3426
  if (typeof msg !== "object" || msg === null || typeof msg.type !== "string") return;
3266
3427
  if (msg.type === "shell.ready") {
3267
- handleShellReady({ hooks, origin: event.origin, runtime, windowId });
3428
+ handleShellReady({
3429
+ hooks,
3430
+ origin: event.origin,
3431
+ runtime,
3432
+ sourceRegistrationId: originRegistry.getRegistrationId(sourceWindow) ?? 0,
3433
+ sourceWindow,
3434
+ windowId
3435
+ });
3268
3436
  return;
3269
3437
  }
3270
3438
  runtime.handleMessage(windowId, msg);
@@ -3946,10 +4114,10 @@ function createNotificationService(options) {
3946
4114
  };
3947
4115
  }
3948
4116
  var IDENTITY_SERVICE_VERSION = "1.0.0";
3949
- function sendProviderError(send, result, fallback, err) {
4117
+ function sendProviderError(send, result, fallback, err2) {
3950
4118
  send({
3951
4119
  ...result,
3952
- error: err?.message ?? fallback
4120
+ error: err2?.message ?? fallback
3953
4121
  });
3954
4122
  }
3955
4123
  async function getCurrentPubkey(options) {
@@ -3966,13 +4134,13 @@ function sendOptionalProviderResult(options, send, fallbackResult, errorFallback
3966
4134
  send(fallbackResult);
3967
4135
  return;
3968
4136
  }
3969
- Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result) => send(result)).catch((err) => sendProviderError(send, fallbackResult, errorFallback, err));
4137
+ Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result) => send(result)).catch((err2) => sendProviderError(send, fallbackResult, errorFallback, err2));
3970
4138
  }
3971
4139
  function sendIdentityError(send, id, typeBase, error) {
3972
4140
  send({ type: `${typeBase}.error`, id, error });
3973
4141
  }
3974
- function sendSignerError(send, id, typeBase, fallback, err) {
3975
- sendIdentityError(send, id, typeBase, err?.message ?? fallback);
4142
+ function sendSignerError(send, id, typeBase, fallback, err2) {
4143
+ sendIdentityError(send, id, typeBase, err2?.message ?? fallback);
3976
4144
  }
3977
4145
  function handleGetPublicKey(options, id, send) {
3978
4146
  const signer = options.getSigner();
@@ -3992,7 +4160,7 @@ function handleGetPublicKey(options, id, send) {
3992
4160
  pubkey: pubkey ?? ""
3993
4161
  };
3994
4162
  send(result);
3995
- }).catch((err) => sendSignerError(send, id, "identity.getPublicKey", "getPublicKey failed", err));
4163
+ }).catch((err2) => sendSignerError(send, id, "identity.getPublicKey", "getPublicKey failed", err2));
3996
4164
  }
3997
4165
  function handleGetRelays(options, id, send) {
3998
4166
  const signer = options.getSigner();
@@ -4007,7 +4175,7 @@ function handleGetRelays(options, id, send) {
4007
4175
  relays
4008
4176
  };
4009
4177
  send(result);
4010
- }).catch((err) => sendSignerError(send, id, "identity.getRelays", "getRelays failed", err));
4178
+ }).catch((err2) => sendSignerError(send, id, "identity.getRelays", "getRelays failed", err2));
4011
4179
  }
4012
4180
  function handleReadProvider(options, id, message, send) {
4013
4181
  switch (message.type) {
@@ -4166,7 +4334,7 @@ function createRelayPoolService(options) {
4166
4334
  return;
4167
4335
  }
4168
4336
  const relayHint = typeof relayMessage.relay === "string" && relayMessage.relay.length > 0 ? relayMessage.relay : void 0;
4169
- const relayUrls = relayHint ? [relayHint] : options.selectRelayTier(filters);
4337
+ const relayUrls2 = relayHint ? [relayHint] : options.selectRelayTier(filters);
4170
4338
  let eoseSent = false;
4171
4339
  const eoseTimer = setTimeout(() => {
4172
4340
  if (!eoseSent) {
@@ -4184,7 +4352,7 @@ function createRelayPoolService(options) {
4184
4352
  return;
4185
4353
  }
4186
4354
  send({ type: "relay.event", subId, event: item });
4187
- }, relayUrls);
4355
+ }, relayUrls2);
4188
4356
  tracked.set(subKey, { handle, eoseTimer });
4189
4357
  return;
4190
4358
  }
@@ -4330,12 +4498,12 @@ function createKeysService(options = {}) {
4330
4498
  unsubscribeHandles.set(m.action.id, unsubscribe);
4331
4499
  if (!bridgeWindowActions.has(windowId)) bridgeWindowActions.set(windowId, /* @__PURE__ */ new Set());
4332
4500
  bridgeWindowActions.get(windowId).add(m.action.id);
4333
- } catch (err) {
4501
+ } catch (err2) {
4334
4502
  const id = m.id ?? "";
4335
4503
  send({
4336
4504
  type: "keys.registerAction.error",
4337
4505
  id,
4338
- error: `bridge subscribe failed: ${err.message}`
4506
+ error: `bridge subscribe failed: ${err2.message}`
4339
4507
  });
4340
4508
  return;
4341
4509
  }
@@ -4477,12 +4645,12 @@ function createKeysService(options = {}) {
4477
4645
  });
4478
4646
  if (!windowActions.has(windowId)) windowActions.set(windowId, /* @__PURE__ */ new Set());
4479
4647
  windowActions.get(windowId).add(m.action.id);
4480
- } catch (err) {
4648
+ } catch (err2) {
4481
4649
  const id = m.id ?? "";
4482
4650
  send({
4483
4651
  type: "keys.registerAction.error",
4484
4652
  id,
4485
- error: `invalid chord: ${err.message}`
4653
+ error: `invalid chord: ${err2.message}`
4486
4654
  });
4487
4655
  return;
4488
4656
  }
@@ -5150,6 +5318,9 @@ function arrayBufferToBase64(buf) {
5150
5318
  }
5151
5319
  return btoa(binary);
5152
5320
  }
5321
+ var DEFAULT_RESOURCE_INFO = {
5322
+ schemes: [{ scheme: "https", enabled: true }]
5323
+ };
5153
5324
  function assertResourceOptions(options) {
5154
5325
  if (typeof options?.fetch !== "function" || typeof options?.isOriginGranted !== "function" || typeof options?.getConnectGrants !== "function" || typeof options?.resolveIdentity !== "function") {
5155
5326
  throw new Error(
@@ -5221,6 +5392,35 @@ function requestIdFromMessage(message) {
5221
5392
  if (typeof message.requestId === "string" && message.requestId.length > 0) return message.requestId;
5222
5393
  return null;
5223
5394
  }
5395
+ function normalizeResourceInfo(info) {
5396
+ return {
5397
+ schemes: Array.isArray(info.schemes) ? info.schemes.filter((scheme) => typeof scheme?.scheme === "string").map((scheme) => ({ scheme: scheme.scheme, enabled: scheme.enabled !== false })) : [],
5398
+ ...typeof info.maxBytes === "number" ? { maxBytes: info.maxBytes } : {},
5399
+ ...typeof info.maxUrls === "number" ? { maxUrls: info.maxUrls } : {}
5400
+ };
5401
+ }
5402
+ async function resolveResourceInfo(options, windowId) {
5403
+ const configured = options.resourceInfo ?? DEFAULT_RESOURCE_INFO;
5404
+ const info = typeof configured === "function" ? await configured({ windowId, identity: options.resolveIdentity(windowId) }) : configured;
5405
+ return normalizeResourceInfo(info);
5406
+ }
5407
+ async function handleInfo(options, windowId, requestId, send) {
5408
+ try {
5409
+ const info = await resolveResourceInfo(options, windowId);
5410
+ send({
5411
+ type: "resource.info.result",
5412
+ id: requestId,
5413
+ info
5414
+ });
5415
+ } catch (err2) {
5416
+ send({
5417
+ type: "resource.info.error",
5418
+ id: requestId,
5419
+ error: "unavailable",
5420
+ message: err2 instanceof Error ? err2.message : String(err2)
5421
+ });
5422
+ }
5423
+ }
5224
5424
  function resourceInvalidRequest(url, message) {
5225
5425
  return {
5226
5426
  ok: false,
@@ -5262,14 +5462,14 @@ async function fetchResourceItem(options, identity, url, init, signal) {
5262
5462
  headers,
5263
5463
  bodyBase64: arrayBufferToBase64(buffer)
5264
5464
  };
5265
- } catch (err) {
5266
- const isAbort = signal.aborted || err instanceof Error && (err.name === "AbortError" || err.name === "DOMException");
5465
+ } catch (err2) {
5466
+ const isAbort = signal.aborted || err2 instanceof Error && (err2.name === "AbortError" || err2.name === "DOMException");
5267
5467
  return {
5268
5468
  ok: false,
5269
5469
  url,
5270
5470
  error: isAbort ? "timeout" : "network-error",
5271
5471
  code: isAbort ? "canceled" : "network-error",
5272
- message: err instanceof Error ? err.message : String(err)
5472
+ message: err2 instanceof Error ? err2.message : String(err2)
5273
5473
  };
5274
5474
  }
5275
5475
  }
@@ -5387,6 +5587,14 @@ function createResourceService(options) {
5387
5587
  });
5388
5588
  return;
5389
5589
  }
5590
+ case "resource.info": {
5591
+ const m = message;
5592
+ const requestId = requestIdFromMessage(m);
5593
+ if (!requestId) return;
5594
+ handleInfo(options, windowId, requestId, send).catch(() => {
5595
+ });
5596
+ return;
5597
+ }
5390
5598
  case "resource.bytesMany": {
5391
5599
  const m = message;
5392
5600
  const requestId = requestIdFromMessage(m);
@@ -5415,7 +5623,7 @@ var OUTBOX_SERVICE_VERSION = "1.0.0";
5415
5623
  var OUTBOX_DESCRIPTOR = {
5416
5624
  name: "outbox",
5417
5625
  version: OUTBOX_SERVICE_VERSION,
5418
- description: "NAP-OUTBOX outbox-aware relay routing \u2014 query/subscribe/publish/resolveRelays"
5626
+ description: "NAP-OUTBOX outbox-aware relay routing \u2014 getEvent/query/subscribe/publish/resolveRelays"
5419
5627
  };
5420
5628
  function normalizeFilters(raw) {
5421
5629
  if (Array.isArray(raw)) {
@@ -5425,6 +5633,59 @@ function normalizeFilters(raw) {
5425
5633
  if (typeof raw === "object" && raw !== null) return [raw];
5426
5634
  return null;
5427
5635
  }
5636
+ function buildEventQuery(eventId, eventOptions) {
5637
+ const filter = { ids: [eventId] };
5638
+ const queryOptions = { limit: 1 };
5639
+ if (typeof eventOptions?.author === "string" && eventOptions.author.length > 0) {
5640
+ filter.authors = [eventOptions.author];
5641
+ queryOptions.authors = [eventOptions.author];
5642
+ }
5643
+ if (Array.isArray(eventOptions?.relays)) queryOptions.relays = eventOptions.relays;
5644
+ if (eventOptions?.strategy !== void 0) queryOptions.strategy = eventOptions.strategy;
5645
+ if (eventOptions?.timeoutMs !== void 0) queryOptions.timeoutMs = eventOptions.timeoutMs;
5646
+ return { filter, queryOptions };
5647
+ }
5648
+ function eventResultFromQuery(eventId, result) {
5649
+ const event = result.events.find((candidate) => candidate.id === eventId);
5650
+ const eventResult = {
5651
+ relays: event ? result.relays[eventId] ?? [] : []
5652
+ };
5653
+ if (event) eventResult.event = event;
5654
+ if (!event) eventResult.error = result.error ?? "not found";
5655
+ else if (result.error !== void 0) eventResult.error = result.error;
5656
+ if (result.incomplete !== void 0) eventResult.incomplete = result.incomplete;
5657
+ return eventResult;
5658
+ }
5659
+ function fallbackGetEvent(router, eventId, eventOptions) {
5660
+ const { filter, queryOptions } = buildEventQuery(eventId, eventOptions);
5661
+ return router.query([filter], queryOptions).then((result) => eventResultFromQuery(eventId, result));
5662
+ }
5663
+ function sendEventResult(id, eventId, result, send) {
5664
+ if (result.event && result.event.id !== eventId) {
5665
+ send({ type: "outbox.getEvent.result", id, relays: [], error: "not found" });
5666
+ return;
5667
+ }
5668
+ send({
5669
+ type: "outbox.getEvent.result",
5670
+ id,
5671
+ ...result.event === void 0 ? {} : { event: result.event },
5672
+ relays: result.relays,
5673
+ ...result.incomplete === void 0 ? {} : { incomplete: result.incomplete },
5674
+ ...result.error === void 0 ? {} : { error: result.error }
5675
+ });
5676
+ }
5677
+ function handleGetEvent(router, msg, send) {
5678
+ const m = msg;
5679
+ const id = m.id ?? "";
5680
+ if (typeof m.eventId !== "string" || m.eventId.length === 0) {
5681
+ send({ type: "outbox.getEvent.result", id, relays: [], error: "invalid filter" });
5682
+ return;
5683
+ }
5684
+ const getEvent = router.getEvent ?? ((eventId, eventOptions) => fallbackGetEvent(router, eventId, eventOptions));
5685
+ void getEvent(m.eventId, m.options).then((result) => sendEventResult(id, m.eventId, result, send)).catch(
5686
+ (err2) => send({ type: "outbox.getEvent.result", id, relays: [], error: toErrorMessage(err2) })
5687
+ );
5688
+ }
5428
5689
  function createOutboxService(options) {
5429
5690
  if (!options || typeof options.router !== "object" || options.router === null) {
5430
5691
  throw new Error("createOutboxService: options.router is required");
@@ -5449,7 +5710,7 @@ function createOutboxService(options) {
5449
5710
  ...result.error === void 0 ? {} : { error: result.error }
5450
5711
  })
5451
5712
  ).catch(
5452
- (err) => send({ type: "outbox.query.result", id, events: [], relays: {}, error: toErrorMessage(err) })
5713
+ (err2) => send({ type: "outbox.query.result", id, events: [], relays: {}, error: toErrorMessage(err2) })
5453
5714
  );
5454
5715
  }
5455
5716
  function handleSubscribe2(windowId, msg, send) {
@@ -5501,7 +5762,7 @@ function createOutboxService(options) {
5501
5762
  ...result.error === void 0 ? {} : { error: result.error }
5502
5763
  })
5503
5764
  ).catch(
5504
- (err) => send({ type: "outbox.publish.result", id, ok: false, error: toErrorMessage(err) })
5765
+ (err2) => send({ type: "outbox.publish.result", id, ok: false, error: toErrorMessage(err2) })
5505
5766
  );
5506
5767
  }
5507
5768
  function handleResolveRelays(msg, send) {
@@ -5512,13 +5773,16 @@ function createOutboxService(options) {
5512
5773
  return;
5513
5774
  }
5514
5775
  void router.resolveRelays(m.target).then((plan) => send({ type: "outbox.resolveRelays.result", id, plan })).catch(
5515
- (err) => send({ type: "outbox.resolveRelays.result", id, error: toErrorMessage(err) })
5776
+ (err2) => send({ type: "outbox.resolveRelays.result", id, error: toErrorMessage(err2) })
5516
5777
  );
5517
5778
  }
5518
5779
  return {
5519
5780
  descriptor: OUTBOX_DESCRIPTOR,
5520
5781
  handleMessage(windowId, message, send) {
5521
5782
  switch (message.type) {
5783
+ case "outbox.getEvent":
5784
+ handleGetEvent(router, message, send);
5785
+ return;
5522
5786
  case "outbox.query":
5523
5787
  handleQuery(message, send);
5524
5788
  return;
@@ -5549,9 +5813,9 @@ function createOutboxService(options) {
5549
5813
  }
5550
5814
  };
5551
5815
  }
5552
- function toErrorMessage(err) {
5553
- if (err instanceof Error) return err.message;
5554
- if (typeof err === "string") return err;
5816
+ function toErrorMessage(err2) {
5817
+ if (err2 instanceof Error) return err2.message;
5818
+ if (typeof err2 === "string") return err2;
5555
5819
  return "outbox request failed";
5556
5820
  }
5557
5821
  var UPLOAD_SERVICE_VERSION = "1.0.0";
@@ -5560,14 +5824,38 @@ var UPLOAD_DESCRIPTOR = {
5560
5824
  version: UPLOAD_SERVICE_VERSION,
5561
5825
  description: "NAP-UPLOAD shell-mediated file/blob upload \u2014 upload/status with progress pushes"
5562
5826
  };
5827
+ var DEFAULT_UPLOAD_INFO = {
5828
+ rails: []
5829
+ };
5563
5830
  function createUploadService(options) {
5564
5831
  if (!options || typeof options.uploader !== "object" || options.uploader === null) {
5565
5832
  throw new Error("createUploadService: options.uploader is required");
5566
5833
  }
5567
5834
  const { uploader } = options;
5835
+ const uploadInfo = options.uploadInfo ?? DEFAULT_UPLOAD_INFO;
5568
5836
  const generateId2 = options.generateId ?? (() => crypto.randomUUID());
5569
5837
  const now = options.now ?? (() => Date.now());
5570
5838
  const entries = /* @__PURE__ */ new Map();
5839
+ function normalizeUploadInfo(info) {
5840
+ return {
5841
+ rails: Array.isArray(info.rails) ? info.rails.filter((rail) => typeof rail?.rail === "string").map((rail) => ({
5842
+ rail: rail.rail,
5843
+ enabled: rail.enabled !== false,
5844
+ ...Array.isArray(rail.returns) ? { returns: rail.returns.filter((value) => typeof value === "string") } : {}
5845
+ })) : [],
5846
+ ...typeof info.maxBytes === "number" ? { maxBytes: info.maxBytes } : {},
5847
+ ...Array.isArray(info.mimeTypes) ? { mimeTypes: info.mimeTypes.filter((value) => typeof value === "string") } : {}
5848
+ };
5849
+ }
5850
+ function handleInfo2(windowId, msg, send) {
5851
+ const m = msg;
5852
+ const id = m.id ?? "";
5853
+ void Promise.resolve().then(() => typeof uploadInfo === "function" ? uploadInfo({ windowId }) : uploadInfo).then((info) => {
5854
+ send({ type: "upload.info.result", id, info: normalizeUploadInfo(info) });
5855
+ }).catch((err2) => {
5856
+ send({ type: "upload.info.result", id, error: toErrorMessage2(err2) });
5857
+ });
5858
+ }
5571
5859
  function handleUpload(windowId, msg, send) {
5572
5860
  const m = msg;
5573
5861
  const id = m.id ?? "";
@@ -5594,9 +5882,9 @@ function createUploadService(options) {
5594
5882
  const entry = entries.get(key);
5595
5883
  if (entry) entry.status = { ...stamped, updatedAt: now() };
5596
5884
  send({ type: "upload.upload.result", id, result: stamped });
5597
- }).catch((err) => {
5885
+ }).catch((err2) => {
5598
5886
  entries.delete(key);
5599
- send({ type: "upload.upload.result", id, error: toErrorMessage2(err) });
5887
+ send({ type: "upload.upload.result", id, error: toErrorMessage2(err2) });
5600
5888
  });
5601
5889
  }
5602
5890
  function handleStatus(windowId, msg, send) {
@@ -5618,7 +5906,7 @@ function createUploadService(options) {
5618
5906
  status ? { type: "upload.status.result", id, status } : { type: "upload.status.result", id, error: "unknown upload" }
5619
5907
  )
5620
5908
  ).catch(
5621
- (err) => send({ type: "upload.status.result", id, error: toErrorMessage2(err) })
5909
+ (err2) => send({ type: "upload.status.result", id, error: toErrorMessage2(err2) })
5622
5910
  );
5623
5911
  return;
5624
5912
  }
@@ -5628,6 +5916,9 @@ function createUploadService(options) {
5628
5916
  descriptor: UPLOAD_DESCRIPTOR,
5629
5917
  handleMessage(windowId, message, send) {
5630
5918
  switch (message.type) {
5919
+ case "upload.info":
5920
+ handleInfo2(windowId, message, send);
5921
+ return;
5631
5922
  case "upload.upload":
5632
5923
  handleUpload(windowId, message, send);
5633
5924
  return;
@@ -5649,9 +5940,9 @@ function createUploadService(options) {
5649
5940
  }
5650
5941
  };
5651
5942
  }
5652
- function toErrorMessage2(err) {
5653
- if (err instanceof Error) return err.message;
5654
- if (typeof err === "string") return err;
5943
+ function toErrorMessage2(err2) {
5944
+ if (err2 instanceof Error) return err2.message;
5945
+ if (typeof err2 === "string") return err2;
5655
5946
  return "upload request failed";
5656
5947
  }
5657
5948
  var INTENT_SERVICE_VERSION = "1.0.0";
@@ -5660,9 +5951,9 @@ var INTENT_DESCRIPTOR = {
5660
5951
  version: INTENT_SERVICE_VERSION,
5661
5952
  description: "NAP-INTENT archetype intent dispatch \u2014 invoke/available/handlers"
5662
5953
  };
5663
- function toErrorMessage4(err) {
5664
- if (err instanceof Error) return err.message;
5665
- if (typeof err === "string") return err;
5954
+ function toErrorMessage4(err2) {
5955
+ if (err2 instanceof Error) return err2.message;
5956
+ if (typeof err2 === "string") return err2;
5666
5957
  return "intent request failed";
5667
5958
  }
5668
5959
  function createIntentService(options) {
@@ -5680,11 +5971,11 @@ function createIntentService(options) {
5680
5971
  let pending;
5681
5972
  try {
5682
5973
  pending = Promise.resolve(call());
5683
- } catch (err) {
5684
- send({ type: resultType, id, error: toErrorMessage4(err) });
5974
+ } catch (err2) {
5975
+ send({ type: resultType, id, error: toErrorMessage4(err2) });
5685
5976
  return;
5686
5977
  }
5687
- pending.then((value) => send(onValue(value))).catch((err) => send({ type: resultType, id, error: toErrorMessage4(err) }));
5978
+ pending.then((value) => send(onValue(value))).catch((err2) => send({ type: resultType, id, error: toErrorMessage4(err2) }));
5688
5979
  }
5689
5980
  function handleInvoke(windowId, msg, send) {
5690
5981
  const m = msg;
@@ -5793,7 +6084,7 @@ function createCvmService(options) {
5793
6084
  const m = msg;
5794
6085
  const id = m.id ?? "";
5795
6086
  void transport.discover(m.query).then((servers) => send({ type: "cvm.discover.result", id, servers })).catch(
5796
- (err) => send({ type: "cvm.discover.result", id, servers: [], error: toErrorMessage5(err) })
6087
+ (err2) => send({ type: "cvm.discover.result", id, servers: [], error: toErrorMessage5(err2) })
5797
6088
  );
5798
6089
  }
5799
6090
  function handleRequest(windowId, msg, send) {
@@ -5809,7 +6100,7 @@ function createCvmService(options) {
5809
6100
  }
5810
6101
  openSession(windowId, m.server, send);
5811
6102
  void transport.request(m.server, m.message, m.options).then((message) => send({ type: "cvm.request.result", id, message })).catch(
5812
- (err) => send({ type: "cvm.request.result", id, error: toErrorMessage5(err) })
6103
+ (err2) => send({ type: "cvm.request.result", id, error: toErrorMessage5(err2) })
5813
6104
  );
5814
6105
  }
5815
6106
  function handleClose(windowId, msg, send) {
@@ -5820,7 +6111,7 @@ function createCvmService(options) {
5820
6111
  return;
5821
6112
  }
5822
6113
  closeSession(windowId, m.server.pubkey);
5823
- void transport.close(m.server).then(() => send({ type: "cvm.close.result", id })).catch((err) => send({ type: "cvm.close.result", id, error: toErrorMessage5(err) }));
6114
+ void transport.close(m.server).then(() => send({ type: "cvm.close.result", id })).catch((err2) => send({ type: "cvm.close.result", id, error: toErrorMessage5(err2) }));
5824
6115
  }
5825
6116
  return {
5826
6117
  descriptor: CVM_DESCRIPTOR,
@@ -5851,9 +6142,9 @@ function createCvmService(options) {
5851
6142
  }
5852
6143
  };
5853
6144
  }
5854
- function toErrorMessage5(err) {
5855
- if (err instanceof Error) return err.message;
5856
- if (typeof err === "string") return err;
6145
+ function toErrorMessage5(err2) {
6146
+ if (err2 instanceof Error) return err2.message;
6147
+ if (typeof err2 === "string") return err2;
5857
6148
  return "cvm request failed";
5858
6149
  }
5859
6150
  var LINK_SERVICE_VERSION = "1.0.0";
@@ -5928,20 +6219,20 @@ var LISTS_DESCRIPTOR = {
5928
6219
  version: LISTS_SERVICE_VERSION,
5929
6220
  description: "NAP-LISTS reference handler for shell-mediated NIP-51 list mutations"
5930
6221
  };
5931
- function errorMessage(err, fallback) {
5932
- if (err instanceof Error) return err.message;
5933
- if (typeof err === "string") return err;
6222
+ function errorMessage(err2, fallback) {
6223
+ if (err2 instanceof Error) return err2.message;
6224
+ if (typeof err2 === "string") return err2;
5934
6225
  return fallback;
5935
6226
  }
5936
6227
  function settle(call, send, okFalse, onValue) {
5937
6228
  let pending;
5938
6229
  try {
5939
6230
  pending = Promise.resolve(call());
5940
- } catch (err) {
5941
- send(okFalse(errorMessage(err, "lists request failed")));
6231
+ } catch (err2) {
6232
+ send(okFalse(errorMessage(err2, "lists request failed")));
5942
6233
  return;
5943
6234
  }
5944
- pending.then((value) => send(onValue(value))).catch((err) => send(okFalse(errorMessage(err, "lists request failed"))));
6235
+ pending.then((value) => send(onValue(value))).catch((err2) => send(okFalse(errorMessage(err2, "lists request failed"))));
5945
6236
  }
5946
6237
  function unsupportedMutation(resultType, id) {
5947
6238
  return {
@@ -6008,20 +6299,20 @@ var SERIAL_DESCRIPTOR = {
6008
6299
  version: SERIAL_SERVICE_VERSION,
6009
6300
  description: "NAP-SERIAL reference handler for shell-mediated serial sessions"
6010
6301
  };
6011
- function errorMessage2(err, fallback) {
6012
- if (err instanceof Error) return err.message;
6013
- if (typeof err === "string") return err;
6302
+ function errorMessage2(err2, fallback) {
6303
+ if (err2 instanceof Error) return err2.message;
6304
+ if (typeof err2 === "string") return err2;
6014
6305
  return fallback;
6015
6306
  }
6016
6307
  function settle2(call, send, okFalse, onValue) {
6017
6308
  let pending;
6018
6309
  try {
6019
6310
  pending = Promise.resolve(call());
6020
- } catch (err) {
6021
- send(okFalse(errorMessage2(err, "serial request failed")));
6311
+ } catch (err2) {
6312
+ send(okFalse(errorMessage2(err2, "serial request failed")));
6022
6313
  return;
6023
6314
  }
6024
- pending.then((value) => send(onValue(value))).catch((err) => send(okFalse(errorMessage2(err, "serial request failed"))));
6315
+ pending.then((value) => send(onValue(value))).catch((err2) => send(okFalse(errorMessage2(err2, "serial request failed"))));
6025
6316
  }
6026
6317
  function unsupported(resultType, id) {
6027
6318
  return {
@@ -6095,20 +6386,20 @@ var BLE_DESCRIPTOR = {
6095
6386
  version: BLE_SERVICE_VERSION,
6096
6387
  description: "NAP-BLE reference handler for shell-mediated BLE/GATT sessions"
6097
6388
  };
6098
- function errorMessage3(err, fallback) {
6099
- if (err instanceof Error) return err.message;
6100
- if (typeof err === "string") return err;
6389
+ function errorMessage3(err2, fallback) {
6390
+ if (err2 instanceof Error) return err2.message;
6391
+ if (typeof err2 === "string") return err2;
6101
6392
  return fallback;
6102
6393
  }
6103
6394
  function settle3(call, send, okFalse, onValue) {
6104
6395
  let pending;
6105
6396
  try {
6106
6397
  pending = Promise.resolve(call());
6107
- } catch (err) {
6108
- send(okFalse(errorMessage3(err, "ble request failed")));
6398
+ } catch (err2) {
6399
+ send(okFalse(errorMessage3(err2, "ble request failed")));
6109
6400
  return;
6110
6401
  }
6111
- pending.then((value) => send(onValue(value))).catch((err) => send(okFalse(errorMessage3(err, "ble request failed"))));
6402
+ pending.then((value) => send(onValue(value))).catch((err2) => send(okFalse(errorMessage3(err2, "ble request failed"))));
6112
6403
  }
6113
6404
  function unsupported2(resultType, id) {
6114
6405
  return {
@@ -6117,12 +6408,20 @@ function unsupported2(resultType, id) {
6117
6408
  error: `${resultType.replace(".result", "")} unavailable`
6118
6409
  };
6119
6410
  }
6411
+ function createContext(windowId, send) {
6412
+ return {
6413
+ windowId,
6414
+ emit(event) {
6415
+ send({ type: "ble.event", event });
6416
+ }
6417
+ };
6418
+ }
6120
6419
  function createBleService(options = {}) {
6121
6420
  return {
6122
6421
  descriptor: BLE_DESCRIPTOR,
6123
6422
  handleMessage(windowId, message, send) {
6124
6423
  const id = message.id ?? "";
6125
- const context = { windowId };
6424
+ const context = createContext(windowId, send);
6126
6425
  if (message.type === "ble.open") {
6127
6426
  if (!options.open) {
6128
6427
  send(unsupported2("ble.open.result", id));
@@ -6238,20 +6537,20 @@ var WEBRTC_DESCRIPTOR = {
6238
6537
  version: WEBRTC_SERVICE_VERSION,
6239
6538
  description: "NAP-WEBRTC reference handler for shell-mediated WebRTC sessions"
6240
6539
  };
6241
- function errorMessage4(err, fallback) {
6242
- if (err instanceof Error) return err.message;
6243
- if (typeof err === "string") return err;
6540
+ function errorMessage4(err2, fallback) {
6541
+ if (err2 instanceof Error) return err2.message;
6542
+ if (typeof err2 === "string") return err2;
6244
6543
  return fallback;
6245
6544
  }
6246
6545
  function settle4(call, send, okFalse, onValue) {
6247
6546
  let pending;
6248
6547
  try {
6249
6548
  pending = Promise.resolve(call());
6250
- } catch (err) {
6251
- send(okFalse(errorMessage4(err, "webrtc request failed")));
6549
+ } catch (err2) {
6550
+ send(okFalse(errorMessage4(err2, "webrtc request failed")));
6252
6551
  return;
6253
6552
  }
6254
- pending.then((value) => send(onValue(value))).catch((err) => send(okFalse(errorMessage4(err, "webrtc request failed"))));
6553
+ pending.then((value) => send(onValue(value))).catch((err2) => send(okFalse(errorMessage4(err2, "webrtc request failed"))));
6255
6554
  }
6256
6555
  function unsupported3(resultType, id) {
6257
6556
  return {
@@ -6260,7 +6559,7 @@ function unsupported3(resultType, id) {
6260
6559
  error: `${resultType.replace(".result", "")} unavailable`
6261
6560
  };
6262
6561
  }
6263
- function createContext(windowId, send) {
6562
+ function createContext2(windowId, send) {
6264
6563
  return {
6265
6564
  windowId,
6266
6565
  emit(event) {
@@ -6273,7 +6572,7 @@ function createWebrtcService(options = {}) {
6273
6572
  descriptor: WEBRTC_DESCRIPTOR,
6274
6573
  handleMessage(windowId, message, send) {
6275
6574
  const id = message.id ?? "";
6276
- const context = createContext(windowId, send);
6575
+ const context = createContext2(windowId, send);
6277
6576
  if (message.type === "webrtc.open") {
6278
6577
  if (!options.open) {
6279
6578
  send(unsupported3("webrtc.open.result", id));
@@ -6334,9 +6633,9 @@ var COMMON_DESCRIPTOR = {
6334
6633
  version: COMMON_SERVICE_VERSION,
6335
6634
  description: "NAP-COMMON reference handler for shell-mediated social helpers"
6336
6635
  };
6337
- function errorMessage5(err, fallback) {
6338
- if (err instanceof Error) return err.message;
6339
- if (typeof err === "string") return err;
6636
+ function errorMessage5(err2, fallback) {
6637
+ if (err2 instanceof Error) return err2.message;
6638
+ if (typeof err2 === "string") return err2;
6340
6639
  return fallback;
6341
6640
  }
6342
6641
  function encodeNip19(input) {
@@ -6365,8 +6664,8 @@ function encodeNip19(input) {
6365
6664
  default:
6366
6665
  return { ok: false, error: "unsupported NIP-19 type" };
6367
6666
  }
6368
- } catch (err) {
6369
- return { ok: false, error: errorMessage5(err, "NIP-19 encode failed") };
6667
+ } catch (err2) {
6668
+ return { ok: false, error: errorMessage5(err2, "NIP-19 encode failed") };
6370
6669
  }
6371
6670
  }
6372
6671
  function decodeNip19Value(value) {
@@ -6399,9 +6698,9 @@ function decodeNip19Value(value) {
6399
6698
  default:
6400
6699
  return { ok: false, error: "unsupported NIP-19 type" };
6401
6700
  }
6402
- } catch (err) {
6701
+ } catch (err2) {
6403
6702
  if (value.startsWith("nrelay1")) return decodeNrelay(value);
6404
- return { ok: false, error: errorMessage5(err, "NIP-19 decode failed") };
6703
+ return { ok: false, error: errorMessage5(err2, "NIP-19 decode failed") };
6405
6704
  }
6406
6705
  }
6407
6706
  function decodeNrelay(value) {
@@ -6417,8 +6716,8 @@ function decodeNrelay(value) {
6417
6716
  const payloadWords = words.slice(0, -6);
6418
6717
  const bytes = convertBits(payloadWords, 5, 8, false);
6419
6718
  return { ok: true, nip19Type: "nrelay", relay: new TextDecoder().decode(Uint8Array.from(bytes)) };
6420
- } catch (err) {
6421
- return { ok: false, error: errorMessage5(err, "invalid nrelay value") };
6719
+ } catch (err2) {
6720
+ return { ok: false, error: errorMessage5(err2, "invalid nrelay value") };
6422
6721
  }
6423
6722
  }
6424
6723
  function convertBits(data, fromBits, toBits, pad) {
@@ -6447,11 +6746,11 @@ function settle5(call, send, okFalse, onValue) {
6447
6746
  let pending;
6448
6747
  try {
6449
6748
  pending = Promise.resolve(call());
6450
- } catch (err) {
6451
- send(okFalse(errorMessage5(err, "common request failed")));
6749
+ } catch (err2) {
6750
+ send(okFalse(errorMessage5(err2, "common request failed")));
6452
6751
  return;
6453
6752
  }
6454
- pending.then((value) => send(onValue(value))).catch((err) => send(okFalse(errorMessage5(err, "common request failed"))));
6753
+ pending.then((value) => send(onValue(value))).catch((err2) => send(okFalse(errorMessage5(err2, "common request failed"))));
6455
6754
  }
6456
6755
  function createCommonService(options = {}) {
6457
6756
  return {