@swetrix/captcha 1.0.3 → 2.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.
@@ -17,7 +17,7 @@
17
17
  }
18
18
  </style>
19
19
 
20
- <script src="../captcha-loader.js" defer></script>
20
+ <script src="../../dist/captcha-loader.js" defer></script>
21
21
  </head>
22
22
 
23
23
  <body>
@@ -25,7 +25,7 @@
25
25
  <input type="text" name="name" value="name">
26
26
  <input type="text" name="email" value="email">
27
27
  <input type="number" name="number" value="number">
28
- <div class="swecaptcha" data-project-id="MP00000000000" data-theme="dark"></div>
28
+ <div class="swecaptcha" data-project-id="AP00000000000" data-theme="light"></div>
29
29
  <input type="submit" value="Submit">
30
30
  </form>
31
31
  </body>
@@ -0,0 +1,178 @@
1
+ export {}
2
+
3
+ // PoW Worker - Computes the proof-of-work solution in a background thread
4
+
5
+ // Maximum allowed difficulty to prevent excessive computation
6
+ const MAX_DIFFICULTY = 32
7
+
8
+ // Default maximum iterations to prevent infinite loops (100 million)
9
+ const DEFAULT_MAX_ITERATIONS = 100_000_000
10
+
11
+ interface PowChallenge {
12
+ challenge: string
13
+ difficulty: number
14
+ maxIterations?: number // Optional: maximum iterations before timeout (default: 100 million)
15
+ }
16
+
17
+ interface PowResult {
18
+ type: 'result'
19
+ nonce: number
20
+ solution: string
21
+ }
22
+
23
+ interface PowProgress {
24
+ type: 'progress'
25
+ attempts: number
26
+ hashRate: number
27
+ }
28
+
29
+ interface PowTimeout {
30
+ type: 'timeout'
31
+ reason: string
32
+ attempts: number
33
+ elapsedMs: number
34
+ hashRate: number
35
+ }
36
+
37
+ interface PowError {
38
+ type: 'error'
39
+ message: string
40
+ }
41
+
42
+ type PowMessage = PowResult | PowProgress | PowTimeout | PowError
43
+
44
+ // SHA-256 implementation using SubtleCrypto
45
+ async function sha256(message: string): Promise<string> {
46
+ const encoder = new TextEncoder()
47
+ const data = encoder.encode(message)
48
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data)
49
+ const hashArray = Array.from(new Uint8Array(hashBuffer))
50
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')
51
+ }
52
+
53
+ // Check if hash has required number of leading zeros
54
+ function hasValidPrefix(hash: string, difficulty: number): boolean {
55
+ for (let i = 0; i < difficulty; i++) {
56
+ if (hash[i] !== '0') {
57
+ return false
58
+ }
59
+ }
60
+ return true
61
+ }
62
+
63
+ // Solve the PoW challenge
64
+ async function solveChallenge(challenge: string, difficulty: number, maxIterations: number): Promise<void> {
65
+ let nonce = 0
66
+ const startTime = Date.now()
67
+ const progressInterval = 10000 // Report progress every 10k attempts
68
+
69
+ while (nonce < maxIterations) {
70
+ const input = `${challenge}:${nonce}`
71
+ const hash = await sha256(input)
72
+
73
+ if (hasValidPrefix(hash, difficulty)) {
74
+ // Found the solution!
75
+ const result: PowResult = {
76
+ type: 'result',
77
+ nonce,
78
+ solution: hash,
79
+ }
80
+ self.postMessage(result)
81
+ return
82
+ }
83
+
84
+ nonce++
85
+
86
+ // Report progress periodically
87
+ if (nonce % progressInterval === 0) {
88
+ const elapsedMs = Date.now() - startTime
89
+ const elapsed = elapsedMs / 1000
90
+ const hashRate = Math.round(nonce / elapsed)
91
+ const progress: PowProgress = {
92
+ type: 'progress',
93
+ attempts: nonce,
94
+ hashRate,
95
+ }
96
+ self.postMessage(progress)
97
+ }
98
+ }
99
+
100
+ // Max iterations reached - send timeout message
101
+ const elapsedMs = Date.now() - startTime
102
+ const elapsed = elapsedMs / 1000
103
+ const hashRate = elapsed > 0 ? Math.round(nonce / elapsed) : 0
104
+ const timeout: PowTimeout = {
105
+ type: 'timeout',
106
+ reason: `Maximum iterations reached (${maxIterations.toLocaleString()})`,
107
+ attempts: nonce,
108
+ elapsedMs,
109
+ hashRate,
110
+ }
111
+ self.postMessage(timeout)
112
+ }
113
+
114
+ // Listen for messages from the main thread
115
+ self.onmessage = async (event: MessageEvent<PowChallenge>) => {
116
+ // Validate event.data exists
117
+ if (!event.data) {
118
+ const error: PowError = {
119
+ type: 'error',
120
+ message: 'Invalid message: event.data is missing or empty',
121
+ }
122
+ self.postMessage(error)
123
+ return
124
+ }
125
+
126
+ const { challenge, difficulty, maxIterations } = event.data
127
+
128
+ // Validate challenge is provided and is a non-empty string
129
+ if (typeof challenge !== 'string' || challenge.length === 0) {
130
+ const error: PowError = {
131
+ type: 'error',
132
+ message: 'Invalid message: challenge must be a non-empty string',
133
+ }
134
+ self.postMessage(error)
135
+ return
136
+ }
137
+
138
+ // Validate difficulty is a positive integer within acceptable range
139
+ if (typeof difficulty !== 'number' || !Number.isInteger(difficulty)) {
140
+ const error: PowError = {
141
+ type: 'error',
142
+ message: 'Invalid message: difficulty must be an integer',
143
+ }
144
+ self.postMessage(error)
145
+ return
146
+ }
147
+
148
+ if (difficulty < 1 || difficulty > MAX_DIFFICULTY) {
149
+ const error: PowError = {
150
+ type: 'error',
151
+ message: `Invalid message: difficulty must be between 1 and ${MAX_DIFFICULTY}`,
152
+ }
153
+ self.postMessage(error)
154
+ return
155
+ }
156
+
157
+ // Validate maxIterations if provided
158
+ const effectiveMaxIterations = maxIterations ?? DEFAULT_MAX_ITERATIONS
159
+ if (typeof effectiveMaxIterations !== 'number' || !Number.isInteger(effectiveMaxIterations)) {
160
+ const error: PowError = {
161
+ type: 'error',
162
+ message: 'Invalid message: maxIterations must be an integer',
163
+ }
164
+ self.postMessage(error)
165
+ return
166
+ }
167
+
168
+ if (effectiveMaxIterations < 1) {
169
+ const error: PowError = {
170
+ type: 'error',
171
+ message: 'Invalid message: maxIterations must be at least 1',
172
+ }
173
+ self.postMessage(error)
174
+ return
175
+ }
176
+
177
+ await solveChallenge(challenge, difficulty, effectiveMaxIterations)
178
+ }
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "moduleResolution": "node",
4
- "target": "es2020",
5
- "module": "es2015",
6
- "lib": ["dom"],
4
+ "target": "ES2020",
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM"],
7
7
  "strict": true,
