Home

j-bitcoin 1.0.2

J-Bitcoin

npm version License: ISC Node.js TypeScript JSDoc

A comprehensive JavaScript/TypeScript cryptocurrency wallet library supporting both custodial and non-custodial wallets for Bitcoin (BTC), Bitcoin Cash (BCH), and Bitcoin SV (BSV).

๐Ÿš€ Features

๐Ÿ’ผ Wallet Types

  • Custodial Wallets - Traditional single-key wallets with HD derivation
  • Non-Custodial Wallets - Advanced threshold signature schemes (TSS)

๐Ÿ” Cryptographic Standards

  • BIP32 - Hierarchical Deterministic Wallets
  • BIP39 - Mnemonic Seed Phrases (12-word)
  • ECDSA - Standard Bitcoin signatures
  • Schnorr - Modern signature scheme (BIP340)
  • Threshold Signatures - Multi-party signature generation

๐Ÿ  Address Formats

  • Legacy - P2PKH addresses (1...)
  • SegWit - Bech32 addresses (bc1...)
  • CashAddr - Bitcoin Cash format

๐ŸŒ Network Support

  • Bitcoin (BTC) - Mainnet & Testnet
  • Bitcoin Cash (BCH) - Mainnet & Testnet
  • Bitcoin SV (BSV) - Mainnet & Testnet

๐Ÿ“ Developer Experience

  • Full TypeScript Support - Complete type definitions with IntelliSense
  • Comprehensive JSDoc - Rich inline documentation
  • ES Modules - Modern JavaScript module support
  • Tree Shaking - Import only what you need

๐Ÿ“š Documentation

JSDoc for J-Bitcoin

๐Ÿ“ฆ Installation

npm install j-bitcoin

๐ŸŽฏ Quick Start

JavaScript

import { Custodial_Wallet } from 'j-bitcoin';

// Generate new wallet
const [mnemonic, wallet] = Custodial_Wallet.fromRandom('main');
console.log('Mnemonic:', mnemonic);
console.log('Address:', wallet.address);

// Sign a message
const [signature, recoveryId] = wallet.sign("Hello Bitcoin!");
console.log('Signature valid:', wallet.verify(signature, "Hello Bitcoin!"));

TypeScript

import { Custodial_Wallet, ECDSASignatureResult } from 'j-bitcoin';

// Generate new wallet with full type safety
const [mnemonic, wallet]: [string, Custodial_Wallet] = Custodial_Wallet.fromRandom('main');

// TypeScript knows the exact return types
const [signature, recoveryId]: ECDSASignatureResult = wallet.sign("Hello Bitcoin!");
const isValid: boolean = wallet.verify(signature, "Hello Bitcoin!");

Advanced Threshold Signatures

JavaScript:

import { Non_Custodial_Wallet } from 'j-bitcoin';

// Create 2-of-3 threshold wallet
const wallet = Non_Custodial_Wallet.fromRandom("main", 3, 2);

// Get shares for distribution
const shares = wallet._shares;
console.log('Distribute shares to participants:', shares);

// Generate threshold signature
const signature = wallet.sign("Multi-party transaction");
console.log('Threshold signature:', signature.serialized_sig);

TypeScript:

import { Non_Custodial_Wallet, ThresholdSignatureResult } from 'j-bitcoin';

// Create 2-of-3 threshold wallet
const wallet: Non_Custodial_Wallet = Non_Custodial_Wallet.fromRandom("main", 3, 2);

// Get shares for distribution
const shares: string[] = wallet._shares;
console.log('Distribute shares to participants:', shares);

// Generate threshold signature
const signature: ThresholdSignatureResult = wallet.sign("Multi-party transaction");
console.log('Threshold signature:', signature.serialized_sig);

Address Conversion

JavaScript:

import { BECH32, CASH_ADDR } from 'j-bitcoin';

const legacyAddress = "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2";

// Convert to SegWit
const segwitAddr = BECH32.to_P2WPKH(legacyAddress);
console.log('SegWit:', segwitAddr);
// Output: bc1qhkfq3zahaqkkzx5mjnamwjsfpw3tvke7v6aaph

