Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@node-dlc/bufio

atomicfinance2.9kMIT1.1.3TypeScript support: included

Buffer IO utilities

readme

Utilities for Buffer IO

CircleCI codecov

Usage:

npm install @node-dlc/bufio
const { BufferReader, BufferWriter } = require('@node-dlc/bufio');

// write arbitrary length data
const writer = new BufferWriter();
writer.writeUInt8(1);
writer.writeUInt16BE(2);
writer.writeUInt32BE(3);
writer.writeBytes(Buffer.from([4]));
let buffer = writer.toBuffer();

// read values
const reader = new BufferReader(buffer);
console.log(buffer.readUInt8());
console.log(buffer.readUInt16BE());
console.log(buffer.readUInt32BE());
console.log(buffer.readBytes());

BufferReader

This class wraps an existing Buffer and allows reading data from the Buffer. This class includes

  • position: number - the current buffer cursor position
  • eof: bool - whether the current position is at the end of the buffer
  • buffer: Buffer - the underlying buffer
  • lastReadBytes - number of bytes last read from the buffer

  • readUInt8(): number - reads 1 byte

  • readUInt16LE(): number - reads 2 bytes as 16-bit little-endian unsigned integer
  • readUInt16BE(): number - reads 2 bytes as 16-bit big-endian unsigned integer
  • readUInt32LE(): number - reads 4 bytes as 32-bit little-endian unsigned integer
  • readUInt32BE(): number - reads 4 bytes as 32-bit big-endian unsigned integer
  • readUInt64LE(): bigint - reads 8 bytes as 64-bit little-endian unsigned integer
  • readUInt64BE(): bigint - reads 8 bytes as 64-bit big-endian unsigned integer
  • readVarUint(): bigint - reads a variable length integer as defined in the Bitcoin protocol docs
  • readBigSize(): bigint - reads a variable length integer as defined in the Lightning Network
  • readBytes([len]): Buffer - reads the optionally specified number of bytes. If no length is supplied, it reads to the end of the buffer.

BufferWriter

This class can accept an existing Buffer and write to. When used in this mode the Buffer length is fixed and writes that overflow the Buffer will throw an execption.

This class can intenrally manage a Buffer and will automatically expand to fit the data footprint required. At the end of writing, .toBuffer must be called to obtain the underlying Buffer.

  • writeUInt8(number): undefined - writes 1 byte
  • writeUInt16LE(number): undefined - writes a number as a 16-bit little-endian unsigned integer
  • writeUInt16BE(number): undefined - writes a number as a 16-bit big-endian unsigned integer
  • writeUInt32LE(number): undefined - writes a number as a 32-bit little-endian unsigned integer
  • writeUInt32BE(number): undefined - writes a number as a 32-bit big-endian unsigned integer
  • writeUInt64LE(number): undefined - writes a number as a 64-bit little-endian unsigned integer
  • writeUInt64BE(number): undefined - writes a number as a 64-bit big-endian unsigned integer
  • writeBytes(buffer): undefined - writes the supplied buffer to the cursor buffer

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[1.0.1] - 2025-07-15

New Features

