mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-13 20:33:25 +00:00
Implement crypto adapter pattern for platform independence
Adds CryptoAdapter interface with WebCryptoAdapter (browser) and
NodeCryptoAdapter (Node.js 19+) implementations.
Changes:
- Created crypto-adapter.ts interface
- Created web-crypto-adapter.ts for browser environments
- Created node-crypto-adapter.ts for Node.js environments
- Updated RondevuAPI to accept optional CryptoAdapter
- Updated Rondevu class to pass crypto adapter through
- Exported adapters and types in index.ts
- Updated README with platform support documentation
- Bumped version to 0.15.0
This allows the client library to work in both browser and Node.js
environments by providing platform-specific crypto implementations.
Example usage in Node.js:
import { Rondevu, NodeCryptoAdapter } from '@xtr-dev/rondevu-client'
const rondevu = new Rondevu({
apiUrl: 'https://api.ronde.vu',
cryptoAdapter: new NodeCryptoAdapter()
})
🤖 Generated with Claude Code
https://claude.com/claude-code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
59
README.md
59
README.md
@@ -202,9 +202,62 @@ Main class for all Rondevu operations.
|
||||
import { Rondevu } from '@xtr-dev/rondevu-client'
|
||||
|
||||
const rondevu = new Rondevu({
|
||||
apiUrl: string, // Signaling server URL
|
||||
username?: string, // Optional: your username (auto-generates anonymous if omitted)
|
||||
keypair?: Keypair // Optional: reuse existing keypair
|
||||
apiUrl: string, // Signaling server URL
|
||||
username?: string, // Optional: your username (auto-generates anonymous if omitted)
|
||||
keypair?: Keypair, // Optional: reuse existing keypair
|
||||
cryptoAdapter?: CryptoAdapter // Optional: platform-specific crypto (defaults to WebCryptoAdapter)
|
||||
})
|
||||
```
|
||||
|
||||
#### Platform Support (Browser & Node.js)
|
||||
|
||||
The client supports both browser and Node.js environments using crypto adapters:
|
||||
|
||||
**Browser (default):**
|
||||
```typescript
|
||||
import { Rondevu } from '@xtr-dev/rondevu-client'
|
||||
|
||||
// WebCryptoAdapter is used by default - no configuration needed
|
||||
const rondevu = new Rondevu({
|
||||
apiUrl: 'https://api.ronde.vu',
|
||||
username: 'alice'
|
||||
})
|
||||
```
|
||||
|
||||
**Node.js (19+ or 18 with --experimental-global-webcrypto):**
|
||||
```typescript
|
||||
import { Rondevu, NodeCryptoAdapter } from '@xtr-dev/rondevu-client'
|
||||
|
||||
const rondevu = new Rondevu({
|
||||
apiUrl: 'https://api.ronde.vu',
|
||||
username: 'alice',
|
||||
cryptoAdapter: new NodeCryptoAdapter()
|
||||
})
|
||||
|
||||
await rondevu.initialize()
|
||||
```
|
||||
|
||||
**Note:** Node.js support requires:
|
||||
- Node.js 19+ (crypto.subtle available globally), OR
|
||||
- Node.js 18 with `--experimental-global-webcrypto` flag
|
||||
- WebRTC implementation like `wrtc` or `node-webrtc` for RTCPeerConnection
|
||||
|
||||
**Custom Crypto Adapter:**
|
||||
```typescript
|
||||
import { CryptoAdapter, Keypair } from '@xtr-dev/rondevu-client'
|
||||
|
||||
class CustomCryptoAdapter implements CryptoAdapter {
|
||||
async generateKeypair(): Promise<Keypair> { /* ... */ }
|
||||
async signMessage(message: string, privateKey: string): Promise<string> { /* ... */ }
|
||||
async verifySignature(message: string, signature: string, publicKey: string): Promise<boolean> { /* ... */ }
|
||||
bytesToBase64(bytes: Uint8Array): string { /* ... */ }
|
||||
base64ToBytes(base64: string): Uint8Array { /* ... */ }
|
||||
randomBytes(length: number): Uint8Array { /* ... */ }
|
||||
}
|
||||
|
||||
const rondevu = new Rondevu({
|
||||
apiUrl: 'https://api.ronde.vu',
|
||||
cryptoAdapter: new CustomCryptoAdapter()
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user