pico-engine 1.5.0 → 1.6.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 +41 -0
- package/dist/RulesetRegistryLoaderFs.js +2 -0
- package/dist/auth/AuthService.js +77 -13
- package/dist/bundledKrl.js +42 -0
- package/dist/identity/IdentityService.js +340 -0
- package/dist/identity/crossPico.js +238 -0
- package/dist/identity/dbHelpers.js +67 -0
- package/dist/identity/didcommIngressRoutes.js +44 -0
- package/dist/identity/didoModule.js +252 -0
- package/dist/identity/errors.js +11 -0
- package/dist/identity/establishSubscription.js +97 -0
- package/dist/identity/index.js +15 -0
- package/dist/identity/peerDid.js +9 -0
- package/dist/identity/skyIntro.js +194 -0
- package/dist/identity/skyProtocol.js +105 -0
- package/dist/identity/store.js +233 -0
- package/dist/identity/types.js +13 -0
- package/dist/identity/veramoDidComm.js +260 -0
- package/dist/identity/webvh.js +266 -0
- package/dist/identity/webvhCrypto.js +128 -0
- package/dist/identity/webvhRoutes.js +61 -0
- package/dist/index.js +26 -2
- package/dist/oauth/OAuthService.js +32 -0
- package/dist/provisionRoot.js +56 -18
- package/dist/server.js +52 -1
- package/dist/uiChannelPolicies.js +48 -0
- package/krl/io.picolabs.did-o.krl +5 -1
- package/krl/io.picolabs.pico-engine-ui.krl +106 -18
- package/krl/io.picolabs.subscription.krl +242 -23
- package/krl/io.picolabs.wrangler.krl +221 -12
- package/package.json +29 -6
- package/public/docs/krl/_sidebar.md +1 -0
- package/public/docs/krl/discovery.md +144 -0
- package/public/docs/krl/modules/ctx.md +8 -0
- package/public/docs/krl/modules/event.md +41 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +21 -18
- package/src/RulesetRegistryLoaderFs.ts +2 -0
- package/src/auth/AuthService.ts +109 -14
- package/src/bundledKrl.ts +42 -0
- package/src/identity/IdentityService.ts +571 -0
- package/src/identity/crossPico.ts +371 -0
- package/src/identity/dbHelpers.ts +51 -0
- package/src/identity/didcommIngressRoutes.ts +54 -0
- package/src/identity/didoModule.ts +388 -0
- package/src/identity/errors.ts +8 -0
- package/src/identity/establishSubscription.ts +160 -0
- package/src/identity/index.ts +24 -0
- package/src/identity/peerDid.ts +22 -0
- package/src/identity/skyIntro.ts +321 -0
- package/src/identity/skyProtocol.ts +192 -0
- package/src/identity/store.ts +343 -0
- package/src/identity/types.ts +63 -0
- package/src/identity/veramoDidComm.ts +363 -0
- package/src/identity/webvh.ts +325 -0
- package/src/identity/webvhCrypto.ts +200 -0
- package/src/identity/webvhRoutes.ts +64 -0
- package/src/index.ts +31 -2
- package/src/oauth/OAuthService.ts +36 -0
- package/src/provisionRoot.ts +75 -21
- package/src/server.ts +58 -1
- package/src/uiChannelPolicies.ts +49 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerWebvhRoutes = registerWebvhRoutes;
|
|
4
|
+
const webvh_1 = require("./webvh");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
function registerWebvhRoutes(app, identity) {
|
|
7
|
+
app.get("/identity/resolve", async (req, res) => {
|
|
8
|
+
try {
|
|
9
|
+
const did = String(req.query.did || "").trim();
|
|
10
|
+
if (!did) {
|
|
11
|
+
res.status(400).json({ error: "Missing did query parameter" });
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const doc = await identity.resolveDid("", did);
|
|
15
|
+
res.json({ did, didDocument: doc });
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
sendIdentityError(res, err);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
app.get("/picos/:picoId/did.jsonl", async (req, res) => {
|
|
22
|
+
try {
|
|
23
|
+
const picoId = decodeURIComponent(req.params.picoId);
|
|
24
|
+
const jsonl = await identity.getWebvhLogJsonl(picoId);
|
|
25
|
+
if (!jsonl) {
|
|
26
|
+
res.status(404).send("Not found");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const log = jsonl
|
|
30
|
+
.trim()
|
|
31
|
+
.split("\n")
|
|
32
|
+
.map((line) => JSON.parse(line));
|
|
33
|
+
await (0, webvh_1.resolveLocalWebvhLog)(log);
|
|
34
|
+
res.type("application/jsonld+json").send(jsonl);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
sendIdentityError(res, err);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
app.get("/picos/:picoId/did.json", async (req, res) => {
|
|
41
|
+
try {
|
|
42
|
+
const picoId = decodeURIComponent(req.params.picoId);
|
|
43
|
+
const doc = await identity.getParallelWebDoc(picoId);
|
|
44
|
+
if (!doc) {
|
|
45
|
+
res.status(404).send("Not found");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
res.json(doc);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
sendIdentityError(res, err);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function sendIdentityError(res, err) {
|
|
56
|
+
if (err instanceof errors_1.IdentityError) {
|
|
57
|
+
res.status(err.statusCode).json({ error: err.message });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
res.status(500).json({ error: err.message || "Internal error" });
|
|
61
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const makeDir = require("make-dir");
|
|
|
8
8
|
const path = require("path");
|
|
9
9
|
const pico_engine_core_1 = require("pico-engine-core");
|
|
10
10
|
const auth_1 = require("./auth");
|
|
11
|
+
const identity_1 = require("./identity");
|
|
11
12
|
const oauth_1 = require("./oauth");
|
|
12
13
|
const logging_1 = require("./logging");
|
|
13
14
|
const provisionRoot_1 = require("./provisionRoot");
|
|
@@ -52,9 +53,22 @@ async function startEngine(configuration = {}) {
|
|
|
52
53
|
return (0, logging_1.getPicoLogs)(logFilePath, picoId);
|
|
53
54
|
},
|
|
54
55
|
});
|
|
56
|
+
const pf = core.picoFramework;
|
|
57
|
+
const identity = new identity_1.IdentityStore({ db: pf.db });
|
|
58
|
+
let identityService;
|
|
59
|
+
identityService = new identity_1.IdentityService({
|
|
60
|
+
store: identity,
|
|
61
|
+
getBaseUrl: () => core.base_url || base_url || "",
|
|
62
|
+
pf,
|
|
63
|
+
});
|
|
64
|
+
core.onPicoCreated = async (picoId, ctx) => {
|
|
65
|
+
if (core.base_url) {
|
|
66
|
+
await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
core.modules["dido"] = (0, identity_1.initDidoModule)(identityService);
|
|
55
70
|
await core.start();
|
|
56
71
|
const rsRegistry = core.rsRegistry;
|
|
57
|
-
const pf = core.picoFramework;
|
|
58
72
|
// Fresh engines boot with zero roots. Adopt + (re)provision only when roots
|
|
59
73
|
// already exist (test harness with autoCreateRootPico, or a migrated DB).
|
|
60
74
|
let uiECI = null;
|
|
@@ -71,8 +85,15 @@ async function startEngine(configuration = {}) {
|
|
|
71
85
|
rpName: configuration.rpName,
|
|
72
86
|
origin: configuration.origin,
|
|
73
87
|
allowSelfSignup: (_b = configuration.allowSelfSignup) !== null && _b !== void 0 ? _b : false,
|
|
88
|
+
flushBootstrapUrl: async (url) => {
|
|
89
|
+
const flushed = await rsRegistry.flush(url);
|
|
90
|
+
return { rid: flushed.rid };
|
|
91
|
+
},
|
|
74
92
|
provisionRoot: async (opts) => {
|
|
75
93
|
const { root, uiECI } = await (0, provisionRoot_1.provisionRoot)(pf, core, opts);
|
|
94
|
+
if (core.base_url) {
|
|
95
|
+
await identityService.ensureWebvhDid(root.id, { isRoot: true });
|
|
96
|
+
}
|
|
76
97
|
return { rootPicoId: root.id, uiECI };
|
|
77
98
|
},
|
|
78
99
|
getUiECI: (rootPicoId) => (0, provisionRoot_1.uiECIForRoot)(pf, rootPicoId),
|
|
@@ -103,7 +124,7 @@ async function startEngine(configuration = {}) {
|
|
|
103
124
|
pf,
|
|
104
125
|
});
|
|
105
126
|
core.modules["oauth"] = (0, oauth_1.initOAuthModule)(oauth);
|
|
106
|
-
const app = (0, server_1.server)(core, uiECI, auth, oauth);
|
|
127
|
+
const app = (0, server_1.server)(core, uiECI, auth, oauth, identityService);
|
|
107
128
|
if ((!port || !_.isInteger(port) || port < 1) && port !== 0) {
|
|
108
129
|
port = process.env.NODE_ENV === "test" ? 0 : 3000;
|
|
109
130
|
}
|
|
@@ -123,6 +144,7 @@ async function startEngine(configuration = {}) {
|
|
|
123
144
|
base_url = `http://localhost:${port}`;
|
|
124
145
|
}
|
|
125
146
|
core.base_url = base_url;
|
|
147
|
+
await identityService.ensureWebvhForAllLoadedPicos();
|
|
126
148
|
log.info(`Listening at ${base_url}`);
|
|
127
149
|
if (uiECI) {
|
|
128
150
|
pf.event({
|
|
@@ -145,5 +167,7 @@ async function startEngine(configuration = {}) {
|
|
|
145
167
|
rsRegistry,
|
|
146
168
|
auth,
|
|
147
169
|
oauth,
|
|
170
|
+
identity,
|
|
171
|
+
identityService,
|
|
148
172
|
};
|
|
149
173
|
}
|
|
@@ -168,6 +168,16 @@ class OAuthService {
|
|
|
168
168
|
return response;
|
|
169
169
|
}
|
|
170
170
|
async skyRequiresBearer(eci) {
|
|
171
|
+
try {
|
|
172
|
+
const channel = this.lookupChannelReadOnly(eci);
|
|
173
|
+
if (channel.tags.includes("didcomm") &&
|
|
174
|
+
channel.tags.includes("ingress")) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (_e) {
|
|
179
|
+
// channel not found — fall through
|
|
180
|
+
}
|
|
171
181
|
if (await this.channelRequiresBearer(eci)) {
|
|
172
182
|
return true;
|
|
173
183
|
}
|
|
@@ -176,6 +186,28 @@ class OAuthService {
|
|
|
176
186
|
async validateBearerToken(token, channelEci) {
|
|
177
187
|
return this.validateSkyBearerToken(token, channelEci);
|
|
178
188
|
}
|
|
189
|
+
/** Mesh-wide OAuth token (authorization_code grant) → root pico id. */
|
|
190
|
+
async resolveMeshBearerToken(token) {
|
|
191
|
+
const trimmed = (token || "").trim();
|
|
192
|
+
if (!trimmed) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const record = await this.getTokenRecord(trimmed);
|
|
196
|
+
if (!record) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
if (record.expiresAt !== 0 && record.expiresAt < Date.now()) {
|
|
200
|
+
await this.deps.db.del([OAUTH_TOKEN_PREFIX, trimmed]);
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
if ((record.grant || "client_credentials") !== "authorization_code") {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
if (!record.rootPicoId) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return { rootPicoId: record.rootPicoId, scope: record.scope };
|
|
210
|
+
}
|
|
179
211
|
async validateSkyBearerToken(token, channelEci) {
|
|
180
212
|
const trimmed = (token || "").trim();
|
|
181
213
|
if (!trimmed || !channelEci) {
|
package/dist/provisionRoot.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uiECIForRoot = uiECIForRoot;
|
|
4
|
+
exports.uiECIForPico = uiECIForPico;
|
|
5
|
+
exports.refreshAllUiChannelPolicies = refreshAllUiChannelPolicies;
|
|
4
6
|
exports.provisionRoot = provisionRoot;
|
|
5
7
|
const path = require("path");
|
|
8
|
+
const uiChannelPolicies_1 = require("./uiChannelPolicies");
|
|
6
9
|
const toFileUrl_1 = require("./utils/toFileUrl");
|
|
10
|
+
const bundledKrl_1 = require("./bundledKrl");
|
|
7
11
|
/**
|
|
8
12
|
* Base rulesets installed onto every root pico. These make up the engine's
|
|
9
13
|
* "OS" layer (wrangler + friends) plus the built-in UI ruleset.
|
|
10
14
|
*/
|
|
11
|
-
const BASE_KRL_FILES = [
|
|
12
|
-
"io.picolabs.pico-engine-ui.krl",
|
|
13
|
-
"io.picolabs.wrangler.krl",
|
|
14
|
-
"io.picolabs.subscription.krl",
|
|
15
|
-
"io.picolabs.did-o.krl",
|
|
16
|
-
"io.picolabs.pds.krl",
|
|
17
|
-
];
|
|
18
|
-
const UI_CHANNEL_TAGS = ["engine", "ui"];
|
|
15
|
+
const BASE_KRL_FILES = [...bundledKrl_1.BUNDLED_KRL_FILES];
|
|
19
16
|
function uiChannelKey(tags) {
|
|
20
17
|
return tags.slice(0).sort().join(",");
|
|
21
18
|
}
|
|
19
|
+
const UI_CHANNEL_CONFIG = {
|
|
20
|
+
tags: [...uiChannelPolicies_1.UI_CHANNEL_TAGS],
|
|
21
|
+
eventPolicy: uiChannelPolicies_1.UI_CHANNEL_EVENT_POLICY,
|
|
22
|
+
queryPolicy: uiChannelPolicies_1.UI_CHANNEL_QUERY_POLICY,
|
|
23
|
+
};
|
|
22
24
|
/**
|
|
23
25
|
* Find the ["engine","ui"] channel on a pico, if it exists.
|
|
24
26
|
*/
|
|
@@ -27,11 +29,34 @@ function uiECIForRoot(pf, rootPicoId) {
|
|
|
27
29
|
if (!pico) {
|
|
28
30
|
return null;
|
|
29
31
|
}
|
|
32
|
+
return uiECIForPico(pico);
|
|
33
|
+
}
|
|
34
|
+
function uiECIForPico(pico) {
|
|
30
35
|
const chann = pico
|
|
31
36
|
.toReadOnly()
|
|
32
|
-
.channels.find((c) => uiChannelKey(UI_CHANNEL_TAGS) === uiChannelKey(c.tags));
|
|
37
|
+
.channels.find((c) => uiChannelKey([...uiChannelPolicies_1.UI_CHANNEL_TAGS]) === uiChannelKey(c.tags));
|
|
33
38
|
return chann ? chann.id : null;
|
|
34
39
|
}
|
|
40
|
+
async function forEachLoadedPico(pf, fn) {
|
|
41
|
+
for (const pico of pf.loadedPicos()) {
|
|
42
|
+
await fn(pico);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Install the current io.picolabs.pico-engine-ui ruleset on every pico and
|
|
47
|
+
* refresh its ["engine","ui"] channel policy directly (no event policy gate).
|
|
48
|
+
*/
|
|
49
|
+
async function refreshAllUiChannelPolicies(pf, core) {
|
|
50
|
+
const uiUrl = (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", "io.picolabs.pico-engine-ui.krl"));
|
|
51
|
+
const { ruleset: uiRuleset } = await core.rsRegistry.flush(uiUrl);
|
|
52
|
+
await forEachLoadedPico(pf, async (pico) => {
|
|
53
|
+
await pico.install(uiRuleset, { url: uiUrl, config: {} });
|
|
54
|
+
const uiEci = uiECIForPico(pico);
|
|
55
|
+
if (uiEci) {
|
|
56
|
+
await pico.putChannel(uiEci, UI_CHANNEL_CONFIG);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
35
60
|
/**
|
|
36
61
|
* Provision a root pico: install the base rulesets, ensure the ["engine","ui"]
|
|
37
62
|
* channel exists, fire `engine_ui setup`, and return the root + its UI ECI.
|
|
@@ -49,23 +74,29 @@ async function provisionRoot(pf, core, opts = {}) {
|
|
|
49
74
|
}
|
|
50
75
|
let uiChannel = root
|
|
51
76
|
.toReadOnly()
|
|
52
|
-
.channels.find((c) => uiChannelKey(UI_CHANNEL_TAGS) === uiChannelKey(c.tags));
|
|
77
|
+
.channels.find((c) => uiChannelKey([...uiChannelPolicies_1.UI_CHANNEL_TAGS]) === uiChannelKey(c.tags));
|
|
53
78
|
if (!uiChannel) {
|
|
54
79
|
uiChannel = (await root.newChannel({
|
|
55
|
-
tags: UI_CHANNEL_TAGS,
|
|
80
|
+
tags: [...uiChannelPolicies_1.UI_CHANNEL_TAGS],
|
|
56
81
|
eventPolicy: {
|
|
57
82
|
allow: [{ domain: "engine_ui", name: "setup" }],
|
|
58
83
|
deny: [],
|
|
59
84
|
},
|
|
60
85
|
})).toReadOnly();
|
|
61
86
|
}
|
|
62
|
-
await pf
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
await refreshAllUiChannelPolicies(pf, core);
|
|
88
|
+
const bootstrapUrl = (opts.bootstrapUrl || "").trim();
|
|
89
|
+
if (bootstrapUrl) {
|
|
90
|
+
// Same path as the Rulesets tab: engine_ui install → wrangler
|
|
91
|
+
// install_ruleset_request → ruleset_installed (bootstrap rulesets depend on this).
|
|
92
|
+
await pf.eventWait({
|
|
93
|
+
eci: uiChannel.id,
|
|
94
|
+
domain: "engine_ui",
|
|
95
|
+
name: "install",
|
|
96
|
+
data: { attrs: { url: bootstrapUrl, config: {} } },
|
|
97
|
+
time: 0,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
69
100
|
const name = (opts.name || "").trim();
|
|
70
101
|
if (name) {
|
|
71
102
|
await pf.eventWait({
|
|
@@ -76,5 +107,12 @@ async function provisionRoot(pf, core, opts = {}) {
|
|
|
76
107
|
time: 0,
|
|
77
108
|
});
|
|
78
109
|
}
|
|
110
|
+
await pf.eventWait({
|
|
111
|
+
eci: uiChannel.id,
|
|
112
|
+
domain: "engine_ui",
|
|
113
|
+
name: "setup",
|
|
114
|
+
data: { attrs: {} },
|
|
115
|
+
time: 0,
|
|
116
|
+
});
|
|
79
117
|
return { root, uiECI: uiChannel.id };
|
|
80
118
|
}
|
package/dist/server.js
CHANGED
|
@@ -8,6 +8,9 @@ const _ = require("lodash");
|
|
|
8
8
|
const path = require("path");
|
|
9
9
|
const auth_1 = require("./auth");
|
|
10
10
|
const oauth_1 = require("./oauth");
|
|
11
|
+
const provisionRoot_1 = require("./provisionRoot");
|
|
12
|
+
const webvhRoutes_1 = require("./identity/webvhRoutes");
|
|
13
|
+
const didcommIngressRoutes_1 = require("./identity/didcommIngressRoutes");
|
|
11
14
|
const engineVersion = require("../package.json").version;
|
|
12
15
|
const SESSION_COOKIE = "pico-session";
|
|
13
16
|
const CEREMONY_COOKIE = "pico-ceremony";
|
|
@@ -55,7 +58,7 @@ function isLocalhostRequest(req) {
|
|
|
55
58
|
const host = req.headers.host || "";
|
|
56
59
|
return host.startsWith("localhost:") || host.startsWith("127.0.0.1:");
|
|
57
60
|
}
|
|
58
|
-
function server(core, uiECI, auth, oauth) {
|
|
61
|
+
function server(core, uiECI, auth, oauth, identity) {
|
|
59
62
|
const pf = core.picoFramework;
|
|
60
63
|
const app = express();
|
|
61
64
|
app.use(function (req, res, next) {
|
|
@@ -97,11 +100,15 @@ function server(core, uiECI, auth, oauth) {
|
|
|
97
100
|
return defaultHelmet(req, res, next);
|
|
98
101
|
});
|
|
99
102
|
app.use(express.static(path.resolve(__dirname, "..", "public")));
|
|
103
|
+
if (identity) {
|
|
104
|
+
(0, webvhRoutes_1.registerWebvhRoutes)(app, identity);
|
|
105
|
+
}
|
|
100
106
|
app.use(bodyParser.json({
|
|
101
107
|
type: [
|
|
102
108
|
"application/json",
|
|
103
109
|
"application/octet-stream",
|
|
104
110
|
"application/ssi-agent-wire",
|
|
111
|
+
"application/didcomm-encrypted+json",
|
|
105
112
|
],
|
|
106
113
|
}));
|
|
107
114
|
app.use(bodyParser.urlencoded({
|
|
@@ -109,6 +116,9 @@ function server(core, uiECI, auth, oauth) {
|
|
|
109
116
|
type: "application/x-www-form-urlencoded",
|
|
110
117
|
extended: false,
|
|
111
118
|
}));
|
|
119
|
+
if (identity) {
|
|
120
|
+
(0, didcommIngressRoutes_1.registerDidcommIngressRoutes)(app, identity);
|
|
121
|
+
}
|
|
112
122
|
if (auth) {
|
|
113
123
|
registerAuthRoutes(app, auth);
|
|
114
124
|
}
|
|
@@ -202,6 +212,46 @@ function server(core, uiECI, auth, oauth) {
|
|
|
202
212
|
if (oauth) {
|
|
203
213
|
registerOAuthRoutes(app, oauth, auth, requireAuthSession, parseCookies);
|
|
204
214
|
}
|
|
215
|
+
app.get("/api/mesh-context", function (req, res, next) {
|
|
216
|
+
if (!oauth) {
|
|
217
|
+
res.status(503).json({ error: "OAuth not enabled" });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const header = req.headers.authorization;
|
|
221
|
+
if (typeof header !== "string" || !header.startsWith("Bearer ")) {
|
|
222
|
+
res.status(401).json({ error: "Bearer token required" });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const token = header.slice("Bearer ".length).trim();
|
|
226
|
+
oauth
|
|
227
|
+
.resolveMeshBearerToken(token)
|
|
228
|
+
.then((ctx) => {
|
|
229
|
+
if (!ctx) {
|
|
230
|
+
res.status(401).json({ error: "Invalid or expired token" });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const rootUiEci = (0, provisionRoot_1.uiECIForRoot)(pf, ctx.rootPicoId);
|
|
234
|
+
if (!rootUiEci) {
|
|
235
|
+
res.status(503).json({ error: "Mesh UI channel not found" });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let baseUrl = core.base_url;
|
|
239
|
+
if (!baseUrl) {
|
|
240
|
+
baseUrl = `${req.protocol}://${req.get("host") || "localhost"}`;
|
|
241
|
+
}
|
|
242
|
+
baseUrl = baseUrl.replace(/\/$/, "");
|
|
243
|
+
res.json({
|
|
244
|
+
baseUrl,
|
|
245
|
+
rootUiEci,
|
|
246
|
+
oauth: {
|
|
247
|
+
authorize: `${baseUrl}/oauth/authorize`,
|
|
248
|
+
token: `${baseUrl}/oauth/token`,
|
|
249
|
+
},
|
|
250
|
+
scope: ctx.scope,
|
|
251
|
+
});
|
|
252
|
+
})
|
|
253
|
+
.catch(next);
|
|
254
|
+
});
|
|
205
255
|
app.get("/api/ui-context", function (req, res, next) {
|
|
206
256
|
const hasRoots = pf.rootPicos().length > 0;
|
|
207
257
|
const base = {
|
|
@@ -609,6 +659,7 @@ function registerAuthRoutes(app, auth) {
|
|
|
609
659
|
.createInvite({
|
|
610
660
|
createdByAccountId: session.accountId,
|
|
611
661
|
label: req.body && req.body.label,
|
|
662
|
+
bootstrapUrl: req.body && req.body.bootstrapUrl,
|
|
612
663
|
})
|
|
613
664
|
.then((invite) => res.json(invite))
|
|
614
665
|
.catch(next);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UI_CHANNEL_TAGS = exports.UI_CHANNEL_QUERY_POLICY = exports.UI_CHANNEL_EVENT_POLICY = void 0;
|
|
4
|
+
/** Keep in sync with uiChannelEventPolicy() in io.picolabs.pico-engine-ui.krl */
|
|
5
|
+
exports.UI_CHANNEL_EVENT_POLICY = {
|
|
6
|
+
allow: [
|
|
7
|
+
{ domain: "engine_ui", name: "setup" },
|
|
8
|
+
{ domain: "engine_ui", name: "box" },
|
|
9
|
+
{ domain: "engine_ui", name: "new" },
|
|
10
|
+
{ domain: "engine_ui", name: "del" },
|
|
11
|
+
{ domain: "engine_ui", name: "install" },
|
|
12
|
+
{ domain: "engine_ui", name: "uninstall" },
|
|
13
|
+
{ domain: "engine_ui", name: "flush" },
|
|
14
|
+
{ domain: "engine_ui", name: "new_channel" },
|
|
15
|
+
{ domain: "engine_ui", name: "del_channel" },
|
|
16
|
+
{ domain: "engine_ui", name: "update_channel" },
|
|
17
|
+
{ domain: "engine_ui", name: "testing_eci" },
|
|
18
|
+
{ domain: "engine", name: "started" },
|
|
19
|
+
{ domain: "wrangler", name: "subscription" },
|
|
20
|
+
{ domain: "wrangler", name: "pending_subscription_approval" },
|
|
21
|
+
{ domain: "wrangler", name: "inbound_rejection" },
|
|
22
|
+
{ domain: "wrangler", name: "outbound_cancellation" },
|
|
23
|
+
{ domain: "wrangler", name: "subscription_cancellation" },
|
|
24
|
+
{ domain: "wrangler", name: "set_public_intro" },
|
|
25
|
+
{ domain: "wrangler", name: "send_event_on_subs" },
|
|
26
|
+
],
|
|
27
|
+
deny: [],
|
|
28
|
+
};
|
|
29
|
+
/** Keep in sync with uiChannelQueryPolicy() in io.picolabs.pico-engine-ui.krl */
|
|
30
|
+
exports.UI_CHANNEL_QUERY_POLICY = {
|
|
31
|
+
allow: [
|
|
32
|
+
{ rid: "*", name: "__testing" },
|
|
33
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "uiECI" },
|
|
34
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "box" },
|
|
35
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "pico" },
|
|
36
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "logs" },
|
|
37
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "testingECI" },
|
|
38
|
+
{ rid: "io.picolabs.pico-engine-ui", name: "name" },
|
|
39
|
+
{ rid: "io.picolabs.subscription", name: "established" },
|
|
40
|
+
{ rid: "io.picolabs.subscription", name: "inbound" },
|
|
41
|
+
{ rid: "io.picolabs.subscription", name: "outbound" },
|
|
42
|
+
{ rid: "io.picolabs.subscription", name: "wellKnown_Rx" },
|
|
43
|
+
{ rid: "io.picolabs.wrangler", name: "myDid" },
|
|
44
|
+
{ rid: "io.picolabs.wrangler", name: "publicIntro" },
|
|
45
|
+
],
|
|
46
|
+
deny: [],
|
|
47
|
+
};
|
|
48
|
+
exports.UI_CHANNEL_TAGS = ["engine", "ui"];
|
|
@@ -20,7 +20,11 @@ DID-O V 1.0.0
|
|
|
20
20
|
name "did-o"
|
|
21
21
|
description
|
|
22
22
|
<<
|
|
23
|
-
|
|
23
|
+
DEPRECATED (pico-engine 1.6+): Layer 2 identity folds DIDComm routing into the
|
|
24
|
+
engine dido module and wrangler core. Do not install on new picos. Use
|
|
25
|
+
wrangler:myDid(), event:send({did: ...}), and wrangler:picoQuery with DID targets instead.
|
|
26
|
+
|
|
27
|
+
Legacy ruleset for DIDComm v2 communication using picos (did:peer:2 era).
|
|
24
28
|
>>
|
|
25
29
|
author "Rembrand Paul Pardo, Kekoapoaono Montalbo, Josh Mann"
|
|
26
30
|
|
|
@@ -3,7 +3,7 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
3
3
|
version "0.0.0"
|
|
4
4
|
name "pico-engine-ui"
|
|
5
5
|
description "This is the only ruleset the pico-engine-ui.js needs to operate"
|
|
6
|
-
shares box, uiECI, pico, logs, testingECI, name
|
|
6
|
+
shares box, uiECI, pico, logs, testingECI, name, needsStartupLayout
|
|
7
7
|
}
|
|
8
8
|
global {
|
|
9
9
|
uiECI = function(){
|
|
@@ -29,6 +29,9 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
29
29
|
name = function(){
|
|
30
30
|
ent:name || "Pico"
|
|
31
31
|
}
|
|
32
|
+
needsStartupLayout = function(){
|
|
33
|
+
ent:x.isnull() && ent:y.isnull()
|
|
34
|
+
}
|
|
32
35
|
box = function(){
|
|
33
36
|
return {
|
|
34
37
|
"eci": uiECI(),
|
|
@@ -124,12 +127,8 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
124
127
|
})
|
|
125
128
|
.reverse()
|
|
126
129
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
select when engine_ui setup
|
|
130
|
-
ctx:upsertChannel(
|
|
131
|
-
tags = ["engine", "ui"],
|
|
132
|
-
eventPolicy = {
|
|
130
|
+
uiChannelEventPolicy = function() {
|
|
131
|
+
{
|
|
133
132
|
"allow": [
|
|
134
133
|
{ "domain": "engine_ui", "name": "setup" },
|
|
135
134
|
{ "domain": "engine_ui", "name": "box" },
|
|
@@ -140,17 +139,22 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
140
139
|
{ "domain": "engine_ui", "name": "flush" },
|
|
141
140
|
{ "domain": "engine_ui", "name": "new_channel" },
|
|
142
141
|
{ "domain": "engine_ui", "name": "del_channel" },
|
|
142
|
+
{ "domain": "engine_ui", "name": "update_channel" },
|
|
143
143
|
{ "domain": "engine_ui", "name": "testing_eci" },
|
|
144
144
|
{ "domain": "engine", "name": "started" },
|
|
145
145
|
{ "domain": "wrangler", "name": "subscription" },
|
|
146
146
|
{ "domain": "wrangler", "name": "pending_subscription_approval" },
|
|
147
147
|
{ "domain": "wrangler", "name": "inbound_rejection" },
|
|
148
148
|
{ "domain": "wrangler", "name": "outbound_cancellation" },
|
|
149
|
-
{ "domain": "wrangler", "name": "subscription_cancellation" }
|
|
149
|
+
{ "domain": "wrangler", "name": "subscription_cancellation" },
|
|
150
|
+
{ "domain": "wrangler", "name": "set_public_intro" },
|
|
151
|
+
{ "domain": "wrangler", "name": "send_event_on_subs" }
|
|
150
152
|
],
|
|
151
153
|
"deny": []
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
uiChannelQueryPolicy = function() {
|
|
157
|
+
{
|
|
154
158
|
"allow": [
|
|
155
159
|
{ "rid": "*", "name": "__testing" },
|
|
156
160
|
{ "rid": "io.picolabs.pico-engine-ui", "name": "uiECI" },
|
|
@@ -162,11 +166,28 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
162
166
|
{ "rid": "io.picolabs.subscription", "name": "established" },
|
|
163
167
|
{ "rid": "io.picolabs.subscription", "name": "inbound" },
|
|
164
168
|
{ "rid": "io.picolabs.subscription", "name": "outbound" },
|
|
165
|
-
{ "rid": "io.picolabs.subscription", "name": "wellKnown_Rx" }
|
|
169
|
+
{ "rid": "io.picolabs.subscription", "name": "wellKnown_Rx" },
|
|
170
|
+
{ "rid": "io.picolabs.wrangler", "name": "myDid" },
|
|
171
|
+
{ "rid": "io.picolabs.wrangler", "name": "publicIntro" }
|
|
166
172
|
],
|
|
167
173
|
"deny": []
|
|
168
174
|
}
|
|
169
|
-
|
|
175
|
+
}
|
|
176
|
+
childPalette = [
|
|
177
|
+
"#FFB347", "#77DD77", "#B19CD9", "#FF6961", "#FDFD96",
|
|
178
|
+
"#84B6F4", "#FFD1DC", "#C9A0DC", "#98FB98", "#E6E6FA"
|
|
179
|
+
]
|
|
180
|
+
refreshUiChannel = defaction() {
|
|
181
|
+
ctx:upsertChannel(
|
|
182
|
+
tags = ["engine", "ui"],
|
|
183
|
+
eventPolicy = uiChannelEventPolicy(),
|
|
184
|
+
queryPolicy = uiChannelQueryPolicy()
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
rule setup {
|
|
189
|
+
select when engine_ui setup
|
|
190
|
+
refreshUiChannel()
|
|
170
191
|
}
|
|
171
192
|
rule box {
|
|
172
193
|
select when engine_ui box
|
|
@@ -177,10 +198,10 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
177
198
|
}
|
|
178
199
|
}
|
|
179
200
|
always {
|
|
180
|
-
ent:x := event:attrs{"x"}.as("Number") if event:attrs{"x"}
|
|
181
|
-
ent:y := event:attrs{"y"}.as("Number") if event:attrs{"y"}
|
|
182
|
-
ent:width := event:attrs{"width"}.as("Number") if event:attrs{"width"}
|
|
183
|
-
ent:height := event:attrs{"height"}.as("Number") if event:attrs{"height"}
|
|
201
|
+
ent:x := event:attrs{"x"}.as("Number") if not event:attrs{"x"}.isnull()
|
|
202
|
+
ent:y := event:attrs{"y"}.as("Number") if not event:attrs{"y"}.isnull()
|
|
203
|
+
ent:width := event:attrs{"width"}.as("Number") if not event:attrs{"width"}.isnull()
|
|
204
|
+
ent:height := event:attrs{"height"}.as("Number") if not event:attrs{"height"}.isnull()
|
|
184
205
|
ent:name := event:attrs{"name"}.as("String") if event:attrs{"name"}
|
|
185
206
|
ent:backgroundColor := event:attrs{"backgroundColor"}.validateColor() if event:attrs{"backgroundColor"}
|
|
186
207
|
ent:parent_ui_eci := event:attrs{"parentUiEci"} if event:attrs{"parentUiEci"}
|
|
@@ -191,12 +212,61 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
191
212
|
pre {
|
|
192
213
|
uiEci = event:attr("uiEci")
|
|
193
214
|
familyEci = event:attr("eci")
|
|
215
|
+
childIndex = ent:child_ui_ecis.defaultsTo({}).keys().length()
|
|
216
|
+
gridCol = childIndex % 4
|
|
217
|
+
gridRow = (childIndex - childIndex % 4) / 4
|
|
218
|
+
layoutX = ent:x.defaultsTo(100) + 48 + gridCol * 118
|
|
219
|
+
layoutY = ent:y.defaultsTo(100) + 48 + gridRow * 98
|
|
220
|
+
layoutColor = childPalette[childIndex % childPalette.length]
|
|
194
221
|
}
|
|
195
|
-
if uiEci && familyEci then
|
|
222
|
+
if uiEci && familyEci then
|
|
223
|
+
ctx:event(
|
|
224
|
+
eci=uiEci,
|
|
225
|
+
domain="engine_ui",
|
|
226
|
+
name="box",
|
|
227
|
+
attrs={
|
|
228
|
+
"x": layoutX,
|
|
229
|
+
"y": layoutY,
|
|
230
|
+
"width": 100,
|
|
231
|
+
"height": 100,
|
|
232
|
+
"backgroundColor": layoutColor,
|
|
233
|
+
"parentUiEci": uiECI()
|
|
234
|
+
}
|
|
235
|
+
)
|
|
196
236
|
always {
|
|
197
237
|
ent:child_ui_ecis{[familyEci]} := uiEci
|
|
198
238
|
}
|
|
199
239
|
}
|
|
240
|
+
rule spread_children_on_startup {
|
|
241
|
+
select when engine started
|
|
242
|
+
foreach ent:child_ui_ecis.defaultsTo({}).keys() setting(familyEci)
|
|
243
|
+
pre {
|
|
244
|
+
uiEci = ent:child_ui_ecis{familyEci}
|
|
245
|
+
childKeys = ent:child_ui_ecis.defaultsTo({}).keys()
|
|
246
|
+
childIndex = childKeys.index(familyEci)
|
|
247
|
+
originX = ent:x.defaultsTo(100)
|
|
248
|
+
originY = ent:y.defaultsTo(100)
|
|
249
|
+
gridCol = childIndex % 4
|
|
250
|
+
gridRow = (childIndex - childIndex % 4) / 4
|
|
251
|
+
layoutX = originX + 48 + gridCol * 118
|
|
252
|
+
layoutY = originY + 48 + gridRow * 98
|
|
253
|
+
layoutColor = childPalette[childIndex % childPalette.length]
|
|
254
|
+
}
|
|
255
|
+
if uiEci && ctx:query(uiEci, ctx:rid, "needsStartupLayout") then
|
|
256
|
+
ctx:event(
|
|
257
|
+
eci=uiEci,
|
|
258
|
+
domain="engine_ui",
|
|
259
|
+
name="box",
|
|
260
|
+
attrs={
|
|
261
|
+
"x": layoutX,
|
|
262
|
+
"y": layoutY,
|
|
263
|
+
"width": 100,
|
|
264
|
+
"height": 100,
|
|
265
|
+
"backgroundColor": layoutColor,
|
|
266
|
+
"parentUiEci": uiECI()
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
}
|
|
200
270
|
rule backfill_child_ui_eci {
|
|
201
271
|
select when engine started
|
|
202
272
|
foreach ctx:children setting(familyEci)
|
|
@@ -251,18 +321,36 @@ ruleset io.picolabs.pico-engine-ui {
|
|
|
251
321
|
select when engine_ui flush
|
|
252
322
|
ctx:flush(url=event:attrs{"url"})
|
|
253
323
|
}
|
|
324
|
+
rule refresh_ui_channel_after_flush {
|
|
325
|
+
select when engine_ui flush
|
|
326
|
+
pre {
|
|
327
|
+
url = event:attrs{"url"} || ""
|
|
328
|
+
self_flush = url.match(re#io\.picolabs\.pico-engine-ui#)
|
|
329
|
+
}
|
|
330
|
+
if self_flush then refreshUiChannel()
|
|
331
|
+
}
|
|
254
332
|
rule new_channel {
|
|
255
333
|
select when engine_ui new_channel
|
|
256
334
|
ctx:newChannel(
|
|
257
335
|
tags=event:attrs{"tags"},
|
|
258
336
|
eventPolicy=event:attrs{"eventPolicy"},
|
|
259
|
-
queryPolicy=event:attrs{"queryPolicy"}
|
|
337
|
+
queryPolicy=event:attrs{"queryPolicy"},
|
|
338
|
+
id=event:attrs{"id"}
|
|
260
339
|
)
|
|
261
340
|
}
|
|
262
341
|
rule del_channel {
|
|
263
342
|
select when engine_ui del_channel
|
|
264
343
|
ctx:delChannel(event:attrs{"eci"})
|
|
265
344
|
}
|
|
345
|
+
rule update_channel {
|
|
346
|
+
select when engine_ui update_channel
|
|
347
|
+
ctx:putChannel(
|
|
348
|
+
eci=event:attrs{"eci"},
|
|
349
|
+
tags=event:attrs{"tags"},
|
|
350
|
+
eventPolicy=event:attrs{"eventPolicy"},
|
|
351
|
+
queryPolicy=event:attrs{"queryPolicy"}
|
|
352
|
+
)
|
|
353
|
+
}
|
|
266
354
|
rule testing_eci {
|
|
267
355
|
select when engine_ui testing_eci
|
|
268
356
|
always {
|