This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
289 lines (230 loc) · 9.26 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
<!DOCTYPE html>
<!---
Hey hey, Read me first.
So if you are curious, I will explain to you.
So how is Nostr account deletion work?
Well, If you are asking about that, That was actually really simple.
You send metadata about your new profile, But you put "deleted: true" on it, like this:
{
"name": "Yonle",
"display_name": "Yonle",
"about": "Self taught programmer from Indonesia",
"website": "https://yonle.lecturify.net",
"nip05": "[email protected]",
"lud16": "[email protected]",
"deleted": true // <--- Here's the cause
}
So what was the project doing here is by sending Event Deletion event (or kind 5 event) about the conflicting event.
Alright. So that's all about how it works.
My Website : https://yonle.lecturify.net
My Nostr : 347a2370900d19b4e4756221594e8bda706ae5c785de09e59e4605f91a03f49c
--->
<!---
BSD 3-Clause License
Copyright (c) 2023, Yonle <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Undelete my Nostr!</title>
<meta name="description" content="Undelete my Nostr account!" />
</head>
<style>
body {
font-size: 14pt;
}
h2,
p {
margin: 0;
}
a {
color: black;
}
div {
margin-top: 30px;
margin-bottom: 30px;
border: 1px solid gray;
padding: 5px;
}
input[type="password"] {
width: 250px;
font-size: 12pt;
}
textarea {
width: 280px;
height: 200px;
}
pre {
white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */
white-space: -pre-wrap; /* Opera */
white-space: -o-pre-wrap; /* Opera */
white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation) http://www.w3.org/TR/css3-text/#white-space */
word-wrap: break-word;
border: 1px solid gray;
font-size: 10pt;
}
@media only screen and (max-width: 480px) {
textarea, input[type="password"], button {
width: 90vw;
}
button {
font-size: 20pt;
}
}
</style>
<body>
<h2 style="margin-top: 15vh;">Undelete my Nostr!</h2>
<p>Undelete my Nostr account!</p>
<div>
<input type="password" placeholder="nsec / hex private key (or use NIP-07)" /><br>
<textarea placeholder="You need a working JavaScript browser enabled"></textarea><br>
<button onclick="scan()">Undelete!</button>
<button onclick="switch_keepProfile()">Keep Profile</button>
<pre>Logs:</pre>
</div>
<a href="#sourcecode" onclick="sourcecode()">Source code</a> - <a href="https://github.com/Yonle/undelete-my-nostr">GitHub repository</a>
<!--- nostr-tools. licensed under public domain --->
<script src="nostr.bundle.js"></script>
<script>
const $ = document.querySelector.bind(document);
let pool = null;
let keepProfile = false;
function sourcecode() {
alert(document.documentElement.innerHTML);
}
function switch_keepProfile() {
if (keepProfile) {
$("pre").innerText += "\n* Keep Profile is OFF.";
return keepProfile = false;
};
$("pre").innerText += "\n* Keep Profile is ON.";
keepProfile = true;
}
async function signEvent(event, privkey) {
event.created_at = Math.floor(Date.now() / 1000);
if (!privkey && window.nostr && typeof(window.nostr) === "object") {
event = await window.nostr.signEvent(event);
} else {
event.pubkey = window.NostrTools.getPublicKey(privkey);
event.id = window.NostrTools.getEventHash(event);
event.sig = window.NostrTools.getSignature(event, privkey);
}
$("pre").innerText += `\n* Signed ${event.id} with ${event.pubkey}`
return event;
}
async function conn() {
if (!window.nostr && (!$("textarea").value || !$('input').value)) return $("pre").innerText += '\n* Please insert a valid private key & list of nostr relays.';
let privkey = $("input").value.startsWith("nsec") ? window.NostrTools.nip19.decode($('input').value).data : $('input').value;
let pubkey = (!privkey && window.nostr) ? await window.nostr.getPublicKey() : window.NostrTools.getPublicKey(privkey);
let relays = $("textarea").value.split("\n").filter(i => i);
if (!relays.length && window.nostr) relays = Object.keys(await window.nostr.getRelays());
localStorage.setItem("relays", JSON.stringify(relays));
$("textarea").value = relays.join("\n");
$("pre").innerText += "\n* Pubkey is " + pubkey;
$("pre").innerText += `\n* You inserted ${relays.length} relays`
$("button").disabled = true;
$("pre").innerText += "\n* Now fetching for profile events. You do not need to wait it till finish.";
pool.sub(relays, [{
authors: [pubkey],
kinds: [0]
}]).on('event', async data => {
try {
let meta = JSON.parse(data.content);
//$("pre").innerText += '\n* Data: ' + data.content;
if (!meta.deleted) return $("pre").innerText += `\n* Your account looks fine: ${data.id}`;
$("pre").innerText += `\n* Your account is deleted: ${data.id}`;
let deletemeta = {
kind: 5,
content: "",
tags: [["e", data.id]]
}
delete meta.deleted;
let newmeta = {
kind: 0,
content: JSON.stringify(meta),
tags: []
}
deletemeta = await signEvent(deletemeta, privkey);
newmeta = await signEvent(newmeta, privkey);
const ok = window.NostrTools.validateEvent(deletemeta);
const veryOk = window.NostrTools.verifySignature(deletemeta);
const newmeta_ok = window.NostrTools.validateEvent(newmeta);
const newmeta_veryOk = window.NostrTools.verifySignature(newmeta);
if (ok && veryOk && newmeta_ok && newmeta_veryOk) {
$("pre").innerText += '\n* Deleting event: ' + data.id
const delpub = pool.publish(relays, deletemeta);
try {
delpub.on('ok', data =>
$("pre").innerText += `\n* DEL OK: ${data}`
);
delpub.on('failed', data =>
$("pre").innerText += `\n* DEL FAILED: ${data}`
);
} catch {}
if (keepProfile) return;
const newpub = pool.publish(relays, newmeta);
try {
newpub.on('ok', data =>
$("pre").innerText += `\n* FIX OK: ${data}`
);
newpub.on('failed', data =>
$("pre").innerText += `\n* FIX FAILED: ${data}`
);
} catch {}
} else {
$("pre").innerText += "\n* Signed event message is invalid. Please check the following:"
$("pre").innerText += "\n* " + JSON.parse(deletemeta);
if (!keepProfile) $("pre").innerText += "\n* " + JSON.parse(newmeta);
}
} catch (e) {
$("pre").innerText += `\n* ${e.toString()}`;
}
});
return;
}
async function scan() {
try {
await conn();
} catch (e) {
$("pre").innerText += `\n* ${e.toString()}`;
$("button").disabled = false;
}
}
if (!window.NostrTools) {
$("pre").innerHTML += '<br><span style="color: red; font-weight: bold;">* Could not load nostr-tools.<br>* Failed to load an library. Please refresh to try again.</span>';
$("button").disabled = true;
} else {
$("pre").innerText += "\n* nostr-tools loaded.";
$("pre").innerText += "\n* Keep Profile is OFF.";
$("textarea").placeholder = "wss://relay.example1.com\nwss://relay.example2.com\n....";
if (localStorage.getItem("relays")) {
$("textarea").value = JSON.parse(localStorage.getItem("relays")).join("\n");
}
pool = new window.NostrTools.SimplePool();
}
</script>
</body>
</html>