Shared library utilities for Go Native workers. This package provides common types, utilities, and helper functions used across all worker packages in the monorepo.
The lib package contains shared utilities that enable consistent functionality across the btcindexer, block-ingestor, sui-indexer, and compliance workers. It includes network type definitions, logging, authentication, secrets management, and blockchain interaction helpers.
Structured JSON logging with four log levels:
debug- Detailed debugging informationinfo- General informational messageswarn- Warning messageserror- Error messages with optional error context
import { logger, logError } from "@gonative-cc/lib/logger";
logger.info({ msg: "Operation started", method: "myFunction" });
try {
// operation
} catch (e) {
logError({ msg: "Operation failed", method: "myFunction" }, e);
}Bitcoin network types and utilities:
BtcNetenum - Network identification (regtest, testnet, mainnet, signet)BitcoinTxStatusenum - Transaction lifecycle states (broadcasting, confirming, finalized, reorg)requireElectrsUrl()- Get Electrs URL for a networkbtcNetFromString()- Parse string to BtcNetcalculateConfirmations()- Calculate tx confirmations from block heights
Sui blockchain network configuration:
SuiNettype - Network identifiers (testnet, mainnet, devnet, localnet)toSuiNet()- Validate and convert string to SuiNetSUI_GRAPHQL_URLS- GraphQL endpoints for each network
Sui coin management utilities for signing operations:
sortCoinsByBalance()- Sort coins by balance (descending)selectBiggestCoins()- Select coins to meet a target balanceselectCoins()- Smart coin selection with limit supportprepareCoin()- Prepare coins for transactions with merging
Request authentication using Bearer tokens with timing-safe comparison:
isAuthorized()- Validate Authorization header against expected secret
Secrets management helpers:
getSecret()- Retrieve secrets from Cloudflare secrets store
Shared RPC type definitions for cross-worker communication:
- Redeem request types and statuses
- Finalize redeem transaction types
- Sui indexer RPC interface
- BTC indexer RPC response types
Cloudflare environment setup helpers:
Setupinterface - Combined BTC/Sui network configurationgetSetup()- Retrieve setup by IDgetActiveSetups()- Get all active setups for an environment- Predefined environments: TestEnv, dev, staging
- BtcNet enum - Standardized Bitcoin network identification
- SuiNet type - Sui blockchain network identifiers
- BitcoinTxStatus - Transaction lifecycle states for deposit tracking
- Setup - Combined configuration for BTC+Sui network pairs
- SuiIndexerRpc - Interface for sui-indexer communication
- RedeemRequestResp - Standardized redeem request responses
- FinalizeRedeemTx - Cross-worker finalization data
JSON-formatted logs with consistent structure:
{ "msg": "message", "level": "info", "method": "functionName", ... }- Key generation for KV storage (
kvBlocksKey) - Network validation and parsing
- Confirmation calculation
- Delay/promise helpers
Import shared utilities in other worker packages:
import { BtcNet, BitcoinTxStatus } from "@gonative-cc/lib/nbtc";
import { SuiNet, SUI_GRAPHQL_URLS } from "@gonative-cc/lib/nsui";
import { logger, logError } from "@gonative-cc/lib/logger";
import { isAuthorized } from "@gonative-cc/lib/auth";
import { getSetup } from "@gonative-cc/lib/setups";
import { selectCoins, prepareCoin } from "@gonative-cc/lib/coin-ops";
import type { SuiIndexerRpc } from "@gonative-cc/lib/rpc-types";Tests are co-located in the same directory as the source files with the .test.ts suffix
Run tests:
bun run testRun type checking:
bun run typecheck