feat: add EIP712 verification, auth service implemention and jwt gen
This commit is contained in:
@@ -3,4 +3,5 @@ package errors
|
||||
var (
|
||||
ErrPhoneInvalid = NewAppError(400, "Invalid phone number", ErrorTypeValidation, nil)
|
||||
ErrNationalIDInvalid = NewAppError(400, "Invalid national ID", ErrorTypeValidation, nil)
|
||||
ErrWalletInvalid = NewAppError(400, "Invalid wallet address", ErrorTypeValidation, nil)
|
||||
)
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
package national
|
||||
package common
|
||||
|
||||
import (
|
||||
"backend/pkg/errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
func IsValid(value string) (bool, error) {
|
||||
func IsValidPhone(value string) (bool, error) {
|
||||
re := regexp.MustCompile(`^(?:0|\+98|0098)(\d{10})$`)
|
||||
result := re.FindStringSubmatch(value)
|
||||
if len(result) > 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, errors.ErrPhoneInvalid
|
||||
}
|
||||
|
||||
func IsValidNationalID(value string) (bool, error) {
|
||||
valueCount := len(value)
|
||||
if valueCount < 8 {
|
||||
return false, errors.ErrNationalIDInvalid
|
||||
@@ -43,3 +55,10 @@ func calculateNationalIDNumbers(valueSlices *[]uint8) (sum int) {
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func IsValidPublicKey(value string) (bool, error) {
|
||||
if !common.IsHexAddress(value) {
|
||||
return false, errors.ErrWalletInvalid
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package phone
|
||||
|
||||
import (
|
||||
"backend/pkg/errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func IsValid(value string) (bool, error) {
|
||||
re := regexp.MustCompile(`^(?:0|\+98|0098)(\d{10})$`)
|
||||
result := re.FindStringSubmatch(value)
|
||||
if len(result) > 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, errors.ErrPhoneInvalid
|
||||
}
|
||||
Reference in New Issue
Block a user