// Convert to CashAddr
const cashAddr = CASH_ADDR.to_cashAddr(legacyAddress, "p2pkh");
console.log('CashAddr:', cashAddr);
// Output: bitcoincash:qztxx64w20kmy5y9sskjwtgxp3j8dc20ksvef26ssu

TypeScript:

import { BECH32, CASH_ADDR } from 'j-bitcoin';

const legacyAddress: string = "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2";

// Convert to SegWit
const segwitAddr: string = BECH32.to_P2WPKH(legacyAddress);
console.log('SegWit:', segwitAddr);
// Output: bc1qhkfq3zahaqkkzx5mjnamwjsfpw3tvke7v6aaph

// Convert to CashAddr
const cashAddr: string = CASH_ADDR.to_cashAddr(legacyAddress, "p2pkh");
console.log('CashAddr:', cashAddr);
// Output: bitcoincash:qztxx64w20kmy5y9sskjwtgxp3j8dc20ksvef26ssu

Schnorr Signatures

JavaScript:

import { schnorr_sig } from 'j-bitcoin';

const privateKey = "L1vHfV6GUbMJSvFaqjnButzwq5x4ThdFaotpUgsfScwMNKjdGVuS";
const message = "Hello Schnorr!";

// Sign with Schnorr
const signature = schnorr_sig.sign(privateKey, message);

// Get public key
const publicKey = schnorr_sig.retrieve_public_key(privateKey);

// Verify signature
const isValid = schnorr_sig.verify(signature, message, publicKey);
console.log('Schnorr signature valid:', isValid);

TypeScript:

import { schnorr_sig } from 'j-bitcoin';

const privateKey: string = "L1vHfV6GUbMJSvFaqjnButzwq5x4ThdFaotpUgsfScwMNKjdGVuS";
const message: string = "Hello Schnorr!";

// Sign with Schnorr
const signature: Uint8Array = schnorr_sig.sign(privateKey, message);

// Get public key
const publicKey: Uint8Array = schnorr_sig.retrieve_public_key(privateKey);

// Verify signature
const isValid: boolean = schnorr_sig.verify(signature, message, publicKey);
console.log('Schnorr signature valid:', isValid);

๐Ÿ“– API Documentation

TypeScript Support

J-Bitcoin provides complete TypeScript definitions with:

// Full IntelliSense support
import type { 
  Custodial_Wallet, 
  Non_Custodial_Wallet,
  ECDSASignatureResult,
  ThresholdSignatureResult,
  HDKeys,
  KeyPair,
  NetworkType 
} from 'j-bitcoin';

// Type-safe network specification
const network: NetworkType = 'main'; // 'main' | 'test'

// Strongly typed wallet creation
const wallet: Custodial_Wallet = Custodial_Wallet.fromRandom(network);

// Comprehensive interface definitions
interface ThresholdSignatureResult {
  sig: { r: bigint; s: bigint; };
  serialized_sig: string;
  msgHash: Buffer;
  recovery_id: number;
}

Custodial_Wallet

Method Description
fromRandom(net, passphrase?) Generate new random wallet
fromMnemonic(net, mnemonic, passphrase?) Import from mnemonic
fromSeed(net, seed) Create from hex seed
derive(path, keyType) Derive child keys
sign(message) Sign with ECDSA
verify(sig, message) Verify signature

Non_Custodial_Wallet

Method Description
fromRandom(net, groupSize, threshold) Create threshold wallet
fromShares(net, shares, threshold) Reconstruct from shares
sign(message) Generate threshold signature
verify(sig, msgHash) Verify threshold signature
_shares Get secret shares
_privateKey Get reconstructed private key

Address Utilities

Function Description
BECH32.to_P2WPKH(address) Convert to SegWit
BECH32.data_to_bech32(prefix, data, encoding) Custom Bech32 encoding
CASH_ADDR.to_cashAddr(address, type?) Convert to CashAddr

๐Ÿ”— BIP32 Key Derivation

JavaScript:

