Package zephyr.common
Class ZephyrUtils
java.lang.Object
zephyr.common.ZephyrUtils
Collection of Zephyr utilities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe ring size the Zephyr network enforces: 16 (Monero's is 12). -
Constructor Summary
ConstructorsConstructorDescriptionThe implicit public constructor, made explicit to document it: every member is static. -
Method Summary
Modifier and TypeMethodDescriptionbinaryBlocksToMap(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.binaryToMap(byte[] bin) Converts the daemon's binary (portable storage) format to a map, using the native library.static voidconfigureNativeLogging(String path, boolean console) Initialize JNI logging.static ZephyrDecodedAddressdecodeAddress(String address) Decodes the given address.static doublefromAtomicUnits(BigInteger amountAtomicUnits) Convert atomic units to coins.static ZephyrIntegratedAddressgetIntegratedAddress(ZephyrNetworkType networkType, String standardAddress, String paymentId) Get an integrated address.static intGet the library's log level.static StringGet the version of the zephyr-java library.static booleanIndicates if the native JNI library is loaded.static booleanisValidAddress(String address, ZephyrNetworkType 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 voidLoad 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.static voidLog a message.static byte[]mapToBinary(Map<String, Object> map) Converts a map to the daemon's binary (portable storage) format, using the native library.static <T extends ZephyrTx>
voidMerges a transaction into a list of existing transactions.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 BigIntegertoAtomicUnits(double amount) Convert coins to atomic units.static voidTry to load the native library if not already loaded.static voidvalidateAddress(String address, ZephyrNetworkType networkType) Validates the given address.static voidvalidateBase58(String standardAddress) Validates that a string uses only the characters of the base58 alphabet.static voidvalidateHex(String str) Validates that a string is hex with an even number of characters.static voidvalidateMnemonic(String mnemonic) Validates the given mnemonic phrase.static voidvalidatePaymentId(String paymentId) Validates the length of a payment ID: 16 hex characters (short, integrated addresses) or 64.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.
-
Field Details
-
RING_SIZE
public static final int RING_SIZEThe 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
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
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:
ZephyrError- 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:
ZephyrError- if the given private view key is invalid
-
validatePublicViewKey
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
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
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 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
Validates the length of a payment ID: 16 hex characters (short, integrated addresses) or 64.- Parameters:
paymentId- is the payment ID to validate
-
validateViewKey
Validates the given view key.- Parameters:
viewKey- is the view key to validate- Throws:
ZephyrError- if the given view key is invalid
-
parseUri
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
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
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
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 ZephyrTx or subclasses like ZephyrTxWallet- Parameters:
txs- are existing transactions to merge intotx- is the transaction to merge into the list
-
mapToBinary
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
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
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
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
-
toAtomicUnits
Convert coins to atomic units.- Parameters:
amount- amount in coins to convert to atomic units- Returns:
- amount in atomic units
-
fromAtomicUnits
Convert atomic units to coins.- Parameters:
amountAtomicUnits- amount in atomic units to convert to coins- Returns:
- amount in coins
-