8
8
  "sourceMap": true,
9
9
  "declaration": true,
10
- "allowSyntheticDefaultImports": true,
11
- "experimentalDecorators": true,
12
- "emitDecoratorMetadata": true,
13
10
  "outDir": "dist/esnext",
14
- "typeRoots": ["node_modules/@types"]
11
+ "typeRoots": ["node_modules/@types"],
12
+ "skipLibCheck": true
15
13
  },
16
14
  "include": ["src"]
17
- }
15
+ }
package/tsconfig.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "moduleResolution": "node",
4
- "target": "es5",
5
- "module": "es2015",
6
- "lib": ["es2015", "es2016", "es2017", "dom"],
4
+ "target": "ES2018",
5
+ "module": "ESNext",
6
+ "lib": ["ES2018", "DOM"],
7
7
  "strict": true,
8
- "allowSyntheticDefaultImports": true,
9
- "experimentalDecorators": true,
10
- "emitDecoratorMetadata": true,
11
8
  "sourceMap": true,
12
9
  "declaration": false,
13
- "outDir": "dist/lib",
14
- "typeRoots": ["node_modules/@types"]
10
+ "allowSyntheticDefaultImports": true,
11
+ "skipLibCheck": true
15
12
  },
16
13
  "include": ["src"]
17
14
  }
