-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
582 lines (522 loc) · 19.9 KB
/
index.html
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.2.0/css/all.css">
<link href="bulma.css" rel="stylesheet">
<link href="bulma-prefers-dark.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/simplestore-indexeddb@1.2.1/dist/simplestore.min.js"></script>
<script src="https://bitcoincore.tech/apps/bitcoinjs-ui/lib/bitcoinjs-lib.js"></script>
<script src="https://bundle.run/bip39@3.0.4"></script>
<script src="https://bundle.run/bip32@2.0.6"></script>
<script src="https://bundle.run/buffer@6.0.3"></script>
<script src="https://bundle.run/noble-secp256k1@1.2.14"></script>
<script src="https://bundle.run/browserify-cipher@1.0.1"></script>
<script src="profile.js"></script>
<script src="elements.js"></script>
<script src="events.js"></script>
<script src="problems.js"></script>
<script src="protocol.js"></script>
<script src="patches.js"></script>
<script src="doki.js"></script>
<script src="renderId.js"></script>
<script src="diff_match_patch_uncompressed.js"></script>
<script src="showdown.min.js"></script>
<script src="home.js"></script>
<script src="account.js"></script>
<script src="samizdat.js"></script>
<script src="ushtree.js"></script>
<script src="status.js"></script>
<script src="expenses.js"></script>
<script src="rankings.js"></script>
<script src="nostr.js"></script>
<script src="dividends.js"></script>
<script src="connecting.js"></script>
<script src="kinds.js"></script>
<script src="window.nostr.js"></script>
<link href='https://fonts.googleapis.com/css?family=Ubuntu&subset=cyrillic,latin' rel='stylesheet' type='text/css' />
<style type="text/css" >
body {
font-family : 'Ubuntu', sans-serif;
}
</style>
<script>
function computeRawPrivkey(node) {
return bitcoinjs.ECPair.fromPrivateKey(node.privateKey, {network: bitcoinjs.networks.mainnet});
}
</script>
<script>
function getPrivkeyHex(backupwords) {
var seed = bip39.mnemonicToSeedSync(backupwords);
var node = bip32.fromSeed(seed);
var npath = `m/44'/1237'/0'/0/0`
var child = node.derivePath(npath);
return computeRawPrivkey(child);
}
</script>
<script>
function toHexString(byteArray) {
return Array.from(byteArray, function (byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
}
</script>
<script>
checkNostr()
var pubKey = ""
if ((localStorage.getItem('backupwords') === null) && (localStorage.getItem('privatekey') === null)){
localStorage.setItem('backupwords', bip39.generateMnemonic())
}
if (localStorage.getItem('backupwords') !== null) {
var privKey = getPrivkeyHex(localStorage.getItem('backupwords'));
privKey = privKey.__D.toString('hex');
localStorage.setItem('privatekey', privKey)
}
if (localStorage.getItem('privatekey') !== null) {
pubKey = nobleSecp256k1.getPublicKey(localStorage.getItem('privatekey'), true);
}
//be aware that not all valid bitcoin pubkeys are valid nostr pubkeys. Valid bitcoin pubkeys include uncompressed pubkeys (that start with 04), compressed pubkeys whose y coordinate is positive (that start with 02), and compressed pubkeys whose y coordinate is negative (that start with 03).
//Only the ones that start with 02 are valid for nostr, which then allows us to chop off the 02 when storing the pubkey.
//So if you change this code to generate random pubkeys, be sure to only use ones that have an 02 at the beginning.
//The pubkeyMinus2 variable is the pubkey created a moment ago but without the 02 at the beginning.
var pubKeyMinus2 = pubKey.substring(2);
pubkeydiv = document.createElement("div");
pubkeydiv.innerHTML = `You are currently using public key ` + pubKeyMinus2;
</script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
// Add a click event on each of them
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
});
</script>
</head>
<body>
<nav aria-label="main navigation" class="navbar is-active is-light" role="navigation">
<div class="navbar-brand">
<div class="navbar-item" >
<a href="#" onclick="renderHome()"><img src="head.png" /></a>
</div>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div class="navbar-menu" id="navbarBasicExample">
<div class="navbar-start">
<a class="navbar-item" href="https://github.com/stackerstan">
<i class="fab fa-github"></i>
</a>
<a class="navbar-item" href="https://t.me/stackerstan">
<img src="Telegram_logo.svg.webp" />
</a>
<a class="navbar-item" onclick="displayKinds()">
Nostr Event Kind Registry
</a>
<a class="navbar-item" onclick="displayUshTree()">
Identity Tree
</a>
<a class="navbar-item" onclick="displaySamizdat()">
Samizdatree
</a>
</div>
<div class="navbar-end">
<a class="navbar-item" style="background-color: #FF9900; color: #ffffff" onclick="renderGettingStarted()">
Get Started Now
</a>
<a class="navbar-item" onclick="displayAccount()">
My Account
</a>
<div class="block" onclick="displayStatus()">
<p><span id="welay" class="block"></span></p>
<p><progress class="progress is-small is-primary block" id="welayconnection" style="width: 90%; height: 4px">15%</progress></p>
</div>
</div>
</div>
</nav>
<div class="content" id="maincontent">
<div class="content" id="connecting"></div>
</div>
<script>
displayWhileConnecting()
function normalizeRelayURL(e) {
let [t, ...r] = e.trim().split("?");
return "http" === t.slice(0, 4) && (t = "ws" + t.slice(4)), "ws" !== t.slice(0, 2) && (t = "wss://" + t), t.length && "/" === t[t.length - 1] && (t = t.slice(0, -1)), [t, ...r].join("?")
}
var relay = "ws://localhost:1031" //"wss://mindmachine.688.org"
relay = normalizeRelayURL(relay);
document.getElementById("welay").innerText = relay
var socket = new WebSocket(relay);
var relaySocket = new WebSocket(normalizeRelayURL("wss://nostr.688.org"));
// function subscribe( pubkey ) {
// var filter = {
// "authors": [
// pubkey
// ]
// };
// var subscription = [ "REQ", "my-sub", filter ];
// subscription = JSON.stringify( subscription );
// sessionStorage.subscription = subscription;
// socket.send( sessionStorage.subscription );
// }
// function fetchSingleEvent(event) {
// if (event !== undefined) {
// var filter = {
// "ids": [event],
// };
// subscription = ["REQ", event, filter];
// subscription = JSON.stringify(subscription);
// sessionStorage.subscription = subscription;
// relaySocket.send(sessionStorage.subscription);
// console.log("subscribed to event " + event)
// relaySocket.addEventListener('message', function (received) {
// let parsed = JSON.parse(received.data);
// if (parsed[0] !== "EOSE") {
// if (parsed[2].id === event) {
// enMapReply(event, parsed[2])
// }
// }
//
// })
// subscription = ["CLOSE", event];
// subscription = JSON.stringify(subscription);
// sessionStorage.subscription = subscription;
// relaySocket.send(sessionStorage.subscription);
// }
// }
var eventsToSubscribe = []
function subscribeToComments(event) {
if (event !== undefined) {
eventsToSubscribe.push(event)
// eventsToSubscribe.forEach(function (item, index) {
//
// })
var filter = {
"#e": eventsToSubscribe
};
var subscription = ["REQ", "comments", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
relaySocket.send(sessionStorage.subscription);
console.log(filter)
console.log(socket.readyState)
}
}
function subscribeeventbucket() {
var filter = {
"#eventer": [
"eventbucket"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to eventbucket events")
}
function subscribeprotocol() {
var filter = {
"#eventer": [
"protocol"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to protocol events")
}
function subscribesamizdat() {
var filter = {
"#eventer": [
"samizdat"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to samizdat events")
}
function subscribeidentity() {
var filter = {
"#eventer": [
"identity"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to identity events")
}
function subscribepatches() {
var filter = {
"#eventer": [
"patches"
]
};
var subscription = ["REQ", "patches", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to patch events")
}
function subscribedoki() {
var filter = {
"#eventer": [
"doki"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to doki events")
}
function subscribeCurrentstate() {
var filter = {
"#eventer": [
"currentstate"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to mindstate events")
}
function fetchMindmachineTip() {
var filter = {
"#eventer": [
"mindmachineTip"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to mindmachine events")
}
function subscribeproblems() {
var filter = {
"#eventer": [
"problems"
]
};
var subscription = ["REQ", "my-sub", filter];
subscription = JSON.stringify(subscription);
sessionStorage.subscription = subscription;
socket.send(sessionStorage.subscription);
console.log("subscribed to problem events")
}
socket.addEventListener('open', function () {
socketConnected = true
subscribeToEverything()
});
relaySocket.addEventListener('open', function () {
relaySocketConnected = true
});
socketConnected = false
relaySocketConnected = false
subscribed = false
function subscribeToEverything() {
if (socketConnected && !subscribed) { //if (socketConnected && relaySocketConnected && !subscribed) {
subscribed = true
document.getElementById("welayconnection").value = 100
subscribedoki()
subscribesamizdat()
subscribeprotocol()
subscribeproblems()
subscribepatches()
subscribeCurrentstate()
detect_id()
subscribeidentity()
subscribeeventbucket()
}
}
// Listen for messages
socket.addEventListener('message', function (e) {
//console.log(e.data)
var event = JSON.parse(e.data);
//console.log(event[2])
if (event[2].kind === 640499) {
enMapIdentityObject(event[2])
}
if (event[2].kind === 641097) {
enMapPatch(event[2])
}
if (event[2].kind === 649999) {
j = JSON.parse(event[2].content)
console.log(j)
currentStatus = j
statusready = true
}
if (event[2].kind === 641099) {
downloadLatest(event[2].content)
} else {
switch (event[2].kind) {
case 641699:
k = JSON.parse(event[2].content)
enMapEventBucketObject(k)
break;
case 640699:
enMapProtocolObject(event[2])
break;
case 640899:
enMapProblemObject(event[2])
break;
case 641299:
enMapDokiObject(event[2])
break;
case 1:
event[2].tags.forEach(function (tagArray) {
if (tagArray[0] === "e") {
if (tagArray[1] === rootSamizdatId) {
enMapSamizdat(event[2])
}
}
})
if (event[2].id === rootSamizdatId) {
enMapSamizdat(event[2])
}
break;
case 641297:
dokiReady = true
break;
case 640697:
protocolReady = true
break;
case 640897:
problemsReady = true
break;
case 641497:
samizdatReady = true
break;
case 641651:
// eventbucketObjects.forEach(function (v,k) {
// console.log("kind: " + k + " number: " + v)
// })
kindsReady = true
break;
}
}
});
// Listen for messages
// relaySocket.addEventListener('message', function (e) {
//
// var event = JSON.parse(e.data);
// if (event[0] !== "EOSE") {
// if (event[2].kind === 1) {
// //console.log(event[2])
// //document.body.innerHTML += event[ 2 ].content + " (sent publicly by " + event[ 2 ].pubkey + ")<br><br>";
// } else if (event[2].kind === 126) {
// // div = document.createElement("div")//createTextNode(`<div class="box">`+ event[ 2 ].content + `</div>`)
// // div.innerHTML = `<div class="box">` + `<span class="tag is-primary">`+ event[ 2 ].tags[0][1]+ `</span>` + event[ 2 ].content + `</div>`;
// event[2].tags.forEach(function (tags) {
// if (tags[0] === "mind") {
// switch (tags[1]) {
// case "protocol":
// enMapProtocolObject(event[2])
// break
// case "problems":
// enMapProblemObject(event[2])
// }
// }
// })
// }
// }
// });
</script>
<script>
function makeNote(note, etag) {
e = makeEvent(note, etag, 1)
signHash(e.id).then(
function (result) {
e.sig = result
sendIt(e)
},
function (error) {
console.log(error)
})
}
function sendIt(signedEvent) {
var sendable = ["EVENT", signedEvent];
sessionStorage.sendable = JSON.stringify(sendable);
socket.send('["EVENT",' + JSON.stringify(JSON.parse(sessionStorage.sendable)[1]) + ']');
}
function makeEvent(note, etag, kind) {
var now = Math.floor((new Date().getTime()) / 1000);
tags = []
if (etag !== undefined) {
if (etag.length > 0) {
if (typeof etag === 'string') {
tags.push(["e", etag])
}
if (Array.isArray(etag)) {
tags.push(["e", ...etag])
}
}
}
// if (kind !== 1) {
if (identityObjects.get(pubKeyMinus2) !== undefined) {
sequence = identityObjects.get(pubKeyMinus2).GlobalSequence + 1
tags.push(["sequence", sequence.toString()])
} else {
sequence = 1
tags.push(["sequence", sequence.toString()])
}
//}
tags.push(["height", currentStatus.Height.toString()])
k = 1
if (kind !== undefined) {
k = kind
}
var newevent = [
0,
pubKeyMinus2,
now,
k,
tags,
note
];
var message = JSON.stringify(newevent);
var msghash = bitcoinjs.crypto.sha256(message).toString('hex');
return {
"id": msghash,
"pubkey": pubKeyMinus2,
"created_at": now,
"kind": k,
"tags": tags,
"content": note,
}
}
function signHash(hash) {
return nobleSecp256k1.schnorr.sign(hash, privKey)
}
</script>
<div id="infomodal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title" id="modal-heading">Modal title</p>
<button class="delete" aria-label="close" onclick="document.getElementById('infomodal').classList.remove('is-active')"></button>
</header>
<section class="modal-card-body" id="modal-body">
</section>
</div>
</div>
</body>
</html>