Skip to content

Commit

Permalink
Fix KeyPair.fromSecretSeet on char array (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms authored Jul 25, 2022
1 parent 423f55e commit 9c778c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit 9c778c8

Please sign in to comment.