pathchain 1.0.8 → 1.0.10

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
@@ -1,8 +1,8 @@
1
- # pathchain [![npm version](https://badge.fury.io/js/pathchain.svg)](https://badge.fury.io/js/pathchain) [![open source](https://img.shields.io/badge/open%20source-pathchain-grey?labelColor=purple&style=flat&logo=Github&logoColor=white&link=http://github.com/rockstarallegue/pathoschain.git)](http://github.com/rockstarallegue/pathoschain.git)
1
+ # pathchain [![npm version](https://badge.fury.io/js/pathchain.svg)](https://badge.fury.io/js/pathchain) [![open source](https://img.shields.io/badge/open%20source-pathchain-grey?labelColor=purple&style=flat&logo=Github&logoColor=white&link=http://github.com/rockstarallegue/pathchain.git)](http://github.com/rockstarallegue/pathchain.git)
2
2
  ![image](https://user-images.githubusercontent.com/104391124/282268780-cbbc1ee6-8d97-4d80-b896-66ae3eb723dd.png)
3
3
 
4
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.
5
+ 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
6
 
7
7
  ---
8
8
  # Pathchain documentation
@@ -10,18 +10,32 @@ Pathchain is a tool to build path-shaped data structures that are chained one to
10
10
  ## Makers
11
11
  Maker functions recieve new data to encode into the chain.
12
12
 
13
- | Function | Parameters |
14
- | --------------------------- | --------------------------------------- |
15
- | [`makeMoment()`](#Moment) | datetime, lat, lon, x, y, z, format |
16
- | [`makePioneer()`](#Pioneer) | format |
13
+ | Function | Parameters |
14
+ | ---------------------------- | --------------------------------------- |
15
+ | [`makeMoment()`](#Moment) | datetime, lat, lon, x, y, z, format |
16
+ | [`makePioneer()`](#Pioneer) | format |
17
+ | [`makeSecret()`](#Secret) | author, format |
17
18
 
18
19
 
19
20
 
20
- ### Moments
21
+ ## Getters
22
+ Getter functions retrieve objects given a hashname and author information
21
23
 
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`.
24
+ | Function | Parameters |
25
+ | --------------------------- | ---------------------------------------- |
26
+ | [`getMoment()`](#Moment) | xmoment |
27
+ | [`getPioneer()`](#Pioneer) | (none) |
28
+ | [`getSecret()`](#Secret) | xsecret |
23
29
 
24
- `<moment>` :: space and time data ::= { `<“moment/”>` + sha256(`<moment>`) }
30
+
31
+ ---
32
+
33
+
34
+ ## Moment
35
+
36
+ A moment is the mimimum 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`.
37
+
38
+ `<moment>` :: space and time data ::= { `<“moments/”>` + sha256(`<moment>`) }
25
39
 
26
40
  #### Protocol Buffer file:
27
41
 
@@ -75,6 +89,7 @@ Parameter rules:
75
89
  |{float} z |(optional)|
76
90
  |{string} format |(optional)|
77
91
 
92
+
78
93
  Summoning `makeMoment(datetime, lat, lon, x, y, z, format)`:
79
94
  ```javascript
80
95
  const pathchain = require("pathchain"); // Summoning pathchain
@@ -96,6 +111,7 @@ Parameter rules:
96
111
  |{string} xauthor |(optional)|
97
112
  |{string} xmoment |(required)|
98
113
 
114
+
99
115
  Summoning `getMomentObj(xauthor, xmoment)`
100
116
  ```
101
117
  const pathchain = require("pathchain"); // Summoning pathchain
@@ -125,3 +141,132 @@ Moment object: {
125
141
  }
126
142
  }
127
143
  ```
144
+
145
+ ## Secret
146
+
147
+ 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.
148
+
149
+ `<secret>` :: secret hash generated by an entity ::= { `<“secrets/”>` + sha256(`<moment>` + `<entity>`) }
150
+
151
+ #### Protocol Buffer file:
152
+
153
+ ``` proto
154
+ syntax = "proto3";
155
+
156
+ message secret {
157
+ required string register = 1;
158
+ required string author = 2;
159
+ required bool used = 3;
160
+ required string tag = 4;
161
+ }
162
+ ```
163
+
164
+ #### Secret maker
165
+
166
+ Parameter rules:
167
+ |Parameter |Required |
168
+ |-------------------------|----------|
169
+ |{string} author |(required)|
170
+ |{string} format |(optional)|
171
+
172
+
173
+ Summoning `makeMoment(author, format)`:
174
+ ```javascript
175
+ const pathchain = require("pathchain"); // Summoning pathchain
176
+
177
+ var sec_pioneer_buff = pathchain.makeSecret(author); // Making a secret with an existing entity hash
178
+ console.log("Secret buffer: ", secret); // Printing
179
+ ```
180
+
181
+ Console:
182
+ ``` bash
183
+ Secret buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
184
+ ```
185
+
186
+ #### Secret usage (using a secret / checking if a secret has been used)
187
+
188
+ Parameter rules:
189
+ |Parameter |Required |
190
+ |-------------------------|----------|
191
+ |{string} xsecret |(required)|
192
+
193
+
194
+ Summoning `useSecret(xsecret)` & `isSecretUsed(xsecret)`:
195
+ ```javascript
196
+ const pathchain = require("pathchain"); // Summoning pathchain
197
+
198
+ var secret_buff = pathchain.makeSecret(author); // Making a secret with an existing entity hash
199
+ console.log("Secret buffer: ", secret); // Printing
200
+
201
+ // Checking if the secret has been used (before using it)
202
+ var used = pathchain.isSecretUsed(secret_buff);
203
+ console.log("Secret buffer used?: ", used); // Printing
204
+
205
+ // Using the secret
206
+ pathchain.useSecret(secret_buff);
207
+
208
+ // Checking if the secret has been used (before using it)
209
+ var used = pathchain.isSecretUsed(secret_buff);
210
+ console.log("Secret buffer used?: ", used); // Printing
211
+ ```
212
+
213
+ Console:
214
+ ``` bash
215
+ Secret buffer: c0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
216
+ ```
217
+
218
+ ``` bash
219
+ Secret buffer used?: false
220
+ ```
221
+
222
+ ``` bash
223
+ Secret buffer used?: true
224
+ ```
225
+
226
+
227
+ #### Secret getter
228
+
229
+ Parameter rules:
230
+ |Parameter |Required |
231
+ |-------------------------|----------|
232
+ |{string} xsecret |(optional)|
233
+
234
+
235
+ Summoning `getSecretObj(xsecret)`
236
+ ```
237
+ const pathchain = require("pathchain"); // Summoning pathchain
238
+
239
+ const secret_nuff = pathchain.makeSecret(author); // Secret creation
240
+
241
+ var secret_obj = pathchain.getSecretObj(secret_buff); // Getting object from hashname
242
+
243
+ console.log("Secret object: ", secret_obj); // Printing
244
+ ```
245
+
246
+ Console:
247
+ ``` bash
248
+ Secret object: {
249
+ register: 'moments/638976edf4684e746f9bd013bd2e9145b1316ee42b40b0877185f6aeda960b8d',
250
+ author: 'pioneer/ebd4ff7e4f69d1c4c2b529eb60a7ca72bb459c1458e1a011b26b6ea84901d143',
251
+ used: false,
252
+ tag: 'secrets/574e8fee76ba4dc93c2f4cd79399aa01e6cfb19257e4eb305dcfaeb16649b7bf'
253
+ }
254
+ ```
255
+
256
+
257
+ ## Pioneer
258
+
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.
260
+
261
+ `<pioneer>` :: pioneer entity ::= { `<“pioneer/”>` + sha256(`<moment>`) }
262
+
263
+ #### Protocol Buffer file:
264
+ ``` javascript
265
+ syntax = "proto3";
266
+
267
+ message entity {
268
+ required string register = 1;
269
+ required string invite = 2;
270
+ required string tag = 3;
271
+ }
272
+ ```
package/checker.js CHANGED
@@ -68,7 +68,7 @@ function isSecretUsed(xsecret) {
68
68
 
69
69
  if(secret_obj.used == false){
70
70
  return false
71
- }
71
+ }
72
72
  return true;
73
73
  }
74
74
 
package/getter.js CHANGED
@@ -28,7 +28,7 @@ function getMomentObj(xmoment) {
28
28
  }
29
29
 
30
30
  // LOADING PB
31
- var moment_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/moment.proto'))
31
+ var moment_pb = pb(fs.readFileSync('node_modules/pathchain/proto/moment.proto'))
32
32
 
33
33
  // NOT FOUND EXCEPTION
34
34
  var fileContents;
@@ -59,7 +59,7 @@ function getMomentObj(xmoment) {
59
59
  function getPioneerObj(xpioneer) {
60
60
 
61
61
  // LOADING PB
62
- var pioneer_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/entity.proto'))
62
+ var pioneer_pb = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'))
63
63
 
64
64
  // NOT FOUND EXCEPTION
65
65
  var fileContents;
@@ -89,23 +89,23 @@ function getPioneerObj(xpioneer) {
89
89
  *
90
90
  * @return void
91
91
  */
92
- function getSecretObj(xsecret) {
92
+ function getSecretObj(xsecret, xauthor) {
93
93
  // "secret/hash" FORMAT EXCEPTION
94
94
  /*if(xsecret.split("/").length > 1){
95
95
  xsecret = xsecret.split("/")[xsecret.length -1]
96
96
  }*/
97
97
 
98
- if(author_folder != ""){
99
- author_folder = author_folder + '/';
98
+ if(xauthor != ""){
99
+ xauthor = xauthor + '/';
100
100
  }
101
101
 
102
102
  // LOADING PB
103
- var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
103
+ var secret_pb = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'))
104
104
 
105
105
  // NOT FOUND EXCEPTION
106
106
  var fileContents;
107
107
  try {
108
- fileContents = fs.readFileSync("files/" + author_folder + "secrets/" + xsecret);
108
+ fileContents = fs.readFileSync("files/" + xauthor + "secrets/" + xsecret);
109
109
  } catch (err) {
110
110
  if (err.code === 'ENOENT') {
111
111
  return "Secret not found";
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const maker = require("./maker");
2
2
  const getter = require("./getter");
3
+ const checker = require("./checker");
3
4
 
4
5
  ///////////////
5
6
  /// HELLO ///
@@ -103,6 +104,16 @@ exports.useSecret = (xsecret) => {
103
104
  return secret_buffer
104
105
  }
105
106
 
107
+ /** isSecretUsed
108
+ * [Check secret availability]
109
+ *
110
+ * @return {bool} true/false
111
+ */
112
+ exports.isSecretUsed = (xsecret) => {
113
+ const is_secret_used = checker.isSecretUsed(xsecret)
114
+ return is_secret_used
115
+ }
116
+
106
117
  /** getSecretObj
107
118
  * [Function that recieves a moment hash and returns the moment object]
108
119
  *
package/maker.js CHANGED
@@ -19,7 +19,7 @@ const checker = require("./checker");
19
19
  * @return {string} moment_buffer
20
20
  */
21
21
  function moment(datetime, lat, lon, x, y, z, format) {
22
- var moment_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/moment.proto'));
22
+ var moment_pb = pb(fs.readFileSync('node_modules/pathchain/proto/moment.proto'));
23
23
 
24
24
  var date_obj = dt.preparse(datetime, format);
25
25
  var moment_obj = {
@@ -68,7 +68,7 @@ function secret(author, format) {
68
68
 
69
69
  // There is no pioneer
70
70
  if(checker.checkEmptyDir("files/entities/")){
71
- var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
71
+ var secret_pb = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'))
72
72
 
73
73
  var register = new Date()
74
74
  register = dt.format(register, dt.compile(format, true));
@@ -101,7 +101,7 @@ function secret(author, format) {
101
101
  /** pioneer
102
102
  * [Pioneer Protocol Buffer Creation]
103
103
  *
104
- * @param {string} datetime (required)
104
+ * @param {string} xbigbang (required) // The creation moment is the bigbang of the system
105
105
  * @param {string} format (required)
106
106
  *
107
107
  * @return {string} pioneer_buffer
@@ -112,7 +112,7 @@ function pioneer(xbigbang, format) {
112
112
  // There is no pioneer
113
113
  if(checker.checkEmptyDir("files/entities/")){
114
114
  // CREATING PIONEER
115
- var entity = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/entity.proto'))
115
+ var entity = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'))
116
116
 
117
117
  var register = new Date()
118
118
  register = dt.format(register, dt.compile(format, true));
@@ -132,7 +132,7 @@ function pioneer(xbigbang, format) {
132
132
  var buffer = entity.entity.encode({
133
133
  birthday: "moments/"+birthday_moment,
134
134
  register: "moments/"+register_moment_hash,
135
- invite: "entities/"+pioneer_hash, // points to itself as inviting entity in the chain
135
+ invite: "entities/"+pioneer_hash, // points to itself as ancestor entity in the chain
136
136
  tag: "entities/"+pioneer_hash,
137
137
  })
138
138
 
@@ -155,5 +155,55 @@ function pioneer(xbigbang, format) {
155
155
  }
156
156
  }
157
157
 
158
+ /** entity
159
+ * [Entity Protocol Buffer Creation]
160
+ *
161
+ * @param {string} xsecret (required)
162
+ * @param {string} format (optional)
163
+ *
164
+ * @return {string} secret_hash
165
+ */
166
+ function entity(xsecret, format) {
167
+ // "secret/hash" FORMAT EXCEPTION
168
+ /*if(xsecret.split("/").length > 1){
169
+ xsecret = xsecret.split("/")[1]
170
+ }*/
171
+
172
+ checker.checkDir("files/entities/");
173
+ if(checker.checkEmptyDir("files/entities/")){
174
+ return "A pioneer's secret is needed to create the first entity. There was no pioneer, but here is the one at 'files/pioneer/'" + pioneer();
175
+ }
176
+ else{
177
+ if(!checker.isSecretUsed(xsecret)){
178
+ // CREATING entity
179
+ var entity = pb(fs.readFileSync('node_modules/pathchain/proto/entity.proto'))
180
+
181
+ var register = new Date()
182
+ register = dt.format(register, dt.compile(format, true));
183
+
184
+ var register_moment_hash = moment(register, format, 0, 0, 0, 0, 0)
185
+ var ancestor_entity_hash = getter.getSecretObj(xsecret).author;
186
+ // console.log("-> ancestor ENTITY HASH: ", ancestor_entity_hash);
187
+
188
+ var entity_hash = sha256(register_moment_hash + "_" + ancestor_entity_hash);
189
+
190
+
191
+ var buffer = entity.entity.encode({
192
+ register: "moments/"+register_moment_hash,
193
+ invite: ancestor_entity_hash,
194
+ tag: "entities/"+entity_hash,
195
+ })
196
+
197
+ checker.checkDir("files/entities/") // checking
198
+ fs.writeFileSync("files/entities/" + entity_hash, buffer);
199
+
200
+ return "entities/"+entity_hash
201
+ }
202
+ else{
203
+ return "Secret has been already used!"
204
+ }
205
+ }
206
+ }
207
+
158
208
 
159
- module.exports = { moment, pioneer, secret }
209
+ module.exports = { moment, pioneer, secret, entity }
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "pathchain",
3
- "version": "1.0.8"
3
+ "version": "1.0.10"
4
4
  }
@@ -0,0 +1,7 @@
1
+ syntax = "proto3";
2
+
3
+ message entity {
4
+ required string register = 1;
5
+ required string ancestor = 2;
6
+ required string tag = 3;
7
+ }
@@ -0,0 +1,9 @@
1
+ syntax = "proto3";
2
+
3
+ message secret {
4
+ required string register = 1;
5
+ required string author = 2;
6
+ required string user = 3;
7
+ required string used = 3;
8
+ required string tag = 4;
9
+ }
package/updater.js ADDED
@@ -0,0 +1,48 @@
1
+ var fs = require("fs");
2
+ const maker = require("./maker");
3
+ var pb = require('protocol-buffers');
4
+
5
+ /** useSecret
6
+ * [Function that changes a secret state to used]
7
+ *
8
+ * @param {string} xsecret
9
+ *
10
+ * @return {string} xsecret
11
+ */
12
+ function useSecret(xsecret, xentity){
13
+ // DECODING SECRET
14
+ var secret_pb = pb(fs.readFileSync('node_modules/pathos-proto-infra/proto/secret.proto'))
15
+
16
+ // NOT FOUND EXCEPTION
17
+ var secret_enc;
18
+ try {
19
+ secret_enc = fs.readFileSync("files/secrets/"+xsecret)
20
+ } catch (err) {
21
+ if (err.code === 'ENOENT') {
22
+ return "Secret not found :(";
23
+ } else {
24
+ throw err;
25
+ }
26
+ }
27
+
28
+ var secret_obj = secret_pb.secret.decode(secret_enc)
29
+
30
+ if(secret_obj.used == false){
31
+ // USING INVITE SECRET
32
+ secret_obj.used = true
33
+
34
+ var register = new Date()
35
+ register = dt.format(register, dt.compile(format, true));
36
+
37
+ var register_moment_hash = moment(register, format, 0, 0, 0, 0, 0)
38
+
39
+
40
+
41
+ fs.writeFileSync("files/secrets/" + xsecret, secret_pb.secret.encode(secret_obj));
42
+
43
+ return xsecret;
44
+ }
45
+ return xsecret;
46
+ }
47
+
48
+ module.exports = { useSecret }