@indra.ai/deva.security 0.4.1 → 0.5.1

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.
Files changed (2) hide show
  1. package/feature/methods.js +60 -30
  2. package/package.json +2 -2
@@ -86,7 +86,7 @@ export default {
86
86
  const text = [
87
87
  `write: #${data.key}.${data.method}.${data.opts} ${data.text}`,
88
88
  '\n',
89
- `::begin:${data.method}:${data.key}:${data.id.uid}`,
89
+ `${this.box.begin}${data.method}:${data.id.uid}`,
90
90
  `sign: ${data.client.fullname} ${data.client.emojis}`,
91
91
  `uid: ${data.id.uid}`,
92
92
  `time: ${data.time}`,
@@ -104,7 +104,7 @@ export default {
104
104
  `md5: ${data.md5}`,
105
105
  `sha256: ${data.sha256}`,
106
106
  `sha512: ${data.sha512}`,
107
- `::end:${data.method}:${data.key}:${data.id.uid}`,
107
+ `${this.box.end}${data.method}:${data.id.uid}`,
108
108
  ].join('\n').trim();
109
109
 
110
110
  // send the text data to #feecting to parse and return valid text, html, and data.
@@ -126,7 +126,8 @@ export default {
126
126
  describe: Return system md5, sha256, sha512 hash from value.
127
127
  ***************/
128
128
  async hash(packet) {
129
- const {id, q} = packet;
129
+ const id = this.uid();
130
+ const {q} = packet;
130
131
  this.feature('security', `hash:${id.uid}`);
131
132
  const {global, personal} = this.security();
132
133
  const agent = this.agent()
@@ -143,20 +144,14 @@ export default {
143
144
  this.state('set', `hash:${id.uid}`); //set the meta state for the proxy
144
145
  const hash = this.hash(q.text, algo);
145
146
 
146
- const time = Date.now();
147
- const date = this.lib.formatDate(time, 'long', true);
148
- const copyright = client.profile.copyright || agent.profile.copyright || this.info().copyright
149
147
  const data = {
150
148
  id,
151
149
  algo,
152
150
  text: q.text,
153
151
  hash,
154
- time,
155
- date,
156
- copyright,
157
152
  };
158
153
 
159
- const status = `${agent.key}:${data.algo}:${data.id.uid}`;
154
+ const status = `${agent.key}:hash:${data.id.uid}`;
160
155
 
161
156
  const text = [
162
157
  `${this.box.begin}${status}`,
@@ -164,15 +159,16 @@ export default {
164
159
  `algo: ${data.algo}`,
165
160
  `text: ${data.text}`,
166
161
  `hash: ${data.hash}`,
167
- `time: ${data.time}`,
168
- `date: ${data.date}`,
169
- `copyright: ${data.copyright}`,
162
+ `time: ${data.id.time}`,
163
+ `date: ${data.id.date}`,
164
+ `warning: ${data.id.warning}`,
165
+ `copyright: ${data.id.copyright}`,
170
166
  `${this.box.end}${status}`,
171
167
  ].join('\n');
172
168
 
173
- this.action('return', `hash:${id.uid}`);
174
- this.state('valid', `hash:${id.uid}`);
175
- this.intent('good', `hash:${id.uid}`);
169
+ this.action('return', `hash:${data.id.uid}`);
170
+ this.state('valid', `hash:${data.id.uid}`);
171
+ this.intent('good', `hash:${data.id.uid}`);
176
172
  return {
177
173
  text,
178
174
  html: false,
@@ -209,7 +205,7 @@ export default {
209
205
 
210
206
  this.state('set', `encrypt:text:${id.uid}`)
211
207
  const text = [
212
- `::begin:${status}`,
208
+ `${this.box.begin}${status}`,
213
209
  `uid: ${id.uid}`,
214
210
  `text: ${q.text}`,
215
211
  `iv: ${data.iv}`,
@@ -222,7 +218,7 @@ export default {
222
218
  `md5: ${data.md5}`,
223
219
  `sha256: ${data.sha256}`,
224
220
  `sha512: ${data.sha512}`,
225
- `::end:${status}`,
221
+ `${this.box.end}${status}`,
226
222
  ].join('\n');
227
223
 
228
224
  this.action('return', `encrypt:${id.uid}`); // set action return
@@ -277,7 +273,7 @@ export default {
277
273
 
278
274
  this.state('set', `decrypt:text:${id.uid}`); // set state set
279
275
  const text = [
280
- `::begin:${status}`,
276
+ `${this.box.begin}:${status}`,
281
277
  `uid: ${data.id.uid}`,
282
278
  `decrypted: ${data.decrypt}`,
283
279
  `time: ${data.id.time}`,
@@ -287,7 +283,7 @@ export default {
287
283
  `md5: ${data.md5}`,
288
284
  `sha256: ${data.sha256}`,
289
285
  `sha512: ${data.sha512}`,
290
- `::end:${status}`,
286
+ `${this.box.end}${status}`,
291
287
  ].join('\n');
292
288
 
293
289
 
@@ -302,19 +298,53 @@ export default {
302
298
  },
303
299
 
304
300
  /**************
305
- method: today
301
+ method: date
306
302
  params: packet
307
303
  describe: Return system date for today.
308
304
  ***************/
309
- today(packet) {
310
- const transport = packet.id;
311
- this.zone('security', `today:${transport}`);
312
- this.feature('security', `today:${transport}`);
313
- this.action('method', `today:${transport}`);
314
- this.state('get', `today:${transport}`);
315
- const theDate = this.lib.formatDate(Date.now(), 'long', true);
316
- this.state('get', `today:${transport}`);
317
- return Promise.resolve(theDate);
305
+ async date(packet) {
306
+ const id = this.uid();
307
+ const {params} = packet.q.meta;
308
+ const {key} = this.agent();
309
+
310
+ this.zone('security', `date:${id.uid}`);
311
+ this.feature('security', `date:${id.uid}`);
312
+ this.action('method', `date:${id.uid}`);
313
+
314
+ const format = params[1] ? params[1] : 'long';
315
+ const time = params[2] ? packet.q.meta.params[2] : false;
316
+
317
+ this.state('set', `date:${id.uid}`);
318
+ const date = this.lib.formatDate(Date.now(), format, time);
319
+
320
+ const data = {
321
+ id,
322
+ date,
323
+ }
324
+
325
+ this.action('hash', `date:data:md5:${id.uid}`); // set action hash
326
+ data.md5 = this.hash(date, 'md5');
327
+ this.action('hash', `date:data:sha256:${id.uid}`); // set action hash
328
+ data.sha256 = this.hash(date, 'sha256');
329
+ this.action('hash', `date:data:sha512:${id.uid}`); // set action hash
330
+ data.sha512 = this.hash(date, 'sha512');
331
+
332
+ const text = [
333
+ `${this.box.begin}${key}:date:${data.id.uid}`,
334
+ `date: ${data.date}`,
335
+ `md5: ${data.md5}`,
336
+ `sha256: ${data.sha256}`,
337
+ `sha512: ${data.sha512}`,
338
+ `${this.box.end}${key}:date:${data.id.uid}`
339
+ ].join('\n');
340
+ this.action('return', `date:${id.uid}`);
341
+ this.state('valid', `date:${id.uid}`);
342
+ this.intent('good', `date:${id.uid}`);
343
+ return {
344
+ text,
345
+ html: false,
346
+ data,
347
+ };
318
348
  },
319
349
  /**************
320
350
  method: time
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "45249771785697968797",
3
3
  "name": "@indra.ai/deva.security",
4
- "version": "0.4.1",
4
+ "version": "0.5.1",
5
5
  "license": "VLA:45249771785697968797 LICENSE.md",
6
6
  "VLA": {
7
7
  "uid": "45249771785697968797",
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "homepage": "https://deva.space/devas/security",
62
62
  "dependencies": {
63
- "@indra.ai/deva": "^1.22.1",
63
+ "@indra.ai/deva": "^1.23.1",
64
64
  "mongodb": "^6.20.0"
65
65
  },
66
66
  "data": {