Skip to content

Commit

Permalink
Update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Sep 28, 2023
1 parent 77094c4 commit 4885d58
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ private static KeyPair deriveKeyPair(final UnsignedByteArray seedBytes, final in
final BigInteger privateKeyInt = derivePrivateKey(seedBytes, accountNumber);
final UnsignedByteArray publicKeyInt = derivePublicKey(privateKeyInt);

// Both ed25519 and secp256k1 _private_ keys are always 32 bytes long. However, in this library, both types of
// private key are prefixed with one byte (0xED for ed25519 and 0x00 for secp256k1) because this is what other
// libraries do, and also so that any particular set of 32 private key bytes can be properly disambiguated.
// All natural secp256k1 private keys always have only 32-bytes. However, when computing `publicKeyInt`,
// the `BigInteger.toByteArray()` will return the byte array in two's-complement form and occasionally prepend
// a zero byte to ensure the number is not negative. When this doesn't happen, we want to normalize the
// private key bytes to always have this one-byte prefix because this library prefixes all private keys with a
// prefix to identify the key type (`0xED` for ed25519 and `0x00` for secp256k1).
// See https://github.com/XRPLF/xrpl4j/issues/486 for more details.
final UnsignedByteArray prefixedPrivateKey;
if (privateKeyInt.toByteArray().length == 32) {
Expand Down

0 comments on commit 4885d58

Please sign in to comment.