utils

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PngMimeType = "image/png"

	TextRegex = `^[a-zA-Z0-9 +.,;:?!'’"\-_/()\[\]~&#$—%]+$`
)

Variables

View Source
var (
	ErrInvalidURL            = errors.New("invalid url")
	ErrInvalidGithubRawURL   = errors.New("invalid github raw url")
	ErrInvalidText           = fmt.Errorf("invalid text format, doesn't conform to regex %s", TextRegex)
	ErrTextTooLong           = errors.New("text should be less than 500 characters")
	ErrEmptyText             = errors.New("text is empty")
	ErrInvalidImageExtension = errors.New(
		"invalid image extension. only " + strings.Join(ImageExtensions, ",") + " is supported",
	)
	ErrInvalidImageMimeType     = errors.New("invalid image mime-type. only png is supported")
	ErrInvalidURLLength         = errors.New("url length should be no larger than 1024 character")
	ErrURLPointingToLocalServer = errors.New("url should not point to local server")
	ErrEmptyURL                 = errors.New("url is empty")
	ErrInvalidTwitterURLRegex   = errors.New(
		"invalid twitter url, it should be of the format https://twitter.com/<username> or https://x.com/<username>",
	)
	ErrResponseTooLarge = errors.New("response too large, allowed size is 1 MB")
)
View Source
var (
	// ImageExtensions List of common image file extensions
	// Only support PNG for now to reduce surface area of image validation
	// We do NOT want to support formats like SVG since they can be used for javascript injection
	// If we get pushback on only supporting png, we can support jpg, jpeg, gif, etc. later
	ImageExtensions = []string{".png"}
)

Functions

func Add0x

func Add0x(address string) string

func CheckBasicURLValidation

func CheckBasicURLValidation(rawURL string) error

func CheckIfURLIsValid

func CheckIfURLIsValid(rawURL string) error

func CheckIfValidTwitterURL

func CheckIfValidTwitterURL(twitterURL string) error

func EcdsaPrivateKeyToAddress

func EcdsaPrivateKeyToAddress(privateKey *ecdsa.PrivateKey) (gethcommon.Address, error)

func IsImageURL

func IsImageURL(urlString string) error

func IsValidEthereumAddress

func IsValidEthereumAddress(address string) bool

func ReadFile

func ReadFile(path string) ([]byte, error)

func ReadJSONConfig

func ReadJSONConfig(path string, o interface{}) error

func ReadPublicURL

func ReadPublicURL(url string) ([]byte, error)

func ReadYamlConfig

func ReadYamlConfig(path string, o interface{}) error

func RoundUpDivideBig

func RoundUpDivideBig(a, b *big.Int) *big.Int

func Trim0x

func Trim0x(address string) string

func TypedErr

func TypedErr(e interface{}) error

func ValidateRawGithubURL

func ValidateRawGithubURL(url string) error

func ValidateText

func ValidateText(text string) error

func WrapError

func WrapError(mainErr interface{}, subErr interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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