Skip to content

Commit

Permalink
Sha256 can just be a helper method on SolanaProgramDerivedAddress - i…
Browse files Browse the repository at this point in the history
…t doesn't need to be it's own class
  • Loading branch information
ml-james committed Oct 29, 2024
1 parent a4ae191 commit a60fe48
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.lmax.solana4j.api.ProgramDerivedAddress;
import com.lmax.solana4j.api.PublicKey;
import com.lmax.solana4j.util.Ed25519;
import com.lmax.solana4j.util.Sha256;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -37,7 +38,7 @@ static ProgramDerivedAddress deriveProgramAddress(final List<byte[]> seeds, fina
programId.write(seedsBuffer);
seedsBuffer.put(PROGRAM_DERIVED_ADDRESS_BYTES);

final byte[] programAddress = Sha256.hash(seedsBuffer.array());
final byte[] programAddress = hash(seedsBuffer.array());

if (isOffCurve(programAddress))
{
Expand All @@ -48,6 +49,20 @@ static ProgramDerivedAddress deriveProgramAddress(final List<byte[]> seeds, fina
throw new RuntimeException("Could not find a program address off the curve.");
}

private static byte[] hash(final byte[] input)
{
final MessageDigest digest;
try
{
digest = MessageDigest.getInstance("SHA-256");
}
catch (final NoSuchAlgorithmException e)
{
throw new RuntimeException(e);
}
return digest.digest(input);
}

private static boolean isOffCurve(final byte[] programAddress)
{
try
Expand Down
40 changes: 0 additions & 40 deletions message-encoding/src/main/java/com/lmax/solana4j/util/Sha256.java

This file was deleted.

This file was deleted.

0 comments on commit a60fe48

Please sign in to comment.