@ipab/cli 0.1.0-rc.4 → 0.1.0-rc.5

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.
Files changed (92) hide show
  1. package/README.md +12 -7
  2. package/dist/cli.d.ts +3 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +114 -25
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config-secret.d.ts +1 -1
  7. package/dist/config-secret.d.ts.map +1 -1
  8. package/dist/config-secret.js +2 -73
  9. package/dist/config-secret.js.map +1 -1
  10. package/dist/config.d.ts +1 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +12 -1
  13. package/dist/config.js.map +1 -1
  14. package/dist/context-types.d.ts +12 -0
  15. package/dist/context-types.d.ts.map +1 -0
  16. package/dist/context-types.js +2 -0
  17. package/dist/context-types.js.map +1 -0
  18. package/dist/context.d.ts +6 -0
  19. package/dist/context.d.ts.map +1 -1
  20. package/dist/context.js +25 -0
  21. package/dist/context.js.map +1 -1
  22. package/dist/ipc.d.ts +3 -1
  23. package/dist/ipc.d.ts.map +1 -1
  24. package/dist/ipc.js +34 -1
  25. package/dist/ipc.js.map +1 -1
  26. package/dist/kubo-install.d.ts +9 -0
  27. package/dist/kubo-install.d.ts.map +1 -0
  28. package/dist/kubo-install.js +361 -0
  29. package/dist/kubo-install.js.map +1 -0
  30. package/dist/kubo-peering.d.ts +11 -0
  31. package/dist/kubo-peering.d.ts.map +1 -0
  32. package/dist/kubo-peering.js +93 -0
  33. package/dist/kubo-peering.js.map +1 -0
  34. package/dist/kubo-peers.d.ts +12 -0
  35. package/dist/kubo-peers.d.ts.map +1 -0
  36. package/dist/kubo-peers.js +118 -0
  37. package/dist/kubo-peers.js.map +1 -0
  38. package/dist/kubo-release.d.ts +3 -0
  39. package/dist/kubo-release.d.ts.map +1 -0
  40. package/dist/kubo-release.js +12 -0
  41. package/dist/kubo-release.js.map +1 -0
  42. package/dist/kubo.d.ts +11 -4
  43. package/dist/kubo.d.ts.map +1 -1
  44. package/dist/kubo.js +150 -197
  45. package/dist/kubo.js.map +1 -1
  46. package/dist/runtime.d.ts +2 -0
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +6 -2
  49. package/dist/runtime.js.map +1 -1
  50. package/dist/setup.d.ts +2 -1
  51. package/dist/setup.d.ts.map +1 -1
  52. package/dist/setup.js +23 -18
  53. package/dist/setup.js.map +1 -1
  54. package/dist/state-storage-windows.d.ts +2 -0
  55. package/dist/state-storage-windows.d.ts.map +1 -0
  56. package/dist/state-storage-windows.js +114 -0
  57. package/dist/state-storage-windows.js.map +1 -0
  58. package/dist/state-storage.d.ts +3 -0
  59. package/dist/state-storage.d.ts.map +1 -0
  60. package/dist/state-storage.js +299 -0
  61. package/dist/state-storage.js.map +1 -0
  62. package/dist/state.d.ts +2 -2
  63. package/dist/state.d.ts.map +1 -1
  64. package/dist/state.js +59 -29
  65. package/dist/state.js.map +1 -1
  66. package/dist/swarm-files.d.ts +1 -1
  67. package/dist/swarm-files.d.ts.map +1 -1
  68. package/dist/swarm-files.js +4 -1
  69. package/dist/swarm-files.js.map +1 -1
  70. package/dist/swarm.d.ts +6 -3
  71. package/dist/swarm.d.ts.map +1 -1
  72. package/dist/swarm.js +184 -70
  73. package/dist/swarm.js.map +1 -1
  74. package/package.json +4 -4
  75. package/src/cli.ts +146 -39
  76. package/src/config-secret.ts +2 -84
  77. package/src/config.ts +14 -1
  78. package/src/context-types.ts +11 -0
  79. package/src/context.ts +40 -0
  80. package/src/ipc.ts +50 -1
  81. package/src/kubo-install.ts +452 -0
  82. package/src/kubo-peering.ts +126 -0
  83. package/src/kubo-peers.ts +145 -0
  84. package/src/kubo-release.ts +17 -0
  85. package/src/kubo.ts +207 -269
  86. package/src/runtime.ts +12 -1
  87. package/src/setup.ts +30 -17
  88. package/src/state-storage-windows.ts +134 -0
  89. package/src/state-storage.ts +329 -0
  90. package/src/state.ts +68 -35
  91. package/src/swarm-files.ts +4 -0
  92. package/src/swarm.ts +256 -90
package/dist/swarm.js CHANGED
@@ -13,13 +13,15 @@ import { canonicalService, isCanonicalPublicKey, POINTER_ID_PATTERN, } from "@ip
13
13
  import { importPrivateKeyPkcs8, importPublicKeyRaw, keyId, signEd25519, verifyEd25519, } from "@ipab/bundle/pointer/crypto";
14
14
  import { HostError, object, message } from "./errors.js";
15
15
  import { accountIdentity } from "./identity.js";
16
+ import { swarmUrl as canonicalSwarmUrl } from "./config.js";
16
17
  import { bundleJson, provideContent } from "./content-provider.js";
17
18
  import { bytes, relativePath } from "./space.js";
18
19
  import { appSchemaCid } from "./app-definition.js";
19
20
  import { State } from "./state.js";
20
21
  import { privateDirectory, readPrivate, withPrivateLock, writePrivate, } from "./swarm-files.js";
21
22
  import { encryptionIdentity, openApproval, sealApproval, parseEnvelope, } from "./swarm-envelope.js";
22
- import { kuboSource, peerId, peerProof, prepareNode, startNode, validateAddress, } from "./kubo.js";
23
+ import { checkCachedNode, kuboSource, peerId, peerProof, prepareNode, startNode, validateAddress, } from "./kubo.js";
24
+ import { memberPeers } from "./kubo-peering.js";
23
25
  async function contextIdentity(context, initialize = false) {
24
26
  context.identity ??= await accountIdentity(context.env, initialize);
25
27
  return context.identity;
@@ -49,20 +51,7 @@ function withState(context, operation) {
49
51
  state.close();
50
52
  }
51
53
  }
