Help us shape the future of Go! Take the 2026 Go Developer Survey

walletbackup

package
v0.17.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package walletbackup is the runtime-agnostic core of `obol agent wallet backup` / `restore`. It owns the on-disk backup wire format, the AES-256-GCM encryption envelope, and the helpers that read/write the keystore password from values-remote-signer.yaml. Per-runtime callers (internal/hermes) compose these primitives with their own deployDir/keystoreDir conventions and namespace-specific cluster apply steps. The on-disk format is unchanged since OpenClaw (removed in v0.16) wrote it too, so a v0.15 OpenClaw backup still restores into Hermes.

Index

Constants

View Source
const Version = 1

Version is the current backup-format version. Bumping requires a parallel bump in Decode's accepted-versions check.

Variables

View Source
var Magic = []byte("OBOL")

Magic is the 4-byte prefix of an encrypted backup file.

Functions

func Decrypt

func Decrypt(data []byte, passphrase string) ([]byte, error)

Decrypt reverses Encrypt for the same passphrase, returning an error if the magic, version, or AEAD tag fails to verify.

func Encode

func Encode(f *File, passphrase string) ([]byte, bool, error)

Encode marshals a backup to bytes. If passphrase is non-empty, it returns an encrypted blob; otherwise it returns the indented JSON. The second return value reports which form was emitted.

func Encrypt

func Encrypt(plaintext []byte, passphrase string) ([]byte, error)

Encrypt wraps plaintext with AES-256-GCM under a scrypt-derived key. Layout: magic(4) | version(1) | salt(32) | nonce(12) | ciphertext+tag. Exported so callers (and crypto-only tests) can exercise the envelope without going through Encode's JSON marshalling step.

func IsEncrypted

func IsEncrypted(data []byte) bool

IsEncrypted reports whether data carries the OBOL magic prefix.

func PromptPassphrase

func PromptPassphrase(flagValue string, hasFlag bool, u *ui.UI) (string, error)

PromptPassphrase resolves a passphrase for backup. If the caller already passed --passphrase explicitly, hasFlag=true short-circuits the prompt (even when flagValue is the empty string, which means "no encryption").

func ReadKeystorePassword

func ReadKeystorePassword(deployDir string) (string, error)

ReadKeystorePassword extracts keystorePassword.value from values-remote-signer.yaml under deployDir (the shape generateRemoteSignerValues writes).

func WriteValuesRemoteSigner

func WriteValuesRemoteSigner(deployDir, content string) error

WriteValuesRemoteSigner writes the rendered values-remote-signer.yaml to deployDir. Callers pass the runtime-specific rendered content (the YAML shape is identical across runtimes, but the comment header differs).

Types

type File

type File struct {
	Version  int      `json:"version"`
	Instance string   `json:"instance"`
	Wallets  []Wallet `json:"wallets"`
}

File is the JSON shape of a wallet backup. One backup may carry multiple wallets; today both runtimes write a single-wallet file.

func Decode

func Decode(data []byte, passphrase string) (*File, error)

Decode parses raw bytes into a File. If the input starts with the OBOL magic, passphrase is required; otherwise it must be empty (or is ignored).

type Wallet

type Wallet struct {
	Address          string          `json:"address"`
	PublicKey        string          `json:"publicKey"`
	KeystoreUUID     string          `json:"keystoreUUID"`
	CreatedAt        string          `json:"createdAt"`
	Keystore         json.RawMessage `json:"keystore"`
	KeystorePassword string          `json:"keystorePassword"`
}

Wallet holds a single wallet's backup data — enough to restore both the keystore JSON on disk and the keystore password the remote-signer needs.

func (Wallet) VerifyKeystore added in v0.17.0

func (w Wallet) VerifyKeystore() error

VerifyKeystore decrypts the wallet's V3 keystore with its recorded password and checks that the derived address is the recorded one. The decrypted key never leaves this function; only addresses appear in the returned error. go-ethereum's decoder is used so keystores imported from other tools (pbkdf2 KDF) verify too.

Jump to

Keyboard shortcuts

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