tty

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const BundlePassphraseEnv = "KPOT_BUNDLE_PASSPHRASE"

BundlePassphraseEnv is a SEPARATE env var for bundle creation / import. Distinct from PassphraseEnv on purpose — bundle passphrases are typically meant to be shared with a recipient (different secret than your everyday vault passphrase). Reusing KPOT_PASSPHRASE for bundle ops would silently make bundle pw == vault pw, defeating the "share the bundle pw out-of-band" mental model.

View Source
const PassphraseEnv = "KPOT_PASSPHRASE"

PassphraseEnv is the environment variable that bypasses the TTY prompt for VAULT-OPENING passphrases. Useful for scripted/non- interactive runs; printed warning on stderr so users notice when they leave it set in production.

Variables

View Source
var ErrNoTTY = errors.New("recovery operations require a TTY (no pipes / redirects allowed)")

ErrNoTTY is returned by recovery-display helpers when stdin/stdout aren't terminals. The pipe-or-redirect case is rejected on purpose: secrets must not flow into log files, scrollback buffers, or CI artifacts. Users running scripted setups have to take the manual route (init interactively, then automate after).

Functions

func DisplayRecoveryOnce

func DisplayRecoveryOnce(header, body string) error

DisplayRecoveryOnce shows a recovery secret directly to the user's terminal (NOT into stdout/stderr if those have been redirected somewhere capturable), waits for the user to acknowledge, and then ANSI-clears the screen. There is no API to redisplay; lose the paper, lose the recovery.

On Unix the sink is `/dev/tty` (so even with stdout/stderr piped to a logger, the secret never reaches the pipe). On Windows there's no /dev/tty, so the sink is os.Stdout — which is the actual console because the IsStdinTTY/IsStdoutTTY check above ensures we only run when both ends are real terminals.

header is the leading "WRITE THIS DOWN" warning block. body is the secret itself (mnemonic words or formatted secret-key string).

func FormatSeedWords

func FormatSeedWords(mnemonic string) string

FormatSeedWords renders 12/24 BIP-39 words as a 4-column numbered grid for easy hand-copying.

func IsStdinTTY

func IsStdinTTY() bool

IsStdinTTY reports whether stdin is connected to a real terminal. Wraps golang.org/x/term so callers (cmd/kpot, recovery flows) don't each grow their own implementation with subtly different semantics.

func IsStdoutTTY

func IsStdoutTTY() bool

IsStdoutTTY mirrors IsStdinTTY for stdout. Used by display flows that must refuse to write secrets when the destination is captured.

func ReadBundlePassphrase

func ReadBundlePassphrase(prompt string) ([]byte, error)

ReadBundlePassphrase reads a bundle-only passphrase. Same shape as ReadPassphrase, but consults BundlePassphraseEnv instead of PassphraseEnv so a vault-unlock env var doesn't silently determine the bundle's passphrase too. The bundle passphrase is intended to be shared with a recipient out-of-band; defaulting to the vault's passphrase would defeat that.

func ReadLine

func ReadLine(prompt string) (string, error)

ReadLine prompts on stderr and reads one line of (echoed) input as a string. Use this for non-sensitive input only; sensitive input should go through ReadLineSecret so the caller can zero the buffer.

func ReadLineSecret

func ReadLineSecret(prompt string) ([]byte, error)

ReadLineSecret reads one line of (echoed) input as a byte slice the caller is expected to crypto.Zero after use. Use for recovery secrets (seed phrases, recovery keys) so the user-typed bytes can be wiped explicitly.

Caveat: bufio.Reader internally buffers a copy we cannot reach, and any string-typed downstream operation (e.g. BIP-39 validation) will produce a string copy that lives until GC. This wipe is best-effort, not airtight — same posture as crypto.Zero for keys.

func ReadNewPassphrase

func ReadNewPassphrase(prompt, confirmPrompt string) ([]byte, error)

ReadNewPassphrase prompts twice and verifies the entries match.

func ReadPassphrase

func ReadPassphrase(prompt string) ([]byte, error)

ReadPassphrase prompts the user for a passphrase with no echo. Falls back to plain stdin reading if the input is not a terminal (useful for tests piping a passphrase). All non-TTY reads go through a single shared bufio.Reader so consecutive prompts don't lose lines to per-call buffering.

If the KPOT_PASSPHRASE environment variable is set, its value is returned without prompting (and a one-time warning is printed to stderr so the user knows the bypass is active).

func ResetEnvWarnForTest

func ResetEnvWarnForTest()

ResetEnvWarnForTest re-arms the once-per-process warning that fires when KPOT_PASSPHRASE is set. Tests that exercise multiple bypass paths in one binary need this; production code never calls it.

func SharedStdin

func SharedStdin() *bufio.Reader

SharedStdin returns a process-wide bufio.Reader bound to os.Stdin. Multiple subsystems (passphrase prompt, REPL) MUST share one reader, otherwise eager bufio buffering in one reader silently swallows lines the next reader expects to see.

Types

This section is empty.

Jump to

Keyboard shortcuts

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