altcha 0.8.0 → 1.0.0
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/README.md +77 -45
- package/dist/altcha.d.ts +10 -3
- package/dist/altcha.js +853 -905
- package/dist/altcha.umd.cjs +2 -2
- package/dist_external/altcha.d.ts +10 -3
- package/dist_external/altcha.js +934 -986
- package/dist_external/altcha.umd.cjs +2 -2
- package/dist_plugins/analytics.d.ts +1 -0
- package/dist_plugins/analytics.js +290 -0
- package/dist_plugins/analytics.umd.cjs +1 -0
- package/dist_plugins/obfuscation.d.ts +1 -0
- package/dist_plugins/obfuscation.js +138 -0
- package/dist_plugins/obfuscation.umd.cjs +1 -0
- package/dist_plugins/upload.d.ts +1 -0
- package/dist_plugins/upload.js +458 -0
- package/dist_plugins/upload.umd.cjs +4 -0
- package/package.json +38 -21
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Visit [ALTCHA](https://altcha.org) for more information.
|
|
|
31
31
|
- [Ruby](https://github.com/altcha-org/altcha-lib-rb)
|
|
32
32
|
- [Elixir](https://github.com/altcha-org/altcha-lib-ex)
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## CMS
|
|
35
35
|
|
|
36
36
|
- [WordPress plugin](https://github.com/altcha-org/wordpress-plugin)
|
|
37
37
|
- [Other libraries and plugins](https://altcha.org/docs/integrations/)
|
|
@@ -80,6 +80,16 @@ See the [configuration](#configuration) below or visit the [website integration
|
|
|
80
80
|
|
|
81
81
|
See [server documentation](https://altcha.org/docs/server-integration) for more details.
|
|
82
82
|
|
|
83
|
+
## Bundle Size
|
|
84
|
+
|
|
85
|
+
ALTCHA's default bundle is lightweight, combining all assets, including CSS and the JavaScript Web Worker, into a single file. When GZIPped, it totals only 17 kB, making ALTCHA’s widget 94% smaller than reCAPTCHA.
|
|
86
|
+
|
|
87
|
+
|Distribution|Size (GZIPped)|
|
|
88
|
+
|---|---|
|
|
89
|
+
|ALTCHA (v1.x)|17 kB|
|
|
90
|
+
|hCaptcha|48+ kB|
|
|
91
|
+
|reCAPTCHA|270+ kB|
|
|
92
|
+
|
|
83
93
|
## Content Security Policy (CSP)
|
|
84
94
|
|
|
85
95
|
The default distribution bundle of the WebComponent includes styles and the worker in a single file. This might cause issues with strict CSP rules. If you require strict CSP compliance, consider using the scripts located in the `/dist_external` directory. For more details, please refer to the [documentation](https://altcha.org/docs/website-integration).
|
|
@@ -88,37 +98,60 @@ The default distribution bundle of the WebComponent includes styles and the work
|
|
|
88
98
|
|
|
89
99
|
Required options (at least one is required):
|
|
90
100
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
101
|
+
- **challengeurl**: URL of your server to fetch the challenge from. Refer to [server integration](https://altcha.org/docs/server-integration).
|
|
102
|
+
- **challengejson**: JSON-encoded challenge data. If avoiding an HTTP request to `challengeurl`, provide the data here.
|
|
93
103
|
|
|
94
104
|
Additional options:
|
|
95
105
|
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
- **auto**: Automatically verify without user interaction (possible values: `off`, `onfocus`, `onload`, `onsubmit`).
|
|
107
|
+
- **delay**: Artificial delay in milliseconds before verification (defaults to 0).
|
|
108
|
+
- **expire**: Challenge expiration duration in milliseconds.
|
|
109
|
+
- **floating**: Enable floating UI (possible values: `auto`, `top`, `bottom`).
|
|
110
|
+
- **floatinganchor**: CSS selector of the "anchor" to which the floating UI will be attached (defaults to the `button[type="submit"]` in the related form).
|
|
111
|
+
- **floatingoffset**: Y offset from the anchor element for the floating UI in pixels (defaults to `12`).
|
|
112
|
+
- **hidefooter**: Hide the footer (ALTCHA link).
|
|
113
|
+
- **hidelogo**: Hide the ALTCHA logo.
|
|
114
|
+
- **maxnumber**: Max number to iterate to (defaults to 1,000,000).
|
|
115
|
+
- **name**: Name of the hidden field containing the payload (defaults to "altcha").
|
|
116
|
+
- **strings**: JSON-encoded translation strings. Refer to [customization](https://altcha.org/docs/widget-customization).
|
|
117
|
+
- **refetchonexpire**: Automatically re-fetch and re-validate when the challenge expires (defaults to true).
|
|
118
|
+
- **workers**: Number of workers to utilize for PoW (defaults to `navigator.hardwareConcurrency || 8`, max value `16`).
|
|
119
|
+
- **workerurl**: URL of the Worker script (defaults to `./worker.js`, only works with `external` build).
|
|
120
|
+
|
|
121
|
+
Spam Filter-related options:
|
|
122
|
+
|
|
123
|
+
- **blockspam**: Only used with the `spamfilter` option. If enabled, it will block form submission and fail verification if the Spam Filter returns a negative classification. This prevents form submission.
|
|
124
|
+
- **spamfilter**: Enable [Spam Filter](#spam-filter).
|
|
125
|
+
- **verifyurl**: URL for server-side verification requests. This option is automatically configured when the `spamfilter` option is used. Override this setting only if using a custom server implementation.
|
|
126
|
+
|
|
127
|
+
Data Obfuscation options:
|
|
128
|
+
|
|
129
|
+
- **obfuscated**: The [obfuscated data](https://altcha.org/docs/obfuscation) provided as a base64-encoded string (requires `altcha/obfuscation` plugin). Use only without `challengeurl`/`challengejson`.
|
|
130
|
+
|
|
131
|
+
Development / Testing options:
|
|
132
|
+
|
|
133
|
+
- **debug**: Print log messages in the console.
|
|
134
|
+
- **mockerror**: Causes verification to always fail with a "mock" error.
|
|
135
|
+
- **test**: Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`.
|
|
136
|
+
|
|
137
|
+
## Plugins
|
|
138
|
+
|
|
139
|
+
Version 0.9.x introduced _plugins_ that can be enabled by importing individual plugin scripts:
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import 'altcha/obfuscation';
|
|
143
|
+
import 'altcha';
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
It is recommended to import plugins _before_ the main `altcha` package to ensure proper registration before any widget instance is created.
|
|
147
|
+
|
|
148
|
+
Available plugins built-in to the `altcha` package:
|
|
149
|
+
|
|
150
|
+
- `altcha/analytics`: Enable analytics with [ALTCHA Forms](https://altcha.org/forms/). See [HTML submissions documentation](https://altcha.org/docs/forms/features/html-submissions).
|
|
151
|
+
- `altcha/obfuscation`: Enable [obfuscation](https://altcha.org/docs/obfuscation) for sensitive data such as email addresses or phone numbers.
|
|
152
|
+
- `altcha/upload`: Enable file upload from `type=file` fields to [ALTCHA Forms](https://altcha.org/forms/). See [HTML submissions documentation](https://altcha.org/docs/forms/features/html-submissions).
|
|
153
|
+
|
|
154
|
+
To enable specific plugins for a particular instance of the widget, use the `plugins` attribute in the widget tag. List the names of the plugins you want to enable, separated by commas, such as `plugins="analytics,obfuscation"`. Plugins still need to be imported as described above. The `plugins` attribute only specifies which plugins should be active for that instance, even if other plugins are already imported.
|
|
122
155
|
|
|
123
156
|
## Programmatic Configuration
|
|
124
157
|
|
|
@@ -142,9 +175,7 @@ Available configuration options:
|
|
|
142
175
|
|
|
143
176
|
```ts
|
|
144
177
|
export interface Configure {
|
|
145
|
-
|
|
146
|
-
auto?: 'onfocus' | 'onload' | 'onsubmit';
|
|
147
|
-
beaconurl?: string;
|
|
178
|
+
auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
|
|
148
179
|
challenge?: {
|
|
149
180
|
algorithm: string;
|
|
150
181
|
challenge: string;
|
|
@@ -186,9 +217,10 @@ export interface Configure {
|
|
|
186
217
|
|
|
187
218
|
## Events
|
|
188
219
|
|
|
189
|
-
-
|
|
190
|
-
-
|
|
191
|
-
-
|
|
220
|
+
- **load** - Triggers when the widget loads. The exported methods become available after this event.
|
|
221
|
+
- **serververification** - Triggers upon a server verification (only in conjunction with `spamfilter`).
|
|
222
|
+
- **statechange** - Triggers whenever an internal `state` changes.
|
|
223
|
+
- **verified** - Triggers when the challenge is verified.
|
|
192
224
|
|
|
193
225
|
```ts
|
|
194
226
|
enum State {
|
|
@@ -239,16 +271,16 @@ interface SpamFilter {
|
|
|
239
271
|
|
|
240
272
|
SpamFilter configuration options:
|
|
241
273
|
|
|
242
|
-
-
|
|
243
|
-
-
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
249
|
-
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
274
|
+
- **blockedCountries** - An array of country codes (ISO 3166 alpha-2) that you want to block.
|
|
275
|
+
- **classifier** - Enforce a specific classifier.
|
|
276
|
+
- **disableRules** - An array of rules to disable.
|
|
277
|
+
- **email** - The name of the input field for the user's email. Disable email checking with `false`.
|
|
278
|
+
- **expectedCountries** - An array of expected countries as 2-letter codes (ISO 3166-1 alpha-2).
|
|
279
|
+
- **expectedLanguages** - An array of expected languages as 2-letter codes (ISO 639 alpha-2).
|
|
280
|
+
- **fields** - An array of input names to send to the spam filter.
|
|
281
|
+
- **ipAddress** - The user's IP is detected automatically but can be overridden or disabled with `false`.
|
|
282
|
+
- **text** - The text to classify. An array of strings can also be submitted.
|
|
283
|
+
- **timeZone** - The user's timezone is detected automatically but can be overridden or disabled with `false`.
|
|
252
284
|
|
|
253
285
|
To include the email field into `fields` (for easier server-side verification), configure the list of input names using the `spamfilter.fields: string[]` option.
|
|
254
286
|
|
package/dist/altcha.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export {};
|
|
|
3
3
|
declare module 'altcha';
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
6
|
+
var altchaCreateWorker: (url?: string) => Worker;
|
|
7
|
+
var altchaPlugins: any[];
|
|
8
|
+
|
|
6
9
|
type AltchaState = 'error' | 'expired' | 'verified' | 'verifying' | 'unverified';
|
|
7
10
|
|
|
8
11
|
interface AltchaStateChangeEvent extends CustomEvent<{
|
|
@@ -17,9 +20,7 @@ declare global {
|
|
|
17
20
|
interface AltchaServerVerificationEvent extends CustomEvent<Record<string, unknown>> {}
|
|
18
21
|
|
|
19
22
|
interface AltchaWidgetOptions {
|
|
20
|
-
|
|
21
|
-
auto?: 'onfocus' | 'onload' | 'onsubmit';
|
|
22
|
-
beaconurl?: string;
|
|
23
|
+
auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
|
|
23
24
|
blockspam?: boolean;
|
|
24
25
|
challengeurl?: string;
|
|
25
26
|
challengejson?: string;
|
|
@@ -47,7 +48,13 @@ declare global {
|
|
|
47
48
|
interface AltchaWidgetMethods {
|
|
48
49
|
configure: (options: AltchaWidgetOptions) => void;
|
|
49
50
|
clarify: () => Promise<void>;
|
|
51
|
+
getConfiguration: () => AltchaWidgetOptions;
|
|
52
|
+
getFloatingAnchor: () => HTMLElement | null;
|
|
53
|
+
getPlugin: <T = unknown>(name: string) => T;
|
|
54
|
+
getState: () => AltchaState;
|
|
50
55
|
reset: (newState: AltchaState = 'unverified', err: string | null = null) => void;
|
|
56
|
+
setFloatingAnchor: (el: HTMLElement) => void;
|
|
57
|
+
setState: (newState: AltchaState, err: string | null = null) => void;
|
|
51
58
|
verify: () => Promise<void>;
|
|
52
59
|
}
|
|
53
60
|
|