models

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TwoFactorTypeNone  = TwoFactorType("none")
	TwoFactorTypeEmail = TwoFactorType("email")
)
View Source
var (
	TwoFactorCredentialTOTP      = TwoFactorCredentialType("totp")
	TwoFactorCredentialYubicoOTP = TwoFactorCredentialType("yubico_otp")
)

Functions

func SpaceModels added in v0.11.1

func SpaceModels() []any

SpaceModels lists the space tables for migration.

Types

type Actor

type Actor struct {
	Did    string `gorm:"primaryKey"`
	Handle string `gorm:"uniqueIndex"`
}

type Blob

type Blob struct {
	ID        uint
	CreatedAt string `gorm:"index"`
	Did       string `gorm:"index;index:idx_blob_did_cid"`
	Cid       []byte `gorm:"index;index:idx_blob_did_cid"`
	RefCount  int
	Storage   string `gorm:"default:sqlite"`
}

type BlobPart

type BlobPart struct {
	Blob   Blob
	BlobID uint `gorm:"primaryKey"`
	Idx    int  `gorm:"primaryKey"`
	Data   []byte
}

type Block

type Block struct {
	Did   string `gorm:"primaryKey;index:idx_blocks_by_rev"`
	Cid   []byte `gorm:"primaryKey"`
	Rev   string `gorm:"index:idx_blocks_by_rev,sort:desc"`
	Value []byte
}

type EventRecord added in v0.8.4

type EventRecord struct {
	Seq       int64 `gorm:"primaryKey;autoIncrement:false"`
	CreatedAt time.Time
	Did       string `gorm:"index"`
	Type      string
	Data      []byte
}

type InviteCode

type InviteCode struct {
	Code              string `gorm:"primaryKey"`
	Did               string `gorm:"index"`
	RemainingUseCount int
}

type Record

type Record struct {
	Did       string `gorm:"primaryKey:idx_record_did_created_at;index:idx_record_did_nsid"`
	CreatedAt string `gorm:"index;index:idx_record_did_created_at,sort:desc"`
	Nsid      string `gorm:"primaryKey;index:idx_record_did_nsid"`
	Rkey      string `gorm:"primaryKey"`
	Cid       string
	Value     []byte
}

type RefreshToken

type RefreshToken struct {
	Token          string `gorm:"primaryKey"`
	Did            string `gorm:"index"`
	SessionVersion int64  `gorm:"not null;default:0"`
	CreatedAt      time.Time
	ExpiresAt      time.Time `gorm:"index:,sort:asc"`
}

type Repo

type Repo struct {
	Did                            string `gorm:"primaryKey"`
	CreatedAt                      time.Time
	Email                          string `gorm:"uniqueIndex"`
	EmailConfirmedAt               *time.Time
	EmailVerificationCode          *string
	EmailVerificationCodeExpiresAt *time.Time
	EmailUpdateCode                *string
	EmailUpdateCodeExpiresAt       *time.Time
	PasswordResetCode              *string `gorm:"index"`
	PasswordResetCodeExpiresAt     *time.Time
	PlcOperationCode               *string
	PlcOperationCodeExpiresAt      *time.Time
	AccountDeleteCode              *string
	AccountDeleteCodeExpiresAt     *time.Time
	Password                       string
	SessionVersion                 int64 `gorm:"not null;default:0"`
	SigningKey                     []byte
	// KemKey is the account's #atproto_kem P-256 private key, with which it
	// establishes shared secrets for space repo MACs. Nil until created.
	KemKey      []byte
	Rev         string
	Root        []byte
	Preferences []byte
	Deactivated bool
	// TakedownRef marks an account taken down. Space data of a taken-down
	// account is neither served nor written.
	TakedownRef            *string
	TwoFactorCode          *string
	TwoFactorCodeExpiresAt *time.Time
	TwoFactorType          TwoFactorType `gorm:"default:none"`
	// Failed second-factor attempts since the last success, and the time
	// until which further attempts are refused once too many have failed.
	TwoFactorFailedAttempts int `gorm:"not null;default:0"`
	TwoFactorLockedUntil    *time.Time
}

func (*Repo) Active

func (r *Repo) Active() bool

func (*Repo) SignFor

func (r *Repo) SignFor(ctx context.Context, did string, msg []byte) ([]byte, error)

func (*Repo) Status

func (r *Repo) Status() *string

func (*Repo) TakenDown added in v0.13.3

func (r *Repo) TakenDown() bool

TakenDown reports whether the account has been taken down by an administrator. A taken-down account's repo is hidden and its writes refused, like a deactivated account's, but (unlike deactivation) an admin can undo it.

type RepoActor

