this.me 2.9.4 → 2.9.5
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 +215 -89
- package/bin/me.cli.js +99 -0
- package/index.js +6 -6
- package/jsdoc.json +41 -0
- package/notes/Entonces_Que_es_me.md +9 -0
- package/notes/Index of this.me Structure.md +154 -0
- package/notes/Index.md +134 -0
- package/{md/context.md → notes/Inmutabilidad_de_la_Identidad_basica.md} +4 -2
- package/notes/Questions.md +62 -0
- package/notes/Summary.md +125 -0
- package/notes/The Problem: Decentralized Yet Trustworthy.md +13 -0
- package/notes/Understanding me && you && himContext.md +11 -0
- package/notes/hot_encoding.md +44 -0
- package/package.json +4 -3
- package/src/example.js +1 -1
- package/src/me.js +129 -37
- package/src/methods/attributes.js +79 -0
- package/src/methods/identity.js +31 -0
- package/src/methods/properties.js +73 -0
- package/src/methods/reactions.js +31 -0
- package/src/methods/relationships.js +26 -0
- package/src/scripts/setup.js +19 -0
- package/src/scripts/setup_validation.js +31 -0
- package/src/.me.cli.js +0 -20
package/notes/Index.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
### **Index of `this.me` Structure**
|
|
2
|
+
Here’s a comprehensive list of the components and their purposes within the `this.me` class:
|
|
3
|
+
|
|
4
|
+
#### **1. Identity**
|
|
5
|
+
- **Description:** Immutable attributes defining the core identity of the user.
|
|
6
|
+
#### **2. Attributes**
|
|
7
|
+
- **Description:** Flexible traits and descriptive properties of the user.
|
|
8
|
+
#### **3. Relationships**
|
|
9
|
+
- **Description:** Connections and associations with others.
|
|
10
|
+
#### **4. Reactions**
|
|
11
|
+
- **Description:** User’s interactions and engagements with the world.
|
|
12
|
+
#### **5. Properties**
|
|
13
|
+
- **Description:** Items owned or managed by the user.
|
|
14
|
+
|
|
15
|
+
------
|
|
16
|
+
|
|
17
|
+
### **1. The Me Structure Overview**
|
|
18
|
+
#### **Core Components**
|
|
19
|
+
- **Identity:** The foundation of the `this.me` object.
|
|
20
|
+
- Immutable attributes: `username`, `DID`.
|
|
21
|
+
- Core methods for validation and setup.
|
|
22
|
+
|
|
23
|
+
------
|
|
24
|
+
|
|
25
|
+
- **Attributes:** Fundamental identity traits.
|
|
26
|
+
Store and manage user traits dynamically:
|
|
27
|
+
- Examples: Name, age, location, pronouns, bio.
|
|
28
|
+
**Use `.be()` to add or update attributes.**
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
```json
|
|
32
|
+
{ name: 'John Doe', age: 30, location: 'Earth' }
|
|
33
|
+
```
|
|
34
|
+
Implement `be()` as a flexible key-value store.
|
|
35
|
+
Add validation for specific attributes (if required).
|
|
36
|
+
|
|
37
|
+
------
|
|
38
|
+
|
|
39
|
+
- **Relationships:** Connections with others.
|
|
40
|
+
- Examples: Friends, groups, networks, organizations.
|
|
41
|
+
**Contacts:** Individual connections.
|
|
42
|
+
**Groups:** Collections of users with shared context.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
.relationships.addContact({ username: 'alice', status: 'friend' });
|
|
46
|
+
.relationships.createGroup({ name: 'Family', members: ['alice', 'bob'] });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Define `addContact` and `createGroup` methods.
|
|
50
|
+
Enable nested relationship structures (e.g., groups of groups).
|
|
51
|
+
|
|
52
|
+
------
|
|
53
|
+
|
|
54
|
+
- **Reactions:** How a user interacts with the world.
|
|
55
|
+
Streamline all user engagements under `.react()`
|
|
56
|
+
- Examples: Likes, comments, shares, emotions.
|
|
57
|
+
- Categorization Rationale:
|
|
58
|
+
- Keeps all engagements unified.
|
|
59
|
+
- Expands easily (adding emojis, advanced reactions).
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
.react.add({ type: 'like', target: 'PostID' });
|
|
63
|
+
.react.add({ type: 'comment', target: 'PhotoID', content: 'Great pic!' });
|
|
64
|
+
```
|
|
65
|
+
Design a structure to store and retrieve reactions efficiently.
|
|
66
|
+
Define a `log` system for reaction history.
|
|
67
|
+
|
|
68
|
+
------
|
|
69
|
+
|
|
70
|
+
- **Properties:** Things the user owns or manages.
|
|
71
|
+
Attach external, modular objects as user-owned assets:
|
|
72
|
+
- Use `this.me.properties` as a unified interface for ownership.
|
|
73
|
+
- Modular objects like `Wallet`, `Device`, `File`.
|
|
74
|
+
- Examples: Wallets, devices, digital files, accounts.
|
|
75
|
+
- **Sub-Methods:** Add, Share, Transfer Ownership, Revoke Access.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const jabellae = new Me('jabellae'); // Create a new Me instance
|
|
79
|
+
const wallet = new Wallet({ type: 'ETH', address: '0x123...' }); // Create a wallet object
|
|
80
|
+
jabellae.addProperty(wallet); // Add wallet as a property to Me
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Implement `add`, `share`, `transferOwnership`, and `revokeAccess` methods for properties. Define modular objects (`Wallet`, `Device`) independently.
|
|
84
|
+
|
|
85
|
+
1. **Creating a Wallet**
|
|
86
|
+
The wallet is created independently and then added to the `Me` instance's properties.
|
|
87
|
+
```javascript
|
|
88
|
+
const jabellae = new Me('jabellae'); // Create a new Me instance
|
|
89
|
+
const wallet = new Wallet({ type: 'ETH', address: '0x123...' }); // Create a wallet object
|
|
90
|
+
jabellae.addProperty(wallet); // Add wallet as a property to Me
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
2. **Sharing the Wallet**
|
|
94
|
+
Sharing logic is handled by the `Me` instance, not the property itself.
|
|
95
|
+
```javascript
|
|
96
|
+
jabellae.shareProperty(wallet, 'otherMe', { permissions: 'view' });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
3. **Transferring Ownership**
|
|
100
|
+
Ownership transfer is also managed by the `Me` instance.
|
|
101
|
+
```javascript
|
|
102
|
+
jabellae.transferOwnership(wallet, 'otherMe');
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
------
|
|
106
|
+
------
|
|
107
|
+
------
|
|
108
|
+
|
|
109
|
+
### **2. Why Independent Objects?**
|
|
110
|
+
#### **Modularity**
|
|
111
|
+
- Keeps the `this.me` instance *agnostic* of specifics.
|
|
112
|
+
- Allows new property types to integrate seamlessly.
|
|
113
|
+
|
|
114
|
+
#### **Reusability**
|
|
115
|
+
- Each property (e.g., `this.wallet`, `this.device`) operates independently.
|
|
116
|
+
- Can be ported across `this.me` instances without coupling.
|
|
117
|
+
|
|
118
|
+
#### **Transferability**
|
|
119
|
+
- Ownership is a property-level concern.
|
|
120
|
+
- Example:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
const wallet = new Wallet(owner = "me");
|
|
124
|
+
wallet.transferOwnership("otherMeInstance");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### **Separation of Concerns**
|
|
128
|
+
- Identity (`this.me`) manages relationships, attributes, and higher-level user interactions.
|
|
129
|
+
- Objects like `Wallet` or `Device` manage their specific functionality.
|
|
130
|
+
|
|
131
|
+
#### **Scalability**
|
|
132
|
+
- Adding a new property type is as simple as:
|
|
133
|
+
1. Defining the object (e.g., `Vehicle`).
|
|
134
|
+
2. Registering it with `this.me`.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
El mayor acto de rebelión en un mundo que busca controlarte es ser libre de verdad.
|
|
2
|
+
|
|
3
|
+
**this.me** y el proceso de autenticación con **Cleaker** como una red de identificación descentralizada (**DID**) tiene sentido dentro de un marco de criptografía y autenticación distribuida. A continuación, desgloso los puntos importantes para asegurarnos de que el concepto sea claro y funcional:
|
|
2
4
|
|
|
3
5
|
### **Inmutabilidad de la Identidad Básica**
|
|
4
|
-
|
|
6
|
+
**this.me** se basa en la creación de una identidad. Los componentes inmutables que mencionas (nombre de usuario, email y la red de autenticación) son fundamentales para que el sistema garantice que la identidad siempre se pueda verificar a partir de un hash único.
|
|
5
7
|
|
|
6
8
|
1. **Nombre de Usuario (username)**: El nombre de usuario es clave en la identidad. No puede cambiar una vez creado porque el hash que lo representa depende de esta cadena de caracteres.
|
|
7
9
|
2. **Correo Electrónico (email)**: Esto actúa como otra pieza inmutable, probablemente porque es un dato importante para autenticar usuarios a través de redes o servicios.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Key Questions to Address
|
|
2
|
+
Identity Core: What defines the essence of .me?
|
|
3
|
+
Relationships: How does .me relate to others, groups, or larger entities?
|
|
4
|
+
Belongings: What does .me own or have as personal items?
|
|
5
|
+
Modularity: How do we allow external objects to seamlessly integrate with .me?
|
|
6
|
+
Hierarchy of Interactions: How do we classify interactions into tiers (self, relationships, society, etc.)?
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### **1. Identity Core: What defines the essence of `.me`?**
|
|
10
|
+
- **Essence Defined:**
|
|
11
|
+
- **Immutable Core Attributes:** `username` and `DID` (Decentralized Identifier).
|
|
12
|
+
- Clearly distinguishes the user's unique existence in the digital realm.
|
|
13
|
+
- **Practical Implementation:**
|
|
14
|
+
- Identity core is foundational and unchangeable, ensuring trust and consistency across systems.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### **2. Relationships: How does `.me` relate to others, groups, or larger entities?**
|
|
19
|
+
- **Connections Defined:**
|
|
20
|
+
- **Contacts:** Direct relationships (e.g., friends, acquaintances).
|
|
21
|
+
- **Groups:** Collections with shared contexts (e.g., family, organizations, societies).
|
|
22
|
+
- **Methods:**
|
|
23
|
+
- `.relationships.addContact()` to add individual connections.
|
|
24
|
+
- `.relationships.createGroup()` to organize groups dynamically.
|
|
25
|
+
- **Hierarchy:**
|
|
26
|
+
- Nested structures enable relationships at various tiers (e.g., groups of groups, organizations within societies).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### **3. Belongings: What does `.me` own or have as personal items?**
|
|
31
|
+
- **Properties Defined:**
|
|
32
|
+
- Everything the user owns or manages (e.g., wallets, devices, digital files).
|
|
33
|
+
- **Methods for Ownership:**
|
|
34
|
+
- `.properties.add()`, `.properties.share()`, `.properties.transferOwnership()`, `.properties.revokeAccess()`.
|
|
35
|
+
- **Modular Approach:**
|
|
36
|
+
- Allows external objects like `Wallet`, `Device`, or `Vehicle` to integrate without hardcoding.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### **4. Modularity: How do we allow external objects to seamlessly integrate with `.me`?**
|
|
41
|
+
- **Independent Objects:**
|
|
42
|
+
- Objects like `Wallet`, `Device`, etc., are designed and managed outside the `this.me` instance.
|
|
43
|
+
- **Integration:**
|
|
44
|
+
- These objects are registered to `this.me` via methods like `.addProperty()`.
|
|
45
|
+
- They maintain their internal logic while adhering to the ownership and interaction protocols defined by `.me`.
|
|
46
|
+
- **Advantages:**
|
|
47
|
+
- Scalability: Easy to introduce new objects without modifying the `this.me` core.
|
|
48
|
+
- Transferability: Ownership can move across `.me` instances seamlessly.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### **5. Hierarchy of Interactions: How do we classify interactions into tiers (self, relationships, society, etc.)?**
|
|
53
|
+
- **Tiers of Interactions:**
|
|
54
|
+
- **Reactions:** Personal engagements (`like`, `comment`, `share`).
|
|
55
|
+
- **Relationships:** Broader social connections (individuals, groups, organizations).
|
|
56
|
+
- **Attributes:** How `.me` defines itself (e.g., status, bio, pronouns).
|
|
57
|
+
- **Properties:** Interaction with owned or managed items.
|
|
58
|
+
- **Unified Structure:**
|
|
59
|
+
- Centralized under `.reactions` and `.relationships`.
|
|
60
|
+
- Interaction types remain modular and expandable, allowing for a hierarchy to emerge naturally through usage (e.g., personal to societal interactions).
|
|
61
|
+
|
|
62
|
+
---
|
package/notes/Summary.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# this.me — Identity System
|
|
2
|
+
|
|
3
|
+
## ✨ Summary
|
|
4
|
+
`this.me` is a decentralized identity system designed to allow users to manage their own identities locally, with optional validation by external authorities such as Cleaker. It combines privacy, user control, and secure interoperability.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## 🔐 Identity Model Comparison
|
|
8
|
+
| **Model** | **Where your identity lives** | **Local signing** | **Real freedom** |
|
|
9
|
+
|----------------------|-------------------------------|-------------------|--------------------------|
|
|
10
|
+
| Web2 (Facebook, etc) | On their servers | ❌ | ❌ |
|
|
11
|
+
| Web3 (wallets) | In extensions or apps | ✅ | 🟡 (fragmented) |
|
|
12
|
+
| `this.me` | In your OS `.this/me/` | ✅✅ | ✅✅✅ |
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🔍 Core Principles
|
|
17
|
+
1. **Freedom to Declare**
|
|
18
|
+
Anyone can generate a `.me` identity locally without external approval.
|
|
19
|
+
2. **Trusted Endorsements**
|
|
20
|
+
Authorities (e.g., Cleaker) can endorse `.me` identities without controlling them.
|
|
21
|
+
3. **Local Ownership**
|
|
22
|
+
All sensitive data (including private keys) stays on the user's machine.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
## 📁 File Structure
|
|
26
|
+
* `~/.this/me/username.me.json` — Encrypted identity file
|
|
27
|
+
* `.me` includes:
|
|
28
|
+
|
|
29
|
+
* `username`
|
|
30
|
+
* `publicKey`, `privateKey` (encrypted)
|
|
31
|
+
* `attributes`, `relationships`, `reactions`, `properties`, `relationships`
|
|
32
|
+
* `endorsements`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🔎 Identity Lifecycle
|
|
37
|
+
|
|
38
|
+
### 1. Create Identity
|
|
39
|
+
```bash
|
|
40
|
+
me create jabellae
|
|
41
|
+
# Prompts for hash (e.g. 4242)
|
|
42
|
+
# Generates encrypted .me file
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Register/Endorse with Authority
|
|
46
|
+
```bash
|
|
47
|
+
me endorse --with cleaker
|
|
48
|
+
# Signs and shares publicKey with Cleaker
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Verify Identity
|
|
52
|
+
```bash
|
|
53
|
+
me verify --with cleaker
|
|
54
|
+
# Validates signature and authority endorsement
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 4. Migrate Across Devices
|
|
58
|
+
```bash
|
|
59
|
+
me restore --from-seed
|
|
60
|
+
# Or use encrypted backup file + hash
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 5. Rotate Keys
|
|
64
|
+
```bash
|
|
65
|
+
me rotate
|
|
66
|
+
# Generates new key pair, requires re-endorsement
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 🔐 Cryptographic Model
|
|
72
|
+
* Identity is unlocked using a user-defined `hash` (password).
|
|
73
|
+
* This hash decrypts the local `.me` file.
|
|
74
|
+
* The identity includes:
|
|
75
|
+
|
|
76
|
+
* A **key pair** (public/private) for signing and verification.
|
|
77
|
+
* Optional **endorsements** signed by Cleaker or other authorities.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 🛡️ Security Model
|
|
82
|
+
* No private key ever leaves the local `.me` file.
|
|
83
|
+
* Endorsements are public and verifiable using the public key.
|
|
84
|
+
* If compromised, user can rotate keys and notify authorities.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 🌐 Multi-Device Support
|
|
89
|
+
* `.me` can be restored using a seed phrase or backup.
|
|
90
|
+
* New devices can be authorized using signatures from old devices.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## ⚖️ Responsibilities
|
|
95
|
+
|
|
96
|
+
* **this.me**
|
|
97
|
+
* Local file management, encryption, signing.
|
|
98
|
+
* CLI + API for usage.
|
|
99
|
+
|
|
100
|
+
* **Cleaker / Authorities**
|
|
101
|
+
|
|
102
|
+
* Store trusted records of `username` + `publicKey`
|
|
103
|
+
* Provide validation/endorsement services.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🌍 Future Use Cases
|
|
108
|
+
* Digital signature of documents
|
|
109
|
+
* Smart contract interaction
|
|
110
|
+
* Federated profiles with trust anchors
|
|
111
|
+
* Group identity and shared contexts (`me && you && them in context/friends`)
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 📖 Glossary
|
|
116
|
+
* `hash`: A password-like string used to unlock `.me`
|
|
117
|
+
* `endorsement`: Signature from a recognized authority on the identity
|
|
118
|
+
* `publicKey/privateKey`: Cryptographic key pair for identity signing
|
|
119
|
+
* `Cleaker`: Example identity authority ledger
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
**Author:** suiGn / neurons.me
|
|
124
|
+
**License:** MIT
|
|
125
|
+
**Project:** [this.me](https://www.npmjs.com/package/this.me)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
The Problem: Decentralized Yet Trustworthy
|
|
2
|
+
Identity, by its nature, is both personal and relational. On the one hand, we want the freedom to define ourselves without external constraints. On the other, our identities must often be validated by trusted authorities to engage in meaningful transactions, whether signing a digital contract or interacting with a service.
|
|
3
|
+
|
|
4
|
+
Traditional centralized systems — such as social media platforms, government IDs, or corporate logins — often prioritize control over freedom. These systems require users to surrender their data and identities to be recognized. While decentralized technologies like blockchains have emerged to challenge this model, they introduce their own complexities and limitations, such as over-reliance on cryptographic keys or lack of intuitive identity frameworks.
|
|
5
|
+
|
|
6
|
+
The question arises:How can we create an identity system that respects personal sovereignty while ensuring trust and usability in a networked world?
|
|
7
|
+
|
|
8
|
+
Enter This.me: A New Paradigm for Identity
|
|
9
|
+
This.me offers a framework for identity creation and interaction that revolves around two core principles:
|
|
10
|
+
|
|
11
|
+
1. Freedom to Declare: Anyone can create a `.me` instance and define their identity without external permissions. This identity exists as a standalone object, enabling users to interact in a purely self-declared state.
|
|
12
|
+
|
|
13
|
+
2. Trust Anchors: When needed, central authorities or networks, such as Cleaker, can validate the identity. These authorities provide the infrastructure for authentication, signing, and verification without compromising the user’s control over their identity.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
This structure implies:
|
|
2
|
+
|
|
3
|
+
1. Logical Grouping of Entities: me && you && him represents a logical grouping, where each entity is included as part of a broader relationship.
|
|
4
|
+
|
|
5
|
+
2. Contextual Scoping: Context/mexicans provides a scope within which this relationship exists, giving meaning to the relationship without establishing a strict hierarchy among me, you, and him.
|
|
6
|
+
|
|
7
|
+
3. Dynamic Meaning: The meaning can change based on context. For example:
|
|
8
|
+
|
|
9
|
+
• me && you && himContext/mexicans could mean a group of entities (me, you, him) sharing a “Mexican” attribute.
|
|
10
|
+
|
|
11
|
+
Context/friends might represent the same group within a “friends” context, applying different attributes or significance.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
### Neural Networks - **One-Hot Encoding**
|
|
2
|
+
--------
|
|
3
|
+
To represent the combinations of **“me, you, him, her, it, us, them”** in a neural network, we need to convert the elements into a suitable format for neural network processing, such as one-hot encoding, and design a neural network architecture that can process these inputs.
|
|
4
|
+
|
|
5
|
+
Here’s a step-by-step approach to achieve this:
|
|
6
|
+
1. **One-Hot Encoding:** Convert each element (“me”, “you”, “him”, “her”, “it”, “us”, “them”) into a one-hot encoded vector.
|
|
7
|
+
2. **Combination Representation:** Create input vectors for each combination by combining the one-hot encoded vectors.
|
|
8
|
+
3. **Neural Network Design:** Design a simple neural network to process these input vectors.
|
|
9
|
+
|
|
10
|
+
#### Step 1: One-Hot Encoding
|
|
11
|
+
One-hot encoding represents each element as a binary vector with a single high (1) value and the rest low (0). For the elements “me”, “you”, “him”, “her”, “it”, “us”, “them”, we can assign the following one-hot encoded vectors:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// Create Me instances
|
|
15
|
+
const meInstance = new Me('me');
|
|
16
|
+
const youInstance = new Me('you');
|
|
17
|
+
const himInstance = new Me('him');
|
|
18
|
+
const herInstance = new Me('her');
|
|
19
|
+
const itInstance = new Me('it');
|
|
20
|
+
const usInstance = new Me('us');
|
|
21
|
+
const themInstance = new Me('them');
|
|
22
|
+
|
|
23
|
+
// One-hot encoding representation
|
|
24
|
+
const subjects = {
|
|
25
|
+
'me': [1, 0, 0, 0, 0, 0, 0],
|
|
26
|
+
'you': [0, 1, 0, 0, 0, 0, 0],
|
|
27
|
+
'him': [0, 0, 1, 0, 0, 0, 0],
|
|
28
|
+
'her': [0, 0, 0, 1, 0, 0, 0],
|
|
29
|
+
'it': [0, 0, 0, 0, 1, 0, 0],
|
|
30
|
+
'us': [0, 0, 0, 0, 0, 1, 0],
|
|
31
|
+
'them': [0, 0, 0, 0, 0, 0, 1]
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Step 2: Combination Representation
|
|
36
|
+
For each combination, we can create an input vector by combining the one-hot encoded vectors of its elements. For example:
|
|
37
|
+
Combination “me, you” would be represented as the sum of the one-hot vectors for “me” and “you”:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
[1, 0, 0, 0, 0, 0, 0] + [0, 1, 0, 0, 0, 0, 0] = [1, 1, 0, 0, 0, 0, 0]
|
|
41
|
+
```
|
|
42
|
+
---
|
|
43
|
+
### Me Deviation Formula
|
|
44
|
+
**How Spread Out the data Points are around the .me?**
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "this.me",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.5",
|
|
4
4
|
"description": "_me-Centric.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node index.js",
|
|
8
|
-
"test": "test"
|
|
8
|
+
"test": "test",
|
|
9
|
+
"postinstall": "node src/scripts/setup.js"
|
|
9
10
|
},
|
|
10
11
|
"bin": {
|
|
11
|
-
"
|
|
12
|
+
"me": "bin/me.cli.js"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
14
15
|
"this.me",
|
package/src/example.js
CHANGED
package/src/me.js
CHANGED
|
@@ -1,56 +1,148 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/me.js
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
2
4
|
import crypto from 'crypto';
|
|
3
5
|
import os from 'os';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
class Me{
|
|
7
|
-
// Static property to keep track of all users globally
|
|
8
|
-
static registry = {};
|
|
7
|
+
const ROOT_DIR = path.join(os.homedir(), '.this', 'me');
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
class Me {
|
|
10
|
+
constructor(username) {
|
|
11
|
+
this.username = username;
|
|
12
|
+
this.filePath = path.join(ROOT_DIR, `${username}.me`); // encrypted .me file path
|
|
13
|
+
this.unlocked = false; // will become true after decrypting with correct hash
|
|
14
|
+
this.data = null; // holds decrypted data (identity, keys, attributes, etc.)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Encrypt and write the current `this.data` to disk.
|
|
19
|
+
*/
|
|
20
|
+
save(hash) {
|
|
21
|
+
if (!this.data) throw new Error('No data to save');
|
|
22
|
+
const iv = crypto.randomBytes(16);
|
|
23
|
+
const key = crypto.createHash('sha256').update(hash).digest();
|
|
24
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
|
|
25
|
+
const encrypted = Buffer.concat([
|
|
26
|
+
iv,
|
|
27
|
+
cipher.update(JSON.stringify(this.data)),
|
|
28
|
+
cipher.final()
|
|
29
|
+
]);
|
|
30
|
+
fs.writeFileSync(this.filePath, encrypted);
|
|
21
31
|
}
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Unlock the .me file by decrypting it using the provided hash.
|
|
35
|
+
*/
|
|
36
|
+
unlock(hash) {
|
|
37
|
+
const fileBuffer = fs.readFileSync(this.filePath);
|
|
38
|
+
const iv = fileBuffer.slice(0, 16);
|
|
39
|
+
const encryptedData = fileBuffer.slice(16);
|
|
40
|
+
const key = crypto.createHash('sha256').update(hash).digest();
|
|
41
|
+
try {
|
|
42
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
43
|
+
const decrypted = Buffer.concat([
|
|
44
|
+
decipher.update(encryptedData),
|
|
45
|
+
decipher.final()
|
|
46
|
+
]);
|
|
47
|
+
this.data = JSON.parse(decrypted.toString('utf-8'));
|
|
48
|
+
this.unlocked = true;
|
|
49
|
+
return true;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return false; // incorrect hash or corrupted file
|
|
29
52
|
}
|
|
30
53
|
}
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Locks the session by wiping in-memory data.
|
|
57
|
+
*/
|
|
58
|
+
lock() {
|
|
59
|
+
this.data = null;
|
|
60
|
+
this.unlocked = false;
|
|
34
61
|
}
|
|
35
62
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Create a new identity file for the given username.
|
|
65
|
+
* Called only if it doesn't already exist.
|
|
66
|
+
*/
|
|
67
|
+
static create(username, hash) {
|
|
68
|
+
const me = new Me(username);
|
|
69
|
+
if (fs.existsSync(me.filePath)) {
|
|
70
|
+
throw new Error('Identity already exists');
|
|
42
71
|
}
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
// Generate keys or initial structure
|
|
74
|
+
me.data = {
|
|
75
|
+
identity: {
|
|
76
|
+
username,
|
|
77
|
+
publicKey: 'publicKeyPlaceholder', // later generate real keypair
|
|
78
|
+
privateKey: 'privateKeyPlaceholder'
|
|
79
|
+
},
|
|
80
|
+
attributes: {},
|
|
81
|
+
relationships: [],
|
|
82
|
+
reactions: [],
|
|
83
|
+
endorsements: []
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
me.save(hash);
|
|
87
|
+
return me;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Create a new identity file for the given username.
|
|
92
|
+
* Called only if it doesn't already exist.
|
|
93
|
+
*/
|
|
94
|
+
static create(username, hash) {
|
|
95
|
+
const me = new Me(username);
|
|
96
|
+
if (fs.existsSync(me.filePath)) {
|
|
97
|
+
throw new Error('Identity already exists');
|
|
47
98
|
}
|
|
99
|
+
|
|
100
|
+
// Generate keys or initial structure
|
|
101
|
+
me.data = {
|
|
102
|
+
identity: {
|
|
103
|
+
username,
|
|
104
|
+
publicKey: 'publicKeyPlaceholder', // later generate real keypair
|
|
105
|
+
privateKey: 'privateKeyPlaceholder'
|
|
106
|
+
},
|
|
107
|
+
attributes: {},
|
|
108
|
+
relationships: [],
|
|
109
|
+
reactions: [],
|
|
110
|
+
endorsements: []
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
me.save(hash);
|
|
114
|
+
return me;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Load and decrypt an existing identity.
|
|
119
|
+
*/
|
|
120
|
+
static load(username, hash) {
|
|
121
|
+
const me = new Me(username);
|
|
122
|
+
const success = me.unlock(hash);
|
|
123
|
+
if (!success) throw new Error('Invalid hash or corrupted file');
|
|
124
|
+
return me;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Add an endorsement (external signature asserting trust in this identity).
|
|
128
|
+
*/
|
|
129
|
+
addEndorsement(endorsement) {
|
|
130
|
+
if (!this.unlocked) throw new Error('Identity is locked');
|
|
131
|
+
this.data.endorsements.push(endorsement);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Example: add an attribute to this.me (like `.be("artist")`).
|
|
136
|
+
*/
|
|
137
|
+
be(key, value) {
|
|
138
|
+
if (!this.unlocked) throw new Error('Identity is locked');
|
|
139
|
+
this.data.attributes[key] = value;
|
|
48
140
|
}
|
|
49
141
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
142
|
+
getAttributes() {
|
|
143
|
+
if (!this.unlocked) throw new Error('Identity is locked');
|
|
144
|
+
return this.data.attributes;
|
|
53
145
|
}
|
|
54
146
|
}
|
|
55
147
|
|
|
56
|
-
export default Me;
|
|
148
|
+
export default Me;
|