dedoohdw
v1.0.2
Published
Blockchain Agnostic HD Wallet library for Bitcoin-like cryptocurrencies
Readme
Dedoo HDW (dedoohdw)
A blockchain-agnostic HD (Hierarchical Deterministic) wallet library for Bitcoin-like cryptocurrencies. Provides secure wallet generation, key derivation, and transaction signing across multiple blockchain networks.
🚀 Key Features:
- Blockchain Agnostic: Works with any Bitcoin-like cryptocurrency
- HD Wallet Support: BIP32/BIP44 hierarchical deterministic wallets
- Network Validation: Enforces network specification for enhanced security
- TypeScript Support: Full type definitions included
- Multiple Address Types: P2PKH, P2SH, P2WPKH, P2WSH, P2TR support
- Mnemonic Support: BIP39 mnemonic phrase generation and import
🌟 Why Choose dedoohdw?
Unlike traditional HD wallet libraries that assume specific networks, dedoohdw requires explicit network specification:
- ✅ Network Enforcement: Prevents accidental cross-network wallet usage
- ✅ Multi-Chain Support: Same API across all supported blockchains
- ✅ Enhanced Security: Network-aware key derivation and signing
- ✅ Future Proof: Easy to extend for new Bitcoin-like cryptocurrencies
📦 Installation
npm install dedoohdw dedoo-coinjs-lib dedoopair🔧 Quick Start
Basic HD Wallet Usage
import { HDPrivateKey, AddressType } from 'dedoohdw';
import { networks } from 'dedoo-coinjs-lib';
// Register your blockchain network
networks.register('mycoin', {
messagePrefix: '\\x19MyCoin Signed Message:\\n',
bech32: 'mc',
bip32: { public: 0x0488b21e, private: 0x0488ade4 },
pubKeyHash: 0,
scriptHash: 5,
wif: 128
});
const network = networks.get('mycoin');
// Generate a new HD wallet from mnemonic
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const hdWallet = HDPrivateKey.fromMnemonic(mnemonic, network);
// Derive addresses for different purposes
const receivingAddress = hdWallet.deriveAddress(AddressType.P2PKH, 0, 0); // m/44'/0'/0'/0/0
const changeAddress = hdWallet.deriveAddress(AddressType.P2PKH, 0, 1); // m/44'/0'/0'/1/0
console.log('Receiving Address:', receivingAddress);
console.log('Change Address:', changeAddress);Multi-Chain Wallet
import { HDPrivateKey, AddressType } from 'dedoohdw';
import { networks } from 'dedoo-coinjs-lib';
// Register multiple networks
networks.register('junkcoin', {
messagePrefix: '\\x19Junkcoin Signed Message:\\n',
bech32: 'jc',
bip32: { public: 0x0488b21e, private: 0x0488ade4 },
pubKeyHash: 16,
scriptHash: 5,
wif: 144
});
networks.register('craftcoin', {
messagePrefix: '\\x19Craftcoin Signed Message:\\n',
bech32: 'craft',
bip32: { public: 0x0488b21e, private: 0x0488ade4 },
pubKeyHash: 57,
scriptHash: 5,
wif: 185
});
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
// Create wallets for different blockchains
const junkWallet = HDPrivateKey.fromMnemonic(mnemonic, networks.get('junkcoin'));
const craftWallet = HDPrivateKey.fromMnemonic(mnemonic, networks.get('craftcoin'));
// Each wallet generates addresses for its specific network
const junkAddress = junkWallet.deriveAddress(AddressType.P2PKH, 0, 0);
const craftAddress = craftWallet.deriveAddress(AddressType.P2PKH, 0, 0);
console.log('Junkcoin Address:', junkAddress);
console.log('Craftcoin Address:', craftAddress);Transaction Signing
import { HDPrivateKey, AddressType } from 'dedoohdw';
import { networks, Psbt } from 'dedoo-coinjs-lib';
const network = networks.get('mycoin');
const hdWallet = HDPrivateKey.fromMnemonic(mnemonic, network);
// Create a PSBT (Partially Signed Bitcoin Transaction)
const psbt = new Psbt({ network });
// Add inputs and outputs to the PSBT
psbt.addInput({
hash: 'transaction_hash',
index: 0,
witnessUtxo: {
script: Buffer.from('script_hex', 'hex'),
value: 100000
}
});
psbt.addOutput({
address: 'recipient_address',
value: 90000
});
// Sign the transaction
const signedPsbt = hdWallet.signPsbt(psbt, [{ index: 0, addressType: AddressType.P2PKH }]);
// Finalize and extract the transaction
signedPsbt.finalizeAllInputs();
const transaction = signedPsbt.extractTransaction();🏗️ API Reference
HDPrivateKey
Static Methods
HDPrivateKey.fromMnemonic(mnemonic, network)- Create HD wallet from mnemonicHDPrivateKey.fromSeed(seed, network)- Create HD wallet from seedHDPrivateKey.fromExtendedKey(xprv, network)- Create HD wallet from extended private key
Instance Methods
deriveAddress(addressType, account, index)- Derive address at specific pathderiveKeyPair(addressType, account, index)- Derive key pair at specific pathsignPsbt(psbt, signingIndexes)- Sign a PSBT transactiongetPublicKey()- Get the public keytoWIF()- Export to WIF format
AddressType Enum
AddressType.P2PKH- Pay to Public Key Hash (Legacy)AddressType.P2SH- Pay to Script HashAddressType.P2WPKH- Pay to Witness Public Key Hash (SegWit)AddressType.P2WSH- Pay to Witness Script HashAddressType.P2TR- Pay to Taproot
🔗 Ecosystem
dedoohdw is part of the Dedoo blockchain-agnostic ecosystem:
- dedoo-coinjs-lib - Core blockchain library
- dedoopair - ECPair key management
- dedoo-inscriber - Inscription support
- dedoo-wallet-sdk - Provider SDK
- dedoo-ordutils - Ordinals utilities
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
- NPM Package: https://www.npmjs.com/package/dedoohdw
- GitHub Repository: https://github.com/dedooxyz/dedoohdw
- Documentation: https://docs.dedoo.xyz
- Website: https://dedoo.xyz
🆘 Support
- GitHub Issues: https://github.com/dedooxyz/dedoohdw/issues
- Community: https://discord.gg/dedoo
- Email: [email protected]
Built with ❤️ by the Dedoo Development Team
