pico-engine 1.6.4 → 1.9.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 (108) hide show
  1. package/README.md +16 -9
  2. package/dist/RulesetRegistryLoaderFs.js +60 -6
  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 +106 -69
  7. package/dist/engineConfig.js +291 -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 +84 -27
  28. package/dist/logging.js +156 -16
  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 +261 -24
  33. package/dist/stageKrl.js +26 -0
  34. package/dist/subtreeWrangler.js +180 -0
  35. package/dist/uiChannelPolicies.js +15 -0
  36. package/dist/xmluiRuntime.js +68 -0
  37. package/krl/io.picolabs.oauth.krl +41 -2
  38. package/krl/io.picolabs.pds.krl +131 -10
  39. package/krl/io.picolabs.pico-engine-ui.krl +217 -94
  40. package/krl/io.picolabs.portable_subtree.krl +97 -0
  41. package/krl/io.picolabs.subscription.krl +180 -72
  42. package/krl/io.picolabs.wrangler.krl +313 -57
  43. package/krl/io.picolabs.xmlui.krl +295 -0
  44. package/mcp/devResources.js +118 -0
  45. package/mcp/devTools.js +351 -0
  46. package/mcp/engineClient.js +133 -0
  47. package/mcp/meshHttp.js +137 -0
  48. package/mcp/meshTools.js +189 -0
  49. package/mcp/runStdio.js +34 -0
  50. package/mcp/schemaToZod.js +56 -0
  51. package/package.json +24 -9
  52. package/public/.DS_Store +0 -0
  53. package/public/docs/_sidebar.md +3 -1
  54. package/public/docs/llms-full.txt +630 -0
  55. package/public/docs/llms.txt +38 -0
  56. package/public/docs/openapi.yaml +78 -0
  57. package/public/docs/pico-engine.md +239 -4
  58. package/public/docs/pico-overview.md +117 -0
  59. package/public/docs/pico-views-xmlui.md +5 -0
  60. package/public/docs/pico-views.md +140 -0
  61. package/public/docs/pico.md +3 -1
  62. package/public/docs/rulesets/README.md +26 -0
  63. package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
  64. package/public/docs/rulesets/io.picolabs.pds.md +327 -0
  65. package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
  66. package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
  67. package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
  68. package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
  69. package/public/pico-engine-ui.css +1 -1
  70. package/public/pico-engine-ui.js +27 -23
  71. package/public/xmlui/0.12.7.js +419 -0
  72. package/public/xmlui/pico-view-boot.js +153 -0
  73. package/src/RulesetRegistryLoaderFs.ts +66 -7
  74. package/src/auth/cookies.ts +34 -0
  75. package/src/auth/index.ts +7 -0
  76. package/src/channelIdentityPolicy.ts +29 -0
  77. package/src/cli.ts +70 -37
  78. package/src/engineConfig.ts +363 -0
  79. package/src/identity/IdentityService.ts +189 -1
  80. package/src/identity/crossPico.ts +57 -8
  81. package/src/identity/didoModule.ts +140 -23
  82. package/src/identity/establishSubscription.ts +2 -2
  83. package/src/identity/identityPortable.ts +153 -0
  84. package/src/identity/index.ts +14 -0
  85. package/src/identity/localPeerReconcile.ts +97 -0
  86. package/src/identity/peerDid4.ts +197 -0
  87. package/src/identity/peerDid4Create.ts +121 -0
  88. package/src/identity/portableExportPrepare.ts +302 -0
  89. package/src/identity/portableMove.ts +193 -0
  90. package/src/identity/skyIntro.ts +11 -11
  91. package/src/identity/skyProtocol.ts +46 -0
  92. package/src/identity/skyRotation.ts +211 -0
  93. package/src/identity/store.ts +5 -1
  94. package/src/identity/subscriptionEntSync.ts +97 -0
  95. package/src/identity/veramoDidComm.ts +52 -2
  96. package/src/identity/webvh.ts +4 -4
  97. package/src/identity/webvhRelocation.ts +167 -0
  98. package/src/index.ts +123 -31
  99. package/src/logging.ts +173 -18
  100. package/src/oauth/OAuthService.ts +11 -3
  101. package/src/policyConfigFromJson.ts +131 -0
  102. package/src/runMcp.ts +30 -0
  103. package/src/server.ts +328 -27
  104. package/src/stageKrl.ts +26 -0
  105. package/src/subtreeWrangler.ts +278 -0
  106. package/src/uiChannelPolicies.ts +15 -0
  107. package/src/xmluiRuntime.ts +66 -0
  108. package/krl/io.picolabs.did-o.krl +0 -349
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installEngineRuntimeSettings = installEngineRuntimeSettings;
4
+ exports.getEngineRuntimeSettings = getEngineRuntimeSettings;
5
+ exports.defaultEngineSettings = defaultEngineSettings;
6
+ exports.defaultEngineConfigFilePath = defaultEngineConfigFilePath;
7
+ exports.resolveEngineConfigFilePath = resolveEngineConfigFilePath;
8
+ exports.applyConfigCliArgs = applyConfigCliArgs;
9
+ exports.loadConfigFileSettings = loadConfigFileSettings;
10
+ exports.settingsFromEnv = settingsFromEnv;
11
+ exports.resolveEngineSettings = resolveEngineSettings;
12
+ const fs = require("fs");
13
+ const os = require("os");
14
+ const path = require("path");
15
+ const policyConfigFromJson_1 = require("./policyConfigFromJson");
16
+ const homeDir = require("home-dir");
17
+ let runtimeSettings = null;
18
+ function installEngineRuntimeSettings(settings) {
19
+ runtimeSettings = settings;
20
+ }
21
+ function getEngineRuntimeSettings() {
22
+ if (!runtimeSettings) {
23
+ runtimeSettings = defaultEngineSettings();
24
+ }
25
+ return runtimeSettings;
26
+ }
27
+ function defaultEngineSettings() {
28
+ return {
29
+ home: homeDir(".pico-engine"),
30
+ port: 3000,
31
+ baseUrl: "http://localhost:3000",
32
+ allowSelfSignup: false,
33
+ allowLocalhostChannelBypass: true,
34
+ wildcardSkyRequireBearer: false,
35
+ logToStdout: false,
36
+ logMirror: true,
37
+ };
38
+ }
39
+ function defaultEngineConfigFilePath() {
40
+ const xdg = process.env.XDG_CONFIG_HOME &&
41
+ process.env.XDG_CONFIG_HOME.trim().length > 0
42
+ ? process.env.XDG_CONFIG_HOME
43
+ : path.join(os.homedir(), ".config");
44
+ return path.join(xdg, "pico-engine", "config.json");
45
+ }
46
+ function resolveEngineConfigFilePath() {
47
+ const explicit = process.env.PICO_ENGINE_CONFIG;
48
+ if (typeof explicit === "string" && explicit.trim().length > 0) {
49
+ return path.resolve(expandHome(explicit.trim()));
50
+ }
51
+ return defaultEngineConfigFilePath();
52
+ }
53
+ /**
54
+ * Parse `--config` / `-c` from argv and set `PICO_ENGINE_CONFIG` before settings resolve.
55
+ * Use one config file per engine process (host or container).
56
+ */
57
+ function applyConfigCliArgs(argv) {
58
+ const out = [];
59
+ for (let i = 0; i < argv.length; i++) {
60
+ const arg = argv[i];
61
+ if (arg === "--config" || arg === "-c") {
62
+ const val = argv[++i];
63
+ if (typeof val !== "string" || val.length === 0) {
64
+ throw new Error(`${arg} requires a config file path`);
65
+ }
66
+ process.env.PICO_ENGINE_CONFIG = path.resolve(expandHome(val));
67
+ continue;
68
+ }
69
+ if (arg.startsWith("--config=")) {
70
+ const val = arg.slice("--config=".length);
71
+ if (val.length === 0) {
72
+ throw new Error("--config= requires a config file path");
73
+ }
74
+ process.env.PICO_ENGINE_CONFIG = path.resolve(expandHome(val));
75
+ continue;
76
+ }
77
+ out.push(arg);
78
+ }
79
+ return out;
80
+ }
81
+ function expandHome(p) {
82
+ if (p.startsWith("~/")) {
83
+ return path.join(os.homedir(), p.slice(2));
84
+ }
85
+ return p;
86
+ }
87
+ function parseConfigFile(raw) {
88
+ let data;
89
+ try {
90
+ data = JSON.parse(raw);
91
+ }
92
+ catch (err) {
93
+ throw new Error(`Invalid engine config JSON (${resolveEngineConfigFilePath()}): ${err}`);
94
+ }
95
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
96
+ throw new Error("Engine config must be a JSON object");
97
+ }
98
+ const o = data;
99
+ const out = {};
100
+ if (typeof o.home === "string" && o.home.length > 0) {
101
+ out.home = expandHome(o.home);
102
+ }
103
+ if (typeof o.port === "number" && o.port >= 0) {
104
+ out.port = o.port;
105
+ }
106
+ if (typeof o.baseUrl === "string" && o.baseUrl.length > 0) {
107
+ out.baseUrl = o.baseUrl;
108
+ }
109
+ const webauthn = o.webauthn && typeof o.webauthn === "object" && !Array.isArray(o.webauthn)
110
+ ? o.webauthn
111
+ : null;
112
+ if (webauthn) {
113
+ if (typeof webauthn.rpId === "string")
114
+ out.rpID = webauthn.rpId;
115
+ if (typeof webauthn.rpName === "string")
116
+ out.rpName = webauthn.rpName;
117
+ if (typeof webauthn.origin === "string")
118
+ out.origin = webauthn.origin;
119
+ }
120
+ if (typeof o.rpID === "string")
121
+ out.rpID = o.rpID;
122
+ if (typeof o.rpName === "string")
123
+ out.rpName = o.rpName;
124
+ if (typeof o.origin === "string")
125
+ out.origin = o.origin;
126
+ if (typeof o.allowSelfSignup === "boolean") {
127
+ out.allowSelfSignup = o.allowSelfSignup;
128
+ }
129
+ if (typeof o.allowLocalhostChannelBypass === "boolean") {
130
+ out.allowLocalhostChannelBypass = o.allowLocalhostChannelBypass;
131
+ }
132
+ if (typeof o.wildcardSkyRequireBearer === "boolean") {
133
+ out.wildcardSkyRequireBearer = o.wildcardSkyRequireBearer;
134
+ }
135
+ if (typeof o.logToStdout === "boolean") {
136
+ out.logToStdout = o.logToStdout;
137
+ }
138
+ if (typeof o.logMirror === "boolean") {
139
+ out.logMirror = o.logMirror;
140
+ }
141
+ if (typeof o.logFile === "string" && o.logFile.length > 0) {
142
+ if (o.logFile === "stdout" || o.logFile === "-") {
143
+ out.logToStdout = true;
144
+ }
145
+ else {
146
+ out.logFile = path.resolve(expandHome(o.logFile));
147
+ }
148
+ }
149
+ const rootCeiling = (0, policyConfigFromJson_1.parsePolicyCeilingFromJson)(o.defaultRootPolicyCeiling, "defaultRootPolicyCeiling");
150
+ if (rootCeiling) {
151
+ out.defaultRootPolicyCeiling = rootCeiling;
152
+ }
153
+ const globalEventDeny = (0, policyConfigFromJson_1.parseGlobalEventDenyFromJson)(o.globalEventDeny);
154
+ if (globalEventDeny) {
155
+ out.globalEventDeny = globalEventDeny;
156
+ }
157
+ const globalQueryDeny = (0, policyConfigFromJson_1.parseGlobalQueryDenyFromJson)(o.globalQueryDeny);
158
+ if (globalQueryDeny) {
159
+ out.globalQueryDeny = globalQueryDeny;
160
+ }
161
+ return out;
162
+ }
163
+ function loadConfigFileSettings() {
164
+ if (process.env.NODE_ENV === "test" && !process.env.PICO_ENGINE_CONFIG) {
165
+ return {};
166
+ }
167
+ const filePath = resolveEngineConfigFilePath();
168
+ if (!fs.existsSync(filePath)) {
169
+ return {};
170
+ }
171
+ const raw = fs.readFileSync(filePath, "utf8");
172
+ return parseConfigFile(raw);
173
+ }
174
+ function parseBoolEnv(val) {
175
+ if (val === undefined)
176
+ return undefined;
177
+ if (val === "true" || val === "1")
178
+ return true;
179
+ if (val === "false" || val === "0")
180
+ return false;
181
+ return undefined;
182
+ }
183
+ function settingsFromEnv() {
184
+ const out = {};
185
+ if (process.env.PORT) {
186
+ const port = parseInt(process.env.PORT, 10);
187
+ if (port >= 0)
188
+ out.port = port;
189
+ }
190
+ if (typeof process.env.PICO_ENGINE_HOME === "string" &&
191
+ process.env.PICO_ENGINE_HOME.length > 0) {
192
+ out.home = expandHome(process.env.PICO_ENGINE_HOME);
193
+ }
194
+ if (typeof process.env.PICO_ENGINE_BASE_URL === "string" &&
195
+ process.env.PICO_ENGINE_BASE_URL.length > 0) {
196
+ out.baseUrl = process.env.PICO_ENGINE_BASE_URL;
197
+ }
198
+ if (typeof process.env.PICO_ENGINE_RP_ID === "string" &&
199
+ process.env.PICO_ENGINE_RP_ID.length > 0) {
200
+ out.rpID = process.env.PICO_ENGINE_RP_ID;
201
+ }
202
+ if (typeof process.env.PICO_ENGINE_ORIGIN === "string" &&
203
+ process.env.PICO_ENGINE_ORIGIN.length > 0) {
204
+ out.origin = process.env.PICO_ENGINE_ORIGIN;
205
+ }
206
+ const signup = parseBoolEnv(process.env.PICO_ENGINE_ALLOW_SELF_SIGNUP);
207
+ if (signup !== undefined)
208
+ out.allowSelfSignup = signup;
209
+ const localhostC = parseBoolEnv(process.env.PICO_ENGINE_ALLOW_LOCALHOST_C);
210
+ if (localhostC !== undefined) {
211
+ out.allowLocalhostChannelBypass = localhostC;
212
+ }
213
+ else if (process.env.PICO_ENGINE_ALLOW_LOCALHOST_C === "0") {
214
+ out.allowLocalhostChannelBypass = false;
215
+ }
216
+ const wildcard = parseBoolEnv(process.env.PICO_ENGINE_WILDCARD_SKY_REQUIRE_BEARER);
217
+ if (wildcard !== undefined)
218
+ out.wildcardSkyRequireBearer = wildcard;
219
+ const logFile = process.env.PICO_ENGINE_LOG_FILE;
220
+ if (logFile === "0" || logFile === "-" || logFile === "stdout" || logFile === "") {
221
+ out.logToStdout = true;
222
+ }
223
+ else if (typeof logFile === "string" && logFile.length > 0) {
224
+ out.logFile = path.resolve(expandHome(logFile));
225
+ }
226
+ const logMirror = parseBoolEnv(process.env.PICO_ENGINE_LOG_MIRROR);
227
+ if (logMirror !== undefined) {
228
+ out.logMirror = logMirror;
229
+ }
230
+ return out;
231
+ }
232
+ function mergeSettings(base, ...layers) {
233
+ const merged = Object.assign({}, base);
234
+ for (const layer of layers) {
235
+ Object.assign(merged, layer);
236
+ }
237
+ return merged;
238
+ }
239
+ /**
240
+ * Resolve settings: defaults ← environment ← config file ← programmatic (tests, API).
241
+ * `PORT` and `PICO_ENGINE_HOME` (and other env keys) apply when the file omits them;
242
+ * values in the config file win when both are set.
243
+ */
244
+ function resolveEngineSettings(programmatic = {}) {
245
+ var _a;
246
+ const fromProgrammatic = {};
247
+ if (programmatic.home)
248
+ fromProgrammatic.home = programmatic.home;
249
+ if (programmatic.port != null)
250
+ fromProgrammatic.port = programmatic.port;
251
+ const baseUrl = (_a = programmatic.baseUrl) !== null && _a !== void 0 ? _a : programmatic.base_url;
252
+ if (baseUrl)
253
+ fromProgrammatic.baseUrl = baseUrl;
254
+ if (programmatic.rpID)
255
+ fromProgrammatic.rpID = programmatic.rpID;
256
+ if (programmatic.rpName)
257
+ fromProgrammatic.rpName = programmatic.rpName;
258
+ if (programmatic.origin)
259
+ fromProgrammatic.origin = programmatic.origin;
260
+ if (programmatic.allowSelfSignup !== undefined) {
261
+ fromProgrammatic.allowSelfSignup = programmatic.allowSelfSignup;
262
+ }
263
+ if (programmatic.allowLocalhostChannelBypass !== undefined) {
264
+ fromProgrammatic.allowLocalhostChannelBypass =
265
+ programmatic.allowLocalhostChannelBypass;
266
+ }
267
+ if (programmatic.wildcardSkyRequireBearer !== undefined) {
268
+ fromProgrammatic.wildcardSkyRequireBearer =
269
+ programmatic.wildcardSkyRequireBearer;
270
+ }
271
+ if (programmatic.logToStdout !== undefined) {
272
+ fromProgrammatic.logToStdout = programmatic.logToStdout;
273
+ }
274
+ if (programmatic.logFile !== undefined) {
275
+ fromProgrammatic.logFile = programmatic.logFile;
276
+ }
277
+ if (programmatic.logMirror !== undefined) {
278
+ fromProgrammatic.logMirror = programmatic.logMirror;
279
+ }
280
+ if (programmatic.defaultRootPolicyCeiling !== undefined) {
281
+ fromProgrammatic.defaultRootPolicyCeiling =
282
+ programmatic.defaultRootPolicyCeiling;
283
+ }
284
+ if (programmatic.globalEventDeny !== undefined) {
285
+ fromProgrammatic.globalEventDeny = programmatic.globalEventDeny;
286
+ }
287
+ if (programmatic.globalQueryDeny !== undefined) {
288
+ fromProgrammatic.globalQueryDeny = programmatic.globalQueryDeny;
289
+ }
290
+ return mergeSettings(defaultEngineSettings(), settingsFromEnv(), loadConfigFileSettings(), fromProgrammatic);
291
+ }
@@ -9,16 +9,79 @@ const veramoDidComm_1 = require("./veramoDidComm");
9
9
  const establishSubscription_1 = require("./establishSubscription");
