simulator

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package simulator runs the official BitBox02 Linux simulator binary and returns a ready-to-use firmware.Communication.

The simulator is Linux/amd64 only. On other platforms Launch reports ErrUnsupportedPlatform and tests should t.Skip.

Index

Constants

View Source
const Port = 15423

Port is the TCP port the BitBox02 simulator listens on once started.

Variables

View Source
var ErrSimulatorNotFound = errors.New("bitbox/simulator: requested version not in embedded list")

ErrSimulatorNotFound is returned when LaunchVersion is given a name that does not appear in Simulators().

View Source
var ErrUnsupportedPlatform = errors.New("bitbox/simulator: requires linux/amd64")

ErrUnsupportedPlatform indicates the host cannot run the BitBox02 simulator binary.

Functions

func Connect added in v0.5.0

func Connect(inst *Instance, opts ConnectOptions) (*firmware.Device, error)

Connect drives the post-Launch bring-up: firmware.NewDevice → Init → poll ChannelHash → ChannelHashVerify. Returns a Device that is ready to accept every BaselineScenarios call.

The simulator regenerates its app-keypair every run (no persistence), so we wire an in-memory ConfigInterface.

func Simulators

func Simulators() []coresim.Binary

Simulators returns the embedded list of BitBox02 simulator binaries the testkit knows about, sorted newest-first. Mirrors upstream's api/firmware/testdata/simulators.json.

Override the list at runtime by setting the BITBOX_SIMULATOR env var to an absolute path; Launch will use that instead.

Types

type ConnectOptions added in v0.5.0

type ConnectOptions struct {
	// HandshakeTimeout caps the wait for the simulator firmware to mark
	// the pairing channel as device-confirmed. The simulator auto-
	// confirms within a few hundred ms; 5s gives generous CI headroom.
	HandshakeTimeout time.Duration
	// Logger lets a caller route firmware-library logs somewhere; nil
	// uses a silent logger.
	Logger firmware.Logger
}

ConnectOptions tunes the bring-up. Zero values are sensible defaults.

type Instance

type Instance struct {
	Process *coresim.Process
	Conn    net.Conn
	Comm    firmware.Communication
}

Instance is a running BitBox02 simulator with an attached client.

func Launch

func Launch(cacheDir string) (*Instance, error)

Launch downloads (if needed) and starts the newest known simulator, connects via TCP, and returns an Instance ready for use with firmware.NewDevice.

cacheDir is where downloaded binaries live; reuse it across tests to avoid re-downloading.

func LaunchVersion added in v0.5.0

func LaunchVersion(cacheDir, name string) (*Instance, error)

LaunchVersion is Launch with an explicit binary version. Pass the `Name` field of one of Simulators() (e.g. "bitbox02-multi-9.21.0") or an empty string for the newest known build. The BITBOX_SIMULATOR env override (absolute path to a binary on disk) takes precedence over this argument — that lets a developer drop in a local debug build without needing to extend the embedded list.

Returns ErrSimulatorNotFound if the name does not match any embedded entry, which is a deliberately distinct error from ErrUnsupportedPlatform so the CLI's --firmware flag can give a helpful "did you mean…" hint.

func (*Instance) Stop

func (i *Instance) Stop()

Stop tears down the connection and kills the simulator subprocess.

type MemoryConfig added in v0.5.0

type MemoryConfig struct {
	// contains filtered or unexported fields
}

MemoryConfig is a minimal in-memory firmware.ConfigInterface. Suitable for throw-away simulator runs where the noise keypair does not need to survive the process.

func (*MemoryConfig) AddDeviceStaticPubkey added in v0.5.0

func (c *MemoryConfig) AddDeviceStaticPubkey(pubkey []byte) error

AddDeviceStaticPubkey records pubkey as trusted.

func (*MemoryConfig) ContainsDeviceStaticPubkey added in v0.5.0

func (c *MemoryConfig) ContainsDeviceStaticPubkey(pubkey []byte) bool

ContainsDeviceStaticPubkey returns true if pubkey was previously added.

func (*MemoryConfig) GetAppNoiseStaticKeypair added in v0.5.0

func (c *MemoryConfig) GetAppNoiseStaticKeypair() *noise.DHKey

GetAppNoiseStaticKeypair returns the persisted app keypair, or nil.

func (*MemoryConfig) SetAppNoiseStaticKeypair added in v0.5.0

func (c *MemoryConfig) SetAppNoiseStaticKeypair(key *noise.DHKey) error

SetAppNoiseStaticKeypair persists the app keypair.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL