pico-engine 1.6.4 → 1.8.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.
Files changed (98) hide show
  1. package/README.md +13 -8
  2. package/dist/RulesetRegistryLoaderFs.js +14 -2
  3. package/dist/auth/cookies.js +32 -0
  4. package/dist/auth/index.js +6 -1
  5. package/dist/channelIdentityPolicy.js +22 -0
  6. package/dist/cli.js +104 -69
  7. package/dist/engineConfig.js +280 -0
  8. package/dist/identity/IdentityService.js +90 -0
  9. package/dist/identity/crossPico.js +24 -8
  10. package/dist/identity/didoModule.js +80 -18
  11. package/dist/identity/establishSubscription.js +2 -2
  12. package/dist/identity/identityPortable.js +92 -0
  13. package/dist/identity/index.js +10 -1
  14. package/dist/identity/localPeerReconcile.js +65 -0
  15. package/dist/identity/peerDid4.js +175 -0
  16. package/dist/identity/peerDid4Create.js +90 -0
  17. package/dist/identity/portableExportPrepare.js +196 -0
  18. package/dist/identity/portableMove.js +87 -0
  19. package/dist/identity/skyIntro.js +6 -3
  20. package/dist/identity/skyProtocol.js +26 -1
  21. package/dist/identity/skyRotation.js +121 -0
  22. package/dist/identity/store.js +5 -1
  23. package/dist/identity/subscriptionEntSync.js +72 -0
  24. package/dist/identity/veramoDidComm.js +41 -2
  25. package/dist/identity/webvh.js +4 -2
  26. package/dist/identity/webvhRelocation.js +115 -0
  27. package/dist/index.js +82 -22
  28. package/dist/logging.js +8 -12
  29. package/dist/oauth/OAuthService.js +6 -2
  30. package/dist/policyConfigFromJson.js +112 -0
  31. package/dist/runMcp.js +27 -0
  32. package/dist/server.js +56 -24
  33. package/dist/subtreeWrangler.js +180 -0
  34. package/dist/uiChannelPolicies.js +15 -0
  35. package/krl/io.picolabs.oauth.krl +41 -2
  36. package/krl/io.picolabs.pds.krl +131 -10
  37. package/krl/io.picolabs.pico-engine-ui.krl +209 -21
  38. package/krl/io.picolabs.portable_subtree.krl +97 -0
  39. package/krl/io.picolabs.subscription.krl +180 -72
  40. package/krl/io.picolabs.wrangler.krl +296 -57
  41. package/mcp/devResources.js +118 -0
  42. package/mcp/devTools.js +351 -0
  43. package/mcp/engineClient.js +133 -0
  44. package/mcp/meshHttp.js +137 -0
  45. package/mcp/meshTools.js +189 -0
  46. package/mcp/runStdio.js +34 -0
  47. package/mcp/schemaToZod.js +56 -0
  48. package/package.json +20 -8
  49. package/public/docs/_sidebar.md +2 -1
  50. package/public/docs/llms-full.txt +479 -0
  51. package/public/docs/llms.txt +37 -0
  52. package/public/docs/openapi.yaml +78 -0
  53. package/public/docs/pico-engine.md +235 -4
  54. package/public/docs/pico-overview.md +117 -0
  55. package/public/docs/pico.md +3 -1
  56. package/public/docs/rulesets/README.md +25 -0
  57. package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
  58. package/public/docs/rulesets/io.picolabs.pds.md +327 -0
  59. package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
  60. package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
  61. package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
  62. package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
  63. package/public/pico-engine-ui.css +1 -1
  64. package/public/pico-engine-ui.js +28 -26
  65. package/src/RulesetRegistryLoaderFs.ts +18 -3
  66. package/src/auth/cookies.ts +34 -0
  67. package/src/auth/index.ts +7 -0
  68. package/src/channelIdentityPolicy.ts +29 -0
  69. package/src/cli.ts +68 -37
  70. package/src/engineConfig.ts +345 -0
  71. package/src/identity/IdentityService.ts +189 -1
  72. package/src/identity/crossPico.ts +57 -8
  73. package/src/identity/didoModule.ts +140 -23
  74. package/src/identity/establishSubscription.ts +2 -2
  75. package/src/identity/identityPortable.ts +153 -0
  76. package/src/identity/index.ts +14 -0
  77. package/src/identity/localPeerReconcile.ts +97 -0
  78. package/src/identity/peerDid4.ts +197 -0
  79. package/src/identity/peerDid4Create.ts +121 -0
  80. package/src/identity/portableExportPrepare.ts +302 -0
  81. package/src/identity/portableMove.ts +193 -0
  82. package/src/identity/skyIntro.ts +11 -11
  83. package/src/identity/skyProtocol.ts +46 -0
  84. package/src/identity/skyRotation.ts +211 -0
  85. package/src/identity/store.ts +5 -1
  86. package/src/identity/subscriptionEntSync.ts +97 -0
  87. package/src/identity/veramoDidComm.ts +52 -2
  88. package/src/identity/webvh.ts +4 -4
  89. package/src/identity/webvhRelocation.ts +167 -0
  90. package/src/index.ts +119 -25
  91. package/src/logging.ts +8 -14
  92. package/src/oauth/OAuthService.ts +11 -3
  93. package/src/policyConfigFromJson.ts +131 -0
  94. package/src/runMcp.ts +30 -0
  95. package/src/server.ts +79 -26
  96. package/src/subtreeWrangler.ts +278 -0
  97. package/src/uiChannelPolicies.ts +15 -0
  98. package/krl/io.picolabs.did-o.krl +0 -349
@@ -1,6 +1,6 @@
1
1
  import * as cuid from "cuid";
2
2
  import fetch from "cross-fetch";
3
- import { PicoFramework } from "pico-framework";
3
+ import { Pico, PicoFramework } from "pico-framework";
4
4
  import { IdentityStore } from "./store";
5
5
  import { DidCommRoutes, PeerSubscriptionRecord } from "./types";
6
6
  import { IdentityError } from "./errors";
@@ -41,9 +41,32 @@ import {
41
41
  SKY_INTRO_RESPONSE,
42
42
  SKY_EVENT,
43
43
  SKY_QUERY,
44
+ SKY_ROTATE,
44
45
  parseSkyEventBody,
45
46
  parseSkyQueryBody,
46
47
  } from "./skyProtocol";
48
+ import {
49
+ handleSkyRotateAtIngress,
50
+ notifyPeersOfWebvhRotation,
51
+ } from "./skyRotation";
52
+ import {
53
+ relocateWebvhDid,
54
+ type RelocateWebvhOptions,
55
+ type RelocateWebvhResult,
56
+ } from "./webvhRelocation";
57
+ import { createSubtreePortableHooks } from "./identityPortable";
58
+ import {
59
+ exportPortableSubtree as exportPortableSubtreeImpl,
60
+ finalizePortableImport as finalizePortableImportImpl,
61
+ importPortableSubtree as importPortableSubtreeImpl,
62
+ type PortableMoveImportResult,
63
+ } from "./portableMove";
64
+ import {
65
+ summarizeSubtreeExportBlob,
66
+ type SubtreeImportResult,
67
+ } from "pico-engine-core";
68
+ import type { RulesetRegistry } from "pico-engine-core";
69
+ import type { SubtreePortableHooks } from "pico-engine-core";
47
70
  import {
48
71
  sendSkyIntro,
49
72
  sendSkyIntroResponse,
@@ -72,6 +95,7 @@ export interface DidCommPlainMessage {
72
95
  to?: string[];
73
96
  thid?: string;
74
97
  pthid?: string;
98
+ from_prior?: string;
75
99
  created_time: number;
76
100
  expires_time?: number;
77
101
  }
@@ -80,21 +104,135 @@ export interface IdentityServiceDeps {
80
104
  store: IdentityStore;
81
105
  getBaseUrl: () => string;
82
106
  pf: PicoFramework;
107
+ rsRegistry: RulesetRegistry;
108
+ resolveBundledRulesetUrl?: (url: string) => string;
109
+ reloadImportedSchedules?: (picoIds: string[]) => Promise<void>;
110
+ firePicoImported?: (
111
+ result: import("pico-engine-core").SubtreeImportResult
112
+ ) => Promise<void>;
83
113
  }
84
114
 
85
115
  /**
86
116
  * Engine identity primitive — store-backed DID state and DIDComm capabilities.
87
117
  * Crypto (pack/unpack) is delegated to Veramo when installed (Epic 2+).
88
118
  */
119
+ function isSelfOrDescendant(
120
+ pf: PicoFramework,
121
+ ancestorPicoId: string,
122
+ descendantPicoId: string
123
+ ): boolean {
124
+ if (ancestorPicoId === descendantPicoId) {
125
+ return true;
126
+ }
127
+ let current: Pico | undefined = pf.getPico(descendantPicoId);
128
+ while (current) {
129
+ if (current.id === ancestorPicoId) {
130
+ return true;
131
+ }
132
+ current = current.parent ? pf.getPico(current.parent) : undefined;
133
+ }
134
+ return false;
135
+ }
136
+
89
137
  export class IdentityService {
90
138
  private store: IdentityStore;
91
139
  private getBaseUrl: () => string;
92
140
  private pf: PicoFramework;
141
+ private rsRegistry: RulesetRegistry;
142
+ private resolveBundledRulesetUrl?: (url: string) => string;
143
+ private reloadImportedSchedules?: (picoIds: string[]) => Promise<void>;
144
+ private firePicoImported?: (
145
+ result: import("pico-engine-core").SubtreeImportResult
146
+ ) => Promise<void>;
93
147
 
94
148
  constructor(deps: IdentityServiceDeps) {
95
149
  this.store = deps.store;
96
150
  this.getBaseUrl = deps.getBaseUrl;
97
151
  this.pf = deps.pf;
152
+ this.rsRegistry = deps.rsRegistry;
153
+ this.resolveBundledRulesetUrl = deps.resolveBundledRulesetUrl;
154
+ this.reloadImportedSchedules = deps.reloadImportedSchedules;
155
+ this.firePicoImported = deps.firePicoImported;
156
+ }
157
+
158
+ /** Hooks wired into ctx:exportSubtree / importSubtree for identity snapshots. */
159
+ subtreePortableHooks(): SubtreePortableHooks {
160
+ return createSubtreePortableHooks(this.store, this.pf);
161
+ }
162
+
163
+ private portableMoveDeps() {
164
+ return {
165
+ store: this.store,
166
+ pf: this.pf,
167
+ rsRegistry: this.rsRegistry,
168
+ identity: this,
169
+ getBaseUrl: this.getBaseUrl,
170
+ resolveBundledRulesetUrl: this.resolveBundledRulesetUrl,
171
+ reloadImportedSchedules: this.reloadImportedSchedules,
172
+ firePicoImported: this.firePicoImported,
173
+ };
174
+ }
175
+
176
+ /**
177
+ * Export subtree + per-pico identity. Caller must be the subtree root or an ancestor.
178
+ */
179
+ async exportPortableSubtree(
180
+ fromPicoId: string,
181
+ subtreeRootPicoId: string,
182
+ secret: string,
183
+ options?: { recurse?: boolean; skipRelationshipUpgrade?: boolean }
184
+ ): Promise<string> {
185
+ if (!isSelfOrDescendant(this.pf, fromPicoId, subtreeRootPicoId)) {
186
+ throw new IdentityError(
187
+ `Pico ${fromPicoId} cannot export subtree rooted at ${subtreeRootPicoId}`,
188
+ 403
189
+ );
190
+ }
191
+ return exportPortableSubtreeImpl(
192
+ this.portableMoveDeps(),
193
+ subtreeRootPicoId,
194
+ secret,
195
+ options
196
+ );
197
+ }
198
+
199
+ /** Decrypt a portable subtree export blob and return a debug summary (no pico access). */
200
+ summarizePortableSubtreeExport(blob: string, secret: string) {
201
+ return summarizeSubtreeExportBlob(blob, secret);
202
+ }
203
+
204
+ /** Import portable subtree under parent; relocate webvh and notify peer subscriptions. */
205
+ async importPortableSubtree(
206
+ parentPicoId: string,
207
+ blob: string,
208
+ secret: string,
209
+ relocateOptions?: RelocateWebvhOptions,
210
+ importOptions?: import("pico-engine-core").SubtreeImportOptions
211
+ ): Promise<PortableMoveImportResult> {
212
+ const parent = this.pf.getPico(parentPicoId);
213
+ if (!parent) {
214
+ throw new IdentityError(`Parent pico not found: ${parentPicoId}`, 404);
215
+ }
216
+ return importPortableSubtreeImpl(
217
+ this.portableMoveDeps(),
218
+ parent,
219
+ blob,
220
+ secret,
221
+ relocateOptions,
222
+ importOptions
223
+ );
224
+ }
225
+
226
+ /** Relocate webvh and notify peers after ctx/importIntoExistingChild hydration. */
227
+ async finalizePortableImport(
228
+ importResult: SubtreeImportResult,
229
+ relocateOptions?: RelocateWebvhOptions
230
+ ): Promise<PortableMoveImportResult["relocation"]> {
231
+ return finalizePortableImportImpl(
232
+ this.portableMoveDeps(),
233
+ importResult,
234
+ relocateOptions
235
+ );
98
236
  }
99
237
 
100
238
  async ensureWebvhDid(
@@ -276,6 +414,52 @@ export class IdentityService {
276
414
  return (await this.store.getRoutes(picoId)) || {};
277
415
  }
278
416
 
417
+ /**
418
+ * Append a did:webvh log entry after move (SCID unchanged, host/path/endpoint may change).
419
+ */
420
+ async relocateWebvhAfterMove(
421
+ picoId: string,
422
+ options: RelocateWebvhOptions = {}
423
+ ): Promise<RelocateWebvhResult> {
424
+ return relocateWebvhDid(
425
+ this.store,
426
+ this.pf,
427
+ () => this.getBaseUrl(),
428
+ picoId,
429
+ options
430
+ );
431
+ }
432
+
433
+ /** Notify established peer subscriptions of a did:webvh relocation. */
434
+ async notifyPeersOfWebvhRotation(
435
+ picoId: string,
436
+ relocation: RelocateWebvhResult
437
+ ): Promise<number> {
438
+ return notifyPeersOfWebvhRotation(this.rotationDeps(), picoId, relocation);
439
+ }
440
+
441
+ /** Relocate did:webvh and notify all peer subscriptions (Phase D move). */
442
+ async completePortableMove(
443
+ picoId: string,
444
+ options: RelocateWebvhOptions = {}
445
+ ): Promise<RelocateWebvhResult & { peersNotified: number }> {
446
+ const relocation = await this.relocateWebvhAfterMove(picoId, options);
447
+ const peersNotified = await this.notifyPeersOfWebvhRotation(
448
+ picoId,
449
+ relocation
450
+ );
451
+ return { ...relocation, peersNotified };
452
+ }
453
+
454
+ private rotationDeps() {
455
+ return {
456
+ store: this.store,
457
+ pf: this.pf,
458
+ getBaseUrl: this.getBaseUrl,
459
+ identity: this,
460
+ };
461
+ }
462
+
279
463
  generateMessage(options: DidCommMessageOptions): DidCommPlainMessage {
280
464
  const message: DidCommPlainMessage = {
281
465
  id: cuid(),
@@ -432,6 +616,10 @@ export class IdentityService {
432
616
  );
433
617
  }
434
618
 
619
+ if (message.type === SKY_ROTATE) {
620
+ return handleSkyRotateAtIngress(this.rotationDeps(), picoId, message);
621
+ }
622
+
435
623
  // Channel policy (Epic 7): authenticated sender peer DID → subscription record →
436
624
  // internal Rx channel. Door verify proves crypto + subscription relationship;
437
625
  // pf.eventWait / pf.query enforce assertEventPolicy / assertQueryPolicy on rxEci.
@@ -47,13 +47,32 @@ function remoteTxHost(sub: PeerSubscriptionRecord, fallback: string): string {
47
47
  return host.replace(/\/$/, "");
48
48
  }
49
49
 
50
+ function normalizeBaseUrl(url: string): string {
51
+ return url.replace(/\/$/, "");
52
+ }
53
+
54
+ /** Peer lives on another engine when identity store says so (post-move rotate). */
55
+ function peerOnRemoteEngine(
56
+ sub: PeerSubscriptionRecord,
57
+ localBaseUrl: string
58
+ ): boolean {
59
+ if (!sub.remoteTxHost) {
60
+ return false;
61
+ }
62
+ return normalizeBaseUrl(sub.remoteTxHost) !== normalizeBaseUrl(localBaseUrl);
63
+ }
64
+
50
65
  export async function usesLocalDispatch(
51
66
  store: IdentityStore,
52
67
  pf: PicoFramework,
53
68
  fromPicoId: string,
54
69
  toPicoId: string,
55
- sub: PeerSubscriptionRecord
70
+ sub: PeerSubscriptionRecord,
71
+ localBaseUrl: string
56
72
  ): Promise<boolean> {
73
+ if (peerOnRemoteEngine(sub, localBaseUrl)) {
74
+ return false;
75
+ }
57
76
  const fromMesh = await store.getMeshRootId(fromPicoId);
58
77
  const toMesh = await store.getMeshRootId(toPicoId);
59
78
  if (!fromMesh || !toMesh || fromMesh !== toMesh) {
@@ -69,20 +88,22 @@ export async function resolveRecipientPicoId(
69
88
  store: IdentityStore,
70
89
  pf: PicoFramework,
71
90
  fromPicoId: string,
72
- subscriptionId: string
91
+ subscriptionId: string,
92
+ localBaseUrl: string
73
93
  ): Promise<string | undefined> {
74
94
  const sub = await store.getPeerSubscription(fromPicoId, subscriptionId);
75
95
  if (!sub) {
76
96
  return undefined;
77
97
  }
98
+ const remoteEngine = peerOnRemoteEngine(sub, localBaseUrl);
78
99
  const remotePeer = sub.remotePeerDid || sub.remoteDid;
79
- if (remotePeer) {
100
+ if (remotePeer && !remoteEngine) {
80
101
  const byPeer = await store.findPicoIdByLocalPeerDid(remotePeer);
81
102
  if (byPeer && pf.loadedPicos().some((p) => p.id === byPeer)) {
82
103
  return byPeer;
83
104
  }
84
105
  }
85
- if (sub.remoteWebvhDid) {
106
+ if (sub.remoteWebvhDid && !remoteEngine) {
86
107
  const byWebvh = await store.findPicoIdByWebvhDid(sub.remoteWebvhDid);
87
108
  if (byWebvh && pf.loadedPicos().some((p) => p.id === byWebvh)) {
88
109
  return byWebvh;
@@ -106,13 +127,27 @@ export async function crossPicoEvent(
106
127
  const callerDid = await deps.store.getWebvhDid(fromPicoId);
107
128
  const attrs = { ...(event.attrs || {}), callerDid: callerDid || undefined };
108
129
 
130
+ const localBase = deps.getBaseUrl();
109
131
  const to =
110
132
  toPicoId ||
111
- (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId));
133
+ (await resolveRecipientPicoId(
134
+ deps.store,
135
+ deps.pf,
136
+ fromPicoId,
137
+ subscriptionId,
138
+ localBase
139
+ ));
112
140
 
113
141
  if (
114
142
  to &&
115
- (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub))
143
+ (await usesLocalDispatch(
144
+ deps.store,
145
+ deps.pf,
146
+ fromPicoId,
147
+ to,
148
+ sub,
149
+ localBase
150
+ ))
116
151
  ) {
117
152
  const rxEci = await resolveRecipientRxEci(deps, to, subscriptionId);
118
153
  if (rxEci) {
@@ -159,13 +194,27 @@ export async function crossPicoQuery(
159
194
  throw new IdentityError(`Unknown subscription ${subscriptionId}`, 404);
160
195
  }
161
196
 
197
+ const localBase = deps.getBaseUrl();
162
198
  const to =
163
199
  toPicoId ||
164
- (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId));
200
+ (await resolveRecipientPicoId(
201
+ deps.store,
202
+ deps.pf,
203
+ fromPicoId,
204
+ subscriptionId,
205
+ localBase
206
+ ));
165
207
 
166
208
  if (
167
209
  to &&
168
- (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub))
210
+ (await usesLocalDispatch(
211
+ deps.store,
212
+ deps.pf,
213
+ fromPicoId,
214
+ to,
215
+ sub,
216
+ localBase
217
+ ))
169
218
  ) {
170
219
  const rxEci = await resolveRecipientRxEci(deps, to, subscriptionId);
171
220
  if (rxEci) {
@@ -1,6 +1,22 @@
1
+ /**
2
+ * Engine global KRL module `dido` — the ruleset-facing bridge to IdentityService.
3
+ *
4
+ * Wrangler and subscription call `dido:*` for Layer 2 identity: did:webvh lookup,
5
+ * SKY intro/response, cross-pico query/event, DIDComm pack/unpack/route, and
6
+ * portable-move helpers. State lives in the engine identity store, not in KRL ent.
7
+ *
8
+ * Not the retired `io.picolabs.did-o` ruleset (removed in 1.7). Do not rename this
9
+ * module; it is internal OS plumbing wired at engine start via core.modules["dido"].
10
+ */
11
+
1
12
  import { krl } from "krl-stdlib";
2
13
  import { IdentityService } from "./IdentityService";
3
14
  import { IdentityError } from "./errors";
15
+ import type {
16
+ SubtreeImportOptions,
17
+ SubtreeImportResult,
18
+ } from "pico-engine-core";
19
+ import type { RelocateWebvhOptions } from "./webvhRelocation";
4
20
 
5
21
  const QUERY_TIMEOUT = 10000;
6
22
 
@@ -103,8 +119,6 @@ export default function initDidoModule(identity: IdentityService) {
103
119
  return undefined;
104
120
  }),
105
121
 
106
- prepareQuery: deprecated("prepareQuery"),
107
-
108
122
  sendQuery: krl.Function(["did", "message"], async function (
109
123
  did: string,
110
124
  message: any
@@ -332,32 +346,135 @@ export default function initDidoModule(identity: IdentityService) {
332
346
  });
333
347
  }),
334
348
 
335
- // Legacy did-o / did:peer:2 surface — removed in Layer 2 reboot.
336
- generateDID: deprecated("generateDID"),
337
- deleteDID: deprecated("deleteDID"),
338
- updateDID: deprecated("updateDID"),
339
- rotateDID: deprecated("rotateDID"),
340
- rotateInviteDID: deprecated("rotateInviteDID"),
341
- clearPendingRotations: deprecated("clearPendingRotations"),
342
- mapDid: deprecated("mapDid"),
343
- clearDidMap: deprecated("clearDidMap"),
344
- clearDidDocs: deprecated("clearDidDocs"),
345
- storeDidDoc: deprecated("storeDidDoc"),
346
- addLabelsToChannel: deprecated("addLabelsToChannel"),
349
+ relocateWebvhAfterMove: krl.Function(["options"], async function (
350
+ options: Record<string, unknown> = {}
351
+ ) {
352
+ const opts: {
353
+ baseUrl?: string;
354
+ renewIngress?: boolean;
355
+ } = {};
356
+ if (typeof options.baseUrl === "string") {
357
+ opts.baseUrl = options.baseUrl;
358
+ }
359
+ if (options.renewIngress === true) {
360
+ opts.renewIngress = true;
361
+ }
362
+ return identity.relocateWebvhAfterMove(this.rsCtx.pico().id, opts);
363
+ }),
364
+
365
+ notifyPeersOfWebvhRotation: krl.Function(["relocation"], async function (
366
+ relocation: Record<string, unknown>
367
+ ) {
368
+ return identity.notifyPeersOfWebvhRotation(
369
+ this.rsCtx.pico().id,
370
+ relocation as unknown as Parameters<
371
+ IdentityService["notifyPeersOfWebvhRotation"]
372
+ >[1]
373
+ );
374
+ }),
375
+
376
+ completePortableMove: krl.Function(["options"], async function (
377
+ options: Record<string, unknown> = {}
378
+ ) {
379
+ const opts: {
380
+ baseUrl?: string;
381
+ renewIngress?: boolean;
382
+ } = {};
383
+ if (typeof options.baseUrl === "string") {
384
+ opts.baseUrl = options.baseUrl;
385
+ }
386
+ if (options.renewIngress === true) {
387
+ opts.renewIngress = true;
388
+ }
389
+ return identity.completePortableMove(this.rsCtx.pico().id, opts);
390
+ }),
391
+
392
+ exportPortableSubtree: krl.Function(
393
+ ["subtreeRootPicoId", "secret"],
394
+ async function (subtreeRootPicoId: string, secret: string) {
395
+ return identity.exportPortableSubtree(
396
+ this.rsCtx.pico().id,
397
+ subtreeRootPicoId,
398
+ secret
399
+ );
400
+ }
401
+ ),
402
+
403
+ summarizePortableSubtreeExport: krl.Function(
404
+ ["blob", "secret"],
405
+ function (blob: string, secret: string) {
406
+ return identity.summarizePortableSubtreeExport(blob, secret);
407
+ }
408
+ ),
409
+
410
+ importPortableSubtree: krl.Function(
411
+ ["blob", "secret", "options"],
412
+ async function (
413
+ blob: string,
414
+ secret: string,
415
+ options: Record<string, unknown> = {}
416
+ ) {
417
+ const opts: RelocateWebvhOptions = {};
418
+ if (typeof options.baseUrl === "string") {
419
+ opts.baseUrl = options.baseUrl;
420
+ }
421
+ if (options.renewIngress === true) {
422
+ opts.renewIngress = true;
423
+ }
424
+ if (Object.keys(opts).length === 0) {
425
+ opts.renewIngress = true;
426
+ }
427
+ const importOpts: SubtreeImportOptions = {};
428
+ if (typeof options.parentChannelEci === "string") {
429
+ importOpts.parentChannelEci = options.parentChannelEci;
430
+ }
431
+ if (typeof options.bootstrapDisplayName === "string") {
432
+ let name = options.bootstrapDisplayName.trim();
433
+ if (
434
+ name.length >= 2 &&
435
+ name.startsWith('"') &&
436
+ name.endsWith('"')
437
+ ) {
438
+ name = name.slice(1, -1).trim();
439
+ }
440
+ if (name.length > 0) {
441
+ importOpts.bootstrapDisplayName = name;
442
+ }
443
+ }
444
+ return identity.importPortableSubtree(
445
+ this.rsCtx.pico().id,
446
+ blob,
447
+ secret,
448
+ opts,
449
+ importOpts
450
+ );
451
+ }
452
+ ),
453
+
454
+ finalizePortableImport: krl.Function(
455
+ ["importResult", "options"],
456
+ async function (
457
+ importResult: SubtreeImportResult,
458
+ options: Record<string, unknown> = {}
459
+ ) {
460
+ const opts: RelocateWebvhOptions = {};
461
+ if (typeof options.baseUrl === "string") {
462
+ opts.baseUrl = options.baseUrl;
463
+ }
464
+ if (options.renewIngress === true) {
465
+ opts.renewIngress = true;
466
+ }
467
+ if (Object.keys(opts).length === 0) {
468
+ opts.renewIngress = true;
469
+ }
470
+ return identity.finalizePortableImport(importResult, opts);
471
+ }
472
+ ),
347
473
  };
348
474
 
349
475
  return module;
350
476
  }
351
477
 
352
- function deprecated(name: string) {
353
- return krl.Function([], async function () {
354
- throw new IdentityError(
355
- `dido:${name} removed in Layer 2 reboot — use engine identity primitives`,
356
- 410
357
- );
358
- });
359
- }
360
-
361
478
  function extractDidcommEndpoint(doc: Record<string, unknown>): string {
362
479
  const services = doc.service as Array<Record<string, unknown>> | undefined;
363
480
  if (!services || services.length === 0) {
@@ -104,7 +104,7 @@ export async function establishSubscriptionIdentity(
104
104
  }
105
105
 
106
106
  export interface LinkRemotePeerInput {
107
- remotePeerDid: string;
107
+ remotePeerDid?: string;
108
108
  remoteWebvhDid?: string;
109
109
  remoteMeshRootId?: string;
110
110
  remoteTxHost?: string;
@@ -123,7 +123,7 @@ export async function linkRemotePeer(
123
123
  }
124
124
  const updated: PeerSubscriptionRecord = {
125
125
  ...sub,
126
- remotePeerDid: input.remotePeerDid,
126
+ remotePeerDid: input.remotePeerDid ?? sub.remotePeerDid,
127
127
  remoteWebvhDid: input.remoteWebvhDid ?? sub.remoteWebvhDid,
128
128
  remoteMeshRootId: input.remoteMeshRootId ?? sub.remoteMeshRootId,
129
129
  remoteTxHost: input.remoteTxHost ?? sub.remoteTxHost,