type RepoActor struct {
	Repo
	Actor
}

type ReservedKey added in v0.7.0

type ReservedKey struct {
	KeyDid     string  `gorm:"primaryKey"`
	Did        *string `gorm:"index"`
	PrivateKey []byte
	CreatedAt  time.Time `gorm:"index"`
}

type RevokedSpaceCredential added in v0.13.1

type RevokedSpaceCredential struct {
	Space     string `gorm:"primaryKey"`
	Jti       string `gorm:"primaryKey"`
	ExpiresAt string `gorm:"not null;index"`
}

RevokedSpaceCredential is a space credential revoked by its authority, kept until it would have expired.

type SimplespaceConfig added in v0.13.1

type SimplespaceConfig struct {
	Did              string `gorm:"primaryKey"`
	Uri              string `gorm:"primaryKey"`
	ReadPolicy       string `gorm:"not null"`
	ReadManagingApp  *string
	WritePolicy      string `gorm:"not null"`
	WriteManagingApp *string
	AppAccessType    string `gorm:"not null"`
	AppAllowed       string `gorm:"not null"` // JSON array of client IDs
}

SimplespaceConfig is the governance config of a space this account is the authority for.

type SimplespaceMember added in v0.13.1

type SimplespaceMember struct {
	Did       string `gorm:"primaryKey"`
	Space     string `gorm:"primaryKey"`
	MemberDid string `gorm:"primaryKey"`
	Read      bool   `gorm:"not null"`
	Write     bool   `gorm:"not null"`
}

SimplespaceMember is a member of a governed space.

type Space added in v0.13.1

type Space struct {
	Did       string `gorm:"primaryKey"`
	Uri       string `gorm:"primaryKey"`
	Authority string `gorm:"not null;index"`
	Type      string `gorm:"not null"`
	CreatedAt string `gorm:"not null"`
	DeletedAt *string
}

Space is a space this account holds a repo in, or governs. DeletedAt marks a deleted space whose row survives as a tombstone.

type SpaceCredentialRecipient added in v0.13.1

type SpaceCredentialRecipient struct {
	Did             string `gorm:"primaryKey"`
	Space           string `gorm:"primaryKey"`
	ServiceDid      string `gorm:"primaryKey"`
	ServiceEndpoint string `gorm:"not null"`
	ExpiresAt       string `gorm:"not null"`
}

SpaceCredentialRecipient is a service registered (registerNotify) to receive a governed space's write notifications.

type SpaceDeletedNotificationRetry added in v0.14.1

type SpaceDeletedNotificationRetry struct {
	Space     string `gorm:"primaryKey"`
	Service   string `gorm:"primaryKey"`
	Attempts  int    `gorm:"not null"`
	RetryAt   int64  `gorm:"not null;index"`
	ExpiresAt int64  `gorm:"not null"`
}

SpaceDeletedNotificationRetry is a notifySpaceDeleted to a registered service that failed and waits to be resent, until it succeeds or the service's registration expires.

type SpaceNotificationRetry added in v0.13.1

type SpaceNotificationRetry struct {
	Repo    string `gorm:"primaryKey"`
	Space   string `gorm:"primaryKey"`
	RepoRev string `gorm:"not null"`
	// Data is the commit data to notify. The column keeps its name from
	// before the protocol renamed the field from hash.
	Data      []byte `gorm:"column:hash;not null"`
	Attempts  int    `gorm:"not null"`
	RetryAt   int64  `gorm:"not null;index"`
	ExpiresAt int64  `gorm:"not null"`
}

SpaceNotificationRetry is a writer's notifyWrite that failed and waits to be resent to the authority, one per repo and space.

type SpaceRecord added in v0.11.1

type SpaceRecord struct {
	Uri        string `gorm:"primaryKey"`
	Did        string `gorm:"not null;uniqueIndex:idx_space_record_path,priority:1;index:idx_space_record_rev,priority:1"`
	Space      string `gorm:"not null;uniqueIndex:idx_space_record_path,priority:2;index:idx_space_record_rev,priority:2"`
	Collection string `gorm:"not null;uniqueIndex:idx_space_record_path,priority:3"`
	Rkey       string `gorm:"not null;uniqueIndex:idx_space_record_path,priority:4"`
	Cid        string `gorm:"not null"`
	Value      []byte `gorm:"not null"`
	RepoRev    string `gorm:"not null;index:idx_space_record_rev,priority:3"`
	IndexedAt  string `gorm:"not null"`
}

SpaceRecord is a record in this account's repo for a space. Uri is globally unique since it names the author.

type SpaceRecordBlob added in v0.13.1

