Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyPair.fromSecretSeet on char array #447

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/org/stellar/sdk/KeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public boolean canSign() {
public static KeyPair fromSecretSeed(char[] seed) {
byte[] decoded = StrKey.decodeStellarSecretSeed(seed);
KeyPair keypair = fromSecretSeed(decoded);
Arrays.fill(decoded, (byte) 0);
return keypair;
}

Expand Down
16 changes: 12 additions & 4 deletions src/test/java/org/stellar/sdk/KeyPairTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

public class KeyPairTest {

private static final String SEED = "1123740522f11bfef6b3671f51e159ccf589ccf8965262dd5f97d1721d383dd4";

@Test
public void testFromSecretSeedCharArray() {
KeyPair original = KeyPair.fromSecretSeed("SDMMJC2BSGESMFQ53MF3WECMCQGJVRY3TJ45J7PYZ53GZZ36NDDDWEDM");

char[] seed = original.getSecretSeed();
KeyPair newPair = KeyPair.fromSecretSeed(seed);

assertArrayEquals(original.getSecretSeed(), newPair.getSecretSeed());
assertEquals(original.getAccountId(), newPair.getAccountId());
}

@Test
public void testInvalidPublicKey() {
try {
Expand Down