// Standard BIP44 paths
wallet.derive("m/44'/0'/0'/0/0");    // Bitcoin account 0, address 0
wallet.derive("m/44'/145'/0'/0/0");  // Bitcoin Cash account 0
wallet.derive("m/44'/236'/0'/0/0");  // Bitcoin SV account 0

// Custom derivation
wallet.derive("m/0'/1'/2");          // Hardened path
wallet.derive("m/0/1/2");            // Non-hardened path

TypeScript:

import { Custodial_Wallet, KeyType } from 'j-bitcoin';

// Standard BIP44 paths with type safety
wallet.derive("m/44'/0'/0'/0/0", 'pri' as KeyType);    // Bitcoin account 0, address 0
wallet.derive("m/44'/145'/0'/0/0", 'pri' as KeyType);  // Bitcoin Cash account 0
wallet.derive("m/44'/236'/0'/0/0", 'pri' as KeyType);  // Bitcoin SV account 0

// Custom derivation with type checking
wallet.derive("m/0'/1'/2", 'pri' as KeyType);          // Hardened path
wallet.derive("m/0/1/2", 'pub' as KeyType);            // Non-hardened path (public key derivation)

๐Ÿ›ก๏ธ Security Features

  • Secure Random Generation - Uses Node.js crypto.randomBytes()
  • Mnemonic Validation - BIP39 checksum verification
  • Threshold Security - Distributed key management
  • Multiple Signature Schemes - ECDSA, Schnorr, TSS
  • Address Validation - Built-in format checking

๐ŸŽ›๏ธ Advanced Examples

TypeScript Multi-Signature Escrow

JavaScript:

import { Non_Custodial_Wallet } from 'j-bitcoin';

// 2-of-3 escrow: buyer, seller, arbiter
const escrow = Non_Custodial_Wallet.fromRandom("main", 3, 2);
const [buyerShare, sellerShare, arbiterShare] = escrow._shares;

// Buyer + Seller can release funds
const release = Non_Custodial_Wallet.fromShares("main", 
  [buyerShare, sellerShare], 2);

// Disputes require arbiter
const dispute = Non_Custodial_Wallet.fromShares("main",
  [buyerShare, arbiterShare], 2);

TypeScript:

import { Non_Custodial_Wallet } from 'j-bitcoin';

// 2-of-3 escrow: buyer, seller, arbiter
const escrow: Non_Custodial_Wallet = Non_Custodial_Wallet.fromRandom("main", 3, 2);
const [buyerShare, sellerShare, arbiterShare]: string[] = escrow._shares;

// Buyer + Seller can release funds
const release: Non_Custodial_Wallet = Non_Custodial_Wallet.fromShares("main", 
  [buyerShare, sellerShare], 2);

// Disputes require arbiter
const dispute: Non_Custodial_Wallet = Non_Custodial_Wallet.fromShares("main",
  [buyerShare, arbiterShare], 2);

Corporate Treasury

JavaScript:

import { Non_Custodial_Wallet } from 'j-bitcoin';

// 3-of-5 corporate signature
const treasury = Non_Custodial_Wallet.fromRandom("main", 5, 3);
const executiveShares = treasury._shares;

// Any 3 executives can authorize
const authorization = Non_Custodial_Wallet.fromShares("main",
  [executiveShares[0], executiveShares[2], executiveShares[4]], 3);

// Generate authorization signature
const authSignature = authorization.sign("Transfer $1M to operations");

TypeScript:

import { Non_Custodial_Wallet, ThresholdSignatureResult } from 'j-bitcoin';

// 3-of-5 corporate signature
const treasury: Non_Custodial_Wallet = Non_Custodial_Wallet.fromRandom("main", 5, 3);
const executiveShares: string[] = treasury._shares;

// Any 3 executives can authorize
const authorization: Non_Custodial_Wallet = Non_Custodial_Wallet.fromShares("main",
  [executiveShares[0], executiveShares[2], executiveShares[4]], 3);

// Type-safe signature generation
const authSignature: ThresholdSignatureResult = authorization.sign("Transfer $1M to operations");