type SpaceRecordBlob struct {
	Did       string `gorm:"not null;index"`
	BlobCid   string `gorm:"primaryKey"`
	RecordUri string `gorm:"primaryKey;index"`
}

SpaceRecordBlob ties a blob to a space record that references it.

type SpaceRecordOplog added in v0.13.1

type SpaceRecordOplog struct {
	Did        string `gorm:"primaryKey"`
	Space      string `gorm:"primaryKey"`
	Rev        string `gorm:"primaryKey"`
	Idx        int    `gorm:"primaryKey;autoIncrement:false"`
	Action     string `gorm:"not null"`
	Uri        string `gorm:"not null"`
	Collection string `gorm:"not null"`
	Rkey       string `gorm:"not null"`
	Cid        *string
	Prev       *string
}

SpaceRecordOplog is one op of a space repo commit.

type SpaceRepo added in v0.11.1

type SpaceRepo struct {
	Did     string `gorm:"primaryKey"`
	Space   string `gorm:"primaryKey"`
	SetHash []byte
	Rev     *string
}

SpaceRepo is this account's repo state in a space: the set hash state and the latest rev. Both are nil until the first write.

type SpaceUsedJti added in v0.13.1

type SpaceUsedJti struct {
	Namespace string `gorm:"primaryKey"`
	Jti       string `gorm:"primaryKey"`
	ExpiresAt int64  `gorm:"not null;index"`
}

SpaceUsedJti records a single-use token (delegation token, client attestation) until it expires, so it can't be replayed.

type SpaceWriter added in v0.11.1

type SpaceWriter struct {
	Did       string `gorm:"primaryKey"`
	Space     string `gorm:"primaryKey;index:idx_space_writer_space_rev,priority:1"`
	WriterDid string `gorm:"primaryKey"`
	RepoRev   string `gorm:"not null"`
	SpaceRev  string `gorm:"not null;index:idx_space_writer_space_rev,priority:2"`
	// Data is the commit data (the set hash digest) last reported. The column
	// keeps its name from before the protocol renamed the field from hash.
	Data []byte `gorm:"column:hash;not null"`
}

SpaceWriter is, on the authority, the latest known state of a writer's repo in a governed space, sequenced by SpaceRev.

type Token

type Token struct {
	Token          string `gorm:"primaryKey"`
	Did            string `gorm:"index"`
	SessionVersion int64  `gorm:"not null;default:0"`
	RefreshToken   string `gorm:"index"`
	CreatedAt      time.Time
	ExpiresAt      time.Time `gorm:"index:,sort:asc"`
}

type TwoFactorBackupCode added in v0.13.1

type TwoFactorBackupCode struct {
	ID        uint   `gorm:"primaryKey"`
	Did       string `gorm:"index;not null"`
	CodeHash  []byte
	CreatedAt time.Time
	UsedAt    *time.Time
}

TwoFactorBackupCode is a single-use recovery code, stored as a SHA-256 hash. Backup codes are only accepted when the account has at least one TwoFactorCredential.

type TwoFactorCredential added in v0.13.1

type TwoFactorCredential struct {
	ID        uint   `gorm:"primaryKey"`
	Did       string `gorm:"index;not null"`
	Type      TwoFactorCredentialType
	Name      string
	CreatedAt time.Time
	// TOTP shared secret, or the YubiKey slot's AES-128 key. Empty for a
	// YubiKey registered as it came from the factory, whose OTPs are checked
	// with Yubico's YubiCloud service instead (see UsesYubiCloud).
	Secret []byte
	// Yubico OTP only: the modhex public identity typed before each OTP, and
	// the 6-byte private identity found inside the encrypted block.
	PublicID  string `gorm:"index"`
	PrivateID []byte
	// Replay protection. TOTP stores the last accepted time step; Yubico OTP
	// stores the last accepted (session counter, session use) pair.
	LastStep    int64 `gorm:"not null;default:0"`
	LastCounter int   `gorm:"not null;default:0"`
	LastUse     int   `gorm:"not null;default:0"`
	LastUsedAt  *time.Time
}

TwoFactorCredential is an authenticator app (TOTP) or a YubiKey slot programmed for Yubico OTP. When an account has any of these, they replace emailed sign-in codes entirely.

func (*TwoFactorCredential) UsesYubiCloud added in v0.13.1

func (c *TwoFactorCredential) UsesYubiCloud() bool

UsesYubiCloud reports whether this YubiKey's OTPs are checked by YubiCloud rather than decrypted locally with a stored AES key.

type TwoFactorCredentialType added in v0.13.1

type TwoFactorCredentialType string

type TwoFactorType added in v0.8.0

type TwoFactorType string

Jump to

Keyboard shortcuts

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