pico-engine 1.2.0 → 1.3.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 CHANGED
@@ -40,6 +40,8 @@ pico-engine uses [leveldb](http://leveldb.org) to store data. It's a C++ library
40
40
 
41
41
  Open command prompt as Administrator then run `npm install --global --production windows-build-tools` That will configure python and c++ compiler for npm.
42
42
 
43
+ We have had reports that the `pico-engine` command stops working with earlier versions of `node.js`, so update to the latest version.
44
+
43
45
  **Mac / Linux**
44
46
 
45
47
  Be sure you have python 2.7 installed. If python 3 is the system default, all you need to do is configure npm to use python 2.7 like so `npm config set python /path/to/executable/python2.7`
package/dist/cli.js CHANGED
@@ -20,7 +20,7 @@ USAGE
20
20
 
21
21
  Environment Variables:
22
22
 
23
- PORT - The port the http server should listen on. By default it's 8080
23
+ PORT - The port the http server should listen on. By default it's 3000
24
24
  PICO_ENGINE_HOME - Where the database and other files should be stored. By default it's ~/.pico-engine/
25
25
  PICO_ENGINE_BASE_URL - The public url prefix to reach this engine. By default it's http://localhost:$PORT
26
26
  `);
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@ async function startEngine(configuration = {}) {
42
42
  (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", "io.picolabs.pico-engine-ui.krl")),
43
43
  (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", "io.picolabs.wrangler.krl")),
44
44
  (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", "io.picolabs.subscription.krl")),
45
+ (0, toFileUrl_1.toFileUrl)(path.resolve(__dirname, "..", "krl", "io.picolabs.did-o.krl")),
45
46
  ];
46
47
  for (const url of krl_urls) {
47
48
  const { ruleset } = await rsRegistry.flush(url);
@@ -0,0 +1,325 @@
1
+ /*
2
+ DID-O V 1.0.0
3
+ ⠀⠀⠀⢠⡜⠛⠛⠿⣤⠀⠀⣤⡼⠿⠿⢧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
4
+ ⠀⣀⡶⠎⠁⠀⠀⠀⠉⠶⠶⠉⠁⠀⠀⠈⠹⢆⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
5
+ ⣀⡿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠶⠶⠶⠶⣆⡀⠀⠀⠀⠀
6
+ ⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢣⡄⠀⠀⠀
7
+ ⠛⣧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀
8
+ ⠀⠛⣧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⠀⠀⠀⠀⢠⡼⠃⠀⠀
9
+ ⠀⠀⠿⢇⡀⠀⠀⠀⠀⠀⠀⠀⠰⠶⠶⢆⣀⣀⣀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀
10
+ ⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀
11
+ ⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀
12
+ ⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢣⣤
13
+ ⠀⣶⡏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿
14
+ ⠀⠿⣇⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⠀⠀⠀⠀⢀⣀⣸⠿
15
+ ⠀⠀⠙⢳⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⡞⠛⠛⠛⠛⠛⠛⣶⣶⣶⣶⡞⠛⠃⠀
16
+ */
17
+
18
+ ruleset io.picolabs.did-o {
19
+ meta {
20
+ name "did-o"
21
+ description
22
+ <<
23
+ Ruleset for DIDComm v2 Communication Using Picos
24
+ >>
25
+ author "Rembrand Paul Pardo, Kekoapoaono Montalbo, Josh Mann"
26
+
27
+ provides addRoute, routes, send, sendEvent, sendQuery, didMap, clearDidMap, didDocs, clearDidDocs, pendingRotations, clearPendingRotations, generate_invitation
28
+
29
+ shares routes, addRoute, didDocs, clearDidDocs, didMap, clearDidMap, pendingRotations, clearPendingRotations, generate_invitation
30
+
31
+ use module io.picolabs.wrangler alias wrangler
32
+ }
33
+
34
+
35
+ global {
36
+ ///////////////////////////////////////////// ROUTING //////////////////////////////////////////////
37
+
38
+ /**
39
+ * Adds a route to the routes stored in the dido.ts library. The type should be a valid Protocol URI.
40
+ * The domain and name are the domain and name of the event that will be raised when a message of the specified type is received.
41
+ */
42
+ addRoute = function(type, _domain, name) {
43
+ dido:addRoute(type, _domain, name)
44
+ }
45
+
46
+ /**
47
+ * Queries the existing routes.
48
+ */
49
+ routes = function() {
50
+ ent:routes
51
+ }
52
+
53
+ /**
54
+ * Send a message to the specified DID. did is the recipient DID and message is a valid DIDComm v2 message.
55
+ */
56
+ send = function(did, message) {
57
+ dido:send(did, message)
58
+ }
59
+
60
+ /**
61
+ * Send an event to the specified DID. did is the recipient DID and the event is formatted as follows:
62
+ * event = {
63
+ * "domain": domain: string,
64
+ * "name": name: string,
65
+ * "attrs": attrs: {[name: string]: any}
66
+ * }
67
+ */
68
+ sendEvent = function(did, event) {
69
+ message = dido:generateMessage({
70
+ "type": "https://picolabs.io/event/1.0/event",
71
+ "from": ent:didMap{did},
72
+ "to": [did],
73
+ "body": event
74
+ })
75
+ dido:send(did, message)
76
+ }
77
+
78
+ /**
79
+ * Send a query to the specified DID. did is the recipient DID and the query is formatted as follows:
80
+ * query = {
81
+ * "rid": rid: string,
82
+ * "name": name: string,
83
+ * "args": args: {[name: string]: any}
84
+ * }
85
+ */
86
+ sendQuery = function(did, _query) {
87
+ message = dido:generateMessage({
88
+ "type": "https://picolabs.io/query/1.0/query",
89
+ "from": ent:didMap{did},
90
+ "to": [did],
91
+ "body": _query
92
+ })
93
+ dido:sendQuery(did, message)
94
+ }
95
+
96
+ ///////////////////////////////////////////// DID MANAGEMENT //////////////////////////////////////////////
97
+
98
+ /**
99
+ * Return the map of DID relationships stored in the pattern [ thier_did : your_did ].
100
+ */
101
+ didMap = function() {
102
+ ent:didMap
103
+ }
104
+
105
+ /**
106
+ * Clear the map of DID relationships.
107
+ */
108
+ clearDidMap = function() {
109
+ dido:clearDidMap()
110
+ }
111
+
112
+ /**
113
+ * Return all the DIDs and DIDDocs stored in the pattern [ did : diddoc ].
114
+ */
115
+ didDocs = function() {
116
+ ent:didDocs
117
+ }
118
+
119
+ /**
120
+ * Clear all the DIDs and DIDDocs.
121
+ */
122
+ clearDidDocs = function() {
123
+ dido:clearDidDocs()
124
+ }
125
+
126
+ /**
127
+ * Return all the pending rotations stored in the pattern [ new_did : from_prior ].
128
+ */
129
+ pendingRotations = function() {
130
+ ent:pendingRotations
131
+ }
132
+
133
+ /**
134
+ * Clear all the pending rotations.
135
+ */
136
+ clearPendingRotations = function() {
137
+ dido:clearPendingRotations()
138
+ }
139
+
140
+ ///////////////////////////////////////////// MESSAGE CREATORS //////////////////////////////////////////////
141
+
142
+ /**
143
+ * Creates an invitation OOB URL that can be used to establish DID based relationships.
144
+ * This automates the DID, channel, and message creation and encodes it into a base64 Out-of-Band URL.
145
+ */
146
+ generate_invitation = function() {
147
+ DIDdoc = dido:generateDID(true)
148
+ new_did = DIDdoc{"id"}
149
+ invitation = dido:generateMessage({
150
+ "type": "https://didcomm.org/out-of-band/2.0/invitation",
151
+ "from": new_did,
152
+ "body": {
153
+ "goal_code": "exchange-did",
154
+ "goal": "ExchangeDid",
155
+ "label": "PicoInvite",
156
+ "accept": [
157
+ "didcomm/v2"
158
+ ]
159
+ }
160
+ })
161
+ base64 = math:base64encode(invitation.encode())
162
+ dido:createInviteUrl(base64)
163
+ }
164
+
165
+ /**
166
+ * Creates a trust ping message according to the DIDComm v2 protocol and returns it. The to parameter is the DID of the recipient.
167
+ */
168
+ generate_trust_ping_message = function(to) {
169
+ dido:generateMessage({
170
+ "type": "https://didcomm.org/trust_ping/2.0/ping",
171
+ "from": ent:didMap{to},
172
+ "to": [to],
173
+ "body": {
174
+ "response_requested": true
175
+ }
176
+ })
177
+ }
178
+
179
+ /**
180
+ * Creates a trust ping response message according to the DIDComm v2 protocol and returns it.
181
+ * The thid parameter is the id of the ping that you are responding to, and the to parameter is the DID of the recipient.
182
+ */
183
+ generate_trust_ping_response = function(thid, to) {
184
+ dido:generateMessage({
185
+ "type": "https://didcomm.org/trust_ping/2.0/ping_response",
186
+ "thid": thid,
187
+ "from": ent:didMap{to},
188
+ "to": [to],
189
+ "body": {}
190
+ })
191
+ }
192
+ }
193
+
194
+ ///////////////////////////////////////////// INITIAILIZATION //////////////////////////////////////////////
195
+
196
+ /**
197
+ * The initialize rule subscribes to the wrangler:ruleset_installed event and is called when the ruleset is installed and initializes the routes.
198
+ */
199
+ rule intialize {
200
+ select when wrangler ruleset_installed where event:attrs{"rids"} >< meta:rid
201
+ pre {
202
+ ping = dido:addRoute("https://didcomm.org/trust_ping/2.0/ping", "dido", "receive_trust_ping")
203
+ ping_response = dido:addRoute("https://didcomm.org/trust_ping/2.0/ping_response", "dido", "receive_trust_ping_response")
204
+ }
205
+ }
206
+
207
+ /**
208
+ * The pico_root_created rule subscribes to the engine_ui:setup event and is called when the engine starts and initializes the routes.
209
+ * This is used in addition to the initialize rule to verify routes exist when a new engine is started.
210
+ */
211
+ rule pico_root_created {
212
+ select when engine_ui setup
213
+ if ent:routes.isnull() then noop()
214
+ fired {
215
+ ping = dido:addRoute("https://didcomm.org/trust_ping/2.0/ping", "dido", "receive_trust_ping")
216
+ ping_response = dido:addRoute("https://didcomm.org/trust_ping/2.0/ping_response", "dido", "receive_trust_ping_response")
217
+ }
218
+ }
219
+
220
+ ///////////////////////////////////////////// ROUTING //////////////////////////////////////////////
221
+
222
+ /**
223
+ * The route_message rule subscribes to the dido:didcommv2_message event. It calls the dido library,
224
+ * unpacks the message, and looks for the proper route based on the message type. It then raises the
225
+ * appropriate event and passes along the unpacked message.
226
+ */
227
+ rule route_message {
228
+ select when dido didcommv2_message
229
+ pre {
230
+ response = dido:route(event:attrs.delete("_headers"))
231
+ }
232
+ if response then send_directive("response", {}.put(response))
233
+ }
234
+
235
+ ///////////////////////////////////////////// INVITATIONS //////////////////////////////////////////////
236
+
237
+ /**
238
+ * The receive_invite rule subscribes to the dido:receive_invite event and receives an invite URL (example.com/invite?_oob=abc...123)
239
+ * from event:attrs{"invite"}. The invite URL is a base 64 encoded invite. The rule then creates a new DID and channel.
240
+ * After that, it raises the dido:send_trust_ping event.
241
+ */
242
+ rule receive_invite {
243
+ select when dido receive_invite
244
+ pre {
245
+ url = event:attrs{"invite"}
246
+ base64 = url.split("_oob=")[1]
247
+ invite = math:base64decode(base64).decode()
248
+ new_did = dido:generateDID()
249
+ didMap = dido:mapDid(invite{"from"}, new_did{"id"})
250
+ stored_doc = dido:storeDidDoc(invite{"from"})
251
+ }
252
+ fired {
253
+ raise dido event "send_trust_ping" attributes event:attrs.put("did", invite{"from"})
254
+ }
255
+ }
256
+
257
+ ///////////////////////////////////////////// TRUST PING //////////////////////////////////////////////
258
+
259
+ /**
260
+ * The send_trust_ping rule subscribes to the dido:send_trust_ping event and requires the DID of the recipient
261
+ * from event:attrs{"did"}. It then sends a generated trust ping message to the provided DID.
262
+ */
263
+ rule send_trust_ping {
264
+ select when dido send_trust_ping
265
+ pre {
266
+ their_did = event:attrs{"did"}
267
+ message = generate_trust_ping_message(their_did)
268
+ send = dido:send(their_did, message)
269
+ }
270
+ }
271
+
272
+ /**
273
+ * The receive_trust_ping rule subscibes to the did:receive_trust_ping event and requires the ping message from
274
+ * event:attrs{"message"}. It then checks if the message was received from an invite. If it was, it rotates the
275
+ * invite DID. Then it generates the response and sends it back.
276
+ */
277
+ rule receive_trust_ping {
278
+ select when dido receive_trust_ping
279
+ pre {
280
+ message = event:attrs{"message"}
281
+ their_did = message{"from"}
282
+ needsRotation = dido:rotateInviteDID(message{"to"}[0], message{"from"})
283
+ response = generate_trust_ping_response(message{"id"}, their_did)
284
+ send = dido:send(their_did, response)
285
+ }
286
+ }
287
+ }
288
+
289
+
290
+ /*
291
+ DID-O - V 1.0.0
292
+ ,--._
293
+ | `...
294
+ ,.-------" `.
295
+ / " `-.__
296
+ . " _, `._
297
+ | __..-" `.
298
+ | ''"' `._
299
+ | `"-.
300
+ ' `.
301
+ . |
302
+ / |
303
+ _,' ,'
304
+ ," /
305
+ . /
306
+ | /
307
+ | .
308
+ ' |
309
+ `. |
310
+ `. |
311
+ `. '
312
+ . .
313
+ | `.
314
+ ' |
315
+ ,' |
316
+ ,' '
317
+ / _...._ /
318
+ . ,-' `"'--'
319
+ | ,'
320
+ .' ,'
321
+ / _,....__ _,'
322
+ | ,.' `---'
323
+ '_ ,--`
324
+ `---'
325
+ */
@@ -88,10 +88,13 @@ ruleset io.picolabs.pico-engine-ui {
88
88
  };
89
89
  entryMap = function(a,e){
90
90
  // a.head() is array of entries; a[1] is whether last entry is eats
91
+ // a[2] is domain:name of the event
91
92
  eats = e{"msg"} == "event added to schedule"
92
- a[1] && eats
93
- => [a.head(),true] // omit an eats
94
- | [a.head().append(episode_line(e)),eats]
93
+ event_dt = eats => e{["event","domain"]} + ":" + e{["event","name"]}
94
+ | ""
95
+ a[1] && eats && a[2]==event_dt
96
+ => [a.head(),true,event_dt] // omit a duplicate eats
97
+ | [a.head().append(episode_line(e)),eats,event_dt]
95
98
  }
96
99
  episodes = ctx:logs()
97
100
  .collect(function(e){e.get("txnId")})
@@ -99,7 +102,7 @@ ruleset io.picolabs.pico-engine-ui {
99
102
  .map(function(k){
100
103
  episode = episodes.get(k)
101
104
  entries = episode
102
- .reduce(entryMap,[[],false]).head()
105
+ .reduce(entryMap,[[],false,""]).head()
103
106
  return {
104
107
  "txnId": k,
105
108
  "time": episode.head().get("time"),
@@ -108,8 +111,8 @@ ruleset io.picolabs.pico-engine-ui {
108
111
  }
109
112
  })
110
113
  .filter(function(g){
111
- g.header.match(re#^QUERY .*io.picolabs.pico-engine-ui/#) => false |
112
- g.header.match(re#^QUERY .*io.picolabs.subscription/established#) => false |
114
+ g{"header"}.match(re#^QUERY .*io.picolabs.pico-engine-ui/#) => false |
115
+ g{"header"}.match(re#^QUERY .*io.picolabs.subscription/established#) => false |
113
116
  true
114
117
  })
115
118
  .reverse()