this.me 2.7.2 → 2.7.3

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.
@@ -0,0 +1,20 @@
1
+ // crypto-browser.js
2
+ async function generateKeyPair() {
3
+ const keyPair = await window.crypto.subtle.generateKey(
4
+ {
5
+ name: "RSASSA-PKCS1-v1_5",
6
+ modulusLength: 2048,
7
+ publicExponent: new Uint8Array([1, 0, 1]),
8
+ hash: "SHA-256"
9
+ },
10
+ true,
11
+ ["sign", "verify"]
12
+ );
13
+ return keyPair;
14
+ }
15
+ // ... other cryptographic operations using the Web Cryptography API ...
16
+ module.exports = {
17
+ generateKeyPair,
18
+ // ... export other cryptographic functions ...
19
+ };
20
+
@@ -0,0 +1,16 @@
1
+ // crypto-node.js
2
+ const crypto = require('crypto');
3
+ function generateKeyPair() {
4
+ const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
5
+ modulusLength: 2048,
6
+ });
7
+ return {
8
+ privateKey: privateKey.export({ type: 'pkcs1', format: 'pem' }),
9
+ publicKey: publicKey.export({ type: 'pkcs1', format: 'pem' }),
10
+ };
11
+ }
12
+ // ... other cryptographic operations using Node's crypto module ...
13
+ module.exports = {
14
+ generateKeyPair,
15
+ // ... export other cryptographic functions ...
16
+ };
package/demo.js CHANGED
@@ -1,17 +1,12 @@
1
1
  const Me = require('./me.js');
2
-
3
2
  // Create a new Me instance
4
3
  const suign = new Me('Suign Name', 'suign@email.com', '01/01/1990', { city: 'SampleCity', country: 'SampleCountry' }, { theme: 'dark', notifications: true });
5
-
6
4
  // Print out the public key (for demonstration purposes)
7
5
  console.log("Suign's Public Key:", suign.getPublicKey());
8
-
9
6
  // Example: Sign some data
10
7
  const dataToSign = "Hello, World!";
11
8
  const signature = suign.signData(dataToSign);
12
-
13
9
  console.log("Signature for 'Hello, World!':", signature.toString('base64')); // Base64 encoding just to make the signature more readable in console.
14
-
15
10
  // Example: Verify the signature
16
11
  const isValidSignature = suign.verifySignature(dataToSign, signature);
17
12
  console.log("Is the signature valid?", isValidSignature);
package/main.js CHANGED
@@ -19,7 +19,7 @@ const me = new Me(
19
19
  country: 'replaceCountry' },
20
20
  { theme: 'dark' }
21
21
  );
