mcrypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AddressLength is the length of a Monero address
	AddressLength = 1 + 32 + 32 + 4
)
View Source
const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

BASE58 ...

Variables

This section is empty.

Functions

func DecodeMoneroBase58

func DecodeMoneroBase58(data string) (result []byte)

DecodeMoneroBase58 decodes base-58 encoded data into a byte slice

func EncodeMoneroBase58

func EncodeMoneroBase58(data ...[]byte) (result string)

EncodeMoneroBase58 encodes byte data using base-58

func ValidateAddress

func ValidateAddress(addr string) error

ValidateAddress checks if the given address is valid TODO: also check chain prefix

Types

type Address

type Address string

Address represents a base58-encoded string

type PrivateKeyInfo

type PrivateKeyInfo struct {
	PrivateSpendKey string
	PrivateViewKey  string
	Address         string
	Environment     string
}

PrivateKeyInfo ...

type PrivateKeyPair

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

PrivateKeyPair represents a monero private spend and view key.

func GenerateKeys

func GenerateKeys() (*PrivateKeyPair, error)

GenerateKeys generates a private spend key and view key

func NewPrivateKeyPair

func NewPrivateKeyPair(sk *PrivateSpendKey, vk *PrivateViewKey) *PrivateKeyPair

NewPrivateKeyPair returns a new PrivateKeyPair from the given PrivateSpendKey and PrivateViewKey. It does not validate if the view key corresponds to the spend key.

func NewPrivateKeyPairFromBytes

func NewPrivateKeyPairFromBytes(skBytes, vkBytes []byte) (*PrivateKeyPair, error)

NewPrivateKeyPairFromBytes returns a new PrivateKeyPair given the canonical byte representation of a private spend and view key.

func (*PrivateKeyPair) Address

func (kp *PrivateKeyPair) Address(env common.Environment) Address

Address returns the base58-encoded address for a PrivateKeyPair with the given environment (ie. mainnet or stagenet)

func (*PrivateKeyPair) AddressBytes

func (kp *PrivateKeyPair) AddressBytes(env common.Environment) []byte

AddressBytes returns the address as bytes for a PrivateKeyPair with the given environment (ie. mainnet or stagenet)

func (*PrivateKeyPair) Info

Info return the private key pair as PrivateKeyInfo, providing its PrivateSpendKey, PrivateViewKey, Address, and Environment. This is intended to be written to a file, which someone can use to regenerate the wallet.

func (*PrivateKeyPair) PublicKeyPair

func (kp *PrivateKeyPair) PublicKeyPair() *PublicKeyPair

PublicKeyPair returns the PublicKeyPair corresponding to the PrivateKeyPair

func (*PrivateKeyPair) SpendKey

func (kp *PrivateKeyPair) SpendKey() *PrivateSpendKey

SpendKey returns the keypair's spend key

func (*PrivateKeyPair) SpendKeyBytes

func (kp *PrivateKeyPair) SpendKeyBytes() []byte

SpendKeyBytes returns the canoncail byte encoding of the private spend key.

func (*PrivateKeyPair) ViewKey

func (kp *PrivateKeyPair) ViewKey() *PrivateViewKey

ViewKey returns the keypair's view key

type PrivateSpendKey

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

PrivateSpendKey represents a monero private spend key

func NewPrivateSpendKey

func NewPrivateSpendKey(b []byte) (*PrivateSpendKey, error)

NewPrivateSpendKey returns a new PrivateSpendKey from the given canonically-encoded scalar.

func SumPrivateSpendKeys

func SumPrivateSpendKeys(a, b *PrivateSpendKey) *PrivateSpendKey

SumPrivateSpendKeys sums two private spend keys (scalars)

func (*PrivateSpendKey) AsPrivateKeyPair

func (k *PrivateSpendKey) AsPrivateKeyPair() (*PrivateKeyPair, error)

AsPrivateKeyPair returns the PrivateSpendKey as a PrivateKeyPair.

func (*PrivateSpendKey) Bytes

func (k *PrivateSpendKey) Bytes() []byte

Bytes returns the PrivateSpendKey as canonical bytes

func (*PrivateSpendKey) Hash

func (k *PrivateSpendKey) Hash() [32]byte

Hash returns the keccak256 of the secret key bytes

func (*PrivateSpendKey) HashString

func (k *PrivateSpendKey) HashString() string