Cross-Platform Wallet

JavaScript:

import { Custodial_Wallet } from 'j-bitcoin';

// Generate with passphrase
const [mnemonic, wallet] = Custodial_Wallet.fromRandom('main', 'secure-pass');

// Reconstruct anywhere
const restored = Custodial_Wallet.fromMnemonic('main', mnemonic, 'secure-pass');

// Derive for different coins
restored.derive("m/44'/0'/0'/0/0");   // Bitcoin
restored.derive("m/44'/145'/0'/0/0"); // Bitcoin Cash
restored.derive("m/44'/236'/0'/0/0"); // Bitcoin SV

TypeScript:

import { Custodial_Wallet, NetworkType } from 'j-bitcoin';

// Type-safe network specification
const network: NetworkType = 'main';

// Generate with passphrase
const [mnemonic, wallet]: [string, Custodial_Wallet] = 
  Custodial_Wallet.fromRandom(network, 'secure-pass');

// Reconstruct anywhere with type safety
const restored: Custodial_Wallet = 
  Custodial_Wallet.fromMnemonic(network, mnemonic, 'secure-pass');

// Derive for different coins
restored.derive("m/44'/0'/0'/0/0");   // Bitcoin
restored.derive("m/44'/145'/0'/0/0"); // Bitcoin Cash
restored.derive("m/44'/236'/0'/0/0"); // Bitcoin SV

๐Ÿ“Š Feature Matrix

Feature Support TypeScript
Hierarchical Deterministic โœ… โœ… Full types
Threshold Signatures โœ… โœ… Complete interfaces
ECDSA Signatures โœ… โœ… Type-safe returns
Schnorr Signatures โœ… โœ… BIP340 types
P2PKH Addresses โœ… โœ… Network types
P2WPKH (SegWit) โœ… โœ… Bech32 types
CashAddr Format โœ… โœ… Format types
P2SH Addresses โŒ ๐Ÿ”„ Planned
P2WSH (SegWit v1) โŒ ๐Ÿ”„ Planned
Transaction Building โŒ ๐Ÿ”„ Planned
SPV Validation โŒ ๐Ÿ”„ Planned

๐Ÿ”ง Dependencies

{
  "@noble/curves": "^1.9.1",
  "base58-js": "^1.0.4", 
  "bigint-conversion": "^2.4.0",
  "bn.js": "^5.2.1"
}

๐Ÿงช Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

๐Ÿ“ Documentation

TypeScript IntelliSense

Experience world-class developer productivity:

// VS Code, WebStorm, and other IDEs provide:
// โœ… Complete autocomplete for all methods
// โœ… Inline parameter documentation
// โœ… Return type information
// โœ… Error detection at compile time

const wallet = Custodial_Wallet.fromRandom('main');
//    ^-- IDE shows: [string, Custodial_Wallet]

wallet.derive("m/44'/0'/0'/0/0", 'pri');
//     ^-- IDE shows available parameters and types

Generate API Documentation

npm install -g jsdoc
npm run docs

View comprehensive documentation in docs/index.html with:

  • Complete API reference with examples
  • TypeScript integration guide
  • Security best practices
  • Advanced usage patterns

๐Ÿ”’ Security Best Practices

Key Management

  • Secure Backup: Store mnemonic phrases in secure, offline locations
  • Share Distribution: Use encrypted channels for threshold share distribution
  • Access Control: Implement proper authentication for wallet operations
  • Regular Rotation: Consider periodic key rotation for long-term security

Development

  • Input Validation: Always validate addresses and amounts before operations
  • Error Handling: Implement comprehensive error handling for all operations
  • Testing: Test thoroughly on testnet before mainnet deployment
  • Auditing: Maintain audit trails for all cryptographic operations

Production Deployment

  • Environment Separation: Keep development and production environments isolated
  • Monitoring: Implement monitoring for wallet operations and security events
  • Backup Procedures: Establish reliable backup and recovery procedures
  • Incident Response: Have plans for handling security incidents

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Development Setup

