utils

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode added in v1.2.0

func Base64Decode(_base64 string) (string, error)

func Base64Encode added in v1.2.0

func Base64Encode(str string) string

func BytesToHexString added in v1.2.0

func BytesToHexString(b []byte) string

func BytesToString added in v1.2.0

func BytesToString(data []byte) string

func ComparePassword added in v1.2.0

func ComparePassword(userPassword string, password string) bool

func Copy added in v1.2.0

func Copy(toValue interface{}, fromValue interface{}) (err error)

func CreateECDSAPrivateKey added in v1.2.0

func CreateECDSAPrivateKey(D *big.Int, curve elliptic.Curve) (*ecdsa.PrivateKey, error)

func CreateECDSAPublicKey added in v1.2.0

func CreateECDSAPublicKey(curve elliptic.Curve, x *big.Int, y *big.Int) (*ecdsa.PublicKey, error)

func DecryptCipherText added in v1.2.0

func DecryptCipherText(cipherText []byte, privateKey *rsa.PrivateKey, options *MessageEncryptionOptions) ([]byte, error)

func EncodeKeyPair added in v1.2.0

func EncodeKeyPair(privateKey *ecdsa.PrivateKey, publicKey *ecdsa.PublicKey) (string, string)

func EncodeRSAKeyPair added in v1.2.0

func EncodeRSAKeyPair(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey) (string, string)

func EncryptMessage added in v1.2.0

func EncryptMessage(message []byte, publicKey *rsa.PublicKey, options *MessageEncryptionOptions) ([]byte, error)

func GenerateDID added in v1.2.0

func GenerateDID(did string, method string) string

func GenerateKeyPairWithOption added in v1.2.0

func GenerateKeyPairWithOption(option *GenerateKeyPairOption) (interface{}, error)

func GetArrayString added in v1.1.0

func GetArrayString(v []*string) []string

func GetBigNumber added in v1.2.0

func GetBigNumber(n string) (*big.Int, bool)

func GetBool added in v1.1.0

func GetBool(v *bool) bool

func GetBoolFalse added in v1.1.0

func GetBoolFalse(v *bool) bool

func GetBoolTrue added in v1.1.0

func GetBoolTrue(v *bool) bool

func GetCurrentDateTime added in v1.2.0

func GetCurrentDateTime() *time.Time

func GetFloat64 added in v1.1.0

func GetFloat64(v *float64) float64

func GetInt added in v1.1.0

func GetInt(v *int) int

func GetInt64 added in v1.1.0

func GetInt64(v *int64) int64

func GetJSON added in v1.1.0

func GetJSON(v *json.RawMessage) json.RawMessage

func GetMD5Hash added in v1.2.0

func GetMD5Hash(text string) string

func GetString added in v1.1.0

func GetString(v *string) string

func GetUUID

func GetUUID() string

func HashPassword added in v1.2.0

func HashPassword(password string) (*string, error)

func HexToBytesString added in v1.2.0

func HexToBytesString(data string) ([]byte, error)

func IsEmpty added in v1.2.0

func IsEmpty(x interface{}) bool

func IsExists added in v1.2.0

func IsExists(db *gorm.DB, field *string, table string, column string, fieldPath string) (bool, error)

func IsExistsWithCondition added in v1.2.0

func IsExistsWithCondition(
	db *gorm.DB,
	table string,
	condition map[string]interface{},
	fieldPath string,
) (bool, error)

func IsStrIn added in v1.2.0

func IsStrIn(input *string, rules string, fieldPath string) (bool, error)

func IsUUID

func IsUUID(str string) bool

func JSONParse added in v1.2.0

func JSONParse(body []byte, model interface{}) error

func JSONToString added in v1.2.0

func JSONToString(s interface{}) string

func JWTDecode added in v1.2.0

func JWTDecode(token string) (string, error)

func LoadPrivateKey added in v1.2.0

func LoadPrivateKey(privateKey string) (*ecdsa.PrivateKey, error)

func LoadPublicKey added in v1.2.0

func LoadPublicKey(publicKey string) (*ecdsa.PublicKey, error)

func LoadRSAPrivateKey added in v1.2.0

