@kernlize/core 0.11.0 → 0.12.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.
package/dist/index.js CHANGED
@@ -784,6 +784,63 @@ function createIdentityProviders(store, pool, tiers, options = {}) {
784
784
  };
785
785
  }
786
786
 
787
+ // src/grants/domain-capabilities.ts
788
+ var DOMAIN_CAPABILITIES = Object.freeze({
789
+ shell: [],
790
+ inc: [],
791
+ relay: ["relay:read", "relay:write"],
792
+ identity: ["identity:read"],
793
+ storage: ["state:read", "state:write"],
794
+ theme: ["theme:read"],
795
+ keys: ["keys:bind", "keys:forward"],
796
+ media: ["media:control"],
797
+ notify: ["notify:send", "notify:channel"],
798
+ config: ["config:read"],
799
+ resource: ["resource:fetch"],
800
+ cvm: ["cvm:call"],
801
+ outbox: ["outbox:read", "outbox:write"],
802
+ upload: ["upload:write"],
803
+ intent: ["intent:read", "intent:write"],
804
+ dm: ["dm:read", "dm:write"],
805
+ fs: ["fs:read", "fs:write"],
806
+ llm: ["llm:generate"],
807
+ cache: ["cache:read", "cache:write"],
808
+ // kehto's ACL has no capability for direct connections; the service checks the grant itself (D-042).
809
+ webrtc: []
810
+ });
811
+ var BASELINE_DOMAINS = Object.freeze(["shell", "inc", "theme", "storage"]);
812
+ function capabilitiesForDomain(domain) {
813
+ return DOMAIN_CAPABILITIES[domain] ?? [];
814
+ }
815
+ function capabilitiesForDomains(domains) {
816
+ const wanted = new Set(domains);
817
+ const result = [];
818
+ for (const [domain, capabilities] of Object.entries(DOMAIN_CAPABILITIES)) {
819
+ if (wanted.has(domain)) result.push(...capabilities);
820
+ }
821
+ return result;
822
+ }
823
+
824
+ // src/grants/message-isolation.ts
825
+ var MESSAGES_DOMAIN = "dm";
826
+ var MESSAGE_COMPANION_DOMAINS = Object.freeze(["shell", MESSAGES_DOMAIN, "identity", "theme", "storage", "config", "notify", "keys", "intent"]);
827
+ var WITHHELD_CAPABILITIES = Object.freeze(["intent:write"]);
828
+ function sealsApplet(granted) {
829
+ return granted.includes(MESSAGES_DOMAIN);
830
+ }
831
+ function domainsInForce(granted, baseline = BASELINE_DOMAINS) {
832
+ const held = [.../* @__PURE__ */ new Set([...baseline, ...granted])];
833
+ return Object.freeze(sealsApplet(granted) ? held.filter((domain) => MESSAGE_COMPANION_DOMAINS.includes(domain)) : held);
834
+ }
835
+ function withheldDomains(granted, baseline = BASELINE_DOMAINS) {
836
+ const inForce = domainsInForce(granted, baseline);
837
+ return Object.freeze([.../* @__PURE__ */ new Set([...baseline, ...granted])].filter((domain) => !inForce.includes(domain)));
838
+ }
839
+ function capabilitiesInForce(granted) {
840
+ const capabilities = capabilitiesForDomains(domainsInForce(granted));
841
+ return sealsApplet(granted) ? capabilities.filter((capability) => !WITHHELD_CAPABILITIES.includes(capability)) : capabilities;
842
+ }
843
+
787
844
  // src/applesauce/accounts.ts
788
845
  import { AccountManager } from "applesauce-accounts";
789
846
  import { registerCommonAccountTypes } from "applesauce-accounts/accounts";
@@ -822,6 +879,29 @@ function createKernlAccounts(storage) {
822
879
  return manager;
823
880
  }
824
881
 
882
+ // src/applesauce/throwaway.ts
883
+ import { BaseAccount } from "applesauce-accounts";
884
+ import { getPublicKey } from "applesauce-core/helpers/keys";
885
+ import { PrivateKeySigner } from "applesauce-signers";
886
+ var THROWAWAY_IDENTITY_TYPE = "throwaway";
887
+ var ThrowawayIdentity = class extends BaseAccount {
888
+ static type = THROWAWAY_IDENTITY_TYPE;
889
+ /**
890
+ * Refuse to be written down.
891
+ *
892
+ * @throws `denied:plaintext-key-persistence`, always.
893
+ */
894
+ toJSON() {
895
+ throw new Error("denied:plaintext-key-persistence");
896
+ }
897
+ };
898
+ function createThrowawayIdentity(name = "Just looking") {
899
+ const signer = new PrivateKeySigner();
900
+ const identity = new ThrowawayIdentity(getPublicKey(signer.key), signer);
901
+ identity.metadata = { name };
902
+ return identity;
903
+ }
904
+
825
905
  // src/applets/pointer.ts
826
906
  import { decodeAddressPointer, decodeEventPointer } from "applesauce-core/helpers";
827
907
 
@@ -1404,43 +1484,6 @@ function createRuntimeFirewallHooks(options) {
1404
1484
  };
1405
1485
  }
1406
1486
 
