diff --git a/src/main/java/org/p2p/solanaj/core/PublicKey.java b/src/main/java/org/p2p/solanaj/core/PublicKey.java index eec1c1b2..2f21e46b 100644 --- a/src/main/java/org/p2p/solanaj/core/PublicKey.java +++ b/src/main/java/org/p2p/solanaj/core/PublicKey.java @@ -91,6 +91,23 @@ public static PublicKey createProgramAddress(List seeds, PublicKey progr } } + public static PublicKey createWithSeed(PublicKey fromPublicKey, String seed, PublicKey programId) { + try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { + if (seed.length() > 32) { + throw new IllegalArgumentException("Max seed length exceeded: " + seed.length()); + } + + buffer.write(fromPublicKey.toByteArray()); + buffer.write(seed.getBytes()); + buffer.write(programId.toByteArray()); + + byte[] hash = Sha256Hash.hash(buffer.toByteArray()); + return new PublicKey(hash); + } catch (IOException e) { + throw new RuntimeException("Error creating program address", e); + } + } + public static class ProgramDerivedAddress { private PublicKey address; private int nonce; @@ -124,6 +141,8 @@ public static ProgramDerivedAddress findProgramAddress(List seeds, Publi throw new IllegalStateException("Unable to find a viable program address nonce"); } + + public static PublicKey valueOf(String publicKey) { return new PublicKey(publicKey); }