From d7007859656cf283f5bac8855ab74d9d9507989c Mon Sep 17 00:00:00 2001 From: David Fuelling Date: Tue, 3 Oct 2023 16:32:29 -0600 Subject: [PATCH] Update Javadoc --- .../codec/addresses/UnsignedByteArray.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/UnsignedByteArray.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/UnsignedByteArray.java index 78e19a748..b8cb873c3 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/UnsignedByteArray.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/UnsignedByteArray.java @@ -80,20 +80,21 @@ public static UnsignedByteArray of(UnsignedByte first, UnsignedByte... rest) { } /** - * Creates an {@link UnsignedByteArray} from a {@link BigInteger} with a minimum number of prefix padding bytes. + * Creates an {@link UnsignedByteArray} from the bytes of a supplied {@link BigInteger}. If the length of the + * resulting array is not at least {@code minFinalByteLength}, then the result prefix padded with `0x00` bytes until + * the final array length is {@code minFinalByteLength}. *

- * This function primarily exists to ensure that transforming a secp256k1 private key (as a {@link BigInteger}) to an - * instance of {@link UnsignedByteArray} is always done in a consistent fashion yielding the desired number of bytes. - * For example, secp256k1 private keys are 32-bytes long naturally. However, when transformed to a byte array via - * `BigInteger.toByteArray()`, the result will occasionally be unexpectedly (though correctly) truncated. For example, - * sometimes the returned array will have 33 bytes, one of which is a zero-byte prefix pad that is meant to ensure the - * underlying number is not represented as a negative number. Other times, the array will have fewer than 32 bytes, - * for example 31 or even 30, if the byte array has redundant leading zero bytes. Thus, this function can be used to - * normalize the bytes array with a desired number of 0-byte padding to ensure that the resulting byte array is always - * the desired {@code minFinalByteLength} (e.g., in this library, secp256k1 private keys should always be comprised of - * a 32-byte natural private key with a one-byte `0x00` prefix pad). For more details, see - * Github issue #486. - *

+ * This function primarily exists to ensure that transformation of secp256k1 private keys from one form to another + * (e.g., from {@link BigInteger} to a byte array) are done in a consistent manner, always yielding the desired number + * of bytes. For example, secp256k1 private keys are 32-bytes long naturally. However, when transformed to a byte + * array via `BigInteger.toByteArray()`, the result will not always have the same number of leading zero bytes that + * one might expect. For example, sometimes the returned array will have 33 bytes, one of which is a zero-byte prefix + * pad that is meant to ensure the underlying number is not represented as a negative number. Other times, the array + * will have fewer than 32 bytes, for example 31 or even 30, if the byte array has redundant leading zero bytes. + *

+ * Thus, this function can be used to normalize a byte array with a desired number of 0-byte padding to ensure that + * the resulting byte array is always the desired {@code minFinalByteLength} (e.g., in this library, secp256k1 private + * keys should always be comprised of a 32-byte natural private key with a one-byte `0x00` prefix pad). * * @param amount A {@link BigInteger} to convert into an {@link UnsignedByteArray}. * @param minFinalByteLength The minimum length, in bytes, that the final result must be. If the final byte length is @@ -102,6 +103,8 @@ public static UnsignedByteArray of(UnsignedByte first, UnsignedByte... rest) { * * @return An {@link UnsignedByteArray}with a length of at least {@code minFinalByteLength} (possibly via zero-byte * prefix padding). + * + * @see "https://github.com/XRPLF/xrpl4j/issues/486" */ public static UnsignedByteArray from(final BigInteger amount, int minFinalByteLength) { Objects.requireNonNull(amount);