<>ts-stack
Get StartedArchitecturePackagesSpecsGuides
⌘K
Reference
Home
Get StartedOverviewInstallChoose your stackKey concepts
ArchitectureOverviewStack layersBEEF (BRC-62)BRC-100 Wallet InterfaceIdentity & AuthConformance pipeline
PackagesOverviewSDKWalletNetworkOverlaysMessagingMiddlewareHelpers
InfrastructureOverviewmessage-box-serveroverlay-serveruhrp-server-basicuhrp-server-cloud-bucketwabwallet-infrachaintracks-server
SpecsOverviewBRC-100 Wallet InterfaceOverlay HTTPMessage-box HTTPAuthsocket (WebSocket)BRC-31 Auth HandshakeBRC-29 Peer PaymentBRC-121 / HTTP 402ARC BroadcastMerkle ServiceStorage AdapterGASP SyncUHRPAir-Gap Optical (BRC-141)
ConformanceOverviewVector catalogTS runnerContributing vectors
GuidesOverviewBuild a wallet-aware appRun an overlay nodePeer-to-peer messagingHTTP 402 payments
ReferenceOverviewBRC indexRepository health
AboutVersioningContributingDoc agentDocumentation sources
Loading…
NextBuild a wallet-aware app
Edit this page on GitHub
© 2026 BSV Blockchain. ts-stack is open-source.
GitHubContributingVersioning

Compiled Package Boundary Examples

These examples are deliberately small. Their purpose is to prove that public entry points across the stack remain usable together from clean, packed npm artifacts. pnpm docs:examples extracts every fence marked compile, packs the referenced packages and their first-party dependency closure, installs those tarballs in a temporary consumer with lifecycle scripts disabled, and runs the native TypeScript compiler.

They validate package names, exports, declarations, module resolution, and cross-package type identity. They do not replace behavioral examples, package tests, browser/mobile bundles, or live-service integration tests.

SDK and high-level helpers

ts
// example-id: sdk-and-simple
import { PrivateKey } from '@bsv/sdk'
import { createWallet, type BrowserWallet } from '@bsv/simple/browser'

const exampleIdentityKey: string = PrivateKey.fromRandom().toPublicKey().toString()
const connectExampleWallet: () => Promise<BrowserWallet> = createWallet

void exampleIdentityKey
void connectExampleWallet

Credentials and identity

ts
// example-id: credentials-and-identity
import { BsvDid, type DidDocument } from '@bsv/did'
import type { DIDQuery } from '@bsv/overlay-topics'

// Declared rather than derived from `PrivateKey`, so this fence compiles on its
// own. Only fences importing a changed package are selected, so the one above
// is absent whenever `@bsv/sdk` is unchanged, and a fence that reaches across to
// it fails for reasons that have nothing to do with the boundary under test.
declare const examplePublicKeyDer: number[]

const exampleDidDocument: DidDocument = BsvDid.toDidDocument(
  BsvDid.fromPublicKey(examplePublicKeyDer)
)
const acceptDidLookup = (query: DIDQuery): DIDQuery => query

void exampleDidDocument
void acceptDidLookup

The compiler combines the selected fences into one consumer module, and on a pull request it selects only the fences whose import closure reaches a changed package. So an earlier fence's imports are available only when that fence happened to be selected too, and a fence that leans on one is broken by any change that does not touch it. Each fence declares everything it names.

Messaging

ts
// example-id: messaging
import type { MessageBoxClientOptions } from '@bsv/message-box-client'
import type { PublicProfile } from '@bsv/paymail'

const exampleMessageBoxOptions: MessageBoxClientOptions = {
  host: 'https://messagebox.example'
}
const exampleProfileConsumer = (profile: PublicProfile): string => profile.name

void exampleMessageBoxOptions
void exampleProfileConsumer

Public Message Box deployments may serve previously unknown application origins. An operator allowlist is optional deployment configuration; it does not replace BRC authentication, permissions, signatures, replay protection, or request bounds.

Authentication and HTTP payments

ts
// example-id: middleware
import { AuthProofClient, type AuthProofOptions } from '@bsv/auth'
import { create402Fetch, type Payment402Options } from '@bsv/402-pay'
import type { AuthRequest } from '@bsv/auth-express-middleware'
import type { PaymentRequest } from '@bsv/payment-express-middleware'

const exampleAuthOptions: AuthProofOptions = {
  protocol: [2, 'compiled docs example']
}
const exampleAuthClient = new AuthProofClient(exampleAuthOptions)
const buildPaidFetch = (options: Payment402Options) => create402Fetch(options)
const acceptAuthRequest = (request: AuthRequest): AuthRequest => request
const acceptPaymentRequest = (request: PaymentRequest): PaymentRequest => request

void exampleAuthClient
void buildPaidFetch
void acceptAuthRequest
void acceptPaymentRequest

Overlay and synchronization

ts
// example-id: overlay-and-gasp
import type { TopicBlockAnchor } from '@bsv/overlay'
import type { GASPStorage } from '@bsv/gasp'
import type { AnyQuery } from '@bsv/overlay-topics'
import type OverlayExpress from '@bsv/overlay-express'

const exampleAnchorConsumer = (anchor: TopicBlockAnchor): number => anchor.blockHeight
const exampleStorageConsumer = (storage: GASPStorage): GASPStorage => storage
const exampleAnyQuery: AnyQuery = {}
const acceptOverlayServer = (server: OverlayExpress): OverlayExpress => server

void exampleAnchorConsumer
void exampleStorageConsumer
void exampleAnyQuery
void acceptOverlayServer

Wallet storage clients

ts
// example-id: wallet-storage
import type { SetupWalletArgs } from '@bsv/wallet-toolbox'
import { StorageClient } from '@bsv/wallet-toolbox-client'
import type { WalletRelayServiceOptions } from '@bsv/wallet-relay'

const exampleWalletSetup = (args: SetupWalletArgs): SetupWalletArgs => args
type ExampleStorageOptions = ConstructorParameters<typeof StorageClient>[2]
const acceptStorageOptions = (options: ExampleStorageOptions): ExampleStorageOptions => options
const acceptRelayOptions = (options: WalletRelayServiceOptions): WalletRelayServiceOptions =>
  options

void exampleWalletSetup
void acceptStorageOptions
void acceptRelayOptions

Remote Wallet Storage is a public service in many deployments. Keep its cross-domain default configurable and public unless an operator explicitly enables an origin allowlist; enforce authorization and identity isolation regardless of CORS mode.

Network messages

ts
// example-id: network
import { tryDecodeMessage, type DecodedMessage } from '@bsv/teranode-listener'

const decodeNetworkMessage = (bytes: Uint8Array): DecodedMessage | null => tryDecodeMessage(bytes)

void decodeNetworkMessage

WASM verification

ts
// example-id: verifast
import { BdkVerifier, type BdkVerifierOptions } from '@bsv/verifast'

const exampleVerifierOptions: BdkVerifierOptions = { mode: 'auto' }
const exampleVerifier = new BdkVerifier(exampleVerifierOptions)

void exampleVerifier

Run:

bash
pnpm build
pnpm docs:examples

The command requires built package outputs and network access only when the clean temporary consumer's external dependencies are not already present in the pnpm store. It never publishes or deploys an artifact.