-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Cletitia/develop
Update to 0.2.0
- Loading branch information
Showing
9 changed files
with
493 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ build/ | |
.gradle/ | ||
.idea | ||
.vscode | ||
demo/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ ext { | |
} | ||
|
||
allprojects { | ||
version '0.1.3' | ||
version '0.2.0' | ||
group = 'org.tron.trident' | ||
|
||
repositories { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
trident-java/core/src/main/java/org/tron/trident/core/Constant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.tron.trident.core; | ||
|
||
public final class Constant{ | ||
|
||
//TronGrid gRPC services, maintained by official team | ||
public static final String TRONGRID_MAIN_NET = "grpc.trongrid.io:50051"; | ||
public static final String TRONGRID_MAIN_NET_SOLIDITY = "grpc.trongrid.io:50052"; | ||
|
||
public static final String TRONGRID_SHASTA = "grpc.shasta.trongrid.io:50051"; | ||
public static final String TRONGRID_SHASTA_SOLIDITY = "grpc.shasta.trongrid.io:50052"; | ||
|
||
//Public Fullnode, maintained by official team | ||
public static final String FULLNODE_NILE = "47.252.19.181:50051"; | ||
public static final String FULLNODE_NILE_SOLIDITY = "47.252.19.181:50061"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
trident-java/core/src/main/java/org/tron/trident/core/transaction/SignatureValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.tron.trident.core.transaction; | ||
|
||
import org.bouncycastle.util.encoders.Hex; | ||
import org.tron.trident.core.ApiWrapper; | ||
import org.tron.trident.core.key.KeyPair; | ||
import org.tron.trident.crypto.SECP256K1; | ||
import org.tron.trident.crypto.tuwenitypes.Bytes; | ||
import org.tron.trident.crypto.tuwenitypes.Bytes32; | ||
import org.tron.trident.proto.Chain.Transaction; | ||
|
||
import java.util.Arrays; | ||
|
||
public class SignatureValidator { | ||
|
||
/** | ||
* Verify if a transction contains a valid signature. | ||
* @param txid the transaction hash | ||
* @param signature the signature message corresponding to the transaction hash | ||
* @param owner the owner of the transaction | ||
* @return true if the signature is valid | ||
*/ | ||
public static boolean verify(byte[] txid, byte[] signature, byte[] owner) { | ||
SECP256K1.Signature sig = SECP256K1.Signature.decode(Bytes.wrap(signature)); | ||
//decode a public key from the signature | ||
SECP256K1.PublicKey pubKey = SECP256K1.PublicKey.recoverFromSignature(Bytes32.wrap(txid), sig).get(); | ||
|
||
final byte[] addressFromPubKey = KeyPair.publicKeyToAddress(pubKey); | ||
|
||
return Arrays.equals(addressFromPubKey, owner); | ||
} | ||
|
||
public static boolean verify(String txid, String signature, String owner) { | ||
byte[] txidBytes = Hex.decode(txid); | ||
byte[] sig = Hex.decode(signature); | ||
byte[] ownerBytes = ApiWrapper.parseAddress(owner).toByteArray(); | ||
|
||
return verify(txidBytes, sig, ownerBytes); | ||
} | ||
} |
Oops, something went wrong.