pathchain 1.0.25 → 1.0.28
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 +126 -4
- package/getter.js +36 -1
- package/index.js +27 -0
- package/maker.js +43 -1
- package/package.json +1 -1
- package/proto/node.proto +8 -0
- package/updater.js +1 -4
package/README.md
CHANGED
|
@@ -203,7 +203,7 @@ var used = pathchain.isSecretUsed(secret_buff);
|
|
|
203
203
|
console.log("Secret buffer used?: ", used); // Printing
|
|
204
204
|
|
|
205
205
|
// Using the secret
|
|
206
|
-
pathchain.useSecret(secret_buff);
|
|
206
|
+
pathchain.useSecret(secret_buff, xentity);
|
|
207
207
|
|
|
208
208
|
// Checking if the secret has been used (before using it)
|
|
209
209
|
var used = pathchain.isSecretUsed(secret_buff);
|
|
@@ -236,9 +236,9 @@ Summoning `getSecretObj(xsecret)`
|
|
|
236
236
|
```
|
|
237
237
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
238
238
|
|
|
239
|
-
const
|
|
239
|
+
const secret_buff = pathchain.makeSecret(author); // Secret creation
|
|
240
240
|
|
|
241
|
-
var secret_obj = pathchain.getSecretObj(secret_buff); //
|
|
241
|
+
var secret_obj = pathchain.getSecretObj(secret_buff); // Getting object from hashname
|
|
242
242
|
|
|
243
243
|
console.log("Secret object: ", secret_obj); // Printing
|
|
244
244
|
```
|
|
@@ -269,4 +269,126 @@ message entity {
|
|
|
269
269
|
required string invite = 2;
|
|
270
270
|
required string tag = 3;
|
|
271
271
|
}
|
|
272
|
-
```
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
## Entity
|
|
276
|
+
|
|
277
|
+
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 entitie(s) secret.
|
|
278
|
+
|
|
279
|
+
`<entity>` :: entity ::= { `<“entities/”>` + sha256(`<moment>` + `<entity>`) }
|
|
280
|
+
|
|
281
|
+
#### Protocol Buffer file:
|
|
282
|
+
|
|
283
|
+
``` proto
|
|
284
|
+
syntax = "proto3";
|
|
285
|
+
|
|
286
|
+
message entity {
|
|
287
|
+
required string register = 1;
|
|
288
|
+
required string ancestor = 2;
|
|
289
|
+
required string tag = 3;
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### Entity maker
|
|
294
|
+
|
|
295
|
+
Parameter rules:
|
|
296
|
+
|Parameter |Required |
|
|
297
|
+
|-------------------------|----------|
|
|
298
|
+
|{string} author |(required)|
|
|
299
|
+
|{string} format |(optional)|
|
|
300
|
+
|
|
301
|
+
Summoning `makeEntity(secret, format)`:
|
|
302
|
+
```javascript
|
|
303
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
304
|
+
|
|
305
|
+
// Entity creation
|
|
306
|
+
var entity_buff = pathchain.makeEntity(secret);
|
|
307
|
+
|
|
308
|
+
console.log("Entity buffer: ", entity_buff);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Console:
|
|
312
|
+
``` bash
|
|
313
|
+
Entity buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### Entity getter
|
|
317
|
+
|
|
318
|
+
Parameter rules:
|
|
319
|
+
|Parameter |Required |
|
|
320
|
+
|-------------------------|----------|
|
|
321
|
+
|{string} xentity |(optional)|
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
Summoning `getEntityObj(xentity)`
|
|
325
|
+
```
|
|
326
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
327
|
+
|
|
328
|
+
// Entity creation
|
|
329
|
+
var entity_buff = pathchain.makeEntity(secret);
|
|
330
|
+
|
|
331
|
+
// Getting entity obj
|
|
332
|
+
var entity_obj = pathchain.getEntityObj(entity_buff);
|
|
333
|
+
|
|
334
|
+
console.log("Entity buffer: ", entity_buff);
|
|
335
|
+
console.log("Entity object: ", entity_obj);
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Console:
|
|
339
|
+
``` bash
|
|
340
|
+
Entity buffer: 9a07ccefa200a3bcf3322fee26f35302f0ec206784d537bb06065bfb9f92885c
|
|
341
|
+
Entity object: {
|
|
342
|
+
register: 'moments/28013246663010e61e9fca8dd21d309959954d95ac90739616126f40b8d93ede',
|
|
343
|
+
ancestor: 'entities/undefined',
|
|
344
|
+
tag: 'entities/9a07ccefa200a3bcf3322fee26f35302f0ec206784d537bb06065bfb9f92885c'
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
## Node
|
|
350
|
+
|
|
351
|
+
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`.
|
|
352
|
+
|
|
353
|
+
`<node>` :: node ::= { `<“nodes/”>` + sha256(`<moment>` + `<author>`) }
|
|
354
|
+
|
|
355
|
+
#### Protocol Buffer file:
|
|
356
|
+
|
|
357
|
+
``` proto
|
|
358
|
+
syntax = "proto3";
|
|
359
|
+
|
|
360
|
+
message node {
|
|
361
|
+
required string register = 1;
|
|
362
|
+
required string author = 2;
|
|
363
|
+
required string file = 3;
|
|
364
|
+
required string text = 4;
|
|
365
|
+
required string url = 5;
|
|
366
|
+
required string tag = 6;
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
#### Node maker
|
|
372
|
+
|
|
373
|
+
Parameter rules:
|
|
374
|
+
|Parameter |Required |
|
|
375
|
+
|-------------------------|----------|
|
|
376
|
+
|{string} author |(required)|
|
|
377
|
+
|{string} text |(optional)|
|
|
378
|
+
|{string} format |(optional)|
|
|
379
|
+
|
|
380
|
+
Summoning `makeNode(secret, text, format)`:
|
|
381
|
+
```javascript
|
|
382
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
383
|
+
|
|
384
|
+
// Node creation
|
|
385
|
+
var node_buff = pathchain.makeNode(author, content);
|
|
386
|
+
|
|
387
|
+
console.log("Node buffer: ", node_buff);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Console:
|
|
391
|
+
``` bash
|
|
392
|
+
Node buffer: a0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
393
|
+
```
|
|
394
|
+
|
package/getter.js
CHANGED
|
@@ -152,4 +152,39 @@ function getEntityObj(xentity, xauthor) {
|
|
|
152
152
|
return entity_obj;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
/** getNodeObj
|
|
156
|
+
* [Function that recieves a node hash and returns the node object]
|
|
157
|
+
*
|
|
158
|
+
* @param {string} xnode (required)
|
|
159
|
+
*
|
|
160
|
+
* @return void
|
|
161
|
+
*/
|
|
162
|
+
function getNodeObj(xnode, xauthor) {
|
|
163
|
+
|
|
164
|
+
if(xauthor != ""){
|
|
165
|
+
xauthor = xauthor + '/';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// LOADING PB
|
|
169
|
+
var node_pb = pb(fs.readFileSync('node_modules/pathchain/proto/node.proto'))
|
|
170
|
+
|
|
171
|
+
// NOT FOUND EXCEPTION
|
|
172
|
+
var fileContents;
|
|
173
|
+
try {
|
|
174
|
+
fileContents = fs.readFileSync("files/" + xauthor + "nodes/" + xnode);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
if (err.code === 'ENOENT') {
|
|
177
|
+
return "Node not found";
|
|
178
|
+
} else {
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// DECODING NODE
|
|
184
|
+
var node_enc = fileContents
|
|
185
|
+
var node_obj = node_pb.node.decode(node_enc)
|
|
186
|
+
|
|
187
|
+
return node_obj;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj, getEntityObj, getNodeObj }
|
package/index.js
CHANGED
|
@@ -152,4 +152,31 @@ exports.isSecretUsed = (xsecret) => {
|
|
|
152
152
|
exports.getSecretObj = (xsecret, xauthor = "") => {
|
|
153
153
|
const secret_object = getter.getSecretObj(xsecret, xauthor);
|
|
154
154
|
return secret_object;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
//////////////////
|
|
159
|
+
/// NODE ///
|
|
160
|
+
//////////////////
|
|
161
|
+
|
|
162
|
+
/** makeNode
|
|
163
|
+
* [Node maker]
|
|
164
|
+
*
|
|
165
|
+
* @return {string} node_buffer
|
|
166
|
+
*/
|
|
167
|
+
exports.makeNode = (xauthor = "", text ="", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
168
|
+
const node_buffer = maker.node(xauthor, text, format);
|
|
169
|
+
return node_buffer;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** getNodeObj
|
|
173
|
+
* [Function that recieves a node hash and returns the node object]
|
|
174
|
+
*
|
|
175
|
+
* @param {string} xnode (required)
|
|
176
|
+
*
|
|
177
|
+
* @return {obj} node_object (node object)
|
|
178
|
+
*/
|
|
179
|
+
exports.getNodeObj = (xnode, xauthor="") => {
|
|
180
|
+
const node_object = getter.getNodeObj(xnode, xauthor);
|
|
181
|
+
return node_object;
|
|
155
182
|
}
|
package/maker.js
CHANGED
|
@@ -206,4 +206,46 @@ function entity(xsecret, format) {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
/** node
|
|
210
|
+
* [Node Protocol Buffer Creation]
|
|
211
|
+
*
|
|
212
|
+
* @param {string} author (optional, default=pioneer_hash)
|
|
213
|
+
* @param {string} file (optional)
|
|
214
|
+
* @param {string} str (optional)
|
|
215
|
+
* @param {string} format (required)
|
|
216
|
+
*
|
|
217
|
+
* @return {string} node_hash
|
|
218
|
+
*/
|
|
219
|
+
function node(author, text, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
220
|
+
var node_pb = pb(fs.readFileSync('node_modules/pathchain/proto/node.proto'))
|
|
221
|
+
|
|
222
|
+
var author_folder = author;
|
|
223
|
+
if(author == ""){
|
|
224
|
+
author = pioneer();
|
|
225
|
+
author_folder = "";
|
|
226
|
+
}else{
|
|
227
|
+
author_folder = author_folder + '/';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
var register = new Date()
|
|
231
|
+
register = dt.format(register, dt.compile(format, true));
|
|
232
|
+
|
|
233
|
+
var register_moment_hash = moment(register, format, 0, 0, 0, 0, 0)
|
|
234
|
+
|
|
235
|
+
var node_hash = sha256(register_moment_hash + "_" + author);
|
|
236
|
+
|
|
237
|
+
var buffer = node_pb.node.encode({
|
|
238
|
+
register: "moments/"+register_moment_hash,
|
|
239
|
+
author: author,
|
|
240
|
+
text: text,
|
|
241
|
+
tag: "nodes/"+node_hash,
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
checker.checkDir("files/" + author_folder + "nodes/") // checking
|
|
245
|
+
fs.writeFileSync("files/" + author_folder + "nodes/" + node_hash, buffer);
|
|
246
|
+
|
|
247
|
+
return node_hash;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
module.exports = { moment, pioneer, secret, entity, node }
|
package/package.json
CHANGED
package/proto/node.proto
ADDED
package/updater.js
CHANGED
|
@@ -36,11 +36,8 @@ function useSecret(xsecret, xauthor = "") {
|
|
|
36
36
|
// USING INVITE SECRET
|
|
37
37
|
secret_obj.used = true;
|
|
38
38
|
secret_obj.user = "entities/"+xauthor;
|
|
39
|
-
|
|
40
|
-
// Private handling
|
|
41
|
-
fs.writeFileSync("files/" + xauthor + "secrets/" + xsecret, secret_pb.secret.encode(secret_obj));
|
|
42
39
|
|
|
43
|
-
//
|
|
40
|
+
// Public handling only >:c
|
|
44
41
|
fs.writeFileSync("files/secrets/" + xsecret, secret_pb.secret.encode(secret_obj));
|
|
45
42
|
}
|
|
46
43
|
return secret_obj;
|