pathchain 1.0.29 → 1.0.31

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
@@ -15,6 +15,9 @@ Maker functions recieve new data to encode into the chain.
15
15
  | [`makeMoment()`](#Moment) | datetime, lat, lon, x, y, z, format |
16
16
  | [`makePioneer()`](#Pioneer) | format |
17
17
  | [`makeSecret()`](#Secret) | author, format |
18
+ | [`makeEntity()`](#Entity) | xsecret, format |
19
+ | [`makeNode()`](#Node) | text, xauthor, format |
20
+ | [`makePath()`](#Path) | xauthor, text, head, ancestor, format |
18
21
 
19
22
 
20
23
 
@@ -26,6 +29,9 @@ Getter functions retrieve objects given a hashname and author information
26
29
  | [`getMoment()`](#Moment) | xmoment |
27
30
  | [`getPioneer()`](#Pioneer) | (none) |
28
31
  | [`getSecret()`](#Secret) | xsecret |
32
+ | [`getEntity()`](#Entity) | xentity |
33
+ | [`getNode()`](#Node) | xnode |
34
+ | [`getPath()`](#Path) | xpath |
29
35
 
30
36
 
31
37
  ---
@@ -81,13 +87,13 @@ message moment {
81
87
  Parameter rules:
82
88
  |Parameter |Required |
83
89
  |-------------------------|----------|
84
- |{string} datetime |(optional)|
85
- |{float} lat |(optional)|
86
- |{float} lon |(optional)|
87
- |{float} x |(optional)|
88
- |{float} y |(optional)|
89
- |{float} z |(optional)|
90
- |{string} format |(optional)|
90
+ |{string} datetime |(optional)|
91
+ |{float} lat |(optional)|
92
+ |{float} lon |(optional)|
93
+ |{float} x |(optional)|
94
+ |{float} y |(optional)|
95
+ |{float} z |(optional)|
96
+ |{string} format |(optional)|
91
97
 
92
98
 
93
99
  Summoning `makeMoment(datetime, lat, lon, x, y, z, format)`:
@@ -229,11 +235,12 @@ Secret buffer used?: true
229
235
  Parameter rules:
230
236
  |Parameter |Required |
231
237
  |-------------------------|----------|
232
- |{string} xsecret |(optional)|
238
+ |{string} xsecret |(required)|
233
239
 
234
240
 
235
- Summoning `getSecretObj(xsecret)`
236
- ```
241
+ Summoning `getSecretObj(xsecret)`:
242
+ ```javascript
243
+
237
244
  const pathchain = require("pathchain"); // Summoning pathchain
238
245
 
239
246
  const secret_buff = pathchain.makeSecret(author); // Secret creation
@@ -256,18 +263,65 @@ Secret object: {
256
263
 
257
264
  ## Pioneer
258
265
 
259
- 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 in the `entities` folder.
266
+ 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.
260
267
 
261
- `<pioneer>` :: pioneer entity ::= { `<“pioneer/”>` + sha256(`<moment>`) }
268
+ `<pioneer>` :: pioneer entity ::= { `<“pioneer/”>` + sha256(`<moment>` + `<moment>`) }
262
269
 
263
- #### Protocol Buffer file:
264
- ``` javascript
265
- syntax = "proto3";
266
270
 
267
- message entity {
268
- required string register = 1;
269
- required string invite = 2;
270
- required string tag = 3;
271
+ #### Pioneer maker
272
+
273
+ Parameter rules:
274
+ |Parameter |Required |
275
+ |-------------------------|----------|
276
+ | |(nothing) |
277
+
278
+
279
+ Summoning `makePioneer()`:
280
+ ```javascript
281
+
282
+ const pathchain = require("pathchain"); // Summoning pathchain
283
+
284
+ var pioneer_buff = pathchain.makePioneer(); // Pioneer creation
285
+
286
+ console.log("Pioneer buffer: ", pioneer_buff);
287
+ ```
288
+
289
+ Console:
290
+ ``` bash
291
+ Pioneer buffer: d945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f
292
+ ```
293
+
294
+ ** If you summon `makePioneer()` again, it will always return the original pioneer. The pioneer will be the same forever and ever!. For the same reason, summoning `getPioneerObj()` does not require parameters. If the pioneer does not exist, it is automatically created by the system. **
295
+
296
+ #### Pioneer getter
297
+
298
+ Parameter rules:
299
+ |Parameter |Required |
300
+ |-------------------------|----------|
301
+ | |(nothing) |
302
+
303
+
304
+ Summoning `getPioneerObj()`:
305
+ ```javascript
306
+
307
+ const pathchain = require("pathchain"); // Summoning pathchain
308
+
309
+
310
+ var pioneer_buff = pathchain.makePioneer(); // Pioneer creation
311
+ var pioneer_obj = pathchain.getPioneerObj();
312
+
313
+ console.log("Pioneer buffer: ", pioneer_buff);
314
+ console.log("Pioneer object: ", pioneer_obj);
315
+ ```
316
+
317
+
318
+ Console:
319
+ ``` bash
320
+ Pioneer buffer: d945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f
321
+ Pioneer object: {
322
+ register: 'moments/c73d1ca5abc2e158c76747f7c2d56afc729614042a88d46603991fe8f3d4b518',
323
+ ancestor: 'entities/d945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f',
324
+ tag: 'entities/d945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f'
271
325
  }
272
326
  ```
273
327
 
@@ -318,11 +372,11 @@ Entity buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
318
372
  Parameter rules:
319
373
  |Parameter |Required |
320
374
  |-------------------------|----------|
321
- |{string} xentity |(optional)|
375
+ |{string} xentity |(required)|
322
376
 
323
377
 
324
- Summoning `getEntityObj(xentity)`
325
- ```
378
+ Summoning `getEntityObj(xentity)`:
379
+ ```javascript
326
380
  const pathchain = require("pathchain"); // Summoning pathchain
327
381
 
328
382
  // Entity creation
@@ -392,3 +446,105 @@ Console:
392
446
  Node buffer: a0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
393
447
  ```
394
448
 
449
+
450
+ #### Node getter
451
+
452
+ Parameter rules:
453
+ |Parameter |Required |
454
+ |-------------------------|----------|
455
+ |{string} xnode |(required)|
456
+ |{string} xauthor |(optional)|
457
+
458
+
459
+ Summoning `getNodeObj(xnode)`:
460
+ ```javascript
461
+ const pathchain = require("pathchain"); // Summoning pathchain
462
+
463
+ // Node creation
464
+ var node_buff = pathchain.makeNode(secret);
465
+
466
+ // Getting node obj
467
+ var node_obj = pathchain.getNodeObj(node_buff);
468
+
469
+ console.log("Node buffer: ", node_buff);
470
+ console.log("Node object: ", node_obj);
471
+ ```
472
+
473
+ Console:
474
+ ``` bash
475
+ Node buffer: 1014d11c4ed954035790bfed6a3c45e2eda2efbd8d77668c8d8c5d95edc6b0dc
476
+ Node object: {
477
+ register: 'moments/299b4964df437863fdd316c86559e032105ee0f6a6388effd004df60b311f75a',
478
+ author: 'd945dfb67de94dafbcf0ea35281c7ca534a293db3a4d1ffd82523cd97ff8110f',
479
+ text: 'Learning to fly, one step closer to knowing',
480
+ tag: 'nodes/1014d11c4ed954035790bfed6a3c45e2eda2efbd8d77668c8d8c5d95edc6b0dc'
481
+ }
482
+ ```
483
+
484
+
485
+ ## Path
486
+
487
+ Paths are the skeleton of the data trees built on pathchain. They are a linear way to connect data.
488
+
489
+ `<path>` :: path ::= { `<“paths/”>` + sha256(`<moment>` + `<author>`) }
490
+
491
+ #### Protocol Buffer file:
492
+
493
+ ``` proto
494
+ ```
495
+
496
+
497
+ #### Path maker
498
+
499
+ Parameter rules:
500
+ |Parameter |Required |
501
+ |-------------------------|----------|
502
+ |{string} xauthor |(required)|
503
+ |{string} text |(required)|
504
+ |{string} head |(required)|
505
+ |{string} format |(optional)|
506
+
507
+ Summoning `makePath(secret, text, format)`:
508
+ ```javascript
509
+ const pathchain = require("pathchain"); // Summoning pathchain
510
+
511
+ // Path creation
512
+ var path_buff = pathchain.makePath(author, text, head);
513
+
514
+ console.log("Path buffer: ", path_buff);
515
+ ```
516
+
517
+ Console:
518
+ ``` bash
519
+ Path buffer: a0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
520
+ ```
521
+
522
+
523
+ #### Path getter
524
+
525
+ Parameter rules:
526
+ |Parameter |Required |
527
+ |-------------------------|----------|
528
+ |{string} xpath |(required)|
529
+ |{string} xauthor |(optional)|
530
+
531
+
532
+ Summoning `getPathObj(xpath)`:
533
+ ```javascript
534
+ const pathchain = require("pathchain"); // Summoning pathchain
535
+
536
+ // Path creation
537
+ var path_buff = pathchain.makePath(secret);
538
+
539
+ // Getting path obj
540
+ var path_obj = pathchain.getPathObj(path_buff);
541
+
542
+ console.log("Path buffer: ", path_buff);
543
+ console.log("Path object: ", path_obj);
544
+ ```
545
+
546
+ Console:
547
+ ``` bash
548
+ ```
549
+
550
+
package/getter.js CHANGED
@@ -145,7 +145,7 @@ function getEntityObj(xentity, xauthor) {
145
145
  }
146
146
  }
147
147
 
148
- // DECODING SECRET
148
+ // DECODING ENTITY
149
149
  var entity_enc = fileContents
150
150
  var entity_obj = entity_pb.entity.decode(entity_enc)
151
151
 
@@ -187,4 +187,40 @@ function getNodeObj(xnode, xauthor) {
187
187
  return node_obj;
188
188
  }
189
189
 
190
- module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj, getEntityObj, getNodeObj }
190
+
191
+ /** getPathObj
192
+ * [Function that recieves a path hash and returns the path object]
193
+ *
194
+ * @param {string} xpath (required)
195
+ *
196
+ * @return void
197
+ */
198
+ function getPathObj(xpath, xauthor) {
199
+
200
+ if(xauthor != ""){
201
+ xauthor = xauthor + '/';
202
+ }
203
+
204
+ // LOADING PB
205
+ var path_pb = pb(fs.readFileSync('path_modules/pathchain/proto/path.proto'))
206
+
207
+ // NOT FOUND EXCEPTION
208
+ var fileContents;
209
+ try {
210
+ fileContents = fs.readFileSync("files/" + xauthor + "paths/" + xpath);
211
+ } catch (err) {
212
+ if (err.code === 'ENOENT') {
213
+ return "Path not found";
214
+ } else {
215
+ throw err;
216
+ }
217
+ }
218
+
219
+ // DECODING PATH
220
+ var path_enc = fileContents
221
+ var path_obj = path_pb.path.decode(path_enc)
222
+
223
+ return path_obj;
224
+ }
225
+
226
+ module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj, getEntityObj, getNodeObj, getPathObj }
package/index.js CHANGED
@@ -165,7 +165,7 @@ exports.getSecretObj = (xsecret, xauthor = "") => {
165
165
  * @return {string} node_buffer
166
166
  */
167
167
  exports.makeNode = (text ="", xauthor = "", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
168
- const node_buffer = maker.node(xauthor, text, format);
168
+ const node_buffer = maker.node(text, xauthor, format);
169
169
  return node_buffer;
170
170
  }
171
171
 
@@ -180,3 +180,32 @@ exports.getNodeObj = (xnode, xauthor="") => {
180
180
  const node_object = getter.getNodeObj(xnode, xauthor);
181
181
  return node_object;
182
182
  }
183
+
184
+
185
+ //////////////////
186
+ /// PATH ///
187
+ //////////////////
188
+
189
+ /** makePath
190
+ * [Path maker]
191
+ *
192
+ * @return {string} path_buffer
193
+ */
194
+ exports.makePath = (xauthor = "", text ="", head="", ancestor="", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
195
+ const path_buffer = maker.path(xauthor, text, head, ancestor, format);
196
+ return path_buffer;
197
+ }
198
+
199
+ /** getPathObj
200
+ * [Function that recieves a path hash and returns the path object]
201
+ *
202
+ * @param {string} xpath (required)
203
+ *
204
+ * @return {obj} path_object (path object)
205
+ */
206
+ exports.getPathObj = (xpath, xauthor="") => {
207
+ const path_object = getter.getPathObj(xpath, xauthor);
208
+ return path_object;
209
+ }
210
+
211
+
package/maker.js CHANGED
@@ -230,15 +230,15 @@ function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
230
230
  var register = new Date()
231
231
  register = dt.format(register, dt.compile(format, true));
232
232
 
233
- var register_moment_hash = moment(register, format, 0, 0, 0, 0, 0)
233
+ var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
234
234
 
235
235
  var node_hash = sha256(register_moment_hash + "_" + author);
236
236
 
237
237
  var buffer = node_pb.node.encode({
238
- register: "moments/"+register_moment_hash,
239
- author: author,
238
+ register: "moments/" + register_moment_hash,
239
+ author: "etities/" + author,
240
240
  text: text,
241
- tag: "nodes/"+node_hash,
241
+ tag: "nodes/" + node_hash
242
242
  })
243
243
 
244
244
  checker.checkDir("files/" + author_folder + "nodes/") // checking
@@ -248,4 +248,54 @@ function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
248
248
  }
249
249
 
250
250
 
251
- module.exports = { moment, pioneer, secret, entity, node }
251
+
252
+ /**
253
+ * [Pioneer Protocol Buffer Creation]
254
+ *
255
+ * @param {string} author (optional, default=pioneer_hash)
256
+ * @param {string} text (optional, default=path_hash)
257
+ * @param {string} head (required)
258
+ * @param {string} ancestor (optional, default=path_hash)
259
+ * @param {string} format (required)
260
+ *
261
+ * @return {string} path_hash
262
+ */
263
+ function path(author, text, head, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
264
+ var path_pb = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'))
265
+
266
+ var author_folder = author;
267
+ if(author == ""){
268
+ author = pioneer();
269
+ author_folder = "";
270
+ }else{
271
+ author_folder = author_folder + '/';
272
+ }
273
+
274
+ var register = new Date()
275
+ register = dt.format(register, dt.compile(format, true));
276
+
277
+ var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
278
+
279
+ var path_hash = sha256(register_moment_hash + "_" + author);
280
+
281
+ if(text == ""){ text = path_hash; }
282
+ if(head == ""){ return "Head node_link is required to create a path!" }
283
+ if(ancestor == ""){ ancestor = path_hash; }
284
+
285
+ var buffer = path_pb.path.encode({
286
+ register: "moments/"+register_moment_hash,
287
+ author: author,
288
+ text: text,
289
+ head: head,
290
+ ancestor: ancestor,
291
+ tag: "paths/"+path_hash,
292
+ })
293
+
294
+ checker.checkDir("files/" + author_folder + "paths/") // checking
295
+ fs.writeFileSync("files/" + author_folder + "paths/" + path_hash, buffer);
296
+
297
+ return author_folder + "/paths/" + path_hash;
298
+ }
299
+
300
+
301
+ module.exports = { moment, pioneer, secret, entity, node, path }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pathchain",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "dependencies": {
5
5
  "date-and-time": "^3.0.2",
6
6
  "empty-dir": "^3.0.0",
@@ -0,0 +1,11 @@
1
+ syntax = "proto3";
2
+
3
+ message path {
4
+ required string register = 1;
5
+ required string author = 2;
6
+ required string text = 3;
7
+ required string head = 4;
8
+ required string ancestor = 5;
9
+ optional string chain = 6;
10
+ required string tag = 7;
11
+ }