utils

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ATOMIC_UNIT                     float64 = 1e12
	CHECKSUM_SIZE                   int     = 4
	KEY_SIZE                        int     = 32
	BASE58_FULL_BLOCK_SIZE          int     = 8
	BASE58_ENCODED_BLOCK_SIZE       int     = 11
	INTEGRATED_ADDRESS_SIZE         int     = 106
	INTEGRATED_ADDRESS_DECODED_SIZE int     = 77
	ADDRESS_SIZE                    int     = 95
	ADDRESS_DECODED_SIZE            int     = 69
)

Variables

This section is empty.

Functions

func DecodeMoneroAddress

func DecodeMoneroAddress(addr string) ([]byte, error)

Decodes and validates if the given addr string is a valid Monero integrated/sub-/primary address

func DecryptOutputPublicSpendKey

func DecryptOutputPublicSpendKey(spendKey *PublicKey, outIndex uint32, outKey *PublicKey, amount string, txPub *PublicKey, viewKey *PrivateKey) (bool, uint64, error)

Checks whether the output belongs to the specific private view and public spend keys and if so, returns a decrypted amount

func DecryptOutputViewTag

func DecryptOutputViewTag(viewTag string, outIndex uint32, amount string, txPub *PublicKey, viewKey *PrivateKey) (bool, uint64, error)

Checks whether the output belongs to the specific private view key by comparing view tags and if so, returns a decrypted amount

func EncodeMoneroAddress

func EncodeMoneroAddress(addr []byte) ([]byte, error)

Validates if the given addr []byte is a valid Monero integrated/sub-/primary decoded representation and encodes it

func Float64ToXMR

func Float64ToXMR(xmr float64) uint64

Converts the float64 to a raw atomic XMR

func GetNetworkTypeAndAddressType

func GetNetworkTypeAndAddressType(prefix byte) (NetworkType, AddressType, error)

Returns a NetworkType and an AddressType base on the Monero address prefix

func GetPaymentIdFromExtra

func GetPaymentIdFromExtra(extra []byte) ([]byte, error)

Parses the extra field and returns a payment id

func GetPrefix

func GetPrefix(nt NetworkType, at AddressType) (byte, error)

Returns a NetworkType and an AddressType base on the Monero address prefix

func Keccak256Hash

func Keccak256Hash(data []byte) ([]byte, error)

Returns a hash calculated by the Keccak256 hash algorithm

func NewPaymentID256

func NewPaymentID256() []byte

NewPaymentID256 generates a 256 bit payment ID (hex encoded).

func NewPaymentID64

func NewPaymentID64() []byte

NewPaymentID64 generates a 64 bit payment ID (hex encoded). With 64 bit IDs, there is a non-negligible chance of a collision if they are randomly generated. It is up to recipients generating them to sanity check for uniqueness.

1 million IDs at 64-bit (simplified): 1,000,000^2 / (2^64 * 2) = ~1/36,893,488 so there is a 50% chance a collision happens around 5.06 billion IDs generated.

func OutputBelongsPublicSpendKey

func OutputBelongsPublicSpendKey(spendKey *PublicKey, outIndex uint32, outKey *PublicKey, txPub *PublicKey, viewKey *PrivateKey) (bool, error)

Checks whether the output belongs to the specific private view and public spend keys

func OutputBelongsViewTag

func OutputBelongsViewTag(viewTag string, outIndex uint32, txPub *PublicKey, viewKey *PrivateKey) (bool, error)

Checks whether the output belongs to the specific private view key by comparing view tags

func ParseJsonString

func ParseJsonString[R any](str string) (*R, error)

func ParseResponse

func ParseResponse[R any](body io.Reader) (*R, error)

func XMRToDecimal

func XMRToDecimal(xmr uint64) string

Converts the raw atomic XMR balance to a more human readable format.

func XMRToFloat64

func XMRToFloat64(xmr uint64) float64

Converts the raw atomic XMR to a float64

Types

type AddressType

type AddressType uint8
const (
	Primary AddressType = iota
	Sub
	Integrated
)

type FullKeyPair added in v0.2.0

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

func NewFullKeyPair added in v0.2.0

func NewFullKeyPair(view *PrivateKey, spend *PrivateKey) *FullKeyPair

func NewFullKeyPairSpendPrivateKey added in v0.2.0

func NewFullKeyPairSpendPrivateKey(spend *PrivateKey) (*FullKeyPair, error)

func (*FullKeyPair) SpendKeyPair added in v0.2.0

func (p *FullKeyPair) SpendKeyPair() *KeyPair

func (*FullKeyPair) ViewKeyPair added in v0.2.0

func (p *FullKeyPair) ViewKeyPair() *KeyPair

func (*FullKeyPair) ViewOnlyKeyPair added in v0.2.0

func (p *FullKeyPair) ViewOnlyKeyPair() *ViewOnlyKeyPair

type IntegratedAddress

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

func (*IntegratedAddress) Address

func (a *IntegratedAddress) Address() string

Returns a string representation of the Monero integrated/sub-/primary address

func (*IntegratedAddress) AddressType

func (a *IntegratedAddress) AddressType() AddressType

Returns an AddressType from the Monero integrated/sub-/primary address

func (*IntegratedAddress) NetworkType

func (a *IntegratedAddress) NetworkType() NetworkType

Returns a NetworkType from the Monero integrated/sub-/primary address

func (*IntegratedAddress) PaymentId

func (a *IntegratedAddress) PaymentId() []byte

Returns a PaymentId from the Monero integrated address

func (*IntegratedAddress) PublicSpendKey

func (a *IntegratedAddress) PublicSpendKey() *PublicKey

Returns a Public Spend Key from the Monero integrated/sub-/primary address

func (*IntegratedAddress) PublicViewKey

func (a *IntegratedAddress) PublicViewKey() *PublicKey

Returns a Public View Key from the Monero integrated/sub-/primary address

type KeyPair added in v0.2.0

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

func NewKeyPair added in v0.2.0

func NewKeyPair(priv *PrivateKey) *KeyPair

func (*KeyPair) PrivateKey added in v0.2.0

func (k *KeyPair) PrivateKey() *PrivateKey

func (*KeyPair) PublicKey added in v0.2.0

func (k *KeyPair) PublicKey() *PublicKey

type MnemonicLanguage added in v0.2.0

type MnemonicLanguage uint8
const (
	English MnemonicLanguage = iota
)

type MoneroAddress

type MoneroAddress interface {
	PublicSpendKey() *PublicKey
	PublicViewKey() *PublicKey
	AddressType() AddressType
	NetworkType() NetworkType
	Address() string
}

func NewAddress

func NewAddress(addr string) (MoneroAddress, error)

Creates a Monero integrated/sub-/primary address

type NetworkType

type NetworkType uint8
const (
	Mainnet NetworkType = iota
	Stagenet
	Testnet
)

type PrimaryAddress

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

func (*PrimaryAddress) Address

func (a *PrimaryAddress) Address() string

Returns a string representation of the Monero integrated/sub-/primary address

func (*PrimaryAddress) AddressType

func (a *PrimaryAddress) AddressType() AddressType

Returns an AddressType from the Monero integrated/sub-/primary address

func (*PrimaryAddress) NetworkType

func (a *PrimaryAddress) NetworkType() NetworkType

Returns a NetworkType from the Monero integrated/sub-/primary address

func (*PrimaryAddress) PublicSpendKey

func (a *PrimaryAddress) PublicSpendKey() *PublicKey

Returns a Public Spend Key from the Monero integrated/sub-/primary address

func (*PrimaryAddress) PublicViewKey

func (a *PrimaryAddress) PublicViewKey() *PublicKey

Returns a Public View Key from the Monero integrated/sub-/primary address

type PrivateKey

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

func GetPrivateViewKeyFromPrivateSpendKey added in v0.2.0

func GetPrivateViewKeyFromPrivateSpendKey(spend *PrivateKey) (*PrivateKey, error)

Derives the Private View Key from the Private Spend Key

func NewPrivateKey

func NewPrivateKey(keyStr string) (*PrivateKey, error)

Creates Private Key from a hex string representation

func (*PrivateKey) Bytes

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

type PublicKey

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

func GetPublicKeyFromPrivate

func GetPublicKeyFromPrivate(privKey *PrivateKey) *PublicKey

Derives the public key from the private (either view or spend)

func GetTxPublicKeyFromExtra

func GetTxPublicKeyFromExtra(extra []byte) (*PublicKey, error)

Parses the extra field and returns a tx pub key

func NewPublicKey

func NewPublicKey(keyStr string) (*PublicKey, error)

Creates Public Key from a hex string representation

func ParseExtra

func ParseExtra(extra []byte) (txKey *PublicKey, payId []byte)

Parses the extra field and returns a tx pub key (or nil if error) and a payment id (or nil if error)

func (*PublicKey) Bytes

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

type Seed added in v0.2.0

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

func NewSeed added in v0.2.0

func NewSeed(lang MnemonicLanguage) (*Seed, error)

Generates a 25 words random mnemonic seed

func NewSeedMnemonic added in v0.2.0

func NewSeedMnemonic(m string, lang MnemonicLanguage) (*Seed, error)

Creates a Seed struct from a 25 words mnemonic seed

func (*Seed) FullKeyPair added in v0.2.0

func (s *Seed) FullKeyPair() *FullKeyPair

func (*Seed) Mnemonic added in v0.2.0

func (s *Seed) Mnemonic() []string

func (*Seed) MnemonicLanguage added in v0.2.0

func (s *Seed) MnemonicLanguage() MnemonicLanguage

type SubAddress

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

func GenerateSubaddress

func GenerateSubaddress(viewKey *PrivateKey, spendKey *PublicKey, major, minor uint32, nt NetworkType) (*SubAddress, error)

Generates a Monero subaddress base on the primary private view and public spend keys, NetworkType, major and minor indices

func (*SubAddress) Address

func (a *SubAddress) Address() string

Returns a string representation of the Monero integrated/sub-/primary address

func (*SubAddress) AddressType

func (a *SubAddress) AddressType() AddressType

Returns an AddressType from the Monero integrated/sub-/primary address

func (*SubAddress) NetworkType

func (a *SubAddress) NetworkType() NetworkType

Returns a NetworkType from the Monero integrated/sub-/primary address

func (*SubAddress) PublicSpendKey

func (a *SubAddress) PublicSpendKey() *PublicKey

Returns a Public Spend Key from the Monero integrated/sub-/primary address

func (*SubAddress) PublicViewKey

func (a *SubAddress) PublicViewKey() *PublicKey

Returns a Public View Key from the Monero integrated/sub-/primary address

type ViewOnlyKeyPair added in v0.2.0

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

func NewViewOnlyKeyPair added in v0.2.0

func NewViewOnlyKeyPair(view *PrivateKey, spend *PublicKey) *ViewOnlyKeyPair

func (*ViewOnlyKeyPair) SpendPublicKey added in v0.2.0

func (p *ViewOnlyKeyPair) SpendPublicKey() *PublicKey

func (*ViewOnlyKeyPair) ViewKeyPair added in v0.2.0

func (p *ViewOnlyKeyPair) ViewKeyPair() *KeyPair

Jump to

Keyboard shortcuts

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