Package monero.common
Class MoneroUtils
java.lang.Object
monero.common.MoneroUtils
Collection of Monero utilities.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
atomicUnitsToXmr
(BigInteger amountAtomicUnits) Convert atomic units to XMR.binaryBlocksToMap
(byte[] binBlocks) binaryToMap
(byte[] bin) static void
configureNativeLogging
(String path, boolean console) Initialize JNI logging.static MoneroDecodedAddress
decodeAddress
(String address) Decodes the given address.static MoneroIntegratedAddress
getIntegratedAddress
(MoneroNetworkType networkType, String standardAddress, String paymentId) Get an integrated address.static int
Get the library's log level.static String
getPaymentUri
(MoneroTxConfig config) Creates a payment URI from a tx configuration.static String
Get the version of the monero-java library.static boolean
Indicates if the native JNI library is loaded.static boolean
isValidAddress
(String address, MoneroNetworkType networkType) Determine if the given address is valid.static boolean
isValidPrivateSpendKey
(String privateSpendKey) Indicates if a private spend key is valid.static boolean
isValidPrivateViewKey
(String privateViewKey) Indicates if a private view key is valid.static boolean
isValidPublicSpendKey
(String publicSpendKey) Indicates if a public spend key is valid.static boolean
isValidPublicViewKey
(String publicViewKey) Indicates if a public view key is valid.static void
static void
Log a message.static byte[]
mapToBinary
(Map<String, Object> map) static <T extends MoneroTx>
voidMerges a transaction into a list of existing transactions.static URI
Converts the string to a URI.static boolean
paymentIdsEqual
(String paymentId1, String paymentId2) Determines if two payment ids are functionally equal.static void
setLogLevel
(int level) Set the library's log level with 0 being least verbose.static void
Try to load the native library if not already loaded.static void
validateAddress
(String address, MoneroNetworkType networkType) Validates the given address.static void
validateBase58
(String standardAddress) static void
validateHex
(String str) static void
validateMnemonic
(String mnemonic) Validates the given mnemonic phrase.static void
validatePaymentId
(String paymentId) static void
validatePrivateSpendKey
(String privateSpendKey) Validate a private spend key.static void
validatePrivateViewKey
(String privateViewKey) Validate a private view key.static void
validatePublicSpendKey
(String publicSpendKey) Validate a public spend key.static void
validatePublicViewKey
(String publicViewKey) Validate a public view key.static void
validateViewKey
(String viewKey) Validates the given view key.static boolean
walletExists
(String path) Indicates if a wallet keys file exists at the given path.static BigInteger
xmrToAtomicUnits
(double amountXmr) Convert XMR to atomic units.
-
Field Details
-
RING_SIZE
public static final int RING_SIZE- See Also:
-
-
Constructor Details
-
MoneroUtils
public MoneroUtils()
-
-
Method Details
-
getVersion
Get the version of the monero-java library.- Returns:
- the version of this monero-java library
-
tryLoadNativeLibrary
public static void tryLoadNativeLibrary()Try to load the native library if not already loaded. -
loadNativeLibrary
public static void loadNativeLibrary() -
isNativeLibraryLoaded
public static boolean isNativeLibraryLoaded()Indicates if the native JNI library is loaded.- Returns:
- true if the native library is loaded, false otherwise
-
walletExists
Indicates if a wallet keys file exists at the given path.- Parameters:
path
- is the path with wallet name to check for existence- Returns:
- true if a wallet keys file exists at the given path, false otherwise
-
validateMnemonic
Validates the given mnemonic phrase.- Parameters:
mnemonic
- is the mnemonic to validate- Throws:
MoneroError
- if the given mnemonic is invalid
-
isValidPrivateViewKey
Indicates if a private view key is valid.- Parameters:
privateViewKey
- is the private view key to validate- Returns:
- true if the private view key is valid, false otherwise
-
isValidPublicViewKey
Indicates if a public view key is valid.- Parameters:
publicViewKey
- is the public view key to validate- Returns:
- true if the public view key is valid, false otherwise
-
isValidPrivateSpendKey
Indicates if a private spend key is valid.- Parameters:
privateSpendKey
- is the private spend key to validate- Returns:
- true if the private spend key is valid, false otherwise
-
isValidPublicSpendKey
Indicates if a public spend key is valid.- Parameters:
publicSpendKey
- is the public spend key to validate- Returns:
- true if the public spend key is valid, false otherwise
-
validatePrivateViewKey
Validate a private view key.- Parameters:
privateViewKey
- is the private view key to validate- Throws:
MoneroError
- if the given private view key is invalid
-
validatePublicViewKey
Validate a public view key.- Parameters:
publicViewKey
- is the public view key to validate- Throws:
MoneroError
- if the given public view key is invalid
-
validatePrivateSpendKey
Validate a private spend key.- Parameters:
privateSpendKey
- is the private spend key to validate- Throws:
MoneroError
- if the given private spend key is invalid
-
validatePublicSpendKey
Validate a public spend key.- Parameters:
publicSpendKey
- is the public spend key to validate- Throws:
MoneroError
- if the given public spend key is invalid
-
getIntegratedAddress
public static MoneroIntegratedAddress getIntegratedAddress(MoneroNetworkType networkType, String standardAddress, String paymentId) Get an integrated address.- Parameters:
networkType
- is the network type of the integrated addressstandardAddress
- is the address to derive the integrated address frompaymentId
- optionally specifies the integrated address's payment id (defaults to random payment id)- Returns:
- the integrated address
-
decodeAddress
Decodes the given address.- Parameters:
address
- is the address to decode- Returns:
- the decoded address and network types
-
isValidAddress
Determine if the given address is valid.- Parameters:
address
- is the address to validatenetworkType
- is the address's network type- Returns:
- true if the address is valid, false otherwise
-
validateAddress
Validates the given address.- Parameters:
address
- is the address to validatenetworkType
- is the address's network type
-
validatePaymentId
-
validateViewKey
Validates the given view key.- Parameters:
viewKey
- is the view key to validate- Throws:
MoneroError
- if the given view key is invalid
-
parseUri
Converts the string to a URI. Throws MoneroException if exception.- Parameters:
uri
- is the string to convert to a URI- Returns:
- URI is the initialized object from the string endpoint
-
validateHex
-
validateBase58
-
paymentIdsEqual
Determines if two payment ids are functionally equal. For example, 03284e41c342f032 and 03284e41c342f032000000000000000000000000000000000000000000000000 are considered equal.- Parameters:
paymentId1
- is a payment id to comparepaymentId2
- is a payment id to compare- Returns:
- true if the payment ids are equal, false otherwise
-
mergeTx
Merges a transaction into a list of existing transactions.- Type Parameters:
T
- is a MoneroTx or subclasses like MoneroTxWallet- Parameters:
txs
- are existing transactions to merge intotx
- is the transaction to merge into the list
-
mapToBinary
-
binaryToMap
-
binaryBlocksToMap
-
log
Log a message.- Parameters:
level
- log level of the messagemsg
- message to log
-
setLogLevel
public static void setLogLevel(int level) Set the library's log level with 0 being least verbose.- Parameters:
level
- - the library's log level
-
getLogLevel
public static int getLogLevel()Get the library's log level.- Returns:
- the library's log level
-
configureNativeLogging
Initialize JNI logging.- Parameters:
path
- the path to write logs toconsole
- specifies whether or not to write to the console
-
xmrToAtomicUnits
Convert XMR to atomic units.- Parameters:
amountXmr
- amount in XMR to convert to atomic units- Returns:
- amount in atomic units
-
atomicUnitsToXmr
Convert atomic units to XMR.- Parameters:
amountAtomicUnits
- amount in atomic units to convert to XMR- Returns:
- amount in XMR
-
getPaymentUri
Creates a payment URI from a tx configuration. TODO: use native bindings to monero-project- Parameters:
config
- specifies configuration for a payment URI- Returns:
- the payment URI
-