Skip to content

Commit 96c3d06

Browse files
committed
sharing project to github
0 parents  commit 96c3d06

File tree

12 files changed

+2190
-0
lines changed

12 files changed

+2190
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
.vscode/
3+
node_modules/
4+
5+
package-lock.json

LICENSE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright 2018 Robin Lamberti
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 535 additions & 0 deletions
Large diffs are not rendered by default.

jsdoc2md/README.hbs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# TIC - Trusted IOTA Contacts
2+
A simple library providing a secure way to validate identities in the IOTA network.
3+
4+
With TIC you can publish information which you want to share about yourself on the tangle and publish that you trust or
5+
distrust the information of someone else. The ones you trust are your 'contacts'. With this a Web of Trust is established
6+
by which you can validate the information of someone by accumulating the trust ratings of your contacts and their contacts
7+
and so on. This makes it possible to derive a trust rating for someone who is not your direct contact.
8+
9+
## CLI
10+
You can use all functions of the TIC library with a simple CLI. The releases contain binaries for different platforms with
11+
that you can use TIC standalone from the command line:
12+
```sh
13+
$ ticCli-linux-x86 <command> [options]
14+
```
15+
It's also possible to run the cli directly with node/npm:
16+
```sh
17+
$ npm install
18+
$ npm run cli <command> -- [options]
19+
```
20+
Note the extra '--' needed before the options.
21+
22+
### Setting Node
23+
The option <code>--provider</code> must be set in all commands. It should be set to the URL of an IOTA full node supporting POW.
24+
25+
### Commands:
26+
#### create
27+
Creates a new TIC account by generating a profile and a contacts channel and saving its channel roots on the tangle.
28+
| Param | Type | Default | Description |
29+
| --- | --- | --- | --- |
30+
| seed | <code>string</code> | | The seed of the TIC account to create. It's used to create the public master channel of the account where the channel roots of the profile and contacts channel are published. |
31+
| password | <code>string</code> | seed | The tryte-encoded password to save the seeds of profile and contacts channel in the restricted channel of the TIC account. If password is not given the seed is used as a default. If null is given the seeds aren't saved. If the seeds are not saved you need to remember these by yourself and pass them as params in certain requests. |
32+
33+
**Example**
34+
```sh
35+
$ ticCli-linux-x86 create --seed=THISISTHESEEDOFTHETICACCOUNTANDISHOULDNOTGIVEITTOANYBODYELSE --provider=https://your.favorite.node
36+
```
37+
#### read
38+
Reads the content of a TIC account from the tangle.
39+
| Param | Type | Default | Description |
40+
| --- | --- | --- | --- |
41+
| seed | <code>string</code> | | The seed of the TIC account |
42+
| masterRoot | <code>string</code> | | The root of the master channel of the TIC account to read |
43+
| profileRoot | <code>string</code> | | The channel root of the profile channel to read |
44+
| contactsRoot | <code>string</code> | | The channel root of the contacts channel to read |
45+
| password | <code>string</code> | seed | The tryte-encoded password to get the seeds of profile and contacts channel in the restricted channel of the TIC account. If password is not given the seed is used as a default. If null is given the seeds aren't retrieved. |
46+
One of these params is needed to read content from an account. The cli will look for them in descending order of the table. If profile and contacts root are given both channels are read.
47+
The password is only needed together with the seed.
48+
49+
**Example**
50+
```sh
51+
$ ticCli-linux-x86 read --profileRoot=RGHGRDSIUHGRDOINGGSOLHKZHSÖFJBRHVUFCFYVNEJKXDSHJGFSDSDF
52+
--contactsRoot=LOIRHGBVSHJRHGREIUAOCNAKSSUEGRFSJHFSDGFDJHFSFKBGHGTZUCNYS --provider=https://your.favorite.node
53+
```
54+
#### putInfo
55+
Adds the given information in JSON format to the profile of a TIC account.
56+
| Param | Type | Default | Description |
57+
| --- | --- | --- | --- |
58+
| seed | <code>string</code> | | The seed of the TIC account |
59+
| password | <code>string</code> | seed | The tryte-encoded password of the TIC account. It's used to retrieve the channel root from the restricted channel. If password is not given the seed is used as a default. If null is given the seed can't be retrieved. |
60+
| profileSeed | <code>string</code> | | The channel root of the profile channel to add information to |
61+
| content | <code>string</code> | | The information to add to the profile in form of key/value pairs formatted as a JSON object. '"' might be needed to escape and the content must be wraped in '' |
62+
Only seed or profile seed is needed for this request. Seed can only be used if channel seeds are saved on the tangle with the
63+
given password.
64+
65+
**Example**
66+
```sh
67+
$ ticCli-linux-x86 putInfo --seed=DSFEDHKSZAGFZUAIUAAWBSFVHJHTRNDBGZUFGJSDGIGDHJSFHGDSJGHSFHD
68+
--password=IUDRHVBVSSHGDGFKSIDFHGVHDZDUSGHDFVBSJKDFUCBHDSJ
69+
--content='{\"name\":\"Max Mustermann\"}' --provider=https://your.favorite.node
70+
```
71+
#### removeInfo
72+
Removes the properties as a JSON array from the profile of a TIC account.
73+
| Param | Type | Default | Description |
74+
| --- | --- | --- | --- |
75+
| seed | <code>string</code> | | The seed of the TIC account |
76+
| password | <code>string</code> | seed | The tryte-encoded password of the TIC account. It's used to retrieve the channel root from the restricted channel. If password is not given the seed is used as a default. If null is given the seed can't be retrieved. |
77+
| profileSeed | <code>string</code> | | The channel root of the profile channel to remove information from |
78+
| content | <code>string</code> | | The information to remove from the profile in form of the keys formatted as a JSON array. '"' might be needed to escape and the content must be wraped in '' |
79+
Only seed or profile seed is needed for this request. Seed can only be used if channel seeds are saved on the tangle with the
80+
given password.
81+
Please note that the information is not really deleted from the tangle as that is not possible. The given information could be read on the mam channel as before by everyone. This request has the effect that the TIC library will not consider the given properties in information that has been published to this profile before, when compiling the profile information.
82+
83+
**Example**
84+
```sh
85+
$ ticCli-linux-x86 removeInfo --profileSeed=THESEEDOFTHEPROFILECHANNELOFTHETICACCOUNTWHICHNEEDSTOBEKEPTPRIVATE
86+
--content='[\"name\"]' --provider=https://your.favorite.node
87+
```
88+
#### trust
89+
Adds the given account to the trusted contacts of a TIC account.
90+
| Param | Type | Default | Description |
91+
| --- | --- | --- | --- |
92+
| seed | <code>string</code> | | The seed of the TIC account |
93+
| password | <code>string</code> | seed | The tryte-encoded password of the TIC account. It's used to retrieve the channel root from the restricted channel. If password is not given the seed is used as a default. If null is given the seed can't be retrieved. |
94+
| contactsSeed | <code>string</code> | | The channel root of the contacts channel to add trusts to |
95+
| content | <code>string</code> | | The master channel roots of the accounts to add to the trusted contacts formatted as a JSON array. '"' might be needed to escape and the content must be wraped in '' |
96+
Only seed or contacts seed is needed for this request. Seed can only be used if channel seeds are saved on the tangle with the
97+
given password.
98+
99+
**Example**
100+
```sh
101+
$ ticCli-linux-x86 trust --contactsSeed=THESEEDOFTHECONTACTSCHANNELOFTHETICACCOUNTWHICHNEEDSTOBEKEPTPRIVATE
102+
--content='[\"GOEFGIEUVHFJHVDFBDHGZGFZIGXGFCDJDKSFIWFUZFIOTHGRTSIUDG\",\"UZOITRZEHSVCXKGHGEUZSVBSZGFSUZGFSZUDGFSDFSGDSHJDSDFHSDFHJDGFSDHJGFD\"]'
103+
--provider=https://your.favorite.node
104+
```
105+
#### distrust
106+
Adds the given account to the distrusted contacts of a TIC account.
107+
| Param | Type | Default | Description |
108+
| --- | --- | --- | --- |
109+
| seed | <code>string</code> | | The seed of the TIC account |
110+
| password | <code>string</code> | seed | The tryte-encoded password of the TIC account. It's used to retrieve the channel root from the restricted channel. If password is not given the seed is used as a default. If null is given the seed can't be retrieved. |
111+
| contactsSeed | <code>string</code> | | The channel root of the contacts channel to add distrusts to |
112+
| content | <code>string</code> | | The master channel roots of the accounts to add to the distrusted contacts formatted as a JSON array. '"' might be needed to escape and the content must be wraped in '' |
113+
Only seed or contacts seed is needed for this request. Seed can only be used if channel seeds are saved on the tangle with the
114+
given password.
115+
116+
**Example**
117+
```sh
118+
$ ticCli-linux-x86 distrust --seed=EWIVBSDFIUGRUISAGAFKGRFZEAUKGFZERGFCFEUGICGFZUDIADHVCB
119+
--password=GRSJDVKBJDFKLHFGSCKHDAGZFTGZCFGHCXDFKHGDHDSGHFHHSDFGHSJ
120+
--content='[\"GOEFGIEUVHFJHVDFBDHGZGFZIGXGFCDJDKSFIWFUZFIOTHGRTSIUDG\",\"UZOITRZEHSVCXKGHGEUZSVBSZGFSUZGFSZUDGFSDFSGDSHJDSDFHSDFHJDGFSDHJGFD\"]'
121+
--provider=https://your.favorite.node
122+
```
123+
#### rating
124+
Computes the trust rating for a given account by querying the contacts of a TIC account.
125+
| Param | Type | Default | Description |
126+
| --- | --- | --- | --- |
127+
| masterRoot | <code>string</code> | | The root of the master channel of the TIC account to base the rating query on |
128+
| seed | <code>string</code> | | The seed of the TIC account to base the rating query on |
129+
| target | <code>string</code> | | The master channel root of the TIC account to compute a trust rating of |
130+
| depth | <code>number</code> | 5 | The maximum depth of recursive querying of contacts of contacts of contacts... |
131+
Only masterRoot or seed is needed for this request. The CLI will look for the master root first.
132+
133+
**Example**
134+
```sh
135+
$ ticCli-linux-x86 rating --seed=RIFHSDJCHJGDIUEAFHUIGTRJUIERNDCSLIEUGSJHKSDFHGDSDFKHSFDKSGDDS
136+
--target=UZOITRZEHSVCXKGHGEUZSVBSZGFSUZGFSZUDGFSDFSGDSHJDSDFHSDFHJDGFSDHJGFD
137+
--provider=https://your.favorite.node
138+
```
139+
The output of this request could look like this for example:
140+
```sh
141+
> info: Computing rating for account 'EARFMSCNONSALMKPH9RKJEQTPZQWOEJT9GQGFVUQEME9FXPQICSJGYWCINFLME9YGYWJZSEQPVOWZFFJV'.
142+
> info: Ratings: { trust: 1, distrust: 2, unknown: 0 }
143+
> info: Tree: (<masterRoot>: <rating> <depth in the tree>)
144+
> info: UJGMXS9SGYAVYXDWGTI9FJEJPUVGIHSRDLDHNLAPFEZXMZOFHXE9LXJBTEOUAHVSWIFKUHIQQMIJPQPCT: distrust 0
145+
> info: Y9LTPBGZGK9GATDYIJROVIFP9OVEAIEDRLDXZEFKEDYE9KRJKSLJVJQOKUDXAZPSANHKZCJMVNIABTCBJ: trust 1
146+
> info: R9PLCWUAZLMLKWRMKDCPNYJSPRBLHXNJUXHKRCVWN9T9DZJZEPSFNODRVCYLY9GSDAFMEWRVPIZNYBEOY: distrust 2
147+
> info: EARFMSCNONSALMKPH9RKJEQTPZQWOEJT9GQGFVUQEME9FXPQICSJGYWCINFLME9YGYWJZSEQPVOWZFFJV: undefined 1
148+
> info: EARFMSCNONSALMKPH9RKJEQTPZQWOEJT9GQGFVUQEME9FXPQICSJGYWCINFLME9YGYWJZSEQPVOWZFFJV: undefined 1
149+
> info: EARFMSCNONSALMKPH9RKJEQTPZQWOEJT9GQGFVUQEME9FXPQICSJGYWCINFLME9YGYWJZSEQPVOWZFFJV: undefined 1
150+
```
151+
The second line holds a summary of all trust ratings collected from the queryied TIC accounts. It shows the amount of accounts having the target account in the trusted contacts,
152+
in their distrusted contacts and the amount of TIC accounts who don't have the target in their contacts at all. These are called 'unknown' ratings.
153+
154+
The following lines show a tree of all queryied TIC accounts. Each line consists of the master channel root of the account followed
155+
by the rating of this account for the target followed by the depth in the tree where it was first found. The first line is your TIC account given by seed or masterRoot.
156+
157+
The depth is also shown by the indent of a line. The contacts of a account have a higher indent as their 'parent'. Queryied are all contacts
158+
of an account that this account trusts.
159+
160+
If a contact has the target in its contacts, trusting or distrusting, the target is shown
161+
as a contact of this account in this tree. The target has an undefined rating because ratings for someones own account are not considered.
162+
* * *
163+
## API Reference
164+
{{#module name="ticApi"}}
165+
{{>body~}}
166+
{{>member-index~}}
167+
{{>members~}}
168+
{{/module}}
169+
* * *
170+
## Types
171+
{{#module name="types"}}
172+
{{>body~}}
173+
{{>member-index~}}
174+
{{>members~}}
175+
{{/module}}
176+
177+
* * *
178+
179+
&copy; 2018 Robin Lamberti \<lamberti[email protected]\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).

lib/chainMessageBuilder.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const extend = require('extend');
2+
3+
const build = (messages, put = "put", del = "delete") => {
4+
let result = {}
5+
messages.forEach(m => {
6+
if (m[del]) {
7+
m[del].forEach(path => deletePropertyPath(result, path))
8+
} else if (m[put]) {
9+
extend(true, result, m[put])
10+
}
11+
})
12+
return result
13+
};
14+
15+
const buildArray = (messages, add = "add", remove = "remove") => {
16+
let result = []
17+
messages.forEach(m => {
18+
if (m[add]) {
19+
array(m[add]).forEach(i => result.push(i))
20+
} else if (m[remove]) {
21+
array(m[remove]).forEach(i => {
22+
const index = result.indexOf(i)
23+
if (index != -1) {
24+
result.splice(index, 1)
25+
}
26+
})
27+
}
28+
})
29+
return result.filter(onlyUnique)
30+
};
31+
32+
const buildUniqueArray = (messages, usedProperties) => {
33+
let keys = {}
34+
const keyOrder = []
35+
messages.forEach(m => {
36+
for (p of usedProperties) {
37+
if (m[p]) {
38+
const a = array(m[p])
39+
a.forEach(v => {
40+
keys[v] = p
41+
keyOrder.push(v)
42+
})
43+
break;
44+
}
45+
}
46+
})
47+
return keyOrder.reverse().filter(onlyUnique).reverse().map(key => ({[key]: keys[key]}))
48+
};
49+
50+
const onlyUnique = (value, index, self) => {
51+
return self.indexOf(value) === index;
52+
};
53+
54+
const array = (obj) => Array.isArray(obj) ? obj : [obj]
55+
56+
const deletePropertyPath = (obj, path) => {
57+
path = path.split('.');
58+
59+
for (var i = 0; i < path.length - 1; i++) {
60+
obj = obj[path[i]];
61+
62+
if (typeof obj === 'undefined') {
63+
return;
64+
}
65+
}
66+
67+
delete obj[path.pop()];
68+
};
69+
70+
module.exports = {
71+
build: build,
72+
buildArray: buildArray,
73+
buildUniqueArray: buildUniqueArray
74+
}

0 commit comments

Comments
 (0)