@kehto/paja 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -192,6 +192,9 @@ function relayMap(action) {
192
192
  if (action === "publishEncrypted") return { senderCap: "relay:write", recipientCap: null };
193
193
  return { senderCap: "relay:read", recipientCap: null };
194
194
  }
195
+ function countMap(_action) {
196
+ return { senderCap: "relay:read", recipientCap: null };
197
+ }
195
198
  function identityMap(action) {
196
199
  if (action === "getPublicKey" || action === "getRelays") {
197
200
  return { senderCap: null, recipientCap: null };
@@ -278,6 +281,8 @@ function resolveCapabilitiesNap(msg) {
278
281
  switch (domain) {
279
282
  case "relay":
280
283
  return relayMap(action);
284
+ case "count":
285
+ return countMap(action);
281
286
  case "identity":
282
287
  return identityMap(action);
283
288
  case "keys":
@@ -607,7 +612,7 @@ function deserialize2(json) {
607
612
  return defaultConfig();
608
613
  }
609
614
 
610
- // ../../node_modules/.pnpm/@napplet+core@0.24.0/node_modules/@napplet/core/dist/index.js
615
+ // ../../node_modules/.pnpm/@napplet+core@0.25.0/node_modules/@napplet/core/dist/index.js
611
616
  function createDispatch() {
612
617
  const handlers = /* @__PURE__ */ new Map();
613
618
  function registerNap2(domain, handler) {
@@ -781,11 +786,11 @@ function capToBit(cap) {
781
786
  return CAP_MAP[cap] ?? 0;
782
787
  }
783
788
  function bitsToCapabilities(bits) {
784
- const result = [];
789
+ const result2 = [];
785
790
  for (const [cap, bit] of Object.entries(CAP_MAP)) {
786
- if (bits & bit) result.push(cap);
791
+ if (bits & bit) result2.push(cap);
787
792
  }
788
- return result;
793
+ return result2;
789
794
  }
790
795
  function toIdentity(pubkey, dTag, hash) {
791
796
  return { pubkey, dTag, hash };
@@ -881,9 +886,9 @@ function createFirewallState(persistence) {
881
886
  let counters = createState2();
882
887
  return {
883
888
  evaluate(observation) {
884
- const result = evaluate(config, counters, observation);
885
- counters = result.newState;
886
- return result;
889
+ const result2 = evaluate(config, counters, observation);
890
+ counters = result2.newState;
891
+ return result2;
887
892
  },
888
893
  setPolicy(napplet, policy) {
889
894
  config = setPolicy(config, napplet, policy);
@@ -979,8 +984,8 @@ function createManifestCache(persistence) {
979
984
  getVerification(eventId) {
980
985
  return verificationCache.get(eventId);
981
986
  },
982
- setVerification(eventId, result) {
983
- verificationCache.set(eventId, result);
987
+ setVerification(eventId, result2) {
988
+ verificationCache.set(eventId, result2);
984
989
  },
985
990
  hasVerification(eventId) {
986
991
  return verificationCache.has(eventId);
@@ -1498,6 +1503,65 @@ function createIdentityHandler(context) {
1498
1503
  }
1499
1504
  };
1500
1505
  }
1506
+ function createCountHandler(context) {
1507
+ return function handleCountMessage(windowId, msg) {
1508
+ if (msg.type !== "count.query") return;
1509
+ const message = msg;
1510
+ const id = typeof message.id === "string" ? message.id : "";
1511
+ const filters = message.filters;
1512
+ if (!isValidFilterArray(filters)) {
1513
+ sendCountError(context.hooks, windowId, id, "invalid-filter", "count.query requires a non-empty filters array");
1514
+ return;
1515
+ }
1516
+ if (message.options !== void 0 && !isPlainObject(message.options)) {
1517
+ sendCountError(context.hooks, windowId, id, "invalid-filter", "count.query options must be an object when present");
1518
+ return;
1519
+ }
1520
+ const service = context.serviceRegistry["count"];
1521
+ if (!service) {
1522
+ sendCountError(
1523
+ context.hooks,
1524
+ windowId,
1525
+ id,
1526
+ "count-unavailable",
1527
+ "count service unavailable; refusing to emulate counts by fetching event payloads"
1528
+ );
1529
+ return;
1530
+ }
1531
+ service.handleMessage(windowId, msg, (resp) => {
1532
+ context.hooks.sendToNapplet(windowId, normalizeCountResult(resp, id));
1533
+ });
1534
+ };
1535
+ }
1536
+ function normalizeCountResult(resp, id) {
1537
+ const value = resp;
1538
+ return {
1539
+ type: "count.query.result",
1540
+ id: typeof value.id === "string" ? value.id : id,
1541
+ ok: value.ok === true,
1542
+ ...typeof value.count === "number" && Number.isFinite(value.count) && value.count >= 0 ? { count: Math.floor(value.count) } : {},
1543
+ ...typeof value.approximate === "boolean" ? { approximate: value.approximate } : {},
1544
+ ...typeof value.hll === "string" ? { hll: value.hll } : {},
1545
+ ...Array.isArray(value.relays) ? { relays: value.relays.filter((relay) => typeof relay === "string") } : {},
1546
+ ...typeof value.error === "string" ? { error: value.error } : {},
1547
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
1548
+ };
1549
+ }
1550
+ function sendCountError(hooks, windowId, id, error, reason) {
1551
+ hooks.sendToNapplet(windowId, {
1552
+ type: "count.query.result",
1553
+ id,
1554
+ ok: false,
1555
+ error,
1556
+ reason
1557
+ });
1558
+ }
1559
+ function isValidFilterArray(value) {
1560
+ return Array.isArray(value) && value.length > 0 && value.every((filter) => isPlainObject(filter));
1561
+ }
1562
+ function isPlainObject(value) {
1563
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1564
+ }
1501
1565
  function createIncRuntime(hooks, sessionRegistry2) {
1502
1566
  const state = {
1503
1567
  subscriptions: /* @__PURE__ */ new Map(),
@@ -1747,14 +1811,14 @@ function handleStorageNap(windowId, msg, sendToNapplet, sessionRegistry2, aclSta
1747
1811
  break;
1748
1812
  }
1749
1813
  const newKey = scopedKey(dTag, aggregateHash, key);
1750
- let result = statePersistence.get(newKey);
1751
- if (result === null && pubkey) {
1752
- result = statePersistence.get(legacyScopedKey(pubkey, dTag, aggregateHash, key));
1814
+ let result2 = statePersistence.get(newKey);
1815
+ if (result2 === null && pubkey) {
1816
+ result2 = statePersistence.get(legacyScopedKey(pubkey, dTag, aggregateHash, key));
1753
1817
  }
1754
- if (result === null && pubkey) {
1755
- result = statePersistence.get(`napp-state:${pubkey}:${dTag}:${aggregateHash}:${key}`);
1818
+ if (result2 === null && pubkey) {
1819
+ result2 = statePersistence.get(`napp-state:${pubkey}:${dTag}:${aggregateHash}:${key}`);
1756
1820
  }
1757
- sendResult({ value: result });
1821
+ sendResult({ value: result2 });
1758
1822
  break;
1759
1823
  }
1760
1824
  case "set": {
@@ -1973,6 +2037,7 @@ function createNapEnvelopeDispatcher(handlers) {
1973
2037
  };
1974
2038
  napDispatch.registerNap("relay", adapt(handlers.relay));
1975
2039
  napDispatch.registerNap("identity", adapt(handlers.identity));
2040
+ napDispatch.registerNap("count", adapt(handlers.count));
1976
2041
  napDispatch.registerNap("keys", adapt(handlers.keys));
1977
2042
  napDispatch.registerNap("media", adapt(handlers.media));
1978
2043
  napDispatch.registerNap("notify", adapt(handlers.notify));
@@ -2040,8 +2105,8 @@ function createFirewallGate(config) {
2040
2105
  const { firewallState, sessionRegistry: sessionRegistry2, hooks, fireConsent } = config;
2041
2106
  return function firewallGate(windowId, envelope, senderCap) {
2042
2107
  const obs = buildObservation(envelope, windowId, senderCap, sessionRegistry2, hooks.getFocusContext);
2043
- const result = firewallState.evaluate(obs);
2044
- const { decision, action, ruleId, reason } = result;
2108
+ const result2 = firewallState.evaluate(obs);
2109
+ const { decision, action, ruleId, reason } = result2;
2045
2110
  const napplet = obs.napplet;
2046
2111
  const opClass = obs.opClass;
2047
2112
  if (decision === "reject" || decision === "prompt") {
@@ -2069,11 +2134,11 @@ function createMessageHandler(hooks, enforceNap, dispatchNapEnvelope, firewallGa
2069
2134
  if (dotIdx === -1) return;
2070
2135
  const caps = resolveCapabilitiesNap(envelope);
2071
2136
  if (caps.senderCap) {
2072
- const result = enforceNap(windowId, caps.senderCap, envelope);
2073
- if (!result.allowed) {
2137
+ const result2 = enforceNap(windowId, caps.senderCap, envelope);
2138
+ if (!result2.allowed) {
2074
2139
  const id = envelope.id ?? "";
2075
2140
  const isStorageEnvelope = envelope.type.startsWith("storage.");
2076
- const error = formatDenialReason(result.capability);
2141
+ const error = formatDenialReason(result2.capability);
2077
2142
  const type = isStorageEnvelope ? `${envelope.type}.result` : `${envelope.type}.error`;
2078
2143
  hooks.sendToNapplet(windowId, { type, id, error });
2079
2144
  return;
@@ -2225,6 +2290,7 @@ function createRuntime(hooks) {
2225
2290
  const dispatchNapEnvelope = createNapEnvelopeDispatcher({
2226
2291
  relay: createRelayHandler({ hooks, serviceRegistry, subscriptions, eventBuffer, replayDetector }),
2227
2292
  identity: createIdentityHandler({ hooks, serviceRegistry }),
2293
+ count: createCountHandler({ hooks, serviceRegistry }),
2228
2294
  inc: incRuntime.handleMessage,
2229
2295
  ...domainHandlers
2230
2296
  });
@@ -2437,12 +2503,12 @@ function createStatePersistence() {
2437
2503
  },
2438
2504
  keys(prefix) {
2439
2505
  try {
2440
- const result = [];
2506
+ const result2 = [];
2441
2507
  for (let i4 = 0; i4 < localStorage.length; i4++) {
2442
2508
  const key = localStorage.key(i4);
2443
- if (key?.startsWith(prefix)) result.push(key);
2509
+ if (key?.startsWith(prefix)) result2.push(key);
2444
2510
  }
2445
- return result;
2511
+ return result2;
2446
2512
  } catch {
2447
2513
  return [];
2448
2514
  }
@@ -3245,6 +3311,7 @@ function buildShellCapabilities(hooks) {
3245
3311
  const domains = hooks.relayPool ? ["relay", "outbox", ...NAP_DOMAINS] : [...NAP_DOMAINS];
3246
3312
  if (hooks.upload) domains.push("upload");
3247
3313
  if (hooks.intent?.isAvailable()) domains.push("intent");
3314
+ if (hooks.services?.count) domains.push("count");
3248
3315
  if (hooks.link?.isAvailable()) domains.push("link");
3249
3316
  if (hooks.common?.isAvailable()) domains.push("common");
3250
3317
  if (hooks.lists?.isAvailable()) domains.push("lists");
@@ -3262,6 +3329,7 @@ function buildShellCapabilities(hooks) {
3262
3329
  const naps = hooks.relayPool ? ["relay", "outbox", ...NAP_DOMAINS, ...NAP_INC_PROTOCOLS] : [...NAP_DOMAINS, ...NAP_INC_PROTOCOLS];
3263
3330
  if (hooks.upload) naps.push("upload");
3264
3331
  if (hooks.intent?.isAvailable()) naps.push("intent");
3332
+ if (hooks.services?.count) naps.push("count");
3265
3333
  if (hooks.link?.isAvailable()) naps.push("link");
3266
3334
  if (hooks.common?.isAvailable()) naps.push("common");
3267
3335
  if (hooks.lists?.isAvailable()) naps.push("lists");
@@ -3981,7 +4049,7 @@ function decode(code) {
3981
4049
  }
3982
4050
  }
3983
4051
  function parseTLV(data) {
3984
- let result = {};
4052
+ let result2 = {};
3985
4053
  let rest = data;
3986
4054
  while (rest.length > 0) {
3987
4055
  let t = rest[0];
@@ -3990,10 +4058,10 @@ function parseTLV(data) {
3990
4058
  rest = rest.slice(2 + l);
3991
4059
  if (v.length < l)
3992
4060
  throw new Error(`not enough data to read on TLV ${t}`);
3993
- result[t] = result[t] || [];
3994
- result[t].push(v);
4061
+ result2[t] = result2[t] || [];
4062
+ result2[t].push(v);
3995
4063
  }
3996
- return result;
4064
+ return result2;
3997
4065
  }
3998
4066
  function npubEncode(hex) {
3999
4067
  return encodeBytes("npub", hexToBytes2(hex));
@@ -4477,8 +4545,8 @@ var _8n = /* @__PURE__ */ BigInt(8);
4477
4545
  var _9n = /* @__PURE__ */ BigInt(9);
4478
4546
  var _16n = /* @__PURE__ */ BigInt(16);
4479
4547
  function mod(a, b) {
4480
- const result = a % b;
4481
- return result >= _0n2 ? result : b + result;
4548
+ const result2 = a % b;
4549
+ return result2 >= _0n2 ? result2 : b + result2;
4482
4550
  }
4483
4551
  function pow2(x, power, modulo) {
4484
4552
  let res = x;
@@ -7194,9 +7262,9 @@ function createNotificationService(options) {
7194
7262
  };
7195
7263
  }
7196
7264
  var IDENTITY_SERVICE_VERSION = "1.0.0";
7197
- function sendProviderError(send, result, fallback, err2) {
7265
+ function sendProviderError(send, result2, fallback, err2) {
7198
7266
  send({
7199
- ...result,
7267
+ ...result2,
7200
7268
  error: err2?.message ?? fallback
7201
7269
  });
7202
7270
  }
@@ -7214,7 +7282,7 @@ function sendOptionalProviderResult(options, send, fallbackResult, errorFallback
7214
7282
  send(fallbackResult);
7215
7283
  return;
7216
7284
  }
7217
- Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result) => send(result)).catch((err2) => sendProviderError(send, fallbackResult, errorFallback, err2));
7285
+ Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result2) => send(result2)).catch((err2) => sendProviderError(send, fallbackResult, errorFallback, err2));
7218
7286
  }
7219
7287
  function sendIdentityError(send, id, typeBase, error) {
7220
7288
  send({ type: `${typeBase}.error`, id, error });
@@ -7225,21 +7293,21 @@ function sendSignerError(send, id, typeBase, fallback, err2) {
7225
7293
  function handleGetPublicKey(options, id, send) {
7226
7294
  const signer = options.getSigner();
7227
7295
  if (!signer) {
7228
- const result = {
7296
+ const result2 = {
7229
7297
  type: "identity.getPublicKey.result",
7230
7298
  id,
7231
7299
  pubkey: ""
7232
7300
  };
7233
- send(result);
7301
+ send(result2);
7234
7302
  return;
7235
7303
  }
7236
7304
  Promise.resolve(signer.getPublicKey?.()).then((pubkey) => {
7237
- const result = {
7305
+ const result2 = {
7238
7306
  type: "identity.getPublicKey.result",
7239
7307
  id,
7240
7308
  pubkey: pubkey ?? ""
7241
7309
  };
7242
- send(result);
7310
+ send(result2);
7243
7311
  }).catch((err2) => sendSignerError(send, id, "identity.getPublicKey", "getPublicKey failed", err2));
7244
7312
  }
7245
7313
  function handleGetRelays(options, id, send) {
@@ -7249,12 +7317,12 @@ function handleGetRelays(options, id, send) {
7249
7317
  return;
7250
7318
  }
7251
7319
  Promise.resolve(signer.getRelays?.() ?? {}).then((relays) => {
7252
- const result = {
7320
+ const result2 = {
7253
7321
  type: "identity.getRelays.result",
7254
7322
  id,
7255
7323
  relays
7256
7324
  };
7257
- send(result);
7325
+ send(result2);
7258
7326
  }).catch((err2) => sendSignerError(send, id, "identity.getRelays", "getRelays failed", err2));
7259
7327
  }
7260
7328
  function handleReadProvider(options, id, message, send) {
@@ -7475,6 +7543,90 @@ function createRelayPoolService(options) {
7475
7543
  }
7476
7544
  };
7477
7545
  }
7546
+ var DEFAULT_MAX_FILTERS = 16;
7547
+ function createCountService(options) {
7548
+ return {
7549
+ descriptor: {
7550
+ name: "count",
7551
+ version: "1.0.0",
7552
+ description: "Runtime-mediated NIP-01 filter counts"
7553
+ },
7554
+ handleMessage(windowId, message, send) {
7555
+ if (message.type !== "count.query") return;
7556
+ const countMessage = message;
7557
+ const id = typeof countMessage.id === "string" ? countMessage.id : "";
7558
+ const filters = countMessage.filters;
7559
+ if (!isValidFilterArray2(filters)) {
7560
+ send(result(id, { ok: false, error: "invalid-filter", reason: "count.query requires a non-empty filters array" }));
7561
+ return;
7562
+ }
7563
+ const maxFilters = options.maxFilters ?? DEFAULT_MAX_FILTERS;
7564
+ if (filters.length > maxFilters) {
7565
+ send(result(id, { ok: false, error: "too-expensive", reason: `count.query accepts at most ${maxFilters} filters` }));
7566
+ return;
7567
+ }
7568
+ for (let i4 = 0; i4 < filters.length; i4++) {
7569
+ const supported = options.isFilterSupported?.(filters[i4], i4) ?? true;
7570
+ if (supported !== true) {
7571
+ send(result(id, {
7572
+ ok: false,
7573
+ error: "unsupported-filter",
7574
+ reason: typeof supported === "string" ? supported : `filter ${i4} is not supported by this count backend`
7575
+ }));
7576
+ return;
7577
+ }
7578
+ }
7579
+ const request = {
7580
+ filters,
7581
+ windowId,
7582
+ ...isPlainObject2(countMessage.options) ? { options: countMessage.options } : {}
7583
+ };
7584
+ Promise.resolve(options.count(request)).then((countResult) => {
7585
+ send(result(id, normalizeCountResult2(countResult)));
7586
+ }).catch((error) => {
7587
+ send(result(id, {
7588
+ ok: false,
7589
+ error: "count-unavailable",
7590
+ reason: error instanceof Error ? error.message : "count backend failed"
7591
+ }));
7592
+ });
7593
+ }
7594
+ };
7595
+ }
7596
+ function result(id, value) {
7597
+ return {
7598
+ type: "count.query.result",
7599
+ id,
7600
+ ok: value.ok,
7601
+ ...typeof value.count === "number" ? { count: value.count } : {},
7602
+ ...typeof value.approximate === "boolean" ? { approximate: value.approximate } : {},
7603
+ ...typeof value.hll === "string" ? { hll: value.hll } : {},
7604
+ ...Array.isArray(value.relays) ? { relays: value.relays.filter((relay) => typeof relay === "string") } : {},
7605
+ ...typeof value.error === "string" ? { error: value.error } : {},
7606
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
7607
+ };
7608
+ }
7609
+ function normalizeCountResult2(value) {
7610
+ if (typeof value === "number") {
7611
+ return Number.isFinite(value) && value >= 0 ? { ok: true, count: Math.floor(value), approximate: false } : { ok: false, error: "count-unavailable", reason: "count backend returned an invalid count" };
7612
+ }
7613
+ const count = typeof value.count === "number" && Number.isFinite(value.count) && value.count >= 0 ? Math.floor(value.count) : void 0;
7614
+ return {
7615
+ ok: value.ok === true,
7616
+ ...count !== void 0 ? { count } : {},
7617
+ ...typeof value.approximate === "boolean" ? { approximate: value.approximate } : {},
7618
+ ...typeof value.hll === "string" ? { hll: value.hll } : {},
7619
+ ...Array.isArray(value.relays) ? { relays: value.relays } : {},
7620
+ ...typeof value.error === "string" ? { error: value.error } : {},
7621
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
7622
+ };
7623
+ }
7624
+ function isValidFilterArray2(value) {
7625
+ return Array.isArray(value) && value.length > 0 && value.every((filter) => isPlainObject2(filter));
7626
+ }
7627
+ function isPlainObject2(value) {
7628
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7629
+ }
7478
7630
  var KEYS_SERVICE_VERSION = "1.2.0";
7479
7631
  var MODIFIER_ALIASES = {
7480
7632
  ctrl: "ctrl",
@@ -7588,13 +7740,13 @@ function createKeysService(options = {}) {
7588
7740
  return;
7589
7741
  }
7590
7742
  }
7591
- const result = {
7743
+ const result2 = {
7592
7744
  type: "keys.registerAction.result",
7593
7745
  id: m.id,
7594
7746
  actionId: m.action.id,
7595
7747
  ...m.action.defaultKey ? { binding: m.action.defaultKey } : {}
7596
7748
  };
7597
- send(result);
7749
+ send(result2);
7598
7750
  return;
7599
7751
  }
7600
7752
  case "keys.unregisterAction": {
@@ -7735,13 +7887,13 @@ function createKeysService(options = {}) {
7735
7887
  return;
7736
7888
  }
7737
7889
  }
7738
- const result = {
7890
+ const result2 = {
7739
7891
  type: "keys.registerAction.result",
7740
7892
  id: m.id,
7741
7893
  actionId: m.action.id,
7742
7894
  ...m.action.defaultKey ? { binding: m.action.defaultKey } : {}
7743
7895
  };
7744
- send(result);
7896
+ send(result2);
7745
7897
  return;
7746
7898
  }
7747
7899
  case "keys.unregisterAction": {
@@ -8166,12 +8318,12 @@ function createNotifyService(options = {}) {
8166
8318
  case "notify.send": {
8167
8319
  const m = message;
8168
8320
  options.onSend?.(windowId, m);
8169
- const result = {
8321
+ const result2 = {
8170
8322
  type: "notify.send.result",
8171
8323
  id: m.id,
8172
8324
  notificationId: gen()
8173
8325
  };
8174
- send(result);
8326
+ send(result2);
8175
8327
  return;
8176
8328
  }
8177
8329
  case "notify.dismiss":
@@ -8180,12 +8332,12 @@ function createNotifyService(options = {}) {
8180
8332
  return;
8181
8333
  case "notify.permission.request": {
8182
8334
  const m = message;
8183
- const result = {
8335
+ const result2 = {
8184
8336
  type: "notify.permission.result",
8185
8337
  id: m.id,
8186
8338
  granted: defaultGrant
8187
8339
  };
8188
- send(result);
8340
+ send(result2);
8189
8341
  return;
8190
8342
  }
8191
8343
  default: {
@@ -8224,12 +8376,12 @@ function createThemeService(options = {}) {
8224
8376
  handleMessage(_windowId, message, send) {
8225
8377
  const id = message.id ?? "";
8226
8378
  if (message.type === "theme.get") {
8227
- const result = {
8379
+ const result2 = {
8228
8380
  type: "theme.get.result",
8229
8381
  id,
8230
8382
  theme: currentTheme
8231
8383
  };
8232
- send(result);
8384
+ send(result2);
8233
8385
  return;
8234
8386
  }
8235
8387
  send({
@@ -8351,14 +8503,14 @@ function createConfigService(options) {
8351
8503
  case "config.registerSchema": {
8352
8504
  const m = message;
8353
8505
  const validation = options.registerSchema ? options.registerSchema(windowId, m.schema, m.version) : validateCoreSubset(m.schema);
8354
- const result = validation.ok ? { type: "config.registerSchema.result", id: m.id, ok: true } : {
8506
+ const result2 = validation.ok ? { type: "config.registerSchema.result", id: m.id, ok: true } : {
8355
8507
  type: "config.registerSchema.result",
8356
8508
  id: m.id,
8357
8509
  ok: false,
8358
8510
  code: validation.code,
8359
8511
  error: validation.error
8360
8512
  };
8361
- send(result);
8513
+ send(result2);
8362
8514
  return;
8363
8515
  }
8364
8516
  case "config.openSettings": {
@@ -8725,33 +8877,33 @@ function buildEventQuery(eventId, eventOptions) {
8725
8877
  if (eventOptions?.timeoutMs !== void 0) queryOptions.timeoutMs = eventOptions.timeoutMs;
8726
8878
  return { filter, queryOptions };
8727
8879
  }
8728
- function eventResultFromQuery(eventId, result) {
8729
- const event = result.events.find((candidate) => candidate.id === eventId);
8880
+ function eventResultFromQuery(eventId, result2) {
8881
+ const event = result2.events.find((candidate) => candidate.id === eventId);
8730
8882
  const eventResult = {
8731
- relays: event ? result.relays[eventId] ?? [] : []
8883
+ relays: event ? result2.relays[eventId] ?? [] : []
8732
8884
  };
8733
8885
  if (event) eventResult.event = event;
8734
- if (!event) eventResult.error = result.error ?? "not found";
8735
- else if (result.error !== void 0) eventResult.error = result.error;
8736
- if (result.incomplete !== void 0) eventResult.incomplete = result.incomplete;
8886
+ if (!event) eventResult.error = result2.error ?? "not found";
8887
+ else if (result2.error !== void 0) eventResult.error = result2.error;
8888
+ if (result2.incomplete !== void 0) eventResult.incomplete = result2.incomplete;
8737
8889
  return eventResult;
8738
8890
  }
8739
8891
  function fallbackGetEvent(router, eventId, eventOptions) {
8740
8892
  const { filter, queryOptions } = buildEventQuery(eventId, eventOptions);
8741
- return router.query([filter], queryOptions).then((result) => eventResultFromQuery(eventId, result));
8893
+ return router.query([filter], queryOptions).then((result2) => eventResultFromQuery(eventId, result2));
8742
8894
  }
8743
- function sendEventResult(id, eventId, result, send) {
8744
- if (result.event && result.event.id !== eventId) {
8895
+ function sendEventResult(id, eventId, result2, send) {
8896
+ if (result2.event && result2.event.id !== eventId) {
8745
8897
  send({ type: "outbox.getEvent.result", id, relays: [], error: "not found" });
8746
8898
  return;
8747
8899
  }
8748
8900
  send({
8749
8901
  type: "outbox.getEvent.result",
8750
8902
  id,
8751
- ...result.event === void 0 ? {} : { event: result.event },
8752
- relays: result.relays,
8753
- ...result.incomplete === void 0 ? {} : { incomplete: result.incomplete },
8754
- ...result.error === void 0 ? {} : { error: result.error }
8903
+ ...result2.event === void 0 ? {} : { event: result2.event },
8904
+ relays: result2.relays,
8905
+ ...result2.incomplete === void 0 ? {} : { incomplete: result2.incomplete },
8906
+ ...result2.error === void 0 ? {} : { error: result2.error }
8755
8907
  });
8756
8908
  }
8757
8909
  function handleGetEvent(router, msg, send) {
@@ -8762,7 +8914,7 @@ function handleGetEvent(router, msg, send) {
8762
8914
  return;
8763
8915
  }
8764
8916
  const getEvent = router.getEvent ?? ((eventId, eventOptions) => fallbackGetEvent(router, eventId, eventOptions));
8765
- void getEvent(m.eventId, m.options).then((result) => sendEventResult(id, m.eventId, result, send)).catch(
8917
+ void getEvent(m.eventId, m.options).then((result2) => sendEventResult(id, m.eventId, result2, send)).catch(
8766
8918
  (err2) => send({ type: "outbox.getEvent.result", id, relays: [], error: toErrorMessage(err2) })
8767
8919
  );
8768
8920
  }
@@ -8781,13 +8933,13 @@ function createOutboxService(options) {
8781
8933
  return;
8782
8934
  }
8783
8935
  void router.query(filters, m.options).then(
8784
- (result) => send({
8936
+ (result2) => send({
8785
8937
  type: "outbox.query.result",
8786
8938
  id,
8787
- events: result.events,
8788
- relays: result.relays,
8789
- ...result.incomplete === void 0 ? {} : { incomplete: result.incomplete },
8790
- ...result.error === void 0 ? {} : { error: result.error }
8939
+ events: result2.events,
8940
+ relays: result2.relays,
8941
+ ...result2.incomplete === void 0 ? {} : { incomplete: result2.incomplete },
8942
+ ...result2.error === void 0 ? {} : { error: result2.error }
8791
8943
  })
8792
8944
  ).catch(
8793
8945
  (err2) => send({ type: "outbox.query.result", id, events: [], relays: {}, error: toErrorMessage(err2) })
@@ -8832,14 +8984,14 @@ function createOutboxService(options) {
8832
8984
  return;
8833
8985
  }
8834
8986
  void router.publish(m.event, m.options).then(
8835
- (result) => send({
8987
+ (result2) => send({
8836
8988
  type: "outbox.publish.result",
8837
8989
  id,
8838
- ok: result.ok,
8839
- ...result.event === void 0 ? {} : { event: result.event },
8840
- ...result.eventId === void 0 ? {} : { eventId: result.eventId },
8841
- ...result.relays === void 0 ? {} : { relays: result.relays },
8842
- ...result.error === void 0 ? {} : { error: result.error }
8990
+ ok: result2.ok,
8991
+ ...result2.event === void 0 ? {} : { event: result2.event },
8992
+ ...result2.eventId === void 0 ? {} : { eventId: result2.eventId },
8993
+ ...result2.relays === void 0 ? {} : { relays: result2.relays },
8994
+ ...result2.error === void 0 ? {} : { error: result2.error }
8843
8995
  })
8844
8996
  ).catch(
8845
8997
  (err2) => send({ type: "outbox.publish.result", id, ok: false, error: toErrorMessage(err2) })
@@ -8957,8 +9109,8 @@ function createUploadService(options) {
8957
9109
  send({ type: "upload.status.changed", status: stamped });
8958
9110
  }
8959
9111
  };
8960
- void uploader.upload(request, ctx).then((result) => {
8961
- const stamped = { ...result, uploadId };
9112
+ void uploader.upload(request, ctx).then((result2) => {
9113
+ const stamped = { ...result2, uploadId };
8962
9114
  const entry = entries.get(key);
8963
9115
  if (entry) entry.status = { ...stamped, updatedAt: now2() };
8964
9116
  send({ type: "upload.upload.result", id, result: stamped });
@@ -9070,7 +9222,7 @@ function createIntentService(options) {
9070
9222
  send,
9071
9223
  "intent.invoke.result",
9072
9224
  id,
9073
- (result) => ({ type: "intent.invoke.result", id, result })
9225
+ (result2) => ({ type: "intent.invoke.result", id, result: result2 })
9074
9226
  );
9075
9227
  }
9076
9228
  function handleAvailable(msg, send) {
@@ -9258,12 +9410,12 @@ async function handleOpen(options, windowId, message, send) {
9258
9410
  return;
9259
9411
  }
9260
9412
  try {
9261
- const result = await options.open({ windowId, url: parsed, options: message.options });
9413
+ const result2 = await options.open({ windowId, url: parsed, options: message.options });
9262
9414
  send({
9263
9415
  type: "link.open.result",
9264
9416
  id: message.id,
9265
- status: result.status,
9266
- ...result.status === "denied" ? { error: "blocked-by-policy" } : {}
9417
+ status: result2.status,
9418
+ ...result2.status === "denied" ? { error: "blocked-by-policy" } : {}
9267
9419
  });
9268
9420
  } catch {
9269
9421
  send(denied(message.id, "blocked-by-policy"));
@@ -9333,7 +9485,7 @@ function settleMutation(hook, message, context, send, resultType) {
9333
9485
  () => hook(message.list, message.items, message.options, context),
9334
9486
  send,
9335
9487
  (error) => ({ type: resultType, id: message.id, ok: false, error: "list-unavailable", reason: error }),
9336
- (result) => ({ type: resultType, id: message.id, ...result })
9488
+ (result2) => ({ type: resultType, id: message.id, ...result2 })
9337
9489
  );
9338
9490
  }
9339
9491
  function createListsService(options = {}) {
@@ -9417,7 +9569,7 @@ function createSerialService(options = {}) {
9417
9569
  () => options.open(serialMessage.request, context),
9418
9570
  send,
9419
9571
  (error) => ({ type: "serial.open.result", id, error }),
9420
- (result) => ({ type: "serial.open.result", id, session: result.session })
9572
+ (result2) => ({ type: "serial.open.result", id, session: result2.session })
9421
9573
  );
9422
9574
  return;
9423
9575
  }
@@ -9512,7 +9664,7 @@ function createBleService(options = {}) {
9512
9664
  () => options.open(bleMessage.request, context),
9513
9665
  send,
9514
9666
  (error) => ({ type: "ble.open.result", id, error }),
9515
- (result) => ({ type: "ble.open.result", id, session: result.session })
9667
+ (result2) => ({ type: "ble.open.result", id, session: result2.session })
9516
9668
  );
9517
9669
  return;
9518
9670
  }
@@ -9663,7 +9815,7 @@ function createWebrtcService(options = {}) {
9663
9815
  () => options.open(webrtcMessage.request, context),
9664
9816
  send,
9665
9817
  (error) => ({ type: "webrtc.open.result", id, error }),
9666
- (result) => ({ type: "webrtc.open.result", id, session: result.session })
9818
+ (result2) => ({ type: "webrtc.open.result", id, session: result2.session })
9667
9819
  );
9668
9820
  return;
9669
9821
  }
@@ -9803,7 +9955,7 @@ function decodeNrelay(value) {
9803
9955
  function convertBits(data, fromBits, toBits, pad2) {
9804
9956
  let acc = 0;
9805
9957
  let bits = 0;
9806
- const result = [];
9958
+ const result2 = [];
9807
9959
  const maxv = (1 << toBits) - 1;
9808
9960
  const maxAcc = (1 << fromBits + toBits - 1) - 1;
9809
9961
  for (const value of data) {
@@ -9812,15 +9964,15 @@ function convertBits(data, fromBits, toBits, pad2) {
9812
9964
  bits += fromBits;
9813
9965
  while (bits >= toBits) {
9814
9966
  bits -= toBits;
9815
- result.push(acc >> bits & maxv);
9967
+ result2.push(acc >> bits & maxv);
9816
9968
  }
9817
9969
  }
9818
9970
  if (pad2) {
9819
- if (bits > 0) result.push(acc << toBits - bits & maxv);
9971
+ if (bits > 0) result2.push(acc << toBits - bits & maxv);
9820
9972
  } else if (bits >= fromBits || (acc << toBits - bits & maxv) !== 0) {
9821
9973
  throw new Error("invalid bech32 padding");
9822
9974
  }
9823
- return result;
9975
+ return result2;
9824
9976
  }
9825
9977
  function settle5(call, send, okFalse, onValue) {
9826
9978
  let pending;
@@ -9840,14 +9992,14 @@ function createCommonService(options = {}) {
9840
9992
  const context = { windowId };
9841
9993
  if (message.type === "common.encodeNip19") {
9842
9994
  const input = message.input;
9843
- const result = input ? encodeNip19(input) : { ok: false, error: "invalid input" };
9844
- send({ type: "common.encodeNip19.result", id, ...result });
9995
+ const result2 = input ? encodeNip19(input) : { ok: false, error: "invalid input" };
9996
+ send({ type: "common.encodeNip19.result", id, ...result2 });
9845
9997
  return;
9846
9998
  }
9847
9999
  if (message.type === "common.decodeNip19") {
9848
10000
  const value = message.value;
9849
- const result = typeof value === "string" ? decodeNip19Value(value) : { ok: false, error: "invalid value" };
9850
- send({ type: "common.decodeNip19.result", id, ...result });
10001
+ const result2 = typeof value === "string" ? decodeNip19Value(value) : { ok: false, error: "invalid value" };
10002
+ send({ type: "common.decodeNip19.result", id, ...result2 });
9851
10003
  return;
9852
10004
  }
9853
10005
  if (message.type === "common.getProfile") {
@@ -9860,7 +10012,7 @@ function createCommonService(options = {}) {
9860
10012
  () => options.getProfile(target, context),
9861
10013
  send,
9862
10014
  (error) => ({ type: "common.getProfile.result", id, ok: false, pubkey: target ?? "", error }),
9863
- (result) => ({ type: "common.getProfile.result", id, ...result })
10015
+ (result2) => ({ type: "common.getProfile.result", id, ...result2 })
9864
10016
  );
9865
10017
  return;
9866
10018
  }
@@ -9873,7 +10025,7 @@ function createCommonService(options = {}) {
9873
10025
  () => options.follows(context),
9874
10026
  send,
9875
10027
  (error) => ({ type: "common.follows.result", id, ok: false, pubkeys: [], error }),
9876
- (result) => ({ type: "common.follows.result", id, ...result })
10028
+ (result2) => ({ type: "common.follows.result", id, ...result2 })
9877
10029
  );
9878
10030
  return;
9879
10031
  }
@@ -9897,7 +10049,7 @@ function createCommonService(options = {}) {
9897
10049
  () => options.react(m.targetEventId, m.reaction, m.customEmojiHref, context),
9898
10050
  send,
9899
10051
  (error) => ({ type: "common.react.result", id, ok: false, error }),
9900
- (result) => ({ type: "common.react.result", id, ...result })
10052
+ (result2) => ({ type: "common.react.result", id, ...result2 })
9901
10053
  );
9902
10054
  return;
9903
10055
  }
@@ -9911,7 +10063,7 @@ function createCommonService(options = {}) {
9911
10063
  () => options.report(m.target, m.reason, m.text, context),
9912
10064
  send,
9913
10065
  (error) => ({ type: "common.report.result", id, ok: false, error }),
9914
- (result) => ({ type: "common.report.result", id, ...result })
10066
+ (result2) => ({ type: "common.report.result", id, ...result2 })
9915
10067
  );
9916
10068
  return;
9917
10069
  }
@@ -9934,7 +10086,7 @@ function settleAction(action, pubkeys, context, send, resultType, id, unavailabl
9934
10086
  () => action(pubkeys, context),
9935
10087
  send,
9936
10088
  (error) => ({ type: resultType, id, ok: false, error }),
9937
- (result) => ({ type: resultType, id, ...result })
10089
+ (result2) => ({ type: resultType, id, ...result2 })
9938
10090
  );
9939
10091
  }
9940
10092
 
@@ -10183,6 +10335,13 @@ function createMemoryRelayPool(getSimulation, confirmRequest) {
10183
10335
  } };
10184
10336
  }
10185
10337
  };
10338
+ },
10339
+ count(_relayUrls, filters) {
10340
+ const seen = /* @__PURE__ */ new Set();
10341
+ for (const event of events) {
10342
+ if (matchesAnyFilter2(event, filters)) seen.add(event.id);
10343
+ }
10344
+ return seen.size;
10186
10345
  }
10187
10346
  };
10188
10347
  }
@@ -10241,7 +10400,7 @@ function createDevUploader(getSimulation) {
10241
10400
  throw new Error("upload simulation is disabled");
10242
10401
  }
10243
10402
  const size = request.data instanceof Blob ? request.data.size : request.data.byteLength;
10244
- const result = {
10403
+ const result2 = {
10245
10404
  ok: true,
10246
10405
  uploadId: ctx.uploadId,
10247
10406
  status: "complete",
@@ -10250,8 +10409,8 @@ function createDevUploader(getSimulation) {
10250
10409
  size,
10251
10410
  mimeType: request.mimeType ?? (request.data instanceof Blob ? request.data.type : void 0)
10252
10411
  };
10253
- ctx.onStatus({ ...result, updatedAt: Date.now() });
10254
- return result;
10412
+ ctx.onStatus({ ...result2, updatedAt: Date.now() });
10413
+ return result2;
10255
10414
  },
10256
10415
  async status(uploadId) {
10257
10416
  const simulation = getSimulation();
@@ -10426,6 +10585,25 @@ function createDevServices(pool, getSimulation, onThemeService, confirmRequest,
10426
10585
  });
10427
10586
  services.outbox = createOutboxService({ router: createOutboxRouter(pool, getSimulation, confirmRequest, signerProvider) });
10428
10587
  }
10588
+ if (getSimulation().capabilities.domains.count && typeof pool.count === "function") {
10589
+ services.count = createCountService({
10590
+ count: async ({ filters }) => {
10591
+ const relays = getRelayUrls(getSimulation());
10592
+ return {
10593
+ ok: true,
10594
+ count: await pool.count(relays, filters),
10595
+ approximate: false,
10596
+ relays
10597
+ };
10598
+ },
10599
+ isFilterSupported: (filter) => {
10600
+ if (Object.keys(filter).length === 0) {
10601
+ return "broad empty filters are too expensive for the Paja count backend";
10602
+ }
10603
+ return true;
10604
+ }
10605
+ });
10606
+ }
10429
10607
  if (getSimulation().capabilities.domains.identity) {
10430
10608
  services.identity = createIdentityService({ getSigner: () => createRuntimeSigner(getSimulation, confirmRequest, signerProvider) });
10431
10609
  }
@@ -11020,8 +11198,8 @@ function binarySearch(arr, compare) {
11020
11198
  return [start, false];
11021
11199
  }
11022
11200
  function mergeReverseSortedLists(list1, list2) {
11023
- const result = new Array(list1.length + list2.length);
11024
- result.length = 0;
11201
+ const result2 = new Array(list1.length + list2.length);
11202
+ result2.length = 0;
11025
11203
  let i1 = 0;
11026
11204
  let i22 = 0;
11027
11205
  let sameTimestampIds = [];
@@ -11034,40 +11212,40 @@ function mergeReverseSortedLists(list1, list2) {
11034
11212
  next = list2[i22];
11035
11213
  i22++;
11036
11214
  }
11037
- if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {
11215
+ if (result2.length > 0 && result2[result2.length - 1].created_at === next.created_at) {
11038
11216
  if (sameTimestampIds.includes(next.id))
11039
11217
  continue;
11040
11218
  } else {
11041
11219
  sameTimestampIds.length = 0;
11042
11220
  }
11043
- result.push(next);
11221
+ result2.push(next);
11044
11222
  sameTimestampIds.push(next.id);
11045
11223
  }
11046
11224
  while (i1 < list1.length) {
11047
11225
  const next = list1[i1];
11048
11226
  i1++;
11049
- if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {
11227
+ if (result2.length > 0 && result2[result2.length - 1].created_at === next.created_at) {
11050
11228
  if (sameTimestampIds.includes(next.id))
11051
11229
  continue;
11052
11230
  } else {
11053
11231
  sameTimestampIds.length = 0;
11054
11232
  }
11055
- result.push(next);
11233
+ result2.push(next);
11056
11234
  sameTimestampIds.push(next.id);
11057
11235
  }
11058
11236
  while (i22 < list2.length) {
11059
11237
  const next = list2[i22];
11060
11238
  i22++;
11061
- if (result.length > 0 && result[result.length - 1].created_at === next.created_at) {
11239
+ if (result2.length > 0 && result2[result2.length - 1].created_at === next.created_at) {
11062
11240
  if (sameTimestampIds.includes(next.id))
11063
11241
  continue;
11064
11242
  } else {
11065
11243
  sameTimestampIds.length = 0;
11066
11244
  }
11067
- result.push(next);
11245
+ result2.push(next);
11068
11246
  sameTimestampIds.push(next.id);
11069
11247
  }
11070
- return result;
11248
+ return result2;
11071
11249
  }
11072
11250
  var JS2 = class {
11073
11251
  generateSecretKey() {
@@ -11519,7 +11697,7 @@ function decode2(code) {
11519
11697
  }
11520
11698
  }
11521
11699
  function parseTLV2(data) {
11522
- let result = {};
11700
+ let result2 = {};
11523
11701
  let rest = data;
11524
11702
  while (rest.length > 0) {
11525
11703
  let t = rest[0];
@@ -11528,10 +11706,10 @@ function parseTLV2(data) {
11528
11706
  rest = rest.slice(2 + l);
11529
11707
  if (v.length < l)
11530
11708
  throw new Error(`not enough data to read on TLV ${t}`);
11531
- result[t] = result[t] || [];
11532
- result[t].push(v);
11709
+ result2[t] = result2[t] || [];
11710
+ result2[t].push(v);
11533
11711
  }
11534
- return result;
11712
+ return result2;
11535
11713
  }
11536
11714
  function nsecEncode(key) {
11537
11715
  return encodeBytes2("nsec", key);
@@ -11682,7 +11860,7 @@ __export(nip10_exports, {
11682
11860
  parse: () => parse
11683
11861
  });
11684
11862
  function parse(event) {
11685
- const result = {
11863
+ const result2 = {
11686
11864
  reply: void 0,
11687
11865
  root: void 0,
11688
11866
  mentions: [],
@@ -11701,15 +11879,15 @@ function parse(event) {
11701
11879
  author: eTagAuthor
11702
11880
  };
11703
11881
  if (eTagMarker === "root") {
11704
- result.root = eventPointer;
11882
+ result2.root = eventPointer;
11705
11883
  continue;
11706
11884
  }
11707
11885
  if (eTagMarker === "reply") {
11708
- result.reply = eventPointer;
11886
+ result2.reply = eventPointer;
11709
11887
  continue;
11710
11888
  }
11711
11889
  if (eTagMarker === "mention") {
11712
- result.mentions.push(eventPointer);
11890
+ result2.mentions.push(eventPointer);
11713
11891
  continue;
11714
11892
  }
11715
11893
  if (!maybeParent) {
@@ -11717,40 +11895,40 @@ function parse(event) {
11717
11895
  } else {
11718
11896
  maybeRoot = eventPointer;
11719
11897
  }
11720
- result.mentions.push(eventPointer);
11898
+ result2.mentions.push(eventPointer);
11721
11899
  continue;
11722
11900
  }
11723
11901
  if (tag[0] === "q" && tag[1]) {
11724
11902
  const [_, eTagEventId, eTagRelayUrl] = tag;
11725
- result.quotes.push({
11903
+ result2.quotes.push({
11726
11904
  id: eTagEventId,
11727
11905
  relays: eTagRelayUrl ? [eTagRelayUrl] : []
11728
11906
  });
11729
11907
  }
11730
11908
  if (tag[0] === "p" && tag[1]) {
11731
- result.profiles.push({
11909
+ result2.profiles.push({
11732
11910
  pubkey: tag[1],
11733
11911
  relays: tag[2] ? [tag[2]] : []
11734
11912
  });
11735
11913
  continue;
11736
11914
  }
11737
11915
  }
11738
- if (!result.root) {
11739
- result.root = maybeRoot || maybeParent || result.reply;
11916
+ if (!result2.root) {
11917
+ result2.root = maybeRoot || maybeParent || result2.reply;
11740
11918
  }
11741
- if (!result.reply) {
11742
- result.reply = maybeParent || result.root;
11919
+ if (!result2.reply) {
11920
+ result2.reply = maybeParent || result2.root;
11743
11921
  }
11744
11922
  ;
11745
- [result.reply, result.root].forEach((ref) => {
11923
+ [result2.reply, result2.root].forEach((ref) => {
11746
11924
  if (!ref)
11747
11925
  return;
11748
- let idx = result.mentions.indexOf(ref);
11926
+ let idx = result2.mentions.indexOf(ref);
11749
11927
  if (idx !== -1) {
11750
- result.mentions.splice(idx, 1);
11928
+ result2.mentions.splice(idx, 1);
11751
11929
  }
11752
11930
  if (ref.author) {
11753
- let author = result.profiles.find((p) => p.pubkey === ref.author);
11931
+ let author = result2.profiles.find((p) => p.pubkey === ref.author);
11754
11932
  if (author && author.relays) {
11755
11933
  if (!ref.relays) {
11756
11934
  ref.relays = [];
@@ -11763,9 +11941,9 @@ function parse(event) {
11763
11941
  }
11764
11942
  }
11765
11943
  });
11766
- result.mentions.forEach((ref) => {
11944
+ result2.mentions.forEach((ref) => {
11767
11945
  if (ref.author) {
11768
- let author = result.profiles.find((p) => p.pubkey === ref.author);
11946
+ let author = result2.profiles.find((p) => p.pubkey === ref.author);
11769
11947
  if (author && author.relays) {
11770
11948
  if (!ref.relays) {
11771
11949
  ref.relays = [];
@@ -11778,7 +11956,7 @@ function parse(event) {
11778
11956
  }
11779
11957
  }
11780
11958
  });
11781
- return result;
11959
+ return result2;
11782
11960
  }
11783
11961
  var nip11_exports = {};
11784
11962
  __export(nip11_exports, {
@@ -13447,11 +13625,11 @@ function createNipEncryptionMethods(state, prefix) {
13447
13625
  }
13448
13626
  async function connectNip46State(state, secret) {
13449
13627
  await openWebSocket(state);
13450
- const result = await sendRequestWithId(state, crypto.randomUUID(), "connect", [state.bunkerPubkey, secret ?? ""]);
13451
- if (typeof result === "string") {
13452
- state.authorizedPubkey = result;
13453
- } else if (result && typeof result === "object" && "pubkey" in result) {
13454
- state.authorizedPubkey = result.pubkey;
13628
+ const result2 = await sendRequestWithId(state, crypto.randomUUID(), "connect", [state.bunkerPubkey, secret ?? ""]);
13629
+ if (typeof result2 === "string") {
13630
+ state.authorizedPubkey = result2;
13631
+ } else if (result2 && typeof result2 === "object" && "pubkey" in result2) {
13632
+ state.authorizedPubkey = result2.pubkey;
13455
13633
  } else {
13456
13634
  const pkResult = await sendRequestWithId(state, crypto.randomUUID(), "get_public_key", []);
13457
13635
  state.authorizedPubkey = pkResult;
@@ -13465,11 +13643,11 @@ function createNip46Signer(state) {
13465
13643
  return sendRequestWithId(state, crypto.randomUUID(), "get_public_key", []);
13466
13644
  },
13467
13645
  signEvent: async (event) => {
13468
- const result = await sendRequestWithId(state, crypto.randomUUID(), "sign_event", [JSON.stringify(event)]);
13469
- if (typeof result === "string") {
13470
- return JSON.parse(result);
13646
+ const result2 = await sendRequestWithId(state, crypto.randomUUID(), "sign_event", [JSON.stringify(event)]);
13647
+ if (typeof result2 === "string") {
13648
+ return JSON.parse(result2);
13471
13649
  }
13472
- return result;
13650
+ return result2;
13473
13651
  },
13474
13652
  nip04: createNipEncryptionMethods(state, "nip04"),
13475
13653
  nip44: createNipEncryptionMethods(state, "nip44")
@@ -13617,6 +13795,7 @@ var PAJA_SIMULATION_DOMAINS = [
13617
13795
  "media",
13618
13796
  "upload",
13619
13797
  "intent",
13798
+ "count",
13620
13799
  "link",
13621
13800
  "common",
13622
13801
  "lists",
@@ -13729,8 +13908,8 @@ function installPajaOriginRegistryProxy(originRegistry2, stateRef) {
13729
13908
  };
13730
13909
  const originalGetWindowId = originRegistry2.getWindowId.bind(originRegistry2);
13731
13910
  originRegistry2.getWindowId = (win) => {
13732
- const result = originalGetWindowId(win);
13733
- if (result) return result;
13911
+ const result2 = originalGetWindowId(win);
13912
+ if (result2) return result2;
13734
13913
  const real = proxyToReal.get(win);
13735
13914
  return real ? originalGetWindowId(real) : void 0;
13736
13915
  };
@@ -14205,11 +14384,11 @@ var AbstractRelay = class {
14205
14384
  }
14206
14385
  async pingpong() {
14207
14386
  if (this.ws?.readyState === 1) {
14208
- const result = await Promise.any([
14387
+ const result2 = await Promise.any([
14209
14388
  this.ws && this.ws.ping && this.ws.once ? this.waitForPingPong() : this.waitForDummyReq(),
14210
14389
  new Promise((res) => setTimeout(() => res(false), this.pingTimeout))
14211
14390
  ]);
14212
- if (!result) {
14391
+ if (!result2) {
14213
14392
  if (this.ws?.readyState === this._WebSocket.OPEN) {
14214
14393
  this.ws?.close();
14215
14394
  }