@indra.ai/deva.security 0.3.1 → 0.4.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 +169 -43
  2. package/package.json +2 -2
@@ -22,22 +22,18 @@ export default {
22
22
  ***************/
23
23
  async uid(packet) {
24
24
  return new Promise((resolve, reject) => {
25
- this.context('uid', packet.id.uid);
26
- this.feature('security', `uid:${packet.id.uid}`);
27
- this.zone('security', `uid:${packet.id.uid}`);
28
- this.belief('security', `uid:${packet.id.uid}`)
29
- const {client} = packet.q;
30
- const agent = this.agent();
31
- const {key} = agent;
32
-
33
25
  const uuid = packet.q.text ? true : false
34
26
  const id = this.uid(uuid);
35
-
27
+ this.context('uid', packet.id.uid);
28
+ this.feature('security', `uid:${id.uid}`);
29
+ this.zone('security', `uid:${id.uid}`);
30
+ this.belief('security', `uid:${id.uid}`)
31
+ const {key} = this.agent();
32
+
36
33
  const showJSON = packet.q.meta.params[1] || false;
37
- const stat = this.vars.status || agent.profile.status || 'om';
38
- const status = `${key}:${stat}:uid:${id.uid}`;
34
+ const status = `${key}:uid:${id.uid}`;
39
35
  const text = [
40
- `::begin:${status}`,
36
+ `${this.box.begin}${status}`,
41
37
  `uid: ${id.uid}`,
42
38
  `time: ${id.time}`,
43
39
  `date: ${id.date}`,
@@ -47,7 +43,7 @@ export default {
47
43
  `md5: ${id.md5}`,
48
44
  `sha256: ${id.sha256}`,
49
45
  `sha512: ${id.sha512}`,
50
- `::end:${status}`,
46
+ `${this.box.end}${status}`,
51
47
  ];
52
48
  const data = {
53
49
  uid: id.uid,
@@ -61,9 +57,9 @@ export default {
61
57
  sha512: id.sha512,
62
58
  }
63
59
  if (showJSON) {
64
- text.push(`::begin:${key}:uid:json:${data.uid}`);
60
+ text.push(`${this.box.begin}${key}:uid:json:${data.uid}`);
65
61
  text.push(JSON.stringify(data, null, 2));
66
- text.push(`::end:${key}:uid:json:${data.uid}`);
62
+ text.push(`${this.box.end}${key}:uid:json:${data.uid}`);
67
63
  }
68
64
 
69
65
  this.question(`${this.askChr}feecting parse ${text.join('\n')}`).then(parsed => {
@@ -129,52 +125,182 @@ export default {
129
125
  params: packet
130
126
  describe: Return system md5, sha256, sha512 hash from value.
131
127
  ***************/
132
- hash(packet) {
133
- const transport = packet.id;
134
- this.zone('security', `hash:${transport}`);
135
- this.feature('security', `hash:${transport}`);
136
- this.action('method', `hash:${transport}`);
128
+ async hash(packet) {
129
+ const {id, q} = packet;
130
+ this.feature('security', `hash:${id.uid}`);
131
+ const {global, personal} = this.security();
132
+ const agent = this.agent()
133
+ const client = this.client();
137
134
 
138
- this.state('set', `meta:${transport}`); //set the meta state for the proxy
139
- const {meta} = packet.q; // set the meta information from the packet question.
140
-
141
- this.state('set', `params:${transport}`); //set the meta state for the proxy
142
- const {params} = meta; // set params from the meta information.
135
+ this.zone('security', `hash:${id.uid}`);
136
+ this.action('method', `hash:${id.uid}`);
137
+
138
+ const {params} = q.meta; // set params from the meta information.
139
+
140
+ this.state('set', `hash:algo:${id.uid}`); //set the meta state for the proxy
141
+ const algo = params[1] || personal.hash || global.hash
143
142
 
144
- this.state('set', `algo:${transport}`); //set the meta state for the proxy
145
- const algo = params[1] ? params[1] : 'md5'
143
+ this.state('set', `hash:${id.uid}`); //set the meta state for the proxy
144
+ const hash = this.hash(q.text, algo);
146
145
 
147
- this.state('set', `hash:${transport}`); //set the meta state for the proxy
148
- const hash = this.lib.hash(packet.q.text, algo);
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
+ const data = {
150
+ id,
151
+ algo,
152
+ text: q.text,
153
+ hash,
154
+ time,
155
+ date,
156
+ copyright,
157
+ };
158
+
159
+ const status = `${agent.key}:${data.algo}:${data.id.uid}`;
149
160
 
150
- this.state('return', `hash:${transport}`);
151
- return Promise.resolve(hash);
161
+ const text = [
162
+ `${this.box.begin}${status}`,
163
+ `uid: ${data.id.uid}`,
164
+ `algo: ${data.algo}`,
165
+ `text: ${data.text}`,
166
+ `hash: ${data.hash}`,
167
+ `time: ${data.time}`,
168
+ `date: ${data.date}`,
169
+ `copyright: ${data.copyright}`,
170
+ `${this.box.end}${status}`,
171
+ ].join('\n');
172
+
173
+ this.action('return', `hash:${id.uid}`);
174
+ this.state('valid', `hash:${id.uid}`);
175
+ this.intent('good', `hash:${id.uid}`);
176
+ return {
177
+ text,
178
+ html: false,
179
+ data,
180
+ };
152
181
  },
153
182
 
154
183
  /**************
155
- method: md5 cipher
184
+ method: encrypt
156
185
  params: packet
157
186
  describe: Return system md5 hash for the based deva.
158
187
  ***************/
159
- encrypt(packet) {
160
- this.feature('security', `encrypt:${packet.id.uid}`);
188
+ async encrypt(packet) {
189
+ const id = this.uid();
190
+ const {q} = packet;
191
+ this.feature('security', `encrypt:${id.uid}`);
161
192
  const {global,personal} = this.security();
193
+ const agent = this.agent();
194
+ this.zone('security', `encrypt:${id.uid}`);
195
+ this.action('encrypt', id.uid);
162
196
 
163
- this.zone('security', `encrypt:${packet.id.uid}`);
164
- this.action('encrypt', packet.id.uid);
197
+ this.state('set', `encrypt:data:${id.uid}`); // set state data
198
+ const data = this.lib.encrypt(q.text, global.encrypt);
199
+ data.id = id;
200
+
201
+ this.action('hash', `encrypt:data:md5:${id.uid}`); // set action hash
202
+ data.md5 = this.hash(data.encrypted, 'md5');
203
+ this.action('hash', `encrypt:data:sha256:${id.uid}`); // set action hash
204
+ data.sha256 = this.hash(data.encrypted, 'sha256');
205
+ this.action('hash', `encrypt:data:sha512:${id.uid}`); // set action hash
206
+ data.sha512 = this.hash(data.encrypted, 'sha512');
165
207
 
166
- this.prompt(JSON.stringify(global, null, 2));
208
+ const status = `${agent.key}:encrypt:${id.uid}`;
209
+
210
+ this.state('set', `encrypt:text:${id.uid}`)
211
+ const text = [
212
+ `::begin:${status}`,
213
+ `uid: ${id.uid}`,
214
+ `text: ${q.text}`,
215
+ `iv: ${data.iv}`,
216
+ `key: ${data.key}`,
217
+ `encrypted: ${data.encrypted}`,
218
+ `time: ${id.time}`,
219
+ `date: ${id.date}`,
220
+ `warning: ${id.warning}`,
221
+ `copyright: ${id.copyright}`,
222
+ `md5: ${data.md5}`,
223
+ `sha256: ${data.sha256}`,
224
+ `sha512: ${data.sha512}`,
225
+ `::end:${status}`,
226
+ ].join('\n');
227
+
228
+ this.action('return', `encrypt:${id.uid}`); // set action return
229
+ this.state('valid', `encrypt:${id.uid}`); // set action return
230
+ this.intent('good', `encrypt:${id.uid}`); // set action return
231
+ return {
232
+ text,
233
+ html: false,
234
+ data,
235
+ };
236
+ },
237
+
238
+ async decrypt(packet) {
239
+ const id = this.uid();
240
+ const {q} = packet
241
+ this.feature('security', `decrypt:${id.uid}`);
242
+ this.zone('security', `decrypt:${id.uid}`);
243
+ const {global,personal} = this.security();
244
+
245
+ this.state('set', `decrypt:agent:${id.uid}`); // set state set
246
+ const agent = this.agent();
247
+ this.state('set', `decrypt:client:${id.uid}`); // set state set
248
+ const client = this.client();
167
249
 
168
- this.state('data', `encrypt:${packet.id.uid}`); // set state data
169
- const data = this.lib.encrypt(packet.q.text, global.encrypt);
250
+ this.state('set', `decrypt:encrypt:${id.uid}`); // set state set
251
+ const encrypt = {
252
+ iv: q.meta.params[1],
253
+ key: q.meta.params[2],
254
+ encrypted: q.text,
255
+ algorithm: global.encrypt.algorithm,
256
+ }
170
257
 
171
- console.log('encrypted data', data);
258
+ this.action('decrypt', id.uid); // set action hash
259
+ const decrypt = this.lib.decrypt(encrypt);
172
260
 
173
- const cipher = `encrypt: ${data.encrypted}`;
261
+ this.state('set', `decrypt:data:${id.uid}`); // set state set
262
+ const data = {
263
+ id,
264
+ agent,
265
+ decrypt,
266
+ encrypt,
267
+ };
268
+
269
+ this.action('hash', `decrypt:data:md5:${id.uid}`); // set action hash
270
+ data.md5 = this.hash(decrypt, 'md5');
271
+ this.action('hash', `decrypt:data:sha256:${id.uid}`); // set action hash
272
+ data.sha256 = this.hash(decrypt, 'sha256');
273
+ this.action('hash', `decrypt:data:sha512:${id.uid}`); // set action hash
274
+ data.sha512 = this.hash(decrypt, 'sha512');
174
275
 
175
- return Promise.resolve(cipher);
276
+ const status = `${agent.key}:decrypt:${data.id.uid}`;
277
+
278
+ this.state('set', `decrypt:text:${id.uid}`); // set state set
279
+ const text = [
280
+ `::begin:${status}`,
281
+ `uid: ${data.id.uid}`,
282
+ `decrypted: ${data.decrypt}`,
283
+ `time: ${data.id.time}`,
284
+ `date: ${data.id.date}`,
285
+ `warning: ${data.id.warning}`,
286
+ `copyright: ${data.id.copyright}`,
287
+ `md5: ${data.md5}`,
288
+ `sha256: ${data.sha256}`,
289
+ `sha512: ${data.sha512}`,
290
+ `::end:${status}`,
291
+ ].join('\n');
292
+
293
+
294
+ this.action('return', `decrypt:${id.uid}`); // set action return
295
+ this.state('valid', `decrypt:${id.uid}`); // set action return
296
+ this.intent('good', `decrypt:${id.uid}`); // set action return
297
+ return {
298
+ text,
299
+ html: false,
300
+ data,
301
+ };
176
302
  },
177
-
303
+
178
304
  /**************
179
305
  method: today
180
306
  params: packet
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "45249771785697968797",
3
3
  "name": "@indra.ai/deva.security",
4
- "version": "0.3.1",
4
+ "version": "0.4.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.21.1",
63
+ "@indra.ai/deva": "^1.22.1",
64
64
  "mongodb": "^6.20.0"
65
65
  },
66
66
  "data": {