func LoadRSAPrivateKey(privateKey string) (*rsa.PrivateKey, error)

func LoadRSAPublicKey added in v1.2.0

func LoadRSAPublicKey(publicKey string) (*rsa.PublicKey, error)

func LogStruct

func LogStruct(v interface{})

func MapToStruct added in v1.2.0

func MapToStruct(src interface{}, to interface{}) error

func MockExplorer added in v1.2.0

func MockExplorer()

func NewSha256 added in v1.2.0

func NewSha256(str string) string

func NewSha384 added in v1.2.0

func NewSha384(str string) string

func NewSha512 added in v1.2.0

func NewSha512(str string) string

func RootDir added in v1.2.0

func RootDir() string

func SignMessage added in v1.2.0

func SignMessage(privateKey *ecdsa.PrivateKey, message string) (string, error)

func SignMessageWithOption added in v1.2.0

func SignMessageWithOption(privateKey interface{}, message string, option *SignMessageOption) (string, error)

func StringToBytes added in v1.2.0

func StringToBytes(data string) []byte

func StructToHexString added in v1.2.0

func StructToHexString(s interface{}) string

func StructToMap added in v1.2.0

func StructToMap(src interface{}) (map[string]interface{}, error)

func StructToString

func StructToString(v interface{}) string

func StructToStringNoPretty added in v1.2.0

func StructToStringNoPretty(v interface{}) string

func ToNonPointer added in v1.1.0

func ToNonPointer[T comparable](v *T) T

func ToPointer added in v1.1.0

func ToPointer[T comparable](v T) *T

func ToUUID

func ToUUID(str string) (uuid.UUID, error)

func VerifySignature added in v1.2.0

func VerifySignature(publicKey string, signature string, msg string) (bool, error)

func VerifySignatureWithOption added in v1.2.0

func VerifySignatureWithOption(publicKey string, signature string, msg string, option *VerifySignatureOption) (bool, error)

Types

type Consensus added in v1.2.0

type Consensus struct {
	Method     string
	ApproveDID string
	DIDAddress string
}

func ConvertConsensus added in v1.2.0

func ConvertConsensus(consensus *string) *Consensus

type DIDDetail added in v1.2.0

type DIDDetail struct {
	Method string `json:"method"`
	ID     string `json:"id"`
}

func ExtractDID added in v1.2.0

func ExtractDID(didAddress string) *DIDDetail

type ECDSASignature added in v1.2.0

type ECDSASignature struct {
	R, S *big.Int
}

type GenerateKeyPairOption added in v1.2.0

type GenerateKeyPairOption struct {
	Algorithm x509.SignatureAlgorithm
	KeySize   RSAKeySize
}

type KeyPair added in v1.2.0

type KeyPair struct {
	PublicKeyPem  string
	PrivateKeyPem string
	PrivateKey    *ecdsa.PrivateKey
}

func GenerateKeyPair added in v1.2.0

func GenerateKeyPair() (*KeyPair, error)

type MessageEncryptionOptions added in v1.2.0

type MessageEncryptionOptions struct {
	HashingAlgorithm crypto.Hash
	Label            []byte
}

type NewKey added in v1.2.0

type NewKey struct {
	Controller *string `json:"controller"`
	KeyPem     string  `json:"key_pem"`
	KeyHash    string  `json:"key_hash"`
	KeyType    string  `json:"key_type"`
	Signature  string  `json:"signature"`
}

func ConvertNewKey added in v1.2.0

func ConvertNewKey(newKey string) (*NewKey, error)

type RSAKeyPair added in v1.2.0

type RSAKeyPair struct {
	PublicKeyPem  string
	PrivateKeyPem string
	PrivateKey    *rsa.PrivateKey
}

type RSAKeySize added in v1.2.0

type RSAKeySize int
const (
	EncryptRSA2048Bits RSAKeySize = iota
	EncryptRSA4096Bits
)

type SignMessageOption added in v1.2.0

type SignMessageOption struct {
	Algorithm x509.SignatureAlgorithm
}

type VerifySignatureOption added in v1.2.0

type VerifySignatureOption struct {
	Algorithm x509.SignatureAlgorithm
}

Jump to

Keyboard shortcuts

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