pathchain 1.1.16 → 1.1.18
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 +247 -99
- package/getter.js +34 -1
- package/index.js +14 -1
- package/maker.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,54 +1,87 @@
|
|
|
1
1
|
# pathchain [](https://badge.fury.io/js/pathchain) [](https://github.com/The-Dream-Operator-s-Garage/pathchain)
|
|
2
2
|

|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
Pathchain is a tool to build path-shaped data structures that are chained one to another from the very moment the tool is initialized. The data behaves like a data tree where you can track the very origin of anything by tracking the origin file hashnames that created any hashname of any file in the chain. Pathchain uses Google's Protocol Buffers to encode and decode the data structures optimally and SHA-256 to build the hashname chain.
|
|
6
5
|
|
|
7
6
|
---
|
|
8
7
|
# Pathchain documentation
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
# Core Function
|
|
10
|
+
| Function | Parameters |
|
|
11
|
+
| ----------------- | ---------------- |
|
|
12
|
+
| [`hello()`](#Hello) | name |
|
|
11
13
|
|
|
12
14
|
# Makers
|
|
13
|
-
Maker functions
|
|
15
|
+
Maker functions receive new data to encode into the chain.
|
|
14
16
|
|
|
15
17
|
| Function | Parameters |
|
|
16
18
|
| ----------------------------- | --------------------------------------- |
|
|
17
19
|
| [`makeMoment()`](#Moment) | datetime, lat, lon, x, y, z, format |
|
|
18
|
-
| [`makePioneer()`](#Pioneer) | format
|
|
20
|
+
| [`makePioneer()`](#Pioneer) | datetime, format |
|
|
19
21
|
| [`makeSecret()`](#Secret) | author, format |
|
|
20
22
|
| [`makeEntity()`](#Entity) | xsecret, format |
|
|
21
23
|
| [`makeNode()`](#Node) | text, xauthor, format |
|
|
22
|
-
| [`
|
|
23
|
-
| [`makePath()`](#Path) |
|
|
24
|
-
| [`
|
|
25
|
-
| [`makeTree()`](#Tree) | xauthor, text, head, ancestor, format |
|
|
26
|
-
|
|
24
|
+
| [`makeLink()`](#Link) | target, prev, next, xauthor, ancestor, format |
|
|
25
|
+
| [`makePath()`](#Path) | text, head, xauthor, ancestor, format |
|
|
26
|
+
| [`makeLabel()`](#Label) | text, xauthor, ancestor, format |
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
# Getters
|
|
30
30
|
Getter functions retrieve objects given a hashname and author information
|
|
31
31
|
|
|
32
|
-
| Function
|
|
33
|
-
|
|
|
34
|
-
| [`
|
|
35
|
-
| [`
|
|
36
|
-
| [`
|
|
37
|
-
| [`
|
|
38
|
-
| [`
|
|
39
|
-
| [`
|
|
40
|
-
| [`
|
|
41
|
-
| [`
|
|
42
|
-
| [`
|
|
43
|
-
| [`
|
|
32
|
+
| Function | Parameters |
|
|
33
|
+
| ----------------------------- | ---------------------------------------- |
|
|
34
|
+
| [`getMomentObj()`](#Moment) | xmoment |
|
|
35
|
+
| [`getPioneerObj()`](#Pioneer) | xpioneer |
|
|
36
|
+
| [`getSecretObj()`](#Secret) | xsecret, xauthor |
|
|
37
|
+
| [`getEntityObj()`](#Entity) | xentity, xauthor |
|
|
38
|
+
| [`getNodeObj()`](#Node) | xnode, xauthor |
|
|
39
|
+
| [`getLinkObj()`](#Link) | xlink, xauthor |
|
|
40
|
+
| [`getPathObj()`](#Path) | xpath, xauthor |
|
|
41
|
+
| [`getPathChainObj()`](#Path) | xpath, xauthor |
|
|
42
|
+
| [`getPatheadObj()`](#Path) | xaddress |
|
|
43
|
+
| [`getLabelObj()`](#Label) | xlabel, xauthor |
|
|
44
|
+
| [`getObj()`](#Common) | xaddress |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
# Other Functions
|
|
48
|
+
| Function | Parameters |
|
|
49
|
+
| ----------------------------- | ---------------------------------------- |
|
|
50
|
+
| [`useSecret()`](#Secret) | xsecret |
|
|
51
|
+
| [`isSecretUsed()`](#Secret) | xsecret |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
## Hello
|
|
55
|
+
|
|
56
|
+
A simple greeting function that confirms the library is working properly.
|
|
57
|
+
|
|
58
|
+
#### Hello function
|
|
59
|
+
|
|
60
|
+
Parameter rules:
|
|
61
|
+
|Parameter |Required |
|
|
62
|
+
|-------------------------|----------|
|
|
63
|
+
|{string} name |(optional)|
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
Summoning `hello(name)`:
|
|
67
|
+
```javascript
|
|
68
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
69
|
+
|
|
70
|
+
const greeting = pathchain.hello("User"); // Simple greeting
|
|
71
|
+
console.log(greeting); // Printing
|
|
72
|
+
```
|
|
44
73
|
|
|
74
|
+
Console:
|
|
75
|
+
``` bash
|
|
76
|
+
Hello from the Dream Operator's Garage, User
|
|
77
|
+
```
|
|
45
78
|
|
|
46
79
|
---
|
|
47
80
|
## Moment
|
|
48
81
|
|
|
49
|
-
A moment is the
|
|
82
|
+
A moment is the minimum representation of the pathchain data structures. Moments are the trunk of every path. They're represented by default with a `MM DD YYYY HH:mm:SSS [GMT]Z` datetime format for `time` and a planet earth representation (0, 0, 0) in general as `space`.
|
|
50
83
|
|
|
51
|
-
`<moment>` :: space and time data ::= {
|
|
84
|
+
`<moment>` :: space and time data ::= { `<"moments/">` + sha256(`<moment>`) }
|
|
52
85
|
|
|
53
86
|
#### Protocol Buffer file:
|
|
54
87
|
|
|
@@ -109,7 +142,7 @@ Summoning `makeMoment(datetime, lat, lon, x, y, z, format)`:
|
|
|
109
142
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
110
143
|
|
|
111
144
|
const moment_pb = pathchain.makeMoment(); // Making moment
|
|
112
|
-
console.log("Moment buffer: ",
|
|
145
|
+
console.log("Moment buffer: ", moment_pb); // Printing
|
|
113
146
|
```
|
|
114
147
|
|
|
115
148
|
Console:
|
|
@@ -122,17 +155,17 @@ Moment buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
|
122
155
|
Parameter rules:
|
|
123
156
|
|Parameter |Required |
|
|
124
157
|
|-------------------------|----------|
|
|
125
|
-
|{string}
|
|
126
|
-
|{string} xmoment |(required)|
|
|
158
|
+
|{string} xmoment |(required)|
|
|
127
159
|
|
|
128
160
|
|
|
129
161
|
---
|
|
130
|
-
Summoning `getMomentObj(
|
|
131
|
-
```
|
|
162
|
+
Summoning `getMomentObj(xmoment)`:
|
|
163
|
+
```javascript
|
|
132
164
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
133
165
|
|
|
134
|
-
const
|
|
135
|
-
var moment_obj = pathchain.getMomentObj(moment_buff); //
|
|
166
|
+
const moment_buff = pathchain.makeMoment(); // Moment creation
|
|
167
|
+
var moment_obj = pathchain.getMomentObj(moment_buff); // Getting object
|
|
168
|
+
console.log("Moment object: ", moment_obj); // Printing
|
|
136
169
|
```
|
|
137
170
|
|
|
138
171
|
Console:
|
|
@@ -161,7 +194,7 @@ Moment object: {
|
|
|
161
194
|
|
|
162
195
|
A secret is an OTP (One Time Password) generated by an entity. The moment it is used, it becomes useless. Secrets are represented as SHA-256 hashes, like everything on pathchain.
|
|
163
196
|
|
|
164
|
-
`<secret>` :: secret hash generated by an entity ::= {
|
|
197
|
+
`<secret>` :: secret hash generated by an entity ::= { `<"secrets/">` + sha256(`<moment>` + `<entity>`) }
|
|
165
198
|
|
|
166
199
|
#### Protocol Buffer file:
|
|
167
200
|
|
|
@@ -181,16 +214,16 @@ message secret {
|
|
|
181
214
|
Parameter rules:
|
|
182
215
|
|Parameter |Required |
|
|
183
216
|
|-------------------------|----------|
|
|
184
|
-
|{string} author |(
|
|
217
|
+
|{string} author |(optional)|
|
|
185
218
|
|{string} format |(optional)|
|
|
186
219
|
|
|
187
220
|
---
|
|
188
|
-
Summoning `
|
|
221
|
+
Summoning `makeSecret(author, format)`:
|
|
189
222
|
```javascript
|
|
190
223
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
191
224
|
|
|
192
|
-
var
|
|
193
|
-
console.log("Secret buffer: ",
|
|
225
|
+
var secret_buff = pathchain.makeSecret(); // Making a secret with default pioneer as author
|
|
226
|
+
console.log("Secret buffer: ", secret_buff); // Printing
|
|
194
227
|
```
|
|
195
228
|
|
|
196
229
|
Console:
|
|
@@ -211,17 +244,17 @@ Summoning `useSecret(xsecret)` & `isSecretUsed(xsecret)`:
|
|
|
211
244
|
```javascript
|
|
212
245
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
213
246
|
|
|
214
|
-
var secret_buff = pathchain.makeSecret(
|
|
215
|
-
console.log("Secret buffer: ",
|
|
247
|
+
var secret_buff = pathchain.makeSecret(); // Making a secret with default pioneer
|
|
248
|
+
console.log("Secret buffer: ", secret_buff); // Printing
|
|
216
249
|
|
|
217
250
|
// Checking if the secret has been used (before using it)
|
|
218
251
|
var used = pathchain.isSecretUsed(secret_buff);
|
|
219
252
|
console.log("Secret buffer used?: ", used); // Printing
|
|
220
253
|
|
|
221
254
|
// Using the secret
|
|
222
|
-
pathchain.useSecret(secret_buff
|
|
255
|
+
pathchain.useSecret(secret_buff);
|
|
223
256
|
|
|
224
|
-
// Checking if the secret has been used (
|
|
257
|
+
// Checking if the secret has been used (after using it)
|
|
225
258
|
var used = pathchain.isSecretUsed(secret_buff);
|
|
226
259
|
console.log("Secret buffer used?: ", used); // Printing
|
|
227
260
|
```
|
|
@@ -229,13 +262,7 @@ console.log("Secret buffer used?: ", used); // Printing
|
|
|
229
262
|
Console:
|
|
230
263
|
``` bash
|
|
231
264
|
Secret buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
``` bash
|
|
235
265
|
Secret buffer used?: false
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
``` bash
|
|
239
266
|
Secret buffer used?: true
|
|
240
267
|
```
|
|
241
268
|
|
|
@@ -246,18 +273,16 @@ Parameter rules:
|
|
|
246
273
|
|Parameter |Required |
|
|
247
274
|
|-------------------------|----------|
|
|
248
275
|
|{string} xsecret |(required)|
|
|
276
|
+
|{string} xauthor |(optional)|
|
|
249
277
|
|
|
250
278
|
|
|
251
279
|
---
|
|
252
|
-
Summoning `getSecretObj(xsecret)`:
|
|
280
|
+
Summoning `getSecretObj(xsecret, xauthor)`:
|
|
253
281
|
```javascript
|
|
254
|
-
|
|
255
282
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
256
283
|
|
|
257
|
-
const secret_buff = pathchain.makeSecret(
|
|
258
|
-
|
|
259
|
-
var secret_obj = pathchain.getSecretObj(secret_buff); // Getting object from hashname
|
|
260
|
-
|
|
284
|
+
const secret_buff = pathchain.makeSecret(); // Secret creation
|
|
285
|
+
var secret_obj = pathchain.getSecretObj(secret_buff); // Getting object from hashname
|
|
261
286
|
console.log("Secret object: ", secret_obj); // Printing
|
|
262
287
|
```
|
|
263
288
|
|
|
@@ -276,7 +301,7 @@ Secret object: {
|
|
|
276
301
|
|
|
277
302
|
A pioneer is a user with all its content made public. It is the first entity on the system and can only generate one [secret](#Secret) in order to initiate the human chain for the system. The pioneer buffer exists as a single buffer in the `pioneer` folder and as an [entity](#Entity) in the `entities` folder.
|
|
278
303
|
|
|
279
|
-
`<pioneer>` :: pioneer entity ::= {
|
|
304
|
+
`<pioneer>` :: pioneer entity ::= { `<"pioneer/">` + sha256(`<moment>` + `<moment>`) }
|
|
280
305
|
|
|
281
306
|
|
|
282
307
|
#### Pioneer maker
|
|
@@ -284,17 +309,16 @@ A pioneer is a user with all its content made public. It is the first entity on
|
|
|
284
309
|
Parameter rules:
|
|
285
310
|
|Parameter |Required |
|
|
286
311
|
|-------------------------|----------|
|
|
287
|
-
|
|
|
312
|
+
|{string} datetime |(optional)|
|
|
313
|
+
|{string} format |(optional)|
|
|
288
314
|
|
|
289
315
|
|
|
290
316
|
---
|
|
291
|
-
Summoning `makePioneer()`:
|
|
317
|
+
Summoning `makePioneer(datetime, format)`:
|
|
292
318
|
```javascript
|
|
293
|
-
|
|
294
319
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
295
320
|
|
|
296
321
|
var pioneer_buff = pathchain.makePioneer(); // Pioneer creation
|
|
297
|
-
|
|
298
322
|
console.log("Pioneer buffer: ", pioneer_buff);
|
|
299
323
|
```
|
|
300
324
|
|
|
@@ -303,23 +327,21 @@ Console:
|
|
|
303
327
|
Pioneer buffer: d945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f
|
|
304
328
|
```
|
|
305
329
|
|
|
306
|
-
** If you summon `makePioneer()` again, it will always return the original pioneer. The pioneer will be the same forever
|
|
330
|
+
**Note: If you summon `makePioneer()` again, it will always return the original pioneer. The pioneer will be the same forever. For the same reason, summoning `getPioneerObj()` does not necessarily require parameters. If the pioneer does not exist, it is automatically created by the system.**
|
|
307
331
|
|
|
308
332
|
#### Pioneer getter
|
|
309
333
|
|
|
310
334
|
Parameter rules:
|
|
311
335
|
|Parameter |Required |
|
|
312
336
|
|-------------------------|----------|
|
|
313
|
-
|
|
|
337
|
+
|{string} xpioneer |(optional)|
|
|
314
338
|
|
|
315
339
|
|
|
316
340
|
---
|
|
317
|
-
Summoning `getPioneerObj()`:
|
|
341
|
+
Summoning `getPioneerObj(xpioneer)`:
|
|
318
342
|
```javascript
|
|
319
|
-
|
|
320
343
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
321
344
|
|
|
322
|
-
|
|
323
345
|
var pioneer_buff = pathchain.makePioneer(); // Pioneer creation
|
|
324
346
|
var pioneer_obj = pathchain.getPioneerObj();
|
|
325
347
|
|
|
@@ -341,9 +363,9 @@ Pioneer object: {
|
|
|
341
363
|
|
|
342
364
|
## Entity
|
|
343
365
|
|
|
344
|
-
Entities are the actors/users that create/author and organize information on the pathchain. Entities are linked to information from their origin and their relationship with other entities and data in the system. Entities can expand and organize with other entities to publish or modify data in the name of an 'alter-ego' or an 'organization'. An entity can only join the pathchain using another
|
|
366
|
+
Entities are the actors/users that create/author and organize information on the pathchain. Entities are linked to information from their origin and their relationship with other entities and data in the system. Entities can expand and organize with other entities to publish or modify data in the name of an 'alter-ego' or an 'organization'. An entity can only join the pathchain using another entity's secret.
|
|
345
367
|
|
|
346
|
-
`<entity>` :: entity ::= {
|
|
368
|
+
`<entity>` :: entity ::= { `<"entities/">` + sha256(`<moment>` + `<entity>`) }
|
|
347
369
|
|
|
348
370
|
|
|
349
371
|
#### Protocol Buffer file:
|
|
@@ -364,17 +386,20 @@ message entity {
|
|
|
364
386
|
Parameter rules:
|
|
365
387
|
|Parameter |Required |
|
|
366
388
|
|-------------------------|----------|
|
|
367
|
-
|{string}
|
|
389
|
+
|{string} xsecret |(required)|
|
|
368
390
|
|{string} format |(optional)|
|
|
369
391
|
|
|
370
392
|
|
|
371
393
|
---
|
|
372
|
-
Summoning `makeEntity(
|
|
394
|
+
Summoning `makeEntity(xsecret, format)`:
|
|
373
395
|
```javascript
|
|
374
396
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
375
397
|
|
|
376
|
-
//
|
|
377
|
-
var
|
|
398
|
+
// First create a secret
|
|
399
|
+
var secret_buff = pathchain.makeSecret();
|
|
400
|
+
|
|
401
|
+
// Entity creation using that secret
|
|
402
|
+
var entity_buff = pathchain.makeEntity(secret_buff);
|
|
378
403
|
|
|
379
404
|
console.log("Entity buffer: ", entity_buff);
|
|
380
405
|
```
|
|
@@ -391,15 +416,19 @@ Parameter rules:
|
|
|
391
416
|
|Parameter |Required |
|
|
392
417
|
|-------------------------|----------|
|
|
393
418
|
|{string} xentity |(required)|
|
|
419
|
+
|{string} xauthor |(optional)|
|
|
394
420
|
|
|
395
421
|
|
|
396
422
|
---
|
|
397
|
-
Summoning `getEntityObj(xentity)`:
|
|
423
|
+
Summoning `getEntityObj(xentity, xauthor)`:
|
|
398
424
|
```javascript
|
|
399
425
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
400
426
|
|
|
427
|
+
// Create a secret
|
|
428
|
+
var secret_buff = pathchain.makeSecret();
|
|
429
|
+
|
|
401
430
|
// Entity creation
|
|
402
|
-
var entity_buff = pathchain.makeEntity(
|
|
431
|
+
var entity_buff = pathchain.makeEntity(secret_buff);
|
|
403
432
|
|
|
404
433
|
// Getting entity obj
|
|
405
434
|
var entity_obj = pathchain.getEntityObj(entity_buff);
|
|
@@ -423,7 +452,7 @@ Entity object: {
|
|
|
423
452
|
|
|
424
453
|
Nodes are the primary data storage elements of the pathchain. They can be the representation of plain `text`, the direction of a `file`, or an internet `url`.
|
|
425
454
|
|
|
426
|
-
`<node>` :: node ::= {
|
|
455
|
+
`<node>` :: node ::= { `<"nodes/">` + sha256(`<moment>` + `<author>` + `<content>`) }
|
|
427
456
|
|
|
428
457
|
|
|
429
458
|
#### Protocol Buffer file:
|
|
@@ -447,18 +476,18 @@ message node {
|
|
|
447
476
|
Parameter rules:
|
|
448
477
|
|Parameter |Required |
|
|
449
478
|
|-------------------------|----------|
|
|
450
|
-
|{string} author |(optional)|
|
|
451
479
|
|{string} text |(optional)|
|
|
480
|
+
|{string} xauthor |(optional)|
|
|
452
481
|
|{string} format |(optional)|
|
|
453
482
|
|
|
454
483
|
|
|
455
484
|
---
|
|
456
|
-
Summoning `makeNode(
|
|
485
|
+
Summoning `makeNode(text, xauthor, format)`:
|
|
457
486
|
```javascript
|
|
458
487
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
459
488
|
|
|
460
489
|
// Node creation
|
|
461
|
-
var node_buff = pathchain.makeNode(
|
|
490
|
+
var node_buff = pathchain.makeNode("This is a test node");
|
|
462
491
|
|
|
463
492
|
console.log("Node buffer: ", node_buff);
|
|
464
493
|
```
|
|
@@ -479,12 +508,12 @@ Parameter rules:
|
|
|
479
508
|
|
|
480
509
|
|
|
481
510
|
---
|
|
482
|
-
Summoning `getNodeObj(xnode)`:
|
|
511
|
+
Summoning `getNodeObj(xnode, xauthor)`:
|
|
483
512
|
```javascript
|
|
484
513
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
485
514
|
|
|
486
515
|
// Node creation
|
|
487
|
-
var node_buff = pathchain.makeNode(
|
|
516
|
+
var node_buff = pathchain.makeNode("Learning to fly, one step closer to knowing");
|
|
488
517
|
|
|
489
518
|
// Getting node obj
|
|
490
519
|
var node_obj = pathchain.getNodeObj(node_buff);
|
|
@@ -509,7 +538,7 @@ Node object: {
|
|
|
509
538
|
|
|
510
539
|
Links are the joints of the paths. They __link__ one node with another.
|
|
511
540
|
|
|
512
|
-
`<link>` :: link ::= {
|
|
541
|
+
`<link>` :: link ::= { `<"links/">` + sha256(`<moment>` + `<author>` + `<target>` + `<prev>` + `<next>`) }
|
|
513
542
|
|
|
514
543
|
|
|
515
544
|
#### Protocol Buffer file:
|
|
@@ -517,7 +546,7 @@ Links are the joints of the paths. They __link__ one node with another.
|
|
|
517
546
|
``` proto
|
|
518
547
|
syntax = "proto3";
|
|
519
548
|
|
|
520
|
-
message
|
|
549
|
+
message link {
|
|
521
550
|
required string register = 1;
|
|
522
551
|
required string author = 2;
|
|
523
552
|
required string ancestor = 3;
|
|
@@ -529,26 +558,29 @@ message nodelink {
|
|
|
529
558
|
```
|
|
530
559
|
|
|
531
560
|
|
|
532
|
-
####
|
|
561
|
+
#### Link maker
|
|
533
562
|
|
|
534
563
|
Parameter rules:
|
|
535
564
|
|Parameter |Required |
|
|
536
565
|
|-------------------------|----------|
|
|
537
|
-
|{string} target |(
|
|
566
|
+
|{string} target |(optional)|
|
|
538
567
|
|{string} prev |(optional)|
|
|
539
568
|
|{string} next |(optional)|
|
|
540
|
-
|{string}
|
|
569
|
+
|{string} xauthor |(optional)|
|
|
541
570
|
|{string} ancestor |(optional)|
|
|
542
571
|
|{string} format |(optional)|
|
|
543
572
|
|
|
544
573
|
|
|
545
574
|
---
|
|
546
|
-
Summoning `makeLink(target, prev, next,
|
|
575
|
+
Summoning `makeLink(target, prev, next, xauthor, ancestor, format)`:
|
|
547
576
|
```javascript
|
|
548
577
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
549
578
|
|
|
550
|
-
//
|
|
551
|
-
var
|
|
579
|
+
// Create a node to target
|
|
580
|
+
var node_buff = pathchain.makeNode("Target node");
|
|
581
|
+
|
|
582
|
+
// Link creation
|
|
583
|
+
var link_buff = pathchain.makeLink(node_buff);
|
|
552
584
|
|
|
553
585
|
console.log("Link buffer: ", link_buff);
|
|
554
586
|
```
|
|
@@ -569,18 +601,21 @@ Parameter rules:
|
|
|
569
601
|
|
|
570
602
|
|
|
571
603
|
---
|
|
572
|
-
Summoning `
|
|
604
|
+
Summoning `getLinkObj(xlink, xauthor)`:
|
|
573
605
|
```javascript
|
|
574
606
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
575
607
|
|
|
576
|
-
//
|
|
577
|
-
var
|
|
608
|
+
// Create a node to target
|
|
609
|
+
var node_buff = pathchain.makeNode("Target node");
|
|
610
|
+
|
|
611
|
+
// Link creation
|
|
612
|
+
var link_buff = pathchain.makeLink(node_buff);
|
|
578
613
|
|
|
579
614
|
// Getting link obj
|
|
580
615
|
var link_obj = pathchain.getLinkObj(link_buff);
|
|
581
616
|
|
|
582
|
-
console.log("
|
|
583
|
-
console.log("
|
|
617
|
+
console.log("Link buffer: ", link_buff);
|
|
618
|
+
console.log("Link object: ", link_obj);
|
|
584
619
|
```
|
|
585
620
|
|
|
586
621
|
Console:
|
|
@@ -601,7 +636,7 @@ Link object: {
|
|
|
601
636
|
|
|
602
637
|
Paths are the skeleton of the data trees built on pathchain. They are a linear way to connect data.
|
|
603
638
|
|
|
604
|
-
`<path>` :: path ::= {
|
|
639
|
+
`<path>` :: path ::= { `<"paths/">` + sha256(`<moment>` + `<author>` + `<head>`) }
|
|
605
640
|
|
|
606
641
|
#### Protocol Buffer file:
|
|
607
642
|
|
|
@@ -625,19 +660,24 @@ message path {
|
|
|
625
660
|
Parameter rules:
|
|
626
661
|
|Parameter |Required |
|
|
627
662
|
|-------------------------|----------|
|
|
628
|
-
|{string}
|
|
629
|
-
|{string}
|
|
630
|
-
|{string}
|
|
663
|
+
|{string} text |(optional)|
|
|
664
|
+
|{string} head |(optional)|
|
|
665
|
+
|{string} xauthor |(optional)|
|
|
666
|
+
|{string} ancestor |(optional)|
|
|
631
667
|
|{string} format |(optional)|
|
|
632
668
|
|
|
633
669
|
|
|
634
670
|
---
|
|
635
|
-
Summoning `makePath(
|
|
671
|
+
Summoning `makePath(text, head, xauthor, ancestor, format)`:
|
|
636
672
|
```javascript
|
|
637
673
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
638
674
|
|
|
675
|
+
// First create a link to use as head
|
|
676
|
+
var node_buff = pathchain.makeNode("First node in path");
|
|
677
|
+
var link_buff = pathchain.makeLink(node_buff);
|
|
678
|
+
|
|
639
679
|
// Path creation
|
|
640
|
-
var path_buff = pathchain.makePath(
|
|
680
|
+
var path_buff = pathchain.makePath("My first path", link_buff);
|
|
641
681
|
|
|
642
682
|
console.log("Path buffer: ", path_buff);
|
|
643
683
|
```
|
|
@@ -648,7 +688,7 @@ Path buffer: a0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
|
648
688
|
```
|
|
649
689
|
|
|
650
690
|
|
|
651
|
-
#### Path
|
|
691
|
+
#### Path getters
|
|
652
692
|
|
|
653
693
|
Parameter rules:
|
|
654
694
|
|Parameter |Required |
|
|
@@ -658,12 +698,16 @@ Parameter rules:
|
|
|
658
698
|
|
|
659
699
|
|
|
660
700
|
---
|
|
661
|
-
Summoning `getPathObj(xpath)`:
|
|
701
|
+
Summoning `getPathObj(xpath, xauthor)`:
|
|
662
702
|
```javascript
|
|
663
703
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
664
704
|
|
|
705
|
+
// Create a node and link
|
|
706
|
+
var node_buff = pathchain.makeNode("First node in path");
|
|
707
|
+
var link_buff = pathchain.makeLink(node_buff);
|
|
708
|
+
|
|
665
709
|
// Path creation
|
|
666
|
-
var path_buff = pathchain.makePath(
|
|
710
|
+
var path_buff = pathchain.makePath("My first path", link_buff);
|
|
667
711
|
|
|
668
712
|
// Getting path obj
|
|
669
713
|
var path_obj = pathchain.getPathObj(path_buff);
|
|
@@ -678,10 +722,114 @@ Path buffer: 426cc58ad2576d48429e2bc32a58b39572fba3e8a1465ae9ecb7826a105d5b31
|
|
|
678
722
|
Path object: {
|
|
679
723
|
register: 'moments/0fede6ab5d5078f7cb535cfdf50f7339c02e343fd9793bd7d68bd544e984ab5b',
|
|
680
724
|
author: 'ad7f31ed77042ed1681119a65b00bbd909b72ecdfb8db5c5f8af596c5a8518bc',
|
|
681
|
-
text: '
|
|
682
|
-
head: '
|
|
725
|
+
text: 'My first path',
|
|
726
|
+
head: 'links/1d3fbcff97b1b995eb83b6c70b23ea95b385add1b9bcef5d5adcd7db21591aac',
|
|
683
727
|
ancestor: 'paths/426cc58ad2576d48429e2bc32a58b39572fba3e8a1465ae9ecb7826a105d5b31',
|
|
684
728
|
chain: '',
|
|
685
729
|
tag: 'paths/426cc58ad2576d48429e2bc32a58b39572fba3e8a1465ae9ecb7826a105d5b31'
|
|
686
730
|
}
|
|
687
731
|
```
|
|
732
|
+
|
|
733
|
+
Summoning `getPathchainObj(xpath, xauthor)` returns the path with its complete chain:
|
|
734
|
+
```javascript
|
|
735
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
736
|
+
|
|
737
|
+
// Get path created earlier
|
|
738
|
+
var path_chain_obj = pathchain.getPathchainObj(path_buff);
|
|
739
|
+
|
|
740
|
+
console.log("Path chain obj: ", path_chain_obj);
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
Summoning `getPatheadObj(xaddress)` returns the head object of a path:
|
|
744
|
+
```javascript
|
|
745
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
746
|
+
|
|
747
|
+
// Get the head object of a path
|
|
748
|
+
var path_head_obj = pathchain.getPatheadObj(path_buff);
|
|
749
|
+
|
|
750
|
+
console.log("Path head object: ", path_head_obj);
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
## Label
|
|
754
|
+
|
|
755
|
+
Labels are used to tag and categorize other elements in the pathchain system.
|
|
756
|
+
|
|
757
|
+
`<label>` :: label ::= { `<"labels/">` + sha256(`<moment>` + `<author>` + `<text>`) }
|
|
758
|
+
|
|
759
|
+
#### Label maker
|
|
760
|
+
|
|
761
|
+
Parameter rules:
|
|
762
|
+
|Parameter |Required |
|
|
763
|
+
|-------------------------|----------|
|
|
764
|
+
|{string} text |(optional)|
|
|
765
|
+
|{string} xauthor |(optional)|
|
|
766
|
+
|{string} ancestor |(optional)|
|
|
767
|
+
|{string} format |(optional)|
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
---
|
|
771
|
+
Summoning `makeLabel(text, xauthor, ancestor, format)`:
|
|
772
|
+
```javascript
|
|
773
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
774
|
+
|
|
775
|
+
// Label creation
|
|
776
|
+
var label_buff = pathchain.makeLabel("Important");
|
|
777
|
+
|
|
778
|
+
console.log("Label buffer: ", label_buff);
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
Console:
|
|
782
|
+
``` bash
|
|
783
|
+
Label buffer: f0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
#### Label getter
|
|
788
|
+
|
|
789
|
+
Parameter rules:
|
|
790
|
+
|Parameter |Required |
|
|
791
|
+
|-------------------------|----------|
|
|
792
|
+
|{string} xlabel |(required)|
|
|
793
|
+
|{string} xauthor |(optional)|
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
---
|
|
797
|
+
Summoning `getLabelObj(xlabel, xauthor)`:
|
|
798
|
+
```javascript
|
|
799
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
800
|
+
|
|
801
|
+
// Label creation
|
|
802
|
+
var label_buff = pathchain.makeLabel("Important");
|
|
803
|
+
|
|
804
|
+
// Getting label obj
|
|
805
|
+
var label_obj = pathchain.getLabelObj(label_buff);
|
|
806
|
+
|
|
807
|
+
console.log("Label buffer: ", label_buff);
|
|
808
|
+
console.log("Label object: ", label_obj);
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
## Common
|
|
812
|
+
|
|
813
|
+
Pathchain provides some generic getter functions that can work with any type of object in the system.
|
|
814
|
+
|
|
815
|
+
#### Generic Object getter
|
|
816
|
+
|
|
817
|
+
Parameter rules:
|
|
818
|
+
|Parameter |Required |
|
|
819
|
+
|-------------------------|----------|
|
|
820
|
+
|{string} xaddress |(required)|
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
---
|
|
824
|
+
Summoning `getObj(xaddress)`:
|
|
825
|
+
```javascript
|
|
826
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
827
|
+
|
|
828
|
+
// Create any object
|
|
829
|
+
var node_buff = pathchain.makeNode("Test node");
|
|
830
|
+
|
|
831
|
+
// Get generic object
|
|
832
|
+
var obj = pathchain.getObj(node_buff);
|
|
833
|
+
|
|
834
|
+
console.log("Object: ", obj);
|
|
835
|
+
```
|
package/getter.js
CHANGED
|
@@ -226,6 +226,38 @@ function getPatheadObj(xpath, xauthor = '') {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Retrieves and decodes a path object from a file.
|
|
231
|
+
* @param {string} xpath - The path hash.
|
|
232
|
+
* @param {string} xauthor - The author of the path (optional).
|
|
233
|
+
* @returns {Object|string} The decoded path object or an error message.
|
|
234
|
+
*/
|
|
235
|
+
function getPathchainObj(xpath, xauthor = '') {
|
|
236
|
+
const pathProto = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'));
|
|
237
|
+
const filePath = `files/${xauthor ? xauthor + '/' : ''}paths/${xpath}`;
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
const fileContents = fs.readFileSync(filePath);
|
|
241
|
+
var pathObj = pathProto.path.decode(fileContents);
|
|
242
|
+
|
|
243
|
+
var current_link = this.getObj(pathObj.head);
|
|
244
|
+
console.log("Head link", current_link);
|
|
245
|
+
var current_obj = this.getObj(current_link.target);
|
|
246
|
+
console.log("First object", current_obj);
|
|
247
|
+
|
|
248
|
+
let obj_list = [];
|
|
249
|
+
// append targets to obj_list until the link's prev property points to itself
|
|
250
|
+
while (current_link.prev !== current_link.target) {
|
|
251
|
+
obj_list.push(current_obj);
|
|
252
|
+
current_link = this.getObj(current_link.prev);
|
|
253
|
+
current_obj = this.getObj(current_link.target);
|
|
254
|
+
}
|
|
255
|
+
// Get link -> get link.target
|
|
256
|
+
return obj_list;
|
|
257
|
+
} catch (err) {
|
|
258
|
+
return err.code === 'ENOENT' ? "Path not found" : err;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
229
261
|
|
|
230
262
|
module.exports = {
|
|
231
263
|
getCurrentDate,
|
|
@@ -238,5 +270,6 @@ module.exports = {
|
|
|
238
270
|
getPathObj,
|
|
239
271
|
getLabelObj,
|
|
240
272
|
getObj,
|
|
241
|
-
getPatheadObj
|
|
273
|
+
getPatheadObj,
|
|
274
|
+
getPathchainObj
|
|
242
275
|
};
|
package/index.js
CHANGED
|
@@ -287,7 +287,7 @@ exports.getObj = (xaddress) => {
|
|
|
287
287
|
return pathchain_object;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
/**
|
|
290
|
+
/** getPatheadObj
|
|
291
291
|
* [Function that recieves a path hash and returns the path object]
|
|
292
292
|
*
|
|
293
293
|
|
|
@@ -298,4 +298,17 @@ exports.getObj = (xaddress) => {
|
|
|
298
298
|
exports.getPatheadObj = (xaddress) => {
|
|
299
299
|
const pathchain_object = getter.getPatheadObj(xaddress);
|
|
300
300
|
return pathchain_object;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** getPathchainObj
|
|
304
|
+
* [Function that recieves a path hash and returns the path object]
|
|
305
|
+
*
|
|
306
|
+
|
|
307
|
+
* Retrieves and decodes a address object from a file.
|
|
308
|
+
* @param {string} xaddress - The address string.
|
|
309
|
+
* @returns {Object|string} The decoded object or an error message.
|
|
310
|
+
*/
|
|
311
|
+
exports.getPathchainObj = (xaddress) => {
|
|
312
|
+
const pathchain_object = getter.getPathchainObj(xaddress);
|
|
313
|
+
return pathchain_object;
|
|
301
314
|
}
|
package/maker.js
CHANGED
|
@@ -230,15 +230,18 @@ function path(text, elements, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [
|
|
|
230
230
|
|
|
231
231
|
let prev_link = "";
|
|
232
232
|
let head_link = "";
|
|
233
|
-
|
|
233
|
+
|
|
234
234
|
// Building target chain
|
|
235
235
|
for (let i = 0; i < elements.length; i++) {
|
|
236
|
+
// link with no next and no prev is set with its target as the current element
|
|
236
237
|
const current_link = link(elements[i], "", "", author, "");
|
|
237
|
-
if
|
|
238
|
+
// onli if this is not the first element
|
|
238
239
|
if (i > 0) {
|
|
239
240
|
updater.setLinkNext(prev_link, current_link);
|
|
240
241
|
updater.setLinkPrev(current_link, prev_link);
|
|
241
242
|
}
|
|
243
|
+
if(i==0) head_link = current_link;
|
|
244
|
+
// for the next iteration, the previous link is set as the current link
|
|
242
245
|
prev_link = current_link;
|
|
243
246
|
}
|
|
244
247
|
|
package/package.json
CHANGED