@@ -5,31 +5,25 @@ import { fileURLToPath } from "url";
55import nacl from "tweetnacl" ;
66import bip39 from "bip39" ;
77
8- import indexHtml from "./index.html" with { type : "text" } ;
9- import logoSvg from "./assets /logo.svg" with { type : "text" } ;
10- import foundersGroteskFontPath from "./assets /founders-grotesk-bold.woff2" with { type : "file" } ;
11- import nationalFontPath from "./assets /national-regular.woff2" with { type : "file" } ;
8+ import indexHtml from "./static/ index.html" with { type : "text" } ;
9+ import logoSvg from "./static /logo.svg" with { type : "text" } ;
10+ import foundersGroteskFontPath from "./static /founders-grotesk-bold.woff2" with { type : "file" } ;
11+ import nationalFontPath from "./static /national-regular.woff2" with { type : "file" } ;
1212
13- // ESM equivalent of __dirname
1413const __filename : string = fileURLToPath ( import . meta. url ) ;
1514const __dirname : string = path . dirname ( __filename ) ;
1615
17- // Embed static assets for executable builds
1816let foundersGroteskFont : ArrayBuffer ;
1917let nationalFont : ArrayBuffer ;
2018
21- // Load assets asynchronously
2219async function loadAssets ( ) {
2320 try {
2421 foundersGroteskFont = await Bun . file ( foundersGroteskFontPath ) . arrayBuffer ( ) ;
2522 nationalFont = await Bun . file ( nationalFontPath ) . arrayBuffer ( ) ;
2623 } catch ( error ) {
27- console . warn ( "Could not load embedded assets:" , error . message ) ;
28- // Assets will be served from filesystem instead
2924 }
3025}
3126
32- // Type definitions
3327interface MasterKey {
3428 masterPrivateKey : Buffer ;
3529 masterChainCode : Buffer ;
@@ -99,7 +93,7 @@ function base64Encode(buffer: Buffer | Uint8Array): string {
9993 return Buffer . from ( buffer ) . toString ( "base64" ) ;
10094}
10195
102- // Base58 encoding for Octra addresses
96+ // Base58 encoding for octra addresses
10397function base58Encode ( buffer : Buffer ) : string {
10498 if ( buffer . length === 0 ) return "" ;
10599
@@ -272,7 +266,7 @@ function deriveForNetwork(
272266 } ;
273267}
274268
275- // Create Octra address
269+ // Create octra address
276270function createOctraAddress ( publicKey : Buffer ) : string {
277271 const hash : Buffer = crypto . createHash ( "sha256" ) . update ( publicKey ) . digest ( ) ;
278272 const base58Hash : string = base58Encode ( hash ) ;
@@ -392,7 +386,7 @@ async function handleGenerateWallet(): Promise<Response> {
392386 controller . enqueue (
393387 encoder . encode (
394388 `data: ${ JSON . stringify ( {
395- status : "Generating Octra address..." ,
389+ status : "Generating octra address..." ,
396390 } ) } \n\n`
397391 )
398392 ) ;
@@ -513,7 +507,7 @@ async function handleSaveWallet(request: Request): Promise<Response> {
513507 - 8
514508 ) } _${ timestamp } .txt`;
515509
516- const content : string = `OCTRA WALLET
510+ const content : string = `octra wallet
517511${ "=" . repeat ( 50 ) }
518512
519513SECURITY WARNING: KEEP THIS FILE SECURE AND NEVER SHARE YOUR PRIVATE KEY
@@ -611,15 +605,15 @@ function serveEmbeddedAsset(pathname: string): Response | null {
611605 }
612606 break ;
613607
614- case '/assets /logo.svg' :
608+ case '/static /logo.svg' :
615609 if ( logoSvg ) {
616610 return new Response ( logoSvg , {
617611 headers : { 'Content-Type' : 'image/svg+xml' }
618612 } ) ;
619613 }
620614 break ;
621615
622- case '/assets /founders-grotesk-bold.woff2' :
616+ case '/static /founders-grotesk-bold.woff2' :
623617 if ( foundersGroteskFont ) {
624618 return new Response ( foundersGroteskFont , {
625619 headers : {
@@ -630,7 +624,7 @@ function serveEmbeddedAsset(pathname: string): Response | null {
630624 }
631625 break ;
632626
633- case '/assets /national-regular.woff2' :
627+ case '/static /national-regular.woff2' :
634628 if ( nationalFont ) {
635629 return new Response ( nationalFont , {
636630 headers : {
@@ -660,10 +654,8 @@ async function serveStaticFile(filePath: string): Promise<Response> {
660654 }
661655}
662656
663- // Load embedded assets
664657await loadAssets ( ) ;
665658
666- // Start server
667659const PORT : number = 8888 ;
668660
669661const server = Bun . serve ( {
@@ -676,7 +668,6 @@ const server = Bun.serve({
676668 method : request . method ,
677669 } ;
678670
679- // Handle GET requests for static assets (embedded or file system)
680671 if ( method === "GET" ) {
681672 // Try to serve embedded asset first
682673 const embeddedAsset = serveEmbeddedAsset ( pathname ) ;
@@ -686,16 +677,15 @@ const server = Bun.serve({
686677
687678 // Fallback to file system for development mode
688679 if ( pathname === "/" || pathname === "/index.html" ) {
689- return serveStaticFile ( path . join ( __dirname , "index.html" ) ) ;
680+ return serveStaticFile ( path . join ( __dirname , "static/ index.html" ) ) ;
690681 }
691682
692- if ( pathname . startsWith ( "/assets /" ) ) {
683+ if ( pathname . startsWith ( "/static /" ) ) {
693684 const assetPath = path . join ( __dirname , pathname ) ;
694685 return serveStaticFile ( assetPath ) ;
695686 }
696687 }
697688
698- // Handle API routes
699689 if ( method === "POST" && pathname === "/generate" ) {
700690 return handleGenerateWallet ( ) ;
701691 }
@@ -708,9 +698,9 @@ const server = Bun.serve({
708698 return handleDeriveWallet ( request ) ;
709699 }
710700
711- // 404 for all other routes
712701 return new Response ( "Not Found" , { status : 404 } ) ;
713702 } ,
714703} ) ;
715704
716- console . log ( "OCTRA Wallet Generator Web Server" ) ;
705+ console . log ( "octra wallet generator server" ) ;
706+ console . log ( `The server is running at: http://localhost:${ PORT } ` ) ;
0 commit comments