@indra.ai/deva.security 0.37.4 → 0.37.6
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 +198 -3
- package/feature/methods.js +355 -355
- package/index.js +3 -3
- package/index.test.js +257 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,202 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Security Deva
|
|
2
|
+
|
|
3
|
+
Security Deva is the security agent for Indra.ai and Deva.world. Its agent key is `security`. It keeps a chain-of-custody log of `devacore:finish` and `devacore:complete` packets in a MongoDB log database, and it ships the security feature methods that the feature loader binds at runtime: `security`, `uid`, `sign`, `hash`, `encrypt`, `decrypt`, `date`, and `time`. Commands talk to it directly with `/uid` or, from another Deva, with `#security uid`.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js with npm. Security Deva's `package.json` sets no `engines`. Deva Core 1.67.26 declares `"node": ">=22"` and `"npm": ">=9.5.1"` in its own `package.json`.
|
|
8
|
+
- A project with `"type": "module"` in its `package.json`. Security Deva is an ES module.
|
|
9
|
+
- `@indra.ai/deva` `^1.67.26` (Deva Core) and `mongodb` `^7.9.1`. Both install with Security Deva.
|
|
10
|
+
- A MongoDB server if you want the chain-of-custody logs saved. A local `mongod` at `mongodb://127.0.0.1:27017` is enough.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @indra.ai/deva.security --save
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import SecurityDeva from '@indra.ai/deva.security';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Two licenses
|
|
23
|
+
|
|
24
|
+
A running Deva carries two separate licenses, and each is checked on its own.
|
|
25
|
+
|
|
26
|
+
- **The core license** comes through the client data as `client.VLA`. Deva Core checks it against the core package's VLA at the start of `init`.
|
|
27
|
+
- **The agent license** comes through the license feature data as `features.license.devas.security`. Deva Core 1.67.26 checks it against the VLA in Security Deva's own `package.json` right after the features load and before `onInit`. Security Deva has no `onInit` of its own, so it has no license check of its own to change or remove.
|
|
28
|
+
|
|
29
|
+
The agent check compares the sha256 of the whole VLA object, so every field has to match exactly.
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
Security Deva reads two features from the client you pass to `init()`. The feature data loader puts them in the client, and Deva Core loads them into the Deva at startup, so both must be there before `init()` runs.
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
"features": {
|
|
37
|
+
"license": {
|
|
38
|
+
"concerns": [],
|
|
39
|
+
"global": [],
|
|
40
|
+
"devas": {
|
|
41
|
+
"security": {"uid": "15266350905933520771"}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"security": {
|
|
45
|
+
"concerns": [],
|
|
46
|
+
"global": {
|
|
47
|
+
"mongo": {
|
|
48
|
+
"uri": "mongodb://127.0.0.1:27017",
|
|
49
|
+
"database": "SecurityDeva",
|
|
50
|
+
"log": "SecurityDevaLog"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"devas": {
|
|
54
|
+
"security": {
|
|
55
|
+
"mongo": {
|
|
56
|
+
"uri": "mongodb://127.0.0.1:27017",
|
|
57
|
+
"database": "SecurityDeva",
|
|
58
|
+
"log": "SecurityDevaLog"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `license.devas.security` is the agent VLA. The short form above only shows where it goes. It must be the full `VLA` object from this package's `package.json`, for example:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import pkg from '@indra.ai/deva.security/package.json' with {type:'json'};
|
|
70
|
+
|
|
71
|
+
const devas = {security: pkg.VLA}; // goes in features.license.devas
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- `security.global.mongo.uri` is the MongoDB connection string. If it is not set, Security Deva still comes online but builds no MongoDB client.
|
|
75
|
+
- `security.global.mongo.database` is the main database name. `onReady` stores it in `this.vars.database`.
|
|
76
|
+
- `security.global.mongo.log` is the log database name. `onReady` stores it in `this.vars.log`. `func.write_log` inserts into a named collection in that database.
|
|
77
|
+
- The tests also set `security.devas.security` with the same `{uri, database, log}` shape. That is the personal record for this agent (`agent.key` is `security`). Deva Core exposes it as `this.security().personal`. `onReady` and `write_log` read only `this.security().global?.mongo`. They do not use the personal record. The feature methods `hash`, `encrypt`, and `decrypt` also call `this.security()` for `global` and `personal` values such as the hash algorithm and encrypt options.
|
|
78
|
+
|
|
79
|
+
## Load it
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import SecurityDeva from '@indra.ai/deva.security';
|
|
83
|
+
|
|
84
|
+
const security = await SecurityDeva.init(client); // client data provided by your loader
|
|
85
|
+
console.log(security.id.uid);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
When the license checks pass, Security Deva walks start, enter, done and ready. In `onReady` it reads `this.security().global?.mongo`, builds a `MongoClient` in `this.modules.client` when `uri` is set, keeps `database` in `this.vars.database` and `log` in `this.vars.log`, and prompts `🚨 Security Deva Ready > VLA:15266350905933520771`.
|
|
89
|
+
|
|
90
|
+
To shut it down:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
await SecurityDeva.stop();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`onStop` closes the MongoDB client, if there is one, then calls `this.close(data, resolve)`. If there is no client, it calls `this.close(data, resolve)` directly. A stopped Deva can start again. Call `init()` again with a client that passes the license check. Security Deva builds a new MongoDB client in `onReady`.
|
|
97
|
+
|
|
98
|
+
## When Security Deva refuses to start
|
|
99
|
+
|
|
100
|
+
If the agent license check fails, Deva Core prompts the message, stops the Deva, and `init()` resolves with that message.
|
|
101
|
+
|
|
102
|
+
| You see | Why |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `❌ Bad Personal VLA` | `features.license.devas` is there but has no `security` entry. |
|
|
105
|
+
| `❌ Invalid VLA Check` | The `security` entry doesn't match this package's VLA, or the license feature has no `devas`. |
|
|
106
|
+
|
|
107
|
+
## Commands
|
|
108
|
+
|
|
109
|
+
Talk to Security Deva with `/uid` when it is the current agent, or with `#security uid` from another Deva, after the feature loader has bound `feature/methods.js`. The same pattern applies to the other feature methods.
|
|
110
|
+
|
|
111
|
+
| Command | What it does |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| `/security` | Calls `this.methods.sign('security', 'default', packet)` and returns that result. |
|
|
114
|
+
| `/uid` | Builds a system uid with `this.uid()`, formats it as a Feecting license block, and asks Feecting to parse it. It returns `{text, html, data}`, where `data` is the uid object. A first parameter of a truthy value, from `packet.q.meta.params[1]`, also appends the uid as JSON. |
|
|
115
|
+
| `/sign` | Calls `this.sign(packet)`, formats the signature as a Feecting block, and asks Feecting to parse it. It returns `{text, html, data}`. |
|
|
116
|
+
| `/hash` | Hashes `packet.q.text` with `this.hash`. The algorithm is `packet.q.meta.params[1]`, or `personal.hash`, or `global.hash` from `this.security()`. It asks Feecting to parse the result and returns `{text, html, data}`. |
|
|
117
|
+
| `/encrypt` | Encrypts `packet.q.text` with `this.lib.encrypt` using `global.encrypt` from `this.security()`. It adds md5, sha256, and sha512 hashes of the ciphertext and returns `{text, html: false, data}`. |
|
|
118
|
+
| `/decrypt` | Decrypts `packet.q.text` with `this.lib.decrypt`. The iv is `packet.q.meta.params[1]`, the key is `params[2]`, and the algorithm is `global.encrypt.algorithm` from `this.security()`. It adds the same three hash tiers of the plaintext and returns `{text, html: false, data}`. |
|
|
119
|
+
| `/date` | Formats the current time with `this.lib.formatDate`. The format is `params[1]` or `long`, and `params[2]` controls whether the time is included. It asks Feecting to parse the result and returns `{text, html, data}`. |
|
|
120
|
+
| `/time` | Returns `Date.now()` as a resolved Promise. The resolved value is the timestamp number, not a `{text, html, data}` object. |
|
|
121
|
+
|
|
122
|
+
## Functions
|
|
123
|
+
|
|
124
|
+
| Func | What it does |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `write_log` | Inserts `packet` into collection `type` in `this.vars.log`, using the one `MongoClient` in `this.modules.client`. It returns the `insertOne` result. The `devacore:finish` and `devacore:complete` listeners call it with `'finish'` and `'complete'` when the Deva is active. There is no try/catch in `func.write_log`; a missing client or a failed insert throws. |
|
|
127
|
+
|
|
128
|
+
## Feature methods
|
|
129
|
+
|
|
130
|
+
`feature/methods.js` exports `uid`, `sign`, `hash`, `encrypt`, `decrypt`, `date`, and `time`. The feature loader binds them at runtime from `client.features.security.methods` onto the Deva's `methods`. `index.js` itself ships `methods: {}`. The `security(packet)` method is the global security feature that installs with every agent.
|
|
131
|
+
|
|
132
|
+
## Help
|
|
133
|
+
|
|
134
|
+
Help lives in Feecting files. `help/main.feecting` is the main help page, with the heading `{{profile.name}}`, the security protocols block, and the license block. `help/corpus.feecting` is the help corpus. `help/frameworks/HigherVGW.feecting` is the Higher Vector Guard Wall writeup. `help/programs/KingdomSecureProtectionArm.feecting` is the Kingdom Secure Protection Arm program. The tests check that the main heading is there and that the license page carries this package's VLA uid and hash tiers.
|
|
135
|
+
|
|
136
|
+
## Inside Security Deva
|
|
137
|
+
|
|
138
|
+
| Name | Kind | What it does |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| `write_log` | func | Inserts a packet into a named collection in the log database, as described above. It lives in `index.js`. |
|
|
141
|
+
| `security`, `uid`, `sign`, `hash`, `encrypt`, `decrypt`, `date`, `time` | feature methods | The commands in `feature/methods.js`, bound at runtime. |
|
|
142
|
+
| `translate`, `parse`, `process` | utils | Each returns its input trimmed. |
|
|
143
|
+
| `onReady` | lifecycle | Builds the MongoDB client from the security feature's `global.mongo` and prompts the ready message. |
|
|
144
|
+
| `onStop` | lifecycle | Closes the MongoDB client, if there is one, then calls `this.close(data, resolve)`. |
|
|
145
|
+
| `onError` | lifecycle | Prompts `💣 ERROR!`, logs the error with `console.error`, and returns `reject(err)` or `Promise.reject(err)`. |
|
|
146
|
+
| `modules.client` | module | The `MongoClient`, set in `onReady` when a `uri` is given. |
|
|
147
|
+
|
|
148
|
+
The `vars` in `package.json` hold the prompt `messages`, the `@SECURITY` trigger, and context labels. `this.vars.database` and `this.vars.log` are set in `onReady` from `global.mongo.database` and `global.mongo.log`. The `devacore:finish` and `devacore:complete` listeners copy the packet and pass it to `write_log` when `this._active` is true.
|
|
149
|
+
|
|
150
|
+
## Testing
|
|
151
|
+
|
|
152
|
+
Start a local MongoDB, then run:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
node --test
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The draft `index.test.js` is written for `node --test`. Once the package.json `test` script is set to `node --test`, `npm test` runs the same file. The tests use `mongodb://127.0.0.1:27017` by default. To use another server, set `MONGO_URI`:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
MONGO_URI="mongodb://127.0.0.1:27018" node --test
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The tests always write to their own databases, `deva_security_test` and `deva_security_log_test`, and drop them when they finish. Only the server can change, so the cleanup never touches another database. If MongoDB can't be reached, the MongoDB insert tests are skipped with a message and the rest still run, including the check that `write_log` rejects when no MongoDB client is built, and the check that `init` with `MONGO_URI=mongodb://127.0.0.1:1` still reaches ready.
|
|
165
|
+
|
|
166
|
+
The tests build a stub client in code from the core VLA in `@indra.ai/deva/package.json` and the VLA in this package's `package.json`, so no client file is needed. They cover:
|
|
167
|
+
|
|
168
|
+
- security builds as a Deva and waits offline before init
|
|
169
|
+
- security data has no placeholders left
|
|
170
|
+
- `func.write_log`, `onReady`, `onStop`, and `onError` exist
|
|
171
|
+
- security comes online and walks to ready
|
|
172
|
+
- security agent matches the package
|
|
173
|
+
- security utils answer with trimmed text
|
|
174
|
+
- security help pages name the Deva and carry the package license
|
|
175
|
+
- feature methods from `feature/methods.js` load at runtime
|
|
176
|
+
- `onReady` reads mongo from `this.security()`, not from another Deva
|
|
177
|
+
- `init` with an unreachable MongoDB uri still reaches ready
|
|
178
|
+
- `write_log` inserts a document into the `finish` collection (MongoDB)
|
|
179
|
+
- `write_log` rejects when no MongoDB client is built
|
|
180
|
+
- a stop and `init` restart builds a new MongoClient and can write_log again (MongoDB)
|
|
181
|
+
- security stops through the full chain
|
|
182
|
+
- security refuses to start with a bad agent VLA
|
|
183
|
+
|
|
184
|
+
## Files
|
|
185
|
+
|
|
186
|
+
| File | What it holds |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `index.js` | The Security Deva: utils, `func.write_log`, the finish and complete listeners, and the lifecycle hooks. |
|
|
189
|
+
| `package.json` | Package info, the package VLA, and the agent, vars, zones, actions, and states data under `data`. |
|
|
190
|
+
| `feature/methods.js` | The security feature methods that the feature loader binds at runtime. |
|
|
191
|
+
| `help/main.feecting` | The main help page and the license block. |
|
|
192
|
+
| `help/corpus.feecting` | The help corpus. |
|
|
193
|
+
| `help/frameworks/HigherVGW.feecting` | The Higher Vector Guard Wall writeup. |
|
|
194
|
+
| `help/programs/KingdomSecureProtectionArm.feecting` | The Kingdom Secure Protection Arm program. |
|
|
195
|
+
| `index.test.js` | The tests. |
|
|
196
|
+
| `assets/` | The emoji, avatar, background and image files. |
|
|
197
|
+
| `LICENSE.md` | The license. |
|
|
3
198
|
|
|
4
199
|
Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
5
200
|
Owner Signature Required For Lawful Use.
|
|
6
|
-
Distributed under VLA:15266350905933520771 LICENSE.md
|
|
201
|
+
Distributed under VLA:15266350905933520771 LICENSE.md
|
|
7
202
|
Wednesday, November 25, 2026 - 9:44:25 AM PST
|
package/feature/methods.js
CHANGED
|
@@ -7,375 +7,375 @@
|
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
/**************
|
|
11
|
+
method: uid
|
|
12
|
+
params: packet
|
|
13
|
+
describe: Return a system id to the user from the Log Buddy.
|
|
14
|
+
***************/
|
|
15
|
+
async uid(packet) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const uuid = packet.q.text ? true : false
|
|
18
|
+
const id = this.uid(uuid);
|
|
19
|
+
this.context('uid', packet.id.uid);
|
|
20
|
+
this.feature('security', `uid:${id.uid}`);
|
|
21
|
+
this.zone('security', `uid:${id.uid}`);
|
|
22
|
+
this.belief('security', `uid:${id.uid}`)
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const agent = this.agent();
|
|
25
|
+
const {key} = agent;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const client = this.client();
|
|
28
|
+
|
|
29
|
+
const showJSON = packet.q.meta.params[1] || false;
|
|
30
|
+
const status = `${key}:uid:${id.uid}`;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
32
|
+
this.state('set', `${key}:uid:text:${id.uid}`); // set state set
|
|
33
|
+
const text = [
|
|
34
|
+
`${this.box.begin}:om:${status}`,
|
|
35
|
+
`uid: ${id.uid}`,
|
|
36
|
+
`time: ${id.time}`,
|
|
37
|
+
`utc: ${id.utc}`,
|
|
38
|
+
`iso: ${id.iso}`,
|
|
39
|
+
`date: ${id.date}`,
|
|
40
|
+
`warning: ${id.warning}`,
|
|
41
|
+
`notice: ${id.notice}`,
|
|
42
|
+
`vectors: ${id.vectors}`,
|
|
43
|
+
`agent: ${agent.profile.name} (${agent.profile.pronouns})`,
|
|
44
|
+
`client: ${client.profile.name} (${client.profile.pronouns})`,
|
|
45
|
+
`creator: ${id.creator}`,
|
|
46
|
+
`owner: ${id.owner}`,
|
|
47
|
+
`salute: ${id.salute}`,
|
|
48
|
+
`license: ${id.license}`,
|
|
49
|
+
`fingerprint: ${id.fingerprint}`,
|
|
50
|
+
`copyright: ${id.copyright}`,
|
|
51
|
+
`md5: ${id.md5}`,
|
|
52
|
+
`sha256: ${id.sha256}`,
|
|
53
|
+
`sha512: ${id.sha512}`,
|
|
54
|
+
`${this.box.end}:om:${status}`,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
if (showJSON) {
|
|
58
|
+
text.push(`${this.box.begin}:${key}:uid:json:${id.uid}`);
|
|
59
|
+
text.push(JSON.stringify(id, null, 2));
|
|
60
|
+
text.push(`${this.box.end}:${key}:uid:json:${id.uid}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.question(`${this.askChr}feecting parse ${text.join('\n')}`, {vars:this.vars}).then(parsed => {
|
|
64
|
+
this.belief('vedic', `uid:${packet.id.uid}`);
|
|
65
|
+
this.action('resolve', `uid:${packet.id.uid}`);
|
|
66
|
+
return resolve({
|
|
67
|
+
text: parsed.a.text,
|
|
68
|
+
html: parsed.a.html,
|
|
69
|
+
data: id,
|
|
70
|
+
});
|
|
71
|
+
}).catch(err => {
|
|
72
|
+
return this.err(err, packet, reject);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
77
|
+
async sign(packet) {
|
|
78
|
+
const data = this.sign(packet);
|
|
79
|
+
|
|
80
|
+
// Text data that is joined by line breaks and then trimmed.
|
|
81
|
+
this.state('set', `${data.key}:${data.method}:text:${data.id.uid}`); // set state to text for output formatting.
|
|
82
|
+
const text = [
|
|
83
|
+
`write: #${data.key}.${data.method}.${data.opts} ${data.text}`,
|
|
84
|
+
'\n',
|
|
85
|
+
`${this.box.begin}:${data.method}:${data.id.uid}`,
|
|
86
|
+
`sign: ${data.client.fullname} ${data.client.emojis}`,
|
|
87
|
+
`uid: ${data.id.uid}`,
|
|
88
|
+
`time: ${data.time}`,
|
|
89
|
+
`expires: ${data.client.expires}`,
|
|
90
|
+
`fingerprint: ${data.id.fingerprint}`,
|
|
91
|
+
`name: ${data.client.name}`,
|
|
92
|
+
`fullname: ${data.client.fullname}`,
|
|
93
|
+
`company: ${data.client.company}`,
|
|
94
|
+
`caseid: ${data.client.caseid}`,
|
|
95
|
+
`agent: ${data.agent.sha256}`,
|
|
96
|
+
`token: ${data.client.token}`,
|
|
97
|
+
`warning: ${data.warning}`,
|
|
98
|
+
`created: ${data.created}`,
|
|
99
|
+
`copyright: ${data.copyright}`,
|
|
100
|
+
`md5: ${data.md5}`,
|
|
101
|
+
`sha256: ${data.sha256}`,
|
|
102
|
+
`sha512: ${data.sha512}`,
|
|
103
|
+
`${this.box.end}${data.method}:${data.id.uid}`,
|
|
104
|
+
].join('\n').trim();
|
|
105
|
+
|
|
106
|
+
// send the text data to #feecting to parse and return valid text, html, and data.
|
|
107
|
+
this.action('parse', `${data.key}:${data.method}:parse:${data.id.uid}`); // action set to feecting parse
|
|
108
|
+
const feecting = await this.question(`${this.askChr}feecting parse:${data.id.uid} ${text}`); // parse with feecting agent.
|
|
109
|
+
|
|
110
|
+
this.action('return', `${data.key}:${data.method}:${data.id.uid}`); // set the state to return proxy
|
|
111
|
+
return {
|
|
112
|
+
text: feecting.a.text,
|
|
113
|
+
html: feecting.a.html,
|
|
114
|
+
data,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
},
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
/**************
|
|
120
|
+
method: md5, sha256, sha512 hash
|
|
121
|
+
params: packet
|
|
122
|
+
describe: Return system md5, sha256, sha512 hash from value.
|
|
123
|
+
***************/
|
|
124
|
+
async hash(packet) {
|
|
125
|
+
const id = this.uid();
|
|
126
|
+
const {q} = packet;
|
|
127
|
+
this.feature('security', `hash:${id.uid}`);
|
|
128
|
+
this.belief('security', `hash:${id.uid}`)
|
|
129
|
+
this.zone('security', `hash:${id.uid}`);
|
|
130
|
+
this.action('method', `hash:${id.uid}`);
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const {global, personal} = this.security();
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
135
|
+
const agent = this.agent()
|
|
136
|
+
const client = this.client();
|
|
137
|
+
|
|
138
|
+
const {params} = q.meta; // set params from the meta information.
|
|
139
|
+
|
|
140
|
+
this.state('set', `hash:${id.uid}`); //set the meta state for the proxy
|
|
141
|
+
const algo = params[1] || personal.hash || global.hash
|
|
142
|
+
|
|
143
|
+
this.state('set', `hash:${id.uid}`); //set the meta state for the proxy
|
|
144
|
+
const hash = this.hash(q.text, algo);
|
|
145
|
+
|
|
146
|
+
const data = {
|
|
147
|
+
id,
|
|
148
|
+
algo,
|
|
149
|
+
text: q.text,
|
|
150
|
+
hash,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const status = `${agent.key}:hash:${data.id.uid}`;
|
|
154
|
+
|
|
155
|
+
const text = [
|
|
156
|
+
`${this.box.begin}:${status}`,
|
|
157
|
+
`uid: ${data.id.uid}`,
|
|
158
|
+
`time: ${data.id.time}`,
|
|
159
|
+
`utc: ${data.id.utc}`,
|
|
160
|
+
`iso: ${data.id.iso}`,
|
|
161
|
+
`date: ${data.id.date}`,
|
|
162
|
+
`text: ${data.text}`,
|
|
163
|
+
`${data.algo}: ${data.hash}`,
|
|
164
|
+
`license: ${data.id.license}`,
|
|
165
|
+
// `warning: ${data.id.warning}`,
|
|
166
|
+
`copyright: ${data.id.copyright}`,
|
|
167
|
+
`${this.box.end}:${status}`,
|
|
168
|
+
].join('\n');
|
|
169
|
+
|
|
170
|
+
this.question(`${this.askChr}feecting parse ${text}`, {vars:this.vars}).then(parsed => {
|
|
171
|
+
this.belief('vedic', `hash:${id.uid}`);
|
|
172
|
+
this.state('valid', `hash:${id.uid}`);
|
|
173
|
+
this.action('resolve', `hash:${id.uid}`);
|
|
174
|
+
this.intent('good', `hash:${id.uid}`);
|
|
175
|
+
return resolve({
|
|
176
|
+
text: parsed.a.text,
|
|
177
|
+
html: parsed.a.html,
|
|
178
|
+
data,
|
|
179
|
+
});
|
|
180
|
+
}).catch(err => {
|
|
181
|
+
return this.err(err, packet, reject);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
/**************
|
|
187
|
+
method: encrypt
|
|
188
|
+
params: packet
|
|
189
|
+
describe: Return system md5 hash for the based deva.
|
|
190
|
+
***************/
|
|
191
|
+
async encrypt(packet) {
|
|
192
|
+
const id = this.uid();
|
|
193
|
+
const {q} = packet;
|
|
194
|
+
this.feature('security', `encrypt:${id.uid}`);
|
|
195
|
+
const {global,personal} = this.security();
|
|
196
|
+
const agent = this.agent();
|
|
197
|
+
this.zone('security', `encrypt:${id.uid}`);
|
|
198
|
+
this.action('encrypt', id.uid);
|
|
199
199
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
this.state('set', `encrypt:data:${id.uid}`); // set state data
|
|
201
|
+
const data = this.lib.encrypt(q.text, global.encrypt);
|
|
202
|
+
data.id = id;
|
|
203
|
+
|
|
204
|
+
this.action('hash', `encrypt:data:md5:${id.uid}`); // set action hash
|
|
205
|
+
data.md5 = this.hash(data.encrypted, 'md5');
|
|
206
|
+
this.action('hash', `encrypt:data:sha256:${id.uid}`); // set action hash
|
|
207
|
+
data.sha256 = this.hash(data.encrypted, 'sha256');
|
|
208
|
+
this.action('hash', `encrypt:data:sha512:${id.uid}`); // set action hash
|
|
209
|
+
data.sha512 = this.hash(data.encrypted, 'sha512');
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
211
|
+
const status = `${agent.key}:encrypt:${id.uid}`;
|
|
212
|
+
|
|
213
|
+
this.state('set', `encrypt:text:${id.uid}`)
|
|
214
|
+
const text = [
|
|
215
|
+
`${this.box.begin}:${status}`,
|
|
216
|
+
`uid: ${id.uid}`,
|
|
217
|
+
`text: ${q.text}`,
|
|
218
|
+
`iv: ${data.iv}`,
|
|
219
|
+
`key: ${data.key}`,
|
|
220
|
+
`encrypted: ${data.encrypted}`,
|
|
221
|
+
`time: ${id.time}`,
|
|
222
|
+
`date: ${id.date}`,
|
|
223
|
+
`warning: ${id.warning}`,
|
|
224
|
+
`copyright: ${id.copyright}`,
|
|
225
|
+
`md5: ${data.md5}`,
|
|
226
|
+
`sha256: ${data.sha256}`,
|
|
227
|
+
`sha512: ${data.sha512}`,
|
|
228
|
+
`${this.box.end}:${status}`,
|
|
229
|
+
].join('\n');
|
|
230
|
+
|
|
231
|
+
this.action('return', `encrypt:${id.uid}`); // set action return
|
|
232
|
+
this.state('valid', `encrypt:${id.uid}`); // set action return
|
|
233
|
+
this.intent('good', `encrypt:${id.uid}`); // set action return
|
|
234
|
+
return {
|
|
235
|
+
text,
|
|
236
|
+
html: false,
|
|
237
|
+
data,
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
async decrypt(packet) {
|
|
242
|
+
const id = this.uid();
|
|
243
|
+
const {q} = packet
|
|
244
|
+
this.feature('security', `decrypt:${id.uid}`);
|
|
245
|
+
this.zone('security', `decrypt:${id.uid}`);
|
|
246
|
+
const {global,personal} = this.security();
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
this.state('set', `decrypt:agent:${id.uid}`); // set state set
|
|
249
|
+
const agent = this.agent();
|
|
250
|
+
this.state('set', `decrypt:client:${id.uid}`); // set state set
|
|
251
|
+
const client = this.client();
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
253
|
+
this.state('set', `decrypt:encrypt:${id.uid}`); // set state set
|
|
254
|
+
const encrypt = {
|
|
255
|
+
iv: q.meta.params[1],
|
|
256
|
+
key: q.meta.params[2],
|
|
257
|
+
encrypted: q.text,
|
|
258
|
+
algorithm: global.encrypt.algorithm,
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.action('decrypt', id.uid); // set action hash
|
|
262
|
+
const decrypt = this.lib.decrypt(encrypt);
|
|
263
|
+
|
|
264
|
+
this.state('set', `decrypt:data:${id.uid}`); // set state set
|
|
265
|
+
const data = {
|
|
266
|
+
id,
|
|
267
|
+
agent,
|
|
268
|
+
decrypt,
|
|
269
|
+
encrypt,
|
|
270
|
+
};
|
|
271
271
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
272
|
+
this.action('hash', `decrypt:data:md5:${id.uid}`); // set action hash
|
|
273
|
+
data.md5 = this.hash(decrypt, 'md5');
|
|
274
|
+
this.action('hash', `decrypt:data:sha256:${id.uid}`); // set action hash
|
|
275
|
+
data.sha256 = this.hash(decrypt, 'sha256');
|
|
276
|
+
this.action('hash', `decrypt:data:sha512:${id.uid}`); // set action hash
|
|
277
|
+
data.sha512 = this.hash(decrypt, 'sha512');
|
|
278
|
+
|
|
279
|
+
const status = `${agent.key}:decrypt:${data.id.uid}`;
|
|
280
|
+
|
|
281
|
+
this.state('set', `decrypt:text:${id.uid}`); // set state set
|
|
282
|
+
const text = [
|
|
283
|
+
`${this.box.begin}:${status}`,
|
|
284
|
+
`uid: ${data.id.uid}`,
|
|
285
|
+
`decrypted: ${data.decrypt}`,
|
|
286
|
+
`time: ${data.id.time}`,
|
|
287
|
+
`date: ${data.id.date}`,
|
|
288
|
+
`warning: ${data.id.warning}`,
|
|
289
|
+
`copyright: ${data.id.copyright}`,
|
|
290
|
+
`md5: ${data.md5}`,
|
|
291
|
+
`sha256: ${data.sha256}`,
|
|
292
|
+
`sha512: ${data.sha512}`,
|
|
293
|
+
`${this.box.end}${status}`,
|
|
294
|
+
].join('\n');
|
|
295
|
+
|
|
296
296
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
297
|
+
this.action('return', `decrypt:${id.uid}`); // set action return
|
|
298
|
+
this.state('valid', `decrypt:${id.uid}`); // set action return
|
|
299
|
+
this.intent('good', `decrypt:${id.uid}`); // set action return
|
|
300
|
+
return {
|
|
301
|
+
text,
|
|
302
|
+
html: false,
|
|
303
|
+
data,
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
/**************
|
|
308
|
+
method: date
|
|
309
|
+
params: packet
|
|
310
|
+
describe: Return system date for today.
|
|
311
|
+
***************/
|
|
312
|
+
async date(packet) {
|
|
313
|
+
return new Promise((resolve, reject) => {
|
|
314
|
+
const id = this.uid();
|
|
315
|
+
const time = Date.now();
|
|
316
|
+
const {params} = packet.q.meta;
|
|
317
|
+
const {key} = this.agent();
|
|
318
|
+
this.zone('security', `date:${id.uid}`);
|
|
319
|
+
this.feature('security', `date:${id.uid}`);
|
|
320
|
+
this.action('method', `date:${id.uid}`);
|
|
321
|
+
|
|
322
|
+
this.state('set', `date:setFormat:${id.uid}`); // set state set
|
|
323
|
+
const setFormat = params[1] ? params[1] : 'long';
|
|
324
|
+
this.state('set', `date:setTime:${id.uid}`); // set state set
|
|
325
|
+
const setTime = params[2] ? packet.q.meta.params[2] : false;
|
|
326
|
+
|
|
327
|
+
this.state('set', `date:${id.uid}`);
|
|
328
|
+
const date = this.lib.formatDate(time, setFormat, setTime);
|
|
329
|
+
|
|
330
|
+
const data = {
|
|
331
|
+
id,
|
|
332
|
+
time,
|
|
333
|
+
date,
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
this.action('hash', `date:data:sha256:${id.uid}`); // set action hash
|
|
337
|
+
data.sha256 = this.hash(date, 'sha256');
|
|
338
|
+
|
|
339
|
+
const text = [
|
|
340
|
+
`${this.box.begin}:om:${key}:date:${data.id.uid}`,
|
|
341
|
+
`uid: ${data.id.uid}`,
|
|
342
|
+
`time: ${data.time}`,
|
|
343
|
+
`date: ${data.date}`,
|
|
344
|
+
`copyright: ${data.id.copyright}`,
|
|
345
|
+
`sha256: ${data.sha256}`,
|
|
346
|
+
`${this.box.end}:om:${key}:date:${data.id.uid}`
|
|
347
|
+
].join('\n');
|
|
348
|
+
|
|
349
|
+
this.question(`${this.askChr}feecting parse ${text}`).then(feecting => {
|
|
350
|
+
data.feecting = feecting;
|
|
351
|
+
this.action('return', `date:${id.uid}`);
|
|
352
|
+
this.state('valid', `date:${id.uid}`);
|
|
353
|
+
this.intent('good', `date:${id.uid}`);
|
|
354
|
+
return resolve({
|
|
355
|
+
text: feecting.a.text,
|
|
356
|
+
html: feecting.a.html,
|
|
357
|
+
data,
|
|
358
|
+
});
|
|
359
|
+
}).catch(err => {
|
|
360
|
+
return this.err(err, data, reject);
|
|
361
|
+
})
|
|
362
362
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
363
|
+
});
|
|
364
|
+
},
|
|
365
|
+
/**************
|
|
366
|
+
method: time
|
|
367
|
+
params: packet
|
|
368
|
+
describe: Return system date for today.
|
|
369
|
+
***************/
|
|
370
|
+
time(packet) {
|
|
371
|
+
const transport = packet.id;
|
|
372
|
+
this.zone('security', `time:${transport}`);
|
|
373
|
+
this.feature('security', `time:${transport}`);
|
|
374
|
+
this.action('method', `time:${transport}`);
|
|
375
|
+
this.state('get', `time:${transport}`);
|
|
376
|
+
const theTime = Date.now();
|
|
377
|
+
this.state('return', `time:${transport}`);
|
|
378
|
+
return Promise.resolve(theTime);
|
|
379
|
+
},
|
|
380
|
+
|
|
381
381
|
}
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// Wednesday, November 25, 2026 - 9:44:25 AM PST
|
|
7
7
|
|
|
8
8
|
import Deva from '@indra.ai/deva';
|
|
9
|
-
import { MongoClient
|
|
9
|
+
import { MongoClient } from 'mongodb';
|
|
10
10
|
|
|
11
11
|
import pkg from './package.json' with {type:'json'};
|
|
12
12
|
const {agent,vars} = pkg.data;
|
|
@@ -80,8 +80,8 @@ const SecurityDeva = new Deva({
|
|
|
80
80
|
onReady(data, resolve) {
|
|
81
81
|
const {VLA} = this.info();
|
|
82
82
|
const {uri, database, log} = this.security().global?.mongo || {};
|
|
83
|
-
this.vars.database = database; // set the main database
|
|
84
|
-
this.vars.log = log; // set the logging database
|
|
83
|
+
if (database) this.vars.database = database; // set the main database
|
|
84
|
+
if (log) this.vars.log = log; // set the logging database
|
|
85
85
|
if (uri) this.modules.client = new MongoClient(uri); // build the client if uri is set
|
|
86
86
|
this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
|
|
87
87
|
return resolve(data);
|
package/index.test.js
CHANGED
|
@@ -1,7 +1,262 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Security Deva Test File
|
|
3
|
-
// Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
4
|
-
// Owner Signature Required For Lawful Use.
|
|
3
|
+
// Copyright ©2000-2026 Quinn Michaels; All rights reserved.
|
|
4
|
+
// Owner Signature Required For Lawful Use.
|
|
5
5
|
// Distributed under VLA:15266350905933520771 LICENSE.md
|
|
6
6
|
// Wednesday, November 25, 2026 - 9:44:25 AM PST
|
|
7
7
|
|
|
8
|
+
// run with: node --test
|
|
9
|
+
// MongoDB tests use a local server at mongodb://127.0.0.1:27017 by default. Set MONGO_URI to use another one.
|
|
10
|
+
// They skip with a message when MongoDB can't be reached.
|
|
11
|
+
import test, {after} from 'node:test';
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import {execFile} from 'node:child_process';
|
|
14
|
+
import {promisify} from 'node:util';
|
|
15
|
+
import {dirname} from 'node:path';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {MongoClient} from 'mongodb';
|
|
18
|
+
import Deva from '@indra.ai/deva';
|
|
19
|
+
import core from '@indra.ai/deva/package.json' with {type:'json'};
|
|
20
|
+
import pkg from './package.json' with {type:'json'};
|
|
21
|
+
import featureMethods from './feature/methods.js';
|
|
22
|
+
import SECURITY from './index.js';
|
|
23
|
+
|
|
24
|
+
const DIR = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const STAGES = ['start', 'enter', 'done', 'ready'];
|
|
26
|
+
const TIERS = ['md5', 'sha256', 'sha512'];
|
|
27
|
+
const PLACEHOLDER = /::[a-z-]+::|\{\{profile\.[a-z]+\}\}/;
|
|
28
|
+
const FEATURE_KEYS = ['uid', 'sign', 'hash', 'encrypt', 'decrypt', 'date', 'time'];
|
|
29
|
+
|
|
30
|
+
// test databases: the uri can change, the names are fixed so the after hook only ever drops the test databases.
|
|
31
|
+
const MONGO_URI = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017';
|
|
32
|
+
const SECURITY_DB = 'deva_security_test';
|
|
33
|
+
const SECURITY_LOG = 'deva_security_log_test';
|
|
34
|
+
|
|
35
|
+
// check the server once before the tests are defined so the MongoDB tests can skip cleanly.
|
|
36
|
+
const mongo = new MongoClient(MONGO_URI, {serverSelectionTimeoutMS: 2000});
|
|
37
|
+
const MONGO_SKIP = await mongo.db('admin').command({ping: 1}).then(
|
|
38
|
+
() => false,
|
|
39
|
+
err => `MongoDB is not reachable at ${MONGO_URI} (${err.message}). Start a local mongod or set MONGO_URI.`
|
|
40
|
+
);
|
|
41
|
+
if (MONGO_SKIP) console.log(`⏭️ ${MONGO_SKIP}`);
|
|
42
|
+
|
|
43
|
+
// stub client built in code: the core VLA for the core check, the agent VLA for Security Deva
|
|
44
|
+
// and the mongo settings for the security feature. useMongo false leaves the security feature without a database.
|
|
45
|
+
const client = (agentVLA = pkg.VLA, useMongo = true, uri = MONGO_URI, methods = false) => ({
|
|
46
|
+
id: '00000000000000000000',
|
|
47
|
+
key: 'client',
|
|
48
|
+
VLA: structuredClone(core.VLA),
|
|
49
|
+
prompt: {
|
|
50
|
+
emoji: '🧪',
|
|
51
|
+
text: 'client',
|
|
52
|
+
colors: {
|
|
53
|
+
label: {R: 2, G: 229, B: 77},
|
|
54
|
+
text: {R: 2, G: 229, B: 77},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
profile: {
|
|
58
|
+
id: '00000000000000000000',
|
|
59
|
+
name: 'Test Client',
|
|
60
|
+
describe: 'Test client for Security Deva',
|
|
61
|
+
lang: 'en',
|
|
62
|
+
locale: 'en-US',
|
|
63
|
+
currency: 'USD',
|
|
64
|
+
},
|
|
65
|
+
features: {
|
|
66
|
+
license: {
|
|
67
|
+
concerns: [],
|
|
68
|
+
global: [],
|
|
69
|
+
devas: {
|
|
70
|
+
security: structuredClone(agentVLA),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
security: {
|
|
74
|
+
concerns: [],
|
|
75
|
+
global: useMongo ? {mongo: {uri, database: SECURITY_DB, log: SECURITY_LOG}} : {},
|
|
76
|
+
devas: useMongo ? {security: {mongo: {uri, database: SECURITY_DB, log: SECURITY_LOG}}} : {},
|
|
77
|
+
methods: methods || undefined,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
let securityClient = false; // Security Deva's own MongoClient, kept so the after hook can close it.
|
|
83
|
+
|
|
84
|
+
after(async () => {
|
|
85
|
+
if (!MONGO_SKIP) {
|
|
86
|
+
await mongo.db(SECURITY_DB).dropDatabase();
|
|
87
|
+
await mongo.db(SECURITY_LOG).dropDatabase();
|
|
88
|
+
}
|
|
89
|
+
await mongo.close();
|
|
90
|
+
if (securityClient) await securityClient.close();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('security builds as a Deva and waits offline before init', async () => {
|
|
94
|
+
assert.ok(SECURITY instanceof Deva, 'the export is a Deva');
|
|
95
|
+
assert.equal(await SECURITY.stop(), SECURITY._messages.offline, 'stop before init answers offline');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('security data has no placeholders left', () => {
|
|
99
|
+
assert.doesNotMatch(JSON.stringify(pkg.data), PLACEHOLDER, 'package.json data');
|
|
100
|
+
assert.doesNotMatch(JSON.stringify(pkg.VLA), PLACEHOLDER, 'package.json VLA');
|
|
101
|
+
assert.doesNotMatch(pkg.copyright, PLACEHOLDER, 'package.json copyright');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('func.write_log, onReady, onStop, and onError exist', () => {
|
|
105
|
+
assert.equal(typeof SECURITY.func.write_log, 'function', 'func.write_log');
|
|
106
|
+
assert.equal(typeof SECURITY.onReady, 'function', 'onReady');
|
|
107
|
+
assert.equal(typeof SECURITY.onStop, 'function', 'onStop');
|
|
108
|
+
assert.equal(typeof SECURITY.onError, 'function', 'onError');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('security comes online and walks to ready', async () => {
|
|
112
|
+
const prompts = [];
|
|
113
|
+
SECURITY.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
114
|
+
const data = await SECURITY.init(client());
|
|
115
|
+
for (const k of STAGES) assert.equal(typeof data[k], 'number', `${k} timestamp`);
|
|
116
|
+
assert.ok(data.start <= data.enter && data.enter <= data.done && data.done <= data.ready, 'stages in order');
|
|
117
|
+
assert.equal(typeof data.id.uid, 'string', 'uid');
|
|
118
|
+
for (const t of TIERS) assert.equal(typeof data[t], 'string', `${t} hash`);
|
|
119
|
+
assert.ok(prompts.includes(`${SECURITY.vars.messages.ready} > VLA:${pkg.VLA.uid}`), 'onReady prompts the ready message');
|
|
120
|
+
assert.ok(SECURITY.modules.client instanceof MongoClient, 'onReady builds the MongoClient');
|
|
121
|
+
assert.equal(SECURITY.vars.database, SECURITY_DB, 'onReady sets the security database');
|
|
122
|
+
assert.equal(SECURITY.vars.log, SECURITY_LOG, 'onReady sets the security log database');
|
|
123
|
+
securityClient = SECURITY.modules.client;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('security agent matches the package', () => {
|
|
127
|
+
const agent = SECURITY.agent();
|
|
128
|
+
assert.equal(agent.key, 'security');
|
|
129
|
+
assert.equal(agent.id, pkg.id);
|
|
130
|
+
assert.equal(agent.profile.id, pkg.id);
|
|
131
|
+
assert.equal(agent.profile.name, 'Security Deva');
|
|
132
|
+
assert.equal(agent.profile.owner, 'Quinn Michaels');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('security utils answer with trimmed text', () => {
|
|
136
|
+
const {translate, parse, process} = SECURITY.utils;
|
|
137
|
+
for (const util of [translate, parse, process]) assert.equal(util(' hello '), 'hello');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('security help pages name the Deva and carry the package license', async () => {
|
|
141
|
+
const main = await SECURITY.help('main', DIR);
|
|
142
|
+
assert.match(main, /^# \{\{profile\.name\}\}$/m, 'main help heading');
|
|
143
|
+
const license = await SECURITY.help('main:license', DIR);
|
|
144
|
+
assert.match(license, new RegExp(`^uid: ${pkg.VLA.uid}$`, 'm'), 'license uid');
|
|
145
|
+
for (const t of TIERS) assert.ok(license.includes(`${t}: ${pkg.VLA[t]}`), `${t} hash in the license help`);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// the feature loader binds client.features.security.methods onto the Deva at init.
|
|
149
|
+
// this uses a fresh instance so it does not change the methods on SECURITY.
|
|
150
|
+
test('feature methods from feature/methods.js load at runtime', async () => {
|
|
151
|
+
assert.deepEqual(Object.keys(featureMethods), FEATURE_KEYS, 'feature export names');
|
|
152
|
+
const {default: FEATURE} = await import('./index.js?feature');
|
|
153
|
+
const data = await FEATURE.init(client(pkg.VLA, false, MONGO_URI, featureMethods));
|
|
154
|
+
assert.equal(typeof data.ready, 'number', 'feature instance reaches ready');
|
|
155
|
+
for (const key of FEATURE_KEYS) assert.equal(typeof FEATURE.methods[key], 'function', `methods.${key}`);
|
|
156
|
+
await FEATURE.stop();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// onReady must read this.security().global?.mongo, not this.report() or this.legal().
|
|
160
|
+
test('onReady reads mongo from this.security() not another Deva', async () => {
|
|
161
|
+
const {default: CONFIG} = await import('./index.js?config');
|
|
162
|
+
const c = client();
|
|
163
|
+
c.features.report = {
|
|
164
|
+
concerns: [],
|
|
165
|
+
global: {mongo: {uri: MONGO_URI, database: 'WRONG_REPORT_DB', log: 'WRONG_REPORT_LOG'}},
|
|
166
|
+
devas: {},
|
|
167
|
+
};
|
|
168
|
+
c.features.legal = {
|
|
169
|
+
concerns: [],
|
|
170
|
+
global: {mongo: {uri: MONGO_URI, database: 'WRONG_LEGAL_DB', log: 'WRONG_LEGAL_LOG'}},
|
|
171
|
+
devas: {},
|
|
172
|
+
};
|
|
173
|
+
const data = await CONFIG.init(c);
|
|
174
|
+
assert.equal(typeof data.ready, 'number', 'config instance reaches ready');
|
|
175
|
+
assert.equal(CONFIG.vars.database, SECURITY_DB, 'database comes from this.security()');
|
|
176
|
+
assert.equal(CONFIG.vars.log, SECURITY_LOG, 'log comes from this.security()');
|
|
177
|
+
assert.notEqual(CONFIG.vars.database, 'WRONG_REPORT_DB');
|
|
178
|
+
assert.notEqual(CONFIG.vars.database, 'WRONG_LEGAL_DB');
|
|
179
|
+
await CONFIG.stop();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// onReady builds a MongoClient but does not connect, so an unreachable uri still reaches ready.
|
|
183
|
+
test('init with an unreachable MongoDB uri still reaches ready', async () => {
|
|
184
|
+
const {default: UNREACH} = await import('./index.js?unreachable');
|
|
185
|
+
const bad = 'mongodb://127.0.0.1:1';
|
|
186
|
+
const data = await UNREACH.init(client(pkg.VLA, true, bad));
|
|
187
|
+
assert.equal(typeof data.ready, 'number', 'unreachable uri still reaches ready');
|
|
188
|
+
assert.ok(UNREACH.modules.client instanceof MongoClient, 'onReady still builds the MongoClient');
|
|
189
|
+
assert.equal(UNREACH.vars.database, SECURITY_DB);
|
|
190
|
+
assert.equal(UNREACH.vars.log, SECURITY_LOG);
|
|
191
|
+
await UNREACH.stop();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('write_log inserts a document into the finish collection', {skip: MONGO_SKIP}, async () => {
|
|
195
|
+
const payload = {id: {uid: 'write-log-test-1'}, content: 'hello security', created: Date.now()};
|
|
196
|
+
const ans = await SECURITY.func.write_log('finish', payload);
|
|
197
|
+
assert.equal(ans.acknowledged, true);
|
|
198
|
+
const doc = await mongo.db(SECURITY_LOG).collection('finish').findOne({'id.uid': 'write-log-test-1'});
|
|
199
|
+
assert.equal(doc?.content, 'hello security');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// runs in a child process with a fresh Security Deva and no database, so it does not
|
|
203
|
+
// share the bound func object or MongoClient with the tests that use SECURITY.
|
|
204
|
+
// with no MongoDB client, write_log returns quietly with undefined and does not throw or hang.
|
|
205
|
+
test('write_log returns quietly when no MongoDB client is built', async () => {
|
|
206
|
+
const code = [
|
|
207
|
+
`const {default: SECURITY} = await import(${JSON.stringify(new URL('./index.js', import.meta.url).href)});`,
|
|
208
|
+
'await SECURITY.init(JSON.parse(process.env.SECURITY_TEST_CLIENT));',
|
|
209
|
+
"const payload = {id: {uid: 'write-log-missing-1'}, content: 'no mongo'};",
|
|
210
|
+
'let timer;',
|
|
211
|
+
'const ans = await Promise.race([',
|
|
212
|
+
' SECURITY.func.write_log("finish", payload),',
|
|
213
|
+
' new Promise((_, reject) => {timer = setTimeout(() => reject(new Error("TIMEOUT")), 8000);}),',
|
|
214
|
+
']).finally(() => clearTimeout(timer));',
|
|
215
|
+
'console.log(`ANSWER:${typeof ans}`);',
|
|
216
|
+
'await SECURITY.stop();',
|
|
217
|
+
'console.log("RESULT:ok");',
|
|
218
|
+
].join('\n');
|
|
219
|
+
const env = {PATH: process.env.PATH, SECURITY_TEST_CLIENT: JSON.stringify(client(pkg.VLA, false))};
|
|
220
|
+
const run = promisify(execFile)(process.execPath, ['--input-type=module', '-e', code], {cwd: DIR, env, timeout: 20000, killSignal: 'SIGKILL'});
|
|
221
|
+
const {stdout} = await run.catch(err => {
|
|
222
|
+
if (err.stdout) assert.fail(err.stdout.trim());
|
|
223
|
+
const why = err.killed ? 'did not return within 20 seconds' : `failed: ${err.message}`;
|
|
224
|
+
assert.fail(`write_log without a MongoDB client ${why}`);
|
|
225
|
+
});
|
|
226
|
+
assert.match(stdout, /^ANSWER:undefined$/m, 'write_log returns undefined without a client');
|
|
227
|
+
assert.match(stdout, /^RESULT:ok$/m, 'write_log returned without hanging');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('a stop and init restart builds a new MongoClient and can write_log again', {skip: MONGO_SKIP}, async () => {
|
|
231
|
+
const before = SECURITY.modules.client;
|
|
232
|
+
await SECURITY.stop();
|
|
233
|
+
const data = await SECURITY.init(client());
|
|
234
|
+
assert.equal(typeof data.ready, 'number', 'restart reaches ready');
|
|
235
|
+
assert.ok(SECURITY.modules.client instanceof MongoClient, 'restart builds a MongoClient');
|
|
236
|
+
assert.notEqual(SECURITY.modules.client, before, 'the MongoClient is new');
|
|
237
|
+
securityClient = SECURITY.modules.client;
|
|
238
|
+
const payload = {id: {uid: 'write-log-restart-1'}, content: 'after restart', created: Date.now()};
|
|
239
|
+
const ans = await SECURITY.func.write_log('complete', payload);
|
|
240
|
+
assert.equal(ans.acknowledged, true);
|
|
241
|
+
const doc = await mongo.db(SECURITY_LOG).collection('complete').findOne({'id.uid': 'write-log-restart-1'});
|
|
242
|
+
assert.equal(doc?.content, 'after restart');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('security stops through the full chain', async () => {
|
|
246
|
+
const data = await SECURITY.stop();
|
|
247
|
+
assert.equal(data.key, 'shutdown', 'the chain ends on shutdown');
|
|
248
|
+
assert.equal(data.value, 'security');
|
|
249
|
+
securityClient = false;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// the refusal check loads a fresh Security Deva instance from the same file, so it starts from a clean state.
|
|
253
|
+
test('security refuses to start with a bad agent VLA', async () => {
|
|
254
|
+
const {default: REFUSE} = await import('./index.js?refuse');
|
|
255
|
+
const prompts = [];
|
|
256
|
+
REFUSE.listen('devacore:prompt', packet => prompts.push(packet.text));
|
|
257
|
+
const result = await REFUSE.init(client({uid: 'bad'}));
|
|
258
|
+
assert.equal(result, REFUSE._messages.checkVLA, 'init answers with the invalid VLA message');
|
|
259
|
+
assert.ok(prompts.includes(REFUSE._messages.checkVLA), 'core prompts the invalid VLA message');
|
|
260
|
+
assert.equal(REFUSE._active, false, 'the Deva stays offline');
|
|
261
|
+
if (REFUSE.modules?.client) await REFUSE.modules.client.close();
|
|
262
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "15266350905933520771",
|
|
3
3
|
"name": "@indra.ai/deva.security",
|
|
4
|
-
"version": "0.37.
|
|
4
|
+
"version": "0.37.6",
|
|
5
5
|
"license": "VLA:15266350905933520771 LICENSE.md",
|
|
6
6
|
"VLA": {
|
|
7
7
|
"uid": "15266350905933520771",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"main": "index.js",
|
|
49
49
|
"type": "module",
|
|
50
50
|
"scripts": {
|
|
51
|
-
"test": "
|
|
51
|
+
"test": "node --test",
|
|
52
52
|
"latest": "npm i @indra.ai/deva@latest mongodb@latest --save"
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"emoji": "/assets/emoji.png",
|
|
116
116
|
"avatar": "/assets/avatar.png",
|
|
117
117
|
"image": "/assets/image.png",
|
|
118
|
-
"background": "/assets/background.
|
|
118
|
+
"background": "/assets/background.jpg",
|
|
119
119
|
"owner": "Quinn Michaels",
|
|
120
120
|
"creator": "Quinn Michaels",
|
|
121
121
|
"company": "Inside The Net, Inc.",
|