Skip to content

Commit

Permalink
fix bugs in createEvidenceWithLogAndCustomKey
Browse files Browse the repository at this point in the history
  • Loading branch information
youwenbusi committed Sep 22, 2023
1 parent dc1f2be commit 47bdfe6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,5 @@ doc/bak/
secring.gpg
*.address
logs/
gradle.properties
gradle.properties
resources/
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1-rc.1
3.1.1-rc.2-SNAPSHOT
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ dependencies {
localDeps 'org.projectlombok:lombok:1.18.10'
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, mysql_driver, redisson, zxing, rpc, pdfbox, protobuf, caffeine, oval, gson, spring, xstream
compile("com.webank:weid-blockchain:3.1.1-rc.1")
compile("com.webank:weid-blockchain:3.1.1-rc.2-SNAPSHOT")

compile fileTree(dir: 'lib', include: '*.jar')
implementation 'com.google.guava:guava:31.1-jre'
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
jdkTlsNamedGroups=secp256r1,secp256k1
repoType=zn
signing.keyId=
signing.password=
signing.secretKeyRingFile=
sonatypeUsername=
sonatypePassword=
signing.keyId=62A32F80
signing.password=weidentity@123
signing.secretKeyRingFile=./secring.gpg
sonatypeUsername=tonychen
sonatypePassword=Abcd1234!@#$
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public ResponseData<String> createEvidenceWithLogAndCustomKey(
WeIdPrivateKey weIdPrivateKey,
String log,
String customKey) {
if (StringUtils.isEmpty(customKey) || DataToolUtils.isValidHash(customKey)) {
if (StringUtils.isEmpty(customKey) || !DataToolUtils.isUtf8String(customKey)) {
logger.error("Custom key must be non-empty and must not be of hash format.");
return new ResponseData<>(StringUtils.EMPTY, ErrorCode.ILLEGAL_INPUT);
}
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/com/webank/weid/util/TestSignatureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

/**
* Test SignatureUtils.
Expand All @@ -27,11 +28,12 @@ public void testSignatureUtils()
throws Exception {

String privateKey =
"58317564669857453586637110679746575832914889677346283755719850144028639639651";
"58317564669857453586637110679746175832914889677346286855728850144028639639411";
//CryptoKeyPair keyPair = com.webank.weid.blockchain.service.fisco.CryptoFisco.cryptoSuite.getKeyPairFactory().createKeyPair(new BigInteger(privateKey));
//logger.info("publicKey:{} ", keyPair.getHexPublicKey());
//BigInteger publicKey = DataToolUtils.publicKeyFromPrivate(new BigInteger(privateKey));
String publicKey = DataToolUtils.publicKeyStrFromPrivate(new BigInteger(privateKey, 10));
String address = DataToolUtils.addressFromPublic(new BigInteger(publicKey, 10));
logger.info("publicKey:{} ", publicKey);

/*ECKeyPair keyPair = TestBaseUtil.createKeyPair();
Expand All @@ -42,13 +44,18 @@ public void testSignatureUtils()
//logger.info("privateKey:{}", keyPair.getHexPrivateKey());

String str = "hello world...........................yes";
String encodedTransaction = "+QO0hAi2YVSFF0h25/+FF0h25/+Cr7KUBpkSD2WtUaFvOjCsTBmdGldzoWuAuQOEY171pQAAAAAAAAAAAAAAACjm35JDYfxrsw1HaGOliu0ub1toAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0xNjk1MzcxNzQ0NTA0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABcWRpZDp3ZWlkOjEwMToweDI4ZTZkZjkyNDM2MWZjNmJiMzBkNDc2ODYzYTU4YWVkMmU2ZjViNjgja2V5cy0zYTg2MDMzZCxFZDI1NTE5VmVyaWZpY2F0aW9uS2V5MjAyMCxkaWQ6d2VpZDoxMDE6MHgyOGU2ZGY5MjQzNjFmYzZiYjMwZDQ3Njg2M2E1OGFlZDJlNmY1YjY4LHo1cnJmM3VQQ2d3ek1CWjRqMnpuMWhZVzF2QWc2OFdUVTZTZFpFQnl3aUdGTnpUZWVZNHR4cFRZTDJHQnJRWmlIdVRjcXg5RjJ5dzlKUndKSjF0NVI2YzY1dG5KTDh2ZUN5VDg1cms2dXlrRGM2aDk0ZVZOSnh3QUg1NlI0OHRoRDd5RlR5VUVTR2RNenVId3oydThHdWRIWXVlZkJzdG1MRktFSjQ2V0tEdnZ4QjlDRlg0ZkZWaG85ZDFYRW9ranpaeVRSRTFFMktiOFg1NkZrU3NibjZCUgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAemRpZDp3ZWlkOjEwMToweDI4ZTZkZjkyNDM2MWZjNmJiMzBkNDc2ODYzYTU4YWVkMmU2ZjViNjgjMDRiOGQ4YWUsV2VJZGVudGl0eSxodHRwczovL2dpdGh1Yi5jb20vV2VCYW5rQmxvY2tjaGFpbi9XZUlkZW50aXR5AAAAAAAAAQGA";
byte[] decodeTransaction = DataToolUtils.base64Decode(encodedTransaction.getBytes());
String decodeTransactionStr = new String(decodeTransaction);
//address = DataToolUtils.addressFromPublic(new BigInteger(decodeTransaction));
//Sign.SignatureData sigData = DataToolUtils.secp256k1SignToSignature(str, keyPair);
//ECDSASignatureResult sigData = DataToolUtils.secp256k1SignToSignature(str, keyPair);
RsvSignature signatureResult = DataToolUtils.signToRsvSignature(str, privateKey);
RsvSignature signatureResult = DataToolUtils.signToRsvSignature(decodeTransactionStr, privateKey);
//byte[] serialized = DataToolUtils.simpleSignatureSerialization(sigData);
//Sign.SignatureData newSigData = DataToolUtils.simpleSignatureDeserialization(serialized);
//ECDSASignatureResult newSigData = DataToolUtils.simpleSignatureDeserialization(serialized);
logger.info(DataToolUtils.SigBase64Serialization(signatureResult));
String result = DataToolUtils.SigBase64Serialization(signatureResult);
logger.info(result);

/*Sign.SignatureData signatureData = DataToolUtils
.convertBase64StringToSignatureData(new String(Base64.encode(serialized)));*/
Expand Down

0 comments on commit 47bdfe6

Please sign in to comment.