this.me 2.9.51 → 3.0.0
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 +77 -82
- package/dist/this-me.cjs.js +55 -0
- package/dist/this-me.es.js +324 -0
- package/dist/this-me.umd.js +55 -0
- package/package.json +27 -19
- package/bin/me.cli.js +0 -99
- package/index.js +0 -12
- package/jsdoc.json +0 -41
- package/notes/Entonces_Que_es_me.md +0 -9
- package/notes/Index of this.me Structure.md +0 -154
- package/notes/Index.md +0 -134
- package/notes/Inmutabilidad_de_la_Identidad_basica.md +0 -44
- package/notes/Questions.md +0 -62
- package/notes/Summary.md +0 -125
- package/notes/The Problem: Decentralized Yet Trustworthy.md +0 -13
- package/notes/Understanding me && you && himContext.md +0 -11
- package/notes/hot_encoding.md +0 -44
- package/src/example.js +0 -25
- package/src/me.js +0 -148
- package/src/methods/attributes.js +0 -79
- package/src/methods/identity.js +0 -31
- package/src/methods/properties.js +0 -73
- package/src/methods/reactions.js +0 -31
- package/src/methods/relationships.js +0 -26
- package/src/scripts/setup.js +0 -19
- package/src/scripts/setup_validation.js +0 -31
package/notes/Summary.md
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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)
|
|
@@ -1,13 +0,0 @@
|
|
|
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.
|
|
@@ -1,11 +0,0 @@
|
|
|
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.
|
package/notes/hot_encoding.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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/src/example.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
//this.me/src/example.js
|
|
2
|
-
import Me from './me.js';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
// Create a new Me instance
|
|
5
|
-
let me = new Me('suign');
|
|
6
|
-
// Add attributes to the identity
|
|
7
|
-
me.be({ fullName: "Jose", lastName: "Abella" });
|
|
8
|
-
me.be({ xy: "z" });
|
|
9
|
-
console.log(me);
|
|
10
|
-
// Examplconsole.log(me.identity());e with another instance
|
|
11
|
-
let anotherMe = new Me('anotherUser');
|
|
12
|
-
anotherMe.be({ nickname: "hero", favoriteColor: "blue" });
|
|
13
|
-
console.log(anotherMe);
|
|
14
|
-
// Create a new Me instance with dynamic property name
|
|
15
|
-
let user = 'suign';
|
|
16
|
-
let users = {};
|
|
17
|
-
users[user] = new Me(user);
|
|
18
|
-
// Add attributes to the identity
|
|
19
|
-
users[user].be({ fullName: "ZZZ", lastName: "WWW" });
|
|
20
|
-
users[user].be({ xy: "axax" });
|
|
21
|
-
console.log(users[user]);
|
|
22
|
-
|
|
23
|
-
console.log(users);
|
|
24
|
-
|
|
25
|
-
|
package/src/me.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// src/me.js
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import crypto from 'crypto';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
|
|
7
|
-
const ROOT_DIR = path.join(os.homedir(), '.this', 'me');
|
|
8
|
-
|
|
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);
|
|
31
|
-
}
|
|
32
|
-
|
|
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
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Locks the session by wiping in-memory data.
|
|
57
|
-
*/
|
|
58
|
-
lock() {
|
|
59
|
-
this.data = null;
|
|
60
|
-
this.unlocked = false;
|
|
61
|
-
}
|
|
62
|
-
|
|
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');
|
|
71
|
-
}
|
|
72
|
-
|
|
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');
|
|
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;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getAttributes() {
|
|
143
|
-
if (!this.unlocked) throw new Error('Identity is locked');
|
|
144
|
-
return this.data.attributes;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export default Me;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Attributes methods
|
|
2
|
-
/**
|
|
3
|
-
* @module Attributes
|
|
4
|
-
* @description Methods to manage attributes for the `Me` class, with key-vaue pairs.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @description Adds or updates an attribute for the `me` instance.
|
|
8
|
-
*
|
|
9
|
-
* This method allows you to dynamically add or update descriptive attributes
|
|
10
|
-
* for the `me` instance. Attributes are stored as key-value pairs, where:
|
|
11
|
-
* - The **key** represents the name of the attribute (e.g., "name", "age", "location").
|
|
12
|
-
* - The **value** represents the data associated with that attribute (e.g., "Sui Gn", 30, "Earth").
|
|
13
|
-
*
|
|
14
|
-
* You can add as many key-value pairs as you want, giving you the flexibility to describe
|
|
15
|
-
* the `me` instance with plain data. The attributes are stored in an object, and each call
|
|
16
|
-
* to `be` either adds a new attribute or updates an existing one if the key already exists.
|
|
17
|
-
*
|
|
18
|
-
* This approach ensures that the `me` instance can evolve and be customized over time
|
|
19
|
-
* with additional or modified attributes as needed.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} key - The attribute key (e.g., "name").
|
|
22
|
-
* @param {string|number|boolean|Object} value - The attribute value associated with the key.
|
|
23
|
-
* This can be any data type (e.g., string, number, boolean, or even a nested object).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Adding a single attribute
|
|
27
|
-
* me.be("name", "Sui Gn");
|
|
28
|
-
* console.log(me.getAttributes()); // { name: "Sui Gn" }
|
|
29
|
-
*
|
|
30
|
-
* // Adding multiple attributes
|
|
31
|
-
* me.be("age", 30);
|
|
32
|
-
* me.be("location", "Earth");
|
|
33
|
-
* console.log(me.getAttributes());
|
|
34
|
-
* // Output: { name: "Sui Gn", age: 30, location: "Earth" }
|
|
35
|
-
*
|
|
36
|
-
* // Updating an existing attribute
|
|
37
|
-
* me.be("name", "John Doe");
|
|
38
|
-
* console.log(me.getAttributes());
|
|
39
|
-
* // Output: { name: "John Doe", age: 30, location: "Earth" }
|
|
40
|
-
*
|
|
41
|
-
* // Using complex data types
|
|
42
|
-
* me.be("preferences", { theme: "dark", language: "en" });
|
|
43
|
-
* console.log(me.getAttributes());
|
|
44
|
-
* // Output: { name: "John Doe", age: 30, location: "Earth", preferences: { theme: "dark", language: "en" } }
|
|
45
|
-
*/
|
|
46
|
-
export function be(attributes, key, value) {
|
|
47
|
-
if (!key || typeof key !== 'string') {
|
|
48
|
-
throw new Error('Invalid key for attribute');
|
|
49
|
-
}
|
|
50
|
-
attributes[key] = value;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @description Retrieves all attributes associated with the `me` instance.
|
|
54
|
-
*
|
|
55
|
-
* This method provides access to the current set of attributes stored in the `me` instance
|
|
56
|
-
* as an object containing key-value pairs. Each key represents the name of an attribute,
|
|
57
|
-
* and its corresponding value represents the data stored for that attribute.
|
|
58
|
-
*
|
|
59
|
-
* You can either:
|
|
60
|
-
* - Retrieve all attributes at once as a single object.
|
|
61
|
-
* - Access specific attributes directly using their keys.
|
|
62
|
-
*
|
|
63
|
-
* @returns {Object} An object containing all the key-value pairs representing
|
|
64
|
-
* the attributes of the `me` instance.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* // Retrieving all attributes
|
|
68
|
-
* console.log(me.getAttributes());
|
|
69
|
-
* // Output: { name: "Sui Gn", age: 30, location: "Earth" }
|
|
70
|
-
*
|
|
71
|
-
* // Accessing specific attributes by their key
|
|
72
|
-
* const attributes = me.getAttributes();
|
|
73
|
-
* console.log(attributes.name); // "Sui Gn"
|
|
74
|
-
* console.log(attributes.age); // 30
|
|
75
|
-
* console.log(attributes.location); // "Earth"
|
|
76
|
-
*/
|
|
77
|
-
export function getAttributes(attributes) {
|
|
78
|
-
return attributes;
|
|
79
|
-
}
|
package/src/methods/identity.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Identity
|
|
3
|
-
* @description Methods to manage identity for the `Me` class.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Sets up the identity for a `Me` instance.
|
|
8
|
-
* @function
|
|
9
|
-
* @param {string} username - The username to set for the identity.
|
|
10
|
-
* @returns {Object} The identity object containing the username.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const identity = setup("suiGn");
|
|
14
|
-
* console.log(identity); // { username: "suiGn" }
|
|
15
|
-
*/
|
|
16
|
-
export function setup(username) {
|
|
17
|
-
return { username };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves the username (identity) of the `Me` instance.
|
|
22
|
-
* @function
|
|
23
|
-
* @param {Object} identity - The identity object of the `Me` instance.
|
|
24
|
-
* @returns {Object} The `Me` username identity object.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* console.log(getMe({ username: "suiGn" })); // { username: "suiGn" }
|
|
28
|
-
*/
|
|
29
|
-
export function getMe(identity) {
|
|
30
|
-
return identity;
|
|
31
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// this.me/src/methods/properties.js
|
|
2
|
-
/**
|
|
3
|
-
* @module Properties
|
|
4
|
-
* @description Methods to manage properties for the `Me` class.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Validates a property before adding it.
|
|
9
|
-
* @function
|
|
10
|
-
* @param {Object} property - The property to validate.
|
|
11
|
-
* @throws {Error} If the property is invalid.
|
|
12
|
-
*/
|
|
13
|
-
function validateProperty(property) {
|
|
14
|
-
if (!property || typeof property !== 'object') {
|
|
15
|
-
throw new Error('Invalid property: Must be a non-null object.');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Adds a property to the identity.
|
|
21
|
-
* @function
|
|
22
|
-
* @param {Array} properties - The properties array to update.
|
|
23
|
-
* @param {Object} property - The property to add (e.g., { type: "ETH", address: "0x123..." }).
|
|
24
|
-
*/
|
|
25
|
-
function addProperty(properties, property) {
|
|
26
|
-
validateProperty(property);
|
|
27
|
-
properties.push(property);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves all properties for the identity.
|
|
32
|
-
* @function
|
|
33
|
-
* @param {Array} properties - The properties array to retrieve from.
|
|
34
|
-
* @returns {Array} The properties array.
|
|
35
|
-
*/
|
|
36
|
-
function getProperties(properties) {
|
|
37
|
-
return [...properties]; // Return a shallow copy to prevent mutation outside
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Removes a property from the identity.
|
|
42
|
-
* @function
|
|
43
|
-
* @param {Array} properties - The properties array to update.
|
|
44
|
-
* @param {Object} property - The property to remove.
|
|
45
|
-
*/
|
|
46
|
-
function removeProperty(properties, property) {
|
|
47
|
-
validateProperty(property);
|
|
48
|
-
const index = properties.findIndex(p => JSON.stringify(p) === JSON.stringify(property));
|
|
49
|
-
if (index !== -1) properties.splice(index, 1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Checks if a specific property exists.
|
|
54
|
-
* @function
|
|
55
|
-
* @param {Array} properties - The properties array.
|
|
56
|
-
* @param {Object} property - The property to check.
|
|
57
|
-
* @returns {boolean} True if the property exists, otherwise false.
|
|
58
|
-
*/
|
|
59
|
-
function hasProperty(properties, property) {
|
|
60
|
-
validateProperty(property);
|
|
61
|
-
return properties.some(p => JSON.stringify(p) === JSON.stringify(property));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Named exports
|
|
65
|
-
export { addProperty, getProperties, removeProperty, hasProperty };
|
|
66
|
-
|
|
67
|
-
// Default export (optional for easier import as an object)
|
|
68
|
-
export default {
|
|
69
|
-
addProperty,
|
|
70
|
-
getProperties,
|
|
71
|
-
removeProperty,
|
|
72
|
-
hasProperty
|
|
73
|
-
};
|
package/src/methods/reactions.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
//this.me/src/methods/reactions.js
|
|
2
|
-
/**
|
|
3
|
-
* @module Reactions
|
|
4
|
-
* @description Methods to manage reactions for the `Me` class.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Add a reaction to a target.
|
|
8
|
-
* @function
|
|
9
|
-
* @param {Array} reactions - The reactions array to update.
|
|
10
|
-
* @param {string} type - The type of reaction (e.g., "like", "comment").
|
|
11
|
-
* @param {string} target - The target of the reaction (e.g., "PostID").
|
|
12
|
-
* @param {string} [content=null] - Additional content for the reaction (e.g., a comment).
|
|
13
|
-
* @throws {Error} If the type or target is invalid.
|
|
14
|
-
*/
|
|
15
|
-
export function react(reactions, type, target, content = null) {
|
|
16
|
-
if (!type || !target) {
|
|
17
|
-
throw new Error('Invalid reaction parameters');
|
|
18
|
-
}
|
|
19
|
-
reactions.push({ type, target, content, timestamp: new Date() });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Retrieve all reactions for the identity.
|
|
24
|
-
* @function
|
|
25
|
-
* @param {Array} reactions - The reactions array to retrieve from.
|
|
26
|
-
* @returns {Array} The reactions array.
|
|
27
|
-
* @instance
|
|
28
|
-
*/
|
|
29
|
-
export function getReactions(reactions) {
|
|
30
|
-
return reactions;
|
|
31
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Relationships
|
|
3
|
-
* @description Manages user relationships.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Function to add a relationship
|
|
7
|
-
export function addRelationship(relationships, relationship) {
|
|
8
|
-
if (!relationship || !relationship.type || !relationship.username) {
|
|
9
|
-
throw new Error('Invalid relationship object. Must include type and username.');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
relationships.push(relationship);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Function to retrieve relationships
|
|
16
|
-
export function getRelationships(relationships, type = null) {
|
|
17
|
-
if (type) {
|
|
18
|
-
return relationships.filter(rel => rel.type === type);
|
|
19
|
-
}
|
|
20
|
-
return relationships;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Function to initialize relationships for a user
|
|
24
|
-
export function createRelationships() {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
package/src/scripts/setup.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// setup.js
|
|
2
|
-
import { mkdirSync, existsSync } from 'fs';
|
|
3
|
-
import { homedir } from 'os';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
const root = path.join(homedir(), '.this');
|
|
6
|
-
const mePath = path.join(root, 'me');
|
|
7
|
-
if (!existsSync(root)) {
|
|
8
|
-
mkdirSync(root);
|
|
9
|
-
console.log('✅ Created ~/.this root directory');
|
|
10
|
-
} else {
|
|
11
|
-
console.log('✅ ~/.this root directory already exists');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!existsSync(mePath)) {
|
|
15
|
-
mkdirSync(mePath);
|
|
16
|
-
console.log('✅ Created ~/.this/me directory');
|
|
17
|
-
} else {
|
|
18
|
-
console.log('✅ ~/.this/me directory already exists');
|
|
19
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
2
|
-
import { homedir } from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const root = path.join(homedir(), '.this');
|
|
6
|
-
const mePath = path.join(root, 'me');
|
|
7
|
-
|
|
8
|
-
export function validateSetup() {
|
|
9
|
-
let updated = false;
|
|
10
|
-
|
|
11
|
-
if (!existsSync(root)) {
|
|
12
|
-
mkdirSync(root);
|
|
13
|
-
console.log('✅ Created ~/.this root directory');
|
|
14
|
-
updated = true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (!existsSync(mePath)) {
|
|
18
|
-
mkdirSync(mePath);
|
|
19
|
-
console.log('✅ Created ~/.this/me directory');
|
|
20
|
-
updated = true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!updated) {
|
|
24
|
-
console.log('.me >> init.');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Run directly if script is executed as entry point
|
|
29
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
30
|
-
validateSetup();
|
|
31
|
-
}
|