walletbackup

package
v0.9.0-rc9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 11 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/openclaw, internal/hermes) compose these primitives with their own deployDir/keystoreDir conventions and namespace-specific cluster apply steps. The on-disk format must round-trip across runtimes, so a backup taken from an OpenClaw instance can restore into a Hermes one and vice versa.

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. Both Hermes and OpenClaw write the same shape, generated by their respective generateRemoteSignerValues.

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.

Jump to

Keyboard shortcuts

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