1
1
// Base API URL
2
2
const API_BASE_URL = 'https://preview.api.zecrypt.io/api/v1/web' ;
3
3
4
- // Import crypto utilities
4
+ // Import configuration and crypto utilities
5
+ importScripts ( 'config.js' ) ;
5
6
importScripts ( 'crypto-utils.js' ) ;
6
7
8
+ // Initialize configuration when extension starts
9
+ ( async function initializeExtension ( ) {
10
+ try {
11
+ await ExtensionConfig . initConfig ( ) ;
12
+ } catch ( error ) {
13
+ console . error ( 'Failed to load extension configuration:' , error ) ;
14
+ console . error ( 'Please ensure you have created a .env file in the extensions directory with the required keys' ) ;
15
+ }
16
+ } ) ( ) ;
17
+
7
18
// Helper function to check if URL is accessible for script injection
8
19
function isValidUrl ( url ) {
9
20
// Exclude chrome:// URLs, chrome-extension:// URLs, and other restricted schemes
@@ -56,7 +67,6 @@ async function storeProjectAesKey(projectAesKey) {
56
67
chrome . storage . local . set ( {
57
68
zecryptProjectAesKey : encryptedKey
58
69
} ) ;
59
- console . log ( 'Project AES key stored securely' ) ;
60
70
} catch ( error ) {
61
71
console . error ( 'Error storing project AES key:' , error ) ;
62
72
}
@@ -69,7 +79,6 @@ async function getDecryptedProjectAesKey() {
69
79
if ( result . zecryptProjectAesKey ) {
70
80
try {
71
81
const decryptedKey = await CryptoUtils . decryptFromLocalStorage ( result . zecryptProjectAesKey ) ;
72
- console . log ( 'Project AES key retrieved and decrypted' ) ;
73
82
resolve ( decryptedKey ) ;
74
83
} catch ( error ) {
75
84
console . error ( 'Error decrypting project AES key:' , error ) ;
@@ -107,7 +116,6 @@ async function processCardData(cardRaw) {
107
116
const decryptedData = await CryptoUtils . decryptDataField ( cardRaw . data , projectAesKey ) ;
108
117
const parsedData = JSON . parse ( decryptedData ) ;
109
118
110
- console . log ( 'Card data decrypted successfully' ) ;
111
119
return {
112
120
...cardRaw ,
113
121
cardNumber : parsedData . number || 'undefined' ,
@@ -174,8 +182,6 @@ async function processEmailData(emailRaw) {
174
182
const decryptedData = await CryptoUtils . decryptDataField ( emailRaw . data , projectAesKey ) ;
175
183
const parsedData = JSON . parse ( decryptedData ) ;
176
184
177
- console . log ( 'Email data decrypted successfully' ) ;
178
- console . log ( "[Zecrypt Debug] Decrypted Email Password:" , parsedData . password ) ;
179
185
return {
180
186
...emailRaw ,
181
187
email : parsedData . email_address || 'undefined' ,
@@ -192,7 +198,6 @@ async function processEmailData(emailRaw) {
192
198
// Data might not be encrypted (legacy format)
193
199
try {
194
200
const parsedData = JSON . parse ( emailRaw . data ) ;
195
- console . log ( "[Zecrypt Debug] Decrypted Email Password (legacy):" , parsedData . password ) ;
196
201
return {
197
202
...emailRaw ,
198
203
email : parsedData . email_address || 'undefined' ,
@@ -268,7 +273,6 @@ function getCards() {
268
273
apiRequest ( ENDPOINTS . cards )
269
274
. then ( async function ( response ) {
270
275
const cards = response . data || [ ] ;
271
- console . log ( `Processing ${ cards . length } cards for decryption` ) ;
272
276
const processedCards = await Promise . all ( cards . map ( processCardData ) ) ;
273
277
274
278
resolve ( {
@@ -291,7 +295,6 @@ function getEmails() {
291
295
apiRequest ( ENDPOINTS . emails )
292
296
. then ( async function ( response ) {
293
297
const emails = response . data || [ ] ;
294
- console . log ( `Processing ${ emails . length } emails for decryption` ) ;
295
298
const processedEmails = await Promise . all ( emails . map ( processEmailData ) ) ;
296
299
297
300
resolve ( {
@@ -311,7 +314,6 @@ function getEmails() {
311
314
// Enhanced external message listener to handle project AES key
312
315
chrome . runtime . onMessageExternal . addListener (
313
316
( message , sender , sendResponse ) => {
314
- console . log ( 'External message received:' , message ) ;
315
317
if ( message . type === 'LOGIN' && message . token ) {
316
318
// Store the token and workspace/project IDs securely in chrome.storage.local
317
319
chrome . storage . local . set ( {
@@ -323,12 +325,9 @@ chrome.runtime.onMessageExternal.addListener(
323
325
console . error ( 'Error storing tokens:' , chrome . runtime . lastError ) ;
324
326
sendResponse ( { success : false , error : chrome . runtime . lastError . message } ) ;
325
327
} else {
326
- console . log ( 'Token and workspace data stored successfully' ) ;
327
-
328
328
// Store project AES key securely if provided
329
329
if ( message . projectAesKey ) {
330
330
await storeProjectAesKey ( message . projectAesKey ) ;
331
- console . log ( 'Project AES key stored successfully' ) ;
332
331
}
333
332
334
333
sendResponse ( { success : true } ) ;
@@ -372,7 +371,6 @@ function checkLocalStorageAuth() {
372
371
}
373
372
} , ( results ) => {
374
373
if ( chrome . runtime . lastError ) {
375
- console . log ( 'Script execution failed:' , chrome . runtime . lastError . message ) ;
376
374
resolve ( { success : false , error : chrome . runtime . lastError . message } ) ;
377
375
return ;
378
376
}
@@ -389,12 +387,9 @@ function checkLocalStorageAuth() {
389
387
console . error ( 'Error storing auth data:' , chrome . runtime . lastError ) ;
390
388
resolve ( { success : false , error : chrome . runtime . lastError . message } ) ;
391
389
} else {
392
- console . log ( 'Auth data retrieved from localStorage and stored' ) ;
393
-
394
390
// Store project AES key securely if provided
395
391
if ( authData . projectAesKey ) {
396
392
await storeProjectAesKey ( authData . projectAesKey ) ;
397
- console . log ( 'Project AES key from localStorage stored successfully' ) ;
398
393
}
399
394
400
395
resolve ( { success : true , authData } ) ;
@@ -404,7 +399,6 @@ function checkLocalStorageAuth() {
404
399
resolve ( { success : false , error : 'No auth data found' } ) ;
405
400
}
406
401
} ) ; } else {
407
- console . log ( 'No valid tab found for localStorage check. Current tab:' , tabs [ 0 ] ?. url || 'No tab' ) ;
408
402
resolve ( { success : false , error : 'No accessible tab found' } ) ;
409
403
}
410
404
} ) ;
@@ -432,7 +426,6 @@ function startAuthCheck() {
432
426
433
427
// Stop checking after max attempts
434
428
if ( authCheckAttempts > MAX_AUTH_CHECK_ATTEMPTS ) {
435
- console . log ( 'Auth check timeout after' , MAX_AUTH_CHECK_ATTEMPTS , 'attempts' ) ;
436
429
stopAuthCheck ( ) ;
437
430
return ;
438
431
}
@@ -442,18 +435,15 @@ function startAuthCheck() {
442
435
if ( result . success ) {
443
436
clearInterval ( authCheckInterval ) ;
444
437
authCheckInterval = null ;
445
- console . log ( 'Authentication successful via localStorage polling' ) ;
446
438
447
439
// Notify popup if it's open
448
440
try {
449
441
chrome . runtime . sendMessage ( { type : 'AUTH_SUCCESS' } ) ;
450
442
} catch ( e ) {
451
443
// Popup might not be open, that's ok
452
- console . log ( 'Could not notify popup:' , e . message ) ;
453
444
}
454
445
} else if ( result . error && result . error . includes ( 'Cannot access' ) ) {
455
446
// If we get access errors, reduce polling frequency
456
- console . log ( 'Access error during auth check, slowing down polling' ) ;
457
447
}
458
448
} catch ( error ) {
459
449
console . error ( 'Error during auth check:' , error ) ;
@@ -491,10 +481,8 @@ function checkAuth() {
491
481
492
482
// Listen for messages from popup or content scripts
493
483
chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
494
- console . log ( 'Internal message received:' , message ) ;
495
484
if ( message . type === 'CHECK_AUTH' ) {
496
485
checkAuth ( ) . then ( result => {
497
- console . log ( 'Auth check result:' , result ) ;
498
486
499
487
// If not authenticated, try checking localStorage as fallback
500
488
if ( ! result . isAuthenticated ) {
@@ -509,8 +497,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
509
497
// Only start periodic checking if we don't have access errors
510
498
if ( ! localResult . error || ! localResult . error . includes ( 'Cannot access' ) ) {
511
499
startAuthCheck ( ) ;
512
- } else {
513
- console . log ( 'Skipping periodic auth check due to access restrictions' ) ;
514
500
}
515
501
}
516
502
} ) ;
@@ -541,10 +527,9 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
541
527
}
542
528
// Handle logout request
543
529
if ( message . type === 'LOGOUT' ) {
544
- chrome . storage . local . remove ( [ 'zecryptToken' , 'zecryptWorkspaceId' , 'zecryptProjectId' , 'zecryptProjectAesKey' ] , ( ) => {
545
- console . log ( 'Tokens and project key removed' ) ;
546
- sendResponse ( { success : true } ) ;
547
- } ) ;
530
+ chrome . storage . local . remove ( [ 'zecryptToken' , 'zecryptWorkspaceId' , 'zecryptProjectId' , 'zecryptProjectAesKey' ] , ( ) => {
531
+ sendResponse ( { success : true } ) ;
532
+ } ) ;
548
533
return true ;
549
534
}
550
535
@@ -555,12 +540,9 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
555
540
zecryptWorkspaceId : message . workspaceId ,
556
541
zecryptProjectId : message . projectId
557
542
} , async ( ) => {
558
- console . log ( 'Token and workspace data stored successfully from popup' ) ;
559
-
560
543
// Store project AES key securely if provided
561
544
if ( message . projectAesKey ) {
562
545
await storeProjectAesKey ( message . projectAesKey ) ;
563
- console . log ( 'Project AES key stored successfully from popup' ) ;
564
546
}
565
547
566
548
sendResponse ( { success : true } ) ;
@@ -630,5 +612,5 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
630
612
631
613
// Initialize when the extension is installed or updated
632
614
chrome . runtime . onInstalled . addListener ( ( ) => {
633
- console . log ( 'Zecrypt extension installed' ) ;
615
+ // Extension installed
634
616
} ) ;
0 commit comments