Package monero.common
Class MoneroUtils
java.lang.Object
monero.common.MoneroUtils
Collection of Monero utilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleatomicUnitsToXmr(BigInteger amountAtomicUnits) Convert atomic units to XMR.binaryBlocksToMap(byte[] binBlocks) binaryToMap(byte[] bin) static voidconfigureNativeLogging(String path, boolean console) Initialize JNI logging.static MoneroDecodedAddressdecodeAddress(String address) Decodes the given address.static doubledivide(BigInteger auDividend, BigInteger auDivisor) Divide atomic units by another atomic units.static MoneroIntegratedAddressgetIntegratedAddress(MoneroNetworkType networkType, String standardAddress, String paymentId) Get an integrated address.static intGet the library's log level.static StringgetPaymentUri(MoneroTxConfig config) Creates a payment URI from a tx configuration.static StringGet the version of the monero-java library.static booleanIndicates if the native JNI library is loaded.static booleanisValidAddress(String address, MoneroNetworkType networkType) Determine if the given address is valid.static booleanisValidPrivateSpendKey(String privateSpendKey) Indicates if a private spend key is valid.static booleanisValidPrivateViewKey(String privateViewKey) Indicates if a private view key is valid.static booleanisValidPublicSpendKey(String publicSpendKey) Indicates if a public spend key is valid.static booleanisValidPublicViewKey(String publicViewKey) Indicates if a public view key is valid.static voidstatic voidLog a message.static byte[]mapToBinary(Map<String, Object> map) static <T extends MoneroTx>
voidMerges a transaction into a list of existing transactions.static BigIntegermultiply(BigInteger amount1, double amount2) Multiply atomic units amount by a double.static URIConverts the string to a URI.static booleanpaymentIdsEqual(String paymentId1, String paymentId2) Determines if two payment ids are functionally equal.static voidsetLogLevel(int level) Set the library's log level with 0 being least verbose.static voidTry to load the native library if not already loaded.static voidvalidateAddress(String address, MoneroNetworkType networkType) Validates the given address.static voidvalidateBase58(String standardAddress) static voidvalidateHex(String str) static voidvalidateMnemonic(String mnemonic) Validates the given mnemonic phrase.static voidvalidatePaymentId(String paymentId) static voidvalidatePrivateSpendKey(String privateSpendKey) Validate a private spend key.static voidvalidatePrivateViewKey(String privateViewKey) Validate a private view key.static voidvalidatePublicSpendKey(String publicSpendKey) Validate a public spend key.static voidvalidatePublicViewKey(String publicViewKey) Validate a public view key.static voidvalidateViewKey(String viewKey) Validates the given view key.static booleanwalletExists(String path) Indicates if a wallet keys file exists at the given path.static BigIntegerxmrToAtomicUnits(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
-
divide
Divide atomic units by another atomic units.- Parameters:
auDividend- atomic units to divideauDivisor- atomic units to divide by- Returns:
- the result in atomic units
-
multiply
Multiply atomic units amount by a double.- Parameters:
amount1- atomic units to multiplyamount2- double to multiply by- Returns:
- the result in atomic units
-
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
-