1407
- // src/grants/domain-capabilities.ts
1408
- var DOMAIN_CAPABILITIES = Object.freeze({
1409
- shell: [],
1410
- inc: [],
1411
- relay: ["relay:read", "relay:write"],
1412
- identity: ["identity:read"],
1413
- storage: ["state:read", "state:write"],
1414
- theme: ["theme:read"],
1415
- keys: ["keys:bind", "keys:forward"],
1416
- media: ["media:control"],
1417
- notify: ["notify:send", "notify:channel"],
1418
- config: ["config:read"],
1419
- resource: ["resource:fetch"],
1420
- cvm: ["cvm:call"],
1421
- outbox: ["outbox:read", "outbox:write"],
1422
- upload: ["upload:write"],
1423
- intent: ["intent:read", "intent:write"],
1424
- dm: ["dm:read", "dm:write"],
1425
- fs: ["fs:read", "fs:write"],
1426
- llm: ["llm:generate"],
1427
- cache: ["cache:read", "cache:write"],
1428
- // kehto's ACL has no capability for direct connections; the service checks the grant itself (D-042).
1429
- webrtc: []
1430
- });
1431
- var BASELINE_DOMAINS = Object.freeze(["shell", "inc", "theme", "storage"]);
1432
- function capabilitiesForDomain(domain) {
1433
- return DOMAIN_CAPABILITIES[domain] ?? [];
1434
- }
1435
- function capabilitiesForDomains(domains) {
1436
- const wanted = new Set(domains);
1437
- const result = [];
1438
- for (const [domain, capabilities] of Object.entries(DOMAIN_CAPABILITIES)) {
1439
- if (wanted.has(domain)) result.push(...capabilities);
1440
- }
1441
- return result;
1442
- }
1443
-
1444
1487
  // src/grants/grants.ts
1445
1488
  import { Subject as Subject2 } from "rxjs";
1446
1489
  var STORAGE_KEY2 = "grants:v1";
@@ -1459,13 +1502,14 @@ function createGrants(options) {
1459
1502
  return {
1460
1503
  identity: { dTag: entry.dTag, hash: entry.hash },
1461
1504
  domains: Object.freeze([...entry.domains]),
1462
- capabilities: capabilitiesForDomains([...BASELINE_DOMAINS, ...entry.domains]),
1505
+ capabilities: capabilitiesInForce(entry.domains),
1506
+ withheld: withheldDomains(entry.domains),
1463
1507
  blocked: entry.blocked,
1464
1508
  stateQuotaBytes: options.acl.getStateQuota("", entry.dTag, entry.hash)
1465
1509
  };
1466
1510
  }
