pathchain 1.0.6 → 1.0.8
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 +127 -0
- package/getter.js +41 -1
- package/index.js +37 -0
- package/maker.js +49 -2
- package/package.json +1 -1
- package/proto/moment.proto +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# pathchain [](https://badge.fury.io/js/pathchain) [](http://github.com/rockstarallegue/pathoschain.git)
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Pathchain is a tool to build path-shaped data structures that are chained one to another from the moment the tool was initialized. The data behaves like a tree where you can track the very origin of your data by tracking the SHA-256 hashname origin of the files. Pathchain uses Google's Protocol Buffers to encode and decode the data structures optimally.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
# Pathchain documentation
|
|
9
|
+
|
|
10
|
+
## Makers
|
|
11
|
+
Maker functions recieve new data to encode into the chain.
|
|
12
|
+
|
|
13
|
+
| Function | Parameters |
|
|
14
|
+
| --------------------------- | --------------------------------------- |
|
|
15
|
+
| [`makeMoment()`](#Moment) | datetime, lat, lon, x, y, z, format |
|
|
16
|
+
| [`makePioneer()`](#Pioneer) | format |
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Moments
|
|
21
|
+
|
|
22
|
+
A moment is the mimimum representation of the pathoschain data structures. Moments are the trunk of any 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`.
|
|
23
|
+
|
|
24
|
+
`<moment>` :: space and time data ::= { `<“moment/”>` + sha256(`<moment>`) }
|
|
25
|
+
|
|
26
|
+
#### Protocol Buffer file:
|
|
27
|
+
|
|
28
|
+
``` proto
|
|
29
|
+
syntax = "proto3";
|
|
30
|
+
|
|
31
|
+
message moment {
|
|
32
|
+
message space {
|
|
33
|
+
message position {
|
|
34
|
+
optional double x = 1;
|
|
35
|
+
optional double y = 2;
|
|
36
|
+
optional double z = 3;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
optional float lat = 1;
|
|
40
|
+
optional float lon = 2;
|
|
41
|
+
optional position xyz = 3;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
message time {
|
|
45
|
+
optional int32 Y = 1;
|
|
46
|
+
optional int32 M = 2;
|
|
47
|
+
optional int32 D = 3;
|
|
48
|
+
optional int32 H = 4;
|
|
49
|
+
optional int32 A = 5;
|
|
50
|
+
optional int32 h = 6;
|
|
51
|
+
optional int32 m = 7;
|
|
52
|
+
optional int32 s = 8;
|
|
53
|
+
optional int32 S = 9;
|
|
54
|
+
optional int32 Z = 10;
|
|
55
|
+
optional int32 _index = 11;
|
|
56
|
+
optional int32 _length = 12;
|
|
57
|
+
optional int32 _match = 13;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
optional space coordinates = 1;
|
|
61
|
+
optional time datetime = 2;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Moment maker
|
|
66
|
+
|
|
67
|
+
Parameter rules:
|
|
68
|
+
|Parameter |Required |
|
|
69
|
+
|-------------------------|----------|
|
|
70
|
+
|{string} datetime |(optional)|
|
|
71
|
+
|{float} lat |(optional)|
|
|
72
|
+
|{float} lon |(optional)|
|
|
73
|
+
|{float} x |(optional)|
|
|
74
|
+
|{float} y |(optional)|
|
|
75
|
+
|{float} z |(optional)|
|
|
76
|
+
|{string} format |(optional)|
|
|
77
|
+
|
|
78
|
+
Summoning `makeMoment(datetime, lat, lon, x, y, z, format)`:
|
|
79
|
+
```javascript
|
|
80
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
81
|
+
|
|
82
|
+
const moment_pb = pathchain.makeMoment(); // Making moment
|
|
83
|
+
console.log("Moment buffer: ", moment); // Printing
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Console:
|
|
87
|
+
``` bash
|
|
88
|
+
Moment buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Moment getter
|
|
92
|
+
|
|
93
|
+
Parameter rules:
|
|
94
|
+
|Parameter |Required |
|
|
95
|
+
|-------------------------|----------|
|
|
96
|
+
|{string} xauthor |(optional)|
|
|
97
|
+
|{string} xmoment |(required)|
|
|
98
|
+
|
|
99
|
+
Summoning `getMomentObj(xauthor, xmoment)`
|
|
100
|
+
```
|
|
101
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
102
|
+
|
|
103
|
+
const moment_pb = pathchain.makeMoment(); // Moment creation
|
|
104
|
+
var moment_obj = pathchain.getMomentObj(moment_buff); // Printing
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Console:
|
|
108
|
+
``` bash
|
|
109
|
+
Moment object: {
|
|
110
|
+
coordinates: { lat: 0, lon: 0, xyz: { x: 0, y: 0, z: 0 } },
|
|
111
|
+
datetime: {
|
|
112
|
+
Y: 2023,
|
|
113
|
+
M: 11,
|
|
114
|
+
D: 8,
|
|
115
|
+
H: 3,
|
|
116
|
+
A: 0,
|
|
117
|
+
h: 0,
|
|
118
|
+
m: 17,
|
|
119
|
+
s: 0,
|
|
120
|
+
S: 175,
|
|
121
|
+
Z: 360,
|
|
122
|
+
_index: 29,
|
|
123
|
+
_length: 29,
|
|
124
|
+
_match: 7
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
package/getter.js
CHANGED
|
@@ -81,4 +81,44 @@ function getPioneerObj(xpioneer) {
|
|
|
81
81
|
return pioneer_obj;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
/** getSecretObj
|
|
86
|
+
* [Function that recieves a secret hash and returns the secret object]
|
|
87
|
+
*
|
|
88
|
+
* @param {string} xsecret (required)
|
|
89
|
+
*
|
|
90
|
+
* @return void
|
|
91
|
+
*/
|
|
92
|
+
function getSecretObj(xsecret) {
|
|
93
|
+
// "secret/hash" FORMAT EXCEPTION
|
|
94
|
+
/*if(xsecret.split("/").length > 1){
|
|
95
|
+
xsecret = xsecret.split("/")[xsecret.length -1]
|
|
96
|
+
}*/
|
|
97
|
+
|
|
98
|
+
if(author_folder != ""){
|
|
99
|
+
author_folder = author_folder + '/';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// LOADING PB
|
|
103
|
+
var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
|
|
104
|
+
|
|
105
|
+
// NOT FOUND EXCEPTION
|
|
106
|
+
var fileContents;
|
|
107
|
+
try {
|
|
108
|
+
fileContents = fs.readFileSync("files/" + author_folder + "secrets/" + xsecret);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
if (err.code === 'ENOENT') {
|
|
111
|
+
return "Secret not found";
|
|
112
|
+
} else {
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// DECODING SECRET
|
|
118
|
+
var secret_enc = fileContents
|
|
119
|
+
var secret_obj = secret_pb.secret.decode(secret_enc)
|
|
120
|
+
|
|
121
|
+
return secret_obj;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj }
|
package/index.js
CHANGED
|
@@ -77,4 +77,41 @@ exports.makePioneer = (datetime = getter.getCurrentDate(), format = 'MM DD YYYY
|
|
|
77
77
|
exports.getPioneerObj = (xpioneer = this.makePioneer()) => {
|
|
78
78
|
const pioneer_object = getter.getPioneerObj(xpioneer);
|
|
79
79
|
return pioneer_object;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
////////////////
|
|
83
|
+
/// SECRET ///
|
|
84
|
+
////////////////
|
|
85
|
+
|
|
86
|
+
/** makeSecret
|
|
87
|
+
* [Secret maker]
|
|
88
|
+
*
|
|
89
|
+
* @return {string} secret_buffer
|
|
90
|
+
*/
|
|
91
|
+
exports.makeSecret = (author = maker.pioneer(), format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
92
|
+
const secret_buffer = maker.secret(author, format)
|
|
93
|
+
return secret_buffer
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** useSecret
|
|
97
|
+
* [Secret using]
|
|
98
|
+
*
|
|
99
|
+
* @return {string} secret_buffer
|
|
100
|
+
*/
|
|
101
|
+
exports.useSecret = (xsecret) => {
|
|
102
|
+
const secret_buffer = updater.useSecret(xsecret)
|
|
103
|
+
return secret_buffer
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** getSecretObj
|
|
107
|
+
* [Function that recieves a moment hash and returns the moment object]
|
|
108
|
+
*
|
|
109
|
+
* @param {string} xsecret (required)
|
|
110
|
+
* @param {string} xauthor (optional)
|
|
111
|
+
*
|
|
112
|
+
* @return {obj} secret_object (entity object)
|
|
113
|
+
*/
|
|
114
|
+
exports.getSecretObj = (xsecret, xauthor = "") => {
|
|
115
|
+
const secret_object = getter.getSecretObj(xsecret, xauthor);
|
|
116
|
+
return secret_object;
|
|
80
117
|
}
|
package/maker.js
CHANGED
|
@@ -14,7 +14,7 @@ const checker = require("./checker");
|
|
|
14
14
|
* @param {float} x (optional)
|
|
15
15
|
* @param {float} y (optional)
|
|
16
16
|
* @param {float} z (optional)
|
|
17
|
-
*
|
|
17
|
+
* @param {string} format (optional)
|
|
18
18
|
*
|
|
19
19
|
* @return {string} moment_buffer
|
|
20
20
|
*/
|
|
@@ -55,6 +55,49 @@ function moment(datetime, lat, lon, x, y, z, format) {
|
|
|
55
55
|
return moment_hash;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** secret
|
|
59
|
+
* [Pioneer Protocol Buffer Creation]
|
|
60
|
+
*
|
|
61
|
+
* @param {string} author (optional, default=pioneer_hash)
|
|
62
|
+
* @param {string} format (required)
|
|
63
|
+
*
|
|
64
|
+
* @return {string} secret_hash
|
|
65
|
+
*/
|
|
66
|
+
function secret(author, format) {
|
|
67
|
+
checker.checkDir("files/entities/")
|
|
68
|
+
|
|
69
|
+
// There is no pioneer
|
|
70
|
+
if(checker.checkEmptyDir("files/entities/")){
|
|
71
|
+
var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
|
|
72
|
+
|
|
73
|
+
var register = new Date()
|
|
74
|
+
register = dt.format(register, dt.compile(format, true));
|
|
75
|
+
|
|
76
|
+
var register_moment_hash = moment(register, format, 0, 0, 0, 0, 0)
|
|
77
|
+
|
|
78
|
+
var secret_hash = sha256(register_moment_hash + "_" + author);
|
|
79
|
+
|
|
80
|
+
var buffer = secret_pb.secret.encode({
|
|
81
|
+
register: "moments/"+register_moment_hash,
|
|
82
|
+
author: author,
|
|
83
|
+
used: false,
|
|
84
|
+
tag: "secrets/"+secret_hash,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
checker.checkDir("files/secrets/") // checking
|
|
88
|
+
checker.checkDir("files/"+ author +"/secrets/") // checking
|
|
89
|
+
|
|
90
|
+
fs.writeFileSync("files/secrets/" + secret_hash, buffer);
|
|
91
|
+
fs.writeFileSync("files/"+ author +"/secrets/" + secret_hash, buffer);
|
|
92
|
+
|
|
93
|
+
return secret_hash;
|
|
94
|
+
}
|
|
95
|
+
// The pioneer already exists
|
|
96
|
+
else{
|
|
97
|
+
return "The pioneer has only one secret";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
58
101
|
/** pioneer
|
|
59
102
|
* [Pioneer Protocol Buffer Creation]
|
|
60
103
|
*
|
|
@@ -93,6 +136,9 @@ function pioneer(xbigbang, format) {
|
|
|
93
136
|
tag: "entities/"+pioneer_hash,
|
|
94
137
|
})
|
|
95
138
|
|
|
139
|
+
const the_secret = secret(pioneer_hash);
|
|
140
|
+
console.log("The pioneer secret buffer is: ", the_secret)
|
|
141
|
+
|
|
96
142
|
// Save as active entity
|
|
97
143
|
checker.checkDir("files/entities/")
|
|
98
144
|
fs.writeFileSync("files/entities/" + pioneer_hash, buffer);
|
|
@@ -109,4 +155,5 @@ function pioneer(xbigbang, format) {
|
|
|
109
155
|
}
|
|
110
156
|
}
|
|
111
157
|
|
|
112
|
-
|
|
158
|
+
|
|
159
|
+
module.exports = { moment, pioneer, secret }
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
message moment {
|
|
4
|
+
message space {
|
|
5
|
+
message position {
|
|
6
|
+
optional double x = 1;
|
|
7
|
+
optional double y = 2;
|
|
8
|
+
optional double z = 3;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
optional float lat = 1;
|
|
12
|
+
optional float lon = 2;
|
|
13
|
+
optional position xyz = 3;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
message time {
|
|
17
|
+
optional int32 Y = 1;
|
|
18
|
+
optional int32 M = 2;
|
|
19
|
+
optional int32 D = 3;
|
|
20
|
+
optional int32 H = 4;
|
|
21
|
+
optional int32 A = 5;
|
|
22
|
+
optional int32 h = 6;
|
|
23
|
+
optional int32 m = 7;
|
|
24
|
+
optional int32 s = 8;
|
|
25
|
+
optional int32 S = 9;
|
|
26
|
+
optional int32 Z = 10;
|
|
27
|
+
optional int32 _index = 11;
|
|
28
|
+
optional int32 _length = 12;
|
|
29
|
+
optional int32 _match = 13;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
optional space coordinates = 1;
|
|
33
|
+
optional time datetime = 2;
|
|
34
|
+
}
|