$ show stx-labs/stacks.js
This is a monorepo of TypeScript packages providing a comprehensive SDK for interacting with the Stacks blockchain. It includes libraries for transaction construction, wallet management, authentication, decentralized storage (Gaia), encryption, and a CLI tool. The most actively developed package is @stacks/bitcoin-staking, which implements the PoX-5 bond/staking protocol with Bitcoin L1 lockups, signer-manager grants, and reward claims. The architecture is a library/CLI, not a server application. Key entry points include the CLI binary (packages/cli/bin.js), transaction builders (packages/transactions/src/builders.ts), wallet SDK (packages/wallet-sdk/src/index.ts), and staking API (packages/bitcoin-staking/src/index.ts). External dependencies include Stacks node API endpoints, Bitcoin regtest/testnet nodes, and various cryptographic libraries (noble-secp256k1, noble-hashes, @scure/btc-signer). The codebase is well-tested with unit, integration, and e2e tests against live networks, using a fixture recording/replay system for offline determinism.
The LLM identified 4 files worth highlighting for reuse:
Pure functions for PoX-5 reward cycle and bond phase calculations. Includes burnHeightToRewardCycle, bondPeriodToRewardCycle, isInPreparePhase, bondPhaseRanges, and bondStatus. No internal package dependencies, only imports from constants and types. Could be extracted and reused in any project needing Stacks PoX-5 cycle math.
Bitcoin script construction for PoX-5 lockups: buildLockScript, buildUnlockScript, buildLockOutputScript, computeRegisterPreimage. Mirrors the pox-5 Clarity contract's script logic for CLTV timelocks and early-exit branches. Self-contained with minimal imports, reusable for any Bitcoin-based staking protocol.
Clarity integer value constructor (intCV, uintCV) with serialization to bytes and JSON. Part of a family of value constructors (bufferCV, stringCV, tupleCV, etc.) that are self-contained and reusable for any Clarity-aware application. Demonstrates careful handling of bigint and signed/unsigned encoding.
Creates a fetch function with middleware chain (API key injection, request/response context). Used across all packages for HTTP calls. The pattern is generic and could be extracted for any project needing composable fetch middleware. Includes retry logic and error handling.