crypto

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidHexString is returned when the hex string is invalid.
	ErrInvalidHexString = errors.New("invalid hex string")

	// ErrInvalidDERNotEnoughData is returned when the DER data is not enough.
	ErrInvalidDERNotEnoughData = errors.New("invalid DER: not enough data")
	// ErrInvalidDERIntegerTag is returned when the DER integer tag is invalid.
	ErrInvalidDERIntegerTag = errors.New("invalid DER: expected integer tag")
	// ErrInvalidDERSignature is returned when the DER signature is invalid.
	ErrInvalidDERSignature = errors.New("invalid signature: incorrect length")
	// ErrLeftoverBytes is returned when there are leftover bytes after parsing the DER signature.
	ErrLeftoverBytes = errors.New("invalid signature: left bytes after parsing")
)
View Source
var (

	// ErrValidatorKeypairDerivation is returned when a validator keypair is attempted to be derived
	ErrValidatorKeypairDerivation = errors.New("validator keypair derivation not supported")
	// ErrInvalidPrivateKey is returned when a private key is invalid
	ErrInvalidPrivateKey = errors.New("invalid private key")
	// ErrInvalidMessage is returned when a message is required but not provided
	ErrInvalidMessage = errors.New("message is required")
)
View Source
var (

	// ErrValidatorNotSupported is returned when a validator keypair is used with the ED25519 algorithm.
	ErrValidatorNotSupported = errors.New("validator keypairs can not use Ed25519")
)

Functions

func DERHexFromSig

func DERHexFromSig(rHex, sHex string) (string, error)

DERHexFromSig converts r and s hex strings to a DER-encoded signature hex string. It returns the DER-encoded signature as a hex string and an error if any occurred during the process.

func DERHexToSig

func DERHexToSig(hexSignature string) ([]byte, []byte, error)

DERHexToSig converts a DER-encoded signature hex string to r and s byte slices. It returns the r and s byte slices and an error if any occurred during the process.

func Sha512Half

func Sha512Half(msg []byte) []byte

Returns the first 32 bytes of a sha512 hash of a message

Types

type Algorithm

type Algorithm interface {
	Prefix() byte
	FamilySeedPrefix() byte
}

type ED25519CryptoAlgorithm

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

ED25519CryptoAlgorithm is the implementation of the ED25519 cryptographic algorithm.

func ED25519

func ED25519() ED25519CryptoAlgorithm

ED25519 returns the ED25519 cryptographic algorithm.

func (ED25519CryptoAlgorithm) DeriveKeypair

func (c ED25519CryptoAlgorithm) DeriveKeypair(decodedSeed []byte, validator bool) (string, string, error)

DeriveKeypair derives a keypair from a seed.

func (ED25519CryptoAlgorithm) FamilySeedPrefix

func (c ED25519CryptoAlgorithm) FamilySeedPrefix() byte

FamilySeedPrefix returns the family seed prefix for the ED25519 cryptographic algorithm.

func (ED25519CryptoAlgorithm) Prefix

func (c ED25519CryptoAlgorithm) Prefix() byte

Prefix returns the prefix for the ED25519 cryptographic algorithm.

func (ED25519CryptoAlgorithm) Sign

func (c ED25519CryptoAlgorithm) Sign(msg, privKey string) (string, error)

func (ED25519CryptoAlgorithm) Validate

func (c ED25519CryptoAlgorithm) Validate(msg, pubkey, sig string) bool

Validate validates a signature for a message with a public key.

type SECP256K1CryptoAlgorithm

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

SECP256K1CryptoAlgorithm is the implementation of the SECP256K1 algorithm.

func SECP256K1

func SECP256K1() SECP256K1CryptoAlgorithm

SECP256K1 returns a new SECP256K1CryptoAlgorithm instance.

func (SECP256K1CryptoAlgorithm) DeriveKeypair

func (c SECP256K1CryptoAlgorithm) DeriveKeypair(seed []byte, validator bool) (string, string, error)

DeriveKeypair derives a keypair from a seed.

func (SECP256K1CryptoAlgorithm) DerivePublicKeyFromPublicGenerator

func (c SECP256K1CryptoAlgorithm) DerivePublicKeyFromPublicGenerator(pubKey []byte) ([]byte, error)

DerivePublicKeyFromPublicGenerator derives a public key from a public generator.

func (SECP256K1CryptoAlgorithm) FamilySeedPrefix

func (c SECP256K1CryptoAlgorithm) FamilySeedPrefix() byte

FamilySeedPrefix returns the family seed prefix for the SECP256K1 algorithm.

func (SECP256K1CryptoAlgorithm) Prefix

func (c SECP256K1CryptoAlgorithm) Prefix() byte

Prefix returns the prefix for the SECP256K1 algorithm.

func (SECP256K1CryptoAlgorithm) Sign

func (c SECP256K1CryptoAlgorithm) Sign(msg, privKey string) (string, error)

Sign signs a message with a private key.

func (SECP256K1CryptoAlgorithm) Validate

func (c SECP256K1CryptoAlgorithm) Validate(msg, pubkey, sig string) bool

Validate validates a signature for a message with a public key.

Jump to

Keyboard shortcuts

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