|
| 1 | +# Bitcoin Taproot Example |
| 2 | + |
| 3 | +A demonstration project showcasing Bitcoin Taproot technology implementation, including address creation, transaction handling, and Schnorr signatures. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Taproot address generation |
| 8 | +- Schnorr signature implementation |
| 9 | +- Transaction creation and signing |
| 10 | +- OP_RETURN output support |
| 11 | +- Debug information output |
| 12 | + |
| 13 | +## Tech Stack |
| 14 | + |
| 15 | +- bitcoinjs-lib: Bitcoin transaction handling library |
| 16 | +- ecpair: Key pair management |
| 17 | +- @bitcoinerlab/secp256k1: Elliptic curve cryptography |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install bitcoinjs-lib ecpair @bitcoinerlab/secp256k1 |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +1. Create a Taproot address: |
| 28 | +```javascript |
| 29 | +const taprootData = createTaprootAddress(); |
| 30 | +console.log('Taproot Address:', taprootData.address); |
| 31 | +``` |
| 32 | + |
| 33 | +2. Create a transaction: |
| 34 | +```javascript |
| 35 | +const tx = await createTaprootTransaction(taprootData, recipientAddress, amount); |
| 36 | +``` |
| 37 | + |
| 38 | +## Core Components |
| 39 | + |
| 40 | +### SchnorrSigner Class |
| 41 | +Handles Schnorr signatures required for Taproot transactions: |
| 42 | +- Key pair management |
| 43 | +- x-only public key conversion |
| 44 | +- Schnorr signature generation |
| 45 | + |
| 46 | +### Utility Functions |
| 47 | +- `toXOnly`: Converts full public key to x-only format |
| 48 | +- `createTaprootAddress`: Generates Taproot address |
| 49 | +- `addOpReturnOutput`: Adds OP_RETURN output |
| 50 | +- `createTaprootTransaction`: Creates and signs transactions |
| 51 | + |
| 52 | +## Important Notes |
| 53 | + |
| 54 | +- Currently configured for testnet |
| 55 | +- Uses fixed transaction fee (1000 satoshis) |
| 56 | +- Example UTXO is placeholder (replace with real UTXO in production) |
| 57 | + |
| 58 | +## Debug Features |
| 59 | + |
| 60 | +The project includes comprehensive debug output: |
| 61 | +- Address information |
| 62 | +- Public key details |
| 63 | +- Transaction details |
| 64 | +- Signature information |
| 65 | + |
| 66 | +## Example Output |
| 67 | + |
| 68 | +When running the program, you'll see: |
| 69 | +- Taproot address |
| 70 | +- Public key (hex format) |
| 71 | +- Output script |
| 72 | +- Network information |
| 73 | +- Transaction details |
| 74 | +- Witness data |
| 75 | + |
| 76 | +## Development Environment |
| 77 | + |
| 78 | +- Node.js |
| 79 | +- npm/yarn |
| 80 | +- Bitcoin Testnet (for testing) |
| 81 | + |
| 82 | +## Security Considerations |
| 83 | + |
| 84 | +- This is a demonstration project, not recommended for mainnet use |
| 85 | +- Ensure proper private key handling in production |
| 86 | +- Implement appropriate error handling for production use |
| 87 | + |
| 88 | +## API Reference |
| 89 | + |
| 90 | +### createTaprootAddress() |
| 91 | +Returns an object containing: |
| 92 | +- signer: SchnorrSigner instance |
| 93 | +- address: Taproot address |
| 94 | +- output: Output script |
| 95 | + |
| 96 | +### createTaprootTransaction(taprootData, recipient, satoshis, message) |
| 97 | +Parameters: |
| 98 | +- taprootData: Object containing signer and output information |
| 99 | +- recipient: Recipient's address |
| 100 | +- satoshis: Amount to send |
| 101 | +- message: Optional OP_RETURN message (default provided) |
| 102 | + |
| 103 | +Returns: Signed transaction in hex format |
| 104 | + |
| 105 | +## References |
| 106 | + |
| 107 | +- [Bitcoin Taproot Documentation](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki) |
| 108 | +- [bitcoinjs-lib Documentation](https://github.com/bitcoinjs/bitcoinjs-lib) |
| 109 | + |
| 110 | +## Contributing |
| 111 | + |
| 112 | +Feel free to submit issues and enhancement requests. |
| 113 | + |
| 114 | +## License |
| 115 | + |
| 116 | +MIT License |
| 117 | +``` |
| 118 | +
|
| 119 | +This README.md provides: |
| 120 | +1. Project overview and key features |
| 121 | +2. Installation and usage instructions |
| 122 | +3. Detailed component descriptions |
| 123 | +4. Development considerations |
| 124 | +5. Debug information |
| 125 | +6. Security notes |
| 126 | +7. API documentation |
| 127 | +8. Relevant references |
| 128 | +
|
| 129 | +You can customize this content based on your specific needs. |
0 commit comments