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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
function threadPage (src, keys) {
get(src).then(msg => {
scroller.appendChild(render(msg, keys))
})
}
function profilePage (src, keys) {
var server = 'ws://localhost:8080/'
var profile = h('div', {classList: 'profile'})
scroller.appendChild(profile)
var input = h('input', {placeholder: 'New name'})
profile.appendChild(h('a', {href: '#' + src}, [getName(src)]))
profile.appendChild(h('div', [
input,
h('button', {
onclick: function () {
content = {
type: 'name',
named: src,
name: input.value
}
publish(content, keys).then(function () {location.reload()})
}
}, ['Identify'])
]))
profile.appendChild(h('button', {
onclick: function () {
sync(src, server, keys)
}
}, ['Sync feed']))
profile.appendChild(h('button', {
onclick: function () {
localforage.removeItem(src).then(function () { location.reload() })
}
}, ['Delete feed']))
bog(src).then(log => {
if (log) {
log.forEach(function (msg) {
open(msg).then(post => {
scroller.appendChild(render(post, keys))
})
})
}
})
}
function publicPage (keys) {
var newlog = []
scroller.appendChild(h('button', {
onclick: function () {
var openedlog = []
localforage.iterate(function(value, key, i) {
if (key[0] == '@') {
newlog = newlog.concat(value)
}
console.log(newlog)
}).then(function () {
newlog.forEach(function (msg) {
var pubkey = nacl.util.decodeBase64(msg.author.substring(1))
var sig = nacl.util.decodeBase64(msg.signature)
var opened = JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey)))
opened.key = msg.key
openedlog.push(opened)
})
console.log(openedlog)
localforage.setItem('log', openedlog).then(function () {location.reload()})
})
}
}, ['Merge']))
scroller.appendChild(h('button', {
onclick: function () {
localforage.getItem('log').then(log => {
log.sort((a, b) => a.timestamp - b.timestamp)
console.log(log)
var reversed = log.reverse()
localforage.setItem('log', reversed).then(function () {location.reload()})
})
}
}, ['Sort']))
scroller.appendChild(h('button', {
onclick: function () {
var openedlog = []
localforage.iterate(function(value, key, i) {
if (key[0] == '@') {
newlog = newlog.concat(value)
}
console.log(newlog)
}).then(function () {
newlog.forEach(function (msg) {
var pubkey = nacl.util.decodeBase64(msg.author.substring(1))
var sig = nacl.util.decodeBase64(msg.signature)
var opened = JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey)))
opened.key = msg.key
openedlog.push(opened)
})
console.log(openedlog)
openedlog.sort((a, b) => a.timestamp - b.timestamp)
var reversed = openedlog.reverse()
localforage.setItem('log', reversed).then(function () {location.reload()})
})
}
}, ['Regenerate']))
scroller.appendChild(composer(keys))
bog().then(log => {
log.forEach(function (msg) {
scroller.appendChild(render(msg, keys))
})
})
}
function keyPage (keys) {
var message = h('div', {classList: 'message'})
message.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using [Bogbook](http://bogbook.com/), save your key in a safe place so that you can continue to use the same identity.')}))
message.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])]))
message.appendChild(h('button', {
onclick: function () {
localforage.removeItem('id', function () {
location.hash = ''
location.reload()
})
}
}, ['Delete Key']))
var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'})
message.appendChild(textarea)
message.appendChild(h('button', {
onclick: function () {
if (textarea.value) {
localforage.setItem('id', JSON.parse(textarea.value))
location.reload()
}
}
}, ['Import Key']))
scroller.appendChild(message)
}
|