Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeBinding(sources []BindingSource) []byte
- func Decrypt(key, ciphertext, nonce, tag, aad []byte) ([]byte, error)
- func DefaultVaultPath() string
- func DeriveKey(bindingID, salt []byte, memory, iterations int) ([]byte, error)
- func Encrypt(key, plaintext, aad, nonce []byte) (ciphertext, outNonce, tag []byte, err error)
- type BindingSource
- type Config
- type Mode
- type OpenResult
- type Vault
- func (v *Vault) Delete(key string)
- func (v *Vault) Get(key string) interface{}
- func (v *Vault) Has(key string) bool
- func (v *Vault) IsOpen() bool
- func (v *Vault) IsUnlocked() bool
- func (v *Vault) Keys() []string
- func (v *Vault) Lock()
- func (v *Vault) Open() (OpenResult, error)
- func (v *Vault) Path() string
- func (v *Vault) Save() error
- func (v *Vault) Set(key string, value interface{})
- func (v *Vault) Unlock() error
Constants ¶
const ( DefaultMemory = 256 * 1024 * 1024 // bytes DefaultIterations = 3 )
Defaults matching the JS implementation's deriveKey defaults.
Variables ¶
var ( ErrNotOpen = errors.New("mrcv: vault is not open") ErrAlreadyOpen = errors.New("mrcv: vault is already open") ErrBindingMismatch = errors.New("mrcv: device binding does not match") ErrInvalidMode = errors.New("mrcv: invalid mode (must be 'bound' or 'strict')") ErrInvalidConfig = errors.New("mrcv: invalid config") ErrDecryptionFailed = errors.New("mrcv: decryption failed") )
Errors returned by the vault.
Functions ¶
func ComputeBinding ¶
func ComputeBinding(sources []BindingSource) []byte
ComputeBinding produces the 32-byte binding ID: SHA-256 of the concatenation of every source value separated by '|'. If no source produced data, the platform name is hashed instead (so the vault still binds to "this OS", not to an empty string).
func Decrypt ¶
Decrypt opens ciphertext with XChaCha20-Poly1305. It must be given the SAME aad used at encryption.
func DefaultVaultPath ¶
func DefaultVaultPath() string
DefaultVaultPath mirrors the JS default: ~/.config/@minerouter/mrcv/storage.mrcv on non-Windows, %APPDATA%/@minerouter/mrcv/storage.mrcv on Windows.
func DeriveKey ¶
DeriveKey runs Argon2id over the binding ID to produce the 32-byte encryption key. Must match libsodium's crypto_pwhash(ARGON2ID13) with the same opslimit/memlimit/parallelism.
func Encrypt ¶
Encrypt seals plaintext with XChaCha20-Poly1305, returning ciphertext, the 24-byte nonce, and the 16-byte tag. aad (the file header) is bound to the ciphertext. If nonce is nil, a fresh one is generated. The caller MUST build the aad from a header that already contains the nonce (matching the JS implementation, where the nonce is created before the header).
Types ¶
type BindingSource ¶
BindingSource is one device fingerprint that contributes to the binding ID.
func DefaultBindingSources ¶
func DefaultBindingSources() []BindingSource
DefaultBindingSources are the Linux device fingerprints used to compute the binding ID. Order matters — it must match the JS implementation.
type Config ¶
type Config struct {
Path string // .mrcv file location; defaults to ~/.config/@minerouter/mrcv/storage.mrcv
Mode Mode // bound (default) or strict
BindingSources []BindingSource // optional custom device-binding sources
Memory int // Argon2id memory in bytes, default 256 MiB
Iterations int // Argon2id iterations, default 3
}
Config configures a Vault. Path is required; everything else has defaults.
type Mode ¶
type Mode string
Mode controls what happens when the vault is opened on a machine whose device binding does not match.
type OpenResult ¶
type OpenResult struct {
// State: "unlocked" (vault ready, created = first-time) or "mismatch"
// (device binding does not match).
State string
Created bool
}
OpenResult is the outcome of Open.
type Vault ¶
type Vault struct {
// contains filtered or unexported fields
}
Vault is a device-bound encrypted key-value store. It mirrors the JS Vault API: Open -> Unlock -> Get/Set/... -> Save, with bound/strict modes.
func (*Vault) IsUnlocked ¶
IsUnlocked reports whether the payload is decrypted.
func (*Vault) Lock ¶
func (v *Vault) Lock()
Lock clears the decrypted data (keys are removed from memory).
func (*Vault) Open ¶
func (v *Vault) Open() (OpenResult, error)
Open computes the device binding and either opens an existing vault or creates a new one. On mismatch in strict mode the file is destroyed.