HashString returns the keccak256 of the secret key bytes as a hex encoded string

func (*PrivateSpendKey) Hex

func (k *PrivateSpendKey) Hex() string

Hex returns the hex-encoded canonical byte representation of the PrivateSpendKey.

func (*PrivateSpendKey) Public

func (k *PrivateSpendKey) Public() *PublicKey

Public returns the public key corresponding to the private key.

func (*PrivateSpendKey) Sign

func (k *PrivateSpendKey) Sign(msg []byte) (*Signature, error)

Sign signs the given message with the private key. The private key must have been created with GenerateKeys().

func (*PrivateSpendKey) View

func (k *PrivateSpendKey) View() (*PrivateViewKey, error)

View returns the private view key corresponding to the PrivateSpendKey.

type PrivateViewKey

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

PrivateViewKey represents a monero private view key.

func NewPrivateViewKeyFromHex

func NewPrivateViewKeyFromHex(vkHex string) (*PrivateViewKey, error)

NewPrivateViewKeyFromHex returns a new PrivateViewKey from the given canonically- and hex-encoded scalar.

func SumPrivateViewKeys

func SumPrivateViewKeys(a, b *PrivateViewKey) *PrivateViewKey

SumPrivateViewKeys sums two private view keys (scalars)

func (*PrivateViewKey) Hex

func (k *PrivateViewKey) Hex() string

Hex returns the hex-encoded canonical byte representation of the PrivateViewKey.

func (*PrivateViewKey) Public

func (k *PrivateViewKey) Public() *PublicKey

Public returns the PublicKey corresponding to this PrivateViewKey.

type PublicKey

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

PublicKey represents a monero public spend or view key.

func NewPublicKeyFromHex

func NewPublicKeyFromHex(s string) (*PublicKey, error)

NewPublicKeyFromHex returns a new PublicKey from the given canonically- and hex-encoded point.

func SumPublicKeys

func SumPublicKeys(a, b *PublicKey) *PublicKey

SumPublicKeys sums two public keys (points)

func (*PublicKey) Bytes

func (k *PublicKey) Bytes() []byte

Bytes returns the canonical byte representation of the PublicKey.

func (*PublicKey) Hex

func (k *PublicKey) Hex() string

Hex returns the hex-encoded canonical byte representation of the PublicKey.

func (*PublicKey) Verify

func (k *PublicKey) Verify(msg []byte, sig *Signature) bool

Verify verifies that the message was signed with the given signature and key.

type PublicKeyPair

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

PublicKeyPair contains a public SpendKey and ViewKey

func NewPublicKeyPair

func NewPublicKeyPair(sk, vk *PublicKey) *PublicKeyPair

NewPublicKeyPair returns a new PublicKeyPair from the given public spend and view keys.

func NewPublicKeyPairFromHex

func NewPublicKeyPairFromHex(skHex, vkHex string) (*PublicKeyPair, error)

NewPublicKeyPairFromHex returns a new PublicKeyPair from the given canonically- and hex-encoded points.

func SumSpendAndViewKeys

func SumSpendAndViewKeys(a, b *PublicKeyPair) *PublicKeyPair

SumSpendAndViewKeys sums two PublicKeyPairs, returning another PublicKeyPair.

func (*PublicKeyPair) Address

func (kp *PublicKeyPair) Address(env common.Environment) Address

Address returns the base58-encoded address for a PublicKeyPair with the given environment (ie. mainnet or stagenet)

func (*PublicKeyPair) AddressBytes

func (kp *PublicKeyPair) AddressBytes(env common.Environment) []byte

AddressBytes returns the address as bytes for a PublicKeyPair with the given environment (ie. mainnet or stagenet)

func (*PublicKeyPair) SpendKey

func (kp *PublicKeyPair) SpendKey() *PublicKey

SpendKey returns the keypair's spend key.

func (*PublicKeyPair) ViewKey

func (kp *PublicKeyPair) ViewKey() *PublicKey

ViewKey returns the keypair's view key.

type Signature

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

Signature represents an ed25519 signature

func NewSignatureFromHex

func NewSignatureFromHex(s string) (*Signature, error)

NewSignatureFromHex returns a new Signature from the given hex-encoded string. The string must be 64 bytes.

func (*Signature) Hex

func (s *Signature) Hex() string

Hex returns the signature as a hex-encoded string.

Jump to

Keyboard shortcuts

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