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
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
|
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,
|