-
Notifications
You must be signed in to change notification settings - Fork 5
/
key.js
44 lines (37 loc) · 945 Bytes
/
key.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
function hex_char(val)
{
if (val < 10)
return String.fromCharCode(48 + val)
if (val < 16)
return String.fromCharCode(97 + val - 10)
}
function hex_encode(buf)
{
str = ""
for (let i = 0; i < buf.length; i++) {
const c = buf[i]
str += hex_char(c >> 4)
str += hex_char(c & 0xF)
}
return str
}
function go() {
const el = document.querySelector("#pub-key")
const hex_el = document.querySelector("#hex-key")
const note_link_el = document.querySelector("#note-link")
const profile_link_el = document.querySelector("#profile-link")
el.addEventListener("input", () => {
const decoded = bech32.decode(el.value)
const bytes = fromWords(decoded.words)
hex_el.value = hex_encode(bytes)
update_note_link(hex_el.value)
});
hex_el.addEventListener("input", () => {
update_note_link(hex_el.value)
})
function update_note_link(id) {
note_link_el.href = `nostr:e:${id}`
profile_link_el.href = `nostr:p:${id}`
}
}
go()