-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
53 lines (46 loc) · 1.54 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
window.onload = () => {
const getNewPerson = () => {
const date = Date.now();
return {
id: `id_${date}`,
name: `name_${date}`,
country: `country_${date}`,
}
}
var gun = Gun();
window.gun = gun;
gun
.get('#user_catalogue_1')
.on((indexedCatalogueOfPubKeys) => {
delete indexedCatalogueOfPubKeys._;
const allPubKeys = Object.values(indexedCatalogueOfPubKeys);
const container = document.getElementById('all_people_container');
container.innerHTML = '';
allPubKeys.forEach(async (justSomePubKey) => {
gun.user(justSomePubKey).get('profile').load(({ name, country }) => {
let element = document.createElement('li');
element.innerText = `${name} -> ${country}`;
container.appendChild(element);
})
})
})
document
.getElementById('create_random_user_button')
.addEventListener('click', () => {
const person = getNewPerson();
gun.user().create(person.name, 'simplepassword123', async () => {
// login as the registered user
gun.user().auth(person.name, 'simplepassword123', () => {
// put some data in a public profile
gun.user().get('profile').put(person, async () => {
// register the user in a content addressed node
const pub = gun.user().is.pub;
const hash = await SEA.work(pub, null, null, {name: "SHA-256"});
gun.get('#user_catalogue_1').get(hash).put(pub);
// logout
gun.user().leave();
});
});
});
});
}