# WCAHT Wallet — Browser Extension

A browser wallet extension for WCAHT universal accounts. New wallets use secp256k1 and show both a WCAHT base58 address and a paired EVM `0x...` address from the same private key. Legacy Ed25519/base58 wallets can still be imported and used.

For external EVM tools, WCAHT is chain ID `7789`. This extension exposes the paired `0x...` address for dashboard login, receive/copy, balance display, and WCAHT transfers to base58 or EVM recipients. It does not replace a full Ethereum provider like `window.ethereum` for contract tooling.

## Features

- **Create & Import** universal secp256k1 wallets, EVM private keys, and legacy Ed25519 keypairs
- **Send & Receive** WCAHT to base58 or EVM `0x...` addresses
- **AES-GCM encrypted** key storage (PBKDF2 derived)
- **dApp Provider** — injects `window.wcaht` for web apps
- **Multi-wallet** support with easy switching
- **Live balance** & node status polling
- **Dark theme** UI

## Install (Chrome / Edge / Brave / Opera)

1. Open your browser and navigate to the extensions page:
   - **Chrome**: `chrome://extensions`
   - **Edge**: `edge://extensions`
   - **Brave**: `brave://extensions`
   - **Opera**: `opera://extensions`
2. Enable **Developer mode** (toggle in the top-right corner).
3. Click **Load unpacked**.
4. Select the `wcaht-wallet-extension` folder.
5. The WCAHT Wallet icon appears in your toolbar.

## Install (Firefox)

1. Open `about:debugging#/runtime/this-firefox`
2. Click **Load Temporary Add-on…**
3. Select any file inside `wcaht-wallet-extension` (e.g., `manifest.json`).
4. The extension loads temporarily (reloads required after browser restart).

> **Note:** For permanent Firefox installation, the extension needs to be signed via [addons.mozilla.org](https://addons.mozilla.org).

## First-Time Setup

1. Click the WCAHT Wallet icon in your toolbar.
2. Create a password (minimum 6 characters). This encrypts your keys locally.
3. Click **Create Universal Wallet** or **Import Wallet**.
   - To import an EVM account, paste a `0x` private key or `secp256k1:<key>`.
   - To import a legacy account, paste the Ed25519 base58/hex/JSON key.
4. Your balance loads automatically if a WCAHT node is running.

## Configuration

By default the extension connects to the public WCAHT RPC configured in `background/service-worker.js`. To change:

- Use the **network dropdown** in the header, or
- Go to **Settings → Custom RPC URL** and enter your node address.

## dApp Integration

Web applications can interact with the wallet via the injected `window.wcaht` provider:

```javascript
// Check if the WCAHT wallet is installed
if (window.wcaht) {
  // Connect
  const { address, publicKey, addressType, evmAddress } = await window.wcaht.connect();
  console.log('Connected account:', address, publicKey, addressType, evmAddress);

  // Get balance
  const balance = await window.wcaht.getBalance();

  // Send transaction
  const { txHash } = await window.wcaht.sendTransaction(
    'RecipientBase58Or0xAddress...',
    1.5  // amount in WCAHT
  );

  // Listen for events
  window.wcaht.on('connect', ({ address, publicKey, addressType, evmAddress }) => { /* ... */ });
  window.wcaht.on('disconnect', () => { /* ... */ });
}
```

`address` is the preferred account identifier: the paired EVM `0x...` address for universal wallets, otherwise the legacy base58 address. `publicKey` is always the WCAHT base58 form, and `evmAddress` is present for universal secp256k1 wallets.

## File Structure

```
wcaht-wallet-extension/
├── manifest.json              # MV3 extension manifest
├── background/
│   └── service-worker.js      # Key management, signing, RPC
├── popup/
│   ├── popup.html             # Wallet UI
│   ├── popup.css              # Dark theme styles
│   └── popup.js               # UI logic
├── content/
│   ├── content-script.js      # Bridge (page ↔ background)
│   └── inject.js              # window.wcaht provider
├── lib/
│   ├── crypto.js              # Ed25519, Base58, TX builder
│   ├── nacl-fast.min.js       # tweetnacl (Ed25519 crypto)
│   └── wcaht-evm.min.js       # secp256k1 + keccak bundle
├── icons/
│   ├── icon16.png
│   ├── icon48.png
│   ├── icon128.png
│   └── icon.svg
└── README.md
```

## Security

- Private keys are AES-GCM encrypted with a PBKDF2-derived key (100k iterations).
- Keys only exist in memory while the wallet is unlocked.
- The password is never stored — only used to derive the encryption key.
- Auto-locks after browser restart.

## Denomination

- **1 WCAHT = 1,000,000,000 kak** (1e9)
- Default network fee: 5,000 kak (0.000005 WCAHT)