22
- // Your CLI logic goes here, display welcome message, handle other commands, etc.
22
+ //CLI LOGIC
23
23
  function displayWelcomeMessage() {
24
24
  console.log(`
25
25
  ___________
@@ -48,7 +48,7 @@ console.log("System Role: ", cleaked.role);
48
48
  /* Create a function that computes the hash of the @src directory.
49
49
  'hashSrc') to handle hashing when the relevant command is passed to the script.*/
50
50
  const { fork } = require('child_process');
51
- const { getAllFiles, hashThis } = require('this.me/hash/hashing');
51
+ const { getAllFiles, hashThis } = require('this.me/crypto/hash/hashing');
52
52
  function hashSrc() {
53
53
  try {
54
54
  // Adjust this to the exact location of your @src directory
@@ -59,7 +59,6 @@ console.log("System Role: ", cleaked.role);
59
59
  console.error('Error hashing @src directory:', error.message);
60
60
  }
61
61
  }
62
-
63
62
  // COMMAND HANDLERS
64
63
  switch(args[0]) {
65
64
  case 'hash-src':
package/me.js CHANGED
@@ -1,6 +1,10 @@
1
- //me.js
2
- const crypto = require('crypto');
3
-
1
+ // me.js
2
+ let cryptoModule;
3
+ if (typeof window !== 'undefined' && typeof window.crypto !== 'undefined') {
4
+ cryptoModule = require('./crypto/crypto-browser');
5
+ } else {
6
+ cryptoModule = require('./crypto/crypto-node');
7
+ }
4
8
  class Me {
5
9
  constructor(name, email, birthDate, location = {}, preferences = {}) {
6
10
  this.name = name;
@@ -9,35 +13,11 @@ class Me {
9
13
  this.location = location;
10
14
  this.preferences = preferences;
11
15
  // Generate key pair upon instantiation
12
- this.keyPair = this.generateKeyPair();
13
- }
14
- generateKeyPair() {
15
- const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
16
- modulusLength: 2048,
17
- });
18
- return {
19
- privateKey: privateKey.export({ type: 'pkcs1', format: 'pem' }),
20
- publicKey: publicKey.export({ type: 'pkcs1', format: 'pem' }),
21
- };
22
- }
23
- getPublicKey() {
24
- return this.keyPair.publicKey;
25
- }
26
- // Use the private key for signing data, and the public key can be shared for verification
27
- signData(data) {
28
- const sign = crypto.createSign('SHA256');
29
- sign.update(data);
30
- sign.end();
31
- return sign.sign(this.keyPair.privateKey);
32
- }
33
- verifySignature(data, signature) {
34
- const verify = crypto.createVerify('SHA256');
35
- verify.update(data);
36
- verify.end();
37
- return verify.verify(this.keyPair.publicKey, signature);
38
- }
39
- updateLocation(newLocation) {
40
- this.location = newLocation;
16
+ this.keyPair = cryptoModule.generateKeyPair();
17
+ // ... rest of your class logic using the cryptoModule abstraction ...
41
18
  }
19
+ // ... other methods ...
42
20
  }
43
21
  module.exports = Me;
22
+
23
+
package/me2.js ADDED
@@ -0,0 +1,57 @@
1
+ //me.js
2
+ const crypto = require('crypto');
3
+ class Me {
4
+ constructor(name, email, birthDate, location = {}, preferences = {}) {
5
+ this.name = name;
6
+ this.email = email;
7
+ this.birthDate = birthDate;
8
+ this.location = location;
9
+ this.preferences = preferences;
10
+ // Generate key pair upon instantiation
11
+ this.keyPair = this.generateKeyPair();
12
+ }
13
+ generateKeyPair() {
14
+ const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
15
+ modulusLength: 2048,
16
+ });
17
+ return {
18
+ privateKey: privateKey.export({ type: 'pkcs1', format: 'pem' }),
19
+ publicKey: publicKey.export({ type: 'pkcs1', format: 'pem' }),
20
+ };
21
+ }
22
+ getPublicKey() {
23
+ return this.keyPair.publicKey;
24
+ }
25
+ // Use the private key for signing data, and the public key can be shared for verification
26
+ signData(data) {
27
+ const sign = crypto.createSign('SHA256');
28
+ sign.update(data);
29
+ sign.end();
30
+ return sign.sign(this.keyPair.privateKey);
31
+ }
32
+ verifySignature(data, signature) {
33
+ const verify = crypto.createVerify('SHA256');
34
+ verify.update(data);
35
+ verify.end();
36
+ return verify.verify(this.keyPair.publicKey, signature);
37
+ }
38
+ updateLocation(newLocation) {
39
+ this.location = newLocation;
40
+ }
41
+ }
42
+ module.exports = Me;
43
+
44
+
45
+
46
+ /*
47
+ Face Recognition:
48
+ async recognizeFace(imageData): This method would use an API or library to recognize the user's face. This can be useful for biometric-based authentication.
49
+ Connect Social Media:
50
+
51
+ connectSocialMedia(platform, credentials): This method would handle integration with various social media platforms. The platform parameter would specify which platform (e.g., "Facebook", "Twitter", "LinkedIn"), and the credentials would contain the necessary authentication details.
52
+ Password Management:
53
+
54
+ addPassword(website, password): Store a password for a particular website.
55
+ getPassword(website): Retrieve the stored password for a specific website.
56
+ generateStrongPassword(): Generate a random, strong password based on certain criteria.
57
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "this.me",
3
- "version": "2.7.2",
3
+ "version": "2.7.3",
4
4
  "description": "This.me should This.be",
5
5
  "bin": {
6
6
  ".me": "./main.js"
@@ -29,7 +29,7 @@
29
29
  "i.mlearning": "^2.2.0",
30
30
  "netget": "^2.2.3",
31
31
  "neurons.me": "^2.7.1",
32
- "this.atom":"1.2.2",
32
+ "this.atom":"^1.3.2",
33
33
  "this.audio": "^1.0.6",
34
34
  "this.be": "^2.1.6",
35
35
  "this.dom": "^1.0.4",
@@ -0,0 +1,18 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './me.js', // Your main file
5
+ output: {
6
+ filename: 'bundle.js', // Output bundle file
7
+ path: path.resolve(__dirname, 'dist') // Directory where bundle.js will be placed
8
+ },
9
+ mode: 'production', // Use 'development' for debugging and development purposes
10
+ module: {
11
+ rules: [
12
+ // You can add loaders here if needed, for instance, for processing other file types or transpiling code.
13
+ ]
14
+ },
15
+ plugins: [
16
+ // Add any webpack plugins here if necessary.
17
+ ]
18
+ };
@@ -1,29 +0,0 @@
1
- const neurons = require('neurons.me');
2
- const { logError } = require('./errorHandler');
3
- module.exports = (rl) => {
4
- const showLayerMenu = () => {
5
- console.log('\nLayers:');
6
- console.log('1. Create a new layer');
7
- console.log('2. List all layers');
8
- console.log('3. Back to Main Menu');
9
- };
10
-
11
- const createLayer = () => {
12
- // Logic to create a new layer
13
- const layer = new neurons.Layer();
14
- console.log('New layer created:', layer);
15
- };
16
-
17
- const listAllLayers = () => {
18
- const allLayers = neurons.Layer.map;
19
- if (allLayers.size === 0) {
20
- console.log('No layers found.');
21
- } else {
22
- console.log('List of all layers:');
23
- allLayers.forEach((layer, id) => {
24
- console.log(`Layer ID: ${id}`, layer);
25
- });
26
- }
27
- };
28
- return { showLayerMenu, createLayer, listAllLayers };
29
- };// end module exports
@@ -1,32 +0,0 @@
1
- const neurons = require('neurons.me');
2
- const { logError } = require('./errorHandler');
3
- const prompt = (question) => new Promise((resolve) => rl.question(question, resolve));
4
-
5
- module.exports = (rl) => {
6
- const showNeuralNetworkMenu = () => {
7
- console.log('\nNeural Networks:');
8
- console.log('1. Create a new neural network');
9
- console.log('2. List all neural networks');
10
- console.log('3. Back to Main Menu');
11
- };
12
-
13
- const createNeuralNetwork = () => {
14
- // Logic to create a new neural network
15
- const neuralNetwork = new neurons.NeuralNetwork();
16
- console.log('New neural network created:', neuralNetwork);
17
- };
18
-
19
- const listAllNeuralNetworks = () => {
20
- const allNeuralNetworks = neurons.NeuralNetwork.map;
21
- if (allNeuralNetworks.size === 0) {
22
- console.log('No neural networks found.');
23
- } else {
24
- console.log('List of all neural networks:');
25
- allNeuralNetworks.forEach((neuralNetwork, id) => {
26
- console.log(`Neural Network ID: ${id}`, neuralNetwork);
27
- });
28
- }
29
- };
30
-
31
- return { showNeuralNetworkMenu, createNeuralNetwork, listAllNeuralNetworks };
32
- };
@@ -1,201 +0,0 @@
1
- // ./src/NeuronsHandler.js
2
- const neurons = require('neurons.me');
3
- const { logError } = require('@sui.gn/me/src/errorHandler');
4
- const { showMenu } = require('./utils');
5
- const prompt = (rl, question) => new Promise((resolve) => rl.question(question, resolve));
6
- //neuron handler
7
- module.exports = (rl) => {
8
- const showNeuronMenu = () => {
9
- console.log('\nNeurons:');
10
- console.log('0. Back to Main Menu');
11
- console.log('1. Create a new neuron');
12
- console.log('2. List all neurons');
13
- console.log('3. Editing Neurons');
14
- };
15
- const neuronConfig = async (rl, neuron, updateNeuronProperties, cloneNeuron) => {
16
- console.log(`\nTailoring Neuron ID: ${neuron.processID}`);
17
- console.log('0. Back to Main Menu');
18
- console.log('1. Edit Properties.');
19
- console.log('2. Clone this neuron');
20
- console.log('3. Back to Neurons Menu');
21
- const action = await prompt(rl, 'Choose an action: ');
22
- switch (action.trim()) {
23
- case '0':
24
- showMenu(rl);
25
- break;
26
- case '1':
27
- await updateNeuronProperties(neuron, rl, neuronConfig);
28
- break;
29
- case '2':
30
- await cloneNeuron(neuron, rl, neuronConfig);
31
- break;
32
- case '3':
33
- showNeuronMenu();
34
- break;
35
- default:
36
- console.log('Invalid action. Back to Neuron Menu.');
37
- showNeuronMenu();
38
- }
39
- };
40
- const showNeuronProperties = (neuron) => {
41
- console.log('\nSelected Neuron Properties:');
42
- console.log('Selected Neuron ID:', neuron.processID);
43
- console.log('Name:', neuron.name);
44
- console.log('Date:', neuron.date);
45
- console.log('Time:', neuron.time);
46
- console.log('Color:', neuron.color);
47
- console.log('Activation Function:', neuron.activationFunction.toString());
48
- console.log('Weights:', neuron.weights);
49
- console.log('Bias:', neuron.bias);
50
- };
51
- const promptNeuronConfig = async (rl, updateNeuronProperties, cloneNeuron, showMenu) => {
52
- try {
53
- const option = await prompt('Choose the ID of the neuron you want to access (or "back" to go back): ');
54
- if (option.toLowerCase() === 'back') {
55
- showNeuronMenu();
56
- } else {
57
- const neuronId = parseInt(option);
58
- const neuron = neurons.Neuron.map.get(neuronId);
59
- if (!neuron) {
60
- console.log('Neuron with the specified ID not found.');
61
- await promptNeuronConfig(updateNeuronProperties, cloneNeuron, showMenu);
62
- } else {
63
- await neuronConfig(neuron, updateNeuronProperties, cloneNeuron, showMenu);
64
- }
65
- }
66
- } catch (error) {
67
- logError(error);
68
- }
69
- };
70
- const listAllNeurons = () => {
71
- const allNeurons = neurons.Neuron.map;
72
- if (allNeurons.size === 0) {
73
- console.log('No neurons found.');
74
- } else {
75
- console.log('List of all neurons:');
76
- allNeurons.forEach((neuron, id) => {
77
- console.log(`${id}.`, neuron);
78
- });
79
- }
80
- showMenu(rl, showNeuronMenu);
81
- };
82
- const createNeuron = async (rl, updateNeuronProperties, cloneNeuron, showMenu) => {
83
- try {
84
- const name = await prompt(rl, 'Enter the name of the neuron: ');
85
- const color = await prompt(rl, 'Enter the color: ');
86
- const activation = await prompt(rl, 'Enter the activation function: ');
87
- const weights = await prompt(rl, 'Enter the weights: ');
88
- const bias = await prompt(rl, 'Enter the bias: ');
89
- const neuronOptions = {
90
- name,
91
- color,
92
- activation,
93
- weights,
94
- bias,
95
- };
96
- const neuron = new neurons.Neuron(neuronOptions);
97
- console.log('New neuron created:', neuron);
98
- await neuronConfig(rl, neuron, updateNeuronProperties, cloneNeuron, showMenu);
99
- } catch (error) {
100
- logError(error);
101
- }
102
- };
103
- const cloneNeuron = async (neuron, rl, updateNeuronProperties, showMenu) => {
104
- try {
105
- const name = await prompt(rl, 'Enter the name of the new neuron: ');
106
-
107
- const clonedNeuron = new neurons.Neuron({
108
- ...neuron,
109
- name,
110
- });
111
-
112
- console.log('New neuron cloned:', clonedNeuron);
113
- showNeuronActions(clonedNeuron, rl, updateNeuronProperties, cloneNeuron, showMenu);
114
- } catch (error) {
115
- logError(error);
116
- }
117
- };
118
- const updateNeuronProperties = async (rl, neuron, cloneNeuron, showMenu) => {
119
- try {
120
- console.log('\nSelected Neuron Properties:');
121
- showNeuronProperties(neuron);
122
- const confirmation = await prompt(rl, '\nAre you sure you want to update properties? (yes/no): ');
123
- if (confirmation.trim().toLowerCase() !== 'yes') {
124
- console.log('Update canceled. Back to Neuron Menu.');
125
- showNeuronActions(neuron, rl, updateNeuronProperties, cloneNeuron, showMenu);
126
- return;
127
- }
128
- let updatedActivation = neuron.activationFunction.toString();
129
- let updatedWeights = neuron.weights;
130
- let updatedBias = neuron.bias;
131
- while (true) {
132
- console.log('\n1. Enter the new activation function');
133
- console.log('2. Enter the new weights');
134
- console.log('3. Enter the new bias');
135
- console.log('4. Update all properties');
136
- console.log('5. Save changes');
137
- console.log('6. Back');
138
- const propertyAction = await prompt(rl, '\nChoose an action: ');
139
- switch (propertyAction.trim()) {
140
- case '1':
141
- updatedActivation = await prompt(rl, 'Enter the new activation function: ');
142
- break;
143
- case '2':
144
- updatedWeights = await prompt(rl, 'Enter the new weights: ');
145
- break;
146
- case '3':
147
- updatedBias = await prompt(rl, 'Enter the new bias: ');
148
- break;
149
- case '4':
150
- const confirmUpdateAll = await prompt(rl, '\nAre you sure you want to update all properties? (yes/no): ');
151
- if (confirmUpdateAll.trim().toLowerCase() === 'yes') {
152
- updatedActivation = await prompt(rl, 'Enter the new activation function: ');
153
- updatedWeights = await prompt(rl, 'Enter the new weights: ');
154
- updatedBias = await prompt(rl, 'Enter the new bias: ');
155
- }
156
- break;
157
- case '5':
158
- neuron.activationFunction = eval(updatedActivation); // Converting the updatedActivation string back to a function
159
- neuron.weights = updatedWeights;
160
- neuron.bias = updatedBias;
161
- console.log('\nUpdated Neuron Properties:');
162
- neuronConfig(rl, neuron, updateNeuronProperties, cloneNeuron, showMenu);
163
- const finalConfirmation = await prompt(rl, '\nDo you want to apply these changes? (yes/no): ');
164
- if (finalConfirmation.trim().toLowerCase() !== 'yes') {
165
- console.log('Changes not applied. Back to Neuron Menu.');
166
- } else {
167
- console.log('Neuron properties updated successfully.');
168
- }
169
- neuronConfig(rl, neuron, updateNeuronProperties, cloneNeuron, showMenu);
170
- return;
171
- case '6':
172
- console.log('Update canceled. Back to Neuron Menu.');
173
- neuronConfig(rl, neuron, updateNeuronProperties, cloneNeuron, showMenu);
174
- return;
175
- default:
176
- console.log('Invalid action. Please choose a valid action.');
177
- }
178
- }
179
- } catch (error) {
180
- logError(error);
181
- }
182
- };
183
- return {
184
- showNeuronMenu,
185
- promptNeuronConfig,
186
- listAllNeurons,
187
- createNeuron,
188
- neuronConfig,
189
- updateNeuronProperties,
190
- cloneNeuron
191
- };
192
- }
193
-
194
- /*Input Validation: It would be better to add some form of input validation.
195
- For example, when setting the weights or bias of a neuron,
196
- you could check that the user's input is a valid number.
197
- Security: Be careful when using eval().
198
- eval() evaluates a string of JavaScript code in the global context,
199
- which can lead to security issues. If the string comes from an untrusted source,
200
- it can potentially run malicious code. If you need to convert a string to a function,
201
- consider safer alternatives.*/
package/src/utils.js DELETED
@@ -1,17 +0,0 @@
1
- //CLASSES
2
- class Menu {
3
- constructor(rl) {
4
- this.rl = rl;
5
- }
6
- prompt(question) {
7
- return new Promise((resolve) => this.rl.question(question, resolve));
8
- }
9
- async display() {
10
- throw new Error('Method display() must be implemented by subclass');
11
- }
12
- async handleInput(input) {
13
- throw new Error('Method handleInput() must be implemented by subclass');
14
- }
15
- }
16
-
17
- module.exports = Menu;
File without changes
File without changes