1467
1511
  function syncAcl(entry) {
1468
- const wanted = new Set(capabilitiesForDomains([...BASELINE_DOMAINS, ...entry.domains]));
1512
+ const wanted = new Set(capabilitiesInForce(entry.domains));
1469
1513
  const held = options.acl.getEntry("", entry.dTag, entry.hash)?.capabilities ?? [];
1470
1514
  for (const capability of held) if (!wanted.has(capability)) options.acl.revoke("", entry.dTag, entry.hash, capability);
1471
1515
  for (const capability of wanted) options.acl.grant("", entry.dTag, entry.hash, capability);
@@ -1515,7 +1559,7 @@ function createGrants(options) {
1515
1559
  function createEnvironmentResolver(grants) {
1516
1560
  return (identity, available) => {
1517
1561
  const record2 = grants.get({ dTag: identity.dTag, hash: identity.aggregateHash });
1518
- const allowed = new Set(record2?.blocked ? ["shell"] : [...grants.baselineDomains(), ...record2?.domains ?? []]);
1562
+ const allowed = new Set(record2?.blocked ? ["shell"] : domainsInForce(record2?.domains ?? [], grants.baselineDomains()));
1519
1563
  return Object.freeze({
1520
1564
  domains: Object.freeze(available.domains.filter((domain) => allowed.has(domain))),
1521
1565
  services: Object.freeze(available.services.filter((service) => allowed.has(service)))
@@ -1675,9 +1719,9 @@ function deletion(event, applet) {
1675
1719
  function vanish(event, applet) {
1676
1720
  const services = tagValues(event, "relay");
1677
1721
  const everywhere = services.length === 0 || services.includes(ALL_SERVICES);
1678
- const lines = [{ label: "Erase", before: "Everything this account has published" }];
1722
+ const lines = [{ label: "Erase", before: "Everything this identity has published" }];
1679
1723
  lines.push({ label: "Services asked", after: everywhere ? "Every service" : describeItems(services, serverName) });
1680
- return destructive(event, applet, "Ask services to erase your account", lines);
1724
+ return destructive(event, applet, "Ask services to erase your identity", lines);
1681
1725
  }
1682
1726
  var HANDLER_PREFERENCES = 31129;
1683
1727
  function appletName(ref) {
@@ -1867,7 +1911,7 @@ import { kinds as kinds2, verifyEvent } from "applesauce-core/helpers";
1867
1911
  import { lockGiftWrap, unlockGiftWrap } from "applesauce-common/helpers/gift-wrap";
1868
1912
  import { getConversationParticipants as getConversationParticipants2 } from "applesauce-common/helpers/messages";
1869
1913
  import { sealRumor, toRumor } from "applesauce-common/operations/gift-wrap";
1870
- import { PrivateKeySigner } from "applesauce-signers";
1914
+ import { PrivateKeySigner as PrivateKeySigner2 } from "applesauce-signers";
1871
1915
 
1872
1916
  // src/messaging/signer-backend.ts
1873
1917
  import { isHexKey, unixNow as unixNow2 } from "applesauce-core/helpers";
@@ -2087,7 +2131,7 @@ function createSignerBackend(options, format) {
2087
2131
  // src/messaging/private-backend.ts
2088
2132
  var WRAP_JITTER_SECONDS = 2 * 24 * 60 * 60;
2089
2133
  async function wrapForRecipient(recipient, seal, createdAt) {
2090
- const ephemeral = new PrivateKeySigner();
2134
+ const ephemeral = new PrivateKeySigner2();
2091
2135
  const content = await ephemeral.nip44.encrypt(recipient, JSON.stringify(seal));
2092
2136
  const jitter = Math.floor(Math.random() * WRAP_JITTER_SECONDS);
2093
2137
  return ephemeral.signEvent({ kind: kinds2.GiftWrap, created_at: createdAt - jitter, tags: [["p", recipient]], content });
@@ -2876,7 +2920,7 @@ function createAppletConfig(options) {
2876
2920
  }
2877
2921
 
2878
2922
  // src/social/common-actions.ts
2879
- import { getProfileContent as getProfileContent2, normalizeToPubkey, unixNow as unixNow5 } from "applesauce-core/helpers";
2923
+ import { getProfileContent as getProfileContent2, unixNow as unixNow5 } from "applesauce-core/helpers";
2880
2924
  var FOLLOWS2 = 3;
2881
2925
  var REACTION = 7;
2882
2926
  var REPORT = 1984;
@@ -2884,9 +2928,7 @@ var reasonOf = (error) => error instanceof Error ? error.message : String(error)
2884
2928
  function followed(event) {
2885
2929
  return (event?.tags ?? []).filter((tag) => tag[0] === "p" && typeof tag[1] === "string").map((tag) => tag[1]);
2886
2930
  }
2887
- function toPubkey(value) {
2888
- return normalizeToPubkey(value) ?? void 0;
2889
- }
2931
+ var located = (options, value) => options.locate(value).catch(() => void 0);
2890
2932
  async function signed(options, windowId, template) {
2891
2933
  const signer = options.signer();
2892
2934
  if (!signer) return { ok: false, error: "denied:read-only" };
@@ -2903,7 +2945,7 @@ async function signed(options, windowId, template) {
2903
2945
  async function changeFollows(options, windowId, pubkeys, add) {
2904
2946
  const self = options.pubkey();
2905
2947
  if (!self) return { ok: false, error: "denied:read-only" };
2906
- const targets = pubkeys.map(toPubkey);
2948
+ const targets = await Promise.all(pubkeys.map((key) => located(options, key)));
2907
2949
  if (targets.some((key) => key === void 0)) return { ok: false, error: "invalid:pubkey" };
2908
2950
  await options.loadFollows(self);
2909
2951
  const previous = options.store.getReplaceable(FOLLOWS2, self);
@@ -2916,7 +2958,7 @@ async function changeFollows(options, windowId, pubkeys, add) {
2916
2958
  function createCommonActions(options) {
2917
2959
  return {
2918
2960
  async getProfile(target) {
2919
- const pubkey = toPubkey(target);
2961
+ const pubkey = await located(options, target);
2920
2962
  if (!pubkey) return { ok: false, pubkey: "", error: "invalid:pubkey" };
2921
2963
  const card = await options.profiles.settled(pubkey);
2922
2964
  const event = options.store.getReplaceable(0, pubkey);
@@ -2947,15 +2989,68 @@ function createCommonActions(options) {
2947
2989
  }
2948
2990
 
2949
2991
  // src/kernl-network.ts
2950
- import { lastValueFrom as lastValueFrom7, map as map7, takeUntil as takeUntil2 } from "rxjs";
2992
+ import { lastValueFrom as lastValueFrom8, map as map7, takeUntil as takeUntil3 } from "rxjs";
2993
+
2994
+ // src/people/person.ts
2995
+ import { catchError as catchError3, EMPTY as EMPTY3, lastValueFrom as lastValueFrom7, takeUntil as takeUntil2, tap, timer as timer4 } from "rxjs";
2996
+ import { decodePointer as decodePointer2 } from "applesauce-core/helpers";
2997
+ var URI_SCHEME = /^nostr:/i;
2998
+ var SOCKET_URL = /^wss?:\/\//i;
2999
+ var HEX_KEY2 = /^[0-9a-f]{64}$/;
3000
+ var NO_RELAYS = Object.freeze([]);
3001
+ function decodeOrNothing(text3) {
3002
+ try {
3003
+ return decodePointer2(text3);
3004
+ } catch {
3005
+ return void 0;
3006
+ }
3007
+ }
3008
+ var PERSON_HINT_TIMEOUT_MS = 8e3;
3009
+ var PERSON_KINDS = [0, 10002, 10050];
3010
+ function parsePerson(input) {
3011
+ const text3 = input.trim().replace(URI_SCHEME, "").toLowerCase();
3012
+ if (HEX_KEY2.test(text3)) return Object.freeze({ pubkey: text3, relays: NO_RELAYS });
3013
+ const decoded = decodeOrNothing(text3);
3014
+ if (decoded?.type === "npub") return Object.freeze({ pubkey: decoded.data, relays: NO_RELAYS });
3015
+ if (decoded?.type !== "nprofile") return void 0;
3016
+ const named = decoded.data.relays;
3017
+ return Object.freeze({ pubkey: decoded.data.pubkey, relays: Object.freeze(named.filter((url) => SOCKET_URL.test(url))) });
3018
+ }
3019
+ function createPeople(options) {
3020
+ const asked = /* @__PURE__ */ new Map();
3021
+ const ask = (person) => {
3022
+ const key = `${person.pubkey}:${[...person.relays].sort().join(",")}`;
3023
+ const known = asked.get(key);
3024
+ if (known) return known;
3025
+ const done = lastValueFrom7(
3026
+ options.pool.request([...person.relays], asFilters([{ kinds: PERSON_KINDS, authors: [person.pubkey] }])).pipe(
3027
+ takeUntil2(timer4(options.timeoutMs ?? PERSON_HINT_TIMEOUT_MS)),
3028
+ tap((event) => options.store.add(event)),
3029
+ catchError3(() => EMPTY3)
3030
+ ),
3031
+ { defaultValue: void 0 }
3032
+ ).then(() => void 0);
3033
+ asked.set(key, done);
3034
+ return done;
3035
+ };
3036
+ return {
3037
+ parse: parsePerson,
3038
+ async locate(input) {
3039
+ const person = parsePerson(input);
3040
+ if (!person) throw new Error("invalid:person");
3041
+ if (person.relays.length > 0) await ask(person);
3042
+ return person.pubkey;
3043
+ }
3044
+ };
3045
+ }
2951
3046
 
2952
3047
  // src/profiles/profiles.ts
2953
- import { catchError as catchError3, distinctUntilChanged as distinctUntilChanged2, EMPTY as EMPTY3, endWith as endWith2, filter as filter2, firstValueFrom as firstValueFrom2, ignoreElements as ignoreElements2, map as map6, merge as merge3, Observable as Observable2, share, switchMap as switchMap4, take as take2, timer as timer4 } from "rxjs";
3048
+ import { catchError as catchError4, distinctUntilChanged as distinctUntilChanged2, EMPTY as EMPTY4, endWith as endWith2, filter as filter2, firstValueFrom as firstValueFrom2, ignoreElements as ignoreElements2, map as map6, merge as merge3, Observable as Observable2, share, switchMap as switchMap4, take as take2, timer as timer5 } from "rxjs";
2954
3049
  import { getDisplayName, getOutboxes as getOutboxes3, getProfileContent as getProfileContent3, getProfilePicture } from "applesauce-core/helpers";
2955
3050
  var PROFILE_KIND = 0;
2956
3051
  var MAILBOX_KIND = 10002;
2957
3052
  var KEEP_ALIVE_MS = 6e4;
2958
- var HEX_KEY2 = /^[0-9a-f]{64}$/;
3053
+ var HEX_KEY3 = /^[0-9a-f]{64}$/;
2959
3054
  function safePicture(event) {
2960
3055
  const picture = getProfilePicture(event);
2961
3056
  return picture?.startsWith("https://") ? picture : void 0;
@@ -2992,7 +3087,7 @@ function createProfiles(options) {
2992
3087
  return subscription;
2993
3088
  };
2994
3089
  const watch = (pubkey) => new Observable2((subscriber) => {
2995
- const loading = HEX_KEY2.test(pubkey) ? lookup(pubkey) : void 0;
3090
+ const loading = HEX_KEY3.test(pubkey) ? lookup(pubkey) : void 0;
2996
3091
  const updates = store.replaceable(PROFILE_KIND, pubkey).pipe(
2997
3092
  map6((event) => toProfileCard(pubkey, event)),
2998
3093
  distinctUntilChanged2((a, b) => JSON.stringify(a) === JSON.stringify(b))
@@ -3001,7 +3096,7 @@ function createProfiles(options) {
3001
3096
  updates.unsubscribe();
3002
3097
  loading?.unsubscribe();
3003
3098
  };
3004
- }).pipe(share({ resetOnRefCountZero: () => timer4(keepAlive) }));
3099
+ }).pipe(share({ resetOnRefCountZero: () => timer5(keepAlive) }));
3005
3100
  const card = (pubkey) => toProfileCard(pubkey, store.getReplaceable(PROFILE_KIND, pubkey.toLowerCase()));
3006
3101
  const profiles = {
3007
3102
  card$(pubkey) {
@@ -3016,10 +3111,10 @@ function createProfiles(options) {
3016
3111
  card,
3017
3112
  settled(pubkey) {
3018
3113
  const key = pubkey.toLowerCase();
3019
- if (!HEX_KEY2.test(key)) return Promise.resolve(card(key));
3114
+ if (!HEX_KEY3.test(key)) return Promise.resolve(card(key));
3020
3115
  const found = profiles.card$(key).pipe(filter2((next) => next.found));
3021
3116
  const answered = load({ kind: PROFILE_KIND, pubkey: key, relays: [...options.lookupRelays()] }).pipe(
3022
- catchError3(() => EMPTY3),
3117
+ catchError4(() => EMPTY4),
3023
3118
  ignoreElements2(),
3024
3119
  endWith2(void 0),
3025
3120
  map6(() => card(key))
@@ -3041,34 +3136,36 @@ function createKernlNetwork(options, parts) {
3041
3136
  const mailboxes = createAccountMailboxes({
3042
3137
  store: eventStore,
3043
3138
  pool,
3044
- pubkey$: accounts.active$.pipe(map7((account) => account?.pubkey), takeUntil2(parts.destroyed$)),
3139
+ pubkey$: accounts.active$.pipe(map7((account) => account?.pubkey), takeUntil3(parts.destroyed$)),
3045
3140
  lookupRelays,
3046
3141
  signer,
3047
3142
  directory
3048
3143
  });
3049
3144
  const profiles = createProfiles({ store: eventStore, load: replaceableLoader, lookupRelays });
3145
+ const people = createPeople({ store: eventStore, pool });
3050
3146
  const files = createAccountFileServers({
3051
3147
  store: eventStore,
3052
3148
  pool,
3053
3149
  load: replaceableLoader,
3054
- pubkey$: accounts.active$.pipe(map7((account) => account?.pubkey), takeUntil2(parts.destroyed$)),
3150
+ pubkey$: accounts.active$.pipe(map7((account) => account?.pubkey), takeUntil3(parts.destroyed$)),
3055
3151
  pubkey: () => accounts.active?.pubkey,
3056
3152
  lookupRelays,
3057
3153
  outboxes: () => tiers.get().outbox,
3058
3154
  signer
3059
3155
  });
3060
- return { eventCache, replaceableLoader, profiles, directory, mailboxes, files, signer };
3156
+ return { eventCache, replaceableLoader, profiles, people, directory, mailboxes, files, signer };
3061
3157
  }
3062
3158
  function commonActionsFor(parts, network, consent) {
3063
3159
  const { eventStore, pool, tiers, accounts } = parts;
3064
3160
  return createCommonActions({
3065
3161
  store: eventStore,
3066
3162
  profiles: network.profiles,
3163
+ locate: network.people.locate,
3067
3164
  pubkey: () => accounts.active?.pubkey,
3068
3165
  signer: network.signer,
3069
3166
  consent,
3070
3167
  publish: (event) => publishAccepted(pool, selectRelayTier(tiers, [{ kinds: [event.kind] }]), event),
3071
- loadFollows: (pubkey) => lastValueFrom7(network.replaceableLoader({ kind: 3, pubkey, relays: lookupRelaysOf(tiers.get()) }), { defaultValue: void 0 }).then(
3168
+ loadFollows: (pubkey) => lastValueFrom8(network.replaceableLoader({ kind: 3, pubkey, relays: lookupRelaysOf(tiers.get()) }), { defaultValue: void 0 }).then(
3072
3169
  () => void 0,
3073
3170
  () => void 0
3074
3171
  )
@@ -3139,14 +3236,14 @@ function createRemoteToolsService(options) {
3139
3236
  }
3140
3237
 
3141
3238
  // src/multiplayer/window-identities.ts
3142
- import { PrivateKeySigner as PrivateKeySigner2 } from "applesauce-signers";
3239
+ import { PrivateKeySigner as PrivateKeySigner3 } from "applesauce-signers";
3143
3240
  function createWindowIdentities() {
3144
3241
  const signers = /* @__PURE__ */ new Map();
3145
3242
  return {
3146
3243
  signer(windowId) {
3147
3244
  let signer = signers.get(windowId);
3148
3245
  if (!signer) {
3149
- signer = new PrivateKeySigner2();
3246
+ signer = new PrivateKeySigner3();
3150
3247
  signers.set(windowId, signer);
3151
3248
  }
3152
3249
  return signer;
@@ -3161,7 +3258,7 @@ function createWindowIdentities() {
3161
3258
  // src/multiplayer/settings.ts
3162
3259
  import { BehaviorSubject as BehaviorSubject7 } from "rxjs";
3163
3260
  var STORAGE_KEY5 = "multiplayer:v1";
3164
- var HEX_KEY3 = /^[0-9a-f]{64}$/u;
3261
+ var HEX_KEY4 = /^[0-9a-f]{64}$/u;
3165
3262
  var HELPER_URL = /^(stuns?|turns?):\S+$/u;
3166
3263
  var RELAY_URL = /^wss?:\/\/\S+$/u;
3167
3264
  var text2 = (value) => typeof value === "string" && value.trim().length > 0 && value.length <= 256;
@@ -3173,7 +3270,7 @@ function validHelper(helper) {
3173
3270
  }
3174
3271
  function validFamily(family) {
3175
3272
  const { server, tools } = family;
3176
- return text2(family.family) && HEX_KEY3.test(server.pubkey) && validServers(server.relays ?? []) && Array.isArray(tools) && tools.length > 0 && tools.length <= 64 && tools.every((tool) => text2(tool.name) && HEX_KEY3.test(tool.schemaHash)) && new Set(tools.map((tool) => tool.name)).size === tools.length;
3273
+ return text2(family.family) && HEX_KEY4.test(server.pubkey) && validServers(server.relays ?? []) && Array.isArray(tools) && tools.length > 0 && tools.length <= 64 && tools.every((tool) => text2(tool.name) && HEX_KEY4.test(tool.schemaHash)) && new Set(tools.map((tool) => tool.name)).size === tools.length;
3177
3274
  }
3178
3275
  function read(raw) {
3179
3276
  const families = Array.isArray(raw.families) ? raw.families.filter(validFamily).slice(0, 16) : [];
@@ -3219,7 +3316,7 @@ function createMultiplayerSettings(storage) {
3219
3316
  }
3220
3317
 
3221
3318
  // src/multiplayer/tool-discovery.ts
3222
- import { lastValueFrom as lastValueFrom8, takeUntil as takeUntil3, timer as timer5, toArray as toArray5 } from "rxjs";
3319
+ import { lastValueFrom as lastValueFrom9, takeUntil as takeUntil4, timer as timer6, toArray as toArray5 } from "rxjs";
3223
3320
  import { decodeEventPointer as decodeEventPointer2, verifyEvent as verifyEvent4 } from "applesauce-core/helpers";
3224
3321
  import { computeCvmToolSchemaHash } from "@kehto/services";
3225
3322
  var KIND_SERVER = 11316;
@@ -3256,7 +3353,7 @@ function parse(input) {
3256
3353
  }
3257
3354
  async function query(options, relays2, filter3) {
3258
3355
  const limit = options.timeoutMs ?? TOOL_DISCOVERY_TIMEOUT_MS;
3259
- const events = await lastValueFrom8(options.pool.request([...relays2], asFilters([{ ...filter3, limit: MAX_TOOLS }])).pipe(takeUntil3(timer5(limit)), toArray5()));
3356
+ const events = await lastValueFrom9(options.pool.request([...relays2], asFilters([{ ...filter3, limit: MAX_TOOLS }])).pipe(takeUntil4(timer6(limit)), toArray5()));
3260
3357
  return events.filter((event) => event.content.length <= MAX_BYTES && verifyEvent4(event)).sort((a, b) => b.created_at - a.created_at);
3261
3358
  }
3262
3359
  async function websiteProvider(url, options) {
@@ -3340,7 +3437,7 @@ var BYTES_PER_SECOND = 524288;
3340
3437
  var MAX_SIGNAL_CHARS = 64e3;
3341
3438
  var MAX_SDP_CHARS = 32e3;
3342
3439
  var UNSET_LIMIT = 65535;
3343
- var HEX_KEY4 = /^[0-9a-f]{64}$/u;
3440
+ var HEX_KEY5 = /^[0-9a-f]{64}$/u;
3344
3441
  var encoder = new TextEncoder();
3345
3442
  function invalid2(message) {
3346
3443
  throw new Error(message);
@@ -3349,8 +3446,8 @@ function validate(request) {
3349
3446
  const { scope } = request;
3350
3447
  if (scope.type === "room") {
3351
3448
  if (typeof scope.room !== "string" || !scope.room || scope.room.length > 256) invalid2("invalid room");
3352
- if (scope.peers && (scope.peers.length > MAX_PEERS || !scope.peers.every((key) => HEX_KEY4.test(key)))) invalid2("invalid peers");
3353
- } else if (scope.type !== "direct" || !HEX_KEY4.test(scope.pubkey)) invalid2("invalid scope");
3449
+ if (scope.peers && (scope.peers.length > MAX_PEERS || !scope.peers.every((key) => HEX_KEY5.test(key)))) invalid2("invalid peers");
3450
+ } else if (scope.type !== "direct" || !HEX_KEY5.test(scope.pubkey)) invalid2("invalid scope");
3354
3451
  if (request.channel !== void 0 && (!request.channel || request.channel.length > 64)) invalid2("invalid channel");
3355
3452
  if (request.protocol !== void 0 && request.protocol.length > 128) invalid2("invalid protocol");
3356
3453
  }
@@ -3365,14 +3462,14 @@ function reliableChannel(channel) {
3365
3462
  function gathered(connection) {
3366
3463
  return new Promise((resolve) => {
3367
3464
  const finish = () => {
3368
- clearTimeout(timer8);
3465
+ clearTimeout(timer9);
3369
3466
  connection.removeEventListener("icegatheringstatechange", changed);
3370
3467
  resolve();
3371
3468
  };
3372
3469
  const changed = () => {
3373
3470
  if (connection.iceGatheringState === "complete") finish();
3374
3471
  };
3375
- const timer8 = setTimeout(finish, GATHER_PATIENCE_MS);
3472
+ const timer9 = setTimeout(finish, GATHER_PATIENCE_MS);
3376
3473
  connection.addEventListener("icegatheringstatechange", changed);
3377
3474
  changed();
3378
3475
  });
@@ -3635,7 +3732,7 @@ function describeDirectConnection(requirements, applet) {
3635
3732
  { label: "They see", after: "Whatever this applet sends them. The shell cannot see it." },
3636
3733
  { label: "Introduced by", after: relays2.join(", ") },
3637
3734
  ...helpers.length > 0 ? [{ label: "Helped by", after: helpers.join(", ") }] : [],
3638
- { label: "They know you as", after: "A new name for this window, not your account" }
3735
+ { label: "They know you as", after: "A new name for this window, not your identity" }
3639
3736
  ],
3640
3737
  applet,
3641
3738
  event: draft
@@ -3726,6 +3823,21 @@ import {
3726
3823
  createUploadService
3727
3824
  } from "@kehto/services";
3728
3825
  import { createBridgeResourceResolver } from "@kernlize/bridges";
3826
+
3827
+ // src/people/locate-recipients.ts
3828
+ function locateRecipients(adapter, people) {
3829
+ return {
3830
+ ...adapter,
3831
+ async send(request) {
3832
+ const recipients = await Promise.all(request.recipients.map((recipient) => people.locate(recipient))).catch(() => {
3833
+ throw new Error("invalid:recipient");
3834
+ });
3835
+ return adapter.send({ ...request, recipients });
3836
+ }
3837
+ };
3838
+ }
3839
+
3840
+ // src/kernl-services.ts
3729
3841
  function isTheme(value) {
3730
3842
  const colors = value?.colors;
3731
3843
  if (typeof colors !== "object" || colors === null) return false;
@@ -3817,8 +3929,8 @@ function gateOutboxPublish(outbox, consent) {
3817
3929
  function createKernlServices(deps) {
3818
3930
  const identity = deps.identity ?? createIdentityProviders(deps.eventStore, deps.pool, deps.tiers);
3819
3931
  const theme = createThemeService(deps.theme ? { initialTheme: deps.theme } : {});
3820
- const composite = deps.messaging.composite();
3821
- const dm = createDmService({ adapter: deps.profiles ? labelConversations(composite, deps.profiles) : composite });
3932
+ const located2 = deps.people ? locateRecipients(deps.messaging.composite(), deps.people) : deps.messaging.composite();
3933
+ const dm = createDmService({ adapter: deps.profiles ? labelConversations(located2, deps.profiles) : located2 });
3822
3934
  const resolve = createBridgeResourceResolver(deps.bridges);
3823
3935
  const identities = deps.identities ?? createWindowIdentities();
3824
3936
  const direct = deps.directConnections;
@@ -3918,7 +4030,7 @@ function grantNarrowingReason(plan, record2, baseline) {
3918
4030
  const { identity } = plan.summary;
3919
4031
  if (record2.identity.dTag !== identity.dTag || record2.identity.hash !== identity.hash) return void 0;
3920
4032
  if (record2.blocked) return "blocked";
3921
- const allowed = /* @__PURE__ */ new Set([...baseline, ...record2.domains]);
4033
+ const allowed = new Set([...baseline, ...record2.domains].filter((domain) => !record2.withheld.includes(domain)));
3922
4034
  return plan.environment.capabilities.domains.some((domain) => !allowed.has(domain)) ? "grant-narrowed" : void 0;
3923
4035
  }
3924
4036
  function keyOf2(identity) {
@@ -4012,7 +4124,7 @@ import { Subscription } from "rxjs";
4012
4124
  import { createIntentService } from "@kehto/services";
4013
4125
 
4014
4126
  // src/intents/defaults.ts
4015
- import { lastValueFrom as lastValueFrom9, Subject as Subject3, takeUntil as takeUntil4, timer as timer6, toArray as toArray6 } from "rxjs";
4127
+ import { lastValueFrom as lastValueFrom10, Subject as Subject3, takeUntil as takeUntil5, timer as timer7, toArray as toArray6 } from "rxjs";
4016
4128
  import { verifyEvent as verifyEvent8 } from "applesauce-core/helpers";
4017
4129
 
4018
4130
  // src/intents/preferences.ts
@@ -4128,7 +4240,7 @@ function createHandlerDefaults(options) {
4128
4240
  loadedFor = pubkey;
4129
4241
  if (!pubkey) return;
4130
4242
  const request = options.pool.request([...preferenceRelays(options.tiers)], asFilters([{ kinds: [HANDLER_PREFERENCES_KIND], authors: [pubkey] }]));
4131
- const events = await lastValueFrom9(request.pipe(takeUntil4(timer6(LOAD_TIMEOUT_MS)), toArray6()), { defaultValue: [] }).catch(() => []);
4243
+ const events = await lastValueFrom10(request.pipe(takeUntil5(timer7(LOAD_TIMEOUT_MS)), toArray6()), { defaultValue: [] }).catch(() => []);
4132
4244
  for (const [archetype, event] of newestPerArchetype(events, pubkey)) {
4133
4245
  published.set(archetype, event);
4134
4246
  changes$.next(archetype);
@@ -4390,7 +4502,7 @@ function createKernlIntents(deps) {
4390
4502
  }
4391
4503
 
4392
4504
  // src/catalog/fetch.ts
4393
- import { auditTime as auditTime2, catchError as catchError4, EMPTY as EMPTY4, from, lastValueFrom as lastValueFrom10, map as map8, merge as merge4, mergeAll, scan, share as share2, takeUntil as takeUntil5, tap, timer as timer7 } from "rxjs";
4505
+ import { auditTime as auditTime2, catchError as catchError5, EMPTY as EMPTY5, from, lastValueFrom as lastValueFrom11, map as map8, merge as merge4, mergeAll, scan, share as share2, takeUntil as takeUntil6, tap as tap2, timer as timer8 } from "rxjs";
4394
4506
  import { getSeenRelays } from "applesauce-core/helpers";
4395
4507
  import { NAPPLET_KIND_NAMED, NAPPLET_KIND_ROOT } from "@kehto/nip/5d";
4396
4508
 
@@ -4438,11 +4550,11 @@ function hintsFor(event, relays2) {
4438
4550
  function streamCatalog(pool, tiers, options = {}) {
4439
4551
  const relays2 = catalogRelays(tiers);
4440
4552
  const filters = asFilters(catalogFilters(options));
4441
- const cached = options.cache ? from(options.cache(filters).catch(() => [])).pipe(mergeAll()) : EMPTY4;
4553
+ const cached = options.cache ? from(options.cache(filters).catch(() => [])).pipe(mergeAll()) : EMPTY5;
4442
4554
  const live = pool.request([...relays2], filters).pipe(
4443
- takeUntil5(timer7(options.timeoutMs ?? CATALOG_TIMEOUT_MS)),
4444
- catchError4(() => EMPTY4),
4445
- tap((event) => options.store?.add(event))
4555
+ takeUntil6(timer8(options.timeoutMs ?? CATALOG_TIMEOUT_MS)),
4556
+ catchError5(() => EMPTY5),
4557
+ tap2((event) => options.store?.add(event))
4446
4558
  );
4447
4559
  const events = merge4(cached, live);
4448
4560
  const found = events.pipe(
@@ -4454,11 +4566,11 @@ function streamCatalog(pool, tiers, options = {}) {
4454
4566
  );
4455
4567
  const listed = (state) => newestEntries(state.listed.filter(({ event }) => !isWithdrawn(event, state.withdrawn)).map(({ entry }) => entry));
4456
4568
  const lists = found.pipe(auditTime2(options.emitMs ?? CATALOG_EMIT_MS), map8(listed), share2());
4457
- const nothingYet = timer7(options.settleMs ?? CATALOG_SETTLE_MS).pipe(map8(() => Object.freeze([])), takeUntil5(lists));
4569
+ const nothingYet = timer8(options.settleMs ?? CATALOG_SETTLE_MS).pipe(map8(() => Object.freeze([])), takeUntil6(lists));
4458
4570
  return merge4(nothingYet, lists);
4459
4571
  }
4460
4572
  async function loadCatalog(pool, tiers, options = {}) {
4461
- return lastValueFrom10(streamCatalog(pool, tiers, options), { defaultValue: Object.freeze([]) });
4573
+ return lastValueFrom11(streamCatalog(pool, tiers, options), { defaultValue: Object.freeze([]) });
4462
4574
  }
4463
4575
 
4464
4576
  // src/kernl.ts
@@ -4612,11 +4724,8 @@ function createKernl(options) {
4612
4724
  onRelease: (windowId) => bridge.releaseDeferred(windowId)
4613
4725
  });
4614
4726
  const identityOf = (windowId) => handles.get(windowId)?.summary.identity;
4615
- const { eventCache, replaceableLoader, profiles, directory, mailboxes, files, signer } = createKernlNetwork(options, { eventStore, pool, tiers, accounts, destroyed$ });
4616
- const lookupBefore = lookupReplaceable(eventStore, {
4617
- loader: replaceableLoader,
4618
- relays: () => [...tiers.get().outbox, ...tiers.get().discovery]
4619
- });
4727
+ const { eventCache, replaceableLoader, profiles, people, directory, mailboxes, files, signer } = createKernlNetwork(options, { eventStore, pool, tiers, accounts, destroyed$ });
4728
+ const lookupBefore = lookupReplaceable(eventStore, { loader: replaceableLoader, relays: () => [...tiers.get().outbox, ...tiers.get().discovery] });
4620
4729
  const consent = createSigningConsent({ host, lookupBefore, resolveApplet: identityOf, pubkey: () => accounts.active?.pubkey });
4621
4730
  const meeting = meetingFor(options, { pool, tiers, appletOf: (windowId) => handles.get(windowId)?.summary, grants: () => grants });
4622
4731
  const services = createKernlServices({
@@ -4629,8 +4738,9 @@ function createKernl(options) {
4629
4738
  bridges,
4630
4739
  messaging,
4631
4740
  profiles,
4741
+ people,
4632
4742
  ...host.presentSettings ? { config: createAppletConfig({ storage: host.storage, appletOf: (windowId) => appletOf(handles, windowId), present: host.presentSettings.bind(host) }) } : {},
4633
- common: commonActionsFor({ eventStore, pool, tiers, accounts }, { profiles, replaceableLoader, signer }, consent),
4743
+ common: commonActionsFor({ eventStore, pool, tiers, accounts }, { profiles, people, replaceableLoader, signer }, consent),
4634
4744
  uploader: uploaderFor(host, files, signer, identityOf),
4635
4745
  ...isTheme(options.theme) ? { theme: options.theme } : {},
4636
4746
  ...meeting.deps,
@@ -4693,6 +4803,7 @@ function createKernl(options) {
4693
4803
  stream: (streamOptions) => streamCatalog(pool, tiers, { cache: eventCache.cacheRequest, store: eventStore, ...streamOptions })
4694
4804
  },
4695
4805
  profiles,
4806
+ people,
4696
4807
  mailboxes,
4697
4808
  files,
4698
4809
  multiplayer: meeting.multiplayer,
@@ -4798,13 +4909,18 @@ export {
4798
4909
  KernlAccountManager,
4799
4910
  LINK_PROTOCOLS,
4800
4911
  MANIFEST_TIMING,
4912
+ MESSAGES_DOMAIN,
4913
+ MESSAGE_COMPANION_DOMAINS,
4801
4914
  MESSAGING_UNAVAILABLE_REASONS,
4802
4915
  PACKAGE_NAME,
4916
+ PERSON_HINT_TIMEOUT_MS,
4803
4917
  PLAINTEXT_KEY_ACCOUNT_TYPES,
4804
4918
  RUNTIME_FIREWALL_STORAGE_KEY,
4805
4919
  RUNTIME_OP_CLASSES,
4806
4920
  SHELL_RELAY_OPTIONS,
4921
+ THROWAWAY_IDENTITY_TYPE,
4807
4922
  TOOL_DISCOVERY_TIMEOUT_MS,
4923
+ ThrowawayIdentity,
4808
4924
  UNKNOWN_CURRENT_VERSION,
4809
4925
  abbreviate,
4810
4926
  addressOf,
@@ -4815,6 +4931,7 @@ export {
4815
4931
  builtinAddress,
4816
4932
  capabilitiesForDomain,
4817
4933
  capabilitiesForDomains,
4934
+ capabilitiesInForce,
4818
4935
  catalogIdForRef,
4819
4936
  catalogRelays,
4820
4937
  commonActionsFor,
@@ -4863,6 +4980,7 @@ export {
4863
4980
  createMultiplayerSettings,
4864
4981
  createNamespacedStore,
4865
4982
  createOutboxRelayPool,
4983
+ createPeople,
4866
4984
  createPrivateMessagesBackend,
4867
4985
  createProfiles,
4868
4986
  createRatchetMessagesBackend,
@@ -4878,6 +4996,7 @@ export {
4878
4996
  createShellAdapter,
4879
4997
  createSigningConsent,
4880
4998
  createSqliteOpfsCacheAdapter,
4999
+ createThrowawayIdentity,
4881
5000
  createWindowIdentities,
4882
5001
  createWindowManager,
4883
5002
  decodePointer,
@@ -4889,6 +5008,7 @@ export {
4889
5008
  describeUpload,
4890
5009
  directNamespace,
4891
5010
  discoverToolFamilies,
5011
+ domainsInForce,
4892
5012
  fetchManifestEvent,
4893
5013
  fileServerTags,
4894
5014
  fileServersFromEvent,
@@ -4903,6 +5023,7 @@ export {
4903
5023
  isTheme,
4904
5024
  labelConversations,
4905
5025
  loadCatalog,
5026
+ locateRecipients,
4906
5027
  lookupRelaysOf,
4907
5028
  lookupReplaceable,
4908
5029
  mailboxTags,
@@ -4914,6 +5035,7 @@ export {
4914
5035
  openDefaultArtifactCache,
4915
5036
  openEventCache,
4916
5037
  parseHandlerPreferences,
5038
+ parsePerson,
4917
5039
  planMount,
4918
5040
  popularTopics,
4919
5041
  preferenceRelays,
@@ -4929,6 +5051,7 @@ export {
4929
5051
  resolveWindow,
4930
5052
  resourceInitFor,
4931
5053
  runtimeFirewallRules,
5054
+ sealsApplet,
4932
5055
  searchCatalog,
4933
5056
  selectRelayTier,
4934
5057
  signerAvailability,
@@ -4943,6 +5066,7 @@ export {
4943
5066
  toRelayUrl,
4944
5067
  toSession,
4945
5068
  validFamily,
5069
+ withheldDomains,
4946
5070
  wrapAccountSigner
4947
5071
  };
4948
5072
  //# sourceMappingURL=index.js.map