Skip to content

Commit

Permalink
Use Java MessageDigest for Sha256 hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-james committed Oct 4, 2024
1 parent 3c47b7e commit a6513dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.lmax.solana4j.api.ProgramDerivedAddress;
import com.lmax.solana4j.api.PublicKey;
import com.lmax.solana4j.util.Ed25519;
import org.bitcoinj.core.Sha256Hash;
import com.lmax.solana4j.util.Sha256;

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

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

if (isOffCurve(programAddress))
{
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/lmax/solana4j/util/Sha256.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.lmax.solana4j.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Sha256
{
public 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);
}
}

0 comments on commit a6513dd

Please sign in to comment.