junkcoinpair
v0.0.6
Published
Client-side JavaScript library for JunkCoin with ECPair
Downloads
443
Maintainers
Readme
junkcoinpair
A library for managing SECP256k1 keypairs for JunkCoin, written in TypeScript with transpiled JavaScript committed to git.
Installation
npm install junkcoinpair
Example
TypeScript
import { ECPairFactory, ECPairInterface } from 'junkcoinpair';
import * as crypto from 'crypto';
// Initialize with tiny-secp256k1
const tinysecp = require('tiny-secp256k1');
const ECPair = ECPairFactory(tinysecp);
// Generate random keypair
const keyPair = ECPair.makeRandom();
// Create from WIF
const fromWif = ECPair.fromWIF('your_wif_key_here');
// Create from private key
const fromPrivate = ECPair.fromPrivateKey(crypto.randomBytes(32));
// Create from public key (33 or 65 byte DER format)
const fromPublic = ECPair.fromPublicKey(keyPair.publicKey);
// Sign a message
const message = crypto.createHash('sha256').update('hello world').digest();
const signature = keyPair.sign(message);
// Verify a signature
const isValid = keyPair.verify(message, signature);
Features
- Generate random keypairs
- Import/export private keys in WIF format
- Create keypairs from private or public keys
- Sign messages and verify signatures
- Support for compressed and uncompressed public keys
- Schnorr signature support (when available)
- TypeScript support with full type definitions
API
ECPairFactory(secp256k1)
Creates an ECPair API using the provided secp256k1 implementation.
ECPair Methods
makeRandom([options])
: Generate a random keypairfromPrivateKey(buffer[, options])
: Create a keypair from a private keyfromPublicKey(buffer[, options])
: Create a keypair from a public keyfromWIF(string)
: Create a keypair from a WIF string
Instance Methods
sign(hash)
: Sign a 32-byte hashverify(hash, signature)
: Verify a signaturetoWIF()
: Export private key as WIFtweak(buffer)
: Derive a new keypair by tweaking the current one
Testing
npm test
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Based on bitcoinjs/ecpair, modified for JunkCoin.