Skip to content

Commit

Permalink
Added scripts for hashing an input file
Browse files Browse the repository at this point in the history
  • Loading branch information
aion-shidokht committed Oct 4, 2019
1 parent dca04b7 commit 9bfa885
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Description of relevant components:
11) `withdrawRewards.sh` - withdraws the block rewards of a delegator.
12) `finalizeUndelegate.sh` - finalizes an undelegate Id.
13) `finalizeTransfer.sh` - finalizes a transfer Id.
14) `hashFile.sh` - prints the blake-2b hash of the input file.

How to use scripts
---
Expand Down Expand Up @@ -125,6 +126,14 @@ This script can be used to finalize a transfer.
`caller_private_key` private key of the account making the transaction. Private key should start with `0x`. Both 32 and 64 byte keys are accepted as an input.<br />
`transfer_Id` Id to finalize.<br />

### hashFile.sh

This script prints the blake-2b hash of the input file and can be used to generate the hash of the meta-data json file.

**Usage:**

```./registerPool.sh path_to_file```

### bootstrap.sh

In order to run this
Expand Down
Binary file modified Tools.jar
Binary file not shown.
20 changes: 20 additions & 0 deletions hashFile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# This script can be used to hash the pool meta-data json file.
#
# Usage: ./hashFile.sh path_to_file
# -----------------------------------------------------------------------------
TOOLS_JAR=Tools.jar

file_path="$1"

if [ $# -ne 1 ]
then
echo "Invalid number of parameters."
echo "Usage: ./hashFile.sh path_to_file"
exit 1
fi

hash="$(java -cp $TOOLS_JAR cli.HashFile "$file_path")"
echo "Meta-data content hash:"
echo "$hash"
28 changes: 28 additions & 0 deletions src/cli/HashFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli;

import net.i2p.crypto.eddsa.Utils;
import support.Blake2b;

import java.io.File;
import java.nio.file.Files;

public class HashFile {

public static void main(String[] args) throws Exception {
if (0 == args.length) {
System.err.println("Usage: cli.HashFile FILE_PATH");
System.exit(1);
}

byte[] fileBytes = Files.readAllBytes(new File(args[0]).toPath());

byte[] hash = blake2b(fileBytes);
System.out.println("0x" + Utils.bytesToHex(hash));
}

public static byte[] blake2b(byte[] msg) {
Blake2b digest = Blake2b.Digest.newInstance(32);
digest.update(msg);
return digest.digest();
}
}

0 comments on commit 9bfa885

Please sign in to comment.