10
10
  const crossPico_1 = require("./crossPico");
11
11
  const skyProtocol_1 = require("./skyProtocol");
12
+ const skyRotation_1 = require("./skyRotation");
13
+ const webvhRelocation_1 = require("./webvhRelocation");
14
+ const identityPortable_1 = require("./identityPortable");
15
+ const portableMove_1 = require("./portableMove");
16
+ const pico_engine_core_1 = require("pico-engine-core");
12
17
  const skyIntro_1 = require("./skyIntro");
13
18
  /**
14
19
  * Engine identity primitive — store-backed DID state and DIDComm capabilities.
15
20
  * Crypto (pack/unpack) is delegated to Veramo when installed (Epic 2+).
16
21
  */
22
+ function isSelfOrDescendant(pf, ancestorPicoId, descendantPicoId) {
23
+ if (ancestorPicoId === descendantPicoId) {
24
+ return true;
25
+ }
26
+ let current = pf.getPico(descendantPicoId);
27
+ while (current) {
28
+ if (current.id === ancestorPicoId) {
29
+ return true;
30
+ }
31
+ current = current.parent ? pf.getPico(current.parent) : undefined;
32
+ }
33
+ return false;
34
+ }
17
35
  class IdentityService {
18
36
  constructor(deps) {
19
37
  this.store = deps.store;
20
38
  this.getBaseUrl = deps.getBaseUrl;
21
39
  this.pf = deps.pf;
40
+ this.rsRegistry = deps.rsRegistry;
41
+ this.resolveBundledRulesetUrl = deps.resolveBundledRulesetUrl;
42
+ this.reloadImportedSchedules = deps.reloadImportedSchedules;
43
+ this.firePicoImported = deps.firePicoImported;
44
+ }
45
+ /** Hooks wired into ctx:exportSubtree / importSubtree for identity snapshots. */
46
+ subtreePortableHooks() {
47
+ return (0, identityPortable_1.createSubtreePortableHooks)(this.store, this.pf);
48
+ }
49
+ portableMoveDeps() {
50
+ return {
51
+ store: this.store,
52
+ pf: this.pf,
53
+ rsRegistry: this.rsRegistry,
54
+ identity: this,
55
+ getBaseUrl: this.getBaseUrl,
56
+ resolveBundledRulesetUrl: this.resolveBundledRulesetUrl,
57
+ reloadImportedSchedules: this.reloadImportedSchedules,
58
+ firePicoImported: this.firePicoImported,
59
+ };
60
+ }
61
+ /**
62
+ * Export subtree + per-pico identity. Caller must be the subtree root or an ancestor.
63
+ */
64
+ async exportPortableSubtree(fromPicoId, subtreeRootPicoId, secret, options) {
65
+ if (!isSelfOrDescendant(this.pf, fromPicoId, subtreeRootPicoId)) {
66
+ throw new errors_1.IdentityError(`Pico ${fromPicoId} cannot export subtree rooted at ${subtreeRootPicoId}`, 403);
67
+ }
68
+ return (0, portableMove_1.exportPortableSubtree)(this.portableMoveDeps(), subtreeRootPicoId, secret, options);
69
+ }
70
+ /** Decrypt a portable subtree export blob and return a debug summary (no pico access). */
71
+ summarizePortableSubtreeExport(blob, secret) {
72
+ return (0, pico_engine_core_1.summarizeSubtreeExportBlob)(blob, secret);
73
+ }
74
+ /** Import portable subtree under parent; relocate webvh and notify peer subscriptions. */
75
+ async importPortableSubtree(parentPicoId, blob, secret, relocateOptions, importOptions) {
76
+ const parent = this.pf.getPico(parentPicoId);
77
+ if (!parent) {
78
+ throw new errors_1.IdentityError(`Parent pico not found: ${parentPicoId}`, 404);
79
+ }
80
+ return (0, portableMove_1.importPortableSubtree)(this.portableMoveDeps(), parent, blob, secret, relocateOptions, importOptions);
81
+ }
82
+ /** Relocate webvh and notify peers after ctx/importIntoExistingChild hydration. */
83
+ async finalizePortableImport(importResult, relocateOptions) {
84
+ return (0, portableMove_1.finalizePortableImport)(this.portableMoveDeps(), importResult, relocateOptions);
22
85
  }
23
86
  async ensureWebvhDid(picoId, options = {}) {
24
87
  return (0, webvh_1.ensureWebvhDid)(this.store, this.pf, () => this.getBaseUrl(), picoId, options);
@@ -133,6 +196,30 @@ class IdentityService {
133
196
  async getRoutes(picoId) {
134
197
  return (await this.store.getRoutes(picoId)) || {};
135
198
  }
199
+ /**
200
+ * Append a did:webvh log entry after move (SCID unchanged, host/path/endpoint may change).
201
+ */
202
+ async relocateWebvhAfterMove(picoId, options = {}) {
203
+ return (0, webvhRelocation_1.relocateWebvhDid)(this.store, this.pf, () => this.getBaseUrl(), picoId, options);
204
+ }
205
+ /** Notify established peer subscriptions of a did:webvh relocation. */
206
+ async notifyPeersOfWebvhRotation(picoId, relocation) {
207
+ return (0, skyRotation_1.notifyPeersOfWebvhRotation)(this.rotationDeps(), picoId, relocation);
208
+ }
209
+ /** Relocate did:webvh and notify all peer subscriptions (Phase D move). */
210
+ async completePortableMove(picoId, options = {}) {
211
+ const relocation = await this.relocateWebvhAfterMove(picoId, options);
212
+ const peersNotified = await this.notifyPeersOfWebvhRotation(picoId, relocation);
213
+ return Object.assign(Object.assign({}, relocation), { peersNotified });
214
+ }
215
+ rotationDeps() {
216
+ return {
217
+ store: this.store,
218
+ pf: this.pf,
219
+ getBaseUrl: this.getBaseUrl,
220
+ identity: this,
221
+ };
222
+ }
136
223
  generateMessage(options) {
137
224
  const message = {
138
225
  id: cuid(),
@@ -219,6 +306,9 @@ class IdentityService {
219
306
  if (message.type === skyProtocol_1.SKY_INTRO_RESPONSE) {
220
307
  return (0, skyIntro_1.handleSkyIntroResponseAtIngress)(this.skyIntroDeps(), picoId, message);
221
308
  }
309
+ if (message.type === skyProtocol_1.SKY_ROTATE) {
310
+ return (0, skyRotation_1.handleSkyRotateAtIngress)(this.rotationDeps(), picoId, message);
311
+ }
222
312
  // Channel policy (Epic 7): authenticated sender peer DID → subscription record →
223
313
  // internal Rx channel. Door verify proves crypto + subscription relationship;
224
314
  // pf.eventWait / pf.query enforce assertEventPolicy / assertQueryPolicy on rxEci.
@@ -23,7 +23,20 @@ function remoteTxHost(sub, fallback) {
23
23
  const host = sub.remoteTxHost || fallback;
24
24
  return host.replace(/\/$/, "");
25
25
  }
26
- async function usesLocalDispatch(store, pf, fromPicoId, toPicoId, sub) {
26
+ function normalizeBaseUrl(url) {
27
+ return url.replace(/\/$/, "");
28
+ }
29
+ /** Peer lives on another engine when identity store says so (post-move rotate). */
30
+ function peerOnRemoteEngine(sub, localBaseUrl) {
31
+ if (!sub.remoteTxHost) {
32
+ return false;
33
+ }
34
+ return normalizeBaseUrl(sub.remoteTxHost) !== normalizeBaseUrl(localBaseUrl);
35
+ }
36
+ async function usesLocalDispatch(store, pf, fromPicoId, toPicoId, sub, localBaseUrl) {
37
+ if (peerOnRemoteEngine(sub, localBaseUrl)) {
38
+ return false;
39
+ }
27
40
  const fromMesh = await store.getMeshRootId(fromPicoId);
28
41
  const toMesh = await store.getMeshRootId(toPicoId);
29
42
  if (!fromMesh || !toMesh || fromMesh !== toMesh) {
@@ -34,19 +47,20 @@ async function usesLocalDispatch(store, pf, fromPicoId, toPicoId, sub) {
34
47
  }
35
48
  return pf.loadedPicos().some((p) => p.id === toPicoId);
36
49
  }
37
- async function resolveRecipientPicoId(store, pf, fromPicoId, subscriptionId) {
50
+ async function resolveRecipientPicoId(store, pf, fromPicoId, subscriptionId, localBaseUrl) {
38
51
  const sub = await store.getPeerSubscription(fromPicoId, subscriptionId);
39
52
  if (!sub) {
40
53
  return undefined;
41
54
  }
55
+ const remoteEngine = peerOnRemoteEngine(sub, localBaseUrl);
42
56
  const remotePeer = sub.remotePeerDid || sub.remoteDid;
43
- if (remotePeer) {
57
+ if (remotePeer && !remoteEngine) {
44
58
  const byPeer = await store.findPicoIdByLocalPeerDid(remotePeer);
45
59
  if (byPeer && pf.loadedPicos().some((p) => p.id === byPeer)) {
46
60
  return byPeer;
47
61
  }
48
62
  }
49
- if (sub.remoteWebvhDid) {
63
+ if (sub.remoteWebvhDid && !remoteEngine) {
50
64
  const byWebvh = await store.findPicoIdByWebvhDid(sub.remoteWebvhDid);
51
65
  if (byWebvh && pf.loadedPicos().some((p) => p.id === byWebvh)) {
52
66
  return byWebvh;
@@ -61,10 +75,11 @@ async function crossPicoEvent(deps, fromPicoId, toPicoId, subscriptionId, event)
61
75
  }
62
76
  const callerDid = await deps.store.getWebvhDid(fromPicoId);
63
77
  const attrs = Object.assign(Object.assign({}, (event.attrs || {})), { callerDid: callerDid || undefined });
78
+ const localBase = deps.getBaseUrl();
64
79
  const to = toPicoId ||
65
- (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId));
80
+ (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId, localBase));
66
81
  if (to &&
67
- (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub))) {
82
+ (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub, localBase))) {
68
83
  const rxEci = await resolveRecipientRxEci(deps, to, subscriptionId);
69
84
  if (rxEci) {
70
85
  return deps.pf.eventWait({
@@ -96,10 +111,11 @@ async function crossPicoQuery(deps, fromPicoId, toPicoId, subscriptionId, query)
96
111
  if (!sub || !sub.rxEci) {
97
112
  throw new errors_1.IdentityError(`Unknown subscription ${subscriptionId}`, 404);
98
113
  }
114
+ const localBase = deps.getBaseUrl();
99
115
  const to = toPicoId ||
100
- (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId));
116
+ (await resolveRecipientPicoId(deps.store, deps.pf, fromPicoId, subscriptionId, localBase));
101
117
  if (to &&
102
- (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub))) {
118
+ (await usesLocalDispatch(deps.store, deps.pf, fromPicoId, to, sub, localBase))) {
103
119
  const rxEci = await resolveRecipientRxEci(deps, to, subscriptionId);
104
120
  if (rxEci) {
105
121
  return deps.pf.query({
@@ -1,4 +1,14 @@
1
1
  "use strict";
2
+ /**
3
+ * Engine global KRL module `dido` — the ruleset-facing bridge to IdentityService.
4
+ *
5
+ * Wrangler and subscription call `dido:*` for Layer 2 identity: did:webvh lookup,
6
+ * SKY intro/response, cross-pico query/event, DIDComm pack/unpack/route, and
7
+ * portable-move helpers. State lives in the engine identity store, not in KRL ent.
8
+ *
9
+ * Not the retired `io.picolabs.did-o` ruleset (removed in 1.7). Do not rename this
10
+ * module; it is internal OS plumbing wired at engine start via core.modules["dido"].
11
+ */
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  exports.default = initDidoModule;
4
14
  const krl_stdlib_1 = require("krl-stdlib");
@@ -72,7 +82,6 @@ function initDidoModule(identity) {
72
82
  }
73
83
  return undefined;
74
84
  }),
75
- prepareQuery: deprecated("prepareQuery"),
76
85
  sendQuery: krl_stdlib_1.krl.Function(["did", "message"], async function (did, message) {
77
86
  const picoId = this.rsCtx.pico().id;
78
87
  const from = message.from;
@@ -207,26 +216,79 @@ function initDidoModule(identity) {
207
216
  eid: typeof event.eid === "string" ? event.eid : undefined,
208
217
  });
209
218
  }),
210
- // Legacy did-o / did:peer:2 surface — removed in Layer 2 reboot.
211
- generateDID: deprecated("generateDID"),
212
- deleteDID: deprecated("deleteDID"),
213
- updateDID: deprecated("updateDID"),
214
- rotateDID: deprecated("rotateDID"),
215
- rotateInviteDID: deprecated("rotateInviteDID"),
216
- clearPendingRotations: deprecated("clearPendingRotations"),
217
- mapDid: deprecated("mapDid"),
218
- clearDidMap: deprecated("clearDidMap"),
219
- clearDidDocs: deprecated("clearDidDocs"),
220
- storeDidDoc: deprecated("storeDidDoc"),
221
- addLabelsToChannel: deprecated("addLabelsToChannel"),
219
+ relocateWebvhAfterMove: krl_stdlib_1.krl.Function(["options"], async function (options = {}) {
220
+ const opts = {};
221
+ if (typeof options.baseUrl === "string") {
222
+ opts.baseUrl = options.baseUrl;
223
+ }
224
+ if (options.renewIngress === true) {
225
+ opts.renewIngress = true;
226
+ }
227
+ return identity.relocateWebvhAfterMove(this.rsCtx.pico().id, opts);
228
+ }),
229
+ notifyPeersOfWebvhRotation: krl_stdlib_1.krl.Function(["relocation"], async function (relocation) {
230
+ return identity.notifyPeersOfWebvhRotation(this.rsCtx.pico().id, relocation);
231
+ }),
232
+ completePortableMove: krl_stdlib_1.krl.Function(["options"], async function (options = {}) {
233
+ const opts = {};
234
+ if (typeof options.baseUrl === "string") {
235
+ opts.baseUrl = options.baseUrl;
236
+ }
237
+ if (options.renewIngress === true) {
238
+ opts.renewIngress = true;
239
+ }
240
+ return identity.completePortableMove(this.rsCtx.pico().id, opts);
241
+ }),
242
+ exportPortableSubtree: krl_stdlib_1.krl.Function(["subtreeRootPicoId", "secret"], async function (subtreeRootPicoId, secret) {
243
+ return identity.exportPortableSubtree(this.rsCtx.pico().id, subtreeRootPicoId, secret);
244
+ }),
245
+ summarizePortableSubtreeExport: krl_stdlib_1.krl.Function(["blob", "secret"], function (blob, secret) {
246
+ return identity.summarizePortableSubtreeExport(blob, secret);
247
+ }),
248
+ importPortableSubtree: krl_stdlib_1.krl.Function(["blob", "secret", "options"], async function (blob, secret, options = {}) {
249
+ const opts = {};
250
+ if (typeof options.baseUrl === "string") {
251
+ opts.baseUrl = options.baseUrl;
252
+ }
253
+ if (options.renewIngress === true) {
254
+ opts.renewIngress = true;
255
+ }
256
+ if (Object.keys(opts).length === 0) {
257
+ opts.renewIngress = true;
258
+ }
259
+ const importOpts = {};
260
+ if (typeof options.parentChannelEci === "string") {
261
+ importOpts.parentChannelEci = options.parentChannelEci;
262
+ }
263
+ if (typeof options.bootstrapDisplayName === "string") {
264
+ let name = options.bootstrapDisplayName.trim();
265
+ if (name.length >= 2 &&
266
+ name.startsWith('"') &&
267
+ name.endsWith('"')) {
268
+ name = name.slice(1, -1).trim();
269
+ }
270
+ if (name.length > 0) {
271
+ importOpts.bootstrapDisplayName = name;
272
+ }
273
+ }
274
+ return identity.importPortableSubtree(this.rsCtx.pico().id, blob, secret, opts, importOpts);
275
+ }),
276
+ finalizePortableImport: krl_stdlib_1.krl.Function(["importResult", "options"], async function (importResult, options = {}) {
277
+ const opts = {};
278
+ if (typeof options.baseUrl === "string") {
279
+ opts.baseUrl = options.baseUrl;
280
+ }
281
+ if (options.renewIngress === true) {
282
+ opts.renewIngress = true;
283
+ }
284
+ if (Object.keys(opts).length === 0) {
285
+ opts.renewIngress = true;
286
+ }
287
+ return identity.finalizePortableImport(importResult, opts);
288
+ }),
222
289
  };
223
290
  return module;
224
291
  }
225
- function deprecated(name) {
226
- return krl_stdlib_1.krl.Function([], async function () {
227
- throw new errors_1.IdentityError(`dido:${name} removed in Layer 2 reboot — use engine identity primitives`, 410);
228
- });
229
- }
230
292
  function extractDidcommEndpoint(doc) {
231
293
  const services = doc.service;
232
294
  if (!services || services.length === 0) {
@@ -66,12 +66,12 @@ async function establishSubscriptionIdentity(store, pf, picoId, input) {
66
66
  };
67
67
  }
68
68
  async function linkRemotePeer(store, picoId, subscriptionId, input) {
69
- var _a, _b, _c, _d;
69
+ var _a, _b, _c, _d, _e;
70
70
  const sub = await store.getPeerSubscription(picoId, subscriptionId);
71
71
  if (!sub) {
72
72
  throw new errors_1.IdentityError(`Unknown subscription ${subscriptionId}`, 404);
73
73
  }
74
- const updated = Object.assign(Object.assign({}, sub), { remotePeerDid: input.remotePeerDid, remoteWebvhDid: (_a = input.remoteWebvhDid) !== null && _a !== void 0 ? _a : sub.remoteWebvhDid, remoteMeshRootId: (_b = input.remoteMeshRootId) !== null && _b !== void 0 ? _b : sub.remoteMeshRootId, remoteTxHost: (_c = input.remoteTxHost) !== null && _c !== void 0 ? _c : sub.remoteTxHost, remoteDidcommEndpoint: (_d = input.remoteDidcommEndpoint) !== null && _d !== void 0 ? _d : sub.remoteDidcommEndpoint });
74
+ const updated = Object.assign(Object.assign({}, sub), { remotePeerDid: (_a = input.remotePeerDid) !== null && _a !== void 0 ? _a : sub.remotePeerDid, remoteWebvhDid: (_b = input.remoteWebvhDid) !== null && _b !== void 0 ? _b : sub.remoteWebvhDid, remoteMeshRootId: (_c = input.remoteMeshRootId) !== null && _c !== void 0 ? _c : sub.remoteMeshRootId, remoteTxHost: (_d = input.remoteTxHost) !== null && _d !== void 0 ? _d : sub.remoteTxHost, remoteDidcommEndpoint: (_e = input.remoteDidcommEndpoint) !== null && _e !== void 0 ? _e : sub.remoteDidcommEndpoint });
75
75
  await store.putPeerSubscription(picoId, updated);
76
76
  return updated;
77
77
  }