browser-evm-signer 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AA+VvF;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,YAAY,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAmBtD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAEtF"}
1
+ {"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAuC,MAAM,oBAAoB,CAAC;AAgRvF;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,YAAY,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAkBtD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAEtF"}
@@ -1,96 +1,9 @@
1
1
  import { createServer } from "node:http";
2
- import { statSync } from "node:fs";
3
- import { readFile } from "node:fs/promises";
4
2
  import { getPort } from "./config.js";
5
3
  import { pendingStore as defaultPendingStore } from "./pending-store.js";
4
+ import { getIndexHtml } from "./web-ui.js";
6
5
  // Store test results for e2e browser testing
7
6
  const testResults = new Map();
8
- /**
9
- * Get the path to the bundled web UI
10
- */
11
- function getWebDistPath() {
12
- const scriptDir = new URL(".", globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url).pathname;
13
- // Try candidate paths in order. Dev build (web/dist) must come before web/
14
- // because the web/ source directory also exists and would match statSync.
15
- const candidates = [
16
- `${scriptDir}../web/dist`, // dev: src/ → web/dist (vite build output)
17
- `${scriptDir}../dist/web`, // esbuild: dist/ → dist/web
18
- `${scriptDir}../web`, // dnt: esm/ → package root → web/ (contains built assets)
19
- ];
20
- for (const candidate of candidates) {
21
- try {
22
- statSync(candidate);
23
- return candidate;
24
- }
25
- catch {
26
- // try next
27
- }
28
- }
29
- // Fallback — will fail later with a clear error from serveStaticFile
30
- return candidates[0];
31
- }
32
- /**
33
- * Serve static files from the web dist directory
34
- */
35
- async function serveStaticFile(path, webDistPath) {
36
- // Default to index.html for SPA routing
37
- let filePath = path === "/" || path === "" ? "/index.html" : path;
38
- // Remove leading slash and sanitize
39
- filePath = filePath.replace(/^\/+/, "").replace(/\.\./g, "");
40
- const fullPath = `${webDistPath}/${filePath}`;
41
- try {
42
- const file = new Uint8Array(await readFile(fullPath));
43
- const contentType = getContentType(filePath);
44
- return new Response(file, {
45
- headers: {
46
- "Content-Type": contentType,
47
- "Cache-Control": "no-cache",
48
- },
49
- });
50
- }
51
- catch {
52
- // For SPA, serve index.html for any unknown path
53
- if (!filePath.includes(".")) {
54
- try {
55
- const indexHtml = new Uint8Array(await readFile(`${webDistPath}/index.html`));
56
- return new Response(indexHtml, {
57
- headers: {
58
- "Content-Type": "text/html",
59
- "Cache-Control": "no-cache",
60
- },
61
- });
62
- }
63
- catch {
64
- return new Response("Web UI not found. Run 'deno task build:web' first.", {
65
- status: 404,
66
- });
67
- }
68
- }
69
- return new Response("Not found", { status: 404 });
70
- }
71
- }
72
- /**
73
- * Get content type from file extension
74
- */
75
- function getContentType(path) {
76
- const ext = path.split(".").pop()?.toLowerCase();
77
- const types = {
78
- html: "text/html",
79
- js: "application/javascript",
80
- mjs: "application/javascript",
81
- css: "text/css",
82
- json: "application/json",
83
- png: "image/png",
84
- jpg: "image/jpeg",
85
- jpeg: "image/jpeg",
86
- svg: "image/svg+xml",
87
- ico: "image/x-icon",
88
- woff: "font/woff",
89
- woff2: "font/woff2",
90
- ttf: "font/ttf",
91
- };
92
- return types[ext || ""] || "application/octet-stream";
93
- }
94
7
  /**
95
8
  * Handle API requests
96
9
  */
@@ -281,10 +194,21 @@ async function writeResponse(res, response) {
281
194
  res.end();
282
195
  }
283
196
  }
197
+ /**
198
+ * Serve the inline HTML page for any non-API GET request (SPA routing).
199
+ */
200
+ function serveHtml() {
201
+ return new Response(getIndexHtml(), {
202
+ headers: {
203
+ "Content-Type": "text/html",
204
+ "Cache-Control": "no-cache",
205
+ },
206
+ });
207
+ }
284
208
  /**
285
209
  * Create a node:http request handler using the existing Response-based logic.
286
210
  */
287
- function makeHandler(webDistPath, store) {
211
+ function makeHandler(store) {
288
212
  return async (req, res) => {
289
213
  const url = new URL(req.url, `http://${req.headers.host || "127.0.0.1"}`);
290
214
  const pathname = url.pathname;
@@ -309,7 +233,7 @@ function makeHandler(webDistPath, store) {
309
233
  response = handleApiRequest(pathname, method, body, store);
310
234
  }
311
235
  else {
312
- response = await serveStaticFile(pathname, webDistPath);
236
+ response = serveHtml();
313
237
  }
314
238
  await writeResponse(res, response);
315
239
  };
@@ -320,8 +244,7 @@ function makeHandler(webDistPath, store) {
320
244
  */
321
245
  export async function createHttpServer(store, port) {
322
246
  const targetPort = port ?? getPort();
323
- const webDistPath = getWebDistPath();
324
- const srv = createServer(makeHandler(webDistPath, store));
247
+ const srv = createServer(makeHandler(store));
325
248
  await new Promise((resolve) => {
326
249
  srv.listen(targetPort, "127.0.0.1", () => resolve());
327
250
  });
@@ -0,0 +1,3 @@
1
+ /** Returns the self-contained HTML for the wallet signing UI. */
2
+ export declare function getIndexHtml(): string;
3
+ //# sourceMappingURL=web-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-ui.d.ts","sourceRoot":"","sources":["../src/web-ui.ts"],"names":[],"mappings":"AAGA,iEAAiE;AACjE,wBAAgB,YAAY,IAAI,MAAM,CA2qCrC"}