treadwheel 0.0.0-stage → 1.0.1
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/LICENSE +202 -0
- package/README.md +79 -2
- package/dist/browser/codec.d.ts +3 -0
- package/dist/browser/codec.d.ts.map +1 -0
- package/dist/browser/codec.js +23 -0
- package/dist/browser/codec.js.map +1 -0
- package/dist/browser/index.d.ts +26 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +76 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/widget.d.ts +2 -0
- package/dist/browser/widget.d.ts.map +1 -0
- package/dist/browser/widget.js +225 -0
- package/dist/browser/widget.js.map +1 -0
- package/dist/browser/worker.d.ts +2 -0
- package/dist/browser/worker.d.ts.map +1 -0
- package/dist/browser/worker.js +14 -0
- package/dist/browser/worker.js.map +1 -0
- package/dist/core/cipher.d.ts +4 -0
- package/dist/core/cipher.d.ts.map +1 -0
- package/dist/core/cipher.js +17 -0
- package/dist/core/cipher.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +5 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +32 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/io.d.ts +6 -0
- package/dist/core/io.d.ts.map +1 -0
- package/dist/core/io.js +113 -0
- package/dist/core/io.js.map +1 -0
- package/dist/core/puzzle.d.ts +7 -0
- package/dist/core/puzzle.d.ts.map +1 -0
- package/dist/core/puzzle.js +42 -0
- package/dist/core/puzzle.js.map +1 -0
- package/dist/core/types.d.ts +41 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/node/cli.d.ts +3 -0
- package/dist/node/cli.d.ts.map +1 -0
- package/dist/node/cli.js +137 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/index.d.ts +26 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +72 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/worker.d.ts +2 -0
- package/dist/node/worker.d.ts.map +1 -0
- package/dist/node/worker.js +7 -0
- package/dist/node/worker.js.map +1 -0
- package/dist/treadwheel-widget.min.js +2 -0
- package/dist/treadwheel-widget.min.js.map +1 -0
- package/dist/treadwheel.min.js +2 -0
- package/dist/treadwheel.min.js.map +1 -0
- package/package.json +88 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Treadwheel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/treadwheel)
|
|
4
|
+
[](https://github.com/jo-phil/treadwheel/actions/workflows/ci.yml)
|
|
5
|
+
[](https://jo-phil.github.io/treadwheel/)
|
|
6
|
+
|
|
7
|
+
Treadwheel uses time-lock puzzles based on
|
|
8
|
+
[Rivest, Shamir, and Wagner (1996)](https://people.csail.mit.edu/rivest/pubs/RSW96.pdf)
|
|
9
|
+
to protect information from bots while keeping access simple for humans.
|
|
10
|
+
|
|
11
|
+
Solving a time-lock puzzle requires inherently sequential computation, raising
|
|
12
|
+
the cost of accessing protected information. While this cost is negligible for
|
|
13
|
+
legitimate users looking up a single piece of information, such as an email
|
|
14
|
+
address or phone number, it accumulates across large-scale scraping operations,
|
|
15
|
+
making mass collection more expensive and potentially less attractive.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
**Node.js**
|
|
20
|
+
|
|
21
|
+
- Node.js 22 or later.
|
|
22
|
+
|
|
23
|
+
**Browser**
|
|
24
|
+
|
|
25
|
+
- A secure context (HTTPS or localhost) for the Web Crypto API.
|
|
26
|
+
- ES2020 support, including BigInt.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm i treadwheel
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
This section explains how to seal plaintext using the CLI and integrate a widget
|
|
37
|
+
to unseal it in a web application. For advanced configuration and full API
|
|
38
|
+
details, see the [Documentation](https://jo-phil.github.io/treadwheel/).
|
|
39
|
+
|
|
40
|
+
### 1. Sealing plaintext
|
|
41
|
+
|
|
42
|
+
Use the `treadwheel seal` command to seal plaintext:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx treadwheel seal "Hello, World!"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This outputs a Base64URL-encoded envelope containing the time-lock puzzle and
|
|
49
|
+
encrypted payload, which can be used for the `envelope` attribute of the widget.
|
|
50
|
+
|
|
51
|
+
> [!TIP]
|
|
52
|
+
> The puzzle's difficulty can be adjusted with the `--time` option. See the
|
|
53
|
+
> [CLI Reference](https://jo-phil.github.io/treadwheel/cli) for details.
|
|
54
|
+
|
|
55
|
+
### 2. Importing the widget
|
|
56
|
+
|
|
57
|
+
To allow visitors to unseal the envelope on your website, register the
|
|
58
|
+
`<treadwheel-widget>` element by importing the `treadwheel/widget` module:
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import 'treadwheel/widget';
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Alternatively, use a script tag to load it from a CDN:
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/treadwheel@latest/dist/treadwheel-widget.min.js"></script>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 3. Using the widget
|
|
71
|
+
|
|
72
|
+
Add a `<treadwheel-widget>` element with the envelope to your HTML document:
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<treadwheel-widget envelope="tw__..."></treadwheel-widget>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
This project is licensed under the [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/browser/codec.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAc1D;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAW3E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function bytesToBase64Url(bytes) {
|
|
2
|
+
if ('toBase64' in bytes && typeof bytes.toBase64 === 'function') {
|
|
3
|
+
return bytes.toBase64({ alphabet: 'base64url', omitPadding: true });
|
|
4
|
+
}
|
|
5
|
+
const CHUNK_SIZE = 0x4000;
|
|
6
|
+
let binaryString = '';
|
|
7
|
+
for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
|
|
8
|
+
const chunk = bytes.subarray(i, i + CHUNK_SIZE);
|
|
9
|
+
binaryString += String.fromCharCode(...chunk);
|
|
10
|
+
}
|
|
11
|
+
const base64 = btoa(binaryString);
|
|
12
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
13
|
+
}
|
|
14
|
+
export function base64UrlToBytes(base64Url) {
|
|
15
|
+
if ('fromBase64' in Uint8Array &&
|
|
16
|
+
typeof Uint8Array.fromBase64 === 'function') {
|
|
17
|
+
return Uint8Array.fromBase64(base64Url, { alphabet: 'base64url' });
|
|
18
|
+
}
|
|
19
|
+
let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
20
|
+
base64 += '=='.slice((base64.length + 2) % 4);
|
|
21
|
+
return Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/browser/codec.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,UAAU,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC;IAC1B,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;QAChD,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,IACE,YAAY,IAAI,UAAU;QAC1B,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU,EAC3C,CAAC;QACD,OAAO,UAAU,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7D,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SealOptions, UnsealInWorkerOptions } from '../core/types.js';
|
|
2
|
+
export type { SealOptions, UnsealInWorkerOptions };
|
|
3
|
+
/**
|
|
4
|
+
* Seal plaintext using a time-lock puzzle.
|
|
5
|
+
*
|
|
6
|
+
* @param plaintext - The plaintext to seal.
|
|
7
|
+
* @param options - Optional configuration options.
|
|
8
|
+
* @returns A Base64URL-encoded envelope.
|
|
9
|
+
*/
|
|
10
|
+
export declare function seal(plaintext: string, options?: SealOptions): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Unseal an envelope by solving its time-lock puzzle.
|
|
13
|
+
*
|
|
14
|
+
* @param envelope - A Base64URL-encoded envelope.
|
|
15
|
+
* @returns The decrypted plaintext.
|
|
16
|
+
*/
|
|
17
|
+
export declare function unseal(envelope: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Unseal an envelope in a web worker.
|
|
20
|
+
*
|
|
21
|
+
* @param envelope - A Base64URL-encoded envelope.
|
|
22
|
+
* @param options - Optional configuration options.
|
|
23
|
+
* @returns The decrypted plaintext.
|
|
24
|
+
*/
|
|
25
|
+
export declare function unsealInWorker(envelope: string, options?: UnsealInWorkerOptions): Promise<string>;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAiCjB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SEAL_DEFAULTS } from '../core/defaults.js';
|
|
2
|
+
import { sealFromPrimes, unsealFromBytes } from '../core/index.js';
|
|
3
|
+
import { bytesToBigInt } from '../core/io.js';
|
|
4
|
+
import { base64UrlToBytes, bytesToBase64Url } from './codec.js';
|
|
5
|
+
/**
|
|
6
|
+
* Seal plaintext using a time-lock puzzle.
|
|
7
|
+
*
|
|
8
|
+
* @param plaintext - The plaintext to seal.
|
|
9
|
+
* @param options - Optional configuration options.
|
|
10
|
+
* @returns A Base64URL-encoded envelope.
|
|
11
|
+
*/
|
|
12
|
+
export async function seal(plaintext, options) {
|
|
13
|
+
const config = { ...SEAL_DEFAULTS, ...options };
|
|
14
|
+
const keyPair = await globalThis.crypto.subtle.generateKey({
|
|
15
|
+
name: 'RSA-OAEP',
|
|
16
|
+
modulusLength: config.modulusLength,
|
|
17
|
+
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
18
|
+
hash: 'SHA-256',
|
|
19
|
+
}, true, ['decrypt']);
|
|
20
|
+
const jwk = await globalThis.crypto.subtle.exportKey('jwk', keyPair.privateKey);
|
|
21
|
+
if (!jwk.p || !jwk.q)
|
|
22
|
+
throw new Error('RSA JWK is missing primes p or q');
|
|
23
|
+
const p = bytesToBigInt(base64UrlToBytes(jwk.p));
|
|
24
|
+
const q = bytesToBigInt(base64UrlToBytes(jwk.q));
|
|
25
|
+
return bytesToBase64Url(await sealFromPrimes(plaintext, p, q, config));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unseal an envelope by solving its time-lock puzzle.
|
|
29
|
+
*
|
|
30
|
+
* @param envelope - A Base64URL-encoded envelope.
|
|
31
|
+
* @returns The decrypted plaintext.
|
|
32
|
+
*/
|
|
33
|
+
export async function unseal(envelope) {
|
|
34
|
+
if (!globalThis.crypto?.subtle)
|
|
35
|
+
throw new Error('Web Crypto API is not available');
|
|
36
|
+
return await unsealFromBytes(base64UrlToBytes(envelope));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Unseal an envelope in a web worker.
|
|
40
|
+
*
|
|
41
|
+
* @param envelope - A Base64URL-encoded envelope.
|
|
42
|
+
* @param options - Optional configuration options.
|
|
43
|
+
* @returns The decrypted plaintext.
|
|
44
|
+
*/
|
|
45
|
+
export function unsealInWorker(envelope, options) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
if (options?.signal?.aborted)
|
|
48
|
+
return reject(options.signal.reason);
|
|
49
|
+
options?.signal?.addEventListener('abort', handleAbort);
|
|
50
|
+
const worker = new Worker(new URL('./worker.js', import.meta.url), {
|
|
51
|
+
type: 'module',
|
|
52
|
+
});
|
|
53
|
+
const cleanup = () => {
|
|
54
|
+
worker.terminate();
|
|
55
|
+
options?.signal?.removeEventListener('abort', handleAbort);
|
|
56
|
+
};
|
|
57
|
+
worker.onmessage = (event) => {
|
|
58
|
+
if (event.data.success)
|
|
59
|
+
resolve(event.data.plaintext);
|
|
60
|
+
else
|
|
61
|
+
reject(event.data.error);
|
|
62
|
+
cleanup();
|
|
63
|
+
};
|
|
64
|
+
worker.onerror = (errorEvent) => {
|
|
65
|
+
errorEvent.preventDefault();
|
|
66
|
+
reject(errorEvent.error ?? new Error(errorEvent.message));
|
|
67
|
+
cleanup();
|
|
68
|
+
};
|
|
69
|
+
function handleAbort(event) {
|
|
70
|
+
reject(event.target.reason);
|
|
71
|
+
cleanup();
|
|
72
|
+
}
|
|
73
|
+
worker.postMessage(envelope);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/browser/widget.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { unsealInWorker } from './index.js';
|
|
2
|
+
const html = String.raw;
|
|
3
|
+
const template = document.createElement('template');
|
|
4
|
+
template.innerHTML = html `
|
|
5
|
+
<style>
|
|
6
|
+
article {
|
|
7
|
+
all: initial;
|
|
8
|
+
display: block;
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
width: min(300px, 100dvw);
|
|
11
|
+
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
12
|
+
border-radius: 10px;
|
|
13
|
+
color: #111;
|
|
14
|
+
background: #fff;
|
|
15
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
|
|
16
|
+
font-family:
|
|
17
|
+
Inter, Roboto, "Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial,
|
|
18
|
+
sans-serif;
|
|
19
|
+
font-size: 16px;
|
|
20
|
+
line-height: 1.25;
|
|
21
|
+
user-select: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:host([layout="floating"]) {
|
|
25
|
+
display: inline-block;
|
|
26
|
+
position: relative;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
:host([layout="floating"]) article {
|
|
30
|
+
display: none;
|
|
31
|
+
position: absolute;
|
|
32
|
+
z-index: 1000000;
|
|
33
|
+
opacity: 0;
|
|
34
|
+
transition: opacity .2s ease-in .8s;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
:host([layout="floating"][status]) article {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host([layout="floating"][status="processing"]) article,
|
|
42
|
+
:host([layout="floating"][status="error"]) article {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
transition: opacity .1s ease-out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@supports (position-area: block-end span-inline-end) {
|
|
48
|
+
:host([layout="floating"]) {
|
|
49
|
+
position: static;
|
|
50
|
+
anchor-name: --host;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:host([layout="floating"]) article {
|
|
54
|
+
position: fixed;
|
|
55
|
+
position-anchor: --host;
|
|
56
|
+
position-area: block-end span-inline-end;
|
|
57
|
+
position-try-fallbacks: flip-inline;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
button {
|
|
62
|
+
all: unset;
|
|
63
|
+
width: 100%;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
button:focus-visible {
|
|
68
|
+
outline: revert;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
button, :host([status]) #status {
|
|
72
|
+
position: relative;
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
min-height: 46px;
|
|
75
|
+
padding: 16px 16px 10px 52px;
|
|
76
|
+
border-radius: 6px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
:host([status]) button {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:host([status="processing"]) #status {
|
|
84
|
+
cursor: wait;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
button::before, :host([status]) #status::before {
|
|
88
|
+
content: '';
|
|
89
|
+
position: absolute;
|
|
90
|
+
left: 14px;
|
|
91
|
+
top: 50%;
|
|
92
|
+
width: 24px;
|
|
93
|
+
height: 24px;
|
|
94
|
+
margin-top: -10px;
|
|
95
|
+
border: 1px solid #bbb;
|
|
96
|
+
border-radius: 6px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:host([status="processing"]) #status::before {
|
|
100
|
+
border-radius: 50%;
|
|
101
|
+
border-color: transparent transparent #111 #111;
|
|
102
|
+
animation: spin 1s linear infinite;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
:host([status="success"]) #status::before {
|
|
106
|
+
border-color: #16a34a;
|
|
107
|
+
background-color: #16a34a;
|
|
108
|
+
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PHBhdGggZD0ibTE4IDgtOCA5LTQtNCIvPjwvc3ZnPg==");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
:host([status="error"]) #status::before {
|
|
112
|
+
border-color: #dc2626;
|
|
113
|
+
background-color: #dc2626;
|
|
114
|
+
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCI+PHBhdGggZD0iTTE3IDcgNyAxN003IDdsMTAgMTAiLz48L3N2Zz4=");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
footer {
|
|
118
|
+
text-align: right;
|
|
119
|
+
font-size: 12px;
|
|
120
|
+
color: #666;
|
|
121
|
+
padding: 2px 9px 7px 9px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
footer a {
|
|
125
|
+
color: inherit;
|
|
126
|
+
text-decoration: none;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
footer a:hover {
|
|
130
|
+
text-decoration: underline;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
134
|
+
</style>
|
|
135
|
+
<slot></slot>
|
|
136
|
+
<article>
|
|
137
|
+
<button type="button">I'm not a robot</button>
|
|
138
|
+
<div id="status" role="status"></div>
|
|
139
|
+
<footer>
|
|
140
|
+
Protected by
|
|
141
|
+
<a
|
|
142
|
+
href="https://github.com/jo-phil/treadwheel"
|
|
143
|
+
target="_blank"
|
|
144
|
+
rel="noopener noreferrer"
|
|
145
|
+
>
|
|
146
|
+
Treadwheel
|
|
147
|
+
</a>
|
|
148
|
+
</footer>
|
|
149
|
+
</article>
|
|
150
|
+
`;
|
|
151
|
+
class TreadwheelWidget extends HTMLElement {
|
|
152
|
+
constructor() {
|
|
153
|
+
super();
|
|
154
|
+
this._shadow = this.attachShadow({ mode: 'open' });
|
|
155
|
+
this._handleClick = async (e) => {
|
|
156
|
+
const target = e.target;
|
|
157
|
+
if (!target?.closest('button'))
|
|
158
|
+
return;
|
|
159
|
+
const envelope = this.getAttribute('envelope');
|
|
160
|
+
if (!envelope)
|
|
161
|
+
return;
|
|
162
|
+
this.setAttribute('status', 'processing');
|
|
163
|
+
const status = this._shadow.getElementById('status');
|
|
164
|
+
if (status)
|
|
165
|
+
status.textContent = 'Verifying…';
|
|
166
|
+
this.querySelectorAll('button').forEach((button) => {
|
|
167
|
+
button.disabled = true;
|
|
168
|
+
});
|
|
169
|
+
try {
|
|
170
|
+
const plaintext = await unsealInWorker(envelope, {
|
|
171
|
+
signal: this._abortController?.signal,
|
|
172
|
+
});
|
|
173
|
+
this.setAttribute('status', 'success');
|
|
174
|
+
if (status)
|
|
175
|
+
status.textContent = 'Verified';
|
|
176
|
+
const output = document.createElement('template');
|
|
177
|
+
if (this.getAttribute('output') === 'html') {
|
|
178
|
+
output.innerHTML = plaintext;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
output.content.textContent = plaintext;
|
|
182
|
+
}
|
|
183
|
+
if (this.getAttribute('layout') === 'floating') {
|
|
184
|
+
this.replaceChildren(output.content);
|
|
185
|
+
this._shadow.addEventListener('transitionend', () => this.replaceWith(...this.childNodes), { once: true });
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.replaceWith(output.content);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
193
|
+
this.removeAttribute('status');
|
|
194
|
+
if (status)
|
|
195
|
+
status.textContent = '';
|
|
196
|
+
this.querySelectorAll('button').forEach((button) => {
|
|
197
|
+
button.disabled = false;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.setAttribute('status', 'error');
|
|
202
|
+
if (status)
|
|
203
|
+
status.textContent = 'Verification failed';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
this._shadow.appendChild(template.content.cloneNode(true));
|
|
208
|
+
this._shadow.addEventListener('click', this._handleClick);
|
|
209
|
+
this._shadow.querySelector('slot')?.addEventListener('slotchange', () => {
|
|
210
|
+
if (this.hasAttribute('layout'))
|
|
211
|
+
return;
|
|
212
|
+
if (this.querySelector('button')) {
|
|
213
|
+
this.setAttribute('layout', 'floating');
|
|
214
|
+
}
|
|
215
|
+
}, { once: true });
|
|
216
|
+
}
|
|
217
|
+
connectedCallback() {
|
|
218
|
+
this._abortController = new AbortController();
|
|
219
|
+
}
|
|
220
|
+
disconnectedCallback() {
|
|
221
|
+
this._abortController?.abort();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
customElements.define('treadwheel-widget', TreadwheelWidget);
|
|
225
|
+
//# sourceMappingURL=widget.js.map
|