1package models
2
3import (
4 "context"
5 "time"
6
7 "github.com/bluesky-social/indigo/atproto/crypto"
8)
9
10type TwoFactorType string
11
12var (
13 TwoFactorTypeNone = TwoFactorType("none")
14 TwoFactorTypeTotp = TwoFactorType("totp")
15)
16
17type Repo struct {
18 Did string `gorm:"primaryKey"`
19 CreatedAt time.Time
20 Email string `gorm:"uniqueIndex"`
21 EmailConfirmedAt *time.Time
22 EmailVerificationCode *string
23 EmailVerificationCodeExpiresAt *time.Time
24 EmailUpdateCode *string
25 EmailUpdateCodeExpiresAt *time.Time
26 PasswordResetCode *string
27 PasswordResetCodeExpiresAt *time.Time
28 Password string
29 SigningKey []byte
30 Rev string
31 Root []byte
32 Preferences []byte
33 TwoFactorType TwoFactorType `gorm:"default:none"`
34 TotpSecret *string
35}
36
37func (r *Repo) SignFor(ctx context.Context, did string, msg []byte) ([]byte, error) {
38 k, err := crypto.ParsePrivateBytesK256(r.SigningKey)
39 if err != nil {
40 return nil, err
41 }
42
43 sig, err := k.HashAndSign(msg)
44 if err != nil {
45 return nil, err
46 }
47
48 return sig, nil
49}
50
51type Actor struct {
52 Did string `gorm:"primaryKey"`
53 Handle string `gorm:"uniqueIndex"`
54}
55
56type RepoActor struct {
57 Repo
58 Actor
59}
60
61type InviteCode struct {
62 Code string `gorm:"primaryKey"`
63 Did string `gorm:"index"`
64 RemainingUseCount int
65}
66
67type Token struct {
68 Token string `gorm:"primaryKey"`
69 Did string `gorm:"index"`
70 RefreshToken string `gorm:"index"`
71 CreatedAt time.Time
72 ExpiresAt time.Time `gorm:"index:,sort:asc"`
73}
74
75type RefreshToken struct {
76 Token string `gorm:"primaryKey"`
77 Did string `gorm:"index"`
78 CreatedAt time.Time
79 ExpiresAt time.Time `gorm:"index:,sort:asc"`
80}
81
82type Record struct {
83 Did string `gorm:"primaryKey:idx_record_did_created_at;index:idx_record_did_nsid"`
84 CreatedAt string `gorm:"index;index:idx_record_did_created_at,sort:desc"`
85 Nsid string `gorm:"primaryKey;index:idx_record_did_nsid"`
86 Rkey string `gorm:"primaryKey"`
87 Cid string
88 Value []byte
89}
90
91type Block struct {
92 Did string `gorm:"primaryKey;index:idx_blocks_by_rev"`
93 Cid []byte `gorm:"primaryKey"`
94 Rev string `gorm:"index:idx_blocks_by_rev,sort:desc"`
95 Value []byte
96}
97
98type Blob struct {
99 ID uint
100 CreatedAt string `gorm:"index"`
101 Did string `gorm:"index;index:idx_blob_did_cid"`
102 Cid []byte `gorm:"index;index:idx_blob_did_cid"`
103 RefCount int
104}
105
106type BlobPart struct {
107 Blob Blob
108 BlobID uint `gorm:"primaryKey"`
109 Idx int `gorm:"primaryKey"`
110 Data []byte
111}