Documentation
¶
Index ¶
- Constants
- Variables
- func ConsumeWalletNonce(address string)
- func DeleteKey(key string, purpose string)
- func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem
- func GenerateVerificationCode(length int) string
- func GenerateWalletJWT(userID int, walletAddress string) (token string, expiresAt time.Time, err error)
- func GenerateWalletNonce(address, messagePrefix, chainId string) (nonce string, message string)
- func GenerateWalletRefreshJWT(userID int, walletAddress string) (token string, expiresAt time.Time, err error)
- func GetRequestBody(c *gin.Context) ([]byte, error)
- func GetWalletNonce(address string) (walletNonceValue, bool)
- func Init()
- func InitRedisClient() (err error)
- func IsUcanToken(token string) bool
- func IsValidEthAddress(addr string) bool
- func LogQuota(quota int64) string
- func ParseRedisOption() *redis.Options
- func Password2Hash(password string) (string, error)
- func RedisDecrease(key string, value int64) error
- func RedisDel(key string) error
- func RedisGet(key string) (string, error)
- func RedisSet(key string, value string, expiration time.Duration) error
- func RegisterVerificationCodeWithKey(key string, code string, purpose string)
- func ResolveUcanAudience() string
- func SetEventStreamHeaders(c *gin.Context)
- func UnmarshalBodyReusable(c *gin.Context, v any) error
- func ValidatePasswordAndHash(password string, hash string) bool
- func VerifyCodeWithKey(key string, code string, purpose string) bool
- func VerifyUcanInvocation(token string, expectedAud string, required []UcanCapability) (string, error)
- type CustomEvent
- type InMemoryRateLimiter
- type UcanCapability
- type WalletClaims
Constants ¶
View Source
const ( EmailVerificationPurpose = "v" PasswordResetPurpose = "r" )
Variables ¶
View Source
var ( Port = flag.Int("port", 3011, "the listening port") PrintVersion = flag.Bool("version", false, "print version and exit") PrintHelp = flag.Bool("help", false, "print help and exit") LogDir = flag.String("log-dir", "./logs", "specify the log directory") )
View Source
var RDB redis.Cmdable
View Source
var RedisEnabled = true
View Source
var SQLiteBusyTimeout = env.Int("SQLITE_BUSY_TIMEOUT", 3000)
View Source
var SQLitePath = "one-api.db"
View Source
var StartTime = time.Now().Unix() // unit: second
View Source
var UsingMySQL = false
View Source
var UsingPostgreSQL = false
View Source
var UsingSQLite = false
View Source
var Validate *validator.Validate
View Source
var VerificationValidMinutes = 10
View Source
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
Functions ¶
func ConsumeWalletNonce ¶
func ConsumeWalletNonce(address string)
ConsumeWalletNonce removes a nonce (used after successful auth)
func EmbedFolder ¶
func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem
func GenerateWalletJWT ¶
func GenerateWalletJWT(userID int, walletAddress string) (token string, expiresAt time.Time, err error)
GenerateWalletJWT issues a JWT for the given user id and wallet address.
func GenerateWalletNonce ¶
GenerateWalletNonce creates a nonce & message and stores them for later verification
func GenerateWalletRefreshJWT ¶
func GenerateWalletRefreshJWT(userID int, walletAddress string) (token string, expiresAt time.Time, err error)
GenerateWalletRefreshJWT issues a refresh token for the given user id and wallet address.
func GetWalletNonce ¶
GetWalletNonce returns stored nonce entry if valid
func InitRedisClient ¶
func InitRedisClient() (err error)
InitRedisClient This function is called after init()
func IsUcanToken ¶
func IsValidEthAddress ¶
IsValidEthAddress performs a basic checksum/length check
func ParseRedisOption ¶
func Password2Hash ¶
func RedisDecrease ¶
func ResolveUcanAudience ¶
func ResolveUcanAudience() string
func SetEventStreamHeaders ¶
func ValidatePasswordAndHash ¶
func VerifyUcanInvocation ¶
func VerifyUcanInvocation(token string, expectedAud string, required []UcanCapability) (string, error)
Types ¶
type CustomEvent ¶
func (CustomEvent) Render ¶
func (r CustomEvent) Render(w http.ResponseWriter) error
func (CustomEvent) WriteContentType ¶
func (r CustomEvent) WriteContentType(w http.ResponseWriter)
type InMemoryRateLimiter ¶
type InMemoryRateLimiter struct {
// contains filtered or unexported fields
}
func (*InMemoryRateLimiter) Init ¶
func (l *InMemoryRateLimiter) Init(expirationDuration time.Duration)
type UcanCapability ¶
type WalletClaims ¶
type WalletClaims struct {
UserID int `json:"user_id"`
WalletAddress string `json:"wallet_address"`
TokenType string `json:"token_type,omitempty"`
jwt.RegisteredClaims
}
WalletClaims defines JWT claims for wallet login.
func VerifyWalletJWT ¶
func VerifyWalletJWT(tokenString string) (*WalletClaims, error)
VerifyWalletJWT validates token and returns claims.
func VerifyWalletRefreshJWT ¶
func VerifyWalletRefreshJWT(tokenString string) (*WalletClaims, error)
VerifyWalletRefreshJWT validates refresh token and returns claims.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.