Package monero.common

Class MoneroUtils

java.lang.Object
monero.common.MoneroUtils

public class MoneroUtils extends Object
Collection of Monero utilities.
  • Field Details

  • Constructor Details

    • MoneroUtils

      public MoneroUtils()
  • Method Details

    • getVersion

      public static String 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

      public static boolean walletExists(String path)
      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

      public static void validateMnemonic(String mnemonic)
      Validates the given mnemonic phrase.
      Parameters:
      mnemonic - is the mnemonic to validate
      Throws:
      MoneroError - if the given mnemonic is invalid
    • isValidPrivateViewKey

      public static boolean isValidPrivateViewKey(String privateViewKey)
      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

      public static boolean isValidPublicViewKey(String publicViewKey)
      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

      public static boolean isValidPrivateSpendKey(String privateSpendKey)
      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

      public static boolean isValidPublicSpendKey(String publicSpendKey)
      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

      public static void validatePrivateViewKey(String privateViewKey)
      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

      public static void validatePublicViewKey(String publicViewKey)
      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

      public static void validatePrivateSpendKey(String privateSpendKey)
      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

      public static void validatePublicSpendKey(String publicSpendKey)
      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 address
      standardAddress - is the address to derive the integrated address from
      paymentId - optionally specifies the integrated address's payment id (defaults to random payment id)
      Returns:
      the integrated address
    • decodeAddress

      public static MoneroDecodedAddress decodeAddress(String address)
      Decodes the given address.
      Parameters:
      address - is the address to decode
      Returns:
      the decoded address and network types
    • isValidAddress

      public static boolean isValidAddress(String address, MoneroNetworkType networkType)
      Determine if the given address is valid.
      Parameters:
      address - is the address to validate
      networkType - is the address's network type
      Returns:
      true if the address is valid, false otherwise
    • validateAddress

      public static void validateAddress(String address, MoneroNetworkType networkType)
      Validates the given address.
      Parameters:
      address - is the address to validate
      networkType - is the address's network type
    • validatePaymentId

      public static void validatePaymentId(String paymentId)
    • validateViewKey

      public static void validateViewKey(String viewKey)
      Validates the given view key.
      Parameters:
      viewKey - is the view key to validate
      Throws:
      MoneroError - if the given view key is invalid
    • parseUri

      public static URI parseUri(String uri)
      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

      public static void validateHex(String str)
    • validateBase58

      public static void validateBase58(String standardAddress)
    • paymentIdsEqual

      public static boolean paymentIdsEqual(String paymentId1, String paymentId2)
      Determines if two payment ids are functionally equal. For example, 03284e41c342f032 and 03284e41c342f032000000000000000000000000000000000000000000000000 are considered equal.
      Parameters:
      paymentId1 - is a payment id to compare
      paymentId2 - is a payment id to compare
      Returns:
      true if the payment ids are equal, false otherwise
    • mergeTx

      public static <T extends MoneroTx> void mergeTx(List<T> txs, T tx)
      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 into
      tx - is the transaction to merge into the list
    • mapToBinary

      public static byte[] mapToBinary(Map<String,Object> map)
    • binaryToMap

      public static Map<String,Object> binaryToMap(byte[] bin)
    • binaryBlocksToMap

      public static Map<String,Object> binaryBlocksToMap(byte[] binBlocks)
    • log

      public static void log(int level, String msg)
      Log a message.
      Parameters:
      level - log level of the message
      msg - 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

      public static void configureNativeLogging(String path, boolean console)
      Initialize JNI logging.
      Parameters:
      path - the path to write logs to
      console - specifies whether or not to write to the console
    • xmrToAtomicUnits

      public static BigInteger xmrToAtomicUnits(double amountXmr)
      Convert XMR to atomic units.
      Parameters:
      amountXmr - amount in XMR to convert to atomic units
      Returns:
      amount in atomic units
    • atomicUnitsToXmr

      public static double atomicUnitsToXmr(BigInteger amountAtomicUnits)
      Convert atomic units to XMR.
      Parameters:
      amountAtomicUnits - amount in atomic units to convert to XMR
      Returns:
      amount in XMR
    • getPaymentUri

      public static String getPaymentUri(MoneroTxConfig config)
      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