auth

package
v0.0.0-...-3e0d6b8 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWallet

func CreateWallet() (common.Address, string, string, error)

CreateWallet - Generate new public, private key pair This function is mostly used for testing

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator - A struct for checking user signatures

func CreateAuthenticator

func CreateAuthenticator(address common.Address) (*Authenticator, error)

CreateAuthenticator - Create `Authenticator` instance Arguments:

address - Address for the underlying asset

func (*Authenticator) Sign

func (auth *Authenticator) Sign(msg []byte, privateKey string) (string, error)

Sign - Function to sign with private key Arguments:

msg - The message that should be sent
privateKey - Private key for the user. Must be related to the public key

func (*Authenticator) ValidAddress

func (auth *Authenticator) ValidAddress() bool

ValidAddress - Checks if an address is valid

func (*Authenticator) Verify

func (auth *Authenticator) Verify(sigHex string, msg []byte) bool

Verify - Function to verify a signature Arguments:

sigHex - Signature to be verified
msg - The message that should be sent

Notes:

Taken from https://gist.github.com/dcb9/385631846097e1f59e3cba3b1d42f3ed#file-eth_sign_verify-go

type KeyStore

type KeyStore struct {
	// contains filtered or unexported fields
}

KeyStore - Inherits the `api.KeyStore` interface

func CreateKeyStore

func CreateKeyStore() (*KeyStore, error)

CreateKeyStore - Create KeyStore instance

func (*KeyStore) Insert

func (store *KeyStore) Insert(userID string, key []byte) ([]byte, error)

Insert - Inserts a new (userID, key) combo

func (*KeyStore) Query

func (store *KeyStore) Query(userID string) ([]byte, bool)

Query - Look up key in store

type Message

type Message struct {
	Method      string `json:"method"`
	RequestPath string `json:"requestPath"`
	Body        string `json:"body"`
	Timestamp   int64  `json:"timestamp"`
}

Message - A struct for sending a signed message

func CreateMessage

func CreateMessage(
	method string,
	requestPath string,
	body string,
	timestamp int64,
) (*Message, error)

CreateMessage - Create `Message` instance Arguments:

method - GET or POST
requestPath - URI in the path
body - Stringified of the body
timestamp - UNIX timestamp

type RateLimitManager

type RateLimitManager struct {
	// contains filtered or unexported fields
}

RateLimitManager - Customized limit for each IP address Parameters:

visitors (map) - Map from ip address string to limiter
mu (Mutex) - for locking and unlocking

https://www.alexedwards.net/blog/how-to-rate-limit-http-requests

func CreateRateLimitManager

func CreateRateLimitManager(maxPerSec int, burst int) (*RateLimitManager, error)

CreateRateLimitManager - Create a new rate manager Arguments:

maxPerSec (int) - Allowed rate from IP address
burst (int) - Allowed maximum burst rate

func (*RateLimitManager) GetVisitor

func (manager *RateLimitManager) GetVisitor(ip string) *rate.Limiter

GetVisitor - Retrieve and return the rate limiter for the current visitor if it already exists. Otherwise create a new rate limiter and add it to the visitors map, using the IP address as the key

Jump to

Keyboard shortcuts

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