crypto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Secp256k1CompressedPublicKeySize   = 33
	Secp256k1UncompressedPublicKeySize = 65
)

Variables

View Source
var (
	ErrInvalidSignature       = errors.New("signature verification failed")
	ErrInvalidSignatureLength = errors.New("invalid signature length")
)

Functions

func Sha224

func Sha224(data []byte) []byte

func Sha224Hex

func Sha224Hex(data []byte) string

func Sha256

func Sha256(data []byte) []byte

func Sha256Hex

func Sha256Hex(data []byte) string

Types

type Ed25519PrivateKey

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

func Ed25519PrivateKeyFromBytes

func Ed25519PrivateKeyFromBytes(key []byte) (*Ed25519PrivateKey, error)

func Ed25519PrivateKeyFromHex

func Ed25519PrivateKeyFromHex(key string) (*Ed25519PrivateKey, error)

func GenerateEd25519Key

func GenerateEd25519Key() (*Ed25519PrivateKey, error)

GenerateEd25519Key generates a new ed25519 key pair.

func (*Ed25519PrivateKey) Bytes

func (pv *Ed25519PrivateKey) Bytes() []byte

func (*Ed25519PrivateKey) Hex

func (pv *Ed25519PrivateKey) Hex() string

func (*Ed25519PrivateKey) PubKey

func (pv *Ed25519PrivateKey) PubKey() *Ed25519PublicKey

func (*Ed25519PrivateKey) Sign

func (pv *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)

Sign signs the given message(not hashed). This returns a standard ed25519 signature, 64 bytes long.

type Ed25519PublicKey

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

func Ed25519PublicKeyFromBytes

func Ed25519PublicKeyFromBytes(key []byte) (*Ed25519PublicKey, error)

func (*Ed25519PublicKey) Bytes

func (pub *Ed25519PublicKey) Bytes() []byte

func (*Ed25519PublicKey) Verify

func (pub *Ed25519PublicKey) Verify(sig []byte, msg []byte) error

Verify verifies the given signature against the given message(not hashed). This expects a standard ed25519 signature, 64 bytes long.

type Secp256k1PrivateKey

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

func GenerateSecp256k1Key

func GenerateSecp256k1Key() (*Secp256k1PrivateKey, error)

GenerateSecp256k1Key generates a new secp256k1 private key.

func Secp256k1PrivateKeyFromHex

func Secp256k1PrivateKeyFromHex(key string) (*Secp256k1PrivateKey, error)

func (*Secp256k1PrivateKey) Bytes

func (pv *Secp256k1PrivateKey) Bytes() []byte

func (*Secp256k1PrivateKey) Hex

func (pv *Secp256k1PrivateKey) Hex() string

func (*Secp256k1PrivateKey) PubKey

func (*Secp256k1PrivateKey) Sign

func (pv *Secp256k1PrivateKey) Sign(hash []byte) ([]byte, error)

Sign signs the given hash directly utilizing go-ethereum's Sign function. go-ethereum returns a secp256k1 signature, in [R || S || V] format where V is 0 or 1, 65 bytes long. We want to remove the recovery ID, so we return a 64 byte signature, in [R || S] format.

func (*Secp256k1PrivateKey) SignWithRecoveryID

func (pv *Secp256k1PrivateKey) SignWithRecoveryID(hash []byte) ([]byte, error)

SignWithRecoveryID signs the given hash directly utilizing go-ethereum's Sign function. It includes go-ethereum's recovery ID, which while it is non-standard for Secp256k1, is very common in Bitcoin and Ethereum

type Secp256k1PublicKey

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

func Secp256k1PublicKeyFromBytes

func Secp256k1PublicKeyFromBytes(key []byte) (*Secp256k1PublicKey, error)

func (*Secp256k1PublicKey) Bytes

func (pub *Secp256k1PublicKey) Bytes() []byte

func (*Secp256k1PublicKey) Verify

func (pub *Secp256k1PublicKey) Verify(sig []byte, hash []byte) error

Verify verifies the standard secp256k1 signature against the given hash. Caller of this function should make sure the signature is in one of the following two formats: - 65 bytes, [R || S || V] format. This is the standard format. - 64 bytes, [R || S] format.

Since `Verify` suppose to verify the signature produced from `Sign` function, it expects the signature to be 65 bytes long, and in [R || S || V] format where V is 0 or 1. In this implementation, we use `VerifySignature`, which doesn't care about the recovery ID, so it can also support 64 bytes [R || S] format signature like cometbft. e.g. this `Verify` function is able to verify multi-signature-schema like personal_sign, eip712, cometbft, etc., as long as the given signature is in supported format.

Directories

Path Synopsis
Package auth provides the standard signing and verification methods used in Kwil.
Package auth provides the standard signing and verification methods used in Kwil.

Jump to

Keyboard shortcuts

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