You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

5.3 KiB

Safari Notifications Module

A specialized JavaScript module designed to handle secure notifications for Safari browser extensions and Progressive Web Applications (PWAs). This module abstracts the complex cryptographic operations and IndexedDB interactions required for secure notification processing in browser worker contexts.

Overview

This project was created to separate the PWA build process from the main application, specifically addressing the need to make JavaScript code compatible with browser worker processes. The module provides secure authentication, data encryption/decryption, and notification counting functionality for Safari-based applications.

Features

🔐 Cryptographic Operations

  • JWT Token Generation: Creates secure access tokens using ES256K signing
  • Message Encryption/Decryption: Uses NaCl (TweetNaCl) for secure message handling
  • Digital Signatures: Implements ECDSA signatures with secp256k1 curve
  • Hash Functions: SHA-256 hashing for data integrity

💾 Data Management

  • IndexedDB Integration: Secure storage for settings, accounts, and contacts
  • Local Storage: Encrypted secret management
  • Database Operations: CRUD operations for user data

🔔 Notification System

  • Secure API Communication: Authenticated requests to external notification services
  • Notification Counting: Retrieves and processes notification data
  • DID-based Authentication: Decentralized identifier support

Architecture

Core Components

  1. Cryptographic Utilities (src/safari-notifications.js)

    • JWT creation and signing
    • Message encryption/decryption
    • Digital signature generation
    • Encoding/decoding utilities
  2. Data Access Layer

    • IndexedDB operations for settings, accounts, and contacts
    • Local storage management
    • Promise-based async operations
  3. Notification Service

    • Secure API communication
    • Authentication token management
    • Notification data processing

Build Configuration

The project uses Webpack with specific configurations for browser worker compatibility:

  • Target: webworker - Optimized for service worker contexts
  • Library Target: self - Exports to global scope
  • Mode: production - Optimized for deployment
  • Fallbacks: Crypto module disabled for browser compatibility

Installation

npm install

Dependencies

  • @noble/curves: Cryptographic curve operations (secp256k1)
  • @noble/hashes: Hash function implementations (SHA-256)
  • tweetnacl: High-security cryptographic library
  • tweetnacl-util: Utility functions for TweetNaCl
  • webpack: Module bundler
  • webpack-cli: Webpack command line interface

Usage

Building the Module

npm run build

This creates a bundled JavaScript file in the dist/ directory optimized for browser worker contexts.

Integration

// Import the module in your service worker or web worker
importScripts('./dist/safari-notifications.js');

// Use the exported functions
const notificationCount = await getNotificationCount();

API Reference

getNotificationCount()

Retrieves the notification count for the active DID (Decentralized Identifier).

Returns: Promise