- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
API Documentation
        SecureBitChat edited this page Aug 18, 2025 
        ·
        1 revision
      
    Creates a new P2P connection.
Parameters:
- 
config(Object): Connection configuration- 
iceServers(Array): STUN/TURN servers - 
timeout(Number): Connection timeout in ms 
 - 
 
Returns: Promise
Example:
#### `generateKeyPair()`
Generates a new ECDH key pair.
**Returns:** Promise<CryptoKeyPair>
#### `encryptMessage(message, key)`
Encrypts a message using AES-GCM.
**Parameters:**
- `message` (String): Message to encrypt
- `key` (CryptoKey): Encryption key
**Returns:** Promise<Object> - { encrypted, iv }
#### `decryptMessage(encrypted, key, iv)`
Decrypts a message using AES-GCM.
**Parameters:**
- `encrypted` (ArrayBuffer): Encrypted data
- `key` (CryptoKey): Decryption key
- `iv` (Uint8Array): Initialization vector
**Returns:** Promise<String>
### Payment API
#### `createSession(type)`
Creates a new payment session.
**Parameters:**
- `type` (String): 'demo', 'basic', or 'premium'
**Returns:** Promise<Session>
#### `processPayment(invoice)`
Processes Lightning Network payment.
**Parameters:**
- `invoice` (String): Lightning invoice
**Returns:** Promise<PaymentResult>
## π§ Configuration API
### `configure(options)`
Configures SecureBit.chat instance.
**Parameters:**
- `options` (Object): Configuration options
  - `lightningNode` (String): Lightning node URL
  - `stunServers` (Array): STUN server URLs
  - `turnServers` (Array): TURN server URLs
  - `sessionTimeout` (Number): Session timeout in ms
**Example:**
```javascript
configure({
  lightningNode: 'https://your-node.com',
  stunServers: ['stun:stun.l.google.com:19302'],
  sessionTimeout: 3600000
});
Fired when connection is established.
Fired when message is received.
Fired when payment is processed.
Fired when error occurs.
Example:
on('connection', (connection) => {
  console.log('Connected:', connection.id);
});
on('message', (message) => {
  console.log('Received:', message.text);
});- 
ConnectionError: Connection-related errors - 
CryptoError: Cryptographic operation errors - 
PaymentError: Payment processing errors - 
SessionError: Session management errors 
try {
  const connection = await createConnection(config);
} catch (error) {
  if (error instanceof ConnectionError) {
    console.error('Connection failed:', error.message);
  } else if (error instanceof CryptoError) {
    console.error('Crypto error:', error.message);
  }
}