altcha 0.7.0 → 0.9.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 CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  ALTCHA uses a proof-of-work mechanism to protect your website, APIs, and online services from spam and abuse. Unlike other solutions, ALTCHA is self-hosted, does not use cookies nor fingerprinting, does not track users, and is fully compliant with GDPR.
4
4
 
5
- https://altcha.org
5
+ Visit [ALTCHA](https://altcha.org) for more information.
6
6
 
7
- ## Benefits
7
+ ## Features
8
8
 
9
- - __Friction-less__ - Using PoW instead of visual puzzles.
10
- - __Cookie-less__ - GDPR compliant by design.
11
- - __Self-hosted__ - Without reliance on external providers in self-hosted mode.
12
- - __SaaS available__ - Visit [altcha.org](https://altcha.org/docs/api) to get started with the SaaS API.
9
+ - **Frictionless CAPTCHA Alternative** - Employs proof-of-work (PoW) instead of visual puzzles.
10
+ - **Data Obfuscation** - Safeguards your email address from scraping.
11
+ - **Cookie-less** - Designed to be GDPR compliant by default.
12
+ - **Self-hosted** - Operates independently without relying on external providers.
13
+ - **SaaS Available** - Get started with the SaaS API at [altcha.org/docs/api](https://altcha.org/docs/api).
13
14
 
14
15
  ## Examples
15
16
 
@@ -28,8 +29,9 @@ https://altcha.org
28
29
  - [Python](https://github.com/altcha-org/altcha-lib-py)
29
30
  - [Java](https://github.com/altcha-org/altcha-lib-java)
30
31
  - [Ruby](https://github.com/altcha-org/altcha-lib-rb)
32
+ - [Elixir](https://github.com/altcha-org/altcha-lib-ex)
31
33
 
32
- ## Plugins
34
+ ## CMS
33
35
 
34
36
  - [WordPress plugin](https://github.com/altcha-org/wordpress-plugin)
35
37
  - [Other libraries and plugins](https://altcha.org/docs/integrations/)
@@ -78,6 +80,16 @@ See the [configuration](#configuration) below or visit the [website integration
78
80
 
79
81
  See [server documentation](https://altcha.org/docs/server-integration) for more details.
80
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 (v0.9.x)|17 kB|
90
+ |hCaptcha|48+ kB|
91
+ |reCAPTCHA|270+ kB|
92
+
81
93
  ## Content Security Policy (CSP)
82
94
 
83
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).
@@ -86,36 +98,60 @@ The default distribution bundle of the WebComponent includes styles and the work
86
98
 
87
99
  Required options (at least one is required):
88
100
 
89
- - __challengeurl__ - URL of your server to fetch the challenge from. Refer to [server integration](https://altcha.org/docs/server-integration).
90
- - __challengejson__ - JSON-encoded challenge data. If avoiding an HTTP request to `challengeurl`, provide the data here.
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.
91
103
 
92
104
  Additional options:
93
105
 
94
- - __analytics__ - Enable analytics with [ALTCHA Forms](https://altcha.org/forms/). See [HTML submissions documentation](https://altcha.org/docs/forms/features/html-submissions).
95
- - __auto__ - Automatically verify without user interaction (possible values: `onfocus`, `onload`, `onsubmit`).
96
- - __beaconurl__ - URL to which analytics data will be sent using a beacon POST if the form is abandoned. This option is only used when `analytics` is enabled.
97
- - __blockspam__ - Only used in conjunction with the `spamfilter` option. If enabled, it will block form submission and fail verification if the Spam Filter returns a negative classification. This effectively prevents submission of the form.
98
- - __delay__ - The artificial delay in milliseconds to apply before the verification (defaults to 0).
99
- - __expire__ - The challenge expiration (duration in milliseconds).
100
- - __floating__ - Enable floating UI (possible values: `auto`, `top`, `bottom`).
101
- - __floatinganchor__ - The CSS selector of the "anchor" to which the floating UI will be attached to (defaults to the `button[type="submit"]` in the related form).
102
- - __floatingoffset__ - The Y offset from the anchor element for the floating UI expressed in pixels (defaults to `12`).
103
- - __hidefooter__ - Hide the footer (ALTCHA link).
104
- - __hidelogo__ - Hide the ALTCHA logo.
105
- - __maxnumber__ - The max. number to iterate to (defaults to 1,000,000).
106
- - __name__ - The name of the hidden field containing the payload (defaults to "altcha").
107
- - __spamfilter__ - Enable [Spam Filter](#spam-filter).
108
- - __strings__ - JSON-encoded translation strings. Refer to [customization](/docs/widget-customization).
109
- - __refetchonexpire__ - Automatically re-fetch and re-validate when the challenge expires (defaults to true).
110
- - __verifyurl__ - URL for server-side verification requests. This option is automatically configured when the `spamfilter` option is used. Override this setting only if you are using a custom server implementation.
111
- - __workers__ - The number of workers to utilize for PoW (defaults to `navigator.hardwareConcurrency || 8`, max. value `16`).
112
- - __workerurl__ - The URL of the Worker script (defaults to `./worker.js`, only works with `external` build).
113
-
114
- Development / testing options:
115
-
116
- - __debug__ - Print log messages in the console.
117
- - __mockerror__ - Causes the verification to always fail with a "mock" error.
118
- - __test__ - Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`.
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.
119
155
 
120
156
  ## Programmatic Configuration
121
157
 
@@ -139,9 +175,7 @@ Available configuration options:
139
175
 
140
176
  ```ts
141
177
  export interface Configure {
142
- analytics?: boolean | string;
143
- auto?: 'onfocus' | 'onload' | 'onsubmit';
144
- beaconurl?: string;
178
+ auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
145
179
  challenge?: {
146
180
  algorithm: string;
147
181
  challenge: string;
@@ -162,6 +196,7 @@ export interface Configure {
162
196
  maxnumber?: number;
163
197
  mockerror?: boolean;
164
198
  name?: string;
199
+ obfuscated?: string;
165
200
  refetchonexpire?: boolean;
166
201
  spamfilter?: boolean | 'ipAddress' | SpamFilter;
167
202
  strings?: {
@@ -182,9 +217,10 @@ export interface Configure {
182
217
 
183
218
  ## Events
184
219
 
185
- - __serververification__ - Triggers upon a server verification (only in conjunction with `spamfilter`).
186
- - __statechange__ - Triggers whenever an internal `state` changes.
187
- - __verified__ - Triggers when the challenge is verified.
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.
188
224
 
189
225
  ```ts
190
226
  enum State {
@@ -235,16 +271,16 @@ interface SpamFilter {
235
271
 
236
272
  SpamFilter configuration options:
237
273
 
238
- - __blockedCountries__ - An array of country codes (ISO 3166 alpha-2) that you want to block.
239
- - __classifier__ - Enforce a specific classifier.
240
- - __disableRules__ - An array of rules to disable.
241
- - __email__ - The name of the input field for the user's email. Disable email checking with `false`.
242
- - __expectedCountries__ - An array of expected countries as 2-letter codes (ISO 3166-1 alpha-2).
243
- - __expectedLanguages__ - An array of expected languages as 2-letter codes (ISO 639 alpha-2).
244
- - __fields__ - An array of input names to send to the spam filter.
245
- - __ipAddress__ - The user's IP is detected automatically but can be overridden or disabled with `false`.
246
- - __text__ - The text to classify. An array of strings can also be submitted.
247
- - __timeZone__ - The user's timezone is detected automatically but can be overridden or disabled with `false`.
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`.
248
284
 
249
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.
250
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<{
@@ -16,10 +19,8 @@ declare global {
16
19
 
17
20
  interface AltchaServerVerificationEvent extends CustomEvent<Record<string, unknown>> {}
18
21
 
19
- interface AltchaWidget {
20
- analytics?: boolean | string;
21
- auto?: 'onfocus' | 'onload' | 'onsubmit';
22
- beaconurl?: string;
22
+ interface AltchaWidgetOptions {
23
+ auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
23
24
  blockspam?: boolean;
24
25
  challengeurl?: string;
25
26
  challengejson?: string;
@@ -31,9 +32,10 @@ declare global {
31
32
  floatingoffset?: number;
32
33
  hidefooter?: boolean;
33
34
  hidelogo?: boolean;
34
- name?: string;
35
35
  maxnumber?: number;
36
36
  mockerror?: boolean;
37
+ name?: string;
38
+ obfuscated?: string;
37
39
  refetchonexpire?: boolean;
38
40
  spamfilter?: boolean | 'ipAddress';
39
41
  strings?: string;
@@ -43,6 +45,22 @@ declare global {
43
45
  workerurl?: string;
44
46
  }
45
47
 
48
+ interface AltchaWidgetMethods {
49
+ configure: (options: AltchaWidgetOptions) => void;
50
+ clarify: () => Promise<void>;
51
+ getConfiguration: () => AltchaWidgetOptions;
52
+ getFloatingAnchor: () => HTMLElement | null;
53
+ getPlugin: <T = unknown>(name: string) => T;
54
+ getState: () => AltchaState;
55
+ reset: (newState: AltchaState = 'unverified', err: string | null = null) => void;
56
+ setFloatingAnchor: (el: HTMLElement) => void;
57
+ setState: (newState: AltchaState, err: string | null = null) => void;
58
+ verify: () => Promise<void>;
59
+ }
60
+
61
+ interface AltchaWidget extends AltchaWidgetOptions extends AltchaWidgetMethods {
62
+ }
63
+
46
64
  declare namespace svelteHTML {
47
65
  interface IntrinsicElements {
48
66
  'altcha-widget': AltchaWidgetSvelte;
@@ -74,6 +92,7 @@ declare global {
74
92
  }
75
93
 
76
94
  interface AltchaWidgetReact extends AltchaWidget extends React.HTMLAttributes<HTMLElement> {
95
+ children?: React.ReactNode;
77
96
  ref?: React.RefObject<HTMLElement>;
78
97
  style?: AltchaWidgetCSSProperties;
79
98
  }