# Clone and install dependencies
git clone https://github.com/yfbsei/J-Bitcoin.git
cd J-Bitcoin
npm install

# Run development commands
npm run lint          # Check code style
npm run format        # Format code
npm run test          # Run tests
npm run docs          # Generate documentation

๐Ÿ“œ License

ISC License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

  • BIP Authors - For Bitcoin Improvement Proposals
  • Bitcoin Core - Reference implementation
  • Noble Crypto - Excellent secp256k1 library
  • Bitcoin Community - Continuous innovation

๐Ÿ“ž Support

๐Ÿ”ฎ Roadmap

Short Term (Q2 2025)

  • [ ] P2SH and P2WSH address support with TypeScript definitions
  • [ ] Enhanced error handling and validation
  • [ ] Performance optimizations for threshold operations
  • [ ] Additional test coverage for edge cases

Medium Term (Q3-Q4 2025)

  • [ ] Transaction building and broadcasting with type-safe interfaces
  • [ ] SPV wallet implementation with comprehensive types
  • [ ] Hardware wallet integration with device-specific types
  • [ ] Advanced script templates with template types

Long Term (2026+)

  • [ ] Lightning Network support with protocol types
  • [ ] React/Vue component library with prop types
  • [ ] WebAssembly optimization with typed bindings
  • [ ] Cross-chain interoperability features

๐Ÿ† Why Choose J-Bitcoin?

For Developers

  • TypeScript First: Built with TypeScript developers in mind
  • Modern Architecture: ES modules, tree shaking, and modern JavaScript
  • Comprehensive Documentation: Every function documented with examples
  • Developer Experience: IntelliSense, autocomplete, and type safety

For Enterprises

  • Threshold Security: Advanced multi-party control for corporate treasuries
  • Compliance Ready: Audit trails and multi-signature requirements
  • Battle Tested: Based on proven cryptographic standards
  • Professional Support: Enterprise-grade reliability and support

For Researchers

  • Academic Standards: Implements latest cryptographic research
  • Extensible Design: Easy to extend with new algorithms
  • Reference Implementation: Well-documented algorithms for study
  • Open Source: Transparent implementation for peer review

โš ๏ธ Security Notice: This library handles private keys and should be used with appropriate security measures. Always verify implementations in test environments before production use.

Built with โค๏ธ for the Bitcoin ecosystem and TypeScript developers

index.js

Main entry point for J-Bitcoin cryptocurrency library

J-Bitcoin is a comprehensive JavaScript library for Bitcoin, Bitcoin Cash, and Bitcoin SV that provides both custodial and non-custodial wallet functionality with advanced cryptographic features including threshold signatures and hierarchical deterministic keys.

Version:
  • 1.0.0
Author:
  • yfbsei
License:
  • ISC
Source:
See:

Example

// Import main wallet classes
import { Custodial_Wallet, Non_Custodial_Wallet } from 'j-bitcoin';

// Import address utilities
import { CASH_ADDR, BECH32 } from 'j-bitcoin';

// Import signature utilities  
import { schnorr_sig, ecdsa } from 'j-bitcoin';

src/BIP32/derive.js

BIP32 hierarchical deterministic key derivation

This module implements child key derivation according to BIP32 specification, enabling the generation of a tree of cryptographic keys from a single master key. It supports both hardened and non-hardened derivation with proper validation and mathematical operations over the secp256k1 elliptic curve.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/BIP32/fromSeed.js

src/BIP39/bip39.js

BIP39 implementation for mnemonic phrase generation and seed derivation

This module implements the BIP39 specification for generating deterministic keys from mnemonic phrases. It supports 12-word mnemonics with checksum validation and PBKDF2-based seed generation with optional passphrases.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/ECDSA/ecdsa.js

ECDSA (Elliptic Curve Digital Signature Algorithm) implementation

This module provides ECDSA signature generation and verification using the secp256k1 elliptic curve, which is the standard curve used in Bitcoin. It includes functionality for signing messages, verifying signatures, and recovering public keys from signatures.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/Schnorr-signature/Schnorr_Signature.js

