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