rutils

package module
v0.0.0-...-d7f41d9 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 18 Imported by: 0

README

Rutils

The utils lib used for the Rivative Network.

Compressor.go

This file uses lz4 compression to compress data for the RCP lib. Can also be used for any kind of string compression.

Envar.go

This file allows users to encrypt and decrypt strings with a password and load and set environment variables

Crypto.go

This file uses the same algorithm as ethereum. Provides utilities for generating keys, address and signing.

Documentation

Overview

Package crypto provides utilities for working with cryptographic operations such as key generation, signing, and verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressString

func CompressString(input string) ([]byte, error)

func DecodeSignature

func DecodeSignature(encodedSig string) ([]byte, error)

StringToSignature decodes a hexadecimal encoded signature string into a byte slice.

func DecompressString

func DecompressString(input []byte) (string, error)

func Decrypt

func Decrypt(encryptedText, password string) (string, error)

func Encrypt

func Encrypt(plainText, password string) (string, error)

func GetEnvironmentVariable

func GetEnvironmentVariable(varname string) string

func HashString

func HashString(data string) []byte

hashString computes the SHA-256 hash of the input string and returns the result as a byte slice.

func SaveEnvironmentVariable

func SaveEnvironmentVariable(varname string, data string) error

Types

type KeyPair

type KeyPair struct {
	PrivateKey *PrivateKey
	PublicKey  *PublicKey
	Address    string
}

KeyPair represents a client with a private key, public key, and address.

func KeyPairFromPK

func KeyPairFromPK(key string) *KeyPair

KeyPairFromPK creates a new KeyPair from a private key string.

func NewKeyPair

func NewKeyPair() *KeyPair

NewKeyPair creates a new KeyPair with a generated private key.

func (*KeyPair) Sign

func (skc *KeyPair) Sign(tx string) string

Sign signs a transaction using the client's private key and returns the signature as a string.

type PrivateKey

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

PrivateKey represents a cryptographic private key.

func DecodePrivateKey

func DecodePrivateKey(encoded string) (*PrivateKey, error)

NewPrivateKeyFromStr creates a new PrivateKey instance from a hexadecimal encoded string.

func NewPrivateKey

func NewPrivateKey() (*PrivateKey, error)

NewPrivateKey generates a new cryptographic private key.

func (*PrivateKey) EncodeSignature

func (pk *PrivateKey) EncodeSignature(msg string) (string, error)

SignToString signs a message and returns the base64-encoded signature as a string.

func (*PrivateKey) PublicKey

func (pk *PrivateKey) PublicKey() *PublicKey

PublicKey returns the corresponding public key.

func (*PrivateKey) Sign

func (pk *PrivateKey) Sign(msg string) ([]byte, error)

Sign signs a message using the private key and returns the signature as a byte slice.

func (*PrivateKey) String

func (pk *PrivateKey) String() string

String returns the hexadecimal representation of the private key with "0x" prefix.

type PublicKey

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

PublicKey represents a cryptographic public key.

func DecodePublicKey

func DecodePublicKey(encoded string) (*PublicKey, error)

NewPublicKeyFromStr creates a new PublicKey instance from a hexadecimal encoded string.

func RecoverPublicKeyFromSignature

func RecoverPublicKeyFromSignature(message string, signature string) (*PublicKey, error)

RecoverPublicKeyFromSignature recovers a public key from a message signature.

func (*PublicKey) Address

func (pub *PublicKey) Address() string

Address returns the Ethereum-style address derived from the public key.

func (*PublicKey) String

func (pub *PublicKey) String() string

String returns the hexadecimal representation of the public key with "0x" prefix.

func (*PublicKey) VerifySignature

func (pub *PublicKey) VerifySignature(msg string, signature []byte) bool

Verify verifies a message signature using the public key.

Jump to

Keyboard shortcuts

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