store

package
v0.101.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package store provides cryptographic utilities for secure token storage.

Package store provides database operations for chat app credentials.

Index

Constants

View Source
const (
	MaxPlatformUserID = 255  // Maximum length for platform user ID
	MaxAccessToken    = 2048 // Maximum length for access tokens
	MaxAppSecret      = 2048 // Maximum length for app secrets
	MaxWebhookURL     = 2048 // Maximum length for webhook URLs
)

Validation limits for chat app credential fields.

Variables

View Source
var (
	// ErrInvalidKey is returned when the encryption key is invalid.
	ErrInvalidKey = errors.New("invalid encryption key")
	// ErrInvalidCiphertext is returned when the ciphertext is invalid.
	ErrInvalidCiphertext = errors.New("invalid ciphertext")
)

Functions

func DecryptToken

func DecryptToken(ciphertext, key string) (string, error)

DecryptToken decrypts a token encrypted with EncryptToken.

func EncryptToken

func EncryptToken(plaintext, key string) (string, error)

EncryptToken encrypts a token using AES-256-GCM.

func GenerateKey

func GenerateKey() (string, error)

GenerateKey generates a random 256-bit (32 byte) encryption key. This should be run once to generate the DIVINESENSE_CHAT_APPS_SECRET_KEY.

Types

type ChatAppStore

type ChatAppStore struct {
	// contains filtered or unexported fields
}

ChatAppStore manages chat app credentials in the database.

func NewChatAppStore

func NewChatAppStore(db *sql.DB) *ChatAppStore

NewChatAppStore creates a new chat app store.

func (*ChatAppStore) CreateCredential

func (s *ChatAppStore) CreateCredential(ctx context.Context, req *CreateCredentialRequest) (*chat_apps.Credential, error)

CreateCredential creates a new chat app credential.

func (*ChatAppStore) DeleteCredential

func (s *ChatAppStore) DeleteCredential(ctx context.Context, id int64) error

DeleteCredential deletes a credential by ID.

func (*ChatAppStore) GetCredentialByPlatform

func (s *ChatAppStore) GetCredentialByPlatform(ctx context.Context, userID int32, platform chat_apps.Platform) (*chat_apps.Credential, error)

GetCredentialByPlatform retrieves a credential by user ID and platform.

func (*ChatAppStore) GetCredentialByPlatformUserID

func (s *ChatAppStore) GetCredentialByPlatformUserID(ctx context.Context, platform chat_apps.Platform, platformUserID string) (*chat_apps.Credential, error)

GetCredentialByPlatformUserID retrieves a credential by platform user ID. Used during webhook handling to find the DivineSense user.

func (*ChatAppStore) ListAllEnabled

func (s *ChatAppStore) ListAllEnabled(ctx context.Context) ([]*chat_apps.Credential, error)

ListAllEnabled lists all enabled credentials across all users. Used during service startup to initialize chat channels.

func (*ChatAppStore) ListCredentials

func (s *ChatAppStore) ListCredentials(ctx context.Context, userID int32, platformFilter chat_apps.Platform) ([]*chat_apps.Credential, error)

ListCredentials lists all credentials for a user.

func (*ChatAppStore) SetEnabled

func (s *ChatAppStore) SetEnabled(ctx context.Context, id int64, enabled bool) error

SetEnabled enables or disables a credential.

func (*ChatAppStore) UpdateCredential

func (s *ChatAppStore) UpdateCredential(ctx context.Context, req *UpdateCredentialRequest) (*chat_apps.Credential, error)

UpdateCredential updates a credential.

type CreateCredentialRequest

type CreateCredentialRequest struct {
	UserID         int32
	Platform       chat_apps.Platform
	PlatformUserID string
	PlatformChatID string
	AccessToken    string // Already encrypted
	AppSecret      string // Already encrypted
	WebhookURL     string
}

type UpdateCredentialRequest

type UpdateCredentialRequest struct {
	ID          int64
	AccessToken *string
	AppSecret   *string
	WebhookURL  *string
}

Jump to

Keyboard shortcuts

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