@kehto/paja 0.24.5 → 0.25.0

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.
@@ -19893,13 +19893,13 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
19893
19893
  if (matchesAnyFilter2(event, subscriber.filters)) subscriber.next(event);
19894
19894
  }
19895
19895
  }
19896
- async function attemptPublish(relayUrls2, event) {
19896
+ async function attemptPublish(relayUrls2, event, signerContext) {
19897
19897
  const simulation = getSimulation();
19898
19898
  const rejected2 = Object.fromEntries(relayUrls2.map((url) => [url, false]));
19899
19899
  if (simulation.relay.mode === "disabled") {
19900
19900
  return { outcomes: rejected2, error: "relay unavailable" };
19901
19901
  }
19902
- if (!await confirmRequest({ action: "publish", event })) {
19902
+ if (signerContext?.isCurrent && !signerContext.isCurrent() || !await confirmRequest({ action: "publish", event, ...signerContext ? { signerContext } : {} }) || signerContext?.isCurrent && !signerContext.isCurrent()) {
19903
19903
  return { outcomes: rejected2, error: "publish denied" };
19904
19904
  }
19905
19905
  const outcomes = simulation.relay.mode === "live" ? await publishLive(livePool, relayUrls2, event) : Object.fromEntries(relayUrls2.map((url) => [url, true]));
@@ -19941,8 +19941,8 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
19941
19941
  }
19942
19942
  };
19943
19943
  },
