crypto

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CompressedSecp256K1PublicKeySize = 33

CompressedSecp256K1PublicKeySize is size of public key in compressed format

View Source
const PrivateKeySecp256K1Size = 32

PrivateKeySecp256K1Size is the size of the private key in bytes

Variables

View Source
var (
	ErrInvalidArgument    = errors.New("invalid nil argument")
	ErrVerificationFailed = errors.New("verification failed")
)

Functions

This section is empty.

Types

type InMemorySecp256K1Signer

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

InMemorySecp256K1Signer for using during development

func NewInMemorySecp256K1Signer

func NewInMemorySecp256K1Signer() (*InMemorySecp256K1Signer, error)

NewInMemorySecp256K1Signer generates new key pair and creates a new InMemorySecp256K1Signer.

func NewInMemorySecp256K1SignerFromKey

func NewInMemorySecp256K1SignerFromKey(privKey []byte) (*InMemorySecp256K1Signer, error)

NewInMemorySecp256K1SignerFromKey creates signer from an existing private key.

func (*InMemorySecp256K1Signer) MarshalPrivateKey

func (s *InMemorySecp256K1Signer) MarshalPrivateKey() ([]byte, error)

func (*InMemorySecp256K1Signer) SignBytes

func (s *InMemorySecp256K1Signer) SignBytes(data []byte) ([]byte, error)

SignBytes hashes the data with SHA256 and creates a recoverable ECDSA signature. The produced signature is in the 65-byte [R || S || V] format where V is 0 or 1.

func (*InMemorySecp256K1Signer) SignHash

func (s *InMemorySecp256K1Signer) SignHash(hash []byte) ([]byte, error)

SignHash creates a recoverable ECDSA signature. The produced signature is in the 65-byte [R || S || V] format where V is 0 or 1.

func (*InMemorySecp256K1Signer) SignObject

SignObject transforms the object to canonical form and then signs the data using SignBytes method.

func (*InMemorySecp256K1Signer) Verifier

func (s *InMemorySecp256K1Signer) Verifier() (Verifier, error)

type Signer

type Signer interface {
	// SignBytes signs the data using the signatureScheme and private key specified by the Signer.
	// Returns signature bytes or error.
	SignBytes(data []byte) ([]byte, error)
	// SignHash signs the hashed using the signatureScheme and private key specified by the Signer.
	// Returns signature bytes or error.
	SignHash(data []byte) ([]byte, error)
	// SignObject converts the object into bytes and signs the bytes. Returns signature bytes or error.
	SignObject(obj canonicalizer.Canonicalizer, opts ...canonicalizer.Option) ([]byte, error)
	// MarshalPrivateKey returns the private key bytes so these could be unmarshalled later to create the Signer.
	MarshalPrivateKey() ([]byte, error)
	// Verifier returns a verifier that verifies using the public key part.
	Verifier() (Verifier, error)
}

Signer component for digitally signing data.

type Verifier

type Verifier interface {
	// VerifyBytes verifies the bytes against the signature, using the internal public key.
	VerifyBytes(sig []byte, data []byte) error
	// VerifyHash verifies the hash against the signature, using the internal public key.
	VerifyHash(signature []byte, hash []byte) error
	// VerifyObject verifies that signature authenticates the object canonical form with the public key inside Verifier.
	VerifyObject(sig []byte, obj canonicalizer.Canonicalizer, opts ...canonicalizer.Option) error
	// MarshalPublicKey marshal verifier public key to bytes.
	MarshalPublicKey() ([]byte, error)
	// UnmarshalPubKey unmarshal verifier public key to crypto.PublicKey
	UnmarshalPubKey() (crypto.PublicKey, error)
}

Verifier component for verifying signatures.

func NewVerifierSecp256k1

func NewVerifierSecp256k1(compressedPubKey []byte) (Verifier, error)

NewVerifierSecp256k1 creates new verifier from an existing Secp256k1 compressed public key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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