synapse-shield-vue 0.12.0 → 0.12.2

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
@@ -1,134 +1,134 @@
1
- # Synapse Shield Vue 3 & Nuxt 3 SDK
2
-
3
- Official Vue 3 and Nuxt 3 integration for **Synapse Shield** behavioral biometrics, bot mitigation, and anti-stealth engine.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install synapse-shield-vue
9
- # or
10
- pnpm add synapse-shield-vue
11
- # or
12
- yarn add synapse-shield-vue
13
- ```
14
-
15
- ## Quick Start (Vue 3 / Vite)
16
-
17
- ### Using the Composable (`useSynapseShield`)
18
-
19
- ```vue
20
- <script setup lang="ts">
21
- import { ref } from 'vue';
22
- import { useSynapseShield } from 'synapse-shield-vue';
23
-
24
- const { getProtectedPayload, isReady } = useSynapseShield({
25
- apiEndpoint: '/api',
26
- });
27
-
28
- const username = ref('');
29
- const password = ref('');
30
- const message = ref('');
31
-
32
- const handleLogin = async () => {
33
- // Get cryptographically signed token with behavioral biometrics
34
- const payload = getProtectedPayload();
35
-
36
- const response = await fetch('/api/login', {
37
- method: 'POST',
38
- headers: {
39
- 'Content-Type': 'application/json',
40
- 'X-Synapse-Token': payload.token, // canonical token header
41
- },
42
- body: JSON.stringify({
43
- username: username.value,
44
- password: password.value,
45
- // token: payload.token, // or in JSON body as 'token' (or 'synapse_token' compatibility alias)
46
- }),
47
- });
48
-
49
- const result = await response.json();
50
- message.value = result.message || 'Done';
51
- };
52
- </script>
53
-
54
- <template>
55
- <form @submit.prevent="handleLogin" class="login-form">
56
- <h2>Secure Login</h2>
57
- <input v-model="username" type="text" placeholder="Username" required />
58
- <input v-model="password" type="password" placeholder="Password" required />
59
- <button type="submit" :disabled="!isReady">Sign In</button>
60
- <p v-if="message">{{ message }}</p>
61
- </form>
62
- </template>
63
- ```
64
-
65
- ### Telemetry Shield Component (`SynapseProtect`)
66
-
67
- `<SynapseProtect />` mounts passive telemetry listeners inside your Vue template. Note that backend adapters require JSON bodies or `X-Synapse-Token` headers (traditional non-JS form POSTs are not gated). To submit protected form data, use `submitProtected()` or fetch with `X-Synapse-Token`:
68
-
69
- ```vue
70
- <script setup lang="ts">
71
- import { SynapseProtect } from 'synapse-shield-vue';
72
- </script>
73
-
74
- <template>
75
- <div>
76
- <SynapseProtect />
77
- <!-- Component mounts biometric telemetry listeners into this view -->
78
- </div>
79
- </template>
80
- ```
81
-
82
- ### Automatic Proof-of-Work retry (`submitProtected`)
83
-
84
- Same API as the React SDK. On HTTP 429 `challenge_required` it fetches a fresh challenge, solves the PoW and retries **once**. A second 429 is returned as is.
85
-
86
- ```ts
87
- const { submitProtected } = useSynapseShield();
88
-
89
- const res = await submitProtected('/api/login', (p) => ({
90
- username: username.value,
91
- token: p.token, // canonical body token (or via X-Synapse-Token header; 'synapse_token' alias accepted)
92
- pow_salt: p.pow_salt, // set only on the retry
93
- pow_nonce: p.pow_nonce, // read by the server middleware from the top level of the JSON body
94
- }));
95
- ```
96
-
97
- The retry waits 1.6-3 s (up to 8 s only when needed to keep the last 3 mouse points). It then sends the most recent telemetry window the server accepts. A long session is scored on its last few seconds. Tokens only carry events their challenge can vouch for, so long SPA sessions are not rejected as stale. Autofill, paste and IME entry are recorded in `input_events` as `{ t, kind }` only (no content, `key_count` unchanged).
98
-
99
- ---
100
-
101
- ## Nuxt 3 (SSR Safe)
102
-
103
- `synapse-shield-vue` is completely SSR-safe and guards all browser interactions with `onMounted` and `typeof window !== 'undefined'`. No special plugins or SSR flags are required!
104
-
105
- ```vue
106
- <!-- pages/login.vue in Nuxt 3 -->
107
- <script setup>
108
- import { useSynapseShield } from 'synapse-shield-vue';
109
-
110
- const { getProtectedPayload } = useSynapseShield();
111
- // Works automatically on client mount
112
- </script>
113
- ```
114
-
115
- ---
116
-
117
- ## Features (v0.12.0)
118
-
119
- - **Universal Keystroke Zero-PII Shield (v0.10.4):** Automatic client-side masking of all single-character inputs (`rawKey.length === 1 -> "masked"`) and sensitive fields, local digraph frequency computation (`is_freq_digraph`), transmitting zero raw text or PII across the wire (GDPR & KVKK compliant).
120
- - **SPA Token Lifecycle & Coalescing Mutex (v0.10.3):** Single-use challenge token lifecycle invalidation to eliminate 403 Replay Attack loops in Vue 3 and Nuxt applications.
121
- - **PoW Telemetry Retention (v0.10.3):** Shifts historical telemetry timestamps forward upon PoW challenge retry, eliminating empty telemetry 403 blocks for genuine users.
122
- - **Mobile SDK v2.0 & Handheld Biometrics (v0.10.0):** Tap hold duration tracking (`tap_duration_ms`), passive 3-axis gyroscope motion variance, and WebGL emulator detection.
123
- - **Hardened Security Architecture:** Full alignment with Synapse Shield production hardening (Algorithmic DoS mitigation, Rust SIMD differential curvature $\kappa(t)$, zero-copy buffers, and keystroke entropy analysis).
124
- - **Transparent Token Expiration Refresh:** Seamlessly renegotiates expired tokens (`HTTP 400 EXPIRED`) without triggering IP quarantine or streak bans.
125
- - **Distributed State & Redis Support:** Full compatibility with Synapse Shield multi-worker cluster deployments.
126
- - **Transient Iframe Prototype Unhooking:** Detects stealth tools tampering with `Function.prototype.toString`.
127
- - **Zero-Jank Touch Events:** Passive listeners (`touchstart`, `touchmove`, `touchend`) for high-precision mobile biometrics with zero scroll jank.
128
- - **Dynamic Yielding PoW Solver:** `solvePow(powSalt, difficulty)` takes the signed `pow_salt` from the server's `challenge_required` response (sha256(salt + nonce), bounded at 20M attempts) and yields to the UI thread every 1,000 iterations to avoid freezing browser rendering. `getProtectedPayload()` consumes the single-use challenge and fetches the next one in the background.
129
- - **Safe Unicode Base64:** Robust UTF-8 payload encoding across internationalized environments.
130
- - **Docker Ready Backend:** See the main repository `README.md` for zero-configuration `docker-compose` engine deployment instructions.
131
-
132
- ## License
133
-
134
- MIT © Mustafa Güngör
1
+ # Synapse Shield Vue 3 & Nuxt 3 SDK
2
+
3
+ Official Vue 3 and Nuxt 3 integration for **Synapse Shield** behavioral biometrics, bot mitigation, and anti-stealth engine.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install synapse-shield-vue
9
+ # or
10
+ pnpm add synapse-shield-vue
11
+ # or
12
+ yarn add synapse-shield-vue
13
+ ```
14
+
15
+ ## Quick Start (Vue 3 / Vite)
16
+
17
+ ### Using the Composable (`useSynapseShield`)
18
+
19
+ ```vue
20
+ <script setup lang="ts">
21
+ import { ref } from 'vue';
22
+ import { useSynapseShield } from 'synapse-shield-vue';
23
+
24
+ const { getProtectedPayload, isReady } = useSynapseShield({
25
+ apiEndpoint: '/api',
26
+ });
27
+
28
+ const username = ref('');
29
+ const password = ref('');
30
+ const message = ref('');
31
+
32
+ const handleLogin = async () => {
33
+ // Get cryptographically signed token with behavioral biometrics
34
+ const payload = getProtectedPayload();
35
+
36
+ const response = await fetch('/api/login', {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'X-Synapse-Token': payload.token, // canonical token header
41
+ },
42
+ body: JSON.stringify({
43
+ username: username.value,
44
+ password: password.value,
45
+ // token: payload.token, // or in JSON body as 'token' (or 'synapse_token' compatibility alias)
46
+ }),
47
+ });
48
+
49
+ const result = await response.json();
50
+ message.value = result.message || 'Done';
51
+ };
52
+ </script>
53
+
54
+ <template>
55
+ <form @submit.prevent="handleLogin" class="login-form">
56
+ <h2>Secure Login</h2>
57
+ <input v-model="username" type="text" placeholder="Username" required />
58
+ <input v-model="password" type="password" placeholder="Password" required />
59
+ <button type="submit" :disabled="!isReady">Sign In</button>
60
+ <p v-if="message">{{ message }}</p>
61
+ </form>
62
+ </template>
63
+ ```
64
+
65
+ ### Telemetry Shield Component (`SynapseProtect`)
66
+
67
+ `<SynapseProtect />` mounts passive telemetry listeners inside your Vue template. Note that backend adapters require JSON bodies or `X-Synapse-Token` headers (traditional non-JS form POSTs are not gated). To submit protected form data, use `submitProtected()` or fetch with `X-Synapse-Token`:
68
+
69
+ ```vue
70
+ <script setup lang="ts">
71
+ import { SynapseProtect } from 'synapse-shield-vue';
72
+ </script>
73
+
74
+ <template>
75
+ <div>
76
+ <SynapseProtect />
77
+ <!-- Component mounts biometric telemetry listeners into this view -->
78
+ </div>
79
+ </template>
80
+ ```
81
+
82
+ ### Automatic Proof-of-Work retry (`submitProtected`)
83
+
84
+ Same API as the React SDK. On HTTP 429 `challenge_required` it fetches a fresh challenge, solves the PoW and retries **once**. A second 429 is returned as is.
85
+
86
+ ```ts
87
+ const { submitProtected } = useSynapseShield();
88
+
89
+ const res = await submitProtected('/api/login', (p) => ({
90
+ username: username.value,
91
+ token: p.token, // canonical body token (or via X-Synapse-Token header; 'synapse_token' alias accepted)
92
+ pow_salt: p.pow_salt, // set only on the retry
93
+ pow_nonce: p.pow_nonce, // read by the server middleware from the top level of the JSON body
94
+ }));
95
+ ```
96
+
97
+ The retry waits 1.6-3 s (up to 8 s only when needed to keep the last 3 mouse points). It then sends the most recent telemetry window the server accepts. A long session is scored on its last few seconds. Tokens only carry events their challenge can vouch for, so long SPA sessions are not rejected as stale. Autofill, paste and IME entry are recorded in `input_events` as `{ t, kind }` only (no content, `key_count` unchanged).
98
+
99
+ ---
100
+
101
+ ## Nuxt 3 (SSR Safe)
102
+
103
+ `synapse-shield-vue` is completely SSR-safe and guards all browser interactions with `onMounted` and `typeof window !== 'undefined'`. No special plugins or SSR flags are required!
104
+
105
+ ```vue
106
+ <!-- pages/login.vue in Nuxt 3 -->
107
+ <script setup>
108
+ import { useSynapseShield } from 'synapse-shield-vue';
109
+
110
+ const { getProtectedPayload } = useSynapseShield();
111
+ // Works automatically on client mount
112
+ </script>
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Features (v0.12.2)
118
+
119
+ - **Universal Keystroke Zero-PII Shield (v0.10.4):** Automatic client-side masking of all single-character inputs (`rawKey.length === 1 -> "masked"`) and sensitive fields, local digraph frequency computation (`is_freq_digraph`), transmitting zero raw text or PII across the wire (GDPR & KVKK compliant).
120
+ - **SPA Token Lifecycle & Coalescing Mutex (v0.10.3):** Single-use challenge token lifecycle invalidation to eliminate 403 Replay Attack loops in Vue 3 and Nuxt applications.
121
+ - **PoW Telemetry Retention (v0.10.3):** Shifts historical telemetry timestamps forward upon PoW challenge retry, eliminating empty telemetry 403 blocks for genuine users.
122
+ - **Mobile SDK v2.0 & Handheld Biometrics (v0.10.0):** Tap hold duration tracking (`tap_duration_ms`), passive 3-axis gyroscope motion variance, and WebGL emulator detection.
123
+ - **Hardened Security Architecture:** Full alignment with Synapse Shield production hardening (Algorithmic DoS mitigation, Rust SIMD differential curvature $\kappa(t)$, zero-copy buffers, and keystroke entropy analysis).
124
+ - **Transparent Token Expiration Refresh:** Seamlessly renegotiates expired tokens (`HTTP 400 EXPIRED`) without triggering IP quarantine or streak bans.
125
+ - **Distributed State & Redis Support:** Full compatibility with Synapse Shield multi-worker cluster deployments.
126
+ - **Transient Iframe Prototype Unhooking:** Detects stealth tools tampering with `Function.prototype.toString`.
127
+ - **Zero-Jank Touch Events:** Passive listeners (`touchstart`, `touchmove`, `touchend`) for high-precision mobile biometrics with zero scroll jank.
128
+ - **Dynamic Yielding PoW Solver:** `solvePow(powSalt, difficulty)` takes the signed `pow_salt` from the server's `challenge_required` response (sha256(salt + nonce), bounded at 20M attempts) and yields to the UI thread every 1,000 iterations to avoid freezing browser rendering. `getProtectedPayload()` consumes the single-use challenge and fetches the next one in the background.
129
+ - **Safe Unicode Base64:** Robust UTF-8 payload encoding across internationalized environments.
130
+ - **Docker Ready Backend:** See the main repository `README.md` for zero-configuration `docker-compose` engine deployment instructions.
131
+
132
+ ## License
133
+
134
+ MIT © Mustafa Güngör
@@ -1,5 +1,5 @@
1
1
  import { defineComponent, h } from 'vue';
2
- import { useSynapseShield } from './useSynapseShield';
2
+ import { useSynapseShield } from './useSynapseShield.js';
3
3
  export const SynapseProtect = defineComponent({
4
4
  name: 'SynapseProtect',
5
5
  props: {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { useSynapseShield } from './useSynapseShield';
2
- export type { SynapseTelemetry, SynapsePayload, UseSynapseShieldOptions, } from './useSynapseShield';
3
- export type { SynapseInputKind } from './timing';
4
- export { SynapseProtect } from './SynapseProtect';
1
+ export { useSynapseShield } from './useSynapseShield.js';
2
+ export type { SynapseTelemetry, SynapsePayload, UseSynapseShieldOptions, } from './useSynapseShield.js';
3
+ export type { SynapseInputKind } from './timing.js';
4
+ export { SynapseProtect } from './SynapseProtect.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { useSynapseShield } from './useSynapseShield';
2
- export { SynapseProtect } from './SynapseProtect';
1
+ export { useSynapseShield } from './useSynapseShield.js';
2
+ export { SynapseProtect } from './SynapseProtect.js';
@@ -1,4 +1,4 @@
1
- import type { SynapseInputKind } from './timing';
1
+ import type { SynapseInputKind } from './timing.js';
2
2
  export interface SynapseTelemetry {
3
3
  mouse_movements: Array<{
4
4
  x: number;
@@ -1,5 +1,5 @@
1
1
  import { ref, onMounted, onBeforeUnmount } from 'vue';
2
- import { MIN_CHALLENGE_AGE_MS, alignForRetry, challengeTimestamp, fitTelemetry, inputEventKind, retryWaitMs, } from './timing';
2
+ import { MIN_CHALLENGE_AGE_MS, alignForRetry, challengeTimestamp, fitTelemetry, inputEventKind, retryWaitMs, } from './timing.js';
3
3
  // Safe UTF-8 Base64 Encoder (SSR Safe)
4
4
  function safeBtoa(str) {
5
5
  try {
@@ -137,6 +137,7 @@ export function useSynapseShield(options = {}) {
137
137
  let lastRawKey = "";
138
138
  // Local time at which the current challenge arrived (its age decides which telemetry the server accepts).
139
139
  let challengeFetchedAt = 0;
140
+ let refreshPromise = null;
140
141
  const fetchChallenge = async () => {
141
142
  if (typeof window === 'undefined')
142
143
  return null;
@@ -153,12 +154,22 @@ export function useSynapseShield(options = {}) {
153
154
  return null;
154
155
  };
155
156
  const refreshChallenge = async () => {
156
- const challenge = await fetchChallenge();
157
- if (challenge) {
158
- currentChallenge.value = challenge;
159
- challengeFetchedAt = Date.now();
160
- }
161
- return challenge;
157
+ if (refreshPromise)
158
+ return refreshPromise;
159
+ refreshPromise = (async () => {
160
+ try {
161
+ const challenge = await fetchChallenge();
162
+ if (challenge) {
163
+ currentChallenge.value = challenge;
164
+ challengeFetchedAt = Date.now();
165
+ }
166
+ return challenge;
167
+ }
168
+ finally {
169
+ refreshPromise = null;
170
+ }
171
+ })();
172
+ return refreshPromise;
162
173
  };
163
174
  /**
164
175
  * Solves the server's proof-of-work: find `nonce` so that sha256(powSalt + nonce) starts with `difficulty`
@@ -265,7 +276,15 @@ export function useSynapseShield(options = {}) {
265
276
  const age = Date.now() - challengeFetchedAt;
266
277
  if (currentChallenge.value && age < MIN_CHALLENGE_AGE_MS)
267
278
  await sleep(MIN_CHALLENGE_AGE_MS - age);
279
+ const hadChallenge = Boolean(currentChallenge.value);
268
280
  const first = await send(getProtectedPayload());
281
+ if (first.status === 503) {
282
+ if (refreshPromise)
283
+ await refreshPromise;
284
+ else if (!hadChallenge && !currentChallenge.value)
285
+ await refreshChallenge();
286
+ return first;
287
+ }
269
288
  if (first.status !== 429) {
270
289
  reset();
271
290
  return first;
@@ -301,6 +320,11 @@ export function useSynapseShield(options = {}) {
301
320
  currentChallenge.value = fresh;
302
321
  challengeFetchedAt = freshAt;
303
322
  const second = await send(getProtectedPayload(solution));
323
+ if (second.status === 503) {
324
+ if (refreshPromise)
325
+ await refreshPromise;
326
+ return second;
327
+ }
304
328
  reset();
305
329
  return second;
306
330
  };
package/package.json CHANGED
@@ -1,44 +1,50 @@
1
- {
2
- "name": "synapse-shield-vue",
3
- "version": "0.12.0",
4
- "description": "Vue 3 and Nuxt 3 integration for Synapse Shield Behavioral Biometrics",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist",
10
- "README.md",
11
- "LICENSE"
12
- ],
13
- "scripts": {
14
- "build": "tsc"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/0xStoic-bit/Synapse_Shield.git",
19
- "directory": "synapse-shield-vue"
20
- },
21
- "bugs": {
22
- "url": "https://github.com/0xStoic-bit/Synapse_Shield/issues"
23
- },
24
- "homepage": "https://github.com/0xStoic-bit/Synapse_Shield/tree/main/synapse-shield-vue#readme",
25
- "keywords": [
26
- "vue",
27
- "vue3",
28
- "nuxt",
29
- "nuxt3",
30
- "synapse-shield",
31
- "bot-protection",
32
- "biometrics",
33
- "anti-bot"
34
- ],
35
- "author": "Mustafa G\u00fcng\u00f6r",
36
- "license": "MIT",
37
- "peerDependencies": {
38
- "vue": ">=3.0.0"
39
- },
40
- "devDependencies": {
41
- "typescript": "^5.0.0",
42
- "vue": "^3.4.0"
43
- }
1
+ {
2
+ "name": "synapse-shield-vue",
3
+ "version": "0.12.2",
4
+ "description": "Vue 3 and Nuxt 3 integration for Synapse Shield Behavioral Biometrics",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/0xStoic-bit/Synapse_Shield.git",
25
+ "directory": "synapse-shield-vue"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/0xStoic-bit/Synapse_Shield/issues"
29
+ },
30
+ "homepage": "https://github.com/0xStoic-bit/Synapse_Shield/tree/main/synapse-shield-vue#readme",
31
+ "keywords": [
32
+ "vue",
33
+ "vue3",
34
+ "nuxt",
35
+ "nuxt3",
36
+ "synapse-shield",
37
+ "bot-protection",
38
+ "biometrics",
39
+ "anti-bot"
40
+ ],
41
+ "author": "Mustafa G\u00fcng\u00f6r",
42
+ "license": "MIT",
43
+ "peerDependencies": {
44
+ "vue": ">=3.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "typescript": "^5.0.0",
48
+ "vue": "^3.4.0"
49
+ }
44
50
  }