@sysce/estrogen 0.0.0-stage → 0.5.5

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.
Files changed (140) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +235 -2
  3. package/bin/estrogen.js +38 -0
  4. package/dist/cjs/astro.d.ts +31 -0
  5. package/dist/cjs/astro.js +45 -0
  6. package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
  7. package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
  8. package/dist/cjs/cloak/astro/HolyText.astro +31 -0
  9. package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
  10. package/dist/cjs/cloak/astro.d.ts +2 -0
  11. package/dist/cjs/cloak/astro.js +10 -0
  12. package/dist/cjs/cloak/base64.d.ts +2 -0
  13. package/dist/cjs/cloak/base64.js +20 -0
  14. package/dist/cjs/cloak/crypto.d.ts +16 -0
  15. package/dist/cjs/cloak/crypto.js +40 -0
  16. package/dist/cjs/cloak/decrypt.d.ts +23 -0
  17. package/dist/cjs/cloak/decrypt.js +144 -0
  18. package/dist/cjs/cloak/elements.d.ts +45 -0
  19. package/dist/cjs/cloak/elements.js +195 -0
  20. package/dist/cjs/cloak/index.d.ts +10 -0
  21. package/dist/cjs/cloak/index.js +41 -0
  22. package/dist/cjs/cloak/preact.d.ts +10 -0
  23. package/dist/cjs/cloak/preact.js +19 -0
  24. package/dist/cjs/cloak/props.d.ts +18 -0
  25. package/dist/cjs/cloak/props.js +27 -0
  26. package/dist/cjs/cloak/react-extra.d.ts +327 -0
  27. package/dist/cjs/cloak/react-extra.js +169 -0
  28. package/dist/cjs/cloak/react.d.ts +28 -0
  29. package/dist/cjs/cloak/react.js +159 -0
  30. package/dist/cjs/cloak/render.d.ts +37 -0
  31. package/dist/cjs/cloak/render.js +54 -0
  32. package/dist/cjs/cloak/server.d.ts +35 -0
  33. package/dist/cjs/cloak/server.js +87 -0
  34. package/dist/cjs/cloak/server.node.d.ts +15 -0
  35. package/dist/cjs/cloak/server.node.js +36 -0
  36. package/dist/cjs/cloak/solid.d.ts +13 -0
  37. package/dist/cjs/cloak/solid.js +55 -0
  38. package/dist/cjs/cloak/span.d.ts +8 -0
  39. package/dist/cjs/cloak/span.js +123 -0
  40. package/dist/cjs/cloak/strings.d.ts +18 -0
  41. package/dist/cjs/cloak/strings.js +53 -0
  42. package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
  43. package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  44. package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
  45. package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
  46. package/dist/cjs/cloak/svelte.d.ts +2 -0
  47. package/dist/cjs/cloak/svelte.js +10 -0
  48. package/dist/cjs/cloak/vue.d.ts +36 -0
  49. package/dist/cjs/cloak/vue.js +34 -0
  50. package/dist/cjs/esbuild.d.ts +33 -0
  51. package/dist/cjs/esbuild.js +79 -0
  52. package/dist/cjs/index.d.ts +24 -0
  53. package/dist/cjs/index.js +35 -0
  54. package/dist/cjs/node-require.js +7 -0
  55. package/dist/cjs/obfuscate.d.ts +23 -0
  56. package/dist/cjs/obfuscate.js +154 -0
  57. package/dist/cjs/options.d.ts +264 -0
  58. package/dist/cjs/options.js +105 -0
  59. package/dist/cjs/package.json +3 -0
  60. package/dist/cjs/report.d.ts +74 -0
  61. package/dist/cjs/report.js +55 -0
  62. package/dist/cjs/resolve-binary.d.ts +46 -0
  63. package/dist/cjs/resolve-binary.js +114 -0
  64. package/dist/cjs/rollup.d.ts +30 -0
  65. package/dist/cjs/rollup.js +57 -0
  66. package/dist/cjs/rsbuild.d.ts +29 -0
  67. package/dist/cjs/rsbuild.js +45 -0
  68. package/dist/cjs/vendor.d.ts +16 -0
  69. package/dist/cjs/vendor.js +95 -0
  70. package/dist/cjs/vite.d.ts +31 -0
  71. package/dist/cjs/vite.js +53 -0
  72. package/dist/esm/astro.d.ts +31 -0
  73. package/dist/esm/astro.js +42 -0
  74. package/dist/esm/cloak/astro/HolyLink.astro +36 -0
  75. package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
  76. package/dist/esm/cloak/astro/HolyText.astro +31 -0
  77. package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
  78. package/dist/esm/cloak/astro.d.ts +2 -0
  79. package/dist/esm/cloak/astro.js +2 -0
  80. package/dist/esm/cloak/base64.d.ts +2 -0
  81. package/dist/esm/cloak/base64.js +16 -0
  82. package/dist/esm/cloak/crypto.d.ts +16 -0
  83. package/dist/esm/cloak/crypto.js +36 -0
  84. package/dist/esm/cloak/decrypt.d.ts +23 -0
  85. package/dist/esm/cloak/decrypt.js +136 -0
  86. package/dist/esm/cloak/elements.d.ts +45 -0
  87. package/dist/esm/cloak/elements.js +189 -0
  88. package/dist/esm/cloak/index.d.ts +10 -0
  89. package/dist/esm/cloak/index.js +13 -0
  90. package/dist/esm/cloak/preact.d.ts +10 -0
  91. package/dist/esm/cloak/preact.js +15 -0
  92. package/dist/esm/cloak/props.d.ts +18 -0
  93. package/dist/esm/cloak/props.js +23 -0
  94. package/dist/esm/cloak/react-extra.d.ts +327 -0
  95. package/dist/esm/cloak/react-extra.js +161 -0
  96. package/dist/esm/cloak/react.d.ts +28 -0
  97. package/dist/esm/cloak/react.js +147 -0
  98. package/dist/esm/cloak/render.d.ts +37 -0
  99. package/dist/esm/cloak/render.js +48 -0
  100. package/dist/esm/cloak/server.d.ts +35 -0
  101. package/dist/esm/cloak/server.js +75 -0
  102. package/dist/esm/cloak/server.node.d.ts +15 -0
  103. package/dist/esm/cloak/server.node.js +22 -0
  104. package/dist/esm/cloak/solid.d.ts +13 -0
  105. package/dist/esm/cloak/solid.js +51 -0
  106. package/dist/esm/cloak/span.d.ts +8 -0
  107. package/dist/esm/cloak/span.js +117 -0
  108. package/dist/esm/cloak/strings.d.ts +18 -0
  109. package/dist/esm/cloak/strings.js +47 -0
  110. package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
  111. package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  112. package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
  113. package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
  114. package/dist/esm/cloak/svelte.d.ts +2 -0
  115. package/dist/esm/cloak/svelte.js +2 -0
  116. package/dist/esm/cloak/vue.d.ts +36 -0
  117. package/dist/esm/cloak/vue.js +31 -0
  118. package/dist/esm/esbuild.d.ts +33 -0
  119. package/dist/esm/esbuild.js +76 -0
  120. package/dist/esm/index.d.ts +24 -0
  121. package/dist/esm/index.js +22 -0
  122. package/dist/esm/node-require.js +8 -0
  123. package/dist/esm/obfuscate.d.ts +23 -0
  124. package/dist/esm/obfuscate.js +151 -0
  125. package/dist/esm/options.d.ts +264 -0
  126. package/dist/esm/options.js +101 -0
  127. package/dist/esm/package.json +3 -0
  128. package/dist/esm/report.d.ts +74 -0
  129. package/dist/esm/report.js +49 -0
  130. package/dist/esm/resolve-binary.d.ts +46 -0
  131. package/dist/esm/resolve-binary.js +106 -0
  132. package/dist/esm/rollup.d.ts +30 -0
  133. package/dist/esm/rollup.js +54 -0
  134. package/dist/esm/rsbuild.d.ts +29 -0
  135. package/dist/esm/rsbuild.js +42 -0
  136. package/dist/esm/vendor.d.ts +16 -0
  137. package/dist/esm/vendor.js +92 -0
  138. package/dist/esm/vite.d.ts +31 -0
  139. package/dist/esm/vite.js +50 -0
  140. package/package.json +283 -5
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 David Reed
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,236 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/estrogen.png" alt="estrogen" width="88" />
3
+ </div>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # @sysce/estrogen
6
+
7
+ <div align="center">
8
+ <a href="https://www.npmjs.com/package/@sysce/estrogen"><img src="https://img.shields.io/npm/v/@sysce/estrogen?maxAge=3600&label=npm" alt="npm" /></a>
9
+ <a href="https://github.com/Fracital/estrogen/actions/workflows/ci.yml"><img src="https://github.com/Fracital/estrogen/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
10
+ <a href="https://github.com/Fracital/estrogen/blob/v0.5.5/LICENSE"><img src="https://img.shields.io/badge/license-ISC-blue.svg" alt="license: ISC" /></a>
11
+ <a href="https://github.com/Fracital/estrogen/issues"><img src="https://img.shields.io/github/issues/Fracital/estrogen?style=flat&color=orange" alt="GitHub issues" /></a>
12
+ <a href="https://github.com/Fracital/estrogen/stargazers"><img src="https://img.shields.io/github/stars/Fracital/estrogen?style=flat&color=orange" alt="GitHub stars" /></a>
13
+ </div>
14
+
15
+ A post-build web obfuscator. It takes a directory a bundler already produced and
16
+ rewrites the JS, HTML and SVG in place. In app scripts it pools strings,
17
+ template literals and regex patterns, disguises number and boolean literals as
18
+ equivalent expressions, and shortens local names. In vendor scripts it replaces
19
+ proxy and store names, plus the matching names in embedded wasm. It leaves no
20
+ sensitive plaintext from the canary list, and it does not change what the code
21
+ does.
22
+
23
+ It also assembles the build it protects. `estrogen build` vendors packages and
24
+ folders, from `node_modules` or a glob, into the served tree under per-build
25
+ stamped names, obfuscating them on the way in or copying them verbatim, from a
26
+ `[[vendor]]` config. `estrogen --watch` re-runs on each change, and
27
+ `--sourcemap <dir>` writes a private V3 source map outside the served tree.
28
+ estrogen runs as a command line tool, as esbuild, rsbuild, Vite and Rollup
29
+ plugins, and as an Astro integration.
30
+
31
+ estrogen is written in Rust on [OXC](https://oxc.rs) and published to npm as
32
+ [`@sysce/estrogen`](https://www.npmjs.com/package/@sysce/estrogen). The binary is
33
+ `estrogen`.
34
+
35
+ estrogen transforms a shipped build into something more fun to read for crawlers.
36
+
37
+ Try it in your browser at [estro.help](https://estro.help): the real engine
38
+ compiled to WebAssembly, running locally on what you paste. Nothing is uploaded.
39
+
40
+ ## Install
41
+
42
+ ```sh
43
+ npm i -D @sysce/estrogen
44
+ ```
45
+
46
+ The package pulls the matching per-target binary (`@sysce/estrogen-<os>-<cpu>`) as
47
+ an optional dependency. Supported targets: linux x64 and arm64, darwin x64 and
48
+ arm64, win32 x64.
49
+
50
+ A nightly build of `main` is published under the `nightly` dist-tag, versioned
51
+ like `0.5.5-nightly.202611230617.g1a2b3c4` (UTC time and commit), once a day
52
+ when `main` has a new commit that passed CI:
53
+
54
+ ```sh
55
+ npm i -D @sysce/estrogen@nightly
56
+ ```
57
+
58
+ ## Quick start
59
+
60
+ Run it over a built directory from the command line:
61
+
62
+ ```sh
63
+ npx estrogen dist
64
+ ```
65
+
66
+ Or run it after an esbuild build, over the output directory:
67
+
68
+ ```js
69
+ import estrogen from '@sysce/estrogen/esbuild';
70
+ import { build } from 'esbuild';
71
+
72
+ await build({
73
+ entryPoints: ['src/index.ts'],
74
+ bundle: true,
75
+ outdir: 'dist',
76
+ plugins: [estrogen()],
77
+ });
78
+ ```
79
+
80
+ Or add it to an Astro build, where it runs on `astro:build:done` over the output
81
+ directory:
82
+
83
+ ```js
84
+ import estrogen from '@sysce/estrogen/astro';
85
+ import { defineConfig } from 'astro/config';
86
+
87
+ export default defineConfig({
88
+ integrations: [estrogen()],
89
+ });
90
+ ```
91
+
92
+ estrogen runs exactly once per build. It is not idempotent: a second run would
93
+ encrypt the decoder the first run added.
94
+
95
+ To bring packages into the build as well, run `estrogen build dist` with a
96
+ `[[vendor]]` config. See the [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/CLI.md).
97
+
98
+ ## Benchmarks
99
+
100
+ estrogen and [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator)
101
+ 5.10.1 build the same inputs, and each build runs in its own Node 24.19.0
102
+ process on a Ryzen 9 7950X. The suite is ten small workloads in
103
+ `bench/workloads` (median of 5 processes, 10 timed calls each); the library row
104
+ is Prettier 3.10.1's browser build, 610 KB of minified ES modules, formatting one
105
+ file 20 times (median of 3 processes). javascript-obfuscator runs its three
106
+ shipped presets unchanged, `debugProtection` and `disableConsoleOutput`
107
+ included. Every build returns the same result as the original, and the VM
108
+ compiled every file it was given. The method and full tables are in
109
+ [docs/BENCHMARKS.md](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/BENCHMARKS.md); `npm run bench` reruns it.
110
+
111
+ | | estrogen, VM | estrogen, `--no-vm` | javascript-obfuscator, default | medium | high |
112
+ | ---------------------------------------- | ------------ | ------------------- | ------------------------------ | -------- | --------- |
113
+ | Suite, slowdown (geomean) | 22.9x | 2.29x | 1.19x | 5.75x | 8.14x |
114
+ | Suite, gzip size (geomean) | 19.6x | 2.88x | 1.87x | 15.2x | 61.7x |
115
+ | Suite, build of 10 files | 12 ms | 9 ms | 330 ms | 746 ms | 1,436 ms |
116
+ | Prettier, format 20 times (native 12 ms) | 276 ms | 28 ms | 16 ms | 124 ms | 393 ms |
117
+ | Prettier, gzip (native 169 KB) | 316 KB | 326 KB | 296 KB | 1,320 KB | 3,263 KB |
118
+ | Prettier, import (native 14 ms) | 67 ms | 33 ms | 21 ms | 147 ms | 522 ms |
119
+ | Prettier, build | 75 ms | 36 ms | 2,753 ms | 6,170 ms | 10,378 ms |
120
+
121
+ estrogen builds 27 to 140 times faster: Prettier takes 75 ms through the VM
122
+ and 10.4 s through the high preset. The default preset costs the least at run
123
+ time, 1.19x on the suite, and leaves strings readable in a plain string array;
124
+ `--no-vm` encrypts every string for 2.29x.
125
+
126
+ The VM is the slowest on the small workloads, 22.9x, because each one is a tight
127
+ loop that runs every instruction through the interpreter. On Prettier it runs at
128
+ 22x, ahead of the high preset's 32x, and its output is smaller: 316 KB gzip
129
+ against 3,263 KB, and 1.9x native against the high preset's 19x. On the small
130
+ workloads the VM's size is mostly the runtime, about 9 KB gzip per file, which
131
+ `--shared-runtime` ships once for a build of ES modules. Hot code can leave the
132
+ VM with `--no-vm-glob`.
133
+
134
+ <img alt="Geometric mean slowdown, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/bench/summary.png">
135
+
136
+ <img alt="Prettier format time, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/bench/library.png">
137
+
138
+ <img alt="Steady-state slowdown against native for each workload, tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/bench/slowdown.png">
139
+
140
+ ## Compared with javascript-obfuscator
141
+
142
+ [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator)
143
+ 5.10.1 is the open-source package. Its bytecode VM and HTML parsing are Pro
144
+ features of obfuscator.io: the source is uploaded to its cloud API, which needs a
145
+ paid token, so the benchmark above runs the local package.
146
+
147
+ | Technique | estrogen | javascript-obfuscator |
148
+ | --------------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
149
+ | Bytecode VM | Local, on by default, opcode bytes shuffled per build | Pro only, compiled on obfuscator.io's servers |
150
+ | String literals | Every string in a ChaCha20 pool, keyed per file | String array; base64 or RC4 is opt-in (RC4 in the high preset), 75% of strings by default |
151
+ | Template literals | Static parts pooled; regex patterns pooled too | Rewritten to `concat` calls; parts pooled at the string array threshold |
152
+ | Property names | Static member names and object keys pooled | Member names through the string array; object keys with `transformObjectKeys` |
153
+ | Number and boolean literals | Rewritten as xor, sum and difference expressions, `!0`, `!![]` | `numbersToExpressions` (medium and high presets); `!![]`, `![]` |
154
+ | Local names | Shortened; module top-level bindings too | Hexadecimal or mangled; `renameGlobals` and `renameProperties` opt-in |
155
+ | Control flow flattening | No separate pass; VM code runs as bytecode | Yes (medium and high presets) |
156
+ | Dead code injection | No | Yes (medium and high presets) |
157
+ | Self-defending, anti-debug | No | `selfDefending`, `debugProtection`, `disableConsoleOutput`, `domainLock` |
158
+ | `Function.toString` | VM functions print `[native code]`, in every realm the page opens | Prints the obfuscated source |
159
+ | HTML and SVG | Inline scripts, markup pass, HTML, SVG and CSS minified | Pro only (`parseHtml`) |
160
+ | Proxy runtimes and wasm | Proxy and store names replaced, plus the matching names in embedded wasm | No |
161
+ | Input | A built output directory, rewritten in place; fails closed; canary check | A source string, file or directory of scripts |
162
+ | Vendoring | `estrogen build` copies packages into the build under stamped names | No |
163
+ | Source maps | Private V3 maps written outside the served tree | Inline or separate |
164
+ | Reproducible output | `--seed` | `seed` |
165
+ | Integrations | esbuild, rsbuild, Vite and Rollup plugins and an Astro integration in the package; `--watch` | webpack, Rollup, gulp and Grunt plugins as separate packages; esbuild and Vite plugins by third parties |
166
+ | Implementation | Rust on OXC, one native binary per platform, files in parallel | TypeScript on Node |
167
+ | In the browser | [estro.help](https://estro.help), the engine as WebAssembly, run locally | [obfuscator.io](https://obfuscator.io) |
168
+ | License | ISC | BSD-2-Clause |
169
+
170
+ ## Documentation
171
+
172
+ - [Text cloak and live injector](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/CLOAK.md): per-request ciphertext,
173
+ framework components, Ctrl+E overlays and opt-in frontend build inputs.
174
+ - [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/CLI.md): every flag, examples, exit codes, the
175
+ fail-closed rule.
176
+ - [Node API](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/NODE-API.md): `obfuscate()`, the esbuild, rsbuild, Vite and
177
+ Rollup plugins, the Astro integration, the options object, the `Report` shape.
178
+ - [Rust API](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/RUST-API.md): the `estrogen-core` public surface.
179
+ - [Integration](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/INTEGRATION.md): esbuild, rsbuild, Vite, Rollup, Astro, and
180
+ a plain CLI step in `package.json`.
181
+ - [Benchmarks](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/BENCHMARKS.md): what the VM and the literal pool cost at
182
+ run time and load, per workload, and the harness in `bench/`.
183
+ - [Project status](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/PROJECT_STATUS.md): current validation and remaining
184
+ compatibility work.
185
+ - [Proxy name rename](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/PROXY-NAMES.md): the `[proxy]` table, the vendor
186
+ and build scopes, `keep`, and the text a rename must not change.
187
+ - [Proxy integration coverage](https://github.com/Fracital/estrogen/blob/v0.5.5/docs/PROXY_COVERAGE.md): per-site builds,
188
+ browser evidence, VM percentages and remaining gaps.
189
+ - [Wiki](https://github.com/Fracital/estrogen/wiki): install, configuration,
190
+ source maps, security and limits, contributing.
191
+
192
+ ## Powering
193
+
194
+ <table>
195
+ <tr><th></th><th>Site</th><th>Link</th><th>Repo</th></tr>
196
+ <tr>
197
+ <td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/brands/abstract.png" alt="abstract v2" width="28"></td>
198
+ <td valign="middle">abstract v2</td>
199
+ <td valign="middle"><a href="https://abstracteducation.loan">abstracteducation.loan</a></td>
200
+ <td valign="middle"></td>
201
+ </tr>
202
+ <tr>
203
+ <td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/brands/fracital.svg" alt="Fracital" width="28"></td>
204
+ <td valign="middle">Fracital</td>
205
+ <td valign="middle"><a href="https://fracit.al">fracit.al</a></td>
206
+ <td valign="middle"><a href="https://github.com/Fracital/Fracital"><code>Fracital/Fracital</code></a></td>
207
+ </tr>
208
+ <tr>
209
+ <td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/brands/systemya.png" alt="SystemYA" width="28"></td>
210
+ <td valign="middle">SystemYA</td>
211
+ <td valign="middle"><a href="https://systemya.fracit.al">systemya.fracit.al</a></td>
212
+ <td valign="middle"><a href="https://github.com/Fracital/SystemYA"><code>Fracital/SystemYA</code></a></td>
213
+ </tr>
214
+ <tr>
215
+ <td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/brands/stomp.png" alt="STomp" width="28"></td>
216
+ <td valign="middle">STomp (powerMouse)</td>
217
+ <td valign="middle"><a href="https://stomp.fracit.al">stomp.fracit.al</a></td>
218
+ <td valign="middle"><a href="https://github.com/Fracital/powerMouse"><code>Fracital/powerMouse</code></a></td>
219
+ </tr>
220
+ <tr>
221
+ <td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/brands/holy-unblocker.svg" alt="Holy Unblocker" width="28"></td>
222
+ <td valign="middle">Holy Unblocker</td>
223
+ <td valign="middle"><a href="https://holyunb.locker">holyunb.locker</a></td>
224
+ <td valign="middle"><a href="https://github.com/holy-unblocker/website2"><code>holy-unblocker/website2</code></a></td>
225
+ </tr>
226
+ </table>
227
+
228
+ ## Credits
229
+
230
+ | | GitHub | Name |
231
+ | ----------------------------------------------------------------------------- | ------------------------------ | ---------- |
232
+ | <img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.5/docs/assets/am%20i%20cool%20yet.png" width="64" alt="e9x's avatar"> | [@e9x](https://github.com/e9x) | David Reed |
233
+
234
+ ## License
235
+
236
+ ISC. See [LICENSE](https://github.com/Fracital/estrogen/blob/v0.5.5/LICENSE).
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ // estrogen launcher. Resolves the per-platform binary from the installed
3
+ // @sysce/estrogen-<os>-<cpu> optional dependency and execs it, forwarding argv and
4
+ // the exit code. A missing binary is a clear error, not a stack trace.
5
+ import { spawn } from 'node:child_process';
6
+ import { createRequire } from 'node:module';
7
+
8
+ import { MissingBinaryError, resolveBinaryPath } from '../dist/esm/resolve-binary.js';
9
+
10
+ const require = createRequire(import.meta.url);
11
+
12
+ let binaryPath;
13
+ try {
14
+ // ESTROGEN_BINARY lets a local build or a test point the launcher at its own
15
+ // binary without installing a per-platform package.
16
+ binaryPath = resolveBinaryPath(require, process.env.ESTROGEN_BINARY);
17
+ } catch (error) {
18
+ if (error instanceof MissingBinaryError) {
19
+ process.stderr.write(`${error.message}\n`);
20
+ process.exit(1);
21
+ }
22
+ throw error;
23
+ }
24
+
25
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
26
+
27
+ child.on('error', (error) => {
28
+ process.stderr.write(`estrogen failed to start: ${error.message}\n`);
29
+ process.exit(1);
30
+ });
31
+
32
+ child.on('close', (code, signal) => {
33
+ if (signal) {
34
+ process.kill(process.pid, signal);
35
+ return;
36
+ }
37
+ process.exit(code ?? 1);
38
+ });
@@ -0,0 +1,31 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import type { PluginOptions } from './options.js';
3
+ /**
4
+ * Astro integration that runs estrogen over the build output directory once Astro
5
+ * has written it.
6
+ *
7
+ * It hooks `astro:build:done`, which runs after the build is on disk, and reads
8
+ * the final output directory from that hook's `dir` URL through
9
+ * `fileURLToPath`. For a static (SSG) build this is the directory Astro serves;
10
+ * for an SSR build it is the client output directory, so the integration
11
+ * rewrites the client assets. An estrogen failure is thrown so the build fails.
12
+ *
13
+ * estrogen rewrites that directory in place and raises the cost of reading it.
14
+ * It is not secrecy: a decoder key ships in each file, and anyone with devtools
15
+ * can run the code.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { defineConfig } from 'astro/config';
20
+ * import estrogen from '@sysce/estrogen/astro';
21
+ *
22
+ * export default defineConfig({
23
+ * integrations: [estrogen({ canary: 'canary-list.json' })],
24
+ * });
25
+ * ```
26
+ *
27
+ * @param options estrogen options. `dirs` is ignored; the output directory comes
28
+ * from the Astro build hook.
29
+ */
30
+ export declare function estrogen(options?: PluginOptions): AstroIntegration;
31
+ export default estrogen;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estrogen = estrogen;
4
+ const node_url_1 = require("node:url");
5
+ const obfuscate_js_1 = require("./obfuscate.js");
6
+ /**
7
+ * Astro integration that runs estrogen over the build output directory once Astro
8
+ * has written it.
9
+ *
10
+ * It hooks `astro:build:done`, which runs after the build is on disk, and reads
11
+ * the final output directory from that hook's `dir` URL through
12
+ * `fileURLToPath`. For a static (SSG) build this is the directory Astro serves;
13
+ * for an SSR build it is the client output directory, so the integration
14
+ * rewrites the client assets. An estrogen failure is thrown so the build fails.
15
+ *
16
+ * estrogen rewrites that directory in place and raises the cost of reading it.
17
+ * It is not secrecy: a decoder key ships in each file, and anyone with devtools
18
+ * can run the code.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { defineConfig } from 'astro/config';
23
+ * import estrogen from '@sysce/estrogen/astro';
24
+ *
25
+ * export default defineConfig({
26
+ * integrations: [estrogen({ canary: 'canary-list.json' })],
27
+ * });
28
+ * ```
29
+ *
30
+ * @param options estrogen options. `dirs` is ignored; the output directory comes
31
+ * from the Astro build hook.
32
+ */
33
+ function estrogen(options = {}) {
34
+ return {
35
+ name: '@sysce/estrogen',
36
+ hooks: {
37
+ 'astro:build:done': async ({ dir, logger }) => {
38
+ const outDir = (0, node_url_1.fileURLToPath)(dir);
39
+ logger.info(`running estrogen over ${outDir}`);
40
+ await (0, obfuscate_js_1.obfuscate)({ ...options, dirs: outDir });
41
+ },
42
+ },
43
+ };
44
+ }
45
+ exports.default = estrogen;
@@ -0,0 +1,36 @@
1
+ ---
2
+ import { linkElementProps, type CloakLinkProps } from '../props.js';
3
+ import HolyText from './HolyText.astro';
4
+
5
+ type Props = CloakLinkProps & { plain?: boolean; spanHost?: boolean; text?: string; labelCiphertext?: string; [attribute: string]: unknown };
6
+ const { plain: plainProp, spanHost = false, href, hrefCipher, target, text, labelCiphertext, ...rest } = Astro.props as Props;
7
+ const plain = plainProp ?? (Astro.locals as { isMainWebsite?: boolean }).isMainWebsite ?? false;
8
+ // An HTML href must not ship in the cloak branch. Match website2's
9
+ // request-local encryption when the link was given only a plaintext URL.
10
+ let encryptedHref = hrefCipher;
11
+ if (!plain && href !== undefined && !encryptedHref) {
12
+ const encryptText = (Astro.locals as { encryptText?: (text: string) => Promise<string> }).encryptText;
13
+ if (!encryptText) {
14
+ throw new Error('cloak: HolyLink needs Astro.locals.encryptText or an explicit hrefCipher');
15
+ }
16
+ encryptedHref = await encryptText(href);
17
+ }
18
+ const attributes = linkElementProps({ href, hrefCipher: encryptedHref, target });
19
+ ---
20
+ {plain ? (
21
+ <a {...rest} href={href} target={target}>{typeof text === 'string' ? text : <slot />}</a>
22
+ ) : spanHost ? (
23
+ <span {...rest} data-eclink={attributes['href-cipher']} data-target={target}>
24
+ {typeof text === 'string' ? <HolyText spanHost text={text} ciphertext={labelCiphertext} /> : <slot />}
25
+ </span>
26
+ ) : (
27
+ <holy-link {...rest} href={attributes.href} href-cipher={attributes['href-cipher']} target={attributes.target}>
28
+ {typeof text === 'string' ? <HolyText text={text} ciphertext={labelCiphertext} /> : <slot />}
29
+ </holy-link>
30
+ )}
31
+ <script>
32
+ import '../elements.js';
33
+ import { navigate } from 'astro:transitions/client';
34
+ import { setupSpanCloak } from '../span.js';
35
+ setupSpanCloak(navigate);
36
+ </script>
@@ -0,0 +1,14 @@
1
+ import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
2
+ import type { CloakLinkProps } from '../props.js';
3
+
4
+ declare const HolyLink: AstroComponentFactory &
5
+ ((
6
+ props: CloakLinkProps & {
7
+ plain?: boolean;
8
+ spanHost?: boolean;
9
+ text?: string;
10
+ labelCiphertext?: string;
11
+ [attribute: string]: unknown;
12
+ },
13
+ ) => unknown);
14
+ export default HolyLink;
@@ -0,0 +1,31 @@
1
+ ---
2
+ import { textElementProps, type CloakTextProps } from '../props.js';
3
+
4
+ type Props = CloakTextProps & { plain?: boolean; spanHost?: boolean; [attribute: string]: unknown };
5
+ const { plain: plainProp, spanHost = false, text, ciphertext, ellipsis, revealForBots, ...rest } = Astro.props as Props;
6
+ const plain = plainProp ?? (Astro.locals as { isMainWebsite?: boolean }).isMainWebsite ?? false;
7
+ // website2's HolyText encrypts its text on each SSR request. Keep that
8
+ // contract in the shared component, rather than emitting an unencrypted
9
+ // fallback when a caller supplies text but not a precomputed ciphertext.
10
+ let encrypted = ciphertext;
11
+ if (!plain && text !== undefined && !encrypted) {
12
+ const encryptText = (Astro.locals as { encryptText?: (text: string) => Promise<string> }).encryptText;
13
+ if (!encryptText) {
14
+ throw new Error('cloak: HolyText needs Astro.locals.encryptText or an explicit ciphertext');
15
+ }
16
+ encrypted = await encryptText(text);
17
+ }
18
+ const { attributes, placeholder } = textElementProps({ text, ciphertext: encrypted, ellipsis, revealForBots });
19
+ ---
20
+ {plain ? (
21
+ <span {...rest} set:text={text ?? ''} />
22
+ ) : spanHost ? (
23
+ <span {...rest} data-ectext={attributes.ciphertext}>{placeholder}</span>
24
+ ) : (
25
+ <holy-text {...rest} ciphertext={attributes.ciphertext} ellipsis={attributes.ellipsis} reveal-for-bots={attributes['reveal-for-bots']}>{placeholder}</holy-text>
26
+ )}
27
+ <script>
28
+ import '../elements.js';
29
+ import { setupSpanCloak } from '../span.js';
30
+ setupSpanCloak();
31
+ </script>
@@ -0,0 +1,12 @@
1
+ import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
2
+ import type { CloakTextProps } from '../props.js';
3
+
4
+ declare const HolyText: AstroComponentFactory &
5
+ ((
6
+ props: CloakTextProps & {
7
+ plain?: boolean;
8
+ spanHost?: boolean;
9
+ [attribute: string]: unknown;
10
+ },
11
+ ) => unknown);
12
+ export default HolyText;
@@ -0,0 +1,2 @@
1
+ export { default as HolyText } from './astro/HolyText.astro';
2
+ export { default as HolyLink } from './astro/HolyLink.astro';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HolyLink = exports.HolyText = void 0;
7
+ var HolyText_astro_1 = require("./astro/HolyText.astro");
8
+ Object.defineProperty(exports, "HolyText", { enumerable: true, get: function () { return __importDefault(HolyText_astro_1).default; } });
9
+ var HolyLink_astro_1 = require("./astro/HolyLink.astro");
10
+ Object.defineProperty(exports, "HolyLink", { enumerable: true, get: function () { return __importDefault(HolyLink_astro_1).default; } });
@@ -0,0 +1,2 @@
1
+ export declare function toBase64(bytes: Uint8Array): string;
2
+ export declare function fromBase64(str: string): Uint8Array;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ // Base64 helpers that work in a browser, on Node and on edge runtimes without
3
+ // Buffer. The cloak key and ciphertext move as base64 strings, so both the
4
+ // server (encrypt) and client (decrypt) sides share this one implementation.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toBase64 = toBase64;
7
+ exports.fromBase64 = fromBase64;
8
+ function toBase64(bytes) {
9
+ let binary = '';
10
+ for (let i = 0; i < bytes.length; i++)
11
+ binary += String.fromCharCode(bytes[i]);
12
+ return btoa(binary);
13
+ }
14
+ function fromBase64(str) {
15
+ const binary = atob(str.trim());
16
+ const bytes = new Uint8Array(binary.length);
17
+ for (let i = 0; i < binary.length; i++)
18
+ bytes[i] = binary.charCodeAt(i);
19
+ return bytes;
20
+ }
@@ -0,0 +1,16 @@
1
+ export interface EncryptionSession {
2
+ /** 32-byte AES key. */
3
+ key: Uint8Array;
4
+ /** 16-byte IV. */
5
+ iv: Uint8Array;
6
+ /** base64(iv ++ key), the value that ships in the #eckey element. */
7
+ combinedKeyBase64: string;
8
+ }
9
+ /**
10
+ * Make a fresh random key+IV. Call this once per request (or per build) so the
11
+ * same source text encrypts to different ciphertext every time. Publish
12
+ * `combinedKeyBase64` into the page's #eckey element.
13
+ */
14
+ export declare function createEncryptionSession(randomFill?: (buffer: Uint8Array) => Uint8Array): EncryptionSession;
15
+ /** Encrypt one string under a session. Returns base64 AES-256-CBC ciphertext. */
16
+ export declare function encryptText(text: string, session: EncryptionSession): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // Server/build side of the cloak: make a per-request key and encrypt text with
3
+ // it. AES-256-CBC via @noble/ciphers and web getRandomValues, so this runs the
4
+ // same on Node, on an edge runtime (Cloudflare Pages, Deno) and in a build
5
+ // step. The wire format matches what the client decryptor expects: a 48-byte
6
+ // combined key, base64(iv(16) ++ key(32)), and base64 AES-CBC ciphertext.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.createEncryptionSession = createEncryptionSession;
9
+ exports.encryptText = encryptText;
10
+ const aes_js_1 = require("@noble/ciphers/aes.js");
11
+ const base64_js_1 = require("./base64.js");
12
+ function randomBytes(length, randomFill) {
13
+ const out = new Uint8Array(length);
14
+ if (randomFill)
15
+ return randomFill(out);
16
+ if (typeof globalThis.crypto?.getRandomValues !== 'function') {
17
+ throw new Error('cloak: globalThis.crypto.getRandomValues is unavailable; need Node >=19, an edge runtime or a browser');
18
+ }
19
+ globalThis.crypto.getRandomValues(out);
20
+ return out;
21
+ }
22
+ /**
23
+ * Make a fresh random key+IV. Call this once per request (or per build) so the
24
+ * same source text encrypts to different ciphertext every time. Publish
25
+ * `combinedKeyBase64` into the page's #eckey element.
26
+ */
27
+ function createEncryptionSession(randomFill) {
28
+ const key = randomBytes(32, randomFill);
29
+ const iv = randomBytes(16, randomFill);
30
+ const combined = new Uint8Array(48);
31
+ combined.set(iv, 0);
32
+ combined.set(key, 16);
33
+ return { key, iv, combinedKeyBase64: (0, base64_js_1.toBase64)(combined) };
34
+ }
35
+ const encoder = new TextEncoder();
36
+ /** Encrypt one string under a session. Returns base64 AES-256-CBC ciphertext. */
37
+ function encryptText(text, session) {
38
+ const ciphertext = (0, aes_js_1.cbc)(session.key, session.iv).encrypt(encoder.encode(text));
39
+ return (0, base64_js_1.toBase64)(ciphertext);
40
+ }
@@ -0,0 +1,23 @@
1
+ /** Read the key from a host application's existing runtime, without copying globals. */
2
+ export declare function setCloakKeyProvider(provider: (() => string | null | undefined) | undefined): void;
3
+ /**
4
+ * Tell the decryptor where to look for the #eckey element first, e.g. a decoy
5
+ * overlay's shadow root. The document is always checked as a fallback.
6
+ */
7
+ export declare function setCloakRoot(resolver: (() => Document | ShadowRoot | null | undefined) | undefined): void;
8
+ /** Load the combined key from the DOM (or the window global). Safe to re-call. */
9
+ export declare function loadDecryptionKey(): boolean;
10
+ /**
11
+ * Decrypt one base64 ciphertext string to plaintext. Returns "" on a missing
12
+ * key or a decrypt error, so a caller can keep its dash placeholder rather than
13
+ * blanking the text.
14
+ */
15
+ export declare function holyDecrypt(ciphertextB64: string): string;
16
+ /** Parse a JSON payload encrypted with `encryptJson` on the server. */
17
+ export declare function holyDecryptJson<T = unknown>(ciphertextB64: string): T | undefined;
18
+ /**
19
+ * A tripwire, not a security control: flags a likely headless/automated browser
20
+ * so the reveal step can stay on the dash placeholder. Must never block a real
21
+ * user, so it only reads navigator.webdriver.
22
+ */
23
+ export declare function isLikelyBot(): boolean;