pico-engine 1.6.2 → 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 +117 -14
- package/dist/RulesetRegistryLoaderFs.js +24 -8
- package/dist/auth/cookies.js +32 -0
- package/dist/auth/index.js +6 -1
- package/dist/bundledKrl.js +129 -11
- package/dist/channelIdentityPolicy.js +22 -0
- package/dist/cli.js +105 -46
- package/dist/engineConfig.js +280 -0
- package/dist/identity/IdentityService.js +90 -0
- package/dist/identity/crossPico.js +106 -30
- 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 +10 -4
- 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 +127 -34
- package/dist/levelDb.js +102 -0
- package/dist/logging.js +47 -8
- package/dist/oauth/OAuthService.js +12 -5
- package/dist/oauth/channelEligibility.js +7 -1
- package/dist/oauth/index.js +3 -1
- package/dist/policyConfigFromJson.js +112 -0
- package/dist/runMcp.js +27 -0
- package/dist/server.js +95 -24
- package/dist/subtreeWrangler.js +180 -0
- package/dist/uiChannelPolicies.js +16 -0
- package/krl/io.picolabs.oauth.krl +51 -5
- package/krl/io.picolabs.pds.krl +131 -10
- package/krl/io.picolabs.pico-engine-ui.krl +219 -22
- package/krl/io.picolabs.portable_subtree.krl +97 -0
- package/krl/io.picolabs.subscription.krl +226 -72
- package/krl/io.picolabs.wrangler.krl +300 -58
- 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 +22 -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 +43 -11
- package/src/auth/cookies.ts +34 -0
- package/src/auth/index.ts +7 -0
- package/src/bundledKrl.ts +150 -12
- package/src/channelIdentityPolicy.ts +29 -0
- package/src/cli.ts +98 -40
- package/src/engineConfig.ts +345 -0
- package/src/identity/IdentityService.ts +189 -1
- package/src/identity/crossPico.ts +161 -41
- 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 +16 -12
- 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 +179 -39
- package/src/levelDb.ts +122 -0
- package/src/logging.ts +63 -11
- package/src/oauth/OAuthService.ts +20 -6
- package/src/oauth/channelEligibility.ts +9 -0
- package/src/oauth/index.ts +7 -1
- package/src/policyConfigFromJson.ts +131 -0
- package/src/runMcp.ts +30 -0
- package/src/server.ts +133 -27
- package/src/subtreeWrangler.ts +278 -0
- package/src/uiChannelPolicies.ts +16 -0
- package/krl/io.picolabs.did-o.krl +0 -349
- package/krl/test/didtestdid.krl +0 -78
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Before portable export: upgrade extant Layer 1 subscription buses to Layer 2 (DID)
|
|
4
|
+
* so relationships (including community ↔ thing) survive cross-engine move + webvh rotate.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.prepareSubtreeRelationshipsForPortableExport = prepareSubtreeRelationshipsForPortableExport;
|
|
8
|
+
const establishSubscription_1 = require("./establishSubscription");
|
|
9
|
+
const SUBSCRIPTION_RID = "io.picolabs.subscription";
|
|
10
|
+
function busId(bus) {
|
|
11
|
+
const id = bus["Id"];
|
|
12
|
+
return typeof id === "string" && id.length > 0 ? id : undefined;
|
|
13
|
+
}
|
|
14
|
+
function collectSubtreePicoIds(pf, picoRef) {
|
|
15
|
+
const pico = pf.getPico(picoRef);
|
|
16
|
+
const ids = [pico.id];
|
|
17
|
+
for (const childEci of pico.toReadOnly().children) {
|
|
18
|
+
const child = pf.lookupChannel(childEci).pico;
|
|
19
|
+
ids.push(...collectSubtreePicoIds(pf, child.id));
|
|
20
|
+
}
|
|
21
|
+
return ids;
|
|
22
|
+
}
|
|
23
|
+
/** Read did:webvh from the identity store — never pf.query (deadlocks during export KRL query). */
|
|
24
|
+
async function webvhDidForChannelEci(store, pf, remoteEci) {
|
|
25
|
+
try {
|
|
26
|
+
const did = await store.getWebvhDid(pf.getPico(remoteEci).id);
|
|
27
|
+
return typeof did === "string" && did.length > 0 ? did : null;
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function mergeBusToLayer2(bus, remoteWebvhDid, rxPeerDid) {
|
|
34
|
+
return Object.assign(Object.assign({}, bus), { layer2: true, Tx_did: remoteWebvhDid, Rx_did: rxPeerDid, Tx: "" });
|
|
35
|
+
}
|
|
36
|
+
async function upgradeEstablishedList(store, pf, picoId, list) {
|
|
37
|
+
const localDid = await store.getWebvhDid(picoId);
|
|
38
|
+
const reciprocals = [];
|
|
39
|
+
let upgraded = 0;
|
|
40
|
+
let skipped = 0;
|
|
41
|
+
const next = [];
|
|
42
|
+
for (const raw of list) {
|
|
43
|
+
if (!raw || typeof raw !== "object") {
|
|
44
|
+
next.push(raw);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const bus = Object.assign({}, raw);
|
|
48
|
+
if (bus["layer2"] === true) {
|
|
49
|
+
next.push(bus);
|
|
50
|
+
skipped += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const subId = busId(bus);
|
|
54
|
+
const remoteEci = typeof bus["Tx"] === "string" && bus["Tx"].length > 0
|
|
55
|
+
? bus["Tx"]
|
|
56
|
+
: undefined;
|
|
57
|
+
if (!subId || !remoteEci) {
|
|
58
|
+
next.push(bus);
|
|
59
|
+
skipped += 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const remoteWebvhDid = await webvhDidForChannelEci(store, pf, remoteEci);
|
|
63
|
+
if (!remoteWebvhDid) {
|
|
64
|
+
next.push(bus);
|
|
65
|
+
skipped += 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const established = await (0, establishSubscription_1.establishSubscriptionIdentity)(store, pf, picoId, {
|
|
69
|
+
subscriptionId: subId,
|
|
70
|
+
remoteWebvhDid,
|
|
71
|
+
remoteTxHost: typeof bus["Tx_host"] === "string" ? bus["Tx_host"] : undefined,
|
|
72
|
+
rxEci: typeof bus["Rx"] === "string" ? bus["Rx"] : undefined,
|
|
73
|
+
channelName: typeof bus["name"] === "string" ? bus["name"] : undefined,
|
|
74
|
+
channelType: typeof bus["channel_type"] === "string"
|
|
75
|
+
? bus["channel_type"]
|
|
76
|
+
: undefined,
|
|
77
|
+
});
|
|
78
|
+
next.push(mergeBusToLayer2(bus, remoteWebvhDid, established.peerDid));
|
|
79
|
+
upgraded += 1;
|
|
80
|
+
if (localDid) {
|
|
81
|
+
try {
|
|
82
|
+
const remotePico = pf.getPico(remoteEci);
|
|
83
|
+
reciprocals.push({
|
|
84
|
+
remotePicoId: remotePico.id,
|
|
85
|
+
localWebvhDid: localDid,
|
|
86
|
+
subId,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
// remote not on this engine
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { next, upgraded, skipped, reciprocals };
|
|
95
|
+
}
|
|
96
|
+
async function upgradeReciprocalBuses(store, pf, remotePicoId, localPicoId, localWebvhDid) {
|
|
97
|
+
const remote = pf.loadedPicos().find((p) => p.id === remotePicoId);
|
|
98
|
+
if (!(remote === null || remote === void 0 ? void 0 : remote.rulesets[SUBSCRIPTION_RID])) {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
const establishedRaw = await remote.getEnt(SUBSCRIPTION_RID, "established");
|
|
102
|
+
if (!Array.isArray(establishedRaw) || establishedRaw.length === 0) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
let upgraded = 0;
|
|
106
|
+
const next = [];
|
|
107
|
+
for (const raw of establishedRaw) {
|
|
108
|
+
if (!raw || typeof raw !== "object") {
|
|
109
|
+
next.push(raw);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const bus = Object.assign({}, raw);
|
|
113
|
+
if (bus["layer2"] === true) {
|
|
114
|
+
next.push(bus);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const subId = busId(bus);
|
|
118
|
+
const tx = typeof bus["Tx"] === "string" && bus["Tx"].length > 0
|
|
119
|
+
? bus["Tx"]
|
|
120
|
+
: undefined;
|
|
121
|
+
let pointsAtLocal = bus["picoID"] === localPicoId;
|
|
122
|
+
if (!pointsAtLocal && tx) {
|
|
123
|
+
try {
|
|
124
|
+
pointsAtLocal = pf.getPico(tx).id === localPicoId;
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
pointsAtLocal = false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!subId || !pointsAtLocal) {
|
|
131
|
+
next.push(bus);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const established = await (0, establishSubscription_1.establishSubscriptionIdentity)(store, pf, remotePicoId, {
|
|
135
|
+
subscriptionId: subId,
|
|
136
|
+
remoteWebvhDid: localWebvhDid,
|
|
137
|
+
remoteTxHost: typeof bus["Tx_host"] === "string" ? bus["Tx_host"] : undefined,
|
|
138
|
+
rxEci: typeof bus["Rx"] === "string" ? bus["Rx"] : undefined,
|
|
139
|
+
});
|
|
140
|
+
const thingSub = await store.getPeerSubscription(localPicoId, subId);
|
|
141
|
+
const remoteWebvh = await store.getWebvhDid(remotePicoId);
|
|
142
|
+
const txHost = typeof bus["Tx_host"] === "string" ? bus["Tx_host"] : undefined;
|
|
143
|
+
if (thingSub === null || thingSub === void 0 ? void 0 : thingSub.peerDid) {
|
|
144
|
+
await (0, establishSubscription_1.linkRemotePeer)(store, remotePicoId, subId, {
|
|
145
|
+
remotePeerDid: thingSub.peerDid,
|
|
146
|
+
remoteWebvhDid: localWebvhDid,
|
|
147
|
+
remoteTxHost: txHost,
|
|
148
|
+
});
|
|
149
|
+
await (0, establishSubscription_1.linkRemotePeer)(store, localPicoId, subId, {
|
|
150
|
+
remotePeerDid: established.peerDid,
|
|
151
|
+
remoteWebvhDid: remoteWebvh !== null && remoteWebvh !== void 0 ? remoteWebvh : undefined,
|
|
152
|
+
remoteTxHost: txHost,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
next.push(mergeBusToLayer2(bus, localWebvhDid, established.peerDid));
|
|
156
|
+
upgraded += 1;
|
|
157
|
+
}
|
|
158
|
+
if (upgraded > 0) {
|
|
159
|
+
await remote.putEnt(SUBSCRIPTION_RID, "established", next);
|
|
160
|
+
}
|
|
161
|
+
return upgraded;
|
|
162
|
+
}
|
|
163
|
+
/** Upgrade extant L1 established buses to L2 for every pico in the export subtree. */
|
|
164
|
+
async function prepareSubtreeRelationshipsForPortableExport(deps, subtreeRootRef) {
|
|
165
|
+
const subtreeIds = new Set(collectSubtreePicoIds(deps.pf, subtreeRootRef));
|
|
166
|
+
let upgradedOnSubtree = 0;
|
|
167
|
+
let upgradedOnPeers = 0;
|
|
168
|
+
let skipped = 0;
|
|
169
|
+
const reciprocalSeen = new Set();
|
|
170
|
+
for (const picoId of subtreeIds) {
|
|
171
|
+
const pico = deps.pf.loadedPicos().find((p) => p.id === picoId);
|
|
172
|
+
if (!(pico === null || pico === void 0 ? void 0 : pico.rulesets[SUBSCRIPTION_RID])) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const establishedRaw = await pico.getEnt(SUBSCRIPTION_RID, "established");
|
|
176
|
+
if (!Array.isArray(establishedRaw) || establishedRaw.length === 0) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const list = establishedRaw.filter((b) => b && typeof b === "object");
|
|
180
|
+
const { next, upgraded, skipped: skip, reciprocals, } = await upgradeEstablishedList(deps.store, deps.pf, picoId, list);
|
|
181
|
+
skipped += skip;
|
|
182
|
+
if (upgraded > 0) {
|
|
183
|
+
await pico.putEnt(SUBSCRIPTION_RID, "established", next);
|
|
184
|
+
upgradedOnSubtree += upgraded;
|
|
185
|
+
}
|
|
186
|
+
for (const r of reciprocals) {
|
|
187
|
+
const key = `${r.remotePicoId}:${r.localWebvhDid}`;
|
|
188
|
+
if (reciprocalSeen.has(key)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
reciprocalSeen.add(key);
|
|
192
|
+
upgradedOnPeers += await upgradeReciprocalBuses(deps.store, deps.pf, r.remotePicoId, picoId, r.localWebvhDid);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { upgradedOnSubtree, upgradedOnPeers, skipped };
|
|
196
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* End-to-end portable move: export subtree + identity, import, relocate, notify peers.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.exportPortableSubtree = exportPortableSubtree;
|
|
7
|
+
exports.finalizePortableImport = finalizePortableImport;
|
|
8
|
+
exports.importPortableSubtree = importPortableSubtree;
|
|
9
|
+
const pico_engine_core_1 = require("pico-engine-core");
|
|
10
|
+
const subtreeWrangler_1 = require("../subtreeWrangler");
|
|
11
|
+
const subtreeWrangler_2 = require("../subtreeWrangler");
|
|
12
|
+
const localPeerReconcile_1 = require("./localPeerReconcile");
|
|
13
|
+
const portableExportPrepare_1 = require("./portableExportPrepare");
|
|
14
|
+
const subscriptionEntSync_1 = require("./subscriptionEntSync");
|
|
15
|
+
function resolveImportBootstrapName(blob, secret, displayNameOverride) {
|
|
16
|
+
const override = displayNameOverride === null || displayNameOverride === void 0 ? void 0 : displayNameOverride.trim();
|
|
17
|
+
if (override) {
|
|
18
|
+
return override;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const fromBlob = (0, pico_engine_core_1.subtreeRootBootstrapName)(blob, secret);
|
|
22
|
+
if (fromBlob !== "imported") {
|
|
23
|
+
return fromBlob;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
// invalid blob handled later in importIntoExistingChild
|
|
28
|
+
}
|
|
29
|
+
return "imported";
|
|
30
|
+
}
|
|
31
|
+
function subtreeServices(deps) {
|
|
32
|
+
return Object.assign({ db: deps.pf.db, rsRegistry: deps.rsRegistry, portableHooks: deps.identity.subtreePortableHooks(), resolveBundledRulesetUrl: deps.resolveBundledRulesetUrl }, (0, subtreeWrangler_2.wranglerSubtreeImportServices)(deps.rsRegistry));
|
|
33
|
+
}
|
|
34
|
+
/** Export a subtree including identity snapshots for each pico. */
|
|
35
|
+
async function exportPortableSubtree(deps, picoId, secret, options) {
|
|
36
|
+
if ((options === null || options === void 0 ? void 0 : options.skipRelationshipUpgrade) !== true) {
|
|
37
|
+
await (0, portableExportPrepare_1.prepareSubtreeRelationshipsForPortableExport)(deps, picoId);
|
|
38
|
+
}
|
|
39
|
+
return (0, pico_engine_core_1.exportSubtree)(subtreeServices(deps), deps.pf, picoId, secret, options);
|
|
40
|
+
}
|
|
41
|
+
/** Relocate webvh + ingress for every imported pico; notify peers from the moved root. */
|
|
42
|
+
async function finalizePortableImport(deps, importResult, relocateOptions = { renewIngress: true }) {
|
|
43
|
+
const importedPicoIds = Object.values(importResult.picoIdMap);
|
|
44
|
+
for (const picoId of importedPicoIds) {
|
|
45
|
+
if (picoId === importResult.newRootPicoId) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (await deps.store.getWebvhDid(picoId)) {
|
|
49
|
+
await deps.identity.relocateWebvhAfterMove(picoId, relocateOptions);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const rootDid = await deps.store.getWebvhDid(importResult.newRootPicoId);
|
|
53
|
+
if (!rootDid) {
|
|
54
|
+
return { skipped: true, peersNotified: 0 };
|
|
55
|
+
}
|
|
56
|
+
const relocation = await deps.identity.completePortableMove(importResult.newRootPicoId, relocateOptions);
|
|
57
|
+
await (0, localPeerReconcile_1.refreshLocalPeersOfMovedRoot)(deps.pf, importResult, relocation, deps.getBaseUrl());
|
|
58
|
+
return relocation;
|
|
59
|
+
}
|
|
60
|
+
async function afterPortableHydrate(deps, result) {
|
|
61
|
+
if (deps.reloadImportedSchedules) {
|
|
62
|
+
await deps.reloadImportedSchedules(Object.values(result.picoIdMap));
|
|
63
|
+
}
|
|
64
|
+
for (const picoId of Object.values(result.picoIdMap)) {
|
|
65
|
+
await (0, subscriptionEntSync_1.syncLayer2EstablishedFromIdentity)(deps.store, deps.pf, picoId);
|
|
66
|
+
}
|
|
67
|
+
if (deps.firePicoImported) {
|
|
68
|
+
await deps.firePicoImported(result);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Import a portable subtree under parent and finalize relocation + peer notification. */
|
|
72
|
+
async function importPortableSubtree(deps, parent, blob, secret, relocateOptions, importOptions) {
|
|
73
|
+
const services = subtreeServices(deps);
|
|
74
|
+
const createOpts = (importOptions === null || importOptions === void 0 ? void 0 : importOptions.parentChannelEci)
|
|
75
|
+
? { channelEci: importOptions.parentChannelEci }
|
|
76
|
+
: undefined;
|
|
77
|
+
const bootstrapName = resolveImportBootstrapName(blob, secret, importOptions === null || importOptions === void 0 ? void 0 : importOptions.bootstrapDisplayName);
|
|
78
|
+
const { familyEci } = await (0, subtreeWrangler_1.createImportChildViaWrangler)(deps.pf, parent, bootstrapName, deps.rsRegistry, createOpts);
|
|
79
|
+
const importResult = await (0, pico_engine_core_1.importIntoExistingChild)(services, deps.pf, parent, familyEci, blob, secret, Object.assign(Object.assign({}, importOptions), { async afterImport(result, payload) {
|
|
80
|
+
if (importOptions === null || importOptions === void 0 ? void 0 : importOptions.afterImport) {
|
|
81
|
+
await importOptions.afterImport(result, payload);
|
|
82
|
+
}
|
|
83
|
+
await afterPortableHydrate(deps, result);
|
|
84
|
+
} }));
|
|
85
|
+
const relocation = await finalizePortableImport(deps, importResult, relocateOptions);
|
|
86
|
+
return Object.assign(Object.assign({}, importResult), { relocation });
|
|
87
|
+
}
|
|
@@ -59,6 +59,10 @@ async function postJwe(endpoint, jwe) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
async function sendSkyIntro(deps, picoId, input) {
|
|
62
|
+
const senderWebvh = await deps.store.getWebvhDid(picoId);
|
|
63
|
+
if (senderWebvh && input.targetDid === senderWebvh) {
|
|
64
|
+
throw new errors_1.IdentityError("Cannot form a relationship with self", 400);
|
|
65
|
+
}
|
|
62
66
|
const established = await (0, establishSubscription_1.establishSubscriptionIdentity)(deps.store, deps.pf, picoId, {
|
|
63
67
|
subscriptionId: input.subscriptionId,
|
|
64
68
|
channelName: input.name,
|
|
@@ -77,7 +81,6 @@ async function sendSkyIntro(deps, picoId, input) {
|
|
|
77
81
|
Tx_host: input.Tx_host || deps.getBaseUrl(),
|
|
78
82
|
subscription_id: input.subscriptionId,
|
|
79
83
|
};
|
|
80
|
-
const senderWebvh = await deps.store.getWebvhDid(picoId);
|
|
81
84
|
if (senderWebvh) {
|
|
82
85
|
body.sender_webvh = senderWebvh;
|
|
83
86
|
try {
|
|
@@ -183,12 +186,15 @@ async function handleSkyIntroResponseAtIngress(deps, picoId, plainMessage) {
|
|
|
183
186
|
const attrs = (0, skyProtocol_1.skyIntroResponseToWranglerAttrs)(response, {
|
|
184
187
|
Id: subscriptionId,
|
|
185
188
|
});
|
|
186
|
-
|
|
189
|
+
// Queue without waiting: the Tx pico may still be inside the outbound
|
|
190
|
+
// subscription transaction that triggered sendSkyIntro (same-engine local
|
|
191
|
+
// dispatch or cross-engine HTTP). eventWait here deadlocks that queue.
|
|
192
|
+
await deps.pf.event({
|
|
187
193
|
eci,
|
|
188
194
|
domain: "wrangler",
|
|
189
195
|
name: "sky_intro_response",
|
|
190
196
|
data: { attrs },
|
|
191
197
|
time: 0,
|
|
192
|
-
}
|
|
193
|
-
return { status: "
|
|
198
|
+
});
|
|
199
|
+
return { status: "intro_response_queued", subscriptionId };
|
|
194
200
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/** SKY protocol on DIDComm v2 — type URIs and payloads (1.0). */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.SKY_QUERY_RESPONSE = exports.SKY_QUERY = exports.SKY_EVENT = exports.SKY_INTRO_RESPONSE = exports.SKY_INTRO = exports.SKY_NS = void 0;
|
|
4
|
+
exports.SKY_ROTATE = exports.SKY_QUERY_RESPONSE = exports.SKY_QUERY = exports.SKY_EVENT = exports.SKY_INTRO_RESPONSE = exports.SKY_INTRO = exports.SKY_NS = void 0;
|
|
5
5
|
exports.parseSkyIntroBody = parseSkyIntroBody;
|
|
6
6
|
exports.parseSkyIntroResponseBody = parseSkyIntroResponseBody;
|
|
7
7
|
exports.skyIntroToWranglerAttrs = skyIntroToWranglerAttrs;
|
|
8
8
|
exports.skyIntroResponseToWranglerAttrs = skyIntroResponseToWranglerAttrs;
|
|
9
|
+
exports.parseSkyRotateBody = parseSkyRotateBody;
|
|
10
|
+
exports.skyRotateToWranglerAttrs = skyRotateToWranglerAttrs;
|
|
9
11
|
exports.parseSkyEventBody = parseSkyEventBody;
|
|
10
12
|
exports.parseSkyQueryBody = parseSkyQueryBody;
|
|
11
13
|
exports.SKY_NS = "https://picolabs.org/sky/1.0";
|
|
@@ -14,6 +16,7 @@ exports.SKY_INTRO_RESPONSE = `${exports.SKY_NS}/intro-response`;
|
|
|
14
16
|
exports.SKY_EVENT = `${exports.SKY_NS}/event`;
|
|
15
17
|
exports.SKY_QUERY = `${exports.SKY_NS}/query`;
|
|
16
18
|
exports.SKY_QUERY_RESPONSE = `${exports.SKY_NS}/query-response`;
|
|
19
|
+
exports.SKY_ROTATE = `${exports.SKY_NS}/rotate`;
|
|
17
20
|
function parseSkyIntroBody(body) {
|
|
18
21
|
if (!body || typeof body !== "object") {
|
|
19
22
|
throw new Error("Invalid SKY intro body");
|
|
@@ -67,6 +70,28 @@ function skyIntroToWranglerAttrs(intro, extras = {}) {
|
|
|
67
70
|
function skyIntroResponseToWranglerAttrs(response, extras = {}) {
|
|
68
71
|
return Object.assign({ layer2: true, status: response.status, subscription_id: response.subscription_id, peer_did_long: response.peer_did_long, Tx_did: response.peer_did_long, Tx_host: response.Tx_host || null, reason: response.reason, detail: response.detail }, extras);
|
|
69
72
|
}
|
|
73
|
+
function parseSkyRotateBody(body) {
|
|
74
|
+
if (!body || typeof body !== "object") {
|
|
75
|
+
throw new Error("Invalid SKY rotate body");
|
|
76
|
+
}
|
|
77
|
+
const b = body;
|
|
78
|
+
if (typeof b.prior_webvh_did !== "string" ||
|
|
79
|
+
typeof b.new_webvh_did !== "string") {
|
|
80
|
+
throw new Error("SKY rotate body missing prior_webvh_did or new_webvh_did");
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
sky_version: String(b.sky_version || "1.0"),
|
|
84
|
+
prior_webvh_did: b.prior_webvh_did,
|
|
85
|
+
new_webvh_did: b.new_webvh_did,
|
|
86
|
+
new_tx_host: typeof b.new_tx_host === "string" ? b.new_tx_host : undefined,
|
|
87
|
+
new_didcomm_endpoint: typeof b.new_didcomm_endpoint === "string"
|
|
88
|
+
? b.new_didcomm_endpoint
|
|
89
|
+
: undefined,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function skyRotateToWranglerAttrs(rotate, extras = {}) {
|
|
93
|
+
return Object.assign({ prior_webvh_did: rotate.prior_webvh_did, new_webvh_did: rotate.new_webvh_did, new_tx_host: rotate.new_tx_host, new_didcomm_endpoint: rotate.new_didcomm_endpoint }, extras);
|
|
94
|
+
}
|
|
70
95
|
function parseSkyEventBody(body) {
|
|
71
96
|
if (!body || typeof body !== "object") {
|
|
72
97
|
throw new Error("Invalid SKY event body");
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DIDComm SKY rotation notices for portable did:webvh move (Phase D).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.notifyPeersOfWebvhRotation = notifyPeersOfWebvhRotation;
|
|
7
|
+
exports.handleSkyRotateAtIngress = handleSkyRotateAtIngress;
|
|
8
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const establishSubscription_1 = require("./establishSubscription");
|
|
11
|
+
const crossPico_1 = require("./crossPico");
|
|
12
|
+
const skyProtocol_1 = require("./skyProtocol");
|
|
13
|
+
const veramoDidComm_1 = require("./veramoDidComm");
|
|
14
|
+
function findPico(pf, picoId) {
|
|
15
|
+
return pf.loadedPicos().find((p) => p.id === picoId);
|
|
16
|
+
}
|
|
17
|
+
async function resolveDidcommEndpointForDid(identity, did, remoteDidcommEndpoint) {
|
|
18
|
+
if (remoteDidcommEndpoint) {
|
|
19
|
+
return remoteDidcommEndpoint;
|
|
20
|
+
}
|
|
21
|
+
const doc = await identity.resolveDid("", did);
|
|
22
|
+
return (0, crossPico_1.extractDidcommEndpoint)(doc);
|
|
23
|
+
}
|
|
24
|
+
async function postJwe(endpoint, jwe) {
|
|
25
|
+
const res = await (0, cross_fetch_1.default)(endpoint, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: { "Content-Type": "application/didcomm-encrypted+json" },
|
|
28
|
+
body: jwe,
|
|
29
|
+
});
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
const detail = await res.text();
|
|
32
|
+
throw new errors_1.IdentityError(`DIDComm POST failed: HTTP ${res.status} ${detail}`, res.status);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function deliverRotateNotice(deps, fromPicoId, toPeerDid, remoteWebvhDid, remoteDidcommEndpoint, body, fromPrior) {
|
|
36
|
+
const fromWebvh = await deps.store.getWebvhDid(fromPicoId);
|
|
37
|
+
const sub = (await deps.store.listPeerSubscriptions(fromPicoId)).find((s) => s.remotePeerDid === toPeerDid || s.remoteDid === toPeerDid);
|
|
38
|
+
const fromPeer = sub === null || sub === void 0 ? void 0 : sub.peerDid;
|
|
39
|
+
if (!fromPeer) {
|
|
40
|
+
throw new errors_1.IdentityError(`No local peer DID for subscription to ${toPeerDid}`, 404);
|
|
41
|
+
}
|
|
42
|
+
const message = Object.assign({ id: `rotate-${Date.now()}`, typ: "application/didcomm-plain+json", type: skyProtocol_1.SKY_ROTATE, from: fromPeer, to: [toPeerDid], body, created_time: Math.floor(Date.now() / 1000) }, (fromPrior ? { from_prior: fromPrior } : {}));
|
|
43
|
+
const packed = await (0, veramoDidComm_1.packDidCommMessage)(fromPicoId, message, fromPeer, toPeerDid, deps.store, { resolveDid: (did) => deps.identity.resolveDid("", did) });
|
|
44
|
+
const endpoint = await resolveDidcommEndpointForDid(deps.identity, remoteWebvhDid || toPeerDid, remoteDidcommEndpoint);
|
|
45
|
+
await postJwe(endpoint, packed);
|
|
46
|
+
}
|
|
47
|
+
/** Notify established peers that this pico's did:webvh location changed. */
|
|
48
|
+
async function notifyPeersOfWebvhRotation(deps, picoId, relocation) {
|
|
49
|
+
const baseUrl = deps.getBaseUrl().replace(/\/$/, "");
|
|
50
|
+
const body = {
|
|
51
|
+
sky_version: "1.0",
|
|
52
|
+
prior_webvh_did: relocation.priorDid,
|
|
53
|
+
new_webvh_did: relocation.newDid,
|
|
54
|
+
new_tx_host: baseUrl,
|
|
55
|
+
new_didcomm_endpoint: relocation.didcommEndpoint,
|
|
56
|
+
};
|
|
57
|
+
const subs = await deps.store.listPeerSubscriptions(picoId);
|
|
58
|
+
let sent = 0;
|
|
59
|
+
for (const sub of subs) {
|
|
60
|
+
const remotePeer = sub.remotePeerDid || sub.remoteDid;
|
|
61
|
+
if (!remotePeer) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
await deliverRotateNotice(deps, picoId, remotePeer, sub.remoteWebvhDid, sub.remoteDidcommEndpoint, body, relocation.priorDid !== relocation.newDid ? relocation.priorDid : undefined);
|
|
66
|
+
sent += 1;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
70
|
+
console.warn(`[portable-move] SKY rotate to ${remotePeer} failed (import continues): ${msg}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return sent;
|
|
74
|
+
}
|
|
75
|
+
/** Apply a SKY rotate message on the recipient pico. */
|
|
76
|
+
async function handleSkyRotateAtIngress(deps, recipientPicoId, message) {
|
|
77
|
+
const senderDid = message.from;
|
|
78
|
+
if (!senderDid) {
|
|
79
|
+
throw new errors_1.IdentityError("SKY rotate missing from", 400);
|
|
80
|
+
}
|
|
81
|
+
const rotate = (0, skyProtocol_1.parseSkyRotateBody)(message.body);
|
|
82
|
+
const sub = await deps.store.findPeerSubscriptionBySenderDid(recipientPicoId, senderDid);
|
|
83
|
+
if (!sub) {
|
|
84
|
+
throw new errors_1.IdentityError("unknown_subscription", 404);
|
|
85
|
+
}
|
|
86
|
+
await (0, establishSubscription_1.linkRemotePeer)(deps.store, recipientPicoId, sub.subscriptionId, {
|
|
87
|
+
remotePeerDid: senderDid,
|
|
88
|
+
remoteWebvhDid: rotate.new_webvh_did,
|
|
89
|
+
remoteTxHost: rotate.new_tx_host,
|
|
90
|
+
remoteDidcommEndpoint: rotate.new_didcomm_endpoint,
|
|
91
|
+
});
|
|
92
|
+
const pending = (await deps.store.getPendingRotations(recipientPicoId)) || [];
|
|
93
|
+
pending.push({
|
|
94
|
+
priorDid: rotate.prior_webvh_did,
|
|
95
|
+
newDid: rotate.new_webvh_did,
|
|
96
|
+
peerDid: senderDid,
|
|
97
|
+
subscriptionId: sub.subscriptionId,
|
|
98
|
+
receivedAt: new Date().toISOString(),
|
|
99
|
+
});
|
|
100
|
+
await deps.store.putPendingRotations(recipientPicoId, pending);
|
|
101
|
+
const pico = findPico(deps.pf, recipientPicoId);
|
|
102
|
+
if (pico) {
|
|
103
|
+
await pico.event({
|
|
104
|
+
eci: pico.id,
|
|
105
|
+
domain: "wrangler",
|
|
106
|
+
name: "webvh_peer_rotated",
|
|
107
|
+
data: {
|
|
108
|
+
attrs: (0, skyProtocol_1.skyRotateToWranglerAttrs)(rotate, {
|
|
109
|
+
Id: sub.subscriptionId,
|
|
110
|
+
peer_did: senderDid,
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
time: Date.now(),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
status: "ok",
|
|
118
|
+
subscriptionId: sub.subscriptionId,
|
|
119
|
+
new_webvh_did: rotate.new_webvh_did,
|
|
120
|
+
};
|
|
121
|
+
}
|
package/dist/identity/store.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IdentityStore = exports.IDENTITY_PREFIX = void 0;
|
|
4
4
|
exports.migrateFromDidO = migrateFromDidO;
|
|
5
5
|
const dbHelpers_1 = require("./dbHelpers");
|
|
6
|
+
const peerDid4_1 = require("./peerDid4");
|
|
6
7
|
exports.IDENTITY_PREFIX = "pico-identity";
|
|
7
8
|
const FIELD = {
|
|
8
9
|
webvhDid: "webvhDid",
|
|
@@ -212,11 +213,14 @@ exports.IdentityStore = IdentityStore;
|
|
|
212
213
|
async function migrateFromDidO(_picoId) {
|
|
213
214
|
return;
|
|
214
215
|
}
|
|
215
|
-
/** Match did:peer short/long forms (numalgo 0/2). */
|
|
216
|
+
/** Match did:peer short/long forms (numalgo 0/2/4). */
|
|
216
217
|
function peerDidMatches(stored, incoming) {
|
|
217
218
|
if (stored === incoming) {
|
|
218
219
|
return true;
|
|
219
220
|
}
|
|
221
|
+
if (stored.startsWith("did:peer:4") || incoming.startsWith("did:peer:4")) {
|
|
222
|
+
return (0, peerDid4_1.peerDid4Matches)(stored, incoming);
|
|
223
|
+
}
|
|
220
224
|
const storedShort = peerDidShortForm(stored);
|
|
221
225
|
const incomingShort = peerDidShortForm(incoming);
|
|
222
226
|
return storedShort.length > 0 && storedShort === incomingShort;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Keep wrangler subscription ent buses aligned with engine identity store after import.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.syncLayer2EstablishedFromIdentity = syncLayer2EstablishedFromIdentity;
|
|
7
|
+
const SUBSCRIPTION_RID = "io.picolabs.subscription";
|
|
8
|
+
function busId(bus) {
|
|
9
|
+
const id = bus["Id"];
|
|
10
|
+
return typeof id === "string" ? id : undefined;
|
|
11
|
+
}
|
|
12
|
+
function mergeIdentityIntoBus(bus, rec) {
|
|
13
|
+
const out = Object.assign(Object.assign({}, bus), { layer2: true });
|
|
14
|
+
if (rec.rxEci) {
|
|
15
|
+
out["Rx"] = rec.rxEci;
|
|
16
|
+
}
|
|
17
|
+
if (rec.peerDid) {
|
|
18
|
+
out["Rx_did"] = rec.peerDid;
|
|
19
|
+
}
|
|
20
|
+
if (rec.remotePeerDid || rec.remoteDid) {
|
|
21
|
+
out["Tx_did"] =
|
|
22
|
+
out["Tx_did"] || rec.remoteWebvhDid || rec.remotePeerDid || rec.remoteDid;
|
|
23
|
+
}
|
|
24
|
+
if (rec.remoteWebvhDid) {
|
|
25
|
+
out["Tx_did"] = rec.remoteWebvhDid;
|
|
26
|
+
}
|
|
27
|
+
if (rec.remoteTxHost) {
|
|
28
|
+
out["Tx_host"] = rec.remoteTxHost;
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function findBusInPools(id, pools) {
|
|
33
|
+
return pools.find((b) => busId(b) === id);
|
|
34
|
+
}
|
|
35
|
+
/** Merge identity peer subscriptions into ent:established (Layer 2 DID relationships). */
|
|
36
|
+
async function syncLayer2EstablishedFromIdentity(store, pf, picoId) {
|
|
37
|
+
const pico = pf.getPico(picoId);
|
|
38
|
+
if (!(pico === null || pico === void 0 ? void 0 : pico.rulesets[SUBSCRIPTION_RID])) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const peerSubs = await store.listPeerSubscriptions(picoId);
|
|
42
|
+
if (peerSubs.length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const establishedRaw = await pico.getEnt(SUBSCRIPTION_RID, "established");
|
|
46
|
+
let list = Array.isArray(establishedRaw)
|
|
47
|
+
? establishedRaw.map((b) => b && typeof b === "object" ? Object.assign({}, b) : {})
|
|
48
|
+
: [];
|
|
49
|
+
const inbound = await pico.getEnt(SUBSCRIPTION_RID, "inbound");
|
|
50
|
+
const outbound = await pico.getEnt(SUBSCRIPTION_RID, "outbound");
|
|
51
|
+
const pools = [
|
|
52
|
+
...(Array.isArray(inbound)
|
|
53
|
+
? inbound.filter((b) => b && typeof b === "object")
|
|
54
|
+
: []),
|
|
55
|
+
...(Array.isArray(outbound)
|
|
56
|
+
? outbound.filter((b) => b && typeof b === "object")
|
|
57
|
+
: []),
|
|
58
|
+
];
|
|
59
|
+
for (const rec of peerSubs) {
|
|
60
|
+
const id = rec.subscriptionId;
|
|
61
|
+
let idx = list.findIndex((b) => busId(b) === id);
|
|
62
|
+
if (idx >= 0) {
|
|
63
|
+
list[idx] = mergeIdentityIntoBus(list[idx], rec);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const fromPool = findBusInPools(id, pools);
|
|
67
|
+
if (fromPool || rec.remotePeerDid || rec.remoteWebvhDid) {
|
|
68
|
+
list.push(mergeIdentityIntoBus(fromPool || { Id: id }, rec));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
await pico.putEnt(SUBSCRIPTION_RID, "established", list);
|
|
72
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.exportVeramoKeysForDid = exportVeramoKeysForDid;
|
|
4
|
+
exports.createPeerDid2WithKeys = createPeerDid2WithKeys;
|
|
4
5
|
exports.createPeerDidWithKeys = createPeerDidWithKeys;
|
|
5
6
|
exports.createPeerDid = createPeerDid;
|
|
6
7
|
exports.warmPeerDidsForPico = warmPeerDidsForPico;
|
|
@@ -10,6 +11,8 @@ exports.unpackDidCommMessage = unpackDidCommMessage;
|
|
|
10
11
|
exports.resetVeramoAgentForTests = resetVeramoAgentForTests;
|
|
11
12
|
const errors_1 = require("./errors");
|
|
12
13
|
const peerDid_1 = require("./peerDid");
|
|
14
|
+
const peerDid4_1 = require("./peerDid4");
|
|
15
|
+
const peerDid4Create_1 = require("./peerDid4Create");
|
|
13
16
|
const webvhCrypto_1 = require("./webvhCrypto");
|
|
14
17
|
const webvh_1 = require("./webvh");
|
|
15
18
|
let agentBundle;
|
|
@@ -52,6 +55,32 @@ async function createAgentBundle() {
|
|
|
52
55
|
const { DIDResolverPlugin } = require("@veramo/did-resolver");
|
|
53
56
|
const { PeerDIDProvider, getResolver: getPeerResolver } = require("@veramo/did-provider-peer");
|
|
54
57
|
const { Resolver } = require("did-resolver");
|
|
58
|
+
const basePeerResolver = getPeerResolver();
|
|
59
|
+
const peerResolver = Object.assign(Object.assign({}, basePeerResolver), { peer: async (did, parsed, resolver, options) => {
|
|
60
|
+
if ((0, peerDid4_1.isPeerDid4)(did)) {
|
|
61
|
+
try {
|
|
62
|
+
const didDocument = (0, peerDid4_1.resolvePeerDid4)(did);
|
|
63
|
+
return {
|
|
64
|
+
didDocument,
|
|
65
|
+
didDocumentMetadata: {},
|
|
66
|
+
didResolutionMetadata: {
|
|
67
|
+
contentType: "application/did+ld+json",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
return {
|
|
73
|
+
didDocument: null,
|
|
74
|
+
didDocumentMetadata: {},
|
|
75
|
+
didResolutionMetadata: {
|
|
76
|
+
error: "invalidDid",
|
|
77
|
+
message: err.message,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return basePeerResolver.peer(did, parsed, resolver, options);
|
|
83
|
+
} });
|
|
55
84
|
const privateKeyStore = new MemoryPrivateKeyStore();
|
|
56
85
|
const agent = createAgent({
|
|
57
86
|
plugins: [
|
|
@@ -67,7 +96,7 @@ async function createAgentBundle() {
|
|
|
67
96
|
},
|
|
68
97
|
}),
|
|
69
98
|
new DIDResolverPlugin({
|
|
70
|
-
resolver: new Resolver(Object.assign(Object.assign({},
|
|
99
|
+
resolver: new Resolver(Object.assign(Object.assign({}, peerResolver), webvhResolverMethods())),
|
|
71
100
|
}),
|
|
72
101
|
new DIDComm(),
|
|
73
102
|
],
|
|
@@ -90,7 +119,7 @@ async function exportVeramoKeysForDid(identity, privateKeyStore) {
|
|
|
90
119
|
return keys;
|
|
91
120
|
}
|
|
92
121
|
/** Create a did:peer (num_algo 2) and export key material for persistence. */
|
|
93
|
-
async function
|
|
122
|
+
async function createPeerDid2WithKeys() {
|
|
94
123
|
const { agent, privateKeyStore } = await getAgentBundle();
|
|
95
124
|
const identity = await agent.didManagerCreate({
|
|
96
125
|
provider: "did:peer",
|
|
@@ -102,6 +131,16 @@ async function createPeerDidWithKeys() {
|
|
|
102
131
|
keys: { veramoKeys },
|
|
103
132
|
};
|
|
104
133
|
}
|
|
134
|
+
/** Create a did:peer:4 (long form) and export key material for persistence. */
|
|
135
|
+
async function createPeerDidWithKeys() {
|
|
136
|
+
const created = (0, peerDid4Create_1.createPeerDid4WithKeys)();
|
|
137
|
+
await getAgentBundle();
|
|
138
|
+
await importPeerDidOnAgent(created.did, created.keys.veramoKeys);
|
|
139
|
+
return {
|
|
140
|
+
did: created.did,
|
|
141
|
+
keys: created.keys,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
105
144
|
/** @deprecated Prefer createPeerDidWithKeys — returns DID only. */
|
|
106
145
|
async function createPeerDid() {
|
|
107
146
|
const { did } = await createPeerDidWithKeys();
|