Single Funded DLC Support (PR #224)

  • Added single funded DLC detection: New singleFunded flag and methods in DlcOffer and DlcAccept
  • Auto-detection logic: Automatically identifies single funded DLC scenarios
  • Updated validation rules: Enhanced validation for single funded DLC scenarios
  • Comprehensive test coverage: Added tests for all new single funded functionality

In single funded DLCs:

  • DlcOffer: totalCollateral equals offerCollateral
  • DlcAccept: acceptCollateral is typically 0 or minimal

Bug Fixes

Number Input Handling (PR #225)

  • Fixed computeRoundingModulus: Now correctly handles number inputs by converting to satoshis (multiply by 1e8)
  • Preserved existing behavior: Value objects and BigInt inputs continue to work as before
  • Enhanced test coverage: Added comprehensive tests for all input types
  • Updated test consistency: Existing tests now use BigInt for raw satoshi values

Previously, number inputs were incorrectly treated as raw satoshi values instead of bitcoin amounts, leading to incorrect calculations.

🔧 Improvements

Development Tooling (PR #226)

  • ESLint upgrade: Updated from v7 to v8 with related plugins
  • TypeScript ESLint upgrade: Updated from v4 to v5
  • Import/export organization: Added simple-import-sort/exports rule for consistent ordering
  • Type safety improvements: Fixed TypeScript types (BigIntbigint) and enhanced type safety
  • Build configuration: Updated tsconfig.json files with consistent build output
  • Code quality: Improved BigNumber usage and better type inference with as const

[1.0.0] - 2025-06-30

🚨 BREAKING CHANGES

  • DLC Protocol Version 1: Complete protocol overhaul with new serialization format
  • Message Class Naming: Removed V0 suffixes from all DLC message classes
  • Incompatible with Previous Versions: All DLC messages use new format incompatible with v0.x releases
  • Type System Refactor: Introduced new type enums (ContractInfoType, ContractDescriptorType, OracleInfoType)

🚀 Major Features

DLC Specifications Compliance (PR #163)

  • Full rust-dlc Compatibility: 100% compatibility with rust-dlc implementation
  • Protocol Version 1: Added PROTOCOL_VERSION = 1 constant
  • Enhanced Type System: New discriminated union types for better type safety
  • F64 Precision Class: High-precision floating-point calculations for financial operations
  • Standardized Properties: Consistent naming across all message types

Message System Overhaul

  • New Message Formats: Complete refactor of DLC message serialization
  • TLV Compatibility: Preserved forward compatibility with unknown TLV handling
  • Enhanced Oracle Support: Improved oracle message parsing and compatibility
  • Simplified Class Names: Cleaner naming convention without version suffixes

🔧 Improvements

  • TypeScript Type Safety: Enhanced type checking with discriminated unions
  • Code Quality: Standardized formatting and removed duck typing patterns
  • Test Coverage: 171 passing internal tests with 24 new test vector files
  • Cross-Language Testing: Compatibility testing infrastructure with rust-dlc
  • Defensive Programming: Added error handling and validation throughout

🐛 Bug Fixes

  • Payout Calculations: Improved accuracy in payout curve calculations
  • Message Parsing: Enhanced oracle message parsing compatibility
  • BigInt Handling: Consolidated BigInt helper functions
  • Import Organization: Cleaned up package imports and dependencies

📦 Package Changes

  • Messaging Package: F64 class moved to messaging package for better organization
  • Transport Updates: Updated for new message format compatibility
  • Storage Libraries: Updated to handle new serialization format
  • CLI Enhancements: Improved rust-dlc CLI with oracle creation capabilities

🧪 Testing

  • Compatibility Tests: Comprehensive testing against rust-dlc implementation
  • Test Vector Updates: New test files for protocol version 1 compliance
  • Cross-Platform Testing: Verified compatibility across different environments
  • Increased Timeout: Extended compatibility test timeouts for complex scenarios

[0.24.1] - 2025-06-09

🔧 Improvements

  • Dependency Updates: Upgraded bitcoinjs-lib to version 6.1.7 across affected packages
    • @node-dlc/chainmon - Updated bitcoinjs-lib dependency
    • @node-dlc/messaging - Updated bitcoinjs-lib dependency
    • @node-dlc/transport - Updated bitcoinjs-lib dependency
  • Security: Latest bitcoinjs-lib includes security fixes and performance improvements
  • Compatibility: Enhanced Bitcoin protocol compatibility with latest library version

🐛 Bug Fixes

  • Package Dependencies: Resolved dependency conflicts in affected packages
  • Build Process: Updated package-lock.json files for consistent dependency resolution

[0.24.0] - 2025-06-02

🚀 Major Features

Node-Lightning Integration Complete

  • Absorbed deprecated node-lightning packages into node-dlc, making the project fully self-contained
  • Added new packages from node-lightning:
    • @node-dlc/bitcoind - Bitcoin Core RPC and ZMQ client
    • @node-dlc/bufio - Buffer I/O utilities
    • @node-dlc/checksum - Checksum utilities (CRC32C)
    • @node-dlc/crypto - Cryptographic functions
    • @node-dlc/wire - Lightning Network wire protocol
    • @node-dlc/noise - Noise protocol implementation
  • Enhanced existing packages with node-lightning functionality:
    • @node-dlc/bitcoin - Added Base58, Script, Tx, and other missing utilities
    • @node-dlc/core - Merged lightning utilities while preserving DLC functionality
    • @node-dlc/logger - Enhanced with additional features from node-lightning
    • @node-dlc/chainmon - Added BlockDiffer and BlockDiffResult functionality

Database Migration: RocksDB → LevelDB

  • Migrated from deprecated RocksDB to actively maintained classic-level
  • Renamed package from @node-dlc/rocksdb to @node-dlc/leveldb
  • Modern async/await API replacing legacy stream-based interface
  • Better performance with native LevelDB implementation

Architecture Improvements

  • Created @node-dlc/common package to resolve circular dependencies
  • Moved shared utilities (BitField, ShortChannelId, ChannelId, Base32) to common package
  • Cleaner dependency hierarchy with no circular references
  • Improved maintainability with better separation of concerns

⚡ New Features

  • Node.js 20.x Support: Upgraded ZeroMQ to v6 for full Node.js 20.x compatibility
  • Batch Funding Group TLV: Added support for batch funding group TLV in DlcSign messages
  • Enhanced DLC Messaging: Improved DLC message containers with bigsize encoding
  • Modern TypeScript: Updated to TypeScript 4.9.5 with better type safety

🔧 Improvements

  • Dependency Cleanup: Removed deprecated bcrypto package
  • Code Quality: Fixed linting and formatting across all packages
  • Documentation: Comprehensive migration guides and technical documentation
  • CI/CD: Updated GitHub Actions for Node.js 18+ support
  • Test Coverage: Maintained ~66% test coverage across all packages

🏗️ Breaking Changes

  • Node.js 18+ Required: Minimum Node.js version is now 18 (up from 14)
  • Database Format: LevelDB format is incompatible with previous RocksDB databases
    • Migration Required: Existing databases cannot be directly migrated
    • Fresh Start: New projects will use LevelDB format going forward
  • Package Renames: @node-dlc/rocksdb is now @node-dlc/leveldb
  • Import Changes: Some internal imports may need updating (see migration guide)

🐛 Bug Fixes

  • Message Size Issues: Fixed out of range errors in accept and sign messages
  • Missing Dependencies: Added missing secp256k1 dependency to messaging package
  • TypeScript Compatibility: Resolved type conflicts with modern TypeScript versions
  • Build Process: Fixed circular dependency issues preventing successful builds

📚 Documentation

  • Migration Guides: Detailed guides for RocksDB→LevelDB and node-lightning integration
  • API Documentation: Updated documentation for all new and enhanced packages
  • Technical Summaries: Comprehensive change documentation for developers
  • README Updates: Removed references to deprecated components

🔄 Internal Changes

  • Lerna Configuration: Improved monorepo management and publishing workflow
  • ESLint Configuration: Enhanced linting rules and formatting consistency
  • TypeScript Configuration: Added skipLibCheck for better compatibility
  • Build Optimization: Streamlined build process across all packages

[0.23.6] - 2024-05-01

Features

  • Added batch funding group TLV to DlcSign message

Bug Fixes

  • Fixed DLC message container size handling to prevent out of range errors
  • Added missing length field to BatchFundingGroup TLV

[0.23.5] - 2024-04-14

Bug Fixes

  • Switched DLC message container to bigsize encoding

[0.23.4] - 2024-04-09

Features

  • Added DLC message containers

Bug Fixes

  • Fixed missing length in BatchFundingGroup TLV

Migration Guide

From 0.23.x to 0.24.0

1. Node.js Version

# Update to Node.js 18+
nvm install 18
nvm use 18

2. Package Updates

# Update dependencies
npm install
# or
yarn install

# Rebuild all packages
npm run bootstrap
# or
yarn bootstrap

3. Database Migration

  • RocksDB databases are not compatible with the new LevelDB format
  • For new projects: No action needed, will use LevelDB automatically
  • For existing projects: Consider if database migration is needed or start fresh

4. Import Updates

// Old
import { BitField } from '@node-dlc/core';

// New - still works (re-exported)
import { BitField } from '@node-dlc/core';
// Or use direct import
import { BitField } from '@node-dlc/common';

5. Package Renames

// Old
import something from '@node-dlc/rocksdb';

// New
import something from '@node-dlc/leveldb';

For detailed migration information, see the individual migration guides in the repository.