this.me 2.9.1 → 2.9.4

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.
@@ -1,201 +0,0 @@
1
- import inquirer from 'inquirer';
2
- import path from 'path';
3
- import os from 'os';
4
- import fs from 'fs';
5
- import Me from 'this.me';
6
-
7
- /***Interactive Shell:
8
- * Leverages the `inquirer` package to provide an interactive shell experience with prompts.
9
- * The `main` function orchestrates the CLI interactions.
10
- */
11
-
12
- /**
13
- * View Existing Profiles, Create New Profile, Exit.
14
- * @returns {Promise<string>} The user's choice.
15
- */
16
- async function selectMe() {
17
- const choices = ['View Existing Profiles', 'Create New Profile', 'Exit'];
18
- const answer = await inquirer.prompt([{
19
- type: 'list',
20
- name: 'action',
21
- message: 'What would you like to do?',
22
- choices: choices
23
- }]);
24
- return answer.action;
25
- }
26
-
27
- /**
28
- * Prompts the user for details to create a new profile.
29
- * @returns {Promise<Me>} The new Me object with user details.
30
- */
31
- async function createMe() {
32
- const questions = [
33
- {
34
- type: 'input',
35
- name: 'name',
36
- message: 'What is your first name?',
37
- // Add validation as needed
38
- },
39
- {
40
- type: 'input',
41
- name: 'lastname',
42
- message: 'What is your last name?',
43
- // Add validation as needed
44
- },
45
- {
46
- type: 'input',
47
- name: 'birthday',
48
- message: 'What is your birthday? (YYYY-MM-DD)',
49
- validate: function(value) {
50
- const pass = value.match(
51
- /^\d{4}-\d{2}-\d{2}$/
52
- );
53
- if (pass) {
54
- return true;
55
- }
56
- return 'Please enter a valid date (YYYY-MM-DD)';
57
- }
58
- },
59
- {
60
- type: 'password',
61
- name: 'password',
62
- message: 'Choose a password:',
63
- // Add validation as needed
64
- },
65
- {
66
- type: 'input',
67
- name: 'pin',
68
- message: 'Choose a PIN:',
69
- // Add validation as needed
70
- },
71
- // ... Add more questions as needed
72
- ];
73
- const userDetails = await inquirer.prompt(questions);
74
- return new Me(
75
- userDetails.name,
76
- userDetails.lastname,
77
- userDetails.birthday,
78
- userDetails.password,
79
- userDetails.pin
80
- );
81
- }
82
-
83
- /**
84
- * Writes the .me object to the filesystem.
85
- * @param {Me} meProfile - The Me object to be saved.
86
- */
87
- function writeMe(meProfile) {
88
- const meDirectory = path.join(os.homedir(), '.me');
89
- if (!fs.existsSync(meDirectory)) {
90
- fs.mkdirSync(meDirectory, { recursive: true });
91
- }
92
-
93
- const filePath = path.join(meDirectory, `${meProfile.name}.me`);
94
- // Encrypting the data here before writing to the filesystem
95
- //fs.writeFileSync(filePath, JSON.stringify(meProfile.getIdentityObject()));
96
- //console.log('Profile created successfully.');
97
- fs.writeFileSync(filePath, JSON.stringify(meProfile.getMe()));
98
- console.log('Profile created successfully.');
99
- }
100
-
101
- /**
102
- * Lists all the .me profile file paths in the user's .me directory.
103
- * @returns {string[]} An array of full file paths for each .me profile.
104
- */
105
- function listMeProfiles() {
106
- const meDirectory = path.join(os.homedir(), '.me');
107
- if (fs.existsSync(meDirectory)) {
108
- const profileFiles = fs.readdirSync(meDirectory)
109
- .filter(file => file.endsWith('.me'));
110
- return profileFiles.map(file => path.join(meDirectory, file));
111
- } else {
112
- console.log('No profiles found.');
113
- return [];
114
- }
115
- }
116
-
117
- /**
118
- * Asks the user to verify their PIN.
119
- * @param {Object} profile - The user's profile object containing their data, including the PIN.
120
- * @returns {Promise<string>} Returns 'success' if the PIN is correct, 'back' to return to the previous menu.
121
- */
122
- async function verifyPin(profile) {
123
- while (true) {
124
- const answer = await inquirer.prompt([{
125
- type: 'password',
126
- name: 'pin',
127
- message: 'Enter your PIN to proceed:',
128
- }]);
129
-
130
- if (answer.pin === profile.pin) {
131
- // Correct PIN
132
- //console.log('Profile Data:', profile);
133
- console.log(`Welcome ${profile.name}!`);
134
- return 'success';
135
- } else {
136
- // Incorrect PIN
137
- console.log('Incorrect PIN.');
138
- const retryChoice = await inquirer.prompt([{
139
- type: 'list',
140
- name: 'action',
141
- message: 'What would you like to do?',
142
- choices: ['Try Again', 'Go Back']
143
- }]);
144
- if (retryChoice.action === 'Go Back') {
145
- return 'back';
146
- }
147
- }
148
- }
149
- }
150
-
151
- /**
152
- * Allows the user to select a .me profile from a list or go back to the main menu.
153
- * After selecting a profile, the user is asked to verify their PIN.
154
- * @returns {Promise<Object|string>} Returns the selected profile object upon successful PIN verification, or 'back' to indicate returning to the main menu.
155
- */
156
- async function selectProfile() {
157
- const profiles = listMeProfiles();
158
- if (profiles.length === 0) {
159
- console.log('No profiles found.');
160
- return 'back';
161
- }
162
-
163
- const choices = profiles.map(file => ({
164
- name: path.basename(file, '.me'),
165
- value: file
166
- })).concat([{ name: 'Go Back to Main Menu', value: 'back' }]);
167
-
168
- const answer = await inquirer.prompt([{
169
- type: 'list',
170
- name: 'selectedProfile',
171
- message: 'Select a profile to view or go back:',
172
- choices: choices
173
- }]);
174
-
175
- if (answer.selectedProfile === 'back') {
176
- return 'back';
177
- } else {
178
- const profileData = fs.readFileSync(answer.selectedProfile, 'utf8');
179
- const profile = JSON.parse(profileData);
180
-
181
- const pinVerified = await verifyPin(profile);
182
- if (!pinVerified) {
183
- console.log('PIN verification failed. Returning to main menu.');
184
- return 'back';
185
- }
186
-
187
- // After successful PIN verification, proceed to a different section of the CLI.
188
- // ... Transition to different CLI section logic goes here ...
189
-
190
- return profile; // Return the profile data for further processing if needed.
191
- }
192
- }
193
-
194
-
195
- export const shell = {
196
- selectMe,
197
- createMe,
198
- writeMe,
199
- listMeProfiles,
200
- selectProfile,
201
- };
package/src/z_hist/env.js DELETED
@@ -1,8 +0,0 @@
1
- // env.js
2
- // Detect if running in Node.js or Browser
3
- let isNodeEnvironment = (typeof process !== 'undefined' && process.versions && process.versions.node);
4
- if (isNodeEnvironment) {
5
- module.exports = require('./me-node');
6
- } else {
7
- module.exports = require('./me-browser');
8
- }
@@ -1,24 +0,0 @@
1
- const crypto = require('crypto');
2
-
3
- function generateKeyPair() {
4
- const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
5
- modulusLength: 2048,
6
- publicKeyEncoding: {
7
- type: 'spki',
8
- format: 'pem',
9
- },
10
- privateKeyEncoding: {
11
- type: 'pkcs8',
12
- format: 'pem',
13
- },
14
- });
15
-
16
- // Store the keys securely (e.g., in files or secure storage).
17
-
18
- return { publicKey, privateKey };
19
- }
20
-
21
- // Example usage:
22
- const { publicKey, privateKey } = generateKeyPair();
23
- console.log('Public Key:', publicKey);
24
- console.log('Private Key:', privateKey);
package/src/z_hist/me.js DELETED
@@ -1,49 +0,0 @@
1
- //src/me.js
2
- /**
3
- * Represents a user identity in the this.me system.
4
- */
5
- class Me {
6
- /**
7
- * Create a me instance.
8
- * @param {string} name - The first name of the user.
9
- * @param {string} lastname - The last name of the user.
10
- * @param {string} birthday - The birthday of the user in YYYY-MM-DD format.
11
- * @param {string} password - The password chosen by the user.
12
- * @param {string} pin - The personal identification number chosen by the user.
13
- */
14
- constructor(name, lastname, birthday, password, pin) {
15
- this.name = name;
16
- this.lastname = lastname;
17
- this.birthday = birthday;
18
- this.password = password;
19
- this.pin = pin;
20
- }
21
-
22
- /**
23
- * Validates the user data. Throws an error if any field is empty.
24
- * @throws Will throw an error if a required field is missing.
25
- */
26
- validateData() {
27
- if (!this.name || !this.lastname || !this.birthday || !this.password || !this.pin) {
28
- throw new Error("All fields must be filled");
29
- }
30
- // Further validation rules can be added here
31
- }
32
-
33
- /**
34
- * Prepares and returns the identity object for hashing .me.
35
- * @returns {Object} The identity object (.me) with user data.
36
- */
37
- getMe() {
38
- this.validateData();
39
- return {
40
- name: this.name,
41
- lastname: this.lastname,
42
- birthday: this.birthday,
43
- password: this.password, // Password as a separate field
44
- pin: this.pin // Pin as a separate field
45
- };
46
- }
47
- }
48
-
49
- export default Me;