pico-engine 1.4.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.
Files changed (82) hide show
  1. package/README.md +188 -0
  2. package/dist/RulesetRegistryLoaderFs.js +2 -0
  3. package/dist/auth/AuthService.js +601 -0
  4. package/dist/auth/index.js +8 -0
  5. package/dist/auth/webauthn.js +97 -0
  6. package/dist/bundledKrl.js +42 -0
  7. package/dist/cli.js +11 -0
  8. package/dist/identity/IdentityService.js +340 -0
  9. package/dist/identity/crossPico.js +238 -0
  10. package/dist/identity/dbHelpers.js +67 -0
  11. package/dist/identity/didcommIngressRoutes.js +44 -0
  12. package/dist/identity/didoModule.js +252 -0
  13. package/dist/identity/errors.js +11 -0
  14. package/dist/identity/establishSubscription.js +97 -0
  15. package/dist/identity/index.js +15 -0
  16. package/dist/identity/peerDid.js +9 -0
  17. package/dist/identity/skyIntro.js +194 -0
  18. package/dist/identity/skyProtocol.js +105 -0
  19. package/dist/identity/store.js +233 -0
  20. package/dist/identity/types.js +13 -0
  21. package/dist/identity/veramoDidComm.js +260 -0
  22. package/dist/identity/webvh.js +266 -0
  23. package/dist/identity/webvhCrypto.js +128 -0
  24. package/dist/identity/webvhRoutes.js +61 -0
  25. package/dist/index.js +100 -44
  26. package/dist/oauth/OAuthService.js +388 -0
  27. package/dist/oauth/acg.js +495 -0
  28. package/dist/oauth/channelEligibility.js +26 -0
  29. package/dist/oauth/errors.js +12 -0
  30. package/dist/oauth/index.js +21 -0
  31. package/dist/oauth/krlModule.js +27 -0
  32. package/dist/oauth/meshOAuth.js +43 -0
  33. package/dist/provisionRoot.js +118 -0
  34. package/dist/server.js +609 -15
  35. package/dist/uiChannelPolicies.js +48 -0
  36. package/krl/io.picolabs.did-o.krl +5 -1
  37. package/krl/io.picolabs.oauth.krl +48 -0
  38. package/krl/io.picolabs.pico-engine-ui.krl +106 -18
  39. package/krl/io.picolabs.subscription.krl +242 -23
  40. package/krl/io.picolabs.wrangler.krl +225 -16
  41. package/package.json +38 -9
  42. package/public/docs/krl/_sidebar.md +1 -0
  43. package/public/docs/krl/discovery.md +144 -0
  44. package/public/docs/krl/modules/ctx.md +8 -0
  45. package/public/docs/krl/modules/event.md +41 -0
  46. package/public/pico-engine-ui.css +1 -1
  47. package/public/pico-engine-ui.js +24 -20
  48. package/public/pico-labs-logo.png +0 -0
  49. package/src/RulesetRegistryLoaderFs.ts +2 -0
  50. package/src/auth/AuthService.ts +850 -0
  51. package/src/auth/index.ts +17 -0
  52. package/src/auth/webauthn.ts +182 -0
  53. package/src/bundledKrl.ts +42 -0
  54. package/src/cli.ts +11 -0
  55. package/src/identity/IdentityService.ts +571 -0
  56. package/src/identity/crossPico.ts +371 -0
  57. package/src/identity/dbHelpers.ts +51 -0
  58. package/src/identity/didcommIngressRoutes.ts +54 -0
  59. package/src/identity/didoModule.ts +388 -0
  60. package/src/identity/errors.ts +8 -0
  61. package/src/identity/establishSubscription.ts +160 -0
  62. package/src/identity/index.ts +24 -0
  63. package/src/identity/peerDid.ts +22 -0
  64. package/src/identity/skyIntro.ts +321 -0
  65. package/src/identity/skyProtocol.ts +192 -0
  66. package/src/identity/store.ts +343 -0
  67. package/src/identity/types.ts +63 -0
  68. package/src/identity/veramoDidComm.ts +363 -0
  69. package/src/identity/webvh.ts +325 -0
  70. package/src/identity/webvhCrypto.ts +200 -0
  71. package/src/identity/webvhRoutes.ts +64 -0
  72. package/src/index.ts +145 -53
  73. package/src/oauth/OAuthService.ts +510 -0
  74. package/src/oauth/acg.ts +666 -0
  75. package/src/oauth/channelEligibility.ts +26 -0
  76. package/src/oauth/errors.ts +10 -0
  77. package/src/oauth/index.ts +14 -0
  78. package/src/oauth/krlModule.ts +31 -0
  79. package/src/oauth/meshOAuth.ts +50 -0
  80. package/src/provisionRoot.ts +151 -0
  81. package/src/server.ts +700 -24
  82. package/src/uiChannelPolicies.ts +49 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uiECIForRoot = uiECIForRoot;
