auth

package
v0.0.0-...-e311ac8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrChallengeNotFound error message
	ErrChallengeNotFound = "Could not find a matching challenge for this address."
	// ErrChallengeBadRequest error message
	ErrChallengeBadRequest = "No address or signature provided when attempting to prove the challenge."
)

Variables

View Source
var (
	// JWTExpiration describes how long the token should be valid, in hours
	JWTExpiration = time.Duration(time.Hour * 48)
)

Functions

func DB

func DB() *cache.Cache

DB returns the cache DB object (only used for testing)

func GetUserFromJWT

func GetUserFromJWT(token interface{}) string

GetUserFromJWT checks if the auth token is valid

func NewChallenge

func NewChallenge(address string) (string, error)

NewChallenge prepares a new challenge message to be signed by the user client-side, using Web3.

func NewJWT

func NewJWT(user string, expTime int64, hexKey string) (string, error)

NewJWT creates a new JWT for the specfied user, based on the provided secret

func ParseHexKey

func ParseHexKey(hexKey string) (*ecdsa.PrivateKey, error)

ParseHexKey parses a key in hexa (string) into an ECDSA private key

func VerifyChallenge

func VerifyChallenge(address string, signature string) (string, error)

VerifyChallenge is used to check the signature in the response and return the address of the user who signed the message.

Types

type Challenge

type Challenge struct {
	Nonce string
	Date  time.Time
}

Challenge defines the object that makes up the challenge

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL