mcrypto

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mcrypto is for types and libraries that deal with Monero keys, addresses and signing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

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

Address represents a Monero address

func NewAddress

func NewAddress(addrStr string, env common.Environment) (*Address, error)

NewAddress converts a string to a monero Address with validation.

func (*Address) Equal

func (a *Address) Equal(b *Address) bool

Equal returns true if the addresses are identical, otherwise false.

func (*Address) MarshalText

func (a *Address) MarshalText() ([]byte, error)

MarshalText serializes the Monero Address type with some extra validation.

func (*Address) Network

func (a *Address) Network() Network

Network returns the Monero network of the address

func (*Address) String

func (a *Address) String() string

func (*Address) Type

func (a *Address) Type() AddressType

Type returns the Address type

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(base58Input []byte) error

UnmarshalText converts a base58 encoded monero address to our Address type. The encoding, length and checksum are all validated, but not the network, as it is unknown by the JSON parser. Empty strings are not allowed. Use an address pointer in your serialized types if the Address is optional.

func (*Address) ValidateEnv

func (a *Address) ValidateEnv(env common.Environment) error

ValidateEnv validates that the monero network matches the passed environment. This validation can't be performed when decoding JSON, as the environment is not known at that time.

type AddressType

type AddressType string

AddressType is the type of Monero address: Standard or Subaddress

const (
	Standard   AddressType = "standard"
	Subaddress AddressType = "subaddress"
)

Monero address types. We don't support Integrated.

type Network

type Network string

Network is the Monero network type

const (
	Mainnet  Network = "mainnet"
	Stagenet Network = "stagenet"
	Testnet  Network = "testnet"
)

Monero networks

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. Both values must be set, as no assumptions are made that the view key is derived from the spend key with this type.

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) MarshalJSON

func (kp *PrivateKeyPair) MarshalJSON() ([]byte, error)

MarshalJSON provides JSON marshalling for PrivateKeyPair

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 key pair's spend key

func (*PrivateKeyPair) SpendKeyBytes

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

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

func (*PrivateKeyPair) UnmarshalJSON

func (kp *PrivateKeyPair) UnmarshalJSON(data []byte) error

UnmarshalJSON provides JSON unmarshalling for PrivateKeyPair

func (*PrivateKeyPair) ViewKey

func (kp *PrivateKeyPair) ViewKey() *PrivateViewKey

ViewKey returns the key pair'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) Hex

func (k *PrivateSpendKey) Hex() string

Hex formats the key as a hex string

func (*PrivateSpendKey) MarshalText

func (k *PrivateSpendKey) MarshalText() ([]byte, error)

MarshalText returns the 64-symbol LE hex representation of k

func (*PrivateSpendKey) Public

func (k *PrivateSpendKey) Public() *PublicKey

Public returns the public key corresponding to the private key.

func (*PrivateSpendKey) String

func (k *PrivateSpendKey) String() string

String formats the key as a 0x-prefixed hex string

func (*PrivateSpendKey) UnmarshalText

func (k *PrivateSpendKey) UnmarshalText(input []byte) error

UnmarshalText assigns k from LE hex input (64 symbols, 32 bytes).

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 SumPrivateViewKeys

func SumPrivateViewKeys(a, b *PrivateViewKey) *PrivateViewKey

SumPrivateViewKeys sums two private view keys (scalars)

func (*PrivateViewKey) Bytes

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

Bytes returns the canonical 32-byte little-endian encoding of PrivateViewKey.

func (*PrivateViewKey) Hex

func (k *PrivateViewKey) Hex() string

Hex formats the key as a hex string

func (*PrivateViewKey) MarshalText

func (k *PrivateViewKey) MarshalText() ([]byte, error)

MarshalText returns the 64-symbol LE hex representation of k

func (*PrivateViewKey) Public

func (k *PrivateViewKey) Public() *PublicKey

Public returns the PublicKey corresponding to this PrivateViewKey.

func (*PrivateViewKey) String

func (k *PrivateViewKey) String() string

String formats the key as a 0x-prefixed hex string

func (*PrivateViewKey) UnmarshalText

func (k *PrivateViewKey) UnmarshalText(input []byte) error

UnmarshalText assigns k from LE hex input (64 symbols, 32 bytes).

type PublicKey

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

PublicKey represents a monero public spend or view key.

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(b []byte) (*PublicKey, error)

NewPublicKeyFromBytes returns a new PublicKey from the given canonically-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 32-byte, little-endian encoding of PublicKey.

func (*PublicKey) Hex

func (k *PublicKey) Hex() string

Hex formats the key as a hex string

func (*PublicKey) MarshalText

func (k *PublicKey) MarshalText() ([]byte, error)

MarshalText returns the 64-symbol LE hex representation of k

func (*PublicKey) String

func (k *PublicKey) String() string

String formats the key as a 0x-prefixed hex string

func (*PublicKey) UnmarshalText

func (k *PublicKey) UnmarshalText(input []byte) error

UnmarshalText assigns k from LE hex input (64 symbols, 32 bytes).

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 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 address as bytes for a PublicKeyPair with the given environment (ie. mainnet or stagenet)

func (*PublicKeyPair) MarshalJSON

func (kp *PublicKeyPair) MarshalJSON() ([]byte, error)

MarshalJSON provides JSON marshalling for PublicKeyPair

func (*PublicKeyPair) SpendKey

func (kp *PublicKeyPair) SpendKey() *PublicKey

SpendKey returns the key pair's spend key.

func (*PublicKeyPair) UnmarshalJSON

func (kp *PublicKeyPair) UnmarshalJSON(data []byte) error

UnmarshalJSON provides JSON unmarshalling for PublicKeyPair

func (*PublicKeyPair) ViewKey

func (kp *PublicKeyPair) ViewKey() *PublicKey

ViewKey returns the key pair's view key.

Jump to

Keyboard shortcuts

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