|
| 1 | +// Firebird Background Service Worker |
| 2 | +// φ² + 1/φ² = 3 = TRINITY |
| 3 | + |
| 4 | +const PHI = 1.6180339887; |
| 5 | +const TRINITY = 3.0; |
| 6 | + |
| 7 | +// Firebird state |
| 8 | +let firebirdState = { |
| 9 | + enabled: true, |
| 10 | + similarity: 0.85, |
| 11 | + fingerprint: null, |
| 12 | + lastEvolution: null |
| 13 | +}; |
| 14 | + |
| 15 | +// Initialize on install |
| 16 | +chrome.runtime.onInstalled.addListener(async () => { |
| 17 | + console.log('🔥 Firebird Anti-Detect installed'); |
| 18 | + console.log(`φ² + 1/φ² = ${PHI * PHI + 1 / (PHI * PHI)} = TRINITY`); |
| 19 | + |
| 20 | + // Load saved state |
| 21 | + const result = await chrome.storage.local.get(['firebirdState']); |
| 22 | + if (result.firebirdState) { |
| 23 | + firebirdState = { ...firebirdState, ...result.firebirdState }; |
| 24 | + } |
| 25 | + |
| 26 | + // Generate initial fingerprint |
| 27 | + if (!firebirdState.fingerprint) { |
| 28 | + firebirdState.fingerprint = generateFingerprint(); |
| 29 | + await saveState(); |
| 30 | + } |
| 31 | +}); |
| 32 | + |
| 33 | +// Message handler |
| 34 | +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { |
| 35 | + handleMessage(message, sender).then(sendResponse); |
| 36 | + return true; // Keep channel open for async response |
| 37 | +}); |
| 38 | + |
| 39 | +async function handleMessage(message, sender) { |
| 40 | + switch (message.action) { |
| 41 | + case 'evolve': |
| 42 | + return await evolveFingerprint(message.targetSimilarity || 0.85); |
| 43 | + |
| 44 | + case 'getState': |
| 45 | + return firebirdState; |
| 46 | + |
| 47 | + case 'getFingerprint': |
| 48 | + return firebirdState.fingerprint; |
| 49 | + |
| 50 | + case 'setState': |
| 51 | + firebirdState = { ...firebirdState, ...message.state }; |
| 52 | + await saveState(); |
| 53 | + return { success: true }; |
| 54 | + |
| 55 | + default: |
| 56 | + return { error: 'Unknown action' }; |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// Generate ternary fingerprint vector |
| 61 | +function generateFingerprint(dim = 1000) { |
| 62 | + const trits = new Int8Array(dim); |
| 63 | + for (let i = 0; i < dim; i++) { |
| 64 | + const r = Math.random(); |
| 65 | + if (r < 0.333) trits[i] = -1; |
| 66 | + else if (r < 0.666) trits[i] = 0; |
| 67 | + else trits[i] = 1; |
| 68 | + } |
| 69 | + return { |
| 70 | + trits: Array.from(trits), |
| 71 | + dim: dim, |
| 72 | + created: Date.now() |
| 73 | + }; |
| 74 | +} |
| 75 | + |
| 76 | +// Evolve fingerprint towards human-like pattern |
| 77 | +async function evolveFingerprint(targetSimilarity) { |
| 78 | + const dim = firebirdState.fingerprint?.dim || 1000; |
| 79 | + const humanPattern = generateHumanPattern(dim); |
| 80 | + |
| 81 | + let currentFp = firebirdState.fingerprint?.trits || generateFingerprint(dim).trits; |
| 82 | + let similarity = cosineSimilarity(currentFp, humanPattern); |
| 83 | + |
| 84 | + const maxGenerations = 50; |
| 85 | + const guideRate = 0.9; |
| 86 | + |
| 87 | + for (let gen = 0; gen < maxGenerations; gen++) { |
| 88 | + if (similarity >= targetSimilarity) break; |
| 89 | + |
| 90 | + // Guided mutation: move towards human pattern |
| 91 | + const newFp = new Int8Array(dim); |
| 92 | + for (let i = 0; i < dim; i++) { |
| 93 | + if (Math.random() < guideRate) { |
| 94 | + newFp[i] = humanPattern[i]; |
| 95 | + } else if (Math.random() < 0.3) { |
| 96 | + newFp[i] = currentFp[i]; |
| 97 | + } else { |
| 98 | + // Random trit |
| 99 | + const r = Math.random(); |
| 100 | + if (r < 0.333) newFp[i] = -1; |
| 101 | + else if (r < 0.666) newFp[i] = 0; |
| 102 | + else newFp[i] = 1; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + const newSim = cosineSimilarity(Array.from(newFp), humanPattern); |
| 107 | + if (newSim > similarity) { |
| 108 | + currentFp = Array.from(newFp); |
| 109 | + similarity = newSim; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + firebirdState.fingerprint = { |
| 114 | + trits: currentFp, |
| 115 | + dim: dim, |
| 116 | + created: Date.now() |
| 117 | + }; |
| 118 | + firebirdState.similarity = similarity; |
| 119 | + firebirdState.lastEvolution = Date.now(); |
| 120 | + |
| 121 | + await saveState(); |
| 122 | + |
| 123 | + // Notify all tabs |
| 124 | + notifyAllTabs(); |
| 125 | + |
| 126 | + return { |
| 127 | + success: true, |
| 128 | + similarity: similarity, |
| 129 | + generations: maxGenerations |
| 130 | + }; |
| 131 | +} |
| 132 | + |
| 133 | +// Generate human-like pattern (seeded for consistency) |
| 134 | +function generateHumanPattern(dim) { |
| 135 | + const pattern = new Int8Array(dim); |
| 136 | + // Use φ-based seed for reproducibility |
| 137 | + let seed = PHI * 1000000; |
| 138 | + |
| 139 | + for (let i = 0; i < dim; i++) { |
| 140 | + seed = (seed * 1103515245 + 12345) % 2147483648; |
| 141 | + const r = (seed / 2147483648); |
| 142 | + if (r < 0.333) pattern[i] = -1; |
| 143 | + else if (r < 0.666) pattern[i] = 0; |
| 144 | + else pattern[i] = 1; |
| 145 | + } |
| 146 | + |
| 147 | + return Array.from(pattern); |
| 148 | +} |
| 149 | + |
| 150 | +// Cosine similarity for ternary vectors |
| 151 | +function cosineSimilarity(a, b) { |
| 152 | + let dot = 0; |
| 153 | + let normA = 0; |
| 154 | + let normB = 0; |
| 155 | + |
| 156 | + for (let i = 0; i < a.length; i++) { |
| 157 | + dot += a[i] * b[i]; |
| 158 | + normA += a[i] * a[i]; |
| 159 | + normB += b[i] * b[i]; |
| 160 | + } |
| 161 | + |
| 162 | + if (normA === 0 || normB === 0) return 0; |
| 163 | + return dot / (Math.sqrt(normA) * Math.sqrt(normB)); |
| 164 | +} |
| 165 | + |
| 166 | +// Save state to storage |
| 167 | +async function saveState() { |
| 168 | + await chrome.storage.local.set({ firebirdState }); |
| 169 | +} |
| 170 | + |
| 171 | +// Notify all tabs of state change |
| 172 | +async function notifyAllTabs() { |
| 173 | + const tabs = await chrome.tabs.query({}); |
| 174 | + for (const tab of tabs) { |
| 175 | + try { |
| 176 | + await chrome.tabs.sendMessage(tab.id, { |
| 177 | + action: 'fingerprintUpdated', |
| 178 | + fingerprint: firebirdState.fingerprint, |
| 179 | + similarity: firebirdState.similarity |
| 180 | + }); |
| 181 | + } catch (e) { |
| 182 | + // Tab might not have content script |
| 183 | + } |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +// Periodic evolution check (auto-evolve) |
| 188 | +chrome.alarms.create('autoEvolve', { periodInMinutes: 30 }); |
| 189 | + |
| 190 | +chrome.alarms.onAlarm.addListener(async (alarm) => { |
| 191 | + if (alarm.name === 'autoEvolve') { |
| 192 | + const result = await chrome.storage.local.get(['firebirdState']); |
| 193 | + if (result.firebirdState?.autoEvolve) { |
| 194 | + console.log('🔥 Auto-evolving fingerprint...'); |
| 195 | + await evolveFingerprint(0.85); |
| 196 | + } |
| 197 | + } |
| 198 | +}); |
| 199 | + |
| 200 | +console.log('🔥 Firebird service worker started'); |
0 commit comments