npm-demo-1112
v1.0.0
Published
A TypeScript project for message signing functionality
Downloads
3
Readme
Bitcoin Message Verification (TypeScript)
A modular TypeScript codebase for verifying Bitcoin messages and signatures, including BIP322, Taproot (P2TR), and P2WPKH support.
Features
- ✅ Verify Bitcoin messages using standard and BIP322 methods
- 🟢 Supports Taproot (P2TR) and P2WPKH signature verification
- 🧩 Modular, testable, and well-documented code
- 🦾 TypeScript strict typing
Project Structure
src/
├── index.ts # App entry point and usage example
├── bitcoinUtils.ts # Bitcoin network and hash utilities
├── validators.ts # Schnorr and ECDSA signature validators
├── verifiers.ts # BIP322, P2TR, and P2WPKH verification logic
├── types.ts # Shared types and enumsInstallation
- Install dependencies:
npm install - Build the project:
npm run build - Run the example:
npm start
Usage Example
import bitcoinMessage from 'bitcoinjs-message';
import { NetworkType } from './types';
import { verifySignatureOfBIP322Simple_P2TR, verifySignatureOfBIP322Simple_P2PWPKH } from './verifiers';
const address = "2MzjGy4UPamASW7faK3NZ1u5hx8uXgHjabR";
const message = "2MzjGy4UPamASW7faK3NZ1u5hx8uXgHjabR-1750289075338";
const signature = "I2UYNblWSj1Q/5V+73v3PT6ULC7zi30v2pKTkGky3UMeKZ7A4ZslO2ul+MCxEg67Ttbm8dd5GQx7VmhpSg+G5D8=";
// Standard bitcoinjs-message verification
const isValidStandard = bitcoinMessage.verify(message, address, signature);
console.log("Standard bitcoinjs-message.verify ==> ", isValidStandard);
// BIP322 Taproot (P2TR) verification
const isValidP2TR = verifySignatureOfBIP322Simple_P2TR(address, message, signature, NetworkType.TESTNET);
console.log("BIP322 P2TR verify ==> ", isValidP2TR);
// BIP322 P2WPKH verification
const isValidP2WPKH = verifySignatureOfBIP322Simple_P2PWPKH(address, message, signature, NetworkType.TESTNET);
console.log("BIP322 P2WPKH verify ==> ", isValidP2WPKH);API Reference
bitcoinUtils.ts
toPsbtNetwork(networkType: NetworkType): Network— Convert a network type to a bitcoinjs-lib network object.bip0322_hash(message: string): string— Compute the BIP0322 message hash.
validators.ts
schnorrValidator(pubkey, msghash, signature): boolean— Validate a Schnorr signature.validator(pubkey, msghash, signature): boolean— Validate an ECDSA signature.
verifiers.ts
verifySignatureOfBIP322Simple_P2TR(address, msg, sign, networkType?): boolean— Verify a BIP322 Taproot (P2TR) signature.verifySignatureOfBIP322Simple_P2PWPKH(address, msg, sign, networkType?): boolean— Verify a BIP322 P2WPKH signature.
types.ts
NetworkType— Enum for Bitcoin network types (MAINNET, TESTNET, REGTEST).
Development
- Modular code for easy testing and extension
- Strict TypeScript configuration
License
MIT