52
- export function canonicalSwarmUrl(value) {
53
- if (!/^https?:\/\//.test(value))
54
- throw new HostError("Swarm requires a configuration URL; old Swarm CID protocol is unsupported.");
55
- const url = new URL(value);
56
- canonicalService(url.origin);
57
- if (url.search ||
58
- url.hash ||
59
- url.username ||
60
- url.password ||
61
- url.toString() !== value ||
62
- !/^\/v1\/[a-f0-9]{16}\/[a-f0-9]{16}$/.test(url.pathname))
63
- throw new HostError("Swarm must be an exact Scope configuration URL; old Swarm CID protocol is unsupported.");
64
- return value;
65
- }
54
+ export { canonicalSwarmUrl };
66
55
  function coordinates(configUrl) {
67
56
  const url = new URL(canonicalSwarmUrl(configUrl));
68
57
  const [, , scopeId, configId] = url.pathname.split("/");
@@ -195,11 +184,12 @@ function parseProfile(value, expectedPeer) {
195
184
  }
196
185
  return { name: data.name, addresses, updatedAt: data.updatedAt };
197
186
  }
198
- async function fetchConfig(context, configUrl) {
187
+ async function fetchConfig(context, configUrl, signal) {
199
188
  const c = coordinates(configUrl), api = client(context, c.service);
189
+ const options = signal ? { signal } : {};
200
190
  const [variable, scope] = await Promise.all([
201
- api.read(c.scopeId, c.configId),
202
- api.send("GET", c.scopeId),
191
+ api.read(c.scopeId, c.configId, options),
192
+ api.send("GET", c.scopeId, "", undefined, options),
203
193
  ]);
204
194
  const config = parseOrganization(variable.value, configUrl);
205
195
  if (scope.owner !== config.owner)
@@ -234,7 +224,7 @@ async function validateMembershipSecret(record, config, member) {
234
224
  throw new HostError("Membership package must grant exactly HEAD and this member's profile.");
235
225
  }
236
226
  }
237
- async function activate(context, record) {
227
+ async function privateSource(context, record, signal) {
238
228
  const config = record.config, secret = record.secret;
239
229
  const identity = await contextIdentity(context);
240
230
  const self = config.members.find((member) => member.publicKey === identity.publicKey);
@@ -245,10 +235,10 @@ async function activate(context, record) {
245
235
  await verifyScopeCertificate(secret.certificate, config.owner, c.service, c.scopeId, config.headId, identity.publicKey);
246
236
  await verifyScopeCertificate(secret.certificate, config.owner, c.service, c.scopeId, self.profileId, identity.publicKey);
247
237
  }
248
- const addresses = [...config.bootstrap];
238
+ const addresses = new Map();
249
239
  const api = client(context, c.service);
250
240
  let selfProfile;
251
- const profiles = await Promise.allSettled(config.members.map((member) => api.read(c.scopeId, member.profileId)));
241
+ const profiles = await Promise.allSettled(config.members.map((member) => api.read(c.scopeId, member.profileId, signal ? { signal } : {})));
252
242
  for (const [index, member] of config.members.entries()) {
253
243
  const result = profiles[index];
254
244
  if (result.status === "rejected")
@@ -257,35 +247,58 @@ async function activate(context, record) {
257
247
  const value = parseProfile(profile.value, member.peerId);
258
248
  if (member.publicKey === identity.publicKey)
259
249
  selfProfile = { profile: value, cid: profile.cid };
260
- addresses.push(...value.addresses);
250
+ addresses.set(member.peerId, value.addresses);
261
251
  }
262
- const node = await startNode(context.stateDir, nodeScope(c.service, config.scopeId), secret.swarmKey, config.epoch, [...new Set(addresses)], context.diagnostic, context.listen);
252
+ const desired = memberPeers(self.peerId, addresses, config.bootstrap);
253
+ signal?.throwIfAborted();
254
+ const node = await startNode(context.stateDir, nodeScope(c.service, config.scopeId), secret.swarmKey, config.epoch, context.listen, { self: self.peerId, peers: desired, ...(signal ? { signal } : {}) });
263
255
  if (node.peerId !== self.peerId)
264
256
  throw new HostError("Approved PeerID differs from this local Request's Kubo identity.");
265
- if (context.node?.api !== node.api) {
266
- const store = context.store.withLocalSource(kuboSource(node));
267
- await context.store.close();
268
- context.store = store;
269
- }
270
- context.node = node;
271
- if (selfProfile && selfProfile.profile.addresses.length === 0) {
257
+ const peers = desired.flatMap(({ ID, Addrs }) => Addrs.map((addr) => `${addr}/p2p/${ID}`));
258
+ signal?.throwIfAborted();
259
+ if (!node.addresses.length && !selfProfile?.profile.addresses.length)
260
+ context.diagnostic?.("No private LAN/VPN IPv4 address to advertise. Connect a routed interface or set your own address with swarm profile --address.");
261
+ if (node.addresses.length &&
262
+ selfProfile &&
263
+ selfProfile.profile.addresses.length === 0) {
272
264
  const writer = client(context, c.service, identity, identity.publicKey === config.owner ? undefined : secret);
273
265
  const profile = {
274
266
  ...selfProfile.profile,
275
267
  addresses: node.addresses,
276
268
  updatedAt: new Date().toISOString(),
277
269
  };
278
- await writer.write(c.scopeId, self.profileId, profile, selfProfile.cid, uniqueId());
270
+ await writer.write(c.scopeId, self.profileId, profile, selfProfile.cid, uniqueId(), signal ? { signal } : {});
279
271
  }
272
+ return {
273
+ node,
274
+ peers,
275
+ source: kuboSource(node, peers, context.diagnostic, context.env.IPAB_SWARM_DIAL_DEBUG === "1"),
276
+ };
280
277
  }
281
- async function refresh(context, configUrl) {
278
+ async function activate(context, record) {
279
+ const { node, peers, source } = await privateSource(context, record);
280
+ if (context.node?.api !== node.api ||
281
+ context.sourcePeers?.length !== peers.length ||
282
+ peers.some((peer, i) => context.sourcePeers?.[i] !== peer)) {
283
+ const store = context.store.withLocalSource(source);
284
+ await context.store.close();
285
+ context.store = store;
286
+ context.sourcePeers = peers;
287
+ }
288
+ context.node = node;
289
+ }
290
+ async function localForRead(context, configUrl) {
282
291
  const record = await local(context, configUrl);
283
292
  if (record.account === record.owner) {
284
293
  const transition = await readPrivate(await directory(context), `transition-${localName(configUrl)}`);
285
294
  if (transition && !transition.completed)
286
295
  throw new HostError("Organization switch incomplete; only Owner can continue with swarm resume.");
287
296
  }
288
- const { config } = await fetchConfig(context, configUrl);
297
+ return record;
298
+ }
299
+ async function approvedMembership(context, configUrl, signal) {
300
+ const record = await localForRead(context, configUrl);
301
+ const { config } = await fetchConfig(context, configUrl, signal);
289
302
  if (config.owner !== record.owner)
290
303
  throw new HostError("Pinned Owner changed; refusing configuration.");
291
304
  if (record.config && config.epoch < record.config.epoch)
@@ -305,17 +318,16 @@ async function refresh(context, configUrl) {
305
318
  throw new HostError("Owner key/Swarm key lost: no system recovery is available.");
306
319
  record.config = config;
307
320
  await validateMembershipSecret(record, config, member);
321
+ return record;
322
+ }
323
+ async function refresh(context, configUrl) {
324
+ const record = await approvedMembership(context, configUrl);
308
325
  await saveLocal(context, record);
309
326
  await activate(context, record);
310
327
  return record;
311
328
  }
312
329
  async function readyMembership(context, configUrl) {
313
- const record = await local(context, configUrl);
314
- if (record.account === record.owner) {
315
- const transition = await readPrivate(await directory(context), `transition-${localName(configUrl)}`);
316
- if (transition && !transition.completed)
317
- throw new HostError("Organization switch incomplete; run swarm resume before normal Owner operations.");
318
- }
330
+ const record = await localForRead(context, configUrl);
319
331
  if (!record.config || !record.secret)
320
332
  return refresh(context, configUrl);
321
333
  if (!context.node ||
@@ -500,21 +512,9 @@ export async function swarmHeader(context, configUrl, force = context.forceRefre
500
512
  let record = force
501
513
  ? await refresh(context, configUrl)
502
514
  : await readyMembership(context, configUrl);
503
- const ttl = context.cacheTtl ?? 300;
504
- const cached = force
505
- ? undefined
506
- : withState(context, (state) => state.swarmHeader(record.account, configUrl));
507
- if (cached &&
508
- cached.headId === record.config.headId &&
509
- Date.now() >= cached.verifiedAt &&
510
- Date.now() - cached.verifiedAt < ttl * 1000)
511
- return {
512
- head: headValue(cached.head),
513
- snapshot: decodeSnapshot(Buffer.from(cached.snapshot, "base64")),
514
- config: record.config,
515
- source: "cache",
516
- verifiedAt: new Date(cached.verifiedAt).toISOString(),
517
- };
515
+ const cached = !force && cachedHeader(context, record);
516
+ if (cached)
517
+ return cached;
518
518
  let head = await (await boundPointer(context, configUrl, record)).read();
519
519
  let snapshot;
520
520
  try {
@@ -532,6 +532,7 @@ export async function swarmHeader(context, configUrl, force = context.forceRefre
532
532
  snapshot: Buffer.from(dagCbor.encode(snapshot)).toString("base64"),
533
533
  verifiedAt,
534
534
  headId: current.config.headId,
535
+ epoch: current.config.epoch,
535
536
  });
536
537
  });
537
538
  return {
@@ -542,6 +543,93 @@ export async function swarmHeader(context, configUrl, force = context.forceRefre
542
543
  verifiedAt: new Date(verifiedAt).toISOString(),
543
544
  };
544
545
  }
546
+ function cachedHeader(context, record) {
547
+ const config = record.config;
548
+ if (!config || !record.secret)
549
+ return;
550
+ const cached = withState(context, (state) => state.swarmHeader(record.account, record.configUrl));
551
+ const age = cached ? Date.now() - cached.verifiedAt : NaN;
552
+ if (!cached ||
553
+ cached.headId !== config.headId ||
554
+ (cached.epoch !== undefined && cached.epoch !== config.epoch) ||
555
+ !(age >= 0 && age < (context.cacheTtl ?? 300) * 1000))
556
+ return;
557
+ return {
558
+ head: headValue(cached.head),
559
+ snapshot: decodeSnapshot(Buffer.from(cached.snapshot, "base64")),
560
+ config,
561
+ source: "cache",
562
+ verifiedAt: new Date(cached.verifiedAt).toISOString(),
563
+ };
564
+ }
565
+ async function localHeader(context, url) {
566
+ if (context.forceRefresh)
567
+ return;
568
+ canonicalSwarmUrl(url);
569
+ const record = await localForRead(context, url);
570
+ const header = cachedHeader(context, record);
571
+ if (!header)
572
+ return;
573
+ const config = parseOrganization(header.config, url);
574
+ const member = config.members.find((item) => item.publicKey === record.account);
575
+ if (!member || config.owner !== record.owner)
576
+ throw new HostError("Cached membership no longer matches the account or Owner.");
577
+ if (record.account !== config.owner &&
578
+ (!record.request ||
579
+ record.request.id !== member.requestId ||
580
+ record.request.peerId !== member.peerId ||
581
+ !member.approval))
582
+ throw new HostError("Cached membership does not match the saved Request.");
583
+ await validateMembershipSecret(record, config, member);
584
+ const c = coordinates(url);
585
+ await checkCachedNode(context.stateDir, nodeScope(c.service, c.scopeId), config.epoch, member.peerId);
586
+ return { header, account: record.account };
587
+ }
588
+ // SharedContent invokes this source only after a genuine local ENOENT. Its
589
+ // store is not replaced from inside its own pending read (which would deadlock).
590
+ async function lazyPrivateSource(context, url, account, basis) {
591
+ const lifetime = new AbortController();
592
+ let pending;
593
+ const load = async (signal) => {
594
+ const scoped = { ...context };
595
+ // Re-read the protected HOME binding and live approval on the first miss;
596
+ // do not serve an old resolved Name through a different epoch or identity.
597
+ delete scoped.identity;
598
+ const authorize = async () => {
599
+ const record = await approvedMembership(scoped, url, signal);
600
+ signal.throwIfAborted();
601
+ if (record.account !== account ||
602
+ record.config.owner !== basis.owner ||
603
+ record.config.epoch !== basis.epoch ||
604
+ record.config.headId !== basis.headId)
605
+ throw new HostError("Swarm membership changed since this cached HEAD; retry with --force.");
606
+ return (await privateSource(scoped, record, signal)).source;
607
+ };
608
+ // Same lock order as Owner rotation: credentials first, then the node.
609
+ return withPrivateLock(await directory(scoped), authorize, signal);
610
+ };
611
+ const store = context.store.withLocalSource({
612
+ block: {
613
+ async get(cid, options = {}) {
614
+ const signal = options.signal
615
+ ? AbortSignal.any([lifetime.signal, options.signal])
616
+ : lifetime.signal;
617
+ signal.throwIfAborted();
618
+ const source = await (pending ??= load(signal));
619
+ signal.throwIfAborted();
620
+ return source.block.get(cid, { signal });
621
+ },
622
+ },
623
+ });
624
+ await context.store.close();
625
+ context.store = store;
626
+ delete context.node;
627
+ delete context.sourcePeers;
628
+ context.finishRead = async () => {
629
+ lifetime.abort();
630
+ await pending?.catch(() => { });
631
+ };
632
+ }
545
633
  export async function addSwarm(context, url, alias) {
546
634
  canonicalSwarmUrl(url);
547
635
  await readyMembership(context, url);
@@ -1073,33 +1161,55 @@ export function formalName(name) {
1073
1161
  throw new HostError("Invalid formal Name.");
1074
1162
  return name;
1075
1163
  }
1164
+ function decodeNameComponent(value, part) {
1165
+ try {
1166
+ return decodeURIComponent(value);
1167
+ }
1168
+ catch {
1169
+ throw new HostError(`Malformed percent-encoding in IPAB URI ${part}; use valid UTF-8 escapes or copy the reference from ipab search.`);
1170
+ }
1171
+ }
1076
1172
  export function parseNameReference(reference) {
1077
1173
  if (/^name:/i.test(reference))
1078
1174
  throw new HostError("name: is unsupported; use ipab://ALIAS/PATH.");
1079
1175
  if (!/^ipab:/i.test(reference))
1080
1176
  return undefined;
1081
- const match = /^ipab:\/\/([^/]*)\/([^?#\s]*)$/i.exec(reference);
1177
+ if (/^ipab:\/\/https?:\/\//i.test(reference))
1178
+ throw new HostError("Unencoded configuration URL in IPAB URI. Percent-encode the entire configuration URL and each Name path segment separately, or copy the reference from ipab search.");
1179
+ const match = /^ipab:\/\/([^/]*)\/(.*)$/is.exec(reference);
1082
1180
  if (!match)
1083
1181
  throw new HostError("Invalid IPAB URI; percent-encode the configuration URL authority and each path segment.");
1084
- const authority = decodeURIComponent(match[1]);
1085
- if (authority && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(authority))
1182
+ const authority = decodeNameComponent(match[1], "authority");
1183
+ if (authority && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(authority)) {
1184
+ if (!/^https?:\/\//i.test(authority))
1185
+ throw new HostError("Invalid IPAB URI authority; use a registered alias or the percent-encoded configuration URL.");
1086
1186
  canonicalSwarmUrl(authority);
1187
+ }
1188
+ if (/[?#\s]/.test(match[2]))
1189
+ throw new HostError("Invalid IPAB URI path; percent-encode each Name path segment. Queries and fragments are not supported.");
1087
1190
  const segments = match[2].split("/").map((segment) => {
1088
- const decoded = decodeURIComponent(segment);
1089
- if (decoded.includes("/"))
1090
- throw new HostError("Encoded path separators are unsupported.");
1191
+ const decoded = decodeNameComponent(segment, "path");
1192
+ if (/[/\\]/.test(decoded))
1193
+ throw new HostError("Invalid IPAB URI path separator; use literal / between Name segments, never an encoded slash or backslash.");
1091
1194
  return decoded;
1092
1195
  });
1093
- return {
1094
- ...(authority ? { swarm: authority } : {}),
1095
- name: formalName(segments.join("/")),
1096
- };
1196
+ try {
1197
+ return {
1198
+ ...(authority ? { swarm: authority } : {}),
1199
+ name: formalName(segments.join("/")),
1200
+ };
1201
+ }
1202
+ catch (error) {
1203
+ if (!(error instanceof HostError))
1204
+ throw error;
1205
+ throw new HostError("Invalid IPAB URI path; use a safe relative Name of at most 256 characters without empty, . or .. segments.", error.exitCode, error.code, error.phase);
1206
+ }
1097
1207
  }
1098
- function referenceFor(url, name) {
1208
+ export function formatNameReference(swarm, name) {
1099
1209
  const segment = (value) => encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
1100
- return `ipab://${segment(url)}/${name.split("/").map(segment).join("/")}`;
1210
+ return `ipab://${segment(swarm)}/${name.split("/").map(segment).join("/")}`;
1101
1211
  }
1102
- export async function resolveReference(context, reference, swarm, local, raw = false) {
1212
+ export async function resolveReference(context, reference, swarm, local, raw = false, mode = "active") {
1103
1213
  const shared = parseNameReference(reference);
1104
1214
  let targetCid;
1105
1215
  if (shared) {
@@ -1108,7 +1218,8 @@ export async function resolveReference(context, reference, swarm, local, raw = f
1108
1218
  : swarm;
1109
1219
  if (!selected)
1110
1220
  throw new HostError("Select a configuration URL/alias using --swarm or swarm use.");
1111
- let header = await swarmHeader(context, selected);
1221
+ const warm = mode === "local-first" ? await localHeader(context, selected) : undefined;
1222
+ let header = warm?.header ?? (await swarmHeader(context, selected));
1112
1223
  let link = Object.hasOwn(header.snapshot.names, shared.name)
1113
1224
  ? header.snapshot.names[shared.name]
1114
1225
  : undefined;
@@ -1120,6 +1231,8 @@ export async function resolveReference(context, reference, swarm, local, raw = f
1120
1231
  }
1121
1232
  if (!link)
1122
1233
  throw new HostError(`Formal Name "${shared.name}" was not found after refreshing HEAD.`);
1234
+ if (warm && header === warm.header)
1235
+ await lazyPrivateSource(context, selected, warm.account, header.config);
1123
1236
  targetCid = link.toString();
1124
1237
  }
1125
1238
  else {
@@ -1152,7 +1265,8 @@ export async function searchNames(context, query, swarms) {
1152
1265
  const matches = [];
1153
1266
  const searched = [];
1154
1267
  for (const swarm of swarms) {
1155
- const header = await swarmHeader(context, swarm.cid);
1268
+ const header = (await localHeader(context, swarm.cid))?.header ??
1269
+ (await swarmHeader(context, swarm.cid));
1156
1270
  searched.push({
1157
1271
  configUrl: swarm.cid,
1158
1272
  source: header.source,
@@ -1166,7 +1280,7 @@ export async function searchNames(context, query, swarms) {
1166
1280
  swarm: swarm.cid,
1167
1281
  alias: swarm.alias,
1168
1282
  name,
1169
- reference: referenceFor(swarm.cid, name),
1283
+ reference: formatNameReference(swarm.cid, name),
1170
1284
  targetCid: header.snapshot.names[name].toString(),
1171
1285
  });
1172
1286
  }