crypto-audit-tool
v1.0.0
Published
A professional crypto audit and validation toolkit for blockchain addresses, signatures, and cryptographic operations
Maintainers
Readme
crypto-audit-tool
A comprehensive Node.js toolkit for cryptocurrency address validation, signature verification, and cryptographic operations. Designed for security auditing, blockchain application development, and compliance checks.
Features
- ✅ Ethereum Address Validation - Support for both lowercase and EIP-55 checksum addresses
- ✅ Bitcoin Address Validation - Legacy (P2PKH/P2SH) and SegWit (Bech32) support
- ✅ Signature Verification - ECDSA signature verification with flexible key formats
- ✅ Hash Utilities - SHA-256, Keccak-256 and other hash functions
- ✅ Key Pair Generation - Secp256k1, P-256, and prime256v1 curves
- ✅ Public Key Recovery - Recover public key from signature and message hash
- ✅ Zero Dependencies for Core Functions - Minimal required dependencies
- ✅ TypeScript Support - Includes TypeScript definitions
Installation
npm install crypto-audit-toolUsage
Validate Ethereum Addresses
const { validateEthereumAddress, toChecksumAddress } = require('crypto-audit-tool');
// Basic validation
validateEthereumAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f32145'); // true
validateEthereumAddress('0x742d35cc6634c0532925a3b844bc9e7595f32145'); // true
validateEthereumAddress('742d35Cc6634C0532925a3b844Bc9e7595f32145'); // true
validateEthereumAddress('invalid'); // false
// Convert to checksum
toChecksumAddress('0x742d35cc6634c0532925a3b844bc9e7595f32145');
// '0x742d35Cc6634C0532925a3b844Bc9e7595f32145'Validate Bitcoin Addresses
const { validateBitcoinAddress } = require('crypto-audit-tool');
// Legacy addresses
validateBitcoinAddress('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'); // true
validateBitcoinAddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy'); // true
// Bech32 (SegWit) addresses
validateBitcoinAddress('bc1qw4vdy9j7z8e95d5g3qh6yjedz9g0k2g0k5p6xl'); // true
validateBitcoinAddress('bc1q8372q7peydt5jlh9wydkjmdl6gf5nyj8cxq0ew'); // true
validateBitcoinAddress('invalid'); // falseVerify Signatures
const { verifySignature, generateKeyPair, hashMessage } = require('crypto-audit-tool');
// Generate a key pair
const { privateKey, publicKey } = generateKeyPair('secp256k1');
// Sign a message (using private key manually)
const message = 'Important transaction data';
const messageHash = hashMessage(message, 'sha256');
// For demonstration, we'll sign using crypto module
const signature = crypto.sign(null, Buffer.from(message), { key: privateKey, format: 'der' });
// Verify the signature
const isValid = verifySignature(message, signature, publicKey, 'secp256k1');
console.log('Signature valid:', isValid);Hash Messages
const { hashMessage } = require('crypto-audit-tool');
const hash = hashMessage('Hello, world!', 'sha256');
console.log(hash); // '315f5bdb76d078c43b8ac0064e4a0164615b2e8d9d12e4e3d2d8a6b16c4e32e5'
const keccak = hashMessage('Hello, world!', 'keccak256');
console.log(keccak);Generate Key Pairs
const { generateKeyPair } = require('crypto-audit-tool');
// Secp256k1 (Ethereum, Bitcoin)
const ethKeys = generateKeyPair('secp256k1');
// P-256 (NIST)
const p256Keys = generateKeyPair('p256');API Reference
validateEthereumAddress(address)
Validates an Ethereum address. Supports both mixed-case (EIP-55 checksum) and all-lowercase addresses.
address(string): Ethereum address, with or without '0x' prefix- Returns:
boolean
toChecksumAddress(address)
Converts an Ethereum address to EIP-55 checksum format.
address(string): Ethereum address- Returns:
string(checksum address with 0x prefix)
validateBitcoinAddress(address)
Validates a Bitcoin address. Supports legacy (Base58) and Bech32 formats.
address(string): Bitcoin address- Returns:
boolean
verifySignature(message, signature, publicKey, [curve])
Verifies an ECDSA signature.
message(string|Buffer): Original messagesignature(string|Buffer): DER-encoded signature or hex stringpublicKey(string|Buffer): Public key (hex, DER, or PEM)curve(string): Curve name ('secp256k1', 'p256', 'prime256v1')- Returns:
boolean
hashMessage(message, [algorithm])
Hashes a message using specified algorithm.
message(string|Buffer): Input messagealgorithm(string): Hash algorithm (default: 'sha256')- Returns:
string(hex digest)
generateKeyPair([curve])
Generates a new elliptic curve key pair.
curve(string): Curve name (default: 'secp256k1')- Returns:
{ privateKey: string, publicKey: string }
recoverPublicKey(messageHash, signature, recoveryId)
Recovers public key from signature and message hash (secp256k1 only).
messageHash(Buffer): 32-byte hash of the messagesignature(Buffer): DER-encoded signaturerecoveryId(number): Recovery ID (0-3)- Returns:
Buffer|null
Security
This library is intended for cryptographic validation and auditing purposes. While it uses well-established algorithms and libraries, always perform your own security review before using in production environments.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
MIT © 2024 Security Developer