4
+ exports.uiECIForPico = uiECIForPico;
5
+ exports.refreshAllUiChannelPolicies = refreshAllUiChannelPolicies;
6
+ exports.provisionRoot = provisionRoot;
7
+ const path = require("path");
8
+ const uiChannelPolicies_1 = require("./uiChannelPolicies");
9
+ const toFileUrl_1 = require("./utils/toFileUrl");
10
+ const bundledKrl_1 = require("./bundledKrl");
11
+ /**
12
+ * Base rulesets installed onto every root pico. These make up the engine's
13
+ * "OS" layer (wrangler + friends) plus the built-in UI ruleset.
14
+ */
15
+ const BASE_KRL_FILES = [...bundledKrl_1.BUNDLED_KRL_FILES];
16
+ function uiChannelKey(tags) {
17
+ return tags.slice(0).sort().join(",");
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
+ };
24
+ /**
25
+ * Find the ["engine","ui"] channel on a pico, if it exists.
26
+ */
27
+ function uiECIForRoot(pf, rootPicoId) {
28
+ const pico = pf.rootPicos().find((p) => p.id === rootPicoId);
29
+ if (!pico) {
30
+ return null;
31
+ }
32
+ return uiECIForPico(pico);
33
+ }
34
+ function uiECIForPico(pico) {
35
+ const chann = pico
36
+ .toReadOnly()
37
+ .channels.find((c) => uiChannelKey([...uiChannelPolicies_1.UI_CHANNEL_TAGS]) === uiChannelKey(c.tags));
38
+ return chann ? chann.id : null;
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
+ }
60
+ /**
61
+ * Provision a root pico: install the base rulesets, ensure the ["engine","ui"]
62
+ * channel exists, fire `engine_ui setup`, and return the root + its UI ECI.
63
+ *
64
+ * Pass an existing `root` to (re)provision it — this is how the engine migrates
65
+ * a pre-existing single-root install. Omit it to mint a brand new root, which is
66
+ * what the passkey new-account registration flow does.
67
+ */
68
+ async function provisionRoot(pf, core, opts = {}) {
69
+ const root = opts.root || (await pf.createRootPico());
70
+ for (const file of BASE_KRL_FILES) {
71
+ const url = (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", file));
72
+ const { ruleset } = await core.rsRegistry.flush(url);
73
+ await root.install(ruleset, { url, config: {} });
74
+ }
75
+ let uiChannel = root
76
+ .toReadOnly()
77
+ .channels.find((c) => uiChannelKey([...uiChannelPolicies_1.UI_CHANNEL_TAGS]) === uiChannelKey(c.tags));
78
+ if (!uiChannel) {
79
+ uiChannel = (await root.newChannel({
80
+ tags: [...uiChannelPolicies_1.UI_CHANNEL_TAGS],
81
+ eventPolicy: {
82
+ allow: [{ domain: "engine_ui", name: "setup" }],
83
+ deny: [],
84
+ },
85
+ })).toReadOnly();
86
+ }
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
+ }
100
+ const name = (opts.name || "").trim();
101
+ if (name) {
102
+ await pf.eventWait({
103
+ eci: uiChannel.id,
104
+ domain: "engine_ui",
105
+ name: "box",
106
+ data: { attrs: { name } },
107
+ time: 0,
108
+ });
109
+ }
110
+ await pf.eventWait({
111
+ eci: uiChannel.id,
112
+ domain: "engine_ui",
113
+ name: "setup",
114
+ data: { attrs: {} },
115
+ time: 0,
116
+ });
117
+ return { root, uiECI: uiChannel.id };
118
+ }