forked from Trac-Systems/intercom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
390 lines (342 loc) Β· 12.8 KB
/
index.js
File metadata and controls
390 lines (342 loc) Β· 12.8 KB
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
// ββ STATE ββ
let vaults = [];
let feedLog = [];
let heartbeatSeconds = 85632; // ~23h 47m remaining
let checkinsToday = 0;
let currentFilter = 'all';
// ββ DEMO DATA ββ
const demoVaults = [
{
id: 'v1',
name: 'Hardware Wallet Recovery',
message: 'The seed phrase is stored in the red notebook on the left shelf of my office bookcase, behind "The Pragmatic Programmer". The PIN is your mother\'s birth year + 1.\n\nWallet addresses:\n- BTC: bc1q...x4k9\n- ETH: 0x2f3...a91b\n- TRAC: trac1abc...def',
recipients: ['trac1alice...', 'trac1bob...'],
deadline: 7,
type: 'π°',
daysLeft: 5.2,
status: 'active',
createdAt: '2026-02-18',
witnesses: ['trac1wit1...', 'trac1wit2...', 'trac1wit3...'],
},
{
id: 'v2',
name: 'Server Admin Credentials',
message: 'Root password is in Bitwarden under "Production Servers".\nSSH key is in ~/.ssh/id_rsa_prod\nContact: DevOps team at devops@company.com',
recipients: ['trac1colleague...'],
deadline: 3,
type: 'π',
daysLeft: 0.8,
status: 'warning',
createdAt: '2026-02-20',
witnesses: ['trac1wit4...', 'trac1wit5...', 'trac1wit6...'],
},
{
id: 'v3',
name: 'Letter to My Family',
message: 'If you are reading this, I want you to know how much I love you all. The things I never said out loud...',
recipients: ['trac1family...', 'trac1spouse...'],
deadline: 30,
type: 'π',
daysLeft: 28.5,
status: 'active',
createdAt: '2026-02-01',
witnesses: ['trac1wit7...', 'trac1wit8...', 'trac1wit9...'],
},
];
const demoFeed = [
{
time: '09:14',
event: '<strong>Witness trac1wit2...</strong> confirmed node alive for <strong>Hardware Wallet Recovery</strong>',
badge: 'witness',
cls: 'badge-witness',
},
{
time: '08:32',
event: '<strong>You</strong> checked in β all vault timers reset',
badge: 'check-in',
cls: 'badge-checkin',
},
{
time: '07:55',
event: '<strong>Witness trac1wit6...</strong> confirmed node alive for <strong>Server Admin Credentials</strong>',
badge: 'witness',
cls: 'badge-witness',
},
{
time: 'yesterday',
event: '<strong>Vault</strong> "Letter to My Family" was sealed and registered on Intercom',
badge: 'create',
cls: 'badge-create',
},
];
// ββ INIT ββ
function init() {
vaults = [...demoVaults];
feedLog = [...demoFeed];
updateStats();
renderVaults();
renderFeed();
startHeartbeatTimer();
startCountdownTick();
}
// ββ STATS ββ
function updateStats() {
document.getElementById('totalVaults').textContent = vaults.filter(v => v.status !== 'triggered').length;
document.getElementById('triggeredCount').textContent = vaults.filter(v => v.status === 'triggered').length;
document.getElementById('checkinsToday').textContent = checkinsToday;
document.getElementById('totalWitnesses').textContent = vaults.length * 3;
}
// ββ RENDER VAULTS ββ
function renderVaults() {
const grid = document.getElementById('vaultGrid');
const filtered = currentFilter === 'all'
? vaults
: vaults.filter(v => v.status === currentFilter);
if (filtered.length === 0) {
grid.innerHTML = `
<div class="empty">
<div class="empty-icon">π</div>
<div class="empty-text">No vaults here yet.<br>Create your first vault using the panel on the left.</div>
</div>`;
return;
}
grid.innerHTML = filtered.map(v => {
const days = Math.floor(v.daysLeft);
const hours = Math.floor((v.daysLeft % 1) * 24);
const display = v.daysLeft < 1 ? hours + 'h' : days + 'd';
const recipStr = v.recipients
.map(r => `<span class="recipient-tag">${r.substring(0, 10)}β¦</span>`)
.join('');
const countdownColor = {
active: '#3d5a4c',
warning: '#b45309',
critical: '#dc2626',
triggered: '#6b7280',
}[v.status] || '#6b7280';
const actions = v.status !== 'triggered'
? `<button class="action-btn confirm" onclick="doCheckin()">β Check In</button>
<button class="action-btn peek" onclick="peekVault('${v.id}')">π Preview</button>
<button class="action-btn revoke" onclick="revokeVault('${v.id}')">β Revoke</button>`
: `<button class="action-btn peek" onclick="peekVault('${v.id}')">π¬ View Released Contents</button>`;
return `
<div class="vault-card ${v.status}" data-id="${v.id}">
<div class="vault-icon">${v.type}</div>
<div>
<div class="vault-name">${v.name}</div>
<div class="vault-meta">
<span>β‘ ${v.deadline}-day window</span>
<span>π₯ ${v.recipients.length} recipient${v.recipients.length > 1 ? 's' : ''}</span>
<span>π§ββοΈ 3 witnesses</span>
<span>π
${v.createdAt}</span>
</div>
<div class="vault-recipients">${recipStr}</div>
<div class="vault-actions">${actions}</div>
</div>
<div class="vault-countdown">
<div class="countdown-val" style="color:${countdownColor}">
${v.status === 'triggered' ? 'SENT' : display}
</div>
<span class="countdown-unit">${v.status === 'triggered' ? 'released' : 'remaining'}</span>
</div>
</div>`;
}).join('');
}
// ββ RENDER FEED ββ
function renderFeed() {
const container = document.getElementById('feedItems');
container.innerHTML = feedLog.map(f => `
<div class="feed-item">
<span class="feed-time">${f.time}</span>
<span class="feed-event">${f.event}</span>
<span class="feed-badge ${f.cls}">${f.badge}</span>
</div>`
).join('') || '<div style="font-size:0.68rem;color:#aaa;padding:1rem 0;">No activity yet.</div>';
}
// ββ CREATE VAULT ββ
function createVault() {
const name = document.getElementById('vaultName').value.trim();
const message = document.getElementById('vaultMessage').value.trim();
const recipientsRaw = document.getElementById('vaultRecipients').value.trim();
const deadline = parseInt(document.getElementById('vaultDeadline').value);
const type = document.getElementById('vaultType').value.split(' ')[0];
if (!name || !message || !recipientsRaw) {
showToast('β Please fill in name, message, and at least one recipient.');
return;
}
const recipients = recipientsRaw.split(',').map(r => r.trim()).filter(Boolean);
const vault = {
id: 'v' + Date.now(),
name,
message,
recipients,
deadline,
type,
daysLeft: deadline,
status: 'active',
createdAt: new Date().toISOString().split('T')[0],
witnesses: ['trac1wit_a...', 'trac1wit_b...', 'trac1wit_c...'],
};
vaults.unshift(vault);
feedLog.unshift({
time: 'just now',
event: `<strong>Vault</strong> "${name}" sealed and registered on Intercom P2P mesh with ${recipients.length} recipient(s)`,
badge: 'create',
cls: 'badge-create',
});
// Reset form fields
['vaultName', 'vaultMessage', 'vaultRecipients'].forEach(id => {
document.getElementById(id).value = '';
});
updateStats();
renderVaults();
renderFeed();
showToast(`π Vault "${name}" sealed successfully.`);
}
// ββ CHECK IN ββ
function doCheckin() {
heartbeatSeconds = 86400; // reset to 24h
checkinsToday++;
updateStats();
updateHeartbeatDisplay();
vaults.forEach(v => {
if (v.status === 'warning') v.status = 'active';
});
feedLog.unshift({
time: 'just now',
event: '<strong>You</strong> checked in β all vault timers reset',
badge: 'check-in',
cls: 'badge-checkin',
});
renderVaults();
renderFeed();
showToast('β Check-in confirmed. All vaults reset.');
}
// ββ REVOKE VAULT ββ
function revokeVault(id) {
const vault = vaults.find(v => v.id === id);
if (!vault) return;
if (!confirm(`Revoke vault "${vault.name}"? This will permanently destroy the sealed contents.`)) return;
feedLog.unshift({
time: 'just now',
event: `<strong>Vault</strong> "${vault.name}" was revoked and destroyed`,
badge: 'revoke',
cls: 'badge-release',
});
vaults = vaults.filter(v => v.id !== id);
updateStats();
renderVaults();
renderFeed();
showToast(`π Vault "${vault.name}" revoked.`);
}
// ββ PEEK VAULT (MODAL) ββ
function peekVault(id) {
const vault = vaults.find(v => v.id === id);
if (!vault) return;
const isTriggered = vault.status === 'triggered';
document.getElementById('modalTitle').textContent = vault.type + ' ' + vault.name;
document.getElementById('modalBody').innerHTML = `
<div style="font-size:0.65rem;letter-spacing:0.12em;text-transform:uppercase;color:#888;margin-bottom:0.75rem;">
${isTriggered ? 'π¬ Released to Recipients' : 'π Sealed Β· Preview Mode'}
</div>
${isTriggered
? `<div class="reveal-box">${vault.message}</div>`
: `<div class="reveal-box" style="filter:blur(4px);user-select:none;cursor:not-allowed;">${vault.message}</div>
<p class="modal-note">β Contents are encrypted and sealed. They will only be revealed to your designated recipients after the dead man's switch triggers. This is a preview of the sealed state.</p>`
}
<div style="margin-top:1rem;">
<div style="font-size:0.65rem;letter-spacing:0.12em;text-transform:uppercase;color:#888;margin-bottom:0.5rem;">Recipients</div>
${vault.recipients.map(r => `<span class="recipient-tag">${r}</span>`).join('')}
</div>
<div style="margin-top:1rem;font-size:0.65rem;color:#888;">
<strong>Witnesses:</strong> ${vault.witnesses.join(' Β· ')}
</div>`;
document.getElementById('modal').classList.add('open');
}
function closeModal() {
document.getElementById('modal').classList.remove('open');
}
// ββ SIMULATE TRIGGER (DEMO) ββ
function simulateTrigger() {
const active = vaults.find(v => v.status !== 'triggered');
if (!active) { showToast('No active vaults to trigger.'); return; }
active.status = 'triggered';
active.daysLeft = 0;
feedLog.unshift({
time: 'just now',
event: `π¨ <strong>VAULT TRIGGERED</strong> β "${active.name}" released to ${active.recipients.length} recipient(s) after witness consensus`,
badge: 'release',
cls: 'badge-release',
});
updateStats();
renderVaults();
renderFeed();
showToast(`π¨ TRIGGERED: "${active.name}" has been released!`);
}
// ββ FILTER TABS ββ
function filterVaults(filter, btn) {
currentFilter = filter;
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
btn.classList.add('active');
renderVaults();
}
// ββ HEARTBEAT TIMER ββ
function startHeartbeatTimer() {
setInterval(() => {
heartbeatSeconds = Math.max(0, heartbeatSeconds - 1);
updateHeartbeatDisplay();
if (heartbeatSeconds <= 0) triggerHeartbeatMiss();
}, 1000);
}
function updateHeartbeatDisplay() {
const h = Math.floor(heartbeatSeconds / 3600);
const m = Math.floor((heartbeatSeconds % 3600) / 60);
const s = heartbeatSeconds % 60;
document.getElementById('heartbeatTimer').textContent =
String(h).padStart(2, '0') + ':' +
String(m).padStart(2, '0') + ':' +
String(s).padStart(2, '0');
const pct = ((86400 - heartbeatSeconds) / 86400 * 100).toFixed(1);
document.getElementById('progressFill').style.width = pct + '%';
const dot = document.getElementById('statusDot');
const statusText = document.getElementById('statusText');
if (heartbeatSeconds > 28800) { // > 8h β safe
dot.className = 'status-dot status-safe';
statusText.textContent = 'All vaults safe';
} else if (heartbeatSeconds > 7200) { // > 2h β warn
dot.className = 'status-dot status-warn';
statusText.textContent = 'Check-in recommended soon';
vaults.forEach(v => { if (v.status === 'active') v.status = 'warning'; });
renderVaults();
} else { // < 2h β critical
dot.className = 'status-dot status-danger';
statusText.textContent = 'CRITICAL β Check in now!';
}
}
function triggerHeartbeatMiss() {
showToast('β Heartbeat missed! Witnesses will attempt contact.');
}
// ββ VAULT COUNTDOWN TICK (every minute) ββ
function startCountdownTick() {
setInterval(() => {
vaults.forEach(v => {
if (v.status === 'triggered') return;
v.daysLeft = Math.max(0, v.daysLeft - 1 / 86400);
if (v.daysLeft < 1 && v.status === 'active') v.status = 'warning';
if (v.daysLeft < 0.1 && v.status === 'warning') v.status = 'critical';
});
renderVaults();
}, 60000);
}
// ββ TOAST NOTIFICATION ββ
function showToast(msg) {
const t = document.getElementById('toast');
t.textContent = msg;
t.style.display = 'block';
setTimeout(() => { t.style.display = 'none'; }, 3500);
}
// ββ MODAL CLOSE ON OVERLAY CLICK ββ
document.getElementById('modal').addEventListener('click', function (e) {
if (e.target === this) closeModal();
});
// ββ BOOT ββ
init();