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