src/Threshold-signature/Polynomial.js

src/Threshold-signature/threshold_signature.js

Threshold Signature Scheme implementation for distributed cryptography

This module implements a complete threshold signature scheme using Shamir's Secret Sharing and elliptic curve cryptography. It enables distributed key generation, secret sharing, and threshold signature creation where any t-of-n participants can collaboratively generate valid signatures without reconstructing the private key.

The implementation includes:

  • Joint Verifiable Random Secret Sharing (JVRSS) for distributed key generation
  • Additive Secret Sharing (ADDSS) for linear operations on shared secrets
  • Polynomial Reconstruction Secret Sharing (PROSS) for multiplicative operations
  • Inverse Secret Sharing (INVSS) for computing modular inverses of shared secrets
  • Threshold ECDSA signature generation with proper validation
Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/altAddress/BCH/cash_addr.js

src/altAddress/BTC/bech32.js

src/utilities/Base32.js

Base32 encoding implementation for Bitcoin address formats

This module provides Base32 encoding using the custom alphabet specified in Bech32 (BIP173) and CashAddr specifications. Unlike standard Base32, this implementation uses a specially designed alphabet optimized for human readability and error detection in cryptocurrency addresses.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/utilities/base58.js

Base58Check encoding implementation for Bitcoin

This module implements Base58Check encoding, a checksummed base58 encoding format used extensively in Bitcoin for addresses, private keys, and extended keys. Base58Check provides human-readable encoding with built-in error detection through double SHA256 checksums.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/utilities/decodeKeys.js

Bitcoin key decoding utilities for WIF and address formats

This module provides functions to decode various Bitcoin key and address formats back to their raw binary representations. It handles Wallet Import Format (WIF) private keys and legacy Base58Check addresses, extracting the essential cryptographic material while validating format integrity.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/utilities/encodeKeys.js

Bitcoin key encoding utilities for various formats

This module provides comprehensive encoding functions for Bitcoin cryptographic keys and addresses. It handles the conversion of raw key material into standardized formats used across the Bitcoin ecosystem, including extended keys (BIP32), Wallet Import Format (WIF), and Base58Check addresses.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/utilities/rmd160.js

RIPEMD160 cryptographic hash function implementation

This module provides a pure JavaScript implementation of the RIPEMD160 hash algorithm, which is crucial for Bitcoin address generation. RIPEMD160 produces 160-bit (20-byte) hash values and is used in combination with SHA256 to create the HASH160 operation fundamental to Bitcoin's address system.

RIPEMD160 was developed as an alternative to SHA-1 and is part of Bitcoin's address generation specifically for its 160-bit output size, which provides a good balance between security and address length.

Version:
  • 1.0.0
Author:
  • yfbsei
Source:
See:

src/wallet.js

Main wallet classes for J-Bitcoin library providing custodial and non-custodial wallet functionality

This module implements two distinct wallet architectures for Bitcoin cryptocurrency operations:

Custodial_Wallet: Traditional single-party control wallet using hierarchical deterministic key derivation (BIP32) with standard ECDSA signatures. Suitable for individual users and applications requiring simple key management.

Non_Custodial_Wallet: Advanced multi-party threshold signature scheme (TSS) implementation enabling distributed key management without trusted dealers. Ideal for corporate treasuries, escrow services, and high-security applications requiring multi-party authorization.

Version:
  • 1.0.0
Since:
  • 1.0.0
Author:
  • yfbsei
Source:

Example

// Import wallet classes
import { Custodial_Wallet, Non_Custodial_Wallet } from './wallet.js';

// Create custodial wallet
const [mnemonic, custodialWallet] = Custodial_Wallet.fromRandom('main');

// Create threshold wallet
const thresholdWallet = Non_Custodial_Wallet.fromRandom('main', 3, 2);

Requires

  • module:fromSeed
  • module:derive
  • module:bip39
  • module:ecdsa
  • module:standardKey
  • module:address
  • module:ThresholdSignature
  • module:bn.js
  • module:@noble/curves/secp256k1