@spritz-finance/context-browser 0.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/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @spritz-finance/context-browser
2
+
3
+ Browser SDK for device context headers.
4
+
5
+ ## Usage
6
+
7
+ ```typescript
8
+ import { createContext } from '@spritz-finance/context-browser';
9
+
10
+ const ctx = createContext({ sandbox: true }); // or omit for prod
11
+ await ctx.init();
12
+
13
+ // Add to fetch requests
14
+ fetch('/api/endpoint', {
15
+ headers: {
16
+ ...ctx.getHeader(), // { 'x-meta-sess': '...' }
17
+ },
18
+ });
19
+ ```
20
+
21
+ ## API
22
+
23
+ ```typescript
24
+ const ctx = createContext(config?)
25
+ ```
26
+
27
+ | Config | Type | Default | Description |
28
+ |--------|------|---------|-------------|
29
+ | `sandbox` | `boolean` | `false` | Use sandbox keys |
30
+ | `debug` | `boolean` | `false` | Log to console |
31
+ | `signals.canvas` | `boolean` | `true` | Collect canvas hash |
32
+ | `signals.webgl` | `boolean` | `true` | Collect WebGL renderer |
33
+
34
+ ```typescript
35
+ await ctx.init() // Initialize (required before use)
36
+ ctx.getHeader() // Returns { 'x-meta-sess': string } or {}
37
+ ctx.getClaimedId() // Returns persistent device ID
38
+ ctx.isReady() // Returns true after init
39
+ await ctx.recompute() // Refresh signals (called automatically every 5min)
40
+ ```
41
+
42
+ ## Payload Structure
43
+
44
+ After decrypting `x-meta-sess`, backend receives:
45
+
46
+ ```typescript
47
+ {
48
+ timestamp: number,
49
+ nonce: string,
50
+ identifiers: {
51
+ claimed_id: string, // Persistent device ID
52
+ actual_fp: string, // Signal hash
53
+ },
54
+ signals: {
55
+ screen, timezone, language, platform, cores, memory,
56
+ canvas, webgl, // Hashed/raw values
57
+ automation: { // Bot detection
58
+ webdriver, chromePresent, pluginCount,
59
+ phantomjs, selenium, playwright, puppeteer,
60
+ headlessUA, nativeFnTampered
61
+ },
62
+ _meta: { // Collection diagnostics
63
+ [signal]: { status: 'ok'|'blocked'|'errored', ms?, error? }
64
+ }
65
+ },
66
+ storage: { // ID storage consistency
67
+ sources: ['local'|'session'|'cookie'][],
68
+ allMatch: boolean,
69
+ divergent?: Record<string, string>
70
+ }
71
+ }
72
+ ```