@kehto/paja 0.27.0 → 0.27.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.
- package/README.md +3 -1
- package/dist/browser-host.js +111 -38
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-M5ZFET3T.js → chunk-2M7FG76K.js} +3 -1
- package/dist/chunk-2M7FG76K.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-M5ZFET3T.js.map +0 -1
package/README.md
CHANGED
|
@@ -31,7 +31,9 @@ surface: relay/outbox, storage, identity, keys, config, resource, theme, notify,
|
|
|
31
31
|
media, upload, intent, count, link, common, lists, serial, BLE, WebRTC, DM, FS,
|
|
32
32
|
CVM, and inc. Relay/outbox defaults to live public relays
|
|
33
33
|
and uses NIP-65 relay-list bootstrap plus kind `3` contact-list reads for
|
|
34
|
-
identity flows;
|
|
34
|
+
identity flows; background kind-0 profile warming runs only for a connected
|
|
35
|
+
signer account, so a signer-less session with a fixed simulation identity stays
|
|
36
|
+
read-only. `--relay-mode memory` is the explicit deterministic fixture
|
|
35
37
|
mode and does not advertise relay, outbox, count, or DM. `shell` is the
|
|
36
38
|
mandatory, non-toggleable handshake domain; the deprecated legacy package path
|
|
37
39
|
remains an upstream compatibility alias to `inc`.
|
package/dist/browser-host.js
CHANGED
|
@@ -10219,6 +10219,7 @@ async function resolvePlan(ctx, pubkeys, direction, relayHints) {
|
|
|
10219
10219
|
}
|
|
10220
10220
|
function discoveredReadRelays(ctx, authors, lists) {
|
|
10221
10221
|
const relays = /* @__PURE__ */ new Set();
|
|
10222
|
+
const authorsByRelay = /* @__PURE__ */ new Map();
|
|
10222
10223
|
const missingAuthors = [];
|
|
10223
10224
|
for (const author of new Set(authors)) {
|
|
10224
10225
|
const writeRelays = lists.get(author)?.write;
|
|
@@ -10226,9 +10227,14 @@ function discoveredReadRelays(ctx, authors, lists) {
|
|
|
10226
10227
|
missingAuthors.push(author);
|
|
10227
10228
|
continue;
|
|
10228
10229
|
}
|
|
10229
|
-
for (const url of allowed(ctx, writeRelays))
|
|
10230
|
+
for (const url of allowed(ctx, writeRelays)) {
|
|
10231
|
+
relays.add(url);
|
|
10232
|
+
const owners = authorsByRelay.get(url) ?? [];
|
|
10233
|
+
owners.push(author);
|
|
10234
|
+
authorsByRelay.set(url, owners);
|
|
10235
|
+
}
|
|
10230
10236
|
}
|
|
10231
|
-
return { relays: [...relays], missingAuthors };
|
|
10237
|
+
return { relays: [...relays], authorsByRelay, missingAuthors };
|
|
10232
10238
|
}
|
|
10233
10239
|
function immediateReadPlan(ctx, relayHints) {
|
|
10234
10240
|
const hints = allowed(ctx, relayHints ?? []);
|
|
@@ -10276,8 +10282,8 @@ function buildQueryResult(collector, options, incomplete, subscribedAny) {
|
|
|
10276
10282
|
if (!subscribedAny) result2.error = "relay list unavailable";
|
|
10277
10283
|
return result2;
|
|
10278
10284
|
}
|
|
10279
|
-
function relayPoolSubscribe(ctx, filters, relayUrl2, cb, origin) {
|
|
10280
|
-
return ctx.relayPool.subscribe(filters, [relayUrl2], cb, origin);
|
|
10285
|
+
function relayPoolSubscribe(ctx, filters, relayUrl2, cb, origin, authors) {
|
|
10286
|
+
return ctx.relayPool.subscribe(filters, [relayUrl2], cb, origin, authors);
|
|
10281
10287
|
}
|
|
10282
10288
|
function startQueryImpl(ctx, filters, options, sink) {
|
|
10283
10289
|
if (!ctx.relayPool.isAvailable()) {
|
|
@@ -10327,7 +10333,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10327
10333
|
if (finished2 || discoveryPending || collector.pendingVerifications > 0) return;
|
|
10328
10334
|
if (activeRelays.size === 0 || eoseRelays.size >= activeRelays.size) finalize();
|
|
10329
10335
|
}
|
|
10330
|
-
function attachRelay(relayUrl2, origin) {
|
|
10336
|
+
function attachRelay(relayUrl2, origin, relayAuthors) {
|
|
10331
10337
|
if (finished2 || activeRelays.has(relayUrl2)) return;
|
|
10332
10338
|
activeRelays.add(relayUrl2);
|
|
10333
10339
|
try {
|
|
@@ -10340,7 +10346,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10340
10346
|
}
|
|
10341
10347
|
recordRelay(collector, item.id, relayUrl2);
|
|
10342
10348
|
admitEvent(ctx, collector, item, sink, () => !finished2, maybeFinalize);
|
|
10343
|
-
}, origin);
|
|
10349
|
+
}, origin, relayAuthors);
|
|
10344
10350
|
subscribedAny = true;
|
|
10345
10351
|
if (finished2) {
|
|
10346
10352
|
try {
|
|
@@ -10355,13 +10361,15 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10355
10361
|
incomplete = true;
|
|
10356
10362
|
}
|
|
10357
10363
|
}
|
|
10358
|
-
function attachMany(relayUrls2, origin) {
|
|
10359
|
-
for (const relayUrl2 of relayUrls2)
|
|
10364
|
+
function attachMany(relayUrls2, origin, authorsByRelay) {
|
|
10365
|
+
for (const relayUrl2 of relayUrls2) {
|
|
10366
|
+
attachRelay(relayUrl2, origin, origin === "nip65" ? authorsByRelay?.get(relayUrl2) ?? [] : authors);
|
|
10367
|
+
}
|
|
10360
10368
|
}
|
|
10361
|
-
function attachHintedAndDiscovered(hintRelays,
|
|
10369
|
+
function attachHintedAndDiscovered(hintRelays, discovery) {
|
|
10362
10370
|
attachMany(hintRelays, "hint");
|
|
10363
|
-
attachMany(
|
|
10364
|
-
if (hintRelays.length === 0 &&
|
|
10371
|
+
attachMany(discovery.relays, "nip65", discovery.authorsByRelay);
|
|
10372
|
+
if (hintRelays.length === 0 && discovery.relays.length === 0) {
|
|
10365
10373
|
attachMany(allowed(ctx, ctx.fallbackRelays), "fallback");
|
|
10366
10374
|
}
|
|
10367
10375
|
}
|
|
@@ -10387,7 +10395,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10387
10395
|
const discovery = discoveredReadRelays(ctx, authors, loaded);
|
|
10388
10396
|
discoveryPending = false;
|
|
10389
10397
|
incomplete ||= discovery.missingAuthors.length > 0;
|
|
10390
|
-
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery
|
|
10398
|
+
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery);
|
|
10391
10399
|
maybeFinalize();
|
|
10392
10400
|
} else {
|
|
10393
10401
|
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
@@ -10397,7 +10405,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10397
10405
|
const discovery = discoveredReadRelays(ctx, authors, lists);
|
|
10398
10406
|
discoveryPending = false;
|
|
10399
10407
|
incomplete ||= discovery.missingAuthors.length > 0;
|
|
10400
|
-
attachMany(discovery.relays, "nip65");
|
|
10408
|
+
attachMany(discovery.relays, "nip65", discovery.authorsByRelay);
|
|
10401
10409
|
maybeFinalize();
|
|
10402
10410
|
}).catch(() => {
|
|
10403
10411
|
if (finished2) return;
|
|
@@ -10443,7 +10451,7 @@ function closeLiveSub(sub) {
|
|
|
10443
10451
|
}
|
|
10444
10452
|
sub.handles.clear();
|
|
10445
10453
|
}
|
|
10446
|
-
function attachLiveRelay(ctx, sub, filters, relayUrl2, sink,
|
|
10454
|
+
function attachLiveRelay(ctx, sub, filters, relayUrl2, sink, routing) {
|
|
10447
10455
|
if (sub.closed || sub.relays.has(relayUrl2)) return false;
|
|
10448
10456
|
sub.relays.add(relayUrl2);
|
|
10449
10457
|
try {
|
|
@@ -10455,7 +10463,7 @@ function attachLiveRelay(ctx, sub, filters, relayUrl2, sink, origin) {
|
|
|
10455
10463
|
sub.seen.add(item.id);
|
|
10456
10464
|
sink.event(createRelayEventResultWithHints(item, [relayUrl2]));
|
|
10457
10465
|
});
|
|
10458
|
-
}, origin);
|
|
10466
|
+
}, routing.origin, routing.authors);
|
|
10459
10467
|
if (sub.closed) {
|
|
10460
10468
|
try {
|
|
10461
10469
|
handle.unsubscribe();
|
|
@@ -10481,13 +10489,18 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10481
10489
|
};
|
|
10482
10490
|
let discoveryOpen = authors.length > 0;
|
|
10483
10491
|
let discoveryTimer;
|
|
10484
|
-
function attachMany(relayUrls2, origin) {
|
|
10485
|
-
for (const relayUrl2 of relayUrls2)
|
|
10492
|
+
function attachMany(relayUrls2, origin, authorsByRelay) {
|
|
10493
|
+
for (const relayUrl2 of relayUrls2) {
|
|
10494
|
+
attachLiveRelay(ctx, sub, filters, relayUrl2, sink, {
|
|
10495
|
+
origin,
|
|
10496
|
+
authors: origin === "nip65" ? authorsByRelay?.get(relayUrl2) ?? [] : authors
|
|
10497
|
+
});
|
|
10498
|
+
}
|
|
10486
10499
|
}
|
|
10487
|
-
function attachHintedAndDiscovered(hintRelays,
|
|
10500
|
+
function attachHintedAndDiscovered(hintRelays, discovery) {
|
|
10488
10501
|
attachMany(hintRelays, "hint");
|
|
10489
|
-
attachMany(
|
|
10490
|
-
if (hintRelays.length === 0 &&
|
|
10502
|
+
attachMany(discovery.relays, "nip65", discovery.authorsByRelay);
|
|
10503
|
+
if (hintRelays.length === 0 && discovery.relays.length === 0) {
|
|
10491
10504
|
attachMany(allowed(ctx, ctx.fallbackRelays), "fallback");
|
|
10492
10505
|
}
|
|
10493
10506
|
}
|
|
@@ -10517,7 +10530,7 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10517
10530
|
if (discoveryOpen && loaded instanceof Map) {
|
|
10518
10531
|
const discovery = discoveredReadRelays(ctx, authors, loaded);
|
|
10519
10532
|
discoveryOpen = false;
|
|
10520
|
-
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery
|
|
10533
|
+
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery);
|
|
10521
10534
|
closeUnavailable();
|
|
10522
10535
|
} else if (discoveryOpen) {
|
|
10523
10536
|
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
@@ -10530,7 +10543,8 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10530
10543
|
if (!discoveryOpen || sub.closed) return;
|
|
10531
10544
|
discoveryOpen = false;
|
|
10532
10545
|
clearTimeout(discoveryTimer);
|
|
10533
|
-
|
|
10546
|
+
const discovery = discoveredReadRelays(ctx, authors, lists);
|
|
10547
|
+
attachMany(discovery.relays, "nip65", discovery.authorsByRelay);
|
|
10534
10548
|
closeUnavailable();
|
|
10535
10549
|
}).catch(() => {
|
|
10536
10550
|
if (!discoveryOpen || sub.closed) return;
|
|
@@ -21613,6 +21627,10 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
21613
21627
|
if (relayUrls2.length === 0) return;
|
|
21614
21628
|
relayRequestObserver?.({ ...context, relayUrls: [...relayUrls2] });
|
|
21615
21629
|
};
|
|
21630
|
+
const attributeAuthors = (context, filters) => {
|
|
21631
|
+
const authors = readAuthors(context.authors ?? filters.flatMap((filter) => filter.authors ?? []));
|
|
21632
|
+
return authors.length === 0 && context.authors === void 0 ? context : { ...context, authors };
|
|
21633
|
+
};
|
|
21616
21634
|
const observeRelayEvent = (context, relayUrls2, event, source) => {
|
|
21617
21635
|
relayEventObserver?.({
|
|
21618
21636
|
...context,
|
|
@@ -21626,13 +21644,14 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
21626
21644
|
const query = async (relayUrls2, filters, maxWaitMs, context = { reason: "host" }) => {
|
|
21627
21645
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
21628
21646
|
if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
21629
|
-
|
|
21647
|
+
const readContext = attributeAuthors(context, filters);
|
|
21648
|
+
observeRelayRequest(readContext, relayUrls2);
|
|
21630
21649
|
const liveEvents = await queryPajaLive(
|
|
21631
21650
|
livePool,
|
|
21632
21651
|
relayUrls2,
|
|
21633
21652
|
filters,
|
|
21634
21653
|
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
21635
|
-
(event, source) => observeRelayEvent(
|
|
21654
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source)
|
|
21636
21655
|
);
|
|
21637
21656
|
const out = /* @__PURE__ */ new Map();
|
|
21638
21657
|
for (const event of [...cached, ...liveEvents]) out.set(event.id, event);
|
|
@@ -21641,13 +21660,14 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
21641
21660
|
const queryContactListCandidates = async (relayUrls2, filters, maxWaitMs, signal) => {
|
|
21642
21661
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
21643
21662
|
if (signal?.aborted || getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
21644
|
-
|
|
21663
|
+
const readContext = attributeAuthors({ reason: "host" }, filters);
|
|
21664
|
+
observeRelayRequest(readContext, relayUrls2);
|
|
21645
21665
|
const liveEvents = await queryPajaLive(
|
|
21646
21666
|
livePool,
|
|
21647
21667
|
relayUrls2,
|
|
21648
21668
|
filters,
|
|
21649
21669
|
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
21650
|
-
(event, source) => observeRelayEvent(
|
|
21670
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source),
|
|
21651
21671
|
true,
|
|
21652
21672
|
signal
|
|
21653
21673
|
);
|
|
@@ -21689,13 +21709,14 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
21689
21709
|
};
|
|
21690
21710
|
subscribers.add(subscriber);
|
|
21691
21711
|
for (const event of collectMemoryEvents(cachedEvents(), filters)) next(event);
|
|
21692
|
-
|
|
21712
|
+
const readContext = attributeAuthors(context, filters);
|
|
21713
|
+
if (getSimulation().relay.mode === "live") observeRelayRequest(readContext, relayUrls2);
|
|
21693
21714
|
const liveSub = getSimulation().relay.mode === "live" ? subscribePajaLive(
|
|
21694
21715
|
livePool,
|
|
21695
21716
|
relayUrls2,
|
|
21696
21717
|
filters,
|
|
21697
21718
|
subscriber.next,
|
|
21698
|
-
(event, source) => observeRelayEvent(
|
|
21719
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source),
|
|
21699
21720
|
PAJA_LIVE_QUERY_WAIT_MS
|
|
21700
21721
|
) : null;
|
|
21701
21722
|
queueMicrotask(() => {
|
|
@@ -21738,7 +21759,7 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
21738
21759
|
},
|
|
21739
21760
|
async countWithRelay(relayUrls2, filters) {
|
|
21740
21761
|
if (getSimulation().relay.mode !== "live") throw new Error("count unavailable");
|
|
21741
|
-
observeRelayRequest({ reason: "host" }, relayUrls2);
|
|
21762
|
+
observeRelayRequest(attributeAuthors({ reason: "host" }, filters), relayUrls2);
|
|
21742
21763
|
return countLive(livePool, relayUrls2, normalizedFilters(filters));
|
|
21743
21764
|
},
|
|
21744
21765
|
observedRelayUrls(eventId) {
|
|
@@ -21795,6 +21816,13 @@ function dedupeRelayUrls(urls) {
|
|
|
21795
21816
|
}
|
|
21796
21817
|
return [...out];
|
|
21797
21818
|
}
|
|
21819
|
+
function readAuthors(candidates) {
|
|
21820
|
+
const authors = /* @__PURE__ */ new Set();
|
|
21821
|
+
for (const author of candidates) {
|
|
21822
|
+
if (typeof author === "string" && /^[0-9a-f]{64}$/i.test(author)) authors.add(author.toLowerCase());
|
|
21823
|
+
}
|
|
21824
|
+
return [...authors];
|
|
21825
|
+
}
|
|
21798
21826
|
async function getSignerRelayUrls(signerProvider, direction) {
|
|
21799
21827
|
const signer = signerProvider?.getSigner();
|
|
21800
21828
|
if (!signer?.getRelays) return [];
|
|
@@ -21869,8 +21897,8 @@ function createPajaRelayListLoader(backend, getSimulation, signerProvider, getHo
|
|
|
21869
21897
|
}
|
|
21870
21898
|
function createPajaOutboxRelayPool(backend) {
|
|
21871
21899
|
return {
|
|
21872
|
-
subscribe(filters, relayUrls2, callback, origin) {
|
|
21873
|
-
return backend.subscription(relayUrls2, filters, { reason: "outbox", origin }).subscribe((item) => callback(item));
|
|
21900
|
+
subscribe(filters, relayUrls2, callback, origin, authors) {
|
|
21901
|
+
return backend.subscription(relayUrls2, filters, { reason: "outbox", origin, authors }).subscribe((item) => callback(item));
|
|
21874
21902
|
},
|
|
21875
21903
|
publish(event, relayUrls2) {
|
|
21876
21904
|
return backend.publishToRelays(relayUrls2, event);
|
|
@@ -24077,6 +24105,13 @@ function createDevTheme(mode, values) {
|
|
|
24077
24105
|
}
|
|
24078
24106
|
};
|
|
24079
24107
|
}
|
|
24108
|
+
var HEX_PUBKEY2 = /^[0-9a-f]{64}$/i;
|
|
24109
|
+
function getConnectedAccountPubkey(signerProvider) {
|
|
24110
|
+
const pubkey2 = signerProvider?.getPubkey();
|
|
24111
|
+
if (typeof pubkey2 === "string" && HEX_PUBKEY2.test(pubkey2)) return pubkey2.toLowerCase();
|
|
24112
|
+
if (signerProvider?.getMethod() === "dev") return PAJA_DEV_SIGNER_PUBKEY;
|
|
24113
|
+
return null;
|
|
24114
|
+
}
|
|
24080
24115
|
function createDevServices(backend, getSimulation, relayConfig, onThemeService, onThemeBroadcast, confirmRequest, getConfiguredBlossomServers, uploadRuntime, signerProvider, getIdentity, userActivation, notifyOptions, configOptions, getSignerSource) {
|
|
24081
24116
|
const scopeFor = (windowId, isCurrent) => createPajaWindowScope({
|
|
24082
24117
|
backend,
|
|
@@ -24113,7 +24148,10 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
24113
24148
|
baseRouter: baseOutboxRouter,
|
|
24114
24149
|
loadContactList: createPajaContactListLoader(backend, getSimulation, signerProvider, getReadRelays),
|
|
24115
24150
|
verifyEvent: (event) => verifyEvent(event),
|
|
24116
|
-
|
|
24151
|
+
// Background warming is speculative relay traffic, so it only runs for a
|
|
24152
|
+
// signer account. `getFollows` still answers on demand for any requested
|
|
24153
|
+
// pubkey, including the fixed simulation identity.
|
|
24154
|
+
getActivePubkey: () => getConnectedAccountPubkey(signerProvider),
|
|
24117
24155
|
subscribeSignerChange: signerProvider?.subscribe?.bind(signerProvider)
|
|
24118
24156
|
});
|
|
24119
24157
|
const commonBackend = createPajaCommonBackend({
|
|
@@ -24518,7 +24556,7 @@ function boxKindFor(reason, origin) {
|
|
|
24518
24556
|
return reason === "hint" ? "scoped" : "host";
|
|
24519
24557
|
}
|
|
24520
24558
|
function emptyBox() {
|
|
24521
|
-
return { count: 0, reads: /* @__PURE__ */ new Map(), relays: /* @__PURE__ */ new Map() };
|
|
24559
|
+
return { count: 0, reads: /* @__PURE__ */ new Map(), authors: /* @__PURE__ */ new Map(), relays: /* @__PURE__ */ new Map() };
|
|
24522
24560
|
}
|
|
24523
24561
|
function distinctRelayUrls(urls) {
|
|
24524
24562
|
const unique = /* @__PURE__ */ new Map();
|
|
@@ -24529,6 +24567,13 @@ function distinctRelayUrls(urls) {
|
|
|
24529
24567
|
}
|
|
24530
24568
|
return [...unique.values()];
|
|
24531
24569
|
}
|
|
24570
|
+
function distinctAuthors(authors) {
|
|
24571
|
+
const unique = /* @__PURE__ */ new Set();
|
|
24572
|
+
for (const author of authors ?? []) {
|
|
24573
|
+
if (typeof author === "string" && author.length > 0) unique.add(author.toLowerCase());
|
|
24574
|
+
}
|
|
24575
|
+
return [...unique];
|
|
24576
|
+
}
|
|
24532
24577
|
function createPajaRelayEventCounter(onChange) {
|
|
24533
24578
|
const boxes = /* @__PURE__ */ new Map();
|
|
24534
24579
|
const eventIds = /* @__PURE__ */ new Set();
|
|
@@ -24541,6 +24586,12 @@ function createPajaRelayEventCounter(onChange) {
|
|
|
24541
24586
|
}
|
|
24542
24587
|
return box;
|
|
24543
24588
|
};
|
|
24589
|
+
const attributeAuthors = (kind, authors) => {
|
|
24590
|
+
const box = boxFor(kind);
|
|
24591
|
+
for (const author of distinctAuthors(authors)) {
|
|
24592
|
+
box.authors.set(author, (box.authors.get(author) ?? 0) + 1);
|
|
24593
|
+
}
|
|
24594
|
+
};
|
|
24544
24595
|
const relayFor = (kind, relayUrl2) => {
|
|
24545
24596
|
const box = boxFor(kind);
|
|
24546
24597
|
const key = normalizeURL2(relayUrl2);
|
|
@@ -24588,13 +24639,14 @@ function createPajaRelayEventCounter(onChange) {
|
|
|
24588
24639
|
reason: spec.reason,
|
|
24589
24640
|
...spec.origin ? { origin: spec.origin } : {},
|
|
24590
24641
|
count: box?.count ?? 0,
|
|
24642
|
+
authors: [...box?.authors.entries() ?? []].sort(([leftKey, leftCount], [rightKey, rightCount]) => rightCount - leftCount || leftKey.localeCompare(rightKey)).map(([pubkey2, count]) => ({ pubkey: pubkey2, count })),
|
|
24591
24643
|
relays,
|
|
24592
24644
|
...relays.length === 0 && spec.emptyNote ? { emptyNote: spec.emptyNote } : {}
|
|
24593
24645
|
});
|
|
24594
24646
|
}
|
|
24595
24647
|
return out;
|
|
24596
24648
|
},
|
|
24597
|
-
recordRead(reason, relayUrls2, origin) {
|
|
24649
|
+
recordRead(reason, relayUrls2, origin, authors) {
|
|
24598
24650
|
const kind = boxKindFor(reason, origin);
|
|
24599
24651
|
const box = boxFor(kind);
|
|
24600
24652
|
let changed = false;
|
|
@@ -24604,7 +24656,10 @@ function createPajaRelayEventCounter(onChange) {
|
|
|
24604
24656
|
relayFor(kind, relayUrl2);
|
|
24605
24657
|
changed = true;
|
|
24606
24658
|
}
|
|
24607
|
-
if (changed)
|
|
24659
|
+
if (changed) {
|
|
24660
|
+
attributeAuthors(kind, authors);
|
|
24661
|
+
onChange?.();
|
|
24662
|
+
}
|
|
24608
24663
|
},
|
|
24609
24664
|
recordEvent(reason, event, sightedOn, origin) {
|
|
24610
24665
|
if (typeof event !== "object" || event === null) return;
|
|
@@ -24641,6 +24696,23 @@ function installPajaEventCounterReset(counter) {
|
|
|
24641
24696
|
button2?.addEventListener("click", onClick);
|
|
24642
24697
|
return () => button2?.removeEventListener("click", onClick);
|
|
24643
24698
|
}
|
|
24699
|
+
function renderBoxAuthors(authors) {
|
|
24700
|
+
const row = document.createElement("div");
|
|
24701
|
+
row.className = "event-box-authors";
|
|
24702
|
+
row.replaceChildren(...authors.map(({ pubkey: pubkey2, count }) => {
|
|
24703
|
+
const chip = document.createElement("span");
|
|
24704
|
+
chip.className = "event-author";
|
|
24705
|
+
chip.dataset.authorPubkey = pubkey2;
|
|
24706
|
+
chip.dataset.authorReads = String(count);
|
|
24707
|
+
chip.textContent = count > 1 ? `${shortPubkey(pubkey2)} \xB7 ${count}` : shortPubkey(pubkey2);
|
|
24708
|
+
chip.title = count > 1 ? `${pubkey2} \xB7 routed ${count} reads into this box` : `${pubkey2} \xB7 routed 1 read into this box`;
|
|
24709
|
+
return chip;
|
|
24710
|
+
}));
|
|
24711
|
+
return row;
|
|
24712
|
+
}
|
|
24713
|
+
function shortPubkey(pubkey2) {
|
|
24714
|
+
return pubkey2.length > 12 ? `${pubkey2.slice(0, 8)}\u2026${pubkey2.slice(-4)}` : pubkey2;
|
|
24715
|
+
}
|
|
24644
24716
|
function renderPajaEventKindCounts(counter, inventory) {
|
|
24645
24717
|
const container = document.getElementById("event-kind-counts");
|
|
24646
24718
|
const total = document.getElementById("event-kind-total");
|
|
@@ -24673,6 +24745,7 @@ function renderPajaEventKindCounts(counter, inventory) {
|
|
|
24673
24745
|
boxCount.textContent = box.relays.length === 0 ? box.emptyNote ?? "0" : String(box.count);
|
|
24674
24746
|
head.append(name, boxCount);
|
|
24675
24747
|
section.append(head);
|
|
24748
|
+
if (box.authors.length > 0) section.append(renderBoxAuthors(box.authors));
|
|
24676
24749
|
for (const relay of box.relays) {
|
|
24677
24750
|
const row = document.createElement("div");
|
|
24678
24751
|
row.className = "event-relay";
|
|
@@ -25350,11 +25423,11 @@ function createNipEncryptionMethods(state, prefix) {
|
|
|
25350
25423
|
decrypt: async (pubkey2, ciphertext) => sendRequestWithId(state, crypto.randomUUID(), `${prefix}_decrypt`, [pubkey2, ciphertext])
|
|
25351
25424
|
};
|
|
25352
25425
|
}
|
|
25353
|
-
var
|
|
25426
|
+
var HEX_PUBKEY3 = /^[0-9a-f]{64}$/i;
|
|
25354
25427
|
function readPubkey(value) {
|
|
25355
25428
|
if (typeof value === "string") {
|
|
25356
25429
|
const normalized = value.trim().toLowerCase();
|
|
25357
|
-
return
|
|
25430
|
+
return HEX_PUBKEY3.test(normalized) ? normalized : null;
|
|
25358
25431
|
}
|
|
25359
25432
|
if (value && typeof value === "object" && "pubkey" in value) {
|
|
25360
25433
|
return readPubkey(value.pubkey);
|
|
@@ -29280,7 +29353,7 @@ async function installPajaHost() {
|
|
|
29280
29353
|
relayEventCounts.recordEvent(sighting.reason, sighting.event, sighting.sightedOn, sighting.origin);
|
|
29281
29354
|
});
|
|
29282
29355
|
relayBackend?.setRelayRequestObserver((request) => {
|
|
29283
|
-
relayEventCounts.recordRead(request.reason, request.relayUrls, request.origin);
|
|
29356
|
+
relayEventCounts.recordRead(request.reason, request.relayUrls, request.origin, request.authors);
|
|
29284
29357
|
});
|
|
29285
29358
|
await adapter.ready;
|
|
29286
29359
|
const bridge = createShellBridge(adapter);
|