From 5064a8ca31af86df409afca76e9d446466b0e346 Mon Sep 17 00:00:00 2001 From: AionJayT Date: Wed, 29 Apr 2020 16:45:10 -0400 Subject: [PATCH] Revise the getNextSeed for supporting the signature scheme swap fork --- src/org/aion/staker/BlockSigner.java | 16 +++++++++++++++- src/org/aion/staker/utils/PrivateKey.java | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/org/aion/staker/BlockSigner.java b/src/org/aion/staker/BlockSigner.java index 8842d0b..934e107 100644 --- a/src/org/aion/staker/BlockSigner.java +++ b/src/org/aion/staker/BlockSigner.java @@ -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; @@ -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; } diff --git a/src/org/aion/staker/utils/PrivateKey.java b/src/org/aion/staker/utils/PrivateKey.java index 8d5fcba..ba9e4b2 100644 --- a/src/org/aion/staker/utils/PrivateKey.java +++ b/src/org/aion/staker/utils/PrivateKey.java @@ -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; @@ -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); }