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.
- package/README.md +13 -8
- package/dist/RulesetRegistryLoaderFs.js +14 -2
- package/dist/auth/cookies.js +32 -0
- package/dist/auth/index.js +6 -1
- package/dist/channelIdentityPolicy.js +22 -0
- package/dist/cli.js +104 -69
- package/dist/engineConfig.js +280 -0
- package/dist/identity/IdentityService.js +90 -0
- package/dist/identity/crossPico.js +24 -8
- package/dist/identity/didoModule.js +80 -18
- package/dist/identity/establishSubscription.js +2 -2
- package/dist/identity/identityPortable.js +92 -0
- package/dist/identity/index.js +10 -1
- package/dist/identity/localPeerReconcile.js +65 -0
- package/dist/identity/peerDid4.js +175 -0
- package/dist/identity/peerDid4Create.js +90 -0
- package/dist/identity/portableExportPrepare.js +196 -0
- package/dist/identity/portableMove.js +87 -0
- package/dist/identity/skyIntro.js +6 -3
- package/dist/identity/skyProtocol.js +26 -1
- package/dist/identity/skyRotation.js +121 -0
- package/dist/identity/store.js +5 -1
- package/dist/identity/subscriptionEntSync.js +72 -0
- package/dist/identity/veramoDidComm.js +41 -2
- package/dist/identity/webvh.js +4 -2
- package/dist/identity/webvhRelocation.js +115 -0
- package/dist/index.js +82 -22
- package/dist/logging.js +8 -12
- package/dist/oauth/OAuthService.js +6 -2
- package/dist/policyConfigFromJson.js +112 -0
- package/dist/runMcp.js +27 -0
- package/dist/server.js +56 -24
- package/dist/subtreeWrangler.js +180 -0
- package/dist/uiChannelPolicies.js +15 -0
- package/krl/io.picolabs.oauth.krl +41 -2
- package/krl/io.picolabs.pds.krl +131 -10
- package/krl/io.picolabs.pico-engine-ui.krl +209 -21
- package/krl/io.picolabs.portable_subtree.krl +97 -0
- package/krl/io.picolabs.subscription.krl +180 -72
- package/krl/io.picolabs.wrangler.krl +296 -57
- package/mcp/devResources.js +118 -0
- package/mcp/devTools.js +351 -0
- package/mcp/engineClient.js +133 -0
- package/mcp/meshHttp.js +137 -0
- package/mcp/meshTools.js +189 -0
- package/mcp/runStdio.js +34 -0
- package/mcp/schemaToZod.js +56 -0
- package/package.json +20 -8
- package/public/docs/_sidebar.md +2 -1
- package/public/docs/llms-full.txt +479 -0
- package/public/docs/llms.txt +37 -0
- package/public/docs/openapi.yaml +78 -0
- package/public/docs/pico-engine.md +235 -4
- package/public/docs/pico-overview.md +117 -0
- package/public/docs/pico.md +3 -1
- package/public/docs/rulesets/README.md +25 -0
- package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
- package/public/docs/rulesets/io.picolabs.pds.md +327 -0
- package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
- package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
- package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
- package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +28 -26
- package/src/RulesetRegistryLoaderFs.ts +18 -3
- package/src/auth/cookies.ts +34 -0
- package/src/auth/index.ts +7 -0
- package/src/channelIdentityPolicy.ts +29 -0
- package/src/cli.ts +68 -37
- package/src/engineConfig.ts +345 -0
- package/src/identity/IdentityService.ts +189 -1
- package/src/identity/crossPico.ts +57 -8
- package/src/identity/didoModule.ts +140 -23
- package/src/identity/establishSubscription.ts +2 -2
- package/src/identity/identityPortable.ts +153 -0
- package/src/identity/index.ts +14 -0
- package/src/identity/localPeerReconcile.ts +97 -0
- package/src/identity/peerDid4.ts +197 -0
- package/src/identity/peerDid4Create.ts +121 -0
- package/src/identity/portableExportPrepare.ts +302 -0
- package/src/identity/portableMove.ts +193 -0
- package/src/identity/skyIntro.ts +11 -11
- package/src/identity/skyProtocol.ts +46 -0
- package/src/identity/skyRotation.ts +211 -0
- package/src/identity/store.ts +5 -1
- package/src/identity/subscriptionEntSync.ts +97 -0
- package/src/identity/veramoDidComm.ts +52 -2
- package/src/identity/webvh.ts +4 -4
- package/src/identity/webvhRelocation.ts +167 -0
- package/src/index.ts +119 -25
- package/src/logging.ts +8 -14
- package/src/oauth/OAuthService.ts +11 -3
- package/src/policyConfigFromJson.ts +131 -0
- package/src/runMcp.ts +30 -0
- package/src/server.ts +79 -26
- package/src/subtreeWrangler.ts +278 -0
- package/src/uiChannelPolicies.ts +15 -0
- package/krl/io.picolabs.did-o.krl +0 -349
|
@@ -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
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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: (
|
|
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
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Identity snapshots for portable subtree export/import (Phase D).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rewriteWebvhLogForPicoId = rewriteWebvhLogForPicoId;
|
|
7
|
+
exports.exportNodeIdentity = exportNodeIdentity;
|
|
8
|
+
exports.importNodeIdentity = importNodeIdentity;
|
|
9
|
+
exports.createSubtreePortableHooks = createSubtreePortableHooks;
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
const webvh_1 = require("./webvh");
|
|
12
|
+
const veramoDidComm_1 = require("./veramoDidComm");
|
|
13
|
+
function rewritePicoIdInValue(value, oldPicoId, newPicoId) {
|
|
14
|
+
if (typeof value === "string") {
|
|
15
|
+
return value
|
|
16
|
+
.split(oldPicoId)
|
|
17
|
+
.join(newPicoId);
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
return value.map((item) => rewritePicoIdInValue(item, oldPicoId, newPicoId));
|
|
21
|
+
}
|
|
22
|
+
if (value && typeof value === "object") {
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [key, child] of Object.entries(value)) {
|
|
25
|
+
out[key] = rewritePicoIdInValue(child, oldPicoId, newPicoId);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function rewriteWebvhLogForPicoId(log, oldPicoId, newPicoId) {
|
|
32
|
+
return rewritePicoIdInValue(log, oldPicoId, newPicoId);
|
|
33
|
+
}
|
|
34
|
+
async function exportNodeIdentity(store, picoId) {
|
|
35
|
+
const webvhDid = await store.getWebvhDid(picoId);
|
|
36
|
+
const webvhLog = await store.getWebvhLog(picoId);
|
|
37
|
+
const webvhKeys = await store.getWebvhKeys(picoId);
|
|
38
|
+
if (!webvhDid || !(webvhLog === null || webvhLog === void 0 ? void 0 : webvhLog.length) || !webvhKeys) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
webvhDid,
|
|
43
|
+
webvhLog,
|
|
44
|
+
webvhKeys,
|
|
45
|
+
webvhWebDoc: (await store.getWebvhWebDoc(picoId)) || undefined,
|
|
46
|
+
publicIntro: (await store.getPublicIntro(picoId)) === true,
|
|
47
|
+
peerSubscriptions: await store.listPeerSubscriptions(picoId),
|
|
48
|
+
routes: (await store.getRoutes(picoId)) || undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function importNodeIdentity(store, pf, oldPicoId, newPicoId, raw, eciMap, picoIdMap) {
|
|
52
|
+
if (!raw || typeof raw !== "object") {
|
|
53
|
+
throw new errors_1.IdentityError("Invalid portable identity export", 400);
|
|
54
|
+
}
|
|
55
|
+
const identity = raw;
|
|
56
|
+
if (typeof identity.webvhDid !== "string" ||
|
|
57
|
+
!Array.isArray(identity.webvhLog) ||
|
|
58
|
+
!identity.webvhKeys) {
|
|
59
|
+
throw new errors_1.IdentityError("Portable identity export missing webvh fields", 400);
|
|
60
|
+
}
|
|
61
|
+
const meshRootId = (0, webvh_1.meshRootIdFor)(pf, newPicoId);
|
|
62
|
+
await store.putWebvhKeys(newPicoId, identity.webvhKeys);
|
|
63
|
+
await store.putWebvhLog(newPicoId, identity.webvhLog);
|
|
64
|
+
await store.putWebvhDid(newPicoId, identity.webvhDid);
|
|
65
|
+
await store.putMeshRootId(newPicoId, meshRootId);
|
|
66
|
+
await store.putPublicIntro(newPicoId, identity.publicIntro === true);
|
|
67
|
+
await store.putDidcommIngressEci(newPicoId, "");
|
|
68
|
+
if (identity.webvhWebDoc) {
|
|
69
|
+
await store.putWebvhWebDoc(newPicoId, identity.webvhWebDoc);
|
|
70
|
+
}
|
|
71
|
+
if (identity.routes) {
|
|
72
|
+
await store.putRoutes(newPicoId, identity.routes);
|
|
73
|
+
}
|
|
74
|
+
for (const sub of identity.peerSubscriptions || []) {
|
|
75
|
+
const rxEci = sub.rxEci ? eciMap[sub.rxEci] || sub.rxEci : sub.rxEci;
|
|
76
|
+
const remoteMeshRootId = sub.remoteMeshRootId && picoIdMap[sub.remoteMeshRootId]
|
|
77
|
+
? picoIdMap[sub.remoteMeshRootId]
|
|
78
|
+
: sub.remoteMeshRootId;
|
|
79
|
+
await store.putPeerSubscription(newPicoId, Object.assign(Object.assign({}, sub), { rxEci,
|
|
80
|
+
remoteMeshRootId }));
|
|
81
|
+
}
|
|
82
|
+
await (0, veramoDidComm_1.warmPeerDidsForPico)(store, newPicoId);
|
|
83
|
+
if ((0, webvh_1.webvhPathsForPico)(newPicoId)[1] !== newPicoId) {
|
|
84
|
+
throw new errors_1.IdentityError("Webvh path rewrite failed after import", 500);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function createSubtreePortableHooks(store, pf) {
|
|
88
|
+
return {
|
|
89
|
+
exportNodeIdentity: (picoId) => exportNodeIdentity(store, picoId),
|
|
90
|
+
importNodeIdentity: (oldPicoId, newPicoId, identity, eciMap, picoIdMap) => importNodeIdentity(store, pf, oldPicoId, newPicoId, identity, eciMap, picoIdMap),
|
|
91
|
+
};
|
|
92
|
+
}
|
package/dist/identity/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IDENTITY_STORAGE_KNOWN_GAP = exports.initDidoModule = exports.IdentityError = exports.IdentityService = exports.migrateFromDidO = exports.IDENTITY_PREFIX = exports.IdentityStore = void 0;
|
|
3
|
+
exports.IDENTITY_STORAGE_KNOWN_GAP = exports.finalizePortableImport = exports.importPortableSubtree = exports.exportPortableSubtree = exports.rewriteWebvhLogForPicoId = exports.importNodeIdentity = exports.exportNodeIdentity = exports.createSubtreePortableHooks = exports.initDidoModule = exports.IdentityError = exports.IdentityService = exports.migrateFromDidO = exports.IDENTITY_PREFIX = exports.IdentityStore = void 0;
|
|
4
4
|
var store_1 = require("./store");
|
|
5
5
|
Object.defineProperty(exports, "IdentityStore", { enumerable: true, get: function () { return store_1.IdentityStore; } });
|
|
6
6
|
Object.defineProperty(exports, "IDENTITY_PREFIX", { enumerable: true, get: function () { return store_1.IDENTITY_PREFIX; } });
|
|
@@ -11,5 +11,14 @@ var errors_1 = require("./errors");
|
|
|
11
11
|
Object.defineProperty(exports, "IdentityError", { enumerable: true, get: function () { return errors_1.IdentityError; } });
|
|
12
12
|
var didoModule_1 = require("./didoModule");
|
|
13
13
|
Object.defineProperty(exports, "initDidoModule", { enumerable: true, get: function () { return didoModule_1.default; } });
|
|
14
|
+
var identityPortable_1 = require("./identityPortable");
|
|
15
|
+
Object.defineProperty(exports, "createSubtreePortableHooks", { enumerable: true, get: function () { return identityPortable_1.createSubtreePortableHooks; } });
|
|
16
|
+
Object.defineProperty(exports, "exportNodeIdentity", { enumerable: true, get: function () { return identityPortable_1.exportNodeIdentity; } });
|
|
17
|
+
Object.defineProperty(exports, "importNodeIdentity", { enumerable: true, get: function () { return identityPortable_1.importNodeIdentity; } });
|
|
18
|
+
Object.defineProperty(exports, "rewriteWebvhLogForPicoId", { enumerable: true, get: function () { return identityPortable_1.rewriteWebvhLogForPicoId; } });
|
|
19
|
+
var portableMove_1 = require("./portableMove");
|
|
20
|
+
Object.defineProperty(exports, "exportPortableSubtree", { enumerable: true, get: function () { return portableMove_1.exportPortableSubtree; } });
|
|
21
|
+
Object.defineProperty(exports, "importPortableSubtree", { enumerable: true, get: function () { return portableMove_1.importPortableSubtree; } });
|
|
22
|
+
Object.defineProperty(exports, "finalizePortableImport", { enumerable: true, get: function () { return portableMove_1.finalizePortableImport; } });
|
|
14
23
|
var types_1 = require("./types");
|
|
15
24
|
Object.defineProperty(exports, "IDENTITY_STORAGE_KNOWN_GAP", { enumerable: true, get: function () { return types_1.IDENTITY_STORAGE_KNOWN_GAP; } });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* After a portable import, update relationship buses on other picos on this engine
|
|
4
|
+
* (e.g. ride coordinator) so they still point at the moved root by DID / remapped ECI.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.patchEstablishedBusesForMovedRoot = patchEstablishedBusesForMovedRoot;
|
|
8
|
+
exports.refreshLocalPeersOfMovedRoot = refreshLocalPeersOfMovedRoot;
|
|
9
|
+
const SUBSCRIPTION_RID = "io.picolabs.subscription";
|
|
10
|
+
/** Pure patch logic for unit tests. */
|
|
11
|
+
function patchEstablishedBusesForMovedRoot(established, result, relocation, baseUrl) {
|
|
12
|
+
const host = baseUrl.replace(/\/$/, "");
|
|
13
|
+
const oldRoot = result.oldRootPicoId;
|
|
14
|
+
const newRoot = result.newRootPicoId;
|
|
15
|
+
let changed = false;
|
|
16
|
+
const next = established.map((raw) => {
|
|
17
|
+
if (!raw || typeof raw !== "object") {
|
|
18
|
+
return raw;
|
|
19
|
+
}
|
|
20
|
+
const bus = Object.assign({}, raw);
|
|
21
|
+
const tx = bus["Tx"];
|
|
22
|
+
const txRemapped = typeof tx === "string" && result.eciMap[tx] ? result.eciMap[tx] : undefined;
|
|
23
|
+
const matches = bus["picoID"] === oldRoot ||
|
|
24
|
+
bus["Tx_did"] === relocation.priorDid ||
|
|
25
|
+
txRemapped !== undefined ||
|
|
26
|
+
(typeof tx === "string" && result.eciMap[tx] !== undefined);
|
|
27
|
+
if (!matches) {
|
|
28
|
+
return raw;
|
|
29
|
+
}
|
|
30
|
+
changed = true;
|
|
31
|
+
if (bus["picoID"] === oldRoot) {
|
|
32
|
+
bus["picoID"] = newRoot;
|
|
33
|
+
}
|
|
34
|
+
if (bus["Tx_did"] === relocation.priorDid) {
|
|
35
|
+
bus["Tx_did"] = relocation.newDid;
|
|
36
|
+
}
|
|
37
|
+
if (txRemapped) {
|
|
38
|
+
bus["Tx"] = txRemapped;
|
|
39
|
+
}
|
|
40
|
+
if (bus["layer2"] === true) {
|
|
41
|
+
bus["Tx_host"] = host;
|
|
42
|
+
}
|
|
43
|
+
return bus;
|
|
44
|
+
});
|
|
45
|
+
return { next, changed };
|
|
46
|
+
}
|
|
47
|
+
/** Refresh ent:established on every loaded pico that references the moved root. */
|
|
48
|
+
async function refreshLocalPeersOfMovedRoot(pf, result, relocation, baseUrl) {
|
|
49
|
+
let picosUpdated = 0;
|
|
50
|
+
for (const pico of pf.loadedPicos()) {
|
|
51
|
+
if (!pico.rulesets[SUBSCRIPTION_RID]) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const establishedRaw = await pico.getEnt(SUBSCRIPTION_RID, "established");
|
|
55
|
+
if (!Array.isArray(establishedRaw) || establishedRaw.length === 0) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const { next, changed } = patchEstablishedBusesForMovedRoot(establishedRaw, result, relocation, baseUrl);
|
|
59
|
+
if (changed) {
|
|
60
|
+
await pico.putEnt(SUBSCRIPTION_RID, "established", next);
|
|
61
|
+
picosUpdated += 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return picosUpdated;
|
|
65
|
+
}
|