Skip to content

Commit

Permalink
Revise the getNextSeed for supporting the signature scheme swap fork
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Apr 29, 2020
1 parent 44cbcc9 commit 5064a8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/org/aion/staker/BlockSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.aion.staker.chain.Transaction;
import org.aion.staker.utils.Logger;
import org.aion.staker.utils.PrivateKey;
import org.aion.staker.vrf.VRF_Ed25519;
import org.aion.util.bytes.ByteUtil;
import org.aion.util.conversions.Hex;

Expand Down Expand Up @@ -120,8 +121,21 @@ public static void main(String[] args) throws InvalidKeySpecException, Interrupt

private static byte[] getNextSeed(byte[] oldSeed) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException {
byte[] seed;
int seedLength = 64;
int proofLength = 80;
if (oldSeed != null) {
seed = MessageSigner.signMessageFromKeyBytes(stakerPrivateKey.getPrivateKeyBytes(), oldSeed);
if (oldSeed.length == seedLength) {
seed = MessageSigner.signMessageFromKeyBytes(stakerPrivateKey.getPrivateKeyBytes(), oldSeed);
} else if (oldSeed.length == (seedLength + 1) && oldSeed[seedLength] == 0) {
byte[] oldSeedHash = new byte[seedLength];
System.arraycopy(oldSeed, 0, oldSeedHash, 0, seedLength);
seed = VRF_Ed25519.generateProof(oldSeedHash, stakerPrivateKey.getKeyPairBytes());
} else if (oldSeed.length == proofLength) {
byte[] oldSeedHash = VRF_Ed25519.generateProofHash(oldSeed);
seed = VRF_Ed25519.generateProof(oldSeedHash, stakerPrivateKey.getKeyPairBytes());
} else {
return null;
}
} else {
seed = null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/org/aion/staker/utils/PrivateKey.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.aion.staker.utils;

import org.aion.util.bytes.ByteUtil;
import org.apache.commons.codec.binary.Hex;

import java.security.spec.InvalidKeySpecException;
Expand Down Expand Up @@ -57,6 +58,10 @@ public byte[] getPublicKeyBytes() {
return copyByteArray(this.publicKeyBytes);
}

public byte[] getKeyPairBytes() {
return ByteUtil.merge(privateKeyBytes, publicKeyBytes);
}

private static byte[] copyByteArray(byte[] byteArray) {
return Arrays.copyOf(byteArray, byteArray.length);
}
Expand Down

0 comments on commit 5064a8c

Please sign in to comment.