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,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
- Ruleset for DIDComm v2 Communication Using Picos
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
 
@@ -0,0 +1,48 @@
1
+ ruleset io.picolabs.oauth {
2
+ meta {
3
+ name "OAuth Mesh"
4
+ description <<
5
+ Optional mesh-level OAuth. Install on the root pico to require Bearer tokens on external /sky/*
6
+ for this mesh, and to hold per-mesh OAuth configuration (apps, consent policy, defaults).
7
+ Webhook Client Credentials (per channel) and app Authorization Code grants coexist here.
8
+ Not installed by default.
9
+
10
+ use module io.picolabs.oauth alias oauth
11
+ >>
12
+ author "PICOLABS"
13
+
14
+ provides meshEnabled, meshRequiresOAuth,
15
+ channelStatus, createChannelSecret, revokeChannelSecret, revokeTokens
16
+
17
+ shares meshEnabled, meshRequiresOAuth,
18
+ channelStatus, createChannelSecret, revokeChannelSecret, revokeTokens
19
+ }
20
+
21
+ global {
22
+ /** True when this ruleset is installed on the pico (mesh OAuth opt-in marker). */
23
+ meshEnabled = function() {
24
+ true
25
+ }
26
+
27
+ /** True when external /sky/* for eci requires a Bearer token (mesh lock or oauth-webhook tag). */
28
+ meshRequiresOAuth = function(eci) {
29
+ oauth:meshRequiresOAuth(eci)
30
+ }
31
+
32
+ channelStatus = function(eci) {
33
+ oauth:channelStatus(eci)
34
+ }
35
+
36
+ createChannelSecret = function(eci) {
37
+ oauth:createChannelSecret(eci)
38
+ }
39
+
40
+ revokeChannelSecret = function(eci) {
41
+ oauth:revokeChannelSecret(eci)
42
+ }
43
+
44
+ revokeTokens = function(eci) {
45
+ oauth:revokeTokens(eci)
46
+ }
47
+ }
48
+ }
@@ -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
- rule setup {
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
- queryPolicy = {
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 noop()
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 {