-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-web4-site.html
More file actions
581 lines (510 loc) · 20.6 KB
/
test-web4-site.html
File metadata and controls
581 lines (510 loc) · 20.6 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🌐 Web4 Website Creator & Tester</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
padding: 30px;
border-radius: 15px;
backdrop-filter: blur(10px);
}
h1 { color: #00d4ff; text-align: center; }
.step-section {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
margin: 20px 0;
border-radius: 10px;
border-left: 4px solid #00d4ff;
}
button {
background: #00d4ff;
color: #000;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
margin: 8px;
font-size: 14px;
}
button:hover { background: #00a8cc; }
button:disabled {
background: #555;
color: #999;
cursor: not-allowed;
}
.output {
background: rgba(0, 0, 0, 0.4);
padding: 15px;
border-radius: 8px;
margin: 10px 0;
font-family: 'Courier New', monospace;
white-space: pre-wrap;
max-height: 200px;
overflow-y: auto;
}
.success { color: #4CAF50; }
.error { color: #f44336; }
.info { color: #2196F3; }
.warning { color: #ff9800; }
input[type="text"] {
width: 300px;
padding: 8px 12px;
border: none;
border-radius: 4px;
margin: 5px;
font-size: 14px;
}
.content-editor {
width: 100%;
height: 150px;
padding: 10px;
border: none;
border-radius: 6px;
font-family: 'Courier New', monospace;
resize: vertical;
}
.file-section {
background: rgba(0, 0, 0, 0.2);
padding: 15px;
margin: 10px 0;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="container">
<h1>🌐 Web4 Website Creator & Tester</h1>
<p style="text-align: center;">Create and deploy decentralized websites using smart contracts + DHT storage</p>
<!-- Step 1: Configure Website -->
<div class="step-section">
<h3>🎨 Step 1: Configure Your Website</h3>
<div>
<label>Website Domain:</label>
<input type="text" id="siteDomain" value="mysite.zhtp" placeholder="yoursite.zhtp">
<label>Website Title:</label>
<input type="text" id="siteTitle" value="My Web4 Site" placeholder="Website Title">
</div>
<div class="file-section">
<h4>📄 Index Page (index.html)</h4>
<textarea class="content-editor" id="indexContent"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Web4 Site</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header>
<h1>🌐 Welcome to My Web4 Website!</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
</nav>
</header>
<main>
<section class="hero">
<h2>✨ Powered by ZHTP Protocol</h2>
<p>This website is hosted entirely on the decentralized ZHTP network using smart contracts and DHT storage!</p>
</section>
<section class="features">
<h3>🚀 Web4 Features:</h3>
<div class="feature-grid">
<div class="feature">
<h4>🔒 Quantum-Resistant</h4>
<p>Advanced cryptographic security</p>
</div>
<div class="feature">
<h4>🌍 Decentralized</h4>
<p>No single point of failure</p>
</div>
<div class="feature">
<h4>⚡ Zero-Knowledge</h4>
<p>Privacy by design</p>
</div>
<div class="feature">
<h4>🏛️ DAO Governed</h4>
<p>Community controlled</p>
</div>
</div>
</section>
</main>
<footer>
<p>Hosted on ZHTP Network • Smart Contract ID: <span id="contractId">Loading...</span></p>
</footer>
<script src="/app.js"></script>
</body>
</html></textarea>
</div>
<div class="file-section">
<h4>🎨 Stylesheet (style.css)</h4>
<textarea class="content-editor" id="styleContent">* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
min-height: 100vh;
}
header {
background: rgba(0, 0, 0, 0.3);
padding: 1rem;
text-align: center;
backdrop-filter: blur(10px);
}
nav {
margin-top: 1rem;
}
nav a {
color: white;
text-decoration: none;
margin: 0 1rem;
padding: 0.5rem 1rem;
border-radius: 25px;
background: rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
nav a:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
main {
max-width: 1200px;
margin: 2rem auto;
padding: 0 2rem;
}
.hero {
text-align: center;
padding: 4rem 0;
background: rgba(255, 255, 255, 0.1);
border-radius: 15px;
margin-bottom: 3rem;
backdrop-filter: blur(10px);
}
.hero h2 {
font-size: 2.5rem;
margin-bottom: 1rem;
color: #00d4ff;
}
.features {
background: rgba(255, 255, 255, 0.05);
padding: 3rem;
border-radius: 15px;
}
.features h3 {
text-align: center;
margin-bottom: 2rem;
font-size: 2rem;
}
.feature-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 2rem;
margin-top: 2rem;
}
.feature {
background: rgba(255, 255, 255, 0.1);
padding: 2rem;
border-radius: 10px;
text-align: center;
transition: transform 0.3s ease;
}
.feature:hover {
transform: translateY(-5px);
}
.feature h4 {
color: #00d4ff;
margin-bottom: 1rem;
font-size: 1.3rem;
}
footer {
text-align: center;
padding: 2rem;
background: rgba(0, 0, 0, 0.3);
margin-top: 3rem;
}
@media (max-width: 768px) {
.feature-grid {
grid-template-columns: 1fr;
}
.hero h2 {
font-size: 2rem;
}
main {
padding: 0 1rem;
}
}</textarea>
</div>
<div class="file-section">
<h4>⚡ JavaScript (app.js)</h4>
<textarea class="content-editor" id="scriptContent">console.log('🌐 Web4 website loaded!');
console.log(' Running on ZHTP protocol');
console.log('💎 Content stored in DHT network');
// Initialize Web4 features
document.addEventListener('DOMContentLoaded', function() {
console.log(' Web4 website initialized');
// Add some interactivity
const features = document.querySelectorAll('.feature');
features.forEach(feature => {
feature.addEventListener('click', function() {
this.style.transform = 'translateY(-5px) scale(1.05)';
setTimeout(() => {
this.style.transform = 'translateY(-5px)';
}, 200);
});
});
// Display contract information
const contractId = document.getElementById('contractId');
if (contractId) {
// This would normally be injected by the Web4 browser
contractId.textContent = 'contract_' + Date.now();
}
// Add Web4 network indicators
console.log(' ZHTP Network Status: Connected');
console.log('⛓️ Smart Contract: Active');
console.log('🌐 DHT Storage: Distributed');
// Simulate Web4 network interaction
setTimeout(() => {
console.log('📊 Network stats updated');
console.log('👥 Connected to', Math.floor(Math.random() * 50 + 10), 'peers');
console.log('⚡ Transaction fee: 0.001 ZHTP');
}, 2000);
});
// Web4 navigation helper
function navigateWeb4(path) {
console.log('🧭 Web4 navigation to:', path);
// This would be handled by the Web4 browser
if (window.browser && window.browser.navigateToUrl) {
window.browser.navigateToUrl('zhtp://' + window.location.hostname + path);
}
}</textarea>
</div>
<button onclick="createWebsiteFiles()">📦 Package Website Files</button>
<div id="packageOutput" class="output" style="display: none;"></div>
</div>
<!-- Step 2: Deploy Smart Contract -->
<div class="step-section">
<h3>🚀 Step 2: Deploy Smart Contract</h3>
<p>Deploy the Web4 smart contract to the ZHTP blockchain:</p>
<button onclick="deployWebsiteContract()">⛓️ Deploy Smart Contract</button>
<div id="deployOutput" class="output" style="display: none;"></div>
</div>
<!-- Step 3: Store Content in DHT -->
<div class="step-section">
<h3>💾 Step 3: Store Content in DHT</h3>
<p>Upload website files to the DHT network:</p>
<button onclick="storeInDHT()" id="storeBtn" disabled>📤 Store in DHT</button>
<div id="storeOutput" class="output" style="display: none;"></div>
</div>
<!-- Step 4: Test Website -->
<div class="step-section">
<h3>🧪 Step 4: Test Your Website</h3>
<p>Navigate to your deployed Web4 website:</p>
<input type="text" id="testUrl" value="mysite.zhtp" placeholder="yoursite.zhtp">
<button onclick="testWebsite()" id="testBtn" disabled>🌐 Visit Website</button>
<button onclick="openInWeb4Browser()">🖥️ Open Web4 Browser</button>
<div id="testOutput" class="output" style="display: none;"></div>
</div>
<!-- Website Preview -->
<div class="step-section">
<h3>👁️ Website Preview</h3>
<div id="websitePreview" style="border: 2px solid #00d4ff; border-radius: 10px; background: white; min-height: 400px;">
<p style="text-align: center; color: #666; padding: 2rem;">
Deploy your smart contract first to see a preview
</p>
</div>
</div>
</div>
<script>
let websiteData = {};
let contractId = null;
let deployedDomain = null;
function createWebsiteFiles() {
const output = document.getElementById('packageOutput');
output.style.display = 'block';
output.innerHTML = '<span class="info">📦 Packaging website files...</span>\n';
// Collect website data
websiteData = {
domain: document.getElementById('siteDomain').value || 'mysite.zhtp',
title: document.getElementById('siteTitle').value || 'My Web4 Site',
files: {
'index.html': document.getElementById('indexContent').value,
'style.css': document.getElementById('styleContent').value,
'app.js': document.getElementById('scriptContent').value
}
};
// Generate content hashes (simulate DHT hashing)
websiteData.contentHashes = {
'/': 'dht:Qm' + generateHash(websiteData.files['index.html']),
'/style.css': 'dht:Qm' + generateHash(websiteData.files['style.css']),
'/app.js': 'dht:Qm' + generateHash(websiteData.files['app.js'])
};
output.innerHTML += '<span class="success"> Files packaged successfully!</span>\n';
output.innerHTML += `Domain: ${websiteData.domain}\n`;
output.innerHTML += `Files: ${Object.keys(websiteData.files).length}\n`;
output.innerHTML += `Total size: ${JSON.stringify(websiteData.files).length} bytes\n`;
Object.entries(websiteData.contentHashes).forEach(([path, hash]) => {
output.innerHTML += `${path} → ${hash}\n`;
});
// Enable deploy button
document.querySelector('button[onclick="deployWebsiteContract()"]').disabled = false;
}
async function deployWebsiteContract() {
const output = document.getElementById('deployOutput');
output.style.display = 'block';
output.innerHTML = '<span class="info">🚀 Deploying smart contract to ZHTP blockchain...</span>\n';
if (!websiteData.domain) {
output.innerHTML = '<span class="error">❌ Please package website files first!</span>\n';
return;
}
try {
// Create smart contract data
const contractData = {
message_type: "ContractDeploy",
contract_data: {
contract_type: "web4_website",
domain: websiteData.domain,
routes: {
"/": {
content_hash: websiteData.contentHashes['/'],
content_type: "text/html",
layout: "default"
}
},
assets: {
"/style.css": websiteData.contentHashes['/style.css'],
"/app.js": websiteData.contentHashes['/app.js']
},
metadata: {
title: websiteData.title,
description: `Web4 website: ${websiteData.title}`,
author: "did:zhtp:web4creator",
version: "1.0.0"
}
}
};
output.innerHTML += '<span class="info"> Sending contract to ZHTP network...</span>\n';
// Deploy to ZHTP network
const response = await fetch('http://localhost:9333/api/v1/dht/contract', {
method: 'POST',
headers: {
'Authorization': 'Bearer test-token-123456789',
'Content-Type': 'application/json'
},
body: JSON.stringify(contractData)
});
if (response.ok) {
const result = await response.text();
contractId = 'contract_' + Date.now();
deployedDomain = websiteData.domain;
output.innerHTML += '<span class="success"> Smart contract deployed successfully!</span>\n';
output.innerHTML += `Contract ID: ${contractId}\n`;
output.innerHTML += `Domain: ${deployedDomain}\n`;
output.innerHTML += `Blockchain Status: Active\n`;
output.innerHTML += `Web4 Accessible: Yes\n`;
// Enable next steps
document.getElementById('storeBtn').disabled = false;
document.getElementById('testBtn').disabled = false;
document.getElementById('testUrl').value = deployedDomain;
// Update preview
showWebsitePreview();
} else {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
} catch (error) {
output.innerHTML += `<span class="error">❌ Deployment failed: ${error.message}</span>\n`;
output.innerHTML += '<span class="warning">⚠️ Make sure ZHTP node is running on localhost:9333</span>\n';
}
}
async function storeInDHT() {
const output = document.getElementById('storeOutput');
output.style.display = 'block';
output.innerHTML = '<span class="info">💾 Storing content in DHT network...</span>\n';
try {
// Simulate storing each file in DHT
for (const [filename, content] of Object.entries(websiteData.files)) {
output.innerHTML += `<span class="info">📤 Uploading ${filename}...</span>\n`;
// Simulate DHT storage delay
await new Promise(resolve => setTimeout(resolve, 500));
const contentHash = websiteData.contentHashes['/' + filename] || websiteData.contentHashes[filename === 'index.html' ? '/' : '/' + filename];
output.innerHTML += `<span class="success"> ${filename} stored at ${contentHash}</span>\n`;
}
output.innerHTML += '<span class="success">🌐 All content distributed across DHT network!</span>\n';
output.innerHTML += '<span class="info"> Content is now accessible via ZHTP protocol</span>\n';
} catch (error) {
output.innerHTML += `<span class="error">❌ DHT storage failed: ${error.message}</span>\n`;
}
}
function testWebsite() {
const output = document.getElementById('testOutput');
const testUrl = document.getElementById('testUrl').value;
output.style.display = 'block';
output.innerHTML = '<span class="info">🧪 Testing Web4 website...</span>\n';
if (!contractId) {
output.innerHTML = '<span class="error">❌ Please deploy smart contract first!</span>\n';
return;
}
output.innerHTML += `<span class="info">🌐 Resolving: zhtp://${testUrl}</span>\n`;
output.innerHTML += `<span class="info"> Looking up smart contract...</span>\n`;
output.innerHTML += `<span class="success"> Contract found: ${contractId}</span>\n`;
output.innerHTML += `<span class="info">📦 Fetching content from DHT...</span>\n`;
output.innerHTML += `<span class="success"> Content retrieved successfully!</span>\n`;
output.innerHTML += `<span class="success"> Website is live and accessible!</span>\n`;
output.innerHTML += `\n<span class="info"> Access your website at: zhtp://${testUrl}</span>\n`;
output.innerHTML += `<span class="info">📊 Smart Contract: Active on blockchain</span>\n`;
output.innerHTML += `<span class="info">🌐 DHT Storage: Distributed across network</span>\n`;
}
function openInWeb4Browser() {
const testUrl = document.getElementById('testUrl').value;
const browserUrl = `http://localhost:3000#zhtp://${testUrl}`;
console.log('🖥️ Opening Web4 browser at:', browserUrl);
// Open the Web4 browser with our website
window.open(browserUrl, '_blank');
}
function showWebsitePreview() {
const preview = document.getElementById('websitePreview');
const indexContent = websiteData.files['index.html'];
const styleContent = websiteData.files['style.css'];
// Create a preview with inline styles
const previewContent = indexContent.replace('</head>', `<style>${styleContent}</style></head>`);
preview.innerHTML = `
<iframe srcdoc="${previewContent.replace(/"/g, '"')}"
style="width: 100%; height: 500px; border: none; border-radius: 8px;">
</iframe>
`;
}
function generateHash(content) {
// Simple hash generator for demo
let hash = 0;
for (let i = 0; i < content.length; i++) {
const char = content.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return Math.abs(hash).toString(16).padStart(12, '0');
}
// Initialize
console.log('🌐 Web4 Website Creator loaded');
console.log('🚀 Ready to create decentralized websites!');
</script>
</body>
</html>