Documentation
¶
Index ¶
- Constants
- Variables
- func AcknowledgeDiskRecoveryKey(dataDir string) error
- func ChangeDiskSyncPassphrase(ctx context.Context, dataDir, newPassphrase string, rotateRecovery bool, ...) (string, error)
- func ConfigureDiskSyncWithCredential(ctx context.Context, dataDir, rawSyncDir string, cred UnlockCredential, ...) (savedDir, recoveryKey string, err error)
- func DeleteLocalVEK(dataDir, vaultID string) error
- func DeletePendingRecoveryKey(dataDir, vaultID string) error
- func LoadLocalVEK(dataDir, vaultID string) ([vekSize]byte, bool, error)
- func LoadPendingRecoveryKey(dataDir, vaultID string) string
- func LockDiskSync(dataDir string) error
- func SaveLocalVEK(dataDir, vaultID string, vek [vekSize]byte) error
- func SavePendingRecoveryKey(dataDir, vaultID, formattedKey string) error
- func UnlockDiskSyncWithCredential(ctx context.Context, dataDir string, cred UnlockCredential) error
- func VerifyVaultCredential(syncDir string, cred UnlockCredential) error
- type Argon2Params
- type CredentialKind
- type KeySlot
- type LocalDirTransport
- func (t *LocalDirTransport) EnsureLayout(_ context.Context) error
- func (t *LocalDirTransport) HasAnySyncArtifacts(_ context.Context) (bool, error)
- func (t *LocalDirTransport) ListDeviceChunks(_ context.Context, deviceID string) ([]string, error)
- func (t *LocalDirTransport) ListDevices(_ context.Context) ([]string, error)
- func (t *LocalDirTransport) ListSnapshots(_ context.Context) ([]string, error)
- func (t *LocalDirTransport) OpenBlob(_ context.Context, blobIDHex string) (io.ReadCloser, error)
- func (t *LocalDirTransport) ReadChunk(_ context.Context, deviceID, fileName string) ([]byte, error)
- func (t *LocalDirTransport) ReadManifest(_ context.Context) ([]byte, error)
- func (t *LocalDirTransport) ReadSnapshot(_ context.Context, fileName string) ([]byte, error)
- func (t *LocalDirTransport) StatBlob(_ context.Context, blobIDHex string) (bool, error)
- func (t *LocalDirTransport) WriteBlobStream(_ context.Context, blobIDHex string, writeFn func(w io.Writer) error) error
- func (t *LocalDirTransport) WriteChunk(_ context.Context, deviceID, fileName string, data []byte) error
- func (t *LocalDirTransport) WriteManifest(_ context.Context, data []byte) error
- func (t *LocalDirTransport) WriteSnapshot(_ context.Context, fileName string, data []byte) error
- type Manager
- func (m *Manager) AcknowledgeRecoveryKey() error
- func (m *Manager) ChangePassphrase(ctx context.Context, newPassphrase string, rotateRecovery bool) (string, error)
- func (m *Manager) Close()
- func (m *Manager) Disconnect(ctx context.Context) error
- func (m *Manager) Enabled() bool
- func (m *Manager) FlushOutbox(ctx context.Context) (*SyncReport, error)
- func (m *Manager) Lock(ctx context.Context) error
- func (m *Manager) Locked() bool
- func (m *Manager) Reconfigure(ctx context.Context, rawSyncDir string) (*SyncReport, error)
- func (m *Manager) ReconfigureWithCredential(ctx context.Context, rawSyncDir string, cred UnlockCredential) (*SyncReport, error)
- func (m *Manager) SetOnStatusChange(fn func(SyncStatus))
- func (m *Manager) Start(ctx context.Context)
- func (m *Manager) Status() SyncStatus
- func (m *Manager) SyncDir() string
- func (m *Manager) SyncNow(ctx context.Context) (*SyncReport, error)
- func (m *Manager) Unlock(ctx context.Context, cred UnlockCredential) (*SyncReport, error)
- type Manifest
- type ManifestEncryption
- type ManifestKeySlots
- type OpRecord
- type Options
- type SnapshotDoc
- type SyncReport
- type SyncState
- type SyncStatus
- type Transport
- type UnlockCredential
- type VaultInspection
- type VaultInspectionState
Constants ¶
const ( // ManifestSchemaVersion is the on-disk E2EE OpLog sync format version. ManifestSchemaVersion = 2 // EncryptionModeV1 identifies Mote's XChaCha20-Poly1305 + Argon2id/HKDF E2EE vault format. EncryptionModeV1 = "e2ee-xchacha20poly1305-v1" // Encrypted on-disk file extensions inside <sync_dir>. ChunkFileExt = ".moteop" SnapshotFileExt = ".motesnap" BlobFileExt = ".moteblob" // MinPassphraseLen is the minimum character count required for a sync passphrase. MinPassphraseLen = 8 )
Variables ¶
var ( // ErrSyncLocked indicates the sync folder is configured and encrypted, but this machine // does not currently hold the unwrapped vault key (VEK). ErrSyncLocked = errors.New("sync folder is locked: enter passphrase or recovery key to unlock") // ErrPassphraseRequired indicates initializing a brand-new encrypted sync folder requires a passphrase. ErrPassphraseRequired = errors.New("passphrase is required to initialize encrypted sync folder") // ErrPassphraseTooShort indicates the supplied passphrase is shorter than MinPassphraseLen characters. ErrPassphraseTooShort = fmt.Errorf("passphrase must be at least %d characters", MinPassphraseLen) // ErrInvalidCredentials indicates the supplied passphrase or recovery key failed to unwrap the vault key. ErrInvalidCredentials = errors.New("incorrect passphrase or recovery key") )
var DefaultArgon2Params = Argon2Params{
Time: 3,
MemoryKiB: 64 * 1024,
Threads: 4,
}
DefaultArgon2Params defines production Argon2id parameters (64 MiB, t=3, p=4).
Functions ¶
func AcknowledgeDiskRecoveryKey ¶
AcknowledgeDiskRecoveryKey clears the locally staged pending recovery key when no live Manager is attached.
func ChangeDiskSyncPassphrase ¶
func ChangeDiskSyncPassphrase(ctx context.Context, dataDir, newPassphrase string, rotateRecovery bool, kdfOverride *Argon2Params) (string, error)
ChangeDiskSyncPassphrase rotates the sync passphrase in manifest.json in O(1) when no live Manager is attached.
func ConfigureDiskSyncWithCredential ¶
func ConfigureDiskSyncWithCredential(ctx context.Context, dataDir, rawSyncDir string, cred UnlockCredential, kdfOverride *Argon2Params) (savedDir, recoveryKey string, err error)
ConfigureDiskSyncWithCredential initializes or unlocks an encrypted sync folder on disk and persists <dataDir>/sync.json + <dataDir>/keys/<vault_id>.key when no live Manager is attached.
func DeleteLocalVEK ¶
DeleteLocalVEK removes the cached local VEK for vaultID so the machine enters locked state.
func DeletePendingRecoveryKey ¶
DeletePendingRecoveryKey clears the locally staged recovery key once the user confirms saving it.
func LoadLocalVEK ¶
LoadLocalVEK loads the cached 32-byte VEK from <data_dir>/keys/<vault_id>.key. Returns (zero, false, nil) when the key file does not exist.
func LoadPendingRecoveryKey ¶
LoadPendingRecoveryKey returns the unacknowledged recovery key for vaultID, or "" if acknowledged/absent.
func LockDiskSync ¶
LockDiskSync removes the local cached VEK for the configured sync folder when no live Manager is attached.
func SaveLocalVEK ¶
SaveLocalVEK atomically persists the unwrapped 32-byte VEK under <data_dir>/keys/<vault_id>.key with owner-only permissions (0700 dir, 0600 file). This file stays strictly inside <data_dir> (never inside <sync_dir>) so Desktop, CLI, and MCP share unlocked state with zero OS popup prompts.
func SavePendingRecoveryKey ¶
SavePendingRecoveryKey stores an unacknowledged one-time recovery key locally under <data_dir>/keys/<vault_id>.recovery (0600, never synced) until the user explicitly confirms saving it via AcknowledgeRecoveryKey. Prevents losing recovery keys on transient sync errors, deferred onboarding transitions, or restarts.
func UnlockDiskSyncWithCredential ¶
func UnlockDiskSyncWithCredential(ctx context.Context, dataDir string, cred UnlockCredential) error
UnlockDiskSyncWithCredential unlocks the configured sync folder on disk when no live Manager is attached.
func VerifyVaultCredential ¶
func VerifyVaultCredential(syncDir string, cred UnlockCredential) error
VerifyVaultCredential performs a strictly read-only credential check against <syncDir>/manifest.json.
Types ¶
type Argon2Params ¶
Argon2Params configures Argon2id key derivation for wrapping the master vault key.
type CredentialKind ¶
type CredentialKind string
CredentialKind explicitly distinguishes how an UnlockCredential should unwrap manifest.json.
const ( CredentialAuto CredentialKind = "auto" CredentialPassphrase CredentialKind = "passphrase" CredentialRecovery CredentialKind = "recovery" )
type KeySlot ¶
type KeySlot struct {
KDF string `json:"kdf"`
Salt string `json:"salt"`
Time uint32 `json:"time,omitempty"`
MemoryKiB uint32 `json:"memory_kib,omitempty"`
Threads uint8 `json:"threads,omitempty"`
Nonce string `json:"nonce"`
WrappedVEK string `json:"wrapped_vek"`
}
KeySlot stores one KDF + XChaCha20-Poly1305 wrapped copy of the 256-bit VEK.
type LocalDirTransport ¶
type LocalDirTransport struct {
// contains filtered or unexported fields
}
LocalDirTransport implements Transport over a mounted local or cloud-drive folder.
func NewLocalDirTransport ¶
func NewLocalDirTransport(syncDir string) *LocalDirTransport
NewLocalDirTransport constructs a LocalDirTransport rooted at syncDir.
func (*LocalDirTransport) EnsureLayout ¶
func (t *LocalDirTransport) EnsureLayout(_ context.Context) error
func (*LocalDirTransport) HasAnySyncArtifacts ¶
func (t *LocalDirTransport) HasAnySyncArtifacts(_ context.Context) (bool, error)
func (*LocalDirTransport) ListDeviceChunks ¶
func (*LocalDirTransport) ListDevices ¶
func (t *LocalDirTransport) ListDevices(_ context.Context) ([]string, error)
func (*LocalDirTransport) ListSnapshots ¶
func (t *LocalDirTransport) ListSnapshots(_ context.Context) ([]string, error)
func (*LocalDirTransport) OpenBlob ¶
func (t *LocalDirTransport) OpenBlob(_ context.Context, blobIDHex string) (io.ReadCloser, error)
func (*LocalDirTransport) ReadManifest ¶
func (t *LocalDirTransport) ReadManifest(_ context.Context) ([]byte, error)
func (*LocalDirTransport) ReadSnapshot ¶
func (*LocalDirTransport) WriteBlobStream ¶
func (*LocalDirTransport) WriteChunk ¶
func (*LocalDirTransport) WriteManifest ¶
func (t *LocalDirTransport) WriteManifest(_ context.Context, data []byte) error
func (*LocalDirTransport) WriteSnapshot ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates end-to-end encrypted OpLog folder synchronization between a local SQLite database (always stored on local disk, e.g. ~/.mote) and a user-chosen Sync Folder (Google Drive, iCloud Drive, Dropbox, Syncthing, or a custom Transport).
func New ¶
New constructs an E2EE Sync Folder Manager. Call Start(ctx) to run background debounced pushing and polling, or call SyncNow(ctx) directly for deterministic one-shot CLI/test synchronization.
func OpenForDataDir ¶
func OpenForDataDir(store *db.SQLStore, dataDir string, onRemoteApplied func(SyncReport)) (*Manager, error)
OpenForDataDir loads <dataDir>/sync.json (honoring MOTE_SYNC_DIR and MOTE_SYNC_PASSPHRASE) and constructs a Manager bound to store.
func (*Manager) AcknowledgeRecoveryKey ¶
AcknowledgeRecoveryKey removes the locally staged pending recovery key after the user confirms saving it.
func (*Manager) ChangePassphrase ¶
func (m *Manager) ChangePassphrase(ctx context.Context, newPassphrase string, rotateRecovery bool) (string, error)
ChangePassphrase re-wraps the existing VEK inside manifest.json in O(1) without re-encrypting any historical OpLog chunks, snapshots, or blobs. Optionally rotates the Recovery Key slot as well.
func (*Manager) Close ¶
func (m *Manager) Close()
Close stops the background sync loop and performs a best-effort final push of pending local outbox ops.
func (*Manager) Disconnect ¶
Disconnect disables folder synchronization and returns Mote to local-only mode (~/.mote) without deleting any local notes or any encrypted files already written to the Sync Folder.
func (*Manager) FlushOutbox ¶
func (m *Manager) FlushOutbox(ctx context.Context) (*SyncReport, error)
FlushOutbox encrypts and pushes any pending local sync_outbox entries (and missing local blobs) without running a full remote pull. Returns immediately in O(1) when sync_outbox is empty.
func (*Manager) Lock ¶
Lock clears the cached local VEK from memory and <data_dir>/keys/ and transitions the Manager into StateLocked. Local SQLite editing and sync_outbox capture remain active while Push/Pull pause.
func (*Manager) Locked ¶
Locked reports whether the configured Sync Folder is currently awaiting unlock on this machine.
func (*Manager) Reconfigure ¶
Reconfigure live-switches or disables the Sync Folder using the cached local key or preset passphrase.
func (*Manager) ReconfigureWithCredential ¶
func (m *Manager) ReconfigureWithCredential(ctx context.Context, rawSyncDir string, cred UnlockCredential) (*SyncReport, error)
ReconfigureWithCredential live-switches or initializes an encrypted Sync Folder using cred. Validates the target folder and credentials BEFORE persisting <data_dir>/sync.json.
func (*Manager) SetOnStatusChange ¶
func (m *Manager) SetOnStatusChange(fn func(SyncStatus))
SetOnStatusChange registers or replaces the status transition callback (thread-safe).
func (*Manager) Start ¶
Start launches the background sync loop (debounced local push + periodic remote pull/unlock probe).
func (*Manager) Status ¶
func (m *Manager) Status() SyncStatus
Status returns a thread-safe snapshot of the current Sync Folder status.
func (*Manager) SyncNow ¶
func (m *Manager) SyncNow(ctx context.Context) (*SyncReport, error)
SyncNow executes a complete serialized E2EE synchronization pass.
func (*Manager) Unlock ¶
func (m *Manager) Unlock(ctx context.Context, cred UnlockCredential) (*SyncReport, error)
Unlock unwraps the active sync vault's VEK using a passphrase or recovery key, caches it locally, and immediately runs a full synchronization pass to flush queued local edits and pull remote changes.
type Manifest ¶
type Manifest struct {
SchemaVersion int `json:"schema_version"`
VaultID string `json:"vault_id"`
CreatedAt int64 `json:"created_at"`
Encryption *ManifestEncryption `json:"encryption"`
}
Manifest lives at <sync_dir>/manifest.json and holds only the vault identifier and key-wrapping metadata (zero note titles, folders, or host/device identifiers).
type ManifestEncryption ¶
type ManifestEncryption struct {
Mode string `json:"mode"`
KeyCommitment string `json:"key_commitment"`
Slots ManifestKeySlots `json:"slots"`
}
ManifestEncryption stores the AEAD suite identifier, key commitment, and dual unlock slots.
type ManifestKeySlots ¶
type ManifestKeySlots struct {
Passphrase KeySlot `json:"passphrase"`
Recovery KeySlot `json:"recovery"`
}
ManifestKeySlots wraps the same 256-bit VEK under both user passphrase and recovery key.
type OpRecord ¶
type OpRecord struct {
HLC string `json:"hlc"`
DeviceID string `json:"device_id"`
EntityType db.SyncEntityType `json:"entity_type"`
EntityID string `json:"entity_id"`
OpType db.SyncOpType `json:"op_type"`
BaseHLC string `json:"base_hlc,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
}
OpRecord is a single immutable operation inside an encrypted .moteop chunk file.
type Options ¶
type Options struct {
Store *db.SQLStore
DataDir string
SyncDir string
DeviceID string
Passphrase string
Transport Transport
KDFParams *Argon2Params
DebounceDelay time.Duration
PollInterval time.Duration
SnapshotThreshold int
// OnRemoteApplied is called whenever remote ops or blobs changed local SQLite/assets
// (e.g. to broadcast SSE events and refresh Desktop AppState).
OnRemoteApplied func(report SyncReport)
// OnStatusChange is called whenever Manager's SyncStatus transitions.
OnStatusChange func(status SyncStatus)
}
Options configures a Sync Folder Manager.
type SnapshotDoc ¶
type SnapshotDoc struct {
SchemaVersion int `json:"schema_version"`
VaultID string `json:"vault_id"`
SnapshotHLC string `json:"snapshot_hlc"`
CreatedBy string `json:"created_by"`
CreatedAt int64 `json:"created_at"`
Folders []model.Folder `json:"folders,omitempty"`
Databases []model.Database `json:"databases,omitempty"`
PropertyDefs []model.PropertyDefinition `json:"property_defs,omitempty"`
Views []model.View `json:"views,omitempty"`
Notes []model.Note `json:"notes,omitempty"`
NotePropValues []model.NotePropertyValue `json:"note_prop_values,omitempty"`
Blobs []model.Blob `json:"blobs,omitempty"`
Templates []model.Template `json:"templates,omitempty"`
Whiteboards []model.Whiteboard `json:"whiteboards,omitempty"`
CommentThreads []model.CommentThread `json:"comment_threads,omitempty"`
CommentMessages []model.CommentMessage `json:"comment_messages,omitempty"`
EntityHeads []db.SyncEntityHead `json:"entity_heads,omitempty"`
Tombstones []db.SyncTombstone `json:"tombstones,omitempty"`
}
SnapshotDoc is a full compacted state snapshot stored at <sync_dir>/snapshots/snap_<hlc>_<sha8>.motesnap.
type SyncReport ¶
type SyncReport struct {
VaultID string `json:"vault_id,omitempty"`
DeviceID string `json:"device_id,omitempty"`
SyncDir string `json:"sync_dir,omitempty"`
RecoveryKey string `json:"recovery_key,omitempty"`
BaselineSeeded int `json:"baseline_seeded"`
PushedOps int `json:"pushed_ops"`
PushedChunks int `json:"pushed_chunks"`
PulledSnapshots int `json:"pulled_snapshots"`
PulledChunks int `json:"pulled_chunks"`
PulledOps int `json:"pulled_ops"`
ConflictsSaved int `json:"conflicts_saved"`
ConflictNoteIDs []string `json:"conflict_note_ids,omitempty"`
BlobsPushed int `json:"blobs_pushed"`
BlobsPulled int `json:"blobs_pulled"`
SnapshotWritten bool `json:"snapshot_written"`
SkippedMalformed int `json:"skipped_malformed"`
}
SyncReport summarizes a single Push + Pull + Blob synchronization pass.
type SyncState ¶
type SyncState string
SyncState describes the live operational state of the Sync Folder manager.
type SyncStatus ¶
type SyncStatus struct {
Enabled bool `json:"enabled"`
Encrypted bool `json:"encrypted"`
Locked bool `json:"locked"`
SyncDir string `json:"sync_dir,omitempty"`
LocalDataDir string `json:"local_data_dir,omitempty"`
DeviceID string `json:"device_id,omitempty"`
VaultID string `json:"vault_id,omitempty"`
PendingRecoveryKey string `json:"pending_recovery_key,omitempty"`
State SyncState `json:"state"`
LastSyncedAt int64 `json:"last_synced_at,omitempty"`
LastError string `json:"last_error,omitempty"`
PendingOps int `json:"pending_ops"`
LastPushedOps int `json:"last_pushed_ops"`
LastPulledOps int `json:"last_pulled_ops"`
LastConflicts int `json:"last_conflicts"`
}
SyncStatus is a thread-safe snapshot of current Sync Folder state for Desktop UI, HTTP API, and CLI.
func StatusFromConfig ¶
func StatusFromConfig(dataDir string) SyncStatus
StatusFromConfig builds a read-only SyncStatus snapshot from <dataDir>/sync.json when no live Manager is attached (e.g. deferred first-run UI or lightweight server/UI tests).
type Transport ¶
type Transport interface {
EnsureLayout(ctx context.Context) error
ReadManifest(ctx context.Context) ([]byte, error)
WriteManifest(ctx context.Context, data []byte) error
HasAnySyncArtifacts(ctx context.Context) (bool, error)
ListDevices(ctx context.Context) ([]string, error)
ListDeviceChunks(ctx context.Context, deviceID string) ([]string, error)
ReadChunk(ctx context.Context, deviceID, fileName string) ([]byte, error)
WriteChunk(ctx context.Context, deviceID, fileName string, data []byte) error
ListSnapshots(ctx context.Context) ([]string, error)
ReadSnapshot(ctx context.Context, fileName string) ([]byte, error)
WriteSnapshot(ctx context.Context, fileName string, data []byte) error
StatBlob(ctx context.Context, blobIDHex string) (bool, error)
OpenBlob(ctx context.Context, blobIDHex string) (io.ReadCloser, error)
WriteBlobStream(ctx context.Context, blobIDHex string, writeFn func(w io.Writer) error) error
}
Transport abstracts byte-level storage operations against the encrypted remote sync store. Today LocalDirTransport targets a mounted local/cloud-drive directory (Google Drive, iCloud, Dropbox, Syncthing); future cloud deployments can plug in an HTTPS/S3 relay implementing this exact interface without modifying encryption, framing, or merge code.
type UnlockCredential ¶
type UnlockCredential struct {
Kind CredentialKind `json:"kind,omitempty"`
Secret string `json:"secret,omitempty"`
}
UnlockCredential carries a user-supplied secret along with its explicit slot intent.
func AutoCredential ¶
func AutoCredential(secret string) UnlockCredential
AutoCredential constructs an UnlockCredential for single-field UI inputs or env vars.
func PassphraseCredential ¶
func PassphraseCredential(passphrase string) UnlockCredential
PassphraseCredential constructs an UnlockCredential that strictly targets the passphrase slot.
func RecoveryCredential ¶
func RecoveryCredential(recoveryKey string) UnlockCredential
RecoveryCredential constructs an UnlockCredential that strictly targets the recovery-key slot.
func (UnlockCredential) EffectiveKind ¶
func (c UnlockCredential) EffectiveKind() CredentialKind
EffectiveKind normalizes an omitted Kind to CredentialAuto.
func (UnlockCredential) IsEmpty ¶
func (c UnlockCredential) IsEmpty() bool
IsEmpty reports whether no secret material is present.
type VaultInspection ¶
type VaultInspection struct {
State VaultInspectionState
Manifest *Manifest
Keyring *vaultKeyring
VaultID string
Err error
}
VaultInspection is the single source of truth for manifest validity and local key commitment.
func InspectSyncFolder ¶
func InspectSyncFolder(dataDir, rawSyncDir string) VaultInspection
InspectSyncFolder performs an authoritative read-only check on rawSyncDir against dataDir, validating manifest.json and verifying any cached local VEK against key_commitment.
type VaultInspectionState ¶
type VaultInspectionState uint8
VaultInspectionState describes the authoritative read-only status of a Sync Folder on disk.
const ( VaultEmpty VaultInspectionState = iota VaultUnlocked VaultLocked VaultInvalid )