crypto

package
v0.0.0-...-50d17a8 Latest Latest
Warning

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

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

Documentation

Overview

Package crypto implements cryptographic types and functions used to prove integrity and ownership.

Index

Constants

View Source
const ADDR_BYTE_SIZE = 32

ADDR_BYTE_SIZE is the length of the Address in bytes

View Source
const HASH_BYTE_SIZE = 32

HASH_BYTE_SIZE is the hash length in bytes used by the Hash type.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address [ADDR_BYTE_SIZE]uint8

An Address is used to publicly identify a Blockchain account

func AddressFromBytes

func AddressFromBytes(b []byte) (Address, error)

AddressFromBytes returns an Address given a HASH_BYTE_SIZE byte slice.

func AddressFromString

func AddressFromString(hexAddress string) (Address, error)

AddressFromString returns an Address given a (HASH_BYTE_SIZE * 8) bits hexadecimal address string.

func (Address) Bytes

func (addr Address) Bytes() []byte

Bytes returns the byte slice representation of the Address

func (Address) IsOwner

func (addr Address) IsOwner(pk PublicKey) bool

IsOwner checks that the Address was derived from the PublicKey

func (Address) String

func (addr Address) String() string

String returns the hexadecimal string representation of the Address.

type Hash

type Hash [HASH_BYTE_SIZE]uint8

A Hash is a wrapper around the output of a (HASH_BYTE_SIZE * 8) bits hash function.

func HashFromBytes

func HashFromBytes(b []byte) (Hash, error)

HashFromBytes returns a Hash given a HASH_BYTE_SIZE byte slice.

func HashFromString

func HashFromString(hstr string) (Hash, error)

HashFromString returns a Hash given a (HASH_BYTE_SIZE * 8) bits hexadecimal hash string.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the byte slice representation of the Hash.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero checks that the Hash is equal to zero (is unset or got invalidated).

func (Hash) String

func (h Hash) String() string

String returns the hexadecimal string representation of the Hash.

type PrivateKey

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

A PrivateKey is used for signing objects.

func GeneratePrivateKey

func GeneratePrivateKey() (PrivateKey, error)

GeneratePrivateKey returns a PrivateKey randomized using cryptographically secure entropy.

func NewPrivateKeyFromReader

func NewPrivateKeyFromReader(r io.Reader) (PrivateKey, error)

NewPrivateKeyFromReader returns a random PrivateKey from a io.Reader entropy.

func (PrivateKey) PublicKey

func (k PrivateKey) PublicKey() PublicKey

PublicKey returns the PublicKey of the PrivateKey.

func (PrivateKey) Sign

func (k PrivateKey) Sign(hash Hash) (Signature, error)

Sign returns the Signature of a slice of bytes of size 32 bytes.

type PublicKey

type PublicKey []byte

PublicKey is used to verify a PrivateKey signature.

func (PublicKey) Address

func (k PublicKey) Address() Address

Address returns the public Address corresponding to the PublicKey

func (PublicKey) String

func (k PublicKey) String() string

String returns a hexadecimal string encoding of the PublicKey.

type Signature

type Signature []byte

A Signature is used to prove that some data was signed by a PrivateKey.

func (Signature) PublicKey

func (sig Signature) PublicKey(hash Hash) (PublicKey, error)

PublicKey returns the PublicKey of the Signature signer.

func (Signature) String

func (sig Signature) String() string

String returns a hexadecimal string encoding of the Signature.

Jump to

Keyboard shortcuts

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