use of co.rsk.db.importer.provider.index.data.BootstrapDataSignature in project rskj by rsksmart.
the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataOneEntry.
@Test(expected = BootstrapImportException.class)
public void getMaximumCommonHeightDataOneEntry() {
List<String> keys = Arrays.asList("key1", "key2");
BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
List<BootstrapDataIndex> indexes = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
indexes.add(new BootstrapDataIndex(entries));
indexMCH.getHeightData(indexes);
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataSignature in project rskj by rsksmart.
the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataTwoEntries.
@Test
public void getMaximumCommonHeightDataTwoEntries() {
List<String> keys = Arrays.asList("key1", "key2");
BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
List<BootstrapDataIndex> indexes = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries2 = new ArrayList<>();
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries2.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
indexes.add(new BootstrapDataIndex(entries));
indexes.add(new BootstrapDataIndex(entries2));
BootstrapIndexCandidateSelector.HeightCandidate heightCandidate = indexMCH.getHeightData(indexes);
assertEquals(1, heightCandidate.getHeight());
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataSignature in project rskj by rsksmart.
the class BootstrapIndexCandidateSelectorTest method getMaximumCommonHeightDataManyEntries.
@Test
public void getMaximumCommonHeightDataManyEntries() {
List<String> keys = Arrays.asList("key1", "key2", "keys3");
BootstrapIndexCandidateSelector indexMCH = new BootstrapIndexCandidateSelector(keys, 2);
List<BootstrapDataIndex> indexes = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries2 = new ArrayList<>();
ArrayList<BootstrapDataEntry> entries3 = new ArrayList<>();
entries.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries2.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries3.add(new BootstrapDataEntry(1, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries.add(new BootstrapDataEntry(2, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries2.add(new BootstrapDataEntry(2, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
entries3.add(new BootstrapDataEntry(2, "", "dbPath", "hash", new BootstrapDataSignature("r", "s")));
indexes.add(new BootstrapDataIndex(entries));
indexes.add(new BootstrapDataIndex(entries2));
indexes.add(new BootstrapDataIndex(entries3));
BootstrapIndexCandidateSelector.HeightCandidate heightCandidate = indexMCH.getHeightData(indexes);
assertEquals(heightCandidate.getHeight(), 2L);
}
use of co.rsk.db.importer.provider.index.data.BootstrapDataSignature in project rskj by rsksmart.
the class BootstrapDataVerifier method verifyEntries.
public int verifyEntries(Map<String, BootstrapDataEntry> selectedEntries) {
int verifications = 0;
if (selectedEntries.isEmpty()) {
return 0;
}
String hashToVerify = selectedEntries.values().iterator().next().getHash();
byte[] dbHash = Hex.decode(hashToVerify);
for (Map.Entry<String, BootstrapDataEntry> entry : selectedEntries.entrySet()) {
BootstrapDataEntry bde = entry.getValue();
String currentHash = bde.getHash();
if (!hashToVerify.equals(currentHash)) {
throw new BootstrapImportException(String.format("Error trying to verify different hashes: %s vs %s", hashToVerify, currentHash));
}
BootstrapDataSignature bds = bde.getSig();
// to use the public key we need to have an extra byte according to x9.62 declaring
// which format is using. The current format from signer is uncompressed
byte[] publicKey = Hex.decode(entry.getKey());
// 1 is for forcing to interpret the values as unsigned integers
BigInteger r = new BigInteger(1, Hex.decode(bds.getR()));
BigInteger s = new BigInteger(1, Hex.decode(bds.getS()));
ECDSASignature signature = new ECDSASignature(r, s);
if (Secp256k1.getInstance().verify(dbHash, signature, publicKey)) {
verifications++;
}
}
return verifications;
}
Aggregations