Interface Secp256k1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bouncycastle.crypto.params.ECDomainParametersDeprecated.static final org.bouncycastle.asn1.x9.X9ECParametersDeprecated.This interface is deprecated in-favor ofBcKeyUtils.PARAMS.static final UnsignedBytePrivate keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic UnsignedByteArraytoUnsignedByteArray(BigInteger amount, int minFinalByteLength) Creates anUnsignedByteArrayfrom the bytes of a suppliedBigInteger.static UnsignedByteArraywithZeroPrefixPadding(byte[] bytes, int minFinalByteLength) Construct a newUnsignedByteArraythat contains the bytes frombytes, but with enough `0x00` prefix padding bytes such that the final length of the returned value isminFinalByteLength.static UnsignedByteArraywithZeroPrefixPadding(UnsignedByteArray bytes, int minFinalByteLength) Construct a newUnsignedByteArraythat contains the bytes frombytes, but with enough `0x00` prefix padding bytes such that the final length of the returned value isminFinalByteLength.
-
Field Details
-
EC_PARAMETERS
Deprecated.This interface is deprecated in-favor ofBcKeyUtils.PARAMS.Elliptic Curve parameters for the curve named `secp256k1`. -
EC_DOMAIN_PARAMETERS
Deprecated.This interface is deprecated in-favor ofBcKeyUtils.PARAMS.Elliptic Curve domain parameters for the curve named `secp256k1`. -
SECP256K1_PREFIX
Private keys (whether from the ed25519 or secp256k1 curves) have 32 bytes naturally. At the same time, secp256k1 public keys have 33 bytes naturally, whereas ed25519 public keys have 32 bytes naturally. Because of this, in XRPL, ed25519 public keys are prefixed with a one-byte prefix (i.e., 0xED). For consistency, this library (and other XRPL tooling) also prepends all private keys with artificial prefixes (0xED for ed25519 or 0x00 for secp256k1). This value is the one-byte prefix for secp256k1 keys.
-
-
Method Details
-
toUnsignedByteArray
Creates anUnsignedByteArrayfrom the bytes of a suppliedBigInteger. If the length of the resulting array is not at leastminFinalByteLength, then the result is prefix padded with `0x00` bytes until the final array length isminFinalByteLength.This function exists to ensure that transformation of secp256k1 private keys from a
BigIntegerto 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 viaBigInteger.toByteArray(), the result will not always have the same number of leading zero bytes that one might expect. 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.Note that this function assumes the supplied
amountis always positive, which roughly correlates with the secp256k1 requirement that private key scalar `D` values be in the range [1, N-1].Thus, this function can be used to normalize a byte array containing a secp256k1 private key with a desired number of 0-byte padding to ensure that it is always the desired
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).- Parameters:
amount- ABigIntegerto convert into anUnsignedByteArray.minFinalByteLength- The minimum length, in bytes, that the final result must be. If the final byte length is less than this number, the resulting array will be prefix padded to increase its length to this number.- Returns:
- An
UnsignedByteArraywith a length of at leastminFinalByteLength. - See Also:
-
withZeroPrefixPadding
Construct a newUnsignedByteArraythat contains the bytes frombytes, but with enough `0x00` prefix padding bytes such that the final length of the returned value isminFinalByteLength.- Parameters:
bytes- AnUnsignedByteArrayto zero-pad.minFinalByteLength- The minimum length, in bytes, that the final result must be zero-byte prefix-padded to. If this number is greater-than#length, then this value will be reduced to#length.- Returns:
- A copy of this
UnsignedByteArraythat has been zero-byte prefix-padded such that its final length is at leastminFinalByteLength.
-
withZeroPrefixPadding
Construct a newUnsignedByteArraythat contains the bytes frombytes, but with enough `0x00` prefix padding bytes such that the final length of the returned value isminFinalByteLength.- Parameters:
bytes- A byte array to zero-pad.minFinalByteLength- The minimum length, in bytes, that the final result must be zero-byte prefix-padded to. If this number is greater-than#length, then this value will be reduced to#length.- Returns:
- A copy of this
UnsignedByteArraythat has been zero-byte prefix-padded such that its final length is at leastminFinalByteLength.
-
BcKeyUtils.PARAMS.