|
| 1 | +# Webizen API Specification v0.25 |
| 2 | + |
| 3 | +This document provides a detailed specification for the Webizen API and its core modules. The API is designed to be modular, secure, and extensible, providing a foundation for a decentralized social-web experience. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Webizen API (`services/webizen-api.js`)](#webizen-api-serviceswebizen-apijs) |
| 8 | + - Architecture |
| 9 | + - Message Format |
| 10 | + - Endpoints |
| 11 | +- Security Module (`modules/security/index.js`) |
| 12 | + - SPHINCS+ |
| 13 | + - ECDSA |
| 14 | + - RSA |
| 15 | + - AES |
| 16 | + - Ed25519 |
| 17 | +- Cashtab Module (`modules/cashtab/index.js`) |
| 18 | +- Access Control Module (`modules/access/index.js`) |
| 19 | +- ADP & Mobile Modules |
| 20 | + - ADP Manager (`modules/adp/index.js`) |
| 21 | + - Mobile Manager (`modules/mobile/index.js`) |
| 22 | +- P2P Modules |
| 23 | +- Shared Services |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Webizen API (`services/webizen-api.js`) |
| 28 | + |
| 29 | +The Webizen API is the central nervous system of the application, providing REST-like endpoints over a secure WebSocket connection. |
| 30 | + |
| 31 | +### Architecture |
| 32 | + |
| 33 | +- **Transport**: Secure WebSockets (WSS). |
| 34 | +- **Security**: All messages are intended to be signed. The API includes rate-limiting to prevent abuse. |
| 35 | + |
| 36 | +### Message Format |
| 37 | + |
| 38 | +All communication with the API is done via JSON objects with the following structure: |
| 39 | + |
| 40 | +```json |
| 41 | +{ |
| 42 | + "endpoint": "/path/to/resource", |
| 43 | + "payload": { ... }, |
| 44 | + "signature": "..." |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Endpoints |
| 49 | + |
| 50 | +| Endpoint | Payload | Description | |
| 51 | +| :--- | :--- | :--- | |
| 52 | +| `/modules/register` | `{ "name": "moduleName", ... }` | Registers a new module with the API. | |
| 53 | +| `/modules/unregister` | `{ "name": "moduleName" }` | Unregisters an existing module. | |
| 54 | +| `/resources/load` | `{ "url": "resource/url" }` | Requests the loading of a specified resource. | |
| 55 | +| `/ai/query` | `{ "model": "modelName", "prompt": "..." }` | Sends a query to the specified AI model. | |
| 56 | +| `/sync/data` | `{ "source": "...", "data": { ... } }` | Requests data synchronization from a source. | |
| 57 | +| `/work/create` | `{ "type": "task", "details": { ... } }` | Creates a new work item (e.g., a task or project). | |
| 58 | +| `/email/respond` | `{ "messageId": "...", "response": "..." }` | Sends a response to an email. | |
| 59 | +| `/health` | `{}` | Checks the health of the API and its critical services. | |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Security Module (`modules/security/index.js`) |
| 64 | + |
| 65 | +The `SecurityManager` provides a unified interface for all cryptographic operations. |
| 66 | + |
| 67 | +### SPHINCS+ |
| 68 | + |
| 69 | +- `signWithSphincs(data)`: Signs data using SPHINCS+. |
| 70 | + - **data**: `string` - The data to sign. |
| 71 | + - **Returns**: `Promise<string>` - The signature. |
| 72 | +- `verifyWithSphincs(data, signature)`: Verifies a SPHINCS+ signature. |
| 73 | + - **Returns**: `Promise<boolean>` |
| 74 | + |
| 75 | +### ECDSA |
| 76 | + |
| 77 | +- `signWithEcdsa(data, privateKey)`: Signs data using ECDSA, typically for Bitcoin-related operations. |
| 78 | + - **Returns**: `Promise<string>` |
| 79 | +- `verifyWithEcdsa(data, signature, publicKey)`: Verifies an ECDSA signature. |
| 80 | + - **Returns**: `Promise<boolean>` |
| 81 | + |
| 82 | +### RSA |
| 83 | + |
| 84 | +- `encryptWithRsa(data, publicKey)`: Encrypts data using RSA. |
| 85 | + - **Returns**: `Promise<string>` |
| 86 | +- `decryptWithRsa(encryptedData, privateKey)`: Decrypts data using RSA. |
| 87 | + - **Returns**: `Promise<string>` |
| 88 | + |
| 89 | +### AES |
| 90 | + |
| 91 | +- `encryptWithAes(data, key)`: Encrypts data using AES. |
| 92 | + - **Returns**: `Promise<string>` |
| 93 | +- `decryptWithAes(encryptedData, key)`: Decrypts data using AES. |
| 94 | + - **Returns**: `Promise<string>` |
| 95 | + |
| 96 | +### Ed25519 |
| 97 | + |
| 98 | +- `signWithEd25519(data, privateKey)`: Signs data using Ed25519. |
| 99 | + - **Returns**: `Promise<string>` |
| 100 | +- `verifyWithEd25519(data, signature, publicKey)`: Verifies an Ed25519 signature. |
| 101 | + - **Returns**: `Promise<boolean>` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## Cashtab Module (`modules/cashtab/index.js`) |
| 106 | + |
| 107 | +The `CashtabManager` handles all eCash (XEC) and SLP token functionalities. |
| 108 | + |
| 109 | +- `createWallet(options)`: Creates or imports a wallet. |
| 110 | + - **options**: `object` - Wallet options (e.g., name, seed phrase). |
| 111 | + - **Returns**: `string` - The unique wallet ID. |
| 112 | +- `createMultiSigAddress(walletId, requiredSigners, publicKeys)`: Generates a multi-signature wallet address. |
| 113 | + - **Returns**: `string` - The multi-sig address. |
| 114 | +- `validateSLPToken(tokenId)`: Validates an SLP token. |
| 115 | + - **Returns**: `Promise<boolean>` |
| 116 | +- `createAndSignTransaction(transactionDetails, privateKey)`: Creates and signs a transaction using ECDSA via the `SecurityManager`. |
| 117 | + - **Returns**: `Promise<string>` - The signed transaction hex. |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Access Control Module (`modules/access/index.js`) |
| 122 | + |
| 123 | +The `AccessManager` controls access to Webizen features. |
| 124 | + |
| 125 | +- `grantAccess(walletId, slpTokenId)`: The main access control function. It checks eCash balance or validates an SLP token. If the balance is high, it triggers a payment. |
| 126 | + - **walletId**: `string` |
| 127 | + - **slpTokenId**: `string` (optional) |
| 128 | + - **Returns**: `Promise<boolean>` - `true` if access is granted. |
| 129 | +- `checkBalance(walletId)`: Checks the balance of a given wallet. |
| 130 | + - **Returns**: `Promise<number>` |
| 131 | +- `processPayment(walletId, amount)`: Processes a payment with retry logic. |
| 132 | + - **Returns**: `Promise<boolean>` |
| 133 | +- `trackObligationCost(walletId, serviceName, cost)`: Tracks the cost of a service and creates a signed audit trail entry in Quadstore. |
| 134 | + - **Returns**: `Promise<void>` |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## ADP & Mobile Modules |
| 139 | + |
| 140 | +These modules handle decentralized identity and mobile-specific features. |
| 141 | + |
| 142 | +### ADP Manager (`modules/adp/index.js`) |
| 143 | + |
| 144 | +- `verifyDomain(domain)`: Fetches and verifies an eCash address from a domain's DNS TXT records. Includes a retry mechanism for transient DNS errors. |
| 145 | + - **domain**: `string` - The domain to verify. |
| 146 | + - **Returns**: `Promise<object|null>` - An object with `{ domain, ecashAddress }` or `null`. |
| 147 | + |
| 148 | +### Mobile Manager (`modules/mobile/index.js`) |
| 149 | + |
| 150 | +- `verifyCall(callerId)`: Verifies an incoming call using ADP/WebID. |
| 151 | + - **callerId**: `string` - The caller's identifier (domain or phone number). |
| 152 | + - **Returns**: `Promise<{verified: boolean, details: string}>` - The verification status. |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## P2P Modules |
| 157 | + |
| 158 | +These modules provide the foundation for decentralized communication and data transfer. |
| 159 | + |
| 160 | +- **WebTorrentManager (`modules/webtorrent/index.js`)**: Handles WebTorrent-based P2P file sharing. |
| 161 | +- **GunManager (`modules/gun/index.js`)**: Manages real-time, decentralized data synchronization using GUN. |
| 162 | +- **WebRTCManager (`modules/webrtc/index.js`)**: Manages WebRTC connections for real-time communication. |
| 163 | +- **WebSocketsManager (`modules/websockets/index.js`)**: Manages WebSocket connections for the Webizen API. |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Shared Services |
| 168 | + |
| 169 | +These services provide common functionalities used across the application. |
| 170 | + |
| 171 | +- **LoggingService (`services/logging.js`)**: Handles structured logging with support for exporting to Quadstore and IPFS. |
| 172 | +- **QuadstoreService (`services/quadstore.js`)**: Manages the RDF Quadstore for semantic data storage. |
| 173 | +- **PermissionsService (`services/permissions.js`)**: Manages user permissions for various features. |
| 174 | +- **ModuleManager (`services/moduleManager.js`)**: Handles the lifecycle of application modules. |
| 175 | +- **ConfigService (`services/config.js`)**: Provides access to the application's configuration. |
| 176 | +- **EventBus (`services/eventBus.js`)**: A simple event bus for inter-module communication. |
| 177 | + |
0 commit comments