this.me 2.7.5 → 2.7.7
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/Me.js +71 -0
- package/README.md +8 -170
- package/demo.js +1 -1
- package/main.js +5 -15
- package/me.html +30 -0
- package/package.json +1 -1
- package/me.js +0 -51
package/Me.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
}
|
|
8
|
+
|
|
9
|
+
class Me {
|
|
10
|
+
constructor(name, email, birthDate, location = {}, preferences = {}) {
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.email = email;
|
|
13
|
+
this.birthDate = birthDate;
|
|
14
|
+
this.location = location;
|
|
15
|
+
this.preferences = preferences;
|
|
16
|
+
// Social Media Accounts
|
|
17
|
+
this.socialMedia = {
|
|
18
|
+
facebook: {
|
|
19
|
+
appId: 'YOUR_FACEBOOK_APP_ID', // Replace with your actual Facebook App ID
|
|
20
|
+
token: null
|
|
21
|
+
}
|
|
22
|
+
// ... You can add more platforms here
|
|
23
|
+
};
|
|
24
|
+
// Generate key pair upon instantiation
|
|
25
|
+
this.keyPair = cryptoModule.generateKeyPair();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
connectFacebook(token) {
|
|
29
|
+
this.socialMedia.facebook.token = token;
|
|
30
|
+
// You can expand this function to do more, like fetch the user's profile data using the token.
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getFacebookToken() {
|
|
34
|
+
return this.socialMedia.facebook.token;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// the public key can be shared for verification
|
|
38
|
+
getPublicKey() {
|
|
39
|
+
return this.keyPair.publicKey;
|
|
40
|
+
}
|
|
41
|
+
// Use the private key for signing data.
|
|
42
|
+
signData(data) {
|
|
43
|
+
try {
|
|
44
|
+
const sign = cryptoModule.createSign('SHA256');
|
|
45
|
+
sign.update(data);
|
|
46
|
+
sign.end();
|
|
47
|
+
return sign.sign(this.keyPair.privateKey);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("Error during signing data: ", err);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
verifySignature(data, signature) {
|
|
55
|
+
try {
|
|
56
|
+
const verify = cryptoModule.createVerify('SHA256');
|
|
57
|
+
verify.update(data);
|
|
58
|
+
verify.end();
|
|
59
|
+
return verify.verify(this.keyPair.publicKey, signature);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error("Error during verifying signature: ", err);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
updateLocation(newLocation) {
|
|
67
|
+
this.location = newLocation;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = Me;
|
package/README.md
CHANGED
|
@@ -1,91 +1,26 @@
|
|
|
1
1
|
<img src="./_._.svg" alt="SVG Image" width="123" height="123" style="width123px; height:123px;">
|
|
2
2
|
|
|
3
|
-
# .me
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
```
|
|
7
|
-
npm install this.me
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
Add to your project:
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
let me = require('this.me');
|
|
14
|
-
```
|
|
15
|
-
**Docs:** [this.me](https://www.neurons.me/this-me)
|
|
16
|
-
### Conceptual Flow:
|
|
17
|
-
- [ ] Set up your context with [this.me.](https://www.npmjs.com/package/this.me)
|
|
18
|
-
- [ ] Create a neural network using [neurons.me](https://www.neurons.me).
|
|
19
|
-
- [ ] Define the data you'd like your neural network to recognize or process with [this.](https://www.neurons.me/this) modules.
|
|
20
|
-
- [ ] Use [this.be](https://www.npmjs.com/package/this.be) to maintain a state or context, - watching over [This](https://www.neurons.me/this) and any other states you define for example.
|
|
21
|
-
- [ ] Define desired status and handlers, [be.this](https://www.npmjs.com/package/be.this).
|
|
22
|
-
- [ ] Keep [i.mlearning](https://www.npmjs.com/package/i.mlearning).
|
|
23
|
-
|
|
24
|
-
# Quick Start with Sandbox.
|
|
25
|
-
|
|
26
|
-
1. **Clone this Sandbox Demo Repository**
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
git clone https://github.com/suiGn/sandbox.git
|
|
30
|
-
```
|
|
31
|
-
2. **Navigate to the Project Directory**
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
cd .me
|
|
35
|
-
```
|
|
36
|
-
3. **Install Dependencies**
|
|
37
|
-
You can use either Yarn or npm to install the necessary dependencies.
|
|
38
|
-
|
|
39
|
-
**Using Yarn:**
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
yarn install
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Using npm:**
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npm install
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
4. **Launch the Application**
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
npx electron index.js
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
This model turns the traditional web model on its head. Users no longer depend on centralized authorities for identity or data management. They hold the keys (literally) to their identity and data. Services become more user-centric, providing services based on cryptographic proofs rather than centralized databases.
|
|
58
|
-
|
|
59
|
-
While this approach offers many benefits, including enhanced privacy and user sovereignty, it's still nascent and requires a paradigm shift in development, deployment, and user education.
|
|
60
|
-
|
|
61
|
-
In an audacious twist of fate, I decided to circumvent the monotony of user session code and dive into the cryptographic labyrinth. Rather than getting bogged down by yawn-worthy password management and playing custodian to a sea of data, I embraced a vision where every individual holds the scepter to their digital kingdom. Centralized authorities? Toss 'em out the window. Here, you own your identity, seal it with cryptographic flair, and let no one else govern it. Sure, crafting a cryptographic symphony is no walk in the park, but compared to the drudgery of traditional server management, it feels like reinventing the wheel... but in a world where wheels were never round to begin with. Behold a system where every user is a master, every piece of data a treasure, all guarded by codes and ciphers. A little unorthodox, perhaps, but in an age of digital renaissance, who wants orthodox anyway?
|
|
62
|
-
|
|
63
|
-
I'd sooner recode the Old and New Testaments, heck, throw in the Qabala too, in ASCII, before willingly plunging into the dull abyss of server-side user session management. Why swim in those murky waters when I can bask in the cryptographic labyrinth? Ditching the monotony of password management, I decided to champion a world where every individual becomes the keeper of their digital realms. Centralized authorities? More like relics of a bygone era. Here, you don't just own your identity; you seal it with cryptographic brilliance, untouched and ungoverned by any other. Crafting this cryptographic symphony may seem daunting, but compared to the tedium of server management?
|
|
64
|
-
|
|
65
|
-
POC || GTFO but for now I am traveling to new york.
|
|
3
|
+
# .me
|
|
4
|
+
I decided to circumvent the monotony of user session code and dive into the cryptographic labyrinth.
|
|
5
|
+
I'd sooner recode the Old and New Testaments, heck, throw in the Qabala too, in ASCII, before willingly plunging into the dull abyss of server-side user session management.
|
|
66
6
|
|
|
67
7
|
# Setting up your Context. 👋🏻👋🏼👋🏽👋🏾👋🏿
|
|
68
8
|
Defining the **environment** and context in which your code runs, especially when you're interacting with intelligent agents or services like **me.**
|
|
69
9
|
Having a clear declaration of the environment and the context can have a series of implications for security, interoperability, and clarity. The codebase is often vast, dynamic, and continually evolving. Given the dynamic nature of such environments, ensuring the integrity of the code and data becomes paramount. You wouldn't want an agent to execute or rely on code that has been tampered with or is different from the expected version. This is where hashing comes into play.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Even a tiny change in the content will result in a completely different hash.
|
|
73
|
-
[Read More.](https://www.neurons.me/this-me#h.sg59uu9ka8i8)
|
|
10
|
+
Continue reading about this:
|
|
11
|
+
https://www.mlearning.studio/data-formats/this-me
|
|
74
12
|
|
|
75
13
|
## Quickstart Guide: Understanding `Me`
|
|
76
|
-
|
|
77
|
-
### Introduction:
|
|
78
|
-
|
|
79
14
|
Run node **demo.js** for quick example.
|
|
80
15
|
|
|
81
16
|
```js
|
|
82
|
-
const Me = require('
|
|
17
|
+
const Me = require('this.me');
|
|
83
18
|
```
|
|
84
19
|
|
|
85
20
|
```js
|
|
86
21
|
// Create a new Me instance
|
|
87
22
|
const suign = new Me('Suign Name', 'suign@email.com', '01/01/1990', { city: 'SampleCity', country: 'SampleCountry' }, { theme: 'dark', notifications: true });
|
|
88
|
-
// Print out the public key
|
|
23
|
+
// Print out the public key
|
|
89
24
|
console.log("Suign's Public Key:", suign.getPublicKey());
|
|
90
25
|
// Example: Sign some data
|
|
91
26
|
const dataToSign = "Hello, World!";
|
|
@@ -96,7 +31,7 @@ const isValidSignature = suign.verifySignature(dataToSign, signature);
|
|
|
96
31
|
console.log("Is the signature valid?", isValidSignature);
|
|
97
32
|
```
|
|
98
33
|
|
|
99
|
-
**`Me`** is a digital identity representation
|
|
34
|
+
**`Me`** is a digital identity representation. `Me` encapsulates the essence of an entity with cryptographic guarantees.
|
|
100
35
|
|
|
101
36
|
### Key Features:
|
|
102
37
|
|
|
@@ -111,7 +46,6 @@ console.log("Is the signature valid?", isValidSignature);
|
|
|
111
46
|
- It can register, authenticate, and perform actions with a guarantee of its identity.
|
|
112
47
|
|
|
113
48
|
### Purpose:
|
|
114
|
-
|
|
115
49
|
1. **Enhanced Security**
|
|
116
50
|
- Traditional authentication systems have vulnerabilities (e.g., password breaches). `Me` ensures that without the private key, impersonation is nearly impossible.
|
|
117
51
|
2. **Decentralization Ready**
|
|
@@ -121,109 +55,13 @@ console.log("Is the signature valid?", isValidSignature);
|
|
|
121
55
|
4. **Simplicity**
|
|
122
56
|
- Instead of managing multiple credentials for different services, `Me` offers a unified identity that's recognized across the network.
|
|
123
57
|
|
|
124
|
-
### Getting Started:
|
|
125
|
-
|
|
126
|
-
1. **Initialization**:
|
|
127
|
-
- Create an instance: `const myProfile = new Me('Name', 'email@email.com', 'birthdate', {location}, {preferences});`
|
|
128
|
-
2. **Key Management**:
|
|
129
|
-
- Use integrated cryptographic methods to sign and verify data.
|
|
130
|
-
- Always ensure the private key remains confidential.
|
|
131
|
-
3. **Interactions**:
|
|
132
|
-
- With the public key as an identifier, use `Me` to interact with services, sign transactions, or prove identity in network communications.
|
|
133
|
-
|
|
134
|
-
------
|
|
135
|
-
|
|
136
|
-
Remember, while `Me` provides enhanced security, the principle of key management is paramount. Losing access to the private key might mean losing access to the associated identity.
|
|
137
|
-
|
|
138
|
-
Let's delve into the importance of such declarations:
|
|
139
|
-
|
|
140
|
-
### Security Context:
|
|
141
|
-
Defining the environment ensures that both the user and the IA have a clear understanding of the boundary within which interactions take place.
|
|
142
|
-
Explicitly stating the environment can prevent unintended cross-boundary actions. For instance, without a clear declaration, an IA might access files or services that are beyond its permitted scope, leading to potential security vulnerabilities.
|
|
143
|
-
A well-defined environment acts as a sandbox that can restrict unauthorized or unintended activities. For instance, browsers use a similar principle to run JavaScript in a sandboxed environment for security reasons.
|
|
144
|
-
|
|
145
|
-
**Interoperability:**
|
|
146
|
-
As the ecosystem of software and services becomes increasingly diverse, ensuring your code can interact smoothly with other systems becomes crucial.
|
|
147
|
-
Declaring the environment or context helps ensure that all systems are on the "same page". For example, if an IA knows it's operating within the ".me" context, it can adjust its behavior, assumptions, and dependencies accordingly.
|
|
148
|
-
|
|
149
|
-
**Auditability and Compliance:**
|
|
150
|
-
For industries or applications where audit trails and compliance are important, having a clear declaration of the environment ensures that every interaction and operation can be traced back to a defined context.
|
|
151
|
-
Such clear demarcations can aid in forensic analysis if something goes wrong or if there's a need to understand the context of an interaction.
|
|
152
|
-
|
|
153
58
|
### Conclusion:
|
|
154
59
|
In the broader context of a dynamic and interactive environment like the one you're building, hashing becomes a powerful tool. It's not just about verifying code; it's about ensuring the entire ecosystem's security, integrity, and seamless operation. By employing a hashing mechanism, you're taking a proactive step towards establishing trust in the code and data that powers your system.
|
|
155
60
|
|
|
156
|
-
### Dependencies:
|
|
157
|
-
```json
|
|
158
|
-
"dependencies": {
|
|
159
|
-
"be.this": "^1.1.3",
|
|
160
|
-
"cleaker": "^2.2.9",
|
|
161
|
-
"i.mlearning": "^2.1.7",
|
|
162
|
-
"netget": "^2.1.6",
|
|
163
|
-
"neurons.me": "^2.6.3",
|
|
164
|
-
"this.atom": "^1.0.3",
|
|
165
|
-
"this.audio": "^1.0.0",
|
|
166
|
-
"this.be": "^2.1.3",
|
|
167
|
-
"this.dom": "^1.0.0",
|
|
168
|
-
"this.pixel": "^3.3.5",
|
|
169
|
-
"this.pixelgrid": "^3.3.2",
|
|
170
|
-
"this.text": "^1.0.0",
|
|
171
|
-
"v.path": "^2.1.7"
|
|
172
|
-
},
|
|
173
|
-
```
|
|
174
|
-
|
|
175
61
|
# Context of Abstraction for Machine Learning Standardization
|
|
176
|
-
|
|
177
|
-
Traditional web development elements, from images to audio, are designed mainly for display and interaction. But what if they could be seamlessly converted into standardized formats primed for machine learning? That's the vision behind the **this.** modules.
|
|
178
|
-
|
|
179
|
-
An Introduction to the this. JavaScript Library: Standardizing Web Development Elements for Machine Learning.
|
|
180
|
-
|
|
181
|
-
## Principles Behind the this. Library:
|
|
182
|
-
|
|
183
|
-
- ### **Abstraction for ML:**
|
|
184
|
-
|
|
185
|
-
The library's core principle is to abstract traditional web elements so that they're immediately primed for machine learning. It's about viewing web content not just as data but as structured, consistent, and standardized data.
|
|
186
|
-
|
|
187
|
-
- ### **Built on Web Standards:**
|
|
188
|
-
|
|
189
|
-
Rooted in JavaScript, the this. library builds upon public web development standards. The aim is to ensure that developers remain within familiar territories, even as they venture into the world of machine learning.
|
|
190
|
-
|
|
191
|
-
- ### **Open and Collaborative:**
|
|
192
|
-
|
|
193
|
-
The this. library champions open standards. By leveraging public web standards, it invites collaboration, hoping to create a community that continually refines and enhances the bridge between web development and machine learning.
|
|
194
|
-
|
|
195
62
|
[neurons.me](https://www.neurons.me)
|
|
196
|
-
|
|
197
63
|
[neurons.me/this](https://www.neurons.me/this)
|
|
198
64
|
|
|
199
|
-
# Clone THIS DEMO Playground
|
|
200
|
-
Welcome to the THIS.ME Playground, where the entire THIS.ME suite comes together with NEURONS.ME to provide a rich development and execution environment for your AI adventures.
|
|
201
|
-
|
|
202
|
-
## Sandbox Demo Quick Start
|
|
203
|
-
### 1. Clone the Repository
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
git clone https://github.com/suiGn/.me.git
|
|
207
|
-
```
|
|
208
|
-
### 2. Navigate to the Project Directory
|
|
209
|
-
```bash
|
|
210
|
-
cd .me
|
|
211
|
-
```
|
|
212
|
-
### 3. Install Dependencies
|
|
213
|
-
You can use either Yarn or npm to install the necessary dependencies.
|
|
214
|
-
Using Yarn:
|
|
215
|
-
```bash
|
|
216
|
-
yarn install
|
|
217
|
-
```
|
|
218
|
-
Using npm:
|
|
219
|
-
```bash
|
|
220
|
-
npm install
|
|
221
|
-
```
|
|
222
|
-
### 4. Launch the Application
|
|
223
|
-
```
|
|
224
|
-
npx electron index.js
|
|
225
|
-
```
|
|
226
|
-
|
|
227
65
|
**## License & Policies**
|
|
228
66
|
\- ***\*License\****: MIT License (see LICENSE for details).
|
|
229
67
|
\- ***\*Privacy Policy\****: Respects user privacy; no collection/storage of personal data.
|
package/demo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Me = require('./
|
|
1
|
+
const Me = require('./me2.js');
|
|
2
2
|
// Create a new Me instance
|
|
3
3
|
const suign = new Me('Suign Name', 'suign@email.com', '01/01/1990', { city: 'SampleCity', country: 'SampleCountry' }, { theme: 'dark', notifications: true });
|
|
4
4
|
// Print out the public key (for demonstration purposes)
|
package/main.js
CHANGED
|
@@ -5,15 +5,12 @@ const path = require("path");
|
|
|
5
5
|
const crypto = require('crypto');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
|
-
const neurons = require("neurons.me");
|
|
9
|
-
const cleaker = require("cleaker");
|
|
10
|
-
const netget = require("netget");
|
|
11
8
|
//User Context.
|
|
12
|
-
const Me = require("./me");
|
|
13
9
|
const os = require('os');
|
|
10
|
+
const Me = require('./Me');
|
|
14
11
|
const me = new Me(
|
|
15
12
|
'Me',
|
|
16
|
-
'
|
|
13
|
+
'enter your email.',
|
|
17
14
|
'replaceDateOfBirth',
|
|
18
15
|
{ city: 'replaceCity',
|
|
19
16
|
country: 'replaceCountry' },
|
|
@@ -35,15 +32,11 @@ function displayWelcomeMessage() {
|
|
|
35
32
|
| ^^^^^^^^^^^^^^^^^^^^ |
|
|
36
33
|
[---------------------------------.me-----------]
|
|
37
34
|
-^^^^^^^^zzzz...
|
|
38
|
-
Welcome to .me
|
|
35
|
+
Welcome to .me.
|
|
39
36
|
`);
|
|
40
|
-
console.log(me.getPublicKey());
|
|
41
|
-
const cleaked = new cleaker();
|
|
42
37
|
console.log(`Host_Session@ ${os.userInfo().username}`);
|
|
43
|
-
console.log(
|
|
38
|
+
console.log(`v.path@ ${os.homedir()}`);
|
|
44
39
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
40
|
//.. THIS SECTION IS FOR HASHING PURPOSES ...//
|
|
48
41
|
/* Create a function that computes the hash of the @src directory.
|
|
49
42
|
'hashSrc') to handle hashing when the relevant command is passed to the script.*/
|
|
@@ -52,7 +45,7 @@ console.log("System Role: ", cleaked.role);
|
|
|
52
45
|
function hashSrc() {
|
|
53
46
|
try {
|
|
54
47
|
// Adjust this to the exact location of your @src directory
|
|
55
|
-
const srcDirPath = path.resolve(__dirname, '@
|
|
48
|
+
const srcDirPath = path.resolve(__dirname, '@me');
|
|
56
49
|
const hash = hashThis(srcDirPath);
|
|
57
50
|
console.log(`Hash of @src directory: ${hash}`);
|
|
58
51
|
} catch (error) {
|
|
@@ -78,9 +71,6 @@ switch(args[0]) {
|
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
module.exports = {
|
|
81
|
-
cleaker,
|
|
82
|
-
netget,
|
|
83
|
-
neurons,
|
|
84
74
|
getAllFiles,
|
|
85
75
|
hashThis,
|
|
86
76
|
hashSrc
|
package/me.html
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>.me</title>
|
|
4
|
+
</head>
|
|
5
|
+
<body>
|
|
6
|
+
Hello, me!
|
|
7
|
+
<script>
|
|
8
|
+
window.fbAsyncInit = function() {
|
|
9
|
+
FB.init({
|
|
10
|
+
appId : '{your-app-id}',
|
|
11
|
+
cookie : true,
|
|
12
|
+
xfbml : true,
|
|
13
|
+
version : '{api-version}'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
FB.AppEvents.logPageView();
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
(function(d, s, id){
|
|
21
|
+
var js, fjs = d.getElementsByTagName(s)[0];
|
|
22
|
+
if (d.getElementById(id)) {return;}
|
|
23
|
+
js = d.createElement(s); js.id = id;
|
|
24
|
+
js.src = "https://connect.facebook.net/en_US/sdk.js";
|
|
25
|
+
fjs.parentNode.insertBefore(js, fjs);
|
|
26
|
+
}(document, 'script', 'facebook-jssdk'));
|
|
27
|
+
</script>
|
|
28
|
+
</body>
|
|
29
|
+
|
|
30
|
+
</html>
|
package/package.json
CHANGED
package/me.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
|
8
|
-
class Me {
|
|
9
|
-
constructor(name, email, birthDate, location = {}, preferences = {}) {
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.email = email;
|
|
12
|
-
this.birthDate = birthDate;
|
|
13
|
-
this.location = location;
|
|
14
|
-
this.preferences = preferences;
|
|
15
|
-
// Generate key pair upon instantiation
|
|
16
|
-
this.keyPair = cryptoModule.generateKeyPair();
|
|
17
|
-
// ... rest of your class logic using the cryptoModule abstraction ...
|
|
18
|
-
}
|
|
19
|
-
// ... methods ...
|
|
20
|
-
generateKeyPair() {
|
|
21
|
-
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
|
|
22
|
-
modulusLength: 2048,
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
privateKey: privateKey.export({ type: 'pkcs1', format: 'pem' }),
|
|
26
|
-
publicKey: publicKey.export({ type: 'pkcs1', format: 'pem' }),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
getPublicKey() {
|
|
30
|
-
return this.keyPair.publicKey;
|
|
31
|
-
}
|
|
32
|
-
// Use the private key for signing data, and the public key can be shared for verification
|
|
33
|
-
signData(data) {
|
|
34
|
-
const sign = crypto.createSign('SHA256');
|
|
35
|
-
sign.update(data);
|
|
36
|
-
sign.end();
|
|
37
|
-
return sign.sign(this.keyPair.privateKey);
|
|
38
|
-
}
|
|
39
|
-
verifySignature(data, signature) {
|
|
40
|
-
const verify = crypto.createVerify('SHA256');
|
|
41
|
-
verify.update(data);
|
|
42
|
-
verify.end();
|
|
43
|
-
return verify.verify(this.keyPair.publicKey, signature);
|
|
44
|
-
}
|
|
45
|
-
updateLocation(newLocation) {
|
|
46
|
-
this.location = newLocation;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
module.exports = Me;
|
|
50
|
-
|
|
51
|
-
|