What signature algorithms does XRPL support?
Last updated:
The XRP Ledger implements a multi-algorithm signature system, supporting two distinct elliptic curve digital signature algorithms (ECDSA and EdDSA) to balance compatibility, performance, and security across diverse use cases.
Supported Algorithms
1. Ed25519 (EdDSA on Curve25519)
- Type: Edwards-curve Digital Signature Algorithm - Default: Yes, recommended for new accounts - Key size: 256 bits - Signature size: 64 bytes (fixed) - Speed: Highest performance - Public key prefix: 'ED' in hex encoding
2. secp256k1 (ECDSA)
- Type: Elliptic Curve Digital Signature Algorithm - Compatibility: Bitcoin, Ethereum - Key size: 256 bits - Signature size: 64-72 bytes (DER-encoded) - Speed: Slower than Ed25519 - Public key prefix: '02', '03' (compressed) or '04' (uncompressed)
Algorithm Selection
Users choose the signature algorithm when generating an account, and this choice is permanent for that account. The algorithm is encoded in the public key itself.
```javascript const xrpl = require('xrpl');
// Create Ed25519 account (default, recommended) const ed25519Wallet = xrpl.Wallet.generate(); // or explicitly const ed25519WalletExplicit = xrpl.Wallet.generate('ed25519');
// Create secp256k1 account (for compatibility) const secp256k1Wallet = xrpl.Wallet.generate('ecdsa-secp256k1');
// The algorithm is evident from the public key prefix console.log('Ed25519 pubkey:', ed25519Wallet.publicKey); // Starts with 'ED' console.log('secp256k1 pubkey:', secp256k1Wallet.publicKey); // Starts with '02' or '03' ```
Why Two Algorithms?
XRPL's dual-algorithm approach serves multiple strategic purposes:
1. Legacy Compatibility: secp256k1 enables integration with Bitcoin and Ethereum ecosystems 2. Performance Optimization: Ed25519 provides superior speed for native XRPL applications 3. Risk Mitigation: If vulnerabilities emerge in one algorithm, accounts using the other remain secure 4. User Choice: Different users have different priorities (speed vs. compatibility) 5. Future Flexibility: Demonstrates protocol's ability to support multiple cryptographic schemes
Performance Comparison
Benchmarks on modern x86-64 hardware:
``` Operation Ed25519 secp256k1 ───────────────────────────────────────────── Key Generation 0.02ms 0.05ms Signing 0.05ms 0.15ms Verification 0.13ms 0.70ms Batch Verify (16) 0.85ms 11.2ms ```
Ed25519 shows 2-7x performance advantages, which becomes significant when processing thousands of transactions per second.
Signature Verification Process
The XRPL validator must determine which algorithm to use when verifying a transaction:
```python # Pseudo-code for signature verification def verify_transaction(tx, signature, public_key): # Determine algorithm from public key prefix if public_key.startswith('ED'): return verify_ed25519(tx, signature, public_key) elif public_key.startswith(('02', '03', '04')): return verify_secp256k1(tx, signature, public_key) else: return False # Unknown algorithm ```
Transaction Signing Example
```javascript const xrpl = require('xrpl');
async function signAndSubmit(wallet) { const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233'); await client.connect(); const prepared = await client.autofill({ TransactionType: 'Payment', Account: wallet.address, Destination: 'rN7n7otQDd6FczFgLdlqtyMVrn3HMfgnZh', Amount: '1000000' }); // Signing automatically uses the wallet's algorithm const signed = wallet.sign(prepared); console.log('Algorithm used:', wallet.publicKey.startsWith('ED') ? 'Ed25519' : 'secp256k1' ); console.log('Signature length:', signed.tx_blob.length); const result = await client.submit(signed.tx_blob); await client.disconnect(); return result; } ```
Multi-Signing Support
XRPL's multi-signature feature works with both algorithms. A multi-signed transaction can include signatures from both Ed25519 and secp256k1 accounts:
```javascript // Multi-sign transaction with mixed algorithms const tx = { TransactionType: 'Payment', Account: 'rMultiSigAccount...', // ... transaction details };
// Sign with Ed25519 key const sig1 = ed25519Wallet.sign(tx, true); // true = multi-sign
// Sign with secp256k1 key const sig2 = secp256k1Wallet.sign(tx, true);
// Combine signatures const multisigned = xrpl.multisign([sig1.tx_blob, sig2.tx_blob]); ```
Regular Key Pair Support
Both algorithms can be used for regular key pairs, allowing accounts to use different algorithms for master and regular keys:
```javascript // Master key: secp256k1 (for compatibility) const masterWallet = xrpl.Wallet.generate('ecdsa-secp256k1');
// Regular key: Ed25519 (for performance) const regularWallet = xrpl.Wallet.generate('ed25519');
// Set regular key transaction const setRegularKey = { TransactionType: 'SetRegularKey', Account: masterWallet.address, RegularKey: regularWallet.address }; ```
Comparison to Other Blockchains
- Bitcoin: Only secp256k1 with ECDSA - Ethereum: Only secp256k1 with ECDSA - Cardano: Ed25519 only - Solana: Ed25519 only - XRPL: Both Ed25519 and secp256k1
XRPL's approach is relatively unique in offering both algorithms, providing flexibility not found in most blockchain systems.
Future Algorithm Support
While currently supporting two algorithms, XRPL's architecture could accommodate additional signature schemes through amendments:
- Post-quantum algorithms: When quantum computers threaten existing curves - Newer curves: Such as Curve448 or Ristretto255 - Aggregate signatures: BLS signatures for improved efficiency
The multi-algorithm framework positions XRPL to adapt to cryptographic advances without fundamental protocol changes.
Best Practices
1. Use Ed25519 by default unless you have specific compatibility requirements 2. Never reuse signatures across different transactions 3. Verify algorithm matches expectations when integrating external systems 4. Test both algorithms if building wallet or integration software 5. Keep private keys secure regardless of algorithm choice
The dual-algorithm design exemplifies XRPL's pragmatic approach: providing modern, high-performance cryptography while maintaining compatibility with the broader blockchain ecosystem.