An atproto PDS written in Go
at main 3.2 kB view raw
1package models 2 3import ( 4 "context" 5 "time" 6 7 "github.com/Azure/go-autorest/autorest/to" 8 "github.com/bluesky-social/indigo/atproto/atcrypto" 9) 10 11type Repo struct { 12 Did string `gorm:"primaryKey"` 13 CreatedAt time.Time 14 Email string `gorm:"uniqueIndex"` 15 EmailConfirmedAt *time.Time 16 EmailVerificationCode *string 17 EmailVerificationCodeExpiresAt *time.Time 18 EmailUpdateCode *string 19 EmailUpdateCodeExpiresAt *time.Time 20 PasswordResetCode *string 21 PasswordResetCodeExpiresAt *time.Time 22 PlcOperationCode *string 23 PlcOperationCodeExpiresAt *time.Time 24 AccountDeleteCode *string 25 AccountDeleteCodeExpiresAt *time.Time 26 Password string 27 SigningKey []byte 28 Rev string 29 Root []byte 30 Preferences []byte 31 Deactivated bool 32} 33 34func (r *Repo) SignFor(ctx context.Context, did string, msg []byte) ([]byte, error) { 35 k, err := atcrypto.ParsePrivateBytesK256(r.SigningKey) 36 if err != nil { 37 return nil, err 38 } 39 40 sig, err := k.HashAndSign(msg) 41 if err != nil { 42 return nil, err 43 } 44 45 return sig, nil 46} 47 48func (r *Repo) Status() *string { 49 var status *string 50 if r.Deactivated { 51 status = to.StringPtr("deactivated") 52 } 53 return status 54} 55 56func (r *Repo) Active() bool { 57 return r.Status() == nil 58} 59 60type Actor struct { 61 Did string `gorm:"primaryKey"` 62 Handle string `gorm:"uniqueIndex"` 63} 64 65type RepoActor struct { 66 Repo 67 Actor 68} 69 70type InviteCode struct { 71 Code string `gorm:"primaryKey"` 72 Did string `gorm:"index"` 73 RemainingUseCount int 74} 75 76type Token struct { 77 Token string `gorm:"primaryKey"` 78 Did string `gorm:"index"` 79 RefreshToken string `gorm:"index"` 80 CreatedAt time.Time 81 ExpiresAt time.Time `gorm:"index:,sort:asc"` 82} 83 84type RefreshToken struct { 85 Token string `gorm:"primaryKey"` 86 Did string `gorm:"index"` 87 CreatedAt time.Time 88 ExpiresAt time.Time `gorm:"index:,sort:asc"` 89} 90 91type Record struct { 92 Did string `gorm:"primaryKey:idx_record_did_created_at;index:idx_record_did_nsid"` 93 CreatedAt string `gorm:"index;index:idx_record_did_created_at,sort:desc"` 94 Nsid string `gorm:"primaryKey;index:idx_record_did_nsid"` 95 Rkey string `gorm:"primaryKey"` 96 Cid string 97 Value []byte 98} 99 100type Block struct { 101 Did string `gorm:"primaryKey;index:idx_blocks_by_rev"` 102 Cid []byte `gorm:"primaryKey"` 103 Rev string `gorm:"index:idx_blocks_by_rev,sort:desc"` 104 Value []byte 105} 106 107type Blob struct { 108 ID uint 109 CreatedAt string `gorm:"index"` 110 Did string `gorm:"index;index:idx_blob_did_cid"` 111 Cid []byte `gorm:"index;index:idx_blob_did_cid"` 112 RefCount int 113 Storage string `gorm:"default:sqlite"` 114} 115 116type BlobPart struct { 117 Blob Blob 118 BlobID uint `gorm:"primaryKey"` 119 Idx int `gorm:"primaryKey"` 120 Data []byte 121} 122 123type ReservedKey struct { 124 KeyDid string `gorm:"primaryKey"` 125 Did *string `gorm:"index"` 126 PrivateKey []byte 127 CreatedAt time.Time `gorm:"index"` 128}