Package zephyr.common

Class ZephyrUtils

java.lang.Object
zephyr.common.ZephyrUtils

public class ZephyrUtils extends Object
Collection of Zephyr utilities.
  • Field Details

    • RING_SIZE

      public static final int RING_SIZE
      The ring size the Zephyr network enforces: 16 (Monero's is 12).
      See Also:
  • Constructor Details

    • ZephyrUtils

      public ZephyrUtils()
      The implicit public constructor, made explicit to document it: every member is static.
  • Method Details

    • getVersion

      public static String getVersion()
      Get the version of the zephyr-java library.
      Returns:
      the version of this zephyr-java library
    • tryLoadNativeLibrary

      public static void tryLoadNativeLibrary()
      Try to load the native library if not already loaded.
    • loadNativeLibrary

      public static void loadNativeLibrary()
      Load the native library: from the Java library path first (Android loads it from the APK's native libraries this way), else from the resources of the JAR, which carry one library per operating system and architecture.
    • 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:
      ZephyrError - 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:
      ZephyrError - 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:
      ZephyrError - 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:
      ZephyrError - 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:
      ZephyrError - if the given public spend key is invalid
    • getIntegratedAddress

      public static ZephyrIntegratedAddress getIntegratedAddress(ZephyrNetworkType 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 ZephyrDecodedAddress 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, ZephyrNetworkType 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, ZephyrNetworkType 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)
      Validates the length of a payment ID: 16 hex characters (short, integrated addresses) or 64.
      Parameters:
      paymentId - is the payment ID to validate
    • validateViewKey

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

      public static URI parseUri(String uri)
      Converts the string to a URI. Throws ZephyrException 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)
      Validates that a string is hex with an even number of characters.
      Parameters:
      str - is the string to validate
      Throws:
      ZephyrError - if the string is not hex
    • validateBase58

      public static void validateBase58(String standardAddress)
      Validates that a string uses only the characters of the base58 alphabet.
      Parameters:
      standardAddress - is the string to validate
      Throws:
      ZephyrError - if a character is not in the base58 alphabet
    • 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 ZephyrTx> void mergeTx(List<T> txs, T tx)
      Merges a transaction into a list of existing transactions.
      Type Parameters:
      T - is a ZephyrTx or subclasses like ZephyrTxWallet
      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)
      Converts a map to the daemon's binary (portable storage) format, using the native library.
      Parameters:
      map - is the map to convert
      Returns:
      the binary form
    • binaryToMap

      public static Map<String,Object> binaryToMap(byte[] bin)
      Converts the daemon's binary (portable storage) format to a map, using the native library.
      Parameters:
      bin - is the binary form
      Returns:
      the map
    • binaryBlocksToMap

      public static Map<String,Object> binaryBlocksToMap(byte[] binBlocks)
      Converts the daemon's binary blocks response to a map whose "blocks" entry is a list of block maps, using the native library.
      Parameters:
      binBlocks - is the binary blocks response
      Returns:
      the map
    • 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
    • toAtomicUnits

      public static BigInteger toAtomicUnits(double amount)
      Convert coins to atomic units.
      Parameters:
      amount - amount in coins to convert to atomic units
      Returns:
      amount in atomic units
    • fromAtomicUnits

      public static double fromAtomicUnits(BigInteger amountAtomicUnits)
      Convert atomic units to coins.
      Parameters:
      amountAtomicUnits - amount in atomic units to convert to coins
      Returns:
      amount in coins