19944
- async publish(relayUrls2, event) {
19945
- const attempt = await attemptPublish(relayUrls2, event);
19944
+ async publish(relayUrls2, event, signerContext) {
19945
+ const attempt = await attemptPublish(relayUrls2, event, signerContext);
19946
19946
  if (attempt.error) throw new Error(attempt.error);
19947
19947
  },
19948
19948
  request(relayUrls2, filtersInput, context = { reason: "host" }) {
@@ -19982,8 +19982,8 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
19982
19982
  relayRequestObserver = observer;
19983
19983
  },
19984
19984
  query,
19985
- async publishToRelays(relayUrls2, event) {
19986
- return (await attemptPublish(relayUrls2, event)).outcomes;
19985
+ async publishToRelays(relayUrls2, event, signerContext) {
19986
+ return (await attemptPublish(relayUrls2, event, signerContext)).outcomes;
19987
19987
  },
19988
19988
  async publishWebrtcSignal(relayUrls2, event) {
19989
19989
  if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0 || event.kind !== PAJA_WEBRTC_SIGNAL_KIND || !verifyEvent(event)) {
@@ -20415,7 +20415,7 @@ function createPajaRelayConfig(getSimulation) {
20415
20415
  refresh();
20416
20416
  return runtime;
20417
20417
  }
20418
- function createPajaRelayHooks(pool, getSimulation, relayConfig) {
20418
+ function createPajaRelayHooks(pool, getSimulation, relayConfig, getPublishPool = () => pool) {
20419
20419
  const cleanups = /* @__PURE__ */ new Map();
20420
20420
  const scoped = /* @__PURE__ */ new Map();
20421
20421
  function closeScopedRelay(windowId) {
@@ -20462,7 +20462,7 @@ function createPajaRelayHooks(pool, getSimulation, relayConfig) {
20462
20462
  const active = scoped.get(windowId);
20463
20463
  if (getSimulation().relay.mode !== "live" || !active || !verifyEvent(event)) return false;
20464
20464
  try {
20465
- await pool.publish([active.relayUrl], event);
20465
+ await getPublishPool(windowId).publish([active.relayUrl], event);
20466
20466
  return true;
20467
20467
  } catch {
20468
20468
  return false;
@@ -21050,7 +21050,7 @@ var BrowserWebrtcController = class {
21050
21050
  if (this.windowSessionCount(context.windowId) >= PAJA_WEBRTC_MAX_SESSIONS_PER_WINDOW) {
21051
21051
  throw new Error("session limit reached");
21052
21052
  }
21053
- const signer = this.requireSigner();
21053
+ const signer = this.requireSigner(context.windowId);
21054
21054
  const localPubkey = normalizePubkey3(await signer.getPublicKey());
21055
21055
  if (!localPubkey || localPubkey !== normalizePubkey3(this.options.getPubkey())) throw new Error("signaling unavailable");
21056
21056
  const identity = this.options.getIdentity(context.windowId);
@@ -21292,13 +21292,13 @@ var BrowserWebrtcController = class {
21292
21292
  if (!session || session.windowId !== windowId) throw new Error("session not found");
21293
21293
  return session;
21294
21294
  }
21295
- requireSigner() {
21296
- const signer = this.options.getSigner();
21295
+ requireSigner(windowId) {
21296
+ const signer = this.options.getSigner(windowId);
21297
21297
  if (!isSignalingSigner(signer)) throw new Error("signaling unavailable");
21298
21298
  return signer;
21299
21299
  }
21300
21300
  requireSessionSigner(session) {
21301
- const signer = this.requireSigner();
21301
+ const signer = this.requireSigner(session.windowId);
21302
21302
  if (normalizePubkey3(this.options.getPubkey()) !== session.localPubkey) throw new Error("signaling unavailable");
21303
21303
  return signer;
21304
21304
  }
@@ -22051,6 +22051,7 @@ function createPajaDevSigner(getSimulation, confirm, source) {
22051
22051
  getPublicKey: () => PAJA_DEV_SIGNER_PUBKEY,
22052
22052
  getRelays: () => Object.fromEntries(getPajaRelayUrls(getSimulation()).map((relay) => [relay, { read: true, write: true }])),
22053
22053
  async signEvent(event) {
22054
+ if (source?.isCurrent && !source.isCurrent()) throw new Error("Paja signing source changed");
22054
22055
  const signerContext = source ? { ...source, signerPubkey: PAJA_DEV_SIGNER_PUBKEY } : void 0;
22055
22056
  if (!await confirm({
22056
22057
  action: "sign",
@@ -22059,6 +22060,7 @@ function createPajaDevSigner(getSimulation, confirm, source) {
22059
22060
  })) {
22060
22061
  throw new Error("Paja signing request denied");
22061
22062
  }
22063
+ if (source?.isCurrent && !source.isCurrent()) throw new Error("Paja signing source changed");
22062
22064
  const template = { ...event };
22063
22065
  template.created_at ??= Math.floor(Date.now() / 1e3);
22064
22066
  template.tags ??= [];
@@ -22121,7 +22123,115 @@ function createPajaWorkerRelay(events) {
22121
22123
  };
22122
22124
  }
22123
22125
 
22124
- // src/browser-adapter.ts
22126
+ // src/browser-operation-scope.ts
22127
+ var documentId = Array.from(crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, "0")).join("");
22128
+ function pajaDevelopmentConsentScope(url, windowId) {
22129
+ return `target-url:${url}|load:${documentId}:${windowId}`;
22130
+ }
22131
+ function scopePajaService(base, types, create, scopeKey) {
22132
+ const windows = /* @__PURE__ */ new Map();
22133
+ let runtime;
22134
+ let attached = true;
22135
+ return {
22136
+ ...base,
22137
+ onRegistered(context) {
22138
+ runtime = context;
22139
+ attached = true;
22140
+ base.onRegistered?.(context);
22141
+ },
22142
+ handleMessage(windowId, message2, send) {
22143
+ if (!attached) return;
22144
+ if (!types.includes(message2.type)) return base.handleMessage(windowId, message2, send);
22145
+ let entry = windows.get(windowId);
22146
+ const key = scopeKey?.(windowId);
22147
+ if (entry && entry.key !== key) {
22148
+ entry.active = false;
22149
+ entry.service.onWindowDestroyed?.(windowId);
22150
+ entry.service.onUnregistered?.();
22151
+ windows.delete(windowId);
22152
+ entry = void 0;
22153
+ }
22154
+ if (!entry) {
22155
+ const state = { active: true, key };
22156
+ const service = create(windowId, () => attached && state.active && (!runtime || runtime.listWindowIds().includes(windowId)));
22157
+ entry = Object.assign(state, { service });
22158
+ windows.set(windowId, entry);
22159
+ if (runtime) service.onRegistered?.(runtime);
22160
+ }
22161
+ entry.service.handleMessage(windowId, message2, send);
22162
+ },
22163
+ onWindowDestroyed(windowId) {
22164
+ const entry = windows.get(windowId);
22165
+ if (entry) {
22166
+ entry.active = false;
22167
+ entry.service.onWindowDestroyed?.(windowId);
22168
+ entry.service.onUnregistered?.();
22169
+ windows.delete(windowId);
22170
+ }
22171
+ base.onWindowDestroyed?.(windowId);
22172
+ },
22173
+ onCapabilityRevoked(windowId, capability) {
22174
+ const entry = windows.get(windowId);
22175
+ if (entry) {
22176
+ entry.active = false;
22177
+ entry.service.onCapabilityRevoked?.(windowId, capability);
22178
+ entry.service.onWindowDestroyed?.(windowId);
22179
+ entry.service.onUnregistered?.();
22180
+ windows.delete(windowId);
22181
+ }
22182
+ base.onCapabilityRevoked?.(windowId, capability);
22183
+ },
22184
+ onUnregistered() {
22185
+ attached = false;
22186
+ for (const [windowId, entry] of windows) {
22187
+ entry.active = false;
22188
+ entry.service.onWindowDestroyed?.(windowId);
22189
+ entry.service.onUnregistered?.();
22190
+ }
22191
+ windows.clear();
22192
+ base.onUnregistered?.();
22193
+ }
22194
+ };
22195
+ }
22196
+ function scopePajaRelayBackend(base, context) {
22197
+ const current = async () => {
22198
+ const value = await context();
22199
+ if (value?.isCurrent && !value.isCurrent()) throw new Error("Paja publication source changed");
22200
+ return value;
22201
+ };
22202
+ return {
22203
+ ...base,
22204
+ async publish(relays, event) {
22205
+ return base.publish(relays, event, await current());
22206
+ },
22207
+ async publishToRelays(relays, event) {
22208
+ return base.publishToRelays(relays, event, await current());
22209
+ }
22210
+ };
22211
+ }
22212
+ function createPajaWindowScope(options) {
22213
+ const account = options.getPubkey();
22214
+ const source = {
22215
+ ...options.source,
22216
+ isCurrent: () => options.isCurrent() && account === options.getPubkey() && (!options.source.isCurrent || options.source.isCurrent())
22217
+ };
22218
+ const getSigner = () => options.getSigner(source);
22219
+ return {
22220
+ source,
22221
+ getSigner,
22222
+ backend: scopePajaRelayBackend(options.backend, async () => {
22223
+ if (!source.isCurrent?.()) throw new Error("Paja publication source changed");
22224
+ const signerPubkey = await getSigner()?.getPublicKey?.();
22225
+ if (!signerPubkey || !account) return {
22226
+ ...source,
22227
+ signerPubkey: "host-generated",
22228
+ runtimeScope: `${source.runtimeScope}|host-session:${documentId}`
22229
+ };
22230
+ if (signerPubkey.toLowerCase() !== account.toLowerCase()) throw new Error("Paja signer account changed");
22231
+ return { ...source, signerPubkey };
22232
+ })
22233
+ };
22234
+ }
22125
22235
  function createPajaCvmRelayPool(backend) {
22126
22236
  return {
22127
22237
  subscribe(relays, filter, params) {
@@ -22141,7 +22251,29 @@ function createPajaCvmRelayPool(backend) {
22141
22251
  }
22142
22252
  };
22143
22253
  }
22144
- function createOutboxRouter(backend, getSimulation, relayConfig, confirmRequest, signerProvider) {
22254
+ function getRuntimePubkey(getSimulation, signerProvider) {
22255
+ return signerProvider?.getPubkey() || (signerProvider?.getMethod() === "dev" ? PAJA_DEV_SIGNER_PUBKEY : "") || getSimulation().identity.pubkey;
22256
+ }
22257
+ function createRuntimeSigner(getSimulation, confirmRequest, signerProvider, source) {
22258
+ const signer = signerProvider?.getSigner(source);
22259
+ if (!signer) {
22260
+ if (signerProvider?.getMethod() === "dev") {
22261
+ return createPajaDevSigner(getSimulation, confirmRequest, source);
22262
+ }
22263
+ const fixedPubkey = getSimulation().identity.pubkey;
22264
+ if (fixedPubkey) {
22265
+ return {
22266
+ getPublicKey: () => fixedPubkey,
22267
+ getRelays: () => Object.fromEntries(getPajaRelayUrls(getSimulation()).map((relay) => [relay, { read: true, write: true }]))
22268
+ };
22269
+ }
22270
+ return null;
22271
+ }
22272
+ return signer;
22273
+ }
22274
+
22275
+ // src/browser-adapter.ts
22276
+ function createOutboxRouter(backend, getSimulation, relayConfig, confirmRequest, signerProvider, source) {
22145
22277
  return createRelayPoolOutboxRouter({
22146
22278
  relayPool: createPajaOutboxRelayPool(backend),
22147
22279
  loadRelayLists: createPajaRelayListLoader(
@@ -22152,7 +22284,7 @@ function createOutboxRouter(backend, getSimulation, relayConfig, confirmRequest,
22152
22284
  ),
22153
22285
  fallbackRelays: relayConfig.outboxRelays,
22154
22286
  signEvent: async (template) => {
22155
- const signer = createRuntimeSigner(getSimulation, confirmRequest, signerProvider);
22287
+ const signer = createRuntimeSigner(getSimulation, confirmRequest, signerProvider, source);
22156
22288
  if (!signer?.signEvent) throw new Error("no signer configured");
22157
22289
  const event = { ...template };
22158
22290
  event.created_at ??= Math.floor(Date.now() / 1e3);
@@ -22176,27 +22308,23 @@ function createDevTheme(mode, values) {
22176
22308
  }
22177
22309
  };
22178
22310
  }
22179
- function getRuntimePubkey(getSimulation, signerProvider) {
22180
- return signerProvider?.getPubkey() || (signerProvider?.getMethod() === "dev" ? PAJA_DEV_SIGNER_PUBKEY : "") || getSimulation().identity.pubkey;
22181
- }
22182
- function createRuntimeSigner(getSimulation, confirmRequest, signerProvider, source) {
22183
- const signer = signerProvider?.getSigner(source);
22184
- if (!signer) {
22185
- if (signerProvider?.getMethod() === "dev") {
22186
- return createPajaDevSigner(getSimulation, confirmRequest, source);
22187
- }
22188
- const fixedPubkey = getSimulation().identity.pubkey;
22189
- if (fixedPubkey) {
22190
- return {
22191
- getPublicKey: () => fixedPubkey,
22192
- getRelays: () => Object.fromEntries(getPajaRelayUrls(getSimulation()).map((relay) => [relay, { read: true, write: true }]))
22193
- };
22194
- }
22195
- return null;
22196
- }
22197
- return signer;
22198
- }
22199
- function createDevServices(backend, getSimulation, relayConfig, onThemeService, onThemeBroadcast, confirmRequest, getConfiguredBlossomServers, uploadRuntime, signerProvider, getIdentity, userActivation, notifyOptions, configOptions) {
22311
+ function createDevServices(backend, getSimulation, relayConfig, onThemeService, onThemeBroadcast, confirmRequest, getConfiguredBlossomServers, uploadRuntime, signerProvider, getIdentity, userActivation, notifyOptions, configOptions, getSignerSource) {
22312
+ const scopeFor = (windowId, isCurrent) => createPajaWindowScope({
22313
+ backend,
22314
+ source: getSignerSource?.(windowId) ?? {
22315
+ windowId,
22316
+ napplet: getIdentity?.(windowId) ?? { dTag: "dev-target", aggregateHash: "paja" },
22317
+ runtimeScope: `window:${windowId}`
22318
+ },
22319
+ isCurrent,
22320
+ getPubkey: () => getRuntimePubkey(getSimulation, signerProvider),
22321
+ getSigner: (source) => createRuntimeSigner(getSimulation, confirmRequest, signerProvider, source)
22322
+ });
22323
+ const scopeKey = (windowId) => JSON.stringify([
22324
+ getSignerSource?.(windowId).runtimeScope,
22325
+ getIdentity?.(windowId).aggregateHash,
22326
+ getRuntimePubkey(getSimulation, signerProvider)
22327
+ ]);
22200
22328
  const theme = createThemeService({
22201
22329
  initialTheme: createDevTheme(getSimulation().theme.mode, getSimulation().theme.values),
22202
22330
  onBroadcast: onThemeBroadcast
@@ -22253,7 +22381,7 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22253
22381
  services.keys = createKeysService({ listenerTarget: document });
22254
22382
  }
22255
22383
  if (getSimulation().relay.mode === "live") {
22256
- services.relay = createRelayPoolService({
22384
+ const relayOptions = {
22257
22385
  subscribe: (filters, callback, relayUrls2, fromHint) => backend.subscription(
22258
22386
  (relayUrls2 ?? getReadRelays()).filter((url) => isPajaRelayAllowed(url, getAllRelays)),
22259
22387
  filters,
@@ -22266,11 +22394,19 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22266
22394
  );
22267
22395
  }
22268
22396
  }),
22269
- publish: (event) => backend.publish(getWriteRelays(), event),
22270
22397
  selectRelayTier: getReadRelays,
22271
22398
  isAvailable: () => backend.isAvailable()
22272
- });
22273
- services.outbox = createOutboxService({
22399
+ };
22400
+ services.relay = scopePajaService(
22401
+ createRelayPoolService({ ...relayOptions, publish: (event) => backend.publish(getWriteRelays(), event) }),
22402
+ ["relay.publish", "relay.publishEncrypted"],
22403
+ (windowId, isCurrent) => {
22404
+ const scope = scopeFor(windowId, isCurrent);
22405
+ return createRelayPoolService({ ...relayOptions, publish: (event) => scope.backend.publish(getWriteRelays(), event) });
22406
+ },
22407
+ scopeKey
22408
+ );
22409
+ const outboxOptions = {
22274
22410
  router: baseOutboxRouter,
22275
22411
  getReadRouter: (windowId) => blossomEventResolver.decorate(baseOutboxRouter, windowId),
22276
22412
  getQueryRouter: (windowId, context) => blossomEventResolver.decorate(
@@ -22280,7 +22416,14 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22280
22416
  ),
22281
22417
  windowId
22282
22418
  )
22283
- });
22419
+ };
22420
+ services.outbox = scopePajaService(createOutboxService(outboxOptions), ["outbox.publish"], (windowId, isCurrent) => {
22421
+ const scope = scopeFor(windowId, isCurrent);
22422
+ return createOutboxService({
22423
+ ...outboxOptions,
22424
+ router: createOutboxRouter(scope.backend, getSimulation, relayConfig, confirmRequest, signerProvider, scope.source)
22425
+ });
22426
+ }, scopeKey);
22284
22427
  }
22285
22428
  if (getSimulation().capabilities.domains.count && getSimulation().relay.mode === "live") {
22286
22429
  services.count = createCountService({
@@ -22322,13 +22465,17 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22322
22465
  if (getSimulation().capabilities.domains.theme) services.theme = theme.handler;
22323
22466
  if (getSimulation().capabilities.domains.config && config) services.config = config.handler;
22324
22467
  if (getSimulation().cvm.enabled && getSimulation().relay.mode === "live" && backend.isAvailable()) {
22325
- services.cvm = createCvmService({
22326
- transport: createNostrCvmTransport({
22327
- defaultRelays: relayConfig.allRelays,
22328
- pool: createPajaCvmRelayPool(backend),
22329
- clientInfo: { name: "@kehto/paja", version: "0.11.0" }
22330
- })
22331
- });
22468
+ const cvm = (relay) => {
22469
+ const service = createCvmService({
22470
+ transport: createNostrCvmTransport({
22471
+ defaultRelays: relayConfig.allRelays,
22472
+ pool: createPajaCvmRelayPool(relay),
22473
+ clientInfo: { name: "@kehto/paja", version: "0.11.0" }
22474
+ })
22475
+ });
22476
+ return { ...service, onUnregistered: () => service.dispose() };
22477
+ };
22478
+ services.cvm = scopePajaService(cvm(backend), ["cvm.request", "cvm.close"], (windowId, isCurrent) => cvm(scopeFor(windowId, isCurrent).backend), scopeKey);
22332
22479
  }
22333
22480
  if (uploadRuntime) {
22334
22481
  services.upload = createUploadService({
@@ -22340,33 +22487,46 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22340
22487
  services.link = createLinkService({
22341
22488
  open: async ({ windowId, url, options }) => {
22342
22489
  const napplet = getIdentity?.(windowId) ?? { dTag: "dev-target", aggregateHash: "paja" };
22343
- const allowed2 = await confirmRequest({
22490
+ const request = {
22344
22491
  action: "link",
22345
22492
  windowId,
22346
22493
  napplet,
22347
22494
  url: url.href,
22348
- ...options?.label ? { label: options.label } : {}
22349
- });
22350
- return { status: allowed2 && openPajaExternalLink(url) ? "opened" : "denied" };
22495
+ ...options?.label ? { label: options.label } : {},
22496
+ isCurrent: () => (!("isCurrent" in napplet) || typeof napplet.isCurrent !== "function" || napplet.isCurrent()) && (getIdentity?.(windowId).aggregateHash ?? napplet.aggregateHash) === napplet.aggregateHash
22497
+ };
22498
+ const open = () => request.isCurrent?.() !== false && openPajaExternalLink(url);
22499
+ try {
22500
+ const opened = userActivation ? await userActivation.run(request, open) : await confirmRequest(request) && open();
22501
+ return { status: opened ? "opened" : "denied" };
22502
+ } catch {
22503
+ return { status: "denied" };
22504
+ }
22351
22505
  }
22352
22506
  });
22353
22507
  }
22354
22508
  if (getSimulation().capabilities.domains.common && getSimulation().relay.mode === "live") {
22355
- services.common = createCommonService({
22509
+ services.common = scopePajaService(createCommonService({
22356
22510
  getProfile: (target) => commonBackend.getProfile(target),
22357
22511
  follows: () => commonBackend.follows(),
22358
22512
  follow: (pubkeys) => commonBackend.follow(pubkeys),
22359
22513
  unfollow: (pubkeys) => commonBackend.unfollow(pubkeys),
22360
22514
  react: (targetEventId, reaction, customEmojiHref) => commonBackend.react(targetEventId, reaction, customEmojiHref),
22361
22515
  report: (target, reason, text) => commonBackend.report(target, reason, text)
22362
- });
22516
+ }), ["common.follow", "common.unfollow", "common.react", "common.report"], (windowId, isCurrent) => {
22517
+ const scope = scopeFor(windowId, isCurrent);
22518
+ return createCommonService(createPajaCommonBackend({ relay: scope.backend, getRelays: getAllRelays, getSigner: scope.getSigner }));
22519
+ }, scopeKey);
22363
22520
  }
22364
22521
  if (getSimulation().capabilities.domains.lists && getSimulation().relay.mode === "live") {
22365
- services.lists = createListsService({
22522
+ services.lists = scopePajaService(createListsService({
22366
22523
  supported: () => listsBackend.supported(),
22367
22524
  add: (list, items, options) => listsBackend.add(list, items, options),
22368
22525
  remove: (list, items, options) => listsBackend.remove(list, items, options)
22369
- });
22526
+ }), ["lists.add", "lists.remove"], (windowId, isCurrent) => {
22527
+ const scope = scopeFor(windowId, isCurrent);
22528
+ return createListsService(createPajaListsBackend({ relay: scope.backend, getRelays: getAllRelays, getSigner: scope.getSigner }));
22529
+ }, scopeKey);
22370
22530
  }
22371
22531
  if (getSimulation().capabilities.domains.serial) {
22372
22532
  const controller = userActivation ? createBrowserSerialController(userActivation) : null;
@@ -22386,7 +22546,7 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
22386
22546
  },
22387
22547
  publish: (event) => backend.publishWebrtcSignal(getAllRelays(), event)
22388
22548
  },
22389
- getSigner: () => createRuntimeSigner(getSimulation, confirmRequest, signerProvider),
22549
+ getSigner: (windowId) => createRuntimeSigner(getSimulation, confirmRequest, signerProvider, windowId ? getSignerSource?.(windowId) : void 0),
22390
22550
  getPubkey: () => getRuntimePubkey(getSimulation, signerProvider),
22391
22551
  getIdentity: getIdentity ?? (() => ({ dTag: "dev-target", aggregateHash: "paja" })),
22392
22552
  confirm: confirmRequest
@@ -22429,10 +22589,16 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
22429
22589
  };
22430
22590
  const signerSource = (windowId) => {
22431
22591
  const napplet = resolveIdentity(windowId);
22592
+ const account = getRuntimePubkey(getSimulation, signerProvider);
22593
+ const runtimeScope = "consentScope" in napplet && typeof napplet.consentScope === "string" ? napplet.consentScope : config.target?.mode === "iframe-url" ? pajaDevelopmentConsentScope(config.target.url, windowId) : `artifact:${napplet.aggregateHash}`;
22432
22594
  return {
22433
22595
  windowId,
22434
22596
  napplet,
22435
- runtimeScope: config.target?.mode === "iframe-url" ? `target-url:${config.target.url}` : `artifact:${napplet.aggregateHash}`
22597
+ runtimeScope,
22598
+ isCurrent: () => {
22599
+ const current = resolveIdentity(windowId);
22600
+ return (!("isCurrent" in napplet) || typeof napplet.isCurrent !== "function" || napplet.isCurrent()) && account === getRuntimePubkey(getSimulation, signerProvider) && current.dTag === napplet.dTag && current.aggregateHash === napplet.aggregateHash && (!("consentScope" in napplet) || "consentScope" in current && current.consentScope === napplet.consentScope);
22601
+ }
22436
22602
  };
22437
22603
  };
22438
22604
  const relayBackend = createPajaRelayBackend(getSimulation, confirmRequest);
@@ -22467,7 +22633,8 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
22467
22633
  resolveIdentity,
22468
22634
  userActivation,
22469
22635
  notifyOptions,
22470
- configOptions
22636
+ configOptions,
22637
+ signerSource
22471
22638
  );
22472
22639
  const services = serviceBundle.services;
22473
22640
  const ready = createPajaBrowserFsBackend({
@@ -22491,7 +22658,13 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
22491
22658
  notifyIntentChanged: () => {
22492
22659
  },
22493
22660
  setWindowBlossomServers: serviceBundle.setWindowBlossomServers,
22494
- relayPool: createPajaRelayHooks(relayBackend, getSimulation, relayConfig),
22661
+ relayPool: createPajaRelayHooks(relayBackend, getSimulation, relayConfig, (windowId) => createPajaWindowScope({
22662
+ backend: relayBackend,
22663
+ source: signerSource(windowId),
22664
+ isCurrent: () => true,
22665
+ getPubkey: () => getRuntimePubkey(getSimulation, signerProvider),
22666
+ getSigner: (source) => createRuntimeSigner(getSimulation, confirmRequest, signerProvider, source)
22667
+ }).backend),
22495
22668
  relayConfig,
22496
22669
  windowManager: { createWindow: () => null },
22497
22670
  auth: {
@@ -23097,7 +23270,14 @@ function redactPajaMessageForLog(message2) {
23097
23270
  function isRecord7(value) {
23098
23271
  return typeof value === "object" && value !== null && !Array.isArray(value);
23099
23272
  }
23100
- function installPajaOriginRegistryProxy(originRegistry2, stateRef) {
23273
+ function installPajaOriginRegistryProxy(originRegistry2, stateRef, onWindowRemoved) {
23274
+ if (onWindowRemoved && originRegistry2.unregister) {
23275
+ const unregister = originRegistry2.unregister.bind(originRegistry2);
23276
+ originRegistry2.unregister = (windowId) => {
23277
+ onWindowRemoved(windowId);
23278
+ unregister(windowId);
23279
+ };
23280
+ }
23101
23281
  const originalGetIframeWindow = originRegistry2.getIframeWindow.bind(originRegistry2);
23102
23282
  originRegistry2.getIframeWindow = (windowId) => {
23103
23283
  const win = originalGetIframeWindow(windowId);
@@ -23231,8 +23411,8 @@ function renderSignerStatus(state, signerPubkey) {
23231
23411
  const methodLabel = state.signer.method === "nip07" ? "NIP-07" : state.signer.method === "nip46" ? "bunker" : state.signer.method === "dev" ? "dev" : "none";
23232
23412
  const relay = state.signer.relay ? ` \xB7 relay ${state.signer.relay}` : "";
23233
23413
  const prefix = state.signer.status === "disconnected" ? "no signer connected" : state.signer.status === "error" ? `${methodLabel} error: ${state.signer.error ?? "unknown error"} \xB7 fallback pubkey ${fallbackPubkey}` : `${methodLabel} ${state.signer.status} \xB7 pubkey ${pubkey2 || "(none)"}${relay}`;
23234
- const consentSummary = state.signerConsentCount === 0 ? "signing asks every time" : `${state.signerConsentCount} remembered signing approval${state.signerConsentCount === 1 ? "" : "s"}`;
23235
- el.textContent = `${prefix} \xB7 ${consentSummary} \xB7 publishing asks every time`;
23414
+ const consentSummary = state.signerConsentCount === 0 ? "signing and publishing ask every time" : `${state.signerConsentCount} remembered signing/publishing approval${state.signerConsentCount === 1 ? "" : "s"}`;
23415
+ el.textContent = `${prefix} \xB7 ${consentSummary}`;
23236
23416
  clearConsent.hidden = state.signerConsentCount === 0;
23237
23417
  clearConsent.textContent = `Forget ${state.signerConsentCount} remembered approval${state.signerConsentCount === 1 ? "" : "s"}`;
23238
23418
  clearConsent.onclick = () => state.clearSignerConsent();
@@ -23460,6 +23640,7 @@ function createConfirmedSigner(signer, confirmRequest, source) {
23460
23640
  return {
23461
23641
  ...signer,
23462
23642
  async signEvent(event) {
23643
+ if (source?.isCurrent && !source.isCurrent()) throw new Error("Paja signing source changed");
23463
23644
  if (typeof signer.signEvent !== "function") {
23464
23645
  throw new Error("Signer does not support event signing");
23465
23646
  }
@@ -23471,6 +23652,7 @@ function createConfirmedSigner(signer, confirmRequest, source) {
23471
23652
  })) {
23472
23653
  throw new Error("Paja signing request denied");
23473
23654
  }
23655
+ if (source?.isCurrent && !source.isCurrent()) throw new Error("Paja signing source changed");
23474
23656
  return signer.signEvent(event);
23475
23657
  }
23476
23658
  };
@@ -23592,6 +23774,7 @@ var PAJA_SIGNER_CONSENT_VERSION = 1;
23592
23774
  var MAX_CONSENT_SUBJECTS = 128;
23593
23775
  var MAX_KINDS_PER_SUBJECT = 128;
23594
23776
  var MAX_IDENTITY_FIELD_LENGTH = 512;
23777
+ var warnedLegacyConsent = false;
23595
23778
  function createPajaSignerConsentStore(storage = readPajaSignerConsentStorage()) {
23596
23779
  let grants = readConsentDocument(storage).grants;
23597
23780
  const persist = () => {
@@ -23616,38 +23799,60 @@ function createPajaSignerConsentStore(storage = readPajaSignerConsentStorage())
23616
23799
  const existing = grants.find((grant2) => sameSubject(grant2, subject));
23617
23800
  if (existing) return existing;
23618
23801
  if (grants.length >= MAX_CONSENT_SUBJECTS) return null;
23619
- const created = { ...subject, trusted: false, kinds: [] };
23802
+ const created = { ...subject, trusted: false, kinds: [], publishTrusted: false, publishKinds: [] };
23620
23803
  grants = [...grants, created];
23621
23804
  return created;
23622
23805
  };
23623
23806
  return {
23624
- match(context, kind) {
23807
+ match(context, kind, action = "sign") {
23808
+ if (context.isCurrent && !context.isCurrent()) return null;
23625
23809
  const normalizedKind = normalizeKind(kind);
23626
23810
  if (normalizedKind === null) return null;
23627
23811
  const record2 = recordFor(context);
23628
23812
  if (!record2) return null;
23629
- if (record2.trusted) return "napplet";
23630
- return record2.kinds.includes(normalizedKind) ? "kind" : null;
23813
+ const trusted = action === "sign" ? record2.trusted : record2.publishTrusted;
23814
+ const kinds = action === "sign" ? record2.kinds : record2.publishKinds;
23815
+ if (trusted) return "napplet";
23816
+ return kinds.includes(normalizedKind) ? "kind" : null;
23631
23817
  },
23632
- rememberKind(context, kind) {
23818
+ rememberKind(context, kind, action = "sign") {
23819
+ if (context.isCurrent && !context.isCurrent()) return false;
23633
23820
  const normalizedKind = normalizeKind(kind);
23634
23821
  if (normalizedKind === null) return false;
23635
23822
  const record2 = ensureRecord(context);
23636
23823
  if (!record2) return false;
23637
- if (record2.trusted || record2.kinds.includes(normalizedKind)) return true;
23638
- if (record2.kinds.length >= MAX_KINDS_PER_SUBJECT) return false;
23639
- record2.kinds = [...record2.kinds, normalizedKind].sort((left, right) => left - right);
23824
+ const kinds = action === "sign" ? record2.kinds : record2.publishKinds;
23825
+ if ((action === "sign" ? record2.trusted : record2.publishTrusted) || kinds.includes(normalizedKind)) return true;
23826
+ if (kinds.length >= MAX_KINDS_PER_SUBJECT) return false;
23827
+ const next = [...kinds, normalizedKind].sort((left, right) => left - right);
23828
+ if (action === "sign") record2.kinds = next;
23829
+ else record2.publishKinds = next;
23640
23830
  persist();
23641
23831
  return true;
23642
23832
  },
23643
- trustNapplet(context) {
23833
+ trustNapplet(context, action = "sign") {
23834
+ if (context.isCurrent && !context.isCurrent()) return false;
23644
23835
  const record2 = ensureRecord(context);
23645
23836
  if (!record2) return false;
23646
- if (!record2.trusted || record2.kinds.length > 0) {
23837
+ if (action === "sign") {
23647
23838
  record2.trusted = true;
23648
23839
  record2.kinds = [];
23649
- persist();
23840
+ } else {
23841
+ record2.publishTrusted = true;
23842
+ record2.publishKinds = [];
23650
23843
  }
23844
+ persist();
23845
+ return true;
23846
+ },
23847
+ trustVersion(context) {
23848
+ if (context.isCurrent && !context.isCurrent()) return false;
23849
+ const record2 = ensureRecord(context);
23850
+ if (!record2) return false;
23851
+ record2.trusted = true;
23852
+ record2.kinds = [];
23853
+ record2.publishTrusted = true;
23854
+ record2.publishKinds = [];
23855
+ persist();
23651
23856
  return true;
23652
23857
  },
23653
23858
  clear() {
@@ -23672,7 +23877,7 @@ function createPajaSignerConsentStore(storage = readPajaSignerConsentStorage())
23672
23877
  }
23673
23878
  },
23674
23879
  count() {
23675
- return grants.reduce((total, grant2) => total + (grant2.trusted ? 1 : grant2.kinds.length), 0);
23880
+ return grants.reduce((total, grant2) => total + (grant2.trusted ? 1 : grant2.kinds.length) + (grant2.publishTrusted ? 1 : grant2.publishKinds.length), 0);
23676
23881
  }
23677
23882
  };
23678
23883
  }
@@ -23699,6 +23904,10 @@ function readConsentDocument(storage) {
23699
23904
  for (const candidate of parsed.grants.slice(0, MAX_CONSENT_SUBJECTS)) {
23700
23905
  const record2 = normalizeRecord(candidate);
23701
23906
  if (!record2 || grants.some((existing) => sameSubject(existing, record2))) continue;
23907
+ if (!warnedLegacyConsent && candidate && typeof candidate === "object" && !("publishTrusted" in candidate) && !("publishKinds" in candidate)) {
23908
+ warnedLegacyConsent = true;
23909
+ console.warn("[KEHTO-PAJA-SIGNER-CONSENT-V1] Loaded older signing-only approvals. Publishing still requires approval; review the current napplet version to allow signing and publishing together. This warning appears once per host module lifetime.");
23910
+ }
23702
23911
  grants.push(record2);
23703
23912
  }
23704
23913
  return { version: PAJA_SIGNER_CONSENT_VERSION, grants };
@@ -23720,7 +23929,10 @@ function normalizeRecord(value) {
23720
23929
  return {
23721
23930
  ...subject,
23722
23931
  trusted: candidate.trusted,
23723
- kinds: candidate.trusted ? [] : kinds
23932
+ kinds: candidate.trusted ? [] : kinds,
23933
+ // Old records are signing-only; their omission never grants publication.
23934
+ publishTrusted: candidate.publishTrusted === true,
23935
+ publishKinds: candidate.publishTrusted === true ? [] : Array.isArray(candidate.publishKinds) ? [...new Set(candidate.publishKinds.map(normalizeKind).filter((kind) => kind !== null))].slice(0, MAX_KINDS_PER_SUBJECT) : []
23724
23936
  };
23725
23937
  }
23726
23938
  function normalizeContext(context) {
@@ -23732,8 +23944,9 @@ function normalizeContext(context) {
23732
23944
  );
23733
23945
  }
23734
23946
  function normalizeSubject(signerPubkey, dTag, aggregateHash, runtimeScope) {
23735
- if (typeof signerPubkey !== "string" || !/^[0-9a-f]{64}$/i.test(signerPubkey)) return null;
23736
- if (!validIdentityField(dTag) || !validIdentityField(aggregateHash) || !validIdentityField(runtimeScope)) return null;
23947
+ const hostGenerated = signerPubkey === "host-generated" && typeof runtimeScope === "string" && /\|host-session:[a-f0-9]{32}$/.test(runtimeScope);
23948
+ if (typeof signerPubkey !== "string" || !/^[0-9a-f]{64}$/i.test(signerPubkey) && !hostGenerated) return null;
23949
+ if (typeof dTag !== "string" || dTag.length > MAX_IDENTITY_FIELD_LENGTH || !validIdentityField(aggregateHash) || !validIdentityField(runtimeScope)) return null;
23737
23950
  return {
23738
23951
  signerPubkey: signerPubkey.toLowerCase(),
23739
23952
  dTag,
@@ -23758,52 +23971,53 @@ function confirmationDetails(...lines) {
23758
23971
  function confirmationCopy(title, summary, approveLabel, ...details) {
23759
23972
  return { title, summary, details: confirmationDetails(...details), approveLabel };
23760
23973
  }
23761
- function createPajaConfirmationController(getState, options = {}) {
23762
- const dialog = document.getElementById("paja-confirmation-dialog");
23763
- const title = document.getElementById("paja-confirmation-title");
23764
- const summary = document.getElementById("paja-confirmation-summary");
23765
- const details = document.getElementById("paja-confirmation-details");
23766
- const approve = document.getElementById("paja-confirmation-approve");
23767
- const deny = document.getElementById("paja-confirmation-deny");
23974
+ function createSignerConsentChoices(consentStore, reportSignerConsentChange) {
23768
23975
  const signerConsent = document.getElementById("paja-signer-consent");
23769
23976
  const signerConsentOnce = document.getElementById("paja-signer-consent-once");
23770
23977
  const signerConsentKind = document.getElementById("paja-signer-consent-kind");
23771
23978
  const signerConsentNapplet = document.getElementById("paja-signer-consent-napplet");
23979
+ const signerConsentVersion = document.getElementById("paja-signer-consent-version");
23772
23980
  const signerConsentKindValue = document.getElementById("paja-signer-consent-kind-value");
23773
23981
  const signerConsentNappletValue = document.getElementById("paja-signer-consent-napplet-value");
23774
- const ready = dialog instanceof HTMLDialogElement && title instanceof HTMLElement && summary instanceof HTMLElement && details instanceof HTMLElement && approve instanceof HTMLButtonElement && deny instanceof HTMLButtonElement;
23775
23982
  const signerConsentReady = signerConsent instanceof HTMLFieldSetElement && signerConsentOnce instanceof HTMLInputElement && signerConsentKind instanceof HTMLInputElement && signerConsentNapplet instanceof HTMLInputElement && signerConsentKindValue instanceof HTMLElement && signerConsentNappletValue instanceof HTMLElement;
23776
- const consentStore = createPajaSignerConsentStore(
23777
- options.storage === void 0 ? void 0 : options.storage
23778
- );
23779
- const queue = [];
23780
- let active = null;
23781
- let previousFocus = null;
23782
- let disposed = false;
23783
- const reportSignerConsentChange = () => {
23784
- options.onSignerConsentChange?.(consentStore.count());
23785
- };
23786
23983
  const configureSignerConsent = (request) => {
23787
23984
  if (!signerConsentReady) return;
23788
23985
  signerConsent.hidden = true;
23789
23986
  signerConsentOnce.checked = true;
23790
23987
  signerConsentKind.checked = false;
23791
23988
  signerConsentNapplet.checked = false;
23989
+ if (signerConsentVersion instanceof HTMLInputElement) signerConsentVersion.checked = false;
23792
23990
  const candidate = signerConsentCandidate(request);
23793
23991
  if (!candidate) return;
23794
23992
  signerConsent.hidden = false;
23795
23993
  signerConsentKindValue.textContent = String(candidate.kind);
23796
- signerConsentNappletValue.textContent = candidate.context.napplet.dTag;
23994
+ signerConsentNappletValue.textContent = candidate.context.napplet.dTag || "Root napplet";
23995
+ const verb = request.action === "publish" ? "Publish" : "Sign";
23996
+ for (const [id, text] of [
23997
+ ["paja-signer-consent-legend", `Remember this ${request.action === "publish" ? "publishing" : "signing"} choice`],
23998
+ ["paja-signer-consent-once-label", `${verb} this event only`],
23999
+ ["paja-signer-consent-kind-verb", `Always ${verb.toLowerCase()} kind`],
24000
+ ["paja-signer-consent-napplet-verb", `Allow all ${request.action === "publish" ? "publishing" : "signing"} from`],
24001
+ ["paja-signer-consent-warning", `Paja will ${verb.toLowerCase()} any event this napplet version requests without asking again. A different version or signer needs new approval.`]
24002
+ ]) {
24003
+ const element2 = document.getElementById(id);
24004
+ if (element2) element2.textContent = text;
24005
+ }
23797
24006
  };
23798
24007
  const rememberSignerChoice = (request) => {
23799
24008
  if (!signerConsentReady) return "once";
23800
24009
  const candidate = signerConsentCandidate(request);
23801
24010
  if (!candidate) return "once";
23802
- if (signerConsentNapplet.checked && consentStore.trustNapplet(candidate.context)) {
24011
+ if (signerConsentVersion instanceof HTMLInputElement && signerConsentVersion.checked && consentStore.trustVersion(candidate.context)) {
24012
+ reportSignerConsentChange();
24013
+ return "trust-version";
24014
+ }
24015
+ const action = request.action === "publish" ? "publish" : "sign";
24016
+ if (signerConsentNapplet.checked && consentStore.trustNapplet(candidate.context, action)) {
23803
24017
  reportSignerConsentChange();
23804
24018
  return "trust-napplet";
23805
24019
  }
23806
- if (signerConsentKind.checked && consentStore.rememberKind(candidate.context, candidate.kind)) {
24020
+ if (signerConsentKind.checked && consentStore.rememberKind(candidate.context, candidate.kind, action)) {
23807
24021
  reportSignerConsentChange();
23808
24022
  return "remember-kind";
23809
24023
  }
@@ -23811,14 +24025,40 @@ function createPajaConfirmationController(getState, options = {}) {
23811
24025
  };
23812
24026
  const rememberedSignerChoice = (request) => {
23813
24027
  const candidate = signerConsentCandidate(request);
23814
- return candidate ? consentStore.match(candidate.context, candidate.kind) : null;
24028
+ return candidate ? consentStore.match(candidate.context, candidate.kind, request.action === "publish" ? "publish" : "sign") : null;
24029
+ };
24030
+ return { configure: configureSignerConsent, remember: rememberSignerChoice, match: rememberedSignerChoice };
24031
+ }
24032
+ function createPajaConfirmationController(getState, options = {}) {
24033
+ const dialog = document.getElementById("paja-confirmation-dialog");
24034
+ const title = document.getElementById("paja-confirmation-title");
24035
+ const summary = document.getElementById("paja-confirmation-summary");
24036
+ const details = document.getElementById("paja-confirmation-details");
24037
+ const approve = document.getElementById("paja-confirmation-approve");
24038
+ const deny = document.getElementById("paja-confirmation-deny");
24039
+ const ready = dialog instanceof HTMLDialogElement && title instanceof HTMLElement && summary instanceof HTMLElement && details instanceof HTMLElement && approve instanceof HTMLButtonElement && deny instanceof HTMLButtonElement;
24040
+ const consentStore = createPajaSignerConsentStore(
24041
+ options.storage === void 0 ? void 0 : options.storage
24042
+ );
24043
+ const queue = [];
24044
+ let active = null;
24045
+ let previousFocus = null;
24046
+ let disposed = false;
24047
+ const reportSignerConsentChange = () => {
24048
+ options.onSignerConsentChange?.(consentStore.count());
23815
24049
  };
24050
+ const choices = createSignerConsentChoices(consentStore, reportSignerConsentChange);
23816
24051
  const pump = () => {
23817
24052
  if (!ready || disposed || active) return;
23818
24053
  while (!active && queue.length > 0) {
23819
24054
  const candidate = queue.shift() ?? null;
23820
24055
  if (!candidate) break;
23821
- const remembered = rememberedSignerChoice(candidate.request);
24056
+ if (!isRequestCurrent(candidate.request)) {
24057
+ recordPajaConfirmation(getState(), candidate.request, false);
24058
+ candidate.deny();
24059
+ continue;
24060
+ }
24061
+ const remembered = choices.match(candidate.request);
23822
24062
  if (!remembered) {
23823
24063
  active = candidate;
23824
24064
  break;
@@ -23837,7 +24077,7 @@ function createPajaConfirmationController(getState, options = {}) {
23837
24077
  summary.textContent = copy.summary;
23838
24078
  details.textContent = copy.details;
23839
24079
  approve.textContent = copy.approveLabel;
23840
- configureSignerConsent(active.request);
24080
+ choices.configure(active.request);
23841
24081
  previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
23842
24082
  dialog.showModal();
23843
24083
  deny.focus();
@@ -23845,9 +24085,10 @@ function createPajaConfirmationController(getState, options = {}) {
23845
24085
  const settle6 = (allowed2) => {
23846
24086
  const current = active;
23847
24087
  if (!current) return;
24088
+ allowed2 = allowed2 && isRequestCurrent(current.request);
23848
24089
  active = null;
23849
24090
  if (ready && dialog.open) dialog.close();
23850
- const approvalMode = allowed2 ? rememberSignerChoice(current.request) : void 0;
24091
+ const approvalMode = allowed2 ? choices.remember(current.request) : void 0;
23851
24092
  recordPajaConfirmation(getState(), current.request, allowed2, approvalMode);
23852
24093
  if (allowed2) current.approve();
23853
24094
  else current.deny();
@@ -23866,6 +24107,16 @@ function createPajaConfirmationController(getState, options = {}) {
23866
24107
  deny.addEventListener("click", onDeny);
23867
24108
  dialog.addEventListener("cancel", onCancel);
23868
24109
  }
24110
+ const cancelMatching = (matches) => {
24111
+ for (let index = queue.length - 1; index >= 0; index--) {
24112
+ const pending = queue[index];
24113
+ if (!matches(pending.request)) continue;
24114
+ queue.splice(index, 1);
24115
+ recordPajaConfirmation(getState(), pending.request, false);
24116
+ pending.deny();
24117
+ }
24118
+ if (active && matches(active.request)) settle6(false);
24119
+ };
23869
24120
  return {
23870
24121
  confirm(request) {
23871
24122
  if (!ready || disposed) {
@@ -23908,6 +24159,12 @@ function createPajaConfirmationController(getState, options = {}) {
23908
24159
  return cleared;
23909
24160
  },
23910
24161
  getSignerConsentCount: () => consentStore.count(),
24162
+ cancelWindow(windowId) {
24163
+ cancelMatching((request) => ("windowId" in request ? request.windowId : "signerContext" in request ? request.signerContext?.windowId : void 0) === windowId);
24164
+ },
24165
+ cancelSignerRequests() {
24166
+ cancelMatching((request) => request.action === "sign" || request.action === "publish");
24167
+ },
23911
24168
  dispose() {
23912
24169
  if (disposed) return;
23913
24170
  disposed = true;
@@ -23925,12 +24182,16 @@ function createPajaConfirmationController(getState, options = {}) {
23925
24182
  };
23926
24183
  }
23927
24184
  function signerConsentCandidate(request) {
23928
- if (request.action !== "sign" || !request.signerContext) return null;
24185
+ if (request.action !== "sign" && request.action !== "publish" || !request.signerContext) return null;
23929
24186
  if (!isPajaSignerConsentContext(request.signerContext)) return null;
23930
24187
  const kind = request.event.kind;
23931
24188
  if (typeof kind !== "number" || !Number.isSafeInteger(kind) || kind < 0 || kind > 65535) return null;
23932
24189
  return { context: request.signerContext, kind };
23933
24190
  }
24191
+ function isRequestCurrent(request) {
24192
+ if (request.isCurrent && !request.isCurrent()) return false;
24193
+ return !("signerContext" in request) || !request.signerContext?.isCurrent || request.signerContext.isCurrent();
24194
+ }
23934
24195
  function describeConfirmation(request) {
23935
24196
  if (request.action === "upload") {
23936
24197
  return confirmationCopy(
@@ -23951,6 +24212,7 @@ function describeConfirmation(request) {
23951
24212
  `${request.napplet.dTag} requests browser navigation.`,
23952
24213
  "Open link",
23953
24214
  `Napplet: ${request.napplet.dTag} (${request.windowId})`,
24215
+ `Version: ${request.napplet.aggregateHash}`,
23954
24216
  request.label ? `Label: ${request.label}` : void 0,
23955
24217
  `Destination: ${request.url}`
23956
24218
  );
@@ -24015,12 +24277,13 @@ function describeConfirmation(request) {
24015
24277
  const signerContext = request.signerContext;
24016
24278
  return {
24017
24279
  title: request.action === "sign" ? "Sign this Nostr event?" : "Publish this Nostr event?",
24018
- summary: request.action === "sign" ? signerContext ? `${signerContext.napplet.dTag} requests a signature from the active signer.` : "A Paja host operation requests a signature from the active signer." : "Paja will send this event to the configured relay set.",
24280
+ summary: request.action === "sign" ? signerContext ? `${signerContext.napplet.dTag} requests a signature from the active signer.` : "A Paja host operation requests a signature from the active signer." : signerContext ? `${signerContext.napplet.dTag} requests publication to the configured relays.` : "A Paja host operation will send this event to the configured relay set.",
24019
24281
  details: confirmationDetails(
24020
24282
  signerContext ? `Napplet: ${signerContext.napplet.dTag} (${signerContext.windowId})` : void 0,
24021
- signerContext ? `Identity hash: ${signerContext.napplet.aggregateHash}` : void 0,
24283
+ signerContext ? `Version: ${signerContext.napplet.aggregateHash}` : void 0,
24284
+ signerContext ? `Approval scope: ${signerContext.runtimeScope}` : void 0,
24022
24285
  signerContext?.runtimeScope.startsWith("target-url:") ? `Target URL: ${signerContext.runtimeScope.slice("target-url:".length)}` : void 0,
24023
- signerContext ? `Signer: ${signerContext.signerPubkey}` : void 0,
24286
+ signerContext ? `Signer: ${signerContext.signerPubkey === "host-generated" ? "Host-generated events (this Paja session)" : signerContext.signerPubkey}` : void 0,
24024
24287
  `Kind: ${kind}`,
24025
24288
  `Content: ${content}`
24026
24289
  ),
@@ -27131,8 +27394,17 @@ async function installPajaHost() {
27131
27394
  confirmationController.confirm
27132
27395
  );
27133
27396
  const getWindowIdentity = (windowId) => {
27134
- const tabTarget = stateRef?.tabs.find((tab) => tab.windowId === windowId)?.resolvedTarget;
27135
- return getTargetIdentity(config, tabTarget ?? stateRef?.resolvedTarget);
27397
+ const tab = stateRef?.tabs.find((tab2) => tab2.windowId === windowId);
27398
+ const target = tab?.resolvedTarget ?? stateRef?.resolvedTarget;
27399
+ const identity = getTargetIdentity(config, target);
27400
+ return {
27401
+ ...identity,
27402
+ consentScope: target ? `${isPajaLocalTarget(target) ? "local-file" : target.manifest.catalogId}:artifact:${target.aggregateHash}` : pajaDevelopmentConsentScope(config.target.url, windowId ?? ""),
27403
+ isCurrent: () => {
27404
+ const targetFrame = tab?.frame ?? frame;
27405
+ return !!targetFrame?.contentWindow && originRegistry.getWindowId(targetFrame.contentWindow) === windowId && (!tab || stateRef?.tabs.includes(tab) === true);
27406
+ }
27407
+ };
27136
27408
  };
27137
27409
  const notifyController = createPajaNotifyController({
27138
27410
  confirm: confirmationController.confirm,
@@ -27186,11 +27458,12 @@ async function installPajaHost() {
27186
27458
  await adapter.ready;
27187
27459
  const bridge = createShellBridge(adapter);
27188
27460
  const stopIdentityChanges = signerController.subscribe(() => {
27461
+ confirmationController.cancelSignerRequests();
27189
27462
  bridge.publishIdentityChanged(adapter.auth.getUserPubkey() ?? "");
27190
27463
  });
27191
27464
  themeBroadcast.attach(bridge);
27192
27465
  bridgeRef = bridge;
27193
- installPajaOriginRegistryProxy(originRegistry, () => stateRef);
27466
+ installPajaOriginRegistryProxy(originRegistry, () => stateRef, (windowId) => confirmationController.cancelWindow(windowId));
27194
27467
  const capabilities = buildShellCapabilities(adapter);
27195
27468
  const context = {
27196
27469
  config,