junkcoinjs-lib
v0.0.5
Published
Fork of bitcoinjs-lib for JunkCoin
Downloads
648
Maintainers
Readme
JunkcoinJS (junkcoinjs-lib)
A JavaScript Junkcoin library for Node.js and browsers. Written in TypeScript, but committing the JS files to verify.
Released under the terms of the MIT LICENSE.
Acknowledgments
Special thanks to the developers of BitcoinJS and LuckycoinJS for their inspiration and contributions to the crypto ecosystem. JunkcoinJS builds upon their exceptional work to provide a dedicated solution for Junkcoin.
Should I use this in production?
If you are thinking of using the master branch of this library in production, stop. Master is not stable; it is our development branch, and only tagged releases may be classified as stable.
Can I trust this code?
Don't trust. Verify.
We recommend every user of this library and the junkcoinjs ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.
Mistakes and bugs happen, but with your help in resolving and reporting issues, together we can produce open source software that is:
- Easy to audit and verify
- Tested, with test coverage >95%
- Advanced and feature rich
- Standardized, using prettier and Node
Buffer
s throughout - Friendly, with a strong and helpful community, ready to answer questions
Features
- Junkcoin address generation and validation (Legacy addresses starting with '7' or 'L')
- Transaction building and signing
- Support for various payment types (P2PKH, P2SH, P2WPKH)
- Full TypeScript support
- Comprehensive test suite
Installation
npm install junkcoinjs-lib
# optionally, install key derivation libraries
npm install ecpair bip32
Running Tests
# Install dependencies
npm install
# Run the test suite
npm test
# Run tests with coverage report
npm run coverage
# Watch mode during development
npm run test:watch
Usage
Crypto is hard. Please note these important considerations:
- The random number generator is crucial for security
- We use the
randombytes
module by default - This library uses tiny-secp256k1 with RFC6979
- Verify everything in your target environment
Best practices:
- Don't reuse addresses
- Don't share BIP32 extended public keys ('xpubs')
- Don't use
Math.random
- Have users verify decoded transactions before broadcast
- Don't generate mnemonics manually
- Use TypeScript or similar for better type safety
Examples
Generate a random address
const junkcoinjs = require('junkcoinjs-lib');
const ECPair = require('ecpair');
const { junkcoin } = junkcoinjs.networks;
// Generate random key pair
const keyPair = ECPair.makeRandom({ network: junkcoin });
// Create P2PKH address
const { address } = junkcoinjs.payments.p2pkh({
pubkey: Buffer.from(keyPair.publicKey),
network: junkcoin,
});
Import via WIF
const keyPair = ECPair.fromWIF('YOUR_WIF_HERE', junkcoin);
const { address } = junkcoinjs.payments.p2pkh({
pubkey: Buffer.from(keyPair.publicKey),
network: junkcoin,
});
Create Multi-sig Address
const pubkeys = [
Buffer.from(keyPair1.publicKey),
Buffer.from(keyPair2.publicKey),
Buffer.from(keyPair3.publicKey),
];
const { address } = junkcoinjs.payments.p2sh({
redeem: junkcoinjs.payments.p2ms({
m: 2,
pubkeys,
network: junkcoin,
}),
network: junkcoin,
});
Network Parameters
Junkcoin specific network parameters:
- Message Prefix: '\u0018Junkcoin Signed Message:\n'
- Bech32 Prefix: 'jkc'
- Public Key Hash: 0x10
- Script Hash: 0x05
- WIF: 0x99
- BIP32 Public: 0x0488b21e
- BIP32 Private: 0x0488ade4
Browser
The recommended method is through browserify:
npm install junkcoinjs-lib browserify
npx browserify --standalone junkcoin - -o junkcoinjs-lib.js <<<"module.exports = require('junkcoinjs-lib');"
Import as ESM module:
<script type="module">import "/scripts/junkcoinjs-lib.js"</script>
Development
# Build the project
npm run build
# Run linter
npm run lint
# Format code
npm run format
Complementary Libraries
- BIP21 - A BIP21 compatible URL encoding library
- BIP38 - Passphrase-protected private keys
- BIP39 - Mnemonic generation for deterministic keys
- BIP32-Utils - A set of utilities for working with BIP32
- Base58 - Base58 encoding/decoding
- Bech32 - A Bech32 encoding library
Contributing
See CONTRIBUTING.md for details.