@indra.ai/deva.security 0.3.0 → 0.4.0
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/feature/methods.js +172 -34
- package/package.json +2 -2
package/feature/methods.js
CHANGED
|
@@ -22,20 +22,16 @@ 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
|
|
38
|
-
const status = `${key}:${stat}:uid:${id.uid}`;
|
|
34
|
+
const status = `${key}:uid:${id.uid}`;
|
|
39
35
|
const text = [
|
|
40
36
|
`::begin:${status}`,
|
|
41
37
|
`uid: ${id.uid}`,
|
|
@@ -129,40 +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
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
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.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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', `
|
|
145
|
-
const
|
|
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
|
-
|
|
148
|
-
const
|
|
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
|
-
|
|
151
|
-
|
|
161
|
+
const text = [
|
|
162
|
+
`::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
|
+
`::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:
|
|
184
|
+
method: encrypt
|
|
156
185
|
params: packet
|
|
157
186
|
describe: Return system md5 hash for the based deva.
|
|
158
187
|
***************/
|
|
159
|
-
encrypt(packet) {
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
188
|
+
async encrypt(packet) {
|
|
189
|
+
const id = this.uid();
|
|
190
|
+
const {q} = packet;
|
|
191
|
+
this.feature('security', `encrypt:${id.uid}`);
|
|
192
|
+
const {global,personal} = this.security();
|
|
193
|
+
const agent = this.agent();
|
|
194
|
+
this.zone('security', `encrypt:${id.uid}`);
|
|
195
|
+
this.action('encrypt', id.uid);
|
|
196
|
+
|
|
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');
|
|
207
|
+
|
|
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
|
+
};
|
|
164
236
|
},
|
|
165
|
-
|
|
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();
|
|
249
|
+
|
|
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
|
+
}
|
|
257
|
+
|
|
258
|
+
this.action('decrypt', id.uid); // set action hash
|
|
259
|
+
const decrypt = this.lib.decrypt(encrypt);
|
|
260
|
+
|
|
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');
|
|
275
|
+
|
|
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
|
+
};
|
|
302
|
+
},
|
|
303
|
+
|
|
166
304
|
/**************
|
|
167
305
|
method: today
|
|
168
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.
|
|
4
|
+
"version": "0.4.0",
|
|
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.
|
|
63
|
+
"@indra.ai/deva": "^1.22.0",
|
|
64
64
|
"mongodb": "^6.20.0"
|
|
65
65
|
},
|
|
66
66
|
"data": {
|