diff --git a/config.default.yaml b/config.default.yaml index 37ba375..d88e0dc 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -30,7 +30,8 @@ email: secrets: jwt_secret: example turnstile_secret: example - client_secret_key: example + client_secret_key: aes_32_byte_string + kyc_info_key: aes_32_byte_string ttl: auth_code_ttl: 10m access_ttl: 15s diff --git a/config/types.go b/config/types.go index c4af613..d470c12 100644 --- a/config/types.go +++ b/config/types.go @@ -53,6 +53,7 @@ type secrets struct { JwtSecret string `yaml:"jwt_secret"` TurnstileSecret string `yaml:"turnstile_secret"` ClientSecretKey string `yaml:"client_secret_key"` + KycInfoKey string `yaml:"kyc_info_key"` } type ttl struct { diff --git a/data/agenda.go b/data/agenda.go new file mode 100644 index 0000000..2955ef1 --- /dev/null +++ b/data/agenda.go @@ -0,0 +1,13 @@ +package data + +import "github.com/google/uuid" + +type Agenda struct { + Id uint `json:"id" gorm:"primarykey;autoIncrement"` + UUID uuid.UUID `json:"uuid" gorm:"type:uuid;uniqueIndex;not null"` + AgendaId uuid.UUID `json:"agenda_id" gorm:"type:uuid;uniqueIndex;not null"` + EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"` + UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"` + Name string `json:"name" gorm:"type:varchar(255);not null"` + Description string `json:"description" gorm:"type:text;not null"` +} diff --git a/data/attendance.go b/data/attendance.go index 7e82da7..bf6c351 100644 --- a/data/attendance.go +++ b/data/attendance.go @@ -21,6 +21,7 @@ type Attendance struct { EventId uuid.UUID `json:"event_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"` UserId uuid.UUID `json:"user_id" gorm:"type:uuid;uniqueIndex:unique_event_user;not null"` Role string `json:"role" gorm:"type:varchar(255);not null"` + KycInfo string `json:"kyc_info" gorm:"type:text"` CheckinAt time.Time `json:"checkin_at"` } diff --git a/pkgs/authtoken/token.go b/pkgs/authtoken/authtoken.go similarity index 100% rename from pkgs/authtoken/token.go rename to pkgs/authtoken/authtoken.go diff --git a/pkgs/kyc/kyc.go b/pkgs/kyc/kyc.go new file mode 100644 index 0000000..4b5b09d --- /dev/null +++ b/pkgs/kyc/kyc.go @@ -0,0 +1,50 @@ +package kyc + +import ( + "encoding/base64" + "encoding/json" + "errors" + "nixcn-cms/internal/cryptography" + + "github.com/spf13/viper" +) + +func EncodeB64Json(b64Json string) (*string, error) { + rawJson, err := base64.StdEncoding.DecodeString(b64Json) + if err != nil { + return nil, errors.New("invalid base64 json") + } + + var kyc KycInfo + if err := json.Unmarshal(rawJson, &kyc); err != nil { + return nil, errors.New("invalid json structure") + } + + plainJson, err := json.Marshal(kyc) + if err != nil { + return nil, err + } + + aesKey := viper.GetString("secrets.kyc_info_key") + encrypted, err := cryptography.AESCBCEncrypt(plainJson, []byte(aesKey)) + if err != nil { + return nil, err + } + + return &encrypted, nil +} + +func DecodeAES(cipherStr string) (*KycInfo, error) { + aesKey := viper.GetString("secrets.kyc_info_key") + plainBytes, err := cryptography.AESCBCDecrypt(cipherStr, []byte(aesKey)) + if err != nil { + return nil, err + } + + var kyc KycInfo + if err := json.Unmarshal(plainBytes, &kyc); err != nil { + return nil, errors.New("invalid decrypted json") + } + + return &kyc, nil +} diff --git a/pkgs/kyc/types.go b/pkgs/kyc/types.go new file mode 100644 index 0000000..92595e3 --- /dev/null +++ b/pkgs/kyc/types.go @@ -0,0 +1,7 @@ +package kyc + +type KycInfo struct { + Type string `json:"type"` // Chinese / Foreigner + LegalName string `json:"legal_name"` + ResidentId string `json:"rsident_id"` +}