@johnhenry/sitefile 0.0.2 → 0.0.4
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.
- package/CHANGELOG.md +516 -0
- package/README.md +59 -9
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/bake.d.ts +2 -0
- package/lib/src/bake.js +30 -1
- package/lib/src/bcrypt.d.ts +25 -0
- package/lib/src/bcrypt.js +201 -0
- package/lib/src/canonical.d.ts +19 -0
- package/lib/src/canonical.js +60 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +6 -1
- package/lib/src/cli/index.js +34 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +119 -8
- package/lib/src/cli/servers.d.ts +130 -1
- package/lib/src/cli/servers.js +754 -72
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +231 -24
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/hreflang.d.ts +25 -0
- package/lib/src/hreflang.js +72 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +126 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +189 -7
- package/lib/src/language/validate.js +24 -0
- package/lib/src/links.d.ts +47 -0
- package/lib/src/links.js +289 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +87 -2
- package/lib/src/planner.js +189 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +141 -16
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +419 -0
- package/lib/src/resources/archive.d.ts +37 -1
- package/lib/src/resources/archive.js +353 -71
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +33 -0
- package/lib/src/serve-auth.js +120 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +529 -11
- package/lib/src/server.js +1439 -57
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +115 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +58 -0
- package/lib/src/site.js +216 -5
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,18 +76,25 @@ no runtime dependencies.
|
|
|
76
76
|
| `IMPORT name FROM <dir>\|git+https://…#ref:dir AS sitefile [ARG NAME=value]…` | yes; the stages of another Sitefile, local or from Git, as `name+<stage>` in `FROM` and `--from` (like Earthly targets; `examples/shared-stages`), with its own ARGs and paths, pinned in `Sitefile.lock` |
|
|
77
77
|
| `ARG NAME[: type] [= value]` | yes, `string`/`number`/`boolean`, `--build-arg` |
|
|
78
78
|
| `LET NAME[: type] = value` | yes |
|
|
79
|
-
| `IMPORT name FROM <path or https URL> [AS file\|text\|json\|yaml\|csv\|markdown\|wbn\|tree] [INTEGRITY sha256:…] [SORT BY key [DESC]] [SCHEMA <file>] [DRAFTS true\|false]` | yes; `AS tree` unpacks tar, tar.gz, zip and Web Bundles; `AS markdown` reads posts with frontmatter (`SCHEMA` checks it against a YAML/JSON schema); `AS yaml`/`csv`/`wbn` give data for templates |
|
|
79
|
+
| `IMPORT name FROM <path or https URL> [AS file\|text\|json\|yaml\|csv\|markdown\|wbn\|tree] [INTEGRITY sha256:…] [SORT BY key [DESC]] [SCHEMA <file>] [DRAFTS true\|false]` | yes; `AS tree` unpacks tar, tar.gz, tar.zst, zip and Web Bundles; `AS markdown` reads posts with frontmatter (`SCHEMA` checks it against a YAML/JSON schema); `AS yaml`/`csv`/`wbn` give data for templates |
|
|
80
80
|
| `COPY [--overwrite] [--from=<stage>] <source> <dest>` | yes; source is a local path, `name:/path`, `<<EOF` inline content, or with `--from` an absolute path in an earlier stage |
|
|
81
81
|
| `RENDER [--escape=html] [--overwrite] [--from=<stage>] <template> TO <dest> [FOR item IN list [BY key] [PAGE n [FIRST <dest>]]]` | yes; template is a file or `<<EOF` inline body; `${NAME}`, `${json.path}`, `${#each}`, `${#if}`, `${x\|raw}`; `FOR` renders one page per element, `BY` one per tag, `PAGE` paginates |
|
|
82
82
|
| `PLUGIN name FROM ./plugins/x.mjs\|x.wasm [INTEGRITY sha256:…]` | yes; a custom renderer: a sandboxed JS module (runs only with `--allow-plugin name`) or an import-free WebAssembly module (no flag needed; see [docs/PLUGINS.md](docs/PLUGINS.md), `examples/wasm/`) |
|
|
83
83
|
| `TRANSFORM [--include/--exclude=<pattern>] [<source>] WITH name TO <dest> [OPTIONS k=v …] [FOR item IN list]` | yes; e.g. text → animated SVG (`examples/motion/`), responsive images (`examples/image/`); a directory source runs once per file (`TO /img/thumbs/*.png`) |
|
|
84
84
|
| `TOOL name` + `TRANSFORM … WITH name TO <dest> [OPTIONS …] [FOR …] ARGS …` | yes; run an external program (e.g. `ffmpeg`) you allow with `--allow-exec name`: argv only, no shell, temp files, scrubbed environment (see [docs/PLUGINS.md](docs/PLUGINS.md)) |
|
|
85
|
-
| `SITEMAP BASE <url> [TO <dest>]` | yes; a sitemaps.org `/sitemap.xml` of the `.html` pages so far |
|
|
85
|
+
| `SITEMAP BASE <url> [TO <dest>]` | yes; a sitemaps.org `/sitemap.xml` of the `.html` pages so far (a sitemap index and parts above 50,000 URLs or 50 MiB) |
|
|
86
|
+
| `CANONICAL BASE <url> [PRETTY]` | yes; a `<link rel="canonical">` in every page that has none |
|
|
87
|
+
| `LANGUAGES <code>… [DEFAULT <code>]` | yes; `/en/…`, `/fr/…` folders (or frontmatter `lang` + `translationKey`) are translations: CANONICAL adds `hreflang` alternates, SITEMAP `xhtml:link` alternates (`examples/hreflang/`) |
|
|
86
88
|
| `FEED <import> BASE <url> LINK <path> [TO <dest>] [TITLE <text>]` | yes; an Atom `/feed.xml` from Markdown posts (`title` and `date` required) |
|
|
89
|
+
| `ROBOTS [ALLOW\|DISALLOW <path>]… [SITEMAP] [TO <dest>]`, `SECURITY_TXT CONTACT <uri>… EXPIRES <date> [ENCRYPTION <uri>]… [POLICY <uri>]…` | yes; `/robots.txt` (with the SITEMAP URLs) and an RFC 9116 `/.well-known/security.txt` (Expires required; warns when near) |
|
|
87
90
|
| `REDIRECT <from> <to> [STATUS 301\|302\|303\|307\|308]`, `HEADER <pattern> <Name>: <value>` | yes; `/_redirects` and `/_headers` for Netlify / Cloudflare Pages (and `sitefile serve`); a `wbn` export also bakes HEADER values into each response and exact-path REDIRECTs into 3xx responses (splats stay in `/_redirects`) |
|
|
91
|
+
| `CSP [POLICY <policy>] [META]` | yes; a strict Content-Security-Policy per page in `/_headers` (or a `<meta>`), with the SHA-256 of each inline script and style instead of `'unsafe-inline'` |
|
|
92
|
+
| `MIME <.ext> <type/subtype>` | yes; a custom Content-Type (`.usdz`, `.ts` as MPEG-TS) as a `/_headers` rule, which also types the files in a Web Bundle export |
|
|
88
93
|
| `CHECKLINKS [--warn] [--external]` | yes; fails (or warns) on links to files that do not exist, with file and line; `--external` requests http(s) links under the network policy |
|
|
89
|
-
| `FINGERPRINT [--overwrite] <pattern>… [MANIFEST <dest>]` | yes; renames assets to `name.<hash>.ext` and rewrites the HTML and CSS that reference them, plus a JSON manifest |
|
|
90
|
-
| `
|
|
94
|
+
| `FINGERPRINT [--overwrite] [--no-cache-headers] <pattern>… [MANIFEST <dest>] [INTEGRITY]` | yes; renames assets to `name.<hash>.ext` and rewrites the HTML and CSS that reference them, plus a JSON manifest, `Cache-Control` lines in `/_headers` and (INTEGRITY) SRI attributes |
|
|
95
|
+
| `PRECOMPRESS [--overwrite] [gzip] <pattern>… [MIN <bytes>]` | yes; deterministic `.gz` sidecars of text files for hosts that serve them in place of the file (nginx `gzip_static`, Caddy `precompressed`); `br` and `zstd` are not supported yet |
|
|
96
|
+
| `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]` | yes; a Workbox-style `[{url, revision}]` precache manifest (fingerprinted files get `revision: null`), or injected at `self.__WB_MANIFEST` |
|
|
97
|
+
| `EXPORT <path> [AS directory\|zip\|tar\|tgz\|wbn\|oci\|car\|html\|mhtml\|warc\|swbn\|wacz\|epub] [BASE <https-url>] [AT <root>] [COMPRESSION gzip\|none] [KEY <secret-id>] [FOR <host>]` | yes; `FOR netlify\|cloudflare\|vercel\|firebase\|azure\|github-pages\|s3` writes REDIRECT and HEADER as that host reads them (a rule it cannot express is an error, a warning with `--lossy`); archives are deterministic, `wbn` is an unsigned Web Bundle (needs `BASE` or `--base-url`; `COMPRESSION gzip` gzips it, default `none`), `oci` is a single-layer OCI image of the files (under `AT`, default `/srv/www`; `COMPRESSION` sets its layer, default `gzip`), `car` is an IPFS CARv1 file whose root CID matches kubo's `ipfs add -r --cid-version=1`, `html` is `index.html` with its assets inlined as `data:` URIs, `mhtml` the same page and assets as one MHTML file, `warc` a WARC/1.1 web archive of every file at `BASE` (also imported and served), `swbn` a Signed Web Bundle for an Isolated Web App, signed with the Ed25519 key in `--secret` `KEY`, `wacz` that WARC as a WACZ package for ReplayWeb.page, `epub` an EPUB 3 book of the XHTML pages |
|
|
91
98
|
|
|
92
99
|
Templates can also live in the Sitefile itself (see `examples/inline/`):
|
|
93
100
|
|
|
@@ -174,6 +181,8 @@ sitefile graph [context] [--json | --dot] # dependency graph of imports, st
|
|
|
174
181
|
sitefile why <path> [context] [--json] # which instructions wrote an exported file, and what overwrote it
|
|
175
182
|
sitefile vendor [context] [--vendor-dir vendor/sitefile] # download remote inputs for offline builds
|
|
176
183
|
sitefile outdated [context] [--json] # compare remote imports and BASE images with their pins (read-only)
|
|
184
|
+
sitefile import-config netlify.toml # a host's config (Netlify, Vercel, Firebase, Azure, wrangler, .htaccess) as _redirects/_headers
|
|
185
|
+
sitefile hosts [context] [--json] # the hosts a build would contact and whether they are allowed (no fetch)
|
|
177
186
|
sitefile bake [targets...] [-f sitefile.bake.yaml] [--print [--json]] [-j n] # build several variants
|
|
178
187
|
|
|
179
188
|
# images and servers (see below and docs/CLI.md)
|
|
@@ -184,6 +193,7 @@ sitefile cache du # cache sizes; SITEFILE_
|
|
|
184
193
|
sitefile serve [-d] [--name n] [-p [host:]port] [--spa] <image|./dir|site.zip>
|
|
185
194
|
sitefile serve --watch [-p [host:]port] [--spa] [context] # build in memory, serve, live reload
|
|
186
195
|
sitefile servers [-a] | server stop|rm [-f]|restart|logs [-f] <name>
|
|
196
|
+
sitefile up | down | ps [-f sitefile.servers.yaml] # several servers from one file, like docker compose
|
|
187
197
|
```
|
|
188
198
|
|
|
189
199
|
`--target <stage>` (like `docker build --target`) stops after a named stage and exports that stage's whole
|
|
@@ -395,6 +405,14 @@ tools are code, and run only when you name them on the command line.
|
|
|
395
405
|
checks the target itself before handing it to the proxy. `--allow-hosts` and
|
|
396
406
|
`--deny-hosts` narrow it further, on every hop
|
|
397
407
|
([docs/CLI.md](docs/CLI.md#network-proxy-host-rules-and-timeouts)).
|
|
408
|
+
- **Strict network mode is opt-in.** With `--network strict` (or
|
|
409
|
+
`SITEFILE_NETWORK=strict`) a build contacts only hosts you list with
|
|
410
|
+
`--allow-hosts`, none when you list none. A refused host fails with
|
|
411
|
+
`E_HOST_BLOCKED` naming the flag to add, also as `needs` in the library
|
|
412
|
+
error and in `--json` output, so a tool can ask before allowing it.
|
|
413
|
+
`sitefile hosts` lists the hosts a build needs before any is contacted. A
|
|
414
|
+
vendored build with pinned, stored images contacts nothing
|
|
415
|
+
([docs/CLI.md](docs/CLI.md#strict-network-mode)).
|
|
398
416
|
- **Pins are enforced.** Unpinned URLs are recorded in `Sitefile.lock` and must
|
|
399
417
|
match on later builds; `--strict-pins` refuses any remote import or BASE image
|
|
400
418
|
that is not pinned (`INTEGRITY`, `@sha256:` or a lockfile entry).
|
|
@@ -405,15 +423,35 @@ tools are code, and run only when you name them on the command line.
|
|
|
405
423
|
- **Secrets go only where they are sent.** `--secret id=token,env=API_TOKEN` with
|
|
406
424
|
`IMPORT … SECRET token AS BEARER` (or `AS HEADER X-Api-Key`) sends the secret
|
|
407
425
|
only to that import's own origin, and never into the output, caches,
|
|
408
|
-
`Sitefile.lock`, vendor files, provenance, traces or messages.
|
|
426
|
+
`Sitefile.lock`, vendor files, provenance, traces or messages. In strict mode a
|
|
427
|
+
secret is sent only to a host that `--allow-secret-host <id>=<host>` names.
|
|
409
428
|
- **Nothing executes unless you allow it by name.** A JavaScript `PLUGIN` runs
|
|
410
429
|
only with `--allow-plugin <name>`, in its own Node process under Node's
|
|
411
430
|
permission model (read access to its own folder only, no writes, network,
|
|
412
|
-
processes or environment)
|
|
431
|
+
processes or environment) with a heap limit (`--plugin-memory`, default
|
|
432
|
+
1 GiB), on a Node you can name with `--node` (checked to be at least Node 26
|
|
433
|
+
and printed); a `TOOL` runs only with `--allow-exec <name>`, argv
|
|
413
434
|
only, no shell, scrubbed environment. The Sitefile cannot allow itself. A
|
|
414
|
-
|
|
435
|
+
JavaScript plugin's `INTEGRITY` pins its whole folder (everything it can
|
|
436
|
+
read), a wasm plugin's its module. A WebAssembly plugin must import nothing (checked before the build starts) and
|
|
415
437
|
runs with a time and memory limit, so it needs no flag
|
|
416
438
|
([docs/PLUGINS.md](docs/PLUGINS.md#trust-model---allow-plugin)).
|
|
439
|
+
- **`serve` answers only local names.** A request whose `Host` is not
|
|
440
|
+
`localhost`, `*.localhost` or an IP address is refused (`403`), so a web page
|
|
441
|
+
that DNS-rebinds its name to `127.0.0.1` cannot read a local server;
|
|
442
|
+
`--allowed-host` adds names ([docs/CLI.md](docs/CLI.md#site-servers)).
|
|
443
|
+
- **Caches are trusted.** A TRANSFORM cache hit (local, or from
|
|
444
|
+
`--cache-from <registry>`) is used as if the plugin had returned it, and the
|
|
445
|
+
Rust build loads compiled wasm modules from `$SITEFILE_HOME/cache/wasm` as
|
|
446
|
+
native code (kept `0700`/`0600`). Only pull caches from registries you
|
|
447
|
+
trust; `--no-cache` skips them
|
|
448
|
+
([docs/PLUGINS.md](docs/PLUGINS.md#what-sitefile-trusts-as-is)). JavaScript
|
|
449
|
+
plugins say whether they are deterministic with `export const cache =
|
|
450
|
+
true|false`; one that says neither is cached with a warning.
|
|
451
|
+
- **Sharing a server with `--auth`** keeps people who lack the password out
|
|
452
|
+
(basic authentication on every request, passwords stored only as PBKDF2
|
|
453
|
+
verifiers). It does not hide the traffic: over plain HTTP on a LAN the
|
|
454
|
+
password and the pages travel in the clear, so use it on networks you trust.
|
|
417
455
|
- **No silent overwrites.** Writing different content to an existing path fails
|
|
418
456
|
unless `--overwrite` is given. Two output paths that differ only in case
|
|
419
457
|
(`/A.html`, `/a.html`) always fail (`E_PATH_COLLISION`), and every path is
|
|
@@ -431,6 +469,11 @@ tools are code, and run only when you name them on the command line.
|
|
|
431
469
|
([docs/LANGUAGE.md](docs/LANGUAGE.md#vendoring-sitefile-vendor)).
|
|
432
470
|
- **`sitefile serve` listens on `127.0.0.1`**, GET/HEAD only, no directory
|
|
433
471
|
listings, unless `-p` names another address.
|
|
472
|
+
- **`serve` proxies only where you allow it.** A `_redirects` proxy rule (200
|
|
473
|
+
to a URL) in a site you serve reaches only hosts in `--allow-hosts`; others
|
|
474
|
+
get a `502` naming the flag. `--proxy /api=url` is allowed by being written.
|
|
475
|
+
Both follow the build fetch policy above and never forward cookies or
|
|
476
|
+
`Authorization` ([docs/CLI.md](docs/CLI.md#site-servers)).
|
|
434
477
|
|
|
435
478
|
**What is still yours:**
|
|
436
479
|
|
|
@@ -448,6 +491,13 @@ tools are code, and run only when you name them on the command line.
|
|
|
448
491
|
reproducible.
|
|
449
492
|
- **Web Bundles are unsigned.** `EXPORT … AS wbn` writes an unsigned b2 bundle;
|
|
450
493
|
signing (for example for an Isolated Web App) happens outside sitefile.
|
|
494
|
+
- **Which hosts an open build contacts.** The default network mode is `open`:
|
|
495
|
+
a Sitefile you did not write may make the build contact any public HTTPS
|
|
496
|
+
host its author chose (telling it your IP address and when you build),
|
|
497
|
+
clone Git repositories and pull registry images, and send a `--secret` you
|
|
498
|
+
supplied to the host its `IMPORT … SECRET` names. Use `--network strict`
|
|
499
|
+
with `--allow-hosts` (and `--allow-secret-host`) for builds you did not
|
|
500
|
+
write.
|
|
451
501
|
- **Widening flags are yours to justify.** `--allow-http`,
|
|
452
502
|
`--allow-private-network`, `--allow-hardlinks`, `--force` and `serve -p
|
|
453
503
|
0.0.0.0:…` each turn off one of the guarantees above for that build.
|
|
@@ -481,12 +531,12 @@ not published: the npm versions still behave as the rest of that row says.
|
|
|
481
531
|
| --- | --- | --- | --- |
|
|
482
532
|
| fileable, loose output | sitefile | `COPY ./generated/ /` | Works |
|
|
483
533
|
| fileable, `encode="zip"` | sitefile | `IMPORT gen FROM ./site.zip AS tree`, then `COPY gen:/ /` | Works (same output as loose) |
|
|
484
|
-
| fileable, `encode="wbn"` | sitefile | `IMPORT … AS tree` | **
|
|
534
|
+
| fileable, `encode="wbn"` | sitefile | `IMPORT … AS tree` | **Fixed on main, in the next release:** `AS tree` reads the gzip around the Web Bundle ([#141](https://github.com/johnhenry/sitefile/issues/141)); 0.0.3 and earlier fail with `gzip content is not a tar archive` |
|
|
485
535
|
| fileable tree, rendered during a build | Sitefile | a JavaScript `TRANSFORM` plugin calling fileable's in-memory `toFiles()` | An example on main, not part of the npm package: [`examples/fileable/`](examples/fileable/) ([#145](https://github.com/johnhenry/sitefile/issues/145)). fileable is vendored into the plugin folder; `cmd`, local `src=` and `env://` fail with `E_PLUGIN` |
|
|
486
536
|
| sitefile, `EXPORT / AS wbn BASE <url>` | packfile | `fromWebBundle(buffer, { baseURL })` from `@johnhenry/packfile/web-bundle`, then `createRouter(files)` | Works; tested here (`test/packfile-interop.test.ts`), and packfile's own tests read a bundle written by sitefile 0.0.0 |
|
|
487
537
|
| sitefile `.wbn` | packfile `fromArchive()` | with 0.0.0 / 0.2.0: gzip it, and export with `BASE https://packfile.invalid/` | Works with that workaround. **Fixed on main, in the next release:** `EXPORT … AS wbn COMPRESSION gzip` (or `-o site.wbn.gz`) writes the gzip ([#143](https://github.com/johnhenry/sitefile/issues/143)), and `fromArchive()` takes a `baseURL` or the origin of the bundle's primary URL, so any `BASE` reads back ([packfile#18](https://github.com/johnhenry/packfile/issues/18)) |
|
|
488
538
|
| sitefile `HEADER` / `REDIRECT` | packfile `createWebBundleRouter()` | -- | **Not applied in 0.0.0:** only the `/_headers` and `/_redirects` files are in the bundle. **Fixed on main, in the next release:** each response carries its HEADER values, and exact-path 301/302/303/307/308 REDIRECTs are 3xx responses with `location` ([#144](https://github.com/johnhenry/sitefile/issues/144)). Splats, `200` rewrites and `404` rules stay in `/_redirects` only |
|
|
489
|
-
| packfile `toArchive()` | sitefile | `IMPORT … AS tree` | **
|
|
539
|
+
| packfile `toArchive()` | sitefile | `IMPORT … AS tree` | **Fixed on main, in the next release** (same as fileable's `.wbn`, [#141](https://github.com/johnhenry/sitefile/issues/141)); tested here (`test/packfile-interop.test.ts`) |
|
|
490
540
|
|
|
491
541
|
Gotchas when serving a Sitefile bundle with packfile:
|
|
492
542
|
|
|
@@ -21,8 +21,18 @@ export interface WriterOptions {
|
|
|
21
21
|
/** Read `SOURCE_DATE_EPOCH`; undefined if unset, E_USAGE if malformed. */
|
|
22
22
|
export declare function sourceDateEpoch(env?: NodeJS.ProcessEnv): number | undefined;
|
|
23
23
|
export { crc32 };
|
|
24
|
-
/**
|
|
25
|
-
export declare
|
|
24
|
+
/** File extensions (ASCII, lowercase) whose content is already compressed; zip stores them without deflating. */
|
|
25
|
+
export declare const COMPRESSED_MEDIA: string[];
|
|
26
|
+
/** Whether a zip entry name ends in an already-compressed media extension ({@link COMPRESSED_MEDIA}), ASCII case-insensitively. */
|
|
27
|
+
export declare function isCompressedMedia(name: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Zip (no zip64). Deflate when it shrinks the data, otherwise stored.
|
|
30
|
+
*
|
|
31
|
+
* `first` (tree paths, e.g. `['/mimetype']` for EPUB): these entries come first, in that order, stored
|
|
32
|
+
* and without an extra field (the EPUB container requires its `mimetype` entry that way); the rest
|
|
33
|
+
* follow in path order as usual.
|
|
34
|
+
*/
|
|
35
|
+
export declare function writeZip(tree: Tree, options?: WriterOptions, first?: readonly string[]): Uint8Array;
|
|
26
36
|
/** POSIX ustar; long names use the prefix field, then a pax `path` extended header. */
|
|
27
37
|
export declare function writeTar(tree: Tree, options?: WriterOptions): Uint8Array;
|
|
28
38
|
/** gzip of the tar, header mtime 0 and no filename, so the stream is reproducible. */
|
|
@@ -34,21 +34,63 @@ function dosDateTime(epoch) {
|
|
|
34
34
|
date: ((year - 1980) << 9) | ((d.getUTCMonth() + 1) << 5) | d.getUTCDate(),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
export
|
|
39
|
-
|
|
37
|
+
/** File extensions (ASCII, lowercase) whose content is already compressed; zip stores them without deflating. */
|
|
38
|
+
export const COMPRESSED_MEDIA = [
|
|
39
|
+
'png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'heic', 'jxl',
|
|
40
|
+
'woff', 'woff2',
|
|
41
|
+
'mp3', 'm4a', 'aac', 'ogg', 'oga', 'opus', 'flac',
|
|
42
|
+
'mp4', 'm4v', 'webm', 'mov', 'mkv',
|
|
43
|
+
'zip', 'gz', 'tgz', 'br', 'zst', 'xz', 'bz2', '7z', 'rar', 'wbn',
|
|
44
|
+
];
|
|
45
|
+
const COMPRESSED = new Set(COMPRESSED_MEDIA);
|
|
46
|
+
/** Whether a zip entry name ends in an already-compressed media extension ({@link COMPRESSED_MEDIA}), ASCII case-insensitively. */
|
|
47
|
+
export function isCompressedMedia(name) {
|
|
48
|
+
const base = name.slice(name.lastIndexOf('/') + 1);
|
|
49
|
+
const dot = base.lastIndexOf('.');
|
|
50
|
+
return dot > 0 && COMPRESSED.has(base.slice(dot + 1).replace(/[A-Z]/g, (c) => c.toLowerCase()));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The extended-timestamp extra field (0x5455 "UT", APPNOTE 4.4.6, Info-ZIP extrafld.txt) with the
|
|
54
|
+
* modification time only: unlike the DOS time, which unzippers read as local time, it is UTC
|
|
55
|
+
* seconds, so SOURCE_DATE_EPOCH survives extraction in any time zone. The same 9 bytes go in the
|
|
56
|
+
* local and the central header. Without an epoch it says 1980-01-01, as the DOS time does.
|
|
57
|
+
*/
|
|
58
|
+
function extendedTimestamp(epoch) {
|
|
59
|
+
const ut = Buffer.alloc(9);
|
|
60
|
+
ut.writeUInt16LE(0x5455, 0);
|
|
61
|
+
ut.writeUInt16LE(5, 2);
|
|
62
|
+
ut[4] = 1; // mtime present
|
|
63
|
+
ut.writeUInt32LE(Math.min(Math.max(epoch ?? 315532800, 0), 0xffffffff), 5);
|
|
64
|
+
return ut;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Zip (no zip64). Deflate when it shrinks the data, otherwise stored.
|
|
68
|
+
*
|
|
69
|
+
* `first` (tree paths, e.g. `['/mimetype']` for EPUB): these entries come first, in that order, stored
|
|
70
|
+
* and without an extra field (the EPUB container requires its `mimetype` entry that way); the rest
|
|
71
|
+
* follow in path order as usual.
|
|
72
|
+
*/
|
|
73
|
+
export function writeZip(tree, options = {}, first = []) {
|
|
74
|
+
const all = entriesOf(tree);
|
|
75
|
+
const firstNames = first.map((p) => p.slice(1));
|
|
76
|
+
const plain = new Set(firstNames);
|
|
77
|
+
const entries = [...firstNames.flatMap((n) => all.filter((e) => e.name === n)), ...all.filter((e) => !plain.has(e.name))];
|
|
40
78
|
if (entries.length > ZIP_MAX_ENTRIES) {
|
|
41
79
|
throw new SitefileError('E_EXPORT', `zip export supports at most ${ZIP_MAX_ENTRIES} entries (zip64 is not implemented); got ${entries.length}`);
|
|
42
80
|
}
|
|
43
81
|
const { time, date } = dosDateTime(options.epoch);
|
|
82
|
+
const ut = extendedTimestamp(options.epoch);
|
|
44
83
|
const chunks = [];
|
|
45
84
|
const central = [];
|
|
46
85
|
let offset = 0;
|
|
47
86
|
for (const e of entries) {
|
|
48
87
|
if (e.nameBytes.length > 0xffff)
|
|
49
88
|
throw new SitefileError('E_EXPORT', `zip entry name is too long (${e.nameBytes.length} bytes): '${e.name.slice(0, 60)}…'`);
|
|
50
|
-
const
|
|
51
|
-
|
|
89
|
+
const isPlain = plain.has(e.name);
|
|
90
|
+
// Already-compressed media is stored as is: deflate would only spend time to gain nothing (#203).
|
|
91
|
+
const deflated = isPlain || isCompressedMedia(e.name) ? undefined : deflateRaw(e.bytes);
|
|
92
|
+
const stored = deflated === undefined || deflated.length >= e.bytes.length;
|
|
93
|
+
const extra = isPlain ? Buffer.alloc(0) : ut;
|
|
52
94
|
const data = stored ? e.bytes : deflated;
|
|
53
95
|
if (e.bytes.length > ZIP_MAX || data.length > ZIP_MAX) {
|
|
54
96
|
throw new SitefileError('E_EXPORT', `zip export does not support files of 4 GiB or more (zip64 is not implemented): '/${e.name}'`);
|
|
@@ -68,7 +110,7 @@ export function writeZip(tree, options = {}) {
|
|
|
68
110
|
lh.writeUInt32LE(data.length, 18);
|
|
69
111
|
lh.writeUInt32LE(e.bytes.length, 22);
|
|
70
112
|
lh.writeUInt16LE(e.nameBytes.length, 26);
|
|
71
|
-
lh.writeUInt16LE(
|
|
113
|
+
lh.writeUInt16LE(extra.length, 28);
|
|
72
114
|
const ch = Buffer.alloc(46);
|
|
73
115
|
ch.writeUInt32LE(0x02014b50, 0);
|
|
74
116
|
ch.writeUInt16LE((3 << 8) | 20, 4); // made by: Unix, spec 2.0
|
|
@@ -81,12 +123,13 @@ export function writeZip(tree, options = {}) {
|
|
|
81
123
|
ch.writeUInt32LE(data.length, 20);
|
|
82
124
|
ch.writeUInt32LE(e.bytes.length, 24);
|
|
83
125
|
ch.writeUInt16LE(e.nameBytes.length, 28);
|
|
84
|
-
|
|
126
|
+
ch.writeUInt16LE(extra.length, 30);
|
|
127
|
+
// comment, disk number, internal attrs = 0
|
|
85
128
|
ch.writeUInt32LE(((0o100000 | e.mode) << 16) >>> 0, 38);
|
|
86
129
|
ch.writeUInt32LE(offset, 42);
|
|
87
|
-
chunks.push(lh, e.nameBytes, data);
|
|
88
|
-
central.push(ch, e.nameBytes);
|
|
89
|
-
offset += 30 + e.nameBytes.length + data.length;
|
|
130
|
+
chunks.push(lh, e.nameBytes, extra, data);
|
|
131
|
+
central.push(ch, e.nameBytes, extra);
|
|
132
|
+
offset += 30 + e.nameBytes.length + extra.length + data.length;
|
|
90
133
|
}
|
|
91
134
|
const cdSize = central.reduce((n, c) => n + c.length, 0);
|
|
92
135
|
if (offset + cdSize > ZIP_MAX)
|
package/lib/src/bake.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface BakeTarget {
|
|
|
21
21
|
/** `--target <stage>`. */
|
|
22
22
|
readonly target: string | null;
|
|
23
23
|
readonly output: string;
|
|
24
|
+
/** No `output` in the bake file: `output` is the default name, `dist/<name>` plus the format's extension. */
|
|
25
|
+
readonly defaultOutput: boolean;
|
|
24
26
|
readonly format: string | null;
|
|
25
27
|
readonly tags: readonly string[];
|
|
26
28
|
/** The matrix values of an expanded target. */
|
package/lib/src/bake.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { SitefileError } from './errors.js';
|
|
4
|
+
import { collectBuildArgs } from './build-args.js';
|
|
5
|
+
import { planBuild, sitefileCompression } from './executor.js';
|
|
4
6
|
import { defaultOutName } from './export-formats.js';
|
|
5
7
|
import { EXPORT_FORMATS, parseExportFormat } from './language/ast.js';
|
|
6
8
|
import { parseYaml } from './yaml.js';
|
|
@@ -231,6 +233,7 @@ function expand(def, bakeDir) {
|
|
|
231
233
|
argFiles: (fields['arg-files'] ?? []).map((f) => joinTo(bakeDir, sub('arg-files', f))),
|
|
232
234
|
target: fields.target !== undefined ? sub('target', fields.target) : null,
|
|
233
235
|
output: joinTo(bakeDir, fields.output !== undefined ? sub('output', fields.output) : defaultOut),
|
|
236
|
+
defaultOutput: fields.output === undefined,
|
|
234
237
|
format,
|
|
235
238
|
tags: (fields.tags ?? []).map((t) => sub('tags', t)),
|
|
236
239
|
matrix: raw.matrix ? Object.fromEntries(combo) : null,
|
|
@@ -309,7 +312,33 @@ function checkConflicts(targets) {
|
|
|
309
312
|
}
|
|
310
313
|
/** Read, check and resolve a bake file. */
|
|
311
314
|
export async function bakePlan(file, selected) {
|
|
312
|
-
|
|
315
|
+
const plan = resolveBake(parseBakeDefinition(await loadBakeFile(file), file), file, selected);
|
|
316
|
+
const targets = await Promise.all(plan.targets.map(compressedDefault));
|
|
317
|
+
if (targets.some((t, i) => t !== plan.targets[i]))
|
|
318
|
+
checkConflicts(targets);
|
|
319
|
+
return { file: plan.file, targets };
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* A `wbn` or `warc` target with the default output gets the name `build` would give it: `dist/<name>.wbn.gz`
|
|
323
|
+
* (`.warc.gz`) when its Sitefile's EXPORT in that format says `COMPRESSION gzip` (#151). A Sitefile that cannot
|
|
324
|
+
* be planned keeps the plain name; its build reports why.
|
|
325
|
+
*/
|
|
326
|
+
async function compressedDefault(t) {
|
|
327
|
+
const format = t.format !== null ? parseExportFormat(t.format) : undefined;
|
|
328
|
+
if (!t.defaultOutput || (format !== 'wbn' && format !== 'warc'))
|
|
329
|
+
return t;
|
|
330
|
+
try {
|
|
331
|
+
const buildArgs = await collectBuildArgs(t.argFiles, Object.entries(t.args).map(([k, v]) => `${k}=${v}`));
|
|
332
|
+
const plan = await planBuild({ contextDir: t.context, sitefile: t.file, buildArgs });
|
|
333
|
+
if (sitefileCompression(plan, format) !== 'gzip')
|
|
334
|
+
return t;
|
|
335
|
+
return { ...t, output: t.output + defaultOutName(format, 'gzip').slice(defaultOutName(format).length) };
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
if (e instanceof SitefileError)
|
|
339
|
+
return t;
|
|
340
|
+
throw e;
|
|
341
|
+
}
|
|
313
342
|
}
|
|
314
343
|
/** `--print --json`. */
|
|
315
344
|
export function bakePlanJson(plan) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blowfish's initial P-array (18 words) then S-boxes (4 x 256 words): the hexadecimal digits of pi's
|
|
3
|
+
* fractional part, big-endian, base64 (test/bcrypt.test.ts recomputes them from pi).
|
|
4
|
+
*/
|
|
5
|
+
export declare const PI_WORDS: string;
|
|
6
|
+
/** Whether `hash` looks like a bcrypt entry at all (`$2a$`, `$2b$`, `$2y$`). */
|
|
7
|
+
export declare const isBcryptPrefix: (hash: string) => boolean;
|
|
8
|
+
/** The parts of a well-formed bcrypt hash (cost 4 to 31, canonical salt and hash encodings), else undefined. */
|
|
9
|
+
export declare function parseBcrypt(hash: string): {
|
|
10
|
+
cost: number;
|
|
11
|
+
salt: Uint8Array;
|
|
12
|
+
digest: Uint8Array;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The key bcrypt hashes for `password`: its UTF-8 bytes up to the first NUL (C strings, as htpasswd
|
|
16
|
+
* reads them), then a NUL, at most 72 bytes in all. `$2a$`, `$2b$` and `$2y$` are the same here, as in
|
|
17
|
+
* OpenBSD's and Openwall's current code.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bcryptKey(password: string): Uint8Array;
|
|
20
|
+
/** EksBlowfish: the 24 bytes bcrypt computes for `key` (the encoded hash keeps the first 23). */
|
|
21
|
+
export declare function bcryptRaw(cost: number, salt: Uint8Array, key: Uint8Array): Uint8Array;
|
|
22
|
+
/** The bcrypt hash string of `password` with this cost and salt (tests). */
|
|
23
|
+
export declare function bcryptHash(password: string, cost: number, salt: Uint8Array, prefix?: string): string;
|
|
24
|
+
/** Whether `password` matches bcrypt `hash` (false for a malformed one). The digests are compared in constant time. */
|
|
25
|
+
export declare function verifyBcrypt(hash: string, password: string): boolean;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// bcrypt (EksBlowfish) password verification for `serve --auth-file` (johnhenry/sitefile#278).
|
|
2
|
+
// rust/src/serve_auth.rs checks the same entries (EksBlowfish from the `bcrypt` crate, parsing and the
|
|
3
|
+
// constant-time comparison as here). Written in-repo rather than as an npm dependency (sitefile has
|
|
4
|
+
// none): node:crypto has no Blowfish with bcrypt's expensive key schedule.
|
|
5
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
6
|
+
/**
|
|
7
|
+
* Blowfish's initial P-array (18 words) then S-boxes (4 x 256 words): the hexadecimal digits of pi's
|
|
8
|
+
* fractional part, big-endian, base64 (test/bcrypt.test.ts recomputes them from pi).
|
|
9
|
+
*/
|
|
10
|
+
export const PI_WORDS = 'JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxObIlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TEL' +
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
+
'WGzezxwgyK5bvvfdG1iNQMzSAX9rtOO73aJqfjpZ/0U+NQpEvLTN1XLqzqj6ZIS7jWYSrr88b0fSm+RjVC9dnq7Cdxv2TmNwdA4N' +
|
|
59
|
+
'jedbE1f4chZxr1N9XUBAywhOtOLMNNJGagEVr4ThsAQolZg6HQa4n7TObqBIbz87gjUgq4IBGh1LJ3In+GEVYLHnkz/cuzp5KzRF' +
|
|
60
|
+
'Jb2giDnhUc55Sy8yybegH7rJ4BzIfrzH0fbPARHDoeiqxxqQh0nUT72a0Nrey9UK2jgDOcMqxpE2Z435MXzgsStP955Zt0P1uzry' +
|
|
61
|
+
'1Rn/J9lFnL+XIiwV5vwqD5H8cZuUFSX65ZNhzrac68KoZFkSuqjRtsEHXuMFagwQ0lBlywOkQuDsbg4WmNs7TJigvjJ46WSfH5Uy' +
|
|
62
|
+
'4NOS39OgNCuJcfIeGwp0QUujNIzFvnEgw3Yy2N81n42bmS8u5gtvRw/j8R3lTNpUHtrYkc5iec/NPn5vFhixZv0sHQWEj9LF9vsi' +
|
|
63
|
+
'mfUj81emMnYjk6g1MVbMzQKs8IFiWnXrtW4WNpeI0nPM3pZikoG5SdBMUJAbccZWFObGx70yehQKReHQBsPye5rJqlP9YqgPALsl' +
|
|
64
|
+
'v+I1vdL2cRJpBbIEAiK2y898zXacK1MRPsAWQOPTOKu9YCVHrfC6OCCc90bOdnevocUgdWBghcv+Torojdh6qvmwTPmqfhlIwlwC' +
|
|
65
|
+
'+4qMAcNq5Nbr4fmQ1PhpplzeoD8JJS3CCOaft05hMs534ltXj9/jOsNy5g==';
|
|
66
|
+
const ALPHABET = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
67
|
+
/** bcrypt's base64 (its own alphabet, no padding) of `bytes`. */
|
|
68
|
+
function encode(bytes) {
|
|
69
|
+
let out = '';
|
|
70
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
71
|
+
const n = (bytes[i] << 16) | ((bytes[i + 1] ?? 0) << 8) | (bytes[i + 2] ?? 0);
|
|
72
|
+
const chars = Math.min(4, Math.ceil(((bytes.length - i) * 8) / 6));
|
|
73
|
+
for (let k = 0; k < chars; k++)
|
|
74
|
+
out += ALPHABET[(n >>> (18 - 6 * k)) & 63];
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** `n` bytes from bcrypt base64 `s`, or undefined unless `s` is exactly their canonical encoding. */
|
|
79
|
+
function decode(s, n) {
|
|
80
|
+
const out = new Uint8Array(n);
|
|
81
|
+
let acc = 0;
|
|
82
|
+
let bits = 0;
|
|
83
|
+
let j = 0;
|
|
84
|
+
for (const c of s) {
|
|
85
|
+
const v = ALPHABET.indexOf(c);
|
|
86
|
+
if (v < 0)
|
|
87
|
+
return undefined;
|
|
88
|
+
acc = ((acc << 6) | v) & 0xffffff;
|
|
89
|
+
bits += 6;
|
|
90
|
+
if (bits >= 8) {
|
|
91
|
+
bits -= 8;
|
|
92
|
+
if (j < n)
|
|
93
|
+
out[j++] = (acc >>> bits) & 0xff;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return j === n && encode(out) === s ? out : undefined;
|
|
97
|
+
}
|
|
98
|
+
/** A bcrypt hash: `$2a$`, `$2b$` or `$2y$`, a cost of 04 to 31, a 22-character salt and a 31-character hash. */
|
|
99
|
+
const BCRYPT_HASH = /^\$2[aby]\$(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{53}$/;
|
|
100
|
+
/** Whether `hash` looks like a bcrypt entry at all (`$2a$`, `$2b$`, `$2y$`). */
|
|
101
|
+
export const isBcryptPrefix = (hash) => /^\$2[aby]\$/.test(hash);
|
|
102
|
+
/** The parts of a well-formed bcrypt hash (cost 4 to 31, canonical salt and hash encodings), else undefined. */
|
|
103
|
+
export function parseBcrypt(hash) {
|
|
104
|
+
if (!BCRYPT_HASH.test(hash))
|
|
105
|
+
return undefined;
|
|
106
|
+
const salt = decode(hash.slice(7, 29), 16);
|
|
107
|
+
const digest = decode(hash.slice(29), 23);
|
|
108
|
+
return salt && digest ? { cost: Number(hash.slice(4, 6)), salt, digest } : undefined;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The key bcrypt hashes for `password`: its UTF-8 bytes up to the first NUL (C strings, as htpasswd
|
|
112
|
+
* reads them), then a NUL, at most 72 bytes in all. `$2a$`, `$2b$` and `$2y$` are the same here, as in
|
|
113
|
+
* OpenBSD's and Openwall's current code.
|
|
114
|
+
*/
|
|
115
|
+
export function bcryptKey(password) {
|
|
116
|
+
const pw = Buffer.from(password, 'utf8');
|
|
117
|
+
const nul = pw.indexOf(0);
|
|
118
|
+
const bytes = nul < 0 ? pw : pw.subarray(0, nul);
|
|
119
|
+
const key = new Uint8Array(Math.min(bytes.length + 1, 72));
|
|
120
|
+
key.set(bytes.subarray(0, key.length));
|
|
121
|
+
return key;
|
|
122
|
+
}
|
|
123
|
+
/** EksBlowfish: the 24 bytes bcrypt computes for `key` (the encoded hash keeps the first 23). */
|
|
124
|
+
export function bcryptRaw(cost, salt, key) {
|
|
125
|
+
const init = Buffer.from(PI_WORDS, 'base64');
|
|
126
|
+
const P = new Uint32Array(18);
|
|
127
|
+
const S = new Uint32Array(1024);
|
|
128
|
+
for (let i = 0; i < 18; i++)
|
|
129
|
+
P[i] = init.readUInt32BE(4 * i);
|
|
130
|
+
for (let i = 0; i < 1024; i++)
|
|
131
|
+
S[i] = init.readUInt32BE(72 + 4 * i);
|
|
132
|
+
let l = 0;
|
|
133
|
+
let r = 0;
|
|
134
|
+
const f = (x) => (((S[x >>> 24] + S[256 | ((x >>> 16) & 255)]) ^ S[512 | ((x >>> 8) & 255)]) + S[768 | (x & 255)]) | 0;
|
|
135
|
+
const encipher = () => {
|
|
136
|
+
let xl = l ^ P[0];
|
|
137
|
+
let xr = r;
|
|
138
|
+
for (let i = 1; i <= 16; i += 2) {
|
|
139
|
+
xr ^= f(xl) ^ P[i];
|
|
140
|
+
xl ^= f(xr) ^ P[i + 1];
|
|
141
|
+
}
|
|
142
|
+
l = (xr ^ P[17]) >>> 0;
|
|
143
|
+
r = xl >>> 0;
|
|
144
|
+
};
|
|
145
|
+
// The next big-endian word of `data` at `at.i`, cycling through it.
|
|
146
|
+
const word = (data, at) => {
|
|
147
|
+
let w = 0;
|
|
148
|
+
for (let k = 0; k < 4; k++) {
|
|
149
|
+
w = ((w << 8) | data[at.i]) >>> 0;
|
|
150
|
+
at.i = (at.i + 1) % data.length;
|
|
151
|
+
}
|
|
152
|
+
return w;
|
|
153
|
+
};
|
|
154
|
+
const expand = (data, saltStream) => {
|
|
155
|
+
const at = { i: 0 };
|
|
156
|
+
for (let i = 0; i < 18; i++)
|
|
157
|
+
P[i] = P[i] ^ word(data, at);
|
|
158
|
+
const sat = { i: 0 };
|
|
159
|
+
l = 0;
|
|
160
|
+
r = 0;
|
|
161
|
+
for (const t of [P, S]) {
|
|
162
|
+
for (let i = 0; i < t.length; i += 2) {
|
|
163
|
+
if (saltStream) {
|
|
164
|
+
l = (l ^ word(saltStream, sat)) >>> 0;
|
|
165
|
+
r = (r ^ word(saltStream, sat)) >>> 0;
|
|
166
|
+
}
|
|
167
|
+
encipher();
|
|
168
|
+
t[i] = l;
|
|
169
|
+
t[i + 1] = r;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
expand(key, salt);
|
|
174
|
+
for (let n = 2 ** cost; n > 0; n--) {
|
|
175
|
+
expand(key, undefined);
|
|
176
|
+
expand(salt, undefined);
|
|
177
|
+
}
|
|
178
|
+
const out = Buffer.from('OrpheanBeholderScryDoubt', 'latin1');
|
|
179
|
+
for (let b = 0; b < 24; b += 8) {
|
|
180
|
+
l = out.readUInt32BE(b);
|
|
181
|
+
r = out.readUInt32BE(b + 4);
|
|
182
|
+
for (let i = 0; i < 64; i++)
|
|
183
|
+
encipher();
|
|
184
|
+
out.writeUInt32BE(l, b);
|
|
185
|
+
out.writeUInt32BE(r, b + 4);
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
/** The bcrypt hash string of `password` with this cost and salt (tests). */
|
|
190
|
+
export function bcryptHash(password, cost, salt, prefix = '$2b$') {
|
|
191
|
+
const raw = bcryptRaw(cost, salt, bcryptKey(password));
|
|
192
|
+
return `${prefix}${String(cost).padStart(2, '0')}$${encode(salt)}${encode(raw.subarray(0, 23))}`;
|
|
193
|
+
}
|
|
194
|
+
/** Whether `password` matches bcrypt `hash` (false for a malformed one). The digests are compared in constant time. */
|
|
195
|
+
export function verifyBcrypt(hash, password) {
|
|
196
|
+
const p = parseBcrypt(hash);
|
|
197
|
+
if (!p)
|
|
198
|
+
return false;
|
|
199
|
+
return timingSafeEqual(bcryptRaw(p.cost, p.salt, bcryptKey(password)).subarray(0, 23), p.digest);
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=bcrypt.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SourceSpan } from './errors.js';
|
|
2
|
+
import { type Languages } from './hreflang.js';
|
|
3
|
+
import { type Tree } from './tree.js';
|
|
4
|
+
export interface CanonicalOp {
|
|
5
|
+
readonly base: string;
|
|
6
|
+
readonly pretty: boolean;
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly span: SourceSpan;
|
|
9
|
+
}
|
|
10
|
+
/** A page's canonical URL: `<base><url path>`, `…/index.html` as its directory, and with `pretty` no `.html`. */
|
|
11
|
+
export declare function canonicalUrl(base: string, url: string, pretty: boolean): string;
|
|
12
|
+
/**
|
|
13
|
+
* The tree with `<link rel="canonical" href="…">` inserted before `</head>` of every `.html`/`.htm` page
|
|
14
|
+
* below `root` (except `/404.html` there) that is valid UTF-8 and has no canonical link yet. With `langs`
|
|
15
|
+
* (LANGUAGES), a page that has translations also gets a `<link rel="alternate" hreflang="…">` for each
|
|
16
|
+
* (see {@link alternates}), unless it has such links already. Pages without a `</head>` are left as they
|
|
17
|
+
* are, and named in one warning.
|
|
18
|
+
*/
|
|
19
|
+
export declare function canonical(tree: Tree, op: CanonicalOp, origin: string, warn: (m: string) => void, langs?: Languages): Tree;
|