@@ -1,33 +0,0 @@
1
- declare const isDevelopment: any;
2
- declare const CAPTCHA_SELECTOR = ".swecaptcha";
3
- declare const LIGHT_CAPTCHA_IFRAME_URL: string;
4
- declare const DARK_CAPTCHA_IFRAME_URL: string;
5
- declare const DEFAULT_RESPONSE_INPUT_NAME = "swetrix-captcha-response";
6
- declare const MESSAGE_IDENTIFIER = "swetrix-captcha";
7
- declare const ID_PREFIX = "swetrix-captcha-";
8
- declare const THEMES: string[];
9
- declare const PID_REGEX: RegExp;
10
- declare enum LOG_ACTIONS {
11
- log = "log",
12
- error = "error",
13
- warn = "warn",
14
- info = "info"
15
- }
16
- declare const DUMMY_PIDS: string[];
17
- declare const isValidPID: (pid: string) => boolean;
18
- declare const FRAME_HEIGHT_MAPPING: {
19
- default: string;
20
- manual: string;
21
- };
22
- declare const getFrameID: (cid: string) => string;
23
- declare const ids: string[];
24
- declare const log: (status: LOG_ACTIONS, text: string) => void;
25
- declare const appendParamsToURL: (url: string, params: any) => string;
26
- declare const renderCaptcha: (container: Element, params: any) => void;
27
- declare const generateRandomID: () => string;
28
- declare const postMessageCallback: (pmEvent: MessageEvent) => void;
29
- declare const generateCaptchaFrame: (params: any) => HTMLIFrameElement;
30
- declare const generateHiddenInput: (params: any) => HTMLInputElement;
31
- declare const validateParams: (params: any) => boolean;
32
- declare const parseParams: (container: Element) => object;
33
- declare const main: (forced?: boolean) => void;
@@ -1,182 +0,0 @@
1
- "use strict";
2
- // @ts-ignore
3
- const isDevelopment = window.__SWETRIX_CAPTCHA_DEV || false;
4
- const CAPTCHA_SELECTOR = '.swecaptcha';
5
- const LIGHT_CAPTCHA_IFRAME_URL = isDevelopment ? './light.html' : 'https://cap.swetrix.com/pages/light';
6
- const DARK_CAPTCHA_IFRAME_URL = isDevelopment ? './dark.html' : 'https://cap.swetrix.com/pages/dark';
7
- const DEFAULT_RESPONSE_INPUT_NAME = 'swetrix-captcha-response';
8
- const MESSAGE_IDENTIFIER = 'swetrix-captcha';
9
- const ID_PREFIX = 'swetrix-captcha-';
10
- const THEMES = ['light', 'dark'];
11
- const PID_REGEX = /^(?!.*--)[a-zA-Z0-9-]{12}$/;
12
- var LOG_ACTIONS;
13
- (function (LOG_ACTIONS) {
14
- LOG_ACTIONS["log"] = "log";
15
- LOG_ACTIONS["error"] = "error";
16
- LOG_ACTIONS["warn"] = "warn";
17
- LOG_ACTIONS["info"] = "info";
18
- })(LOG_ACTIONS || (LOG_ACTIONS = {}));
19
- const DUMMY_PIDS = [
20
- 'AP00000000000', 'MP00000000000', 'FAIL000000000',
21
- ];
22
- const isValidPID = (pid) => DUMMY_PIDS.includes(pid) || PID_REGEX.test(pid);
23
- const FRAME_HEIGHT_MAPPING = {
24
- default: '66px',
25
- manual: '200px',
26
- };
27
- const getFrameID = (cid) => `${cid}-frame`;
28
- const ids = [];
29
- const log = (status, text) => {
30
- console[status](`[Swetrix Captcha] ${text}`);
31
- };
32
- const appendParamsToURL = (url, params) => {
33
- const queryString = Object.keys(params).map((key) => {
34
- return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`;
35
- }).join('&');
36
- return `${url}?${queryString}`;
37
- };
38
- const renderCaptcha = (container, params) => {
39
- const cid = generateRandomID();
40
- const cParams = {
41
- ...params,
42
- cid, // CAPTCHA ID
43
- };
44
- const frame = generateCaptchaFrame(cParams);
45
- const input = generateHiddenInput(cParams);
46
- container.appendChild(frame);
47
- container.appendChild(input);
48
- };
49
- const generateRandomID = () => {
50
- const randomID = ID_PREFIX + Math.random().toString(36).substr(2, 6);
51
- if (ids.includes(randomID)) {
52
- return generateRandomID();
53
- }
54
- ids.push(randomID);
55
- return randomID;
56
- };
57
- const postMessageCallback = (pmEvent) => {
58
- // TODO: Validate origin
59
- const { data } = pmEvent;
60
- if (!data) {
61
- return;
62
- }
63
- const { type, cid, event, } = data;
64
- if (type !== MESSAGE_IDENTIFIER) {
65
- return;
66
- }
67
- if (!cid || !ids.includes(cid)) {
68
- return;
69
- }
70
- const input = document.getElementById(cid);
71
- const inputExists = input !== null;
72
- switch (event) {
73
- case 'success': {
74
- const { token } = data;
75
- if (!inputExists) {
76
- log(LOG_ACTIONS.error, '[PM -> success] Input element does not exist.');
77
- return;
78
- }
79
- // @ts-ignore
80
- input.value = token;
81
- break;
82
- }
83
- case 'failure': {
84
- if (!inputExists) {
85
- log(LOG_ACTIONS.error, '[PM -> failure] Input element does not exist.');
86
- return;
87
- }
88
- // @ts-ignore
89
- input.value = '';
90
- break;
91
- }
92
- case 'tokenExpired': {
93
- if (!inputExists) {
94
- log(LOG_ACTIONS.error, '[PM -> failure] Input element does not exist.');
95
- return;
96
- }
97
- // @ts-ignore
98
- input.value = '';
99
- break;
100
- }
101
- case 'manualStarted': {
102
- const frame = document.getElementById(getFrameID(cid));
103
- if (!frame) {
104
- log(LOG_ACTIONS.error, '[PM -> manualStarted] Frame does not exist.');
105
- return;
106
- }
107
- frame.style.height = FRAME_HEIGHT_MAPPING.manual;
108
- break;
109
- }
110
- case 'manualFinished': {
111
- const frame = document.getElementById(getFrameID(cid));
112
- if (!frame) {
113
- log(LOG_ACTIONS.error, '[PM -> manualFinished] Frame does not exist.');
114
- return;
115
- }
116
- frame.style.height = FRAME_HEIGHT_MAPPING.default;
117
- break;
118
- }
119
- }
120
- };
121
- const generateCaptchaFrame = (params) => {
122
- const { theme } = params;
123
- const captchaFrame = document.createElement('iframe');
124
- captchaFrame.id = getFrameID(params.cid);
125
- captchaFrame.src = theme === 'dark'
126
- ? appendParamsToURL(DARK_CAPTCHA_IFRAME_URL, params)
127
- : appendParamsToURL(LIGHT_CAPTCHA_IFRAME_URL, params);
128
- captchaFrame.style.height = FRAME_HEIGHT_MAPPING.default;
129
- captchaFrame.title = 'Swetrix Captcha';
130
- captchaFrame.style.border = 'none';
131
- captchaFrame.style.width = '302px';
132
- captchaFrame.style.overflow = 'visible';
133
- return captchaFrame;
134
- };
135
- const generateHiddenInput = (params) => {
136
- const { cid } = params;
137
- const input = document.createElement('input');
138
- input.type = 'hidden';
139
- input.name = params.respName;
140
- input.value = '';
141
- input.id = cid;
142
- return input;
143
- };
144
- const validateParams = (params) => {
145
- const { theme, pid } = params;
146
- if (theme && !THEMES.includes(theme)) {
147
- log(LOG_ACTIONS.error, `Invalid data-theme parameter: ${theme}`);
148
- return false;
149
- }
150
- if (!pid || !isValidPID(pid)) {
151
- log(LOG_ACTIONS.error, `Invalid data-project-id parameter: ${pid}`);
152
- return false;
153
- }
154
- return true;
155
- };
156
- const parseParams = (container) => ({
157
- pid: container.getAttribute('data-project-id'),
158
- respName: container.getAttribute('data-response-input-name') || DEFAULT_RESPONSE_INPUT_NAME,
159
- theme: container.getAttribute('data-theme'),
160
- });
161
- const main = (forced = false) => {
162
- if (!forced && 'swecaptcha' in window) {
163
- log(LOG_ACTIONS.warn, 'Captcha is already loaded.');
164
- }
165
- // TODO: Add some callbacks here
166
- // @ts-ignore
167
- window.swecaptcha = true;
168
- window.addEventListener('message', postMessageCallback);
169
- const containers = Array.from(document.querySelectorAll(CAPTCHA_SELECTOR));
170
- for (const container of containers) {
171
- const params = parseParams(container);
172
- if (!validateParams(params)) {
173
- log(LOG_ACTIONS.error, 'Aborting captcha rendering due to invalid parameters.');
174
- return;
175
- }
176
- renderCaptcha(container, params);
177
- }
178
- };
179
- // @ts-ignore
180
- window.swetrixCaptchaForceLoad = () => main(true);
181
- document.addEventListener('DOMContentLoaded', () => main());
182
- //# sourceMappingURL=captcha-loader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"captcha-loader.js","sourceRoot":"","sources":["../../src/captcha-loader.ts"],"names":[],"mappings":";AAAA,aAAa;AACb,MAAM,aAAa,GAAG,MAAM,CAAC,qBAAqB,IAAI,KAAK,CAAA;AAE3D,MAAM,gBAAgB,GAAG,aAAa,CAAA;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,qCAAqC,CAAA;AACvG,MAAM,uBAAuB,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,oCAAoC,CAAA;AACpG,MAAM,2BAA2B,GAAG,0BAA0B,CAAA;AAC9D,MAAM,kBAAkB,GAAG,iBAAiB,CAAA;AAC5C,MAAM,SAAS,GAAG,kBAAkB,CAAA;AACpC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAChC,MAAM,SAAS,GAAG,4BAA4B,CAAA;AAE9C,IAAK,WAKJ;AALD,WAAK,WAAW;IACd,0BAAW,CAAA;IACX,8BAAe,CAAA;IACf,4BAAa,CAAA;IACb,4BAAa,CAAA;AACf,CAAC,EALI,WAAW,KAAX,WAAW,QAKf;AAED,MAAM,UAAU,GAAG;IACjB,eAAe,EAAE,eAAe,EAAE,eAAe;CAClD,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC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AgB,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA"}
@@ -1,37 +0,0 @@
1
- declare const isDevelopment: any;
2
- declare const API_URL: string;
3
- declare const MSG_IDENTIFIER = "swetrix-captcha";
4
- declare const DEFAULT_THEME = "light";
5
- declare const CAPTCHA_TOKEN_LIFETIME = 300;
6
- declare let TOKEN: string;
7
- declare let HASH: string;
8
- declare const ENDPOINTS: {
9
- VERIFY: string;
10
- GENERATE: string;
11
- VERIFY_MANUAL: string;
12
- };
13
- declare enum IFRAME_MESSAGE_TYPES {
14
- SUCCESS = "success",
15
- FAILURE = "failure",
16
- TOKEN_EXPIRED = "tokenExpired",
17
- MANUAL_STARTED = "manualStarted",
18
- MANUAL_FINISHED = "manualFinished"
19
- }
20
- declare enum ACTION {
21
- checkbox = "checkbox",
22
- failure = "failure",
23
- completed = "completed",
24
- loading = "loading"
25
- }
26
- declare let activeAction: ACTION;
27
- declare const sendMessageToLoader: (event: IFRAME_MESSAGE_TYPES, data?: {}) => void;
28
- /**
29
- * Sets the provided action visible and the rest hidden
30
- * @param {*} action checkbox | failure | completed | loading
31
- */
32
- declare const activateAction: (action: ACTION) => void;
33
- declare const setLifetimeTimeout: () => void;
34
- declare const enableManualChallenge: (svg: string) => void;
35
- declare const disableManualChallenge: () => void;
36
- declare const generateCaptcha: () => Promise<any>;
37
- declare const verify: () => Promise<any>;