Skip to content

Commit

Permalink
add transinfo in createEvidence
Browse files Browse the repository at this point in the history
  • Loading branch information
youwenbusi committed Oct 17, 2023
1 parent 8dc81ee commit d000452
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 217 deletions.
1 change: 1 addition & 0 deletions global.status
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"authority_issuer_current_cpt_id":1000,"none_authority_issuer_current_cpt_id":2000007,"authority_issuer_current_policy_id":1000,"none_authority_issuer_current_policy_id":2000000,"presentationId":1}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public final class CredentialConstant {
* The Credential Proof Type Enumerate.
*/
public static enum CredentialProofType {
ECDSA("Secp256k1");
ECDSA("Secp256k1"),
SM2("SM2");

/**
* The Type Name of the Credential Proof.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.webank.weid.util.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.fisco.bcos.sdk.model.CryptoType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -1047,7 +1048,7 @@ public ResponseData<CredentialPojo> createCredential(CreateCredentialPojoArgs ar
String creator = args.getWeIdAuthentication().getWeId();
result.putProofValue(ParamKeyConstant.PROOF_CREATOR, creator);
//TODO:目前CredentialProofType只有ECDSA类型,需要添加SM2
String proofType = CredentialProofType.ECDSA.getTypeName();
String proofType = DataToolUtils.cryptoType == CryptoType.ECDSA_TYPE? CredentialProofType.ECDSA.getTypeName():CredentialProofType.SM2.getTypeName();
result.putProofValue(ParamKeyConstant.PROOF_TYPE, proofType);
result.putProofValue(ParamKeyConstant.PROOF_SIGNATURE, signature);
result.setSalt(saltMap);
Expand All @@ -1074,7 +1075,7 @@ private ResponseData<CredentialPojo> createLiteCredential(CredentialPojo credent
String signature = DataToolUtils.SigBase64Serialization(
DataToolUtils.signToRsvSignature(rawData, privateKey)
);
String proofType = CredentialProofType.ECDSA.getTypeName();
String proofType = DataToolUtils.cryptoType == CryptoType.ECDSA_TYPE? CredentialProofType.ECDSA.getTypeName():CredentialProofType.SM2.getTypeName();
credentialPojo.putProofValue(ParamKeyConstant.PROOF_TYPE, proofType);
credentialPojo.putProofValue(ParamKeyConstant.PROOF_SIGNATURE, signature);
ResponseData<CredentialPojo> responseData = new ResponseData<>(
Expand Down Expand Up @@ -1158,7 +1159,7 @@ public ResponseData<CredentialPojo> addSignature(
String creator = callerAuth.getWeId();
result.putProofValue(ParamKeyConstant.PROOF_CREATOR, creator);

String proofType = CredentialProofType.ECDSA.getTypeName();
String proofType = DataToolUtils.cryptoType == CryptoType.ECDSA_TYPE? CredentialProofType.ECDSA.getTypeName():CredentialProofType.SM2.getTypeName();
result.putProofValue(ParamKeyConstant.PROOF_TYPE, proofType);
result.putProofValue(ParamKeyConstant.PROOF_SIGNATURE, signature);
result.setSalt(saltMap);
Expand Down Expand Up @@ -1896,7 +1897,7 @@ private void generatePresentationProof(
WeIdAuthentication weIdAuthentication,
PresentationE presentation) {

String proofType = CredentialProofType.ECDSA.getTypeName();
String proofType = DataToolUtils.cryptoType == CryptoType.ECDSA_TYPE? CredentialProofType.ECDSA.getTypeName():CredentialProofType.SM2.getTypeName();
presentation.putProofValue(ParamKeyConstant.PROOF_TYPE, proofType);

Long proofCreated = DateUtils.getNoMillisecondTimeStamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public ResponseData<CredentialWrapper> createCredential(CreateCredentialArgs arg
credentialWrapper.setDisclosure(disclosureMap);

// Construct Credential Proof
//替换国密
Map<String, String> credentialProof = CredentialUtils.buildCredentialProof(
result,
args.getWeIdPrivateKey().getPrivateKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private ResponseData<Boolean> addByCustomKey(
weIdPrivateKey.getPrivateKey()
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(true, ErrorCode.SUCCESS);
return new ResponseData<>(true, ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(false, resp.getErrorCode(), resp.getErrorMessage());
}
Expand All @@ -425,7 +425,7 @@ private ResponseData<Boolean> addByCustomKey(
weIdPrivateKey.getPrivateKey()
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(true, ErrorCode.SUCCESS);
return new ResponseData<>(true, ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(false, resp.getErrorCode(), resp.getErrorMessage());
}
Expand Down Expand Up @@ -554,7 +554,7 @@ private ResponseData<String> hashToNewEvidence(String hashValue, String privateK
privateKey
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS);
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(StringUtils.EMPTY, resp.getErrorCode(), resp.getErrorMessage());
}
Expand Down Expand Up @@ -812,7 +812,7 @@ public ResponseData<String> createEvidenceWithLogAndCustomKey(
privateKey
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(hashValue, ErrorCode.SUCCESS);
return new ResponseData<>(hashValue, ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(StringUtils.EMPTY, resp.getErrorCode(), resp.getErrorMessage());
}
Expand Down Expand Up @@ -869,7 +869,7 @@ public ResponseData<Boolean> revoke(Hashable object, WeIdAuthentication weIdAuth
weIdAuthentication.getWeIdPrivateKey().getPrivateKey()
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS);
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(false, resp.getErrorCode(), resp.getErrorMessage());
}
Expand Down Expand Up @@ -901,7 +901,7 @@ public ResponseData<Boolean> unRevoke(Hashable object, WeIdAuthentication weIdAu
weIdAuthentication.getWeIdPrivateKey().getPrivateKey()
);
if (resp.getErrorCode() == ErrorCode.SUCCESS.getCode()) {
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS);
return new ResponseData<>(resp.getResult(), ErrorCode.SUCCESS, resp.getTransactionInfo());
} else {
return new ResponseData<>(false, resp.getErrorCode(), resp.getErrorMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ private static ErrorCode isCredentialProofValid(Map<String, Object> proof) {
}
}
// If the Proof type is ECDSA or other signature based scheme, check signature
if (type.equalsIgnoreCase(CredentialProofType.ECDSA.getTypeName())) {
if (type.equalsIgnoreCase(CredentialProofType.ECDSA.getTypeName()) || type.equalsIgnoreCase(CredentialProofType.SM2.getTypeName())) {
if (proof.get(ParamKeyConstant.PROOF_SIGNATURE) == null) {
return ErrorCode.CREDENTIAL_SIGNATURE_BROKEN;
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/webank/weid/util/CredentialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.webank.weid.protocol.request.CreateCredentialArgs;
import org.apache.commons.lang3.StringUtils;
import org.fisco.bcos.sdk.abi.datatypes.generated.Bytes32;
import org.fisco.bcos.sdk.model.CryptoType;

import java.nio.charset.StandardCharsets;
import java.util.*;
Expand Down Expand Up @@ -453,7 +454,7 @@ private static ErrorCode isCredentialProofValid(Map<String, String> proof) {
return ErrorCode.CREDENTIAL_ISSUER_INVALID;
}
// If the Proof type is ECDSA or other signature based scheme, check signature
if (type.equalsIgnoreCase(CredentialProofType.ECDSA.getTypeName())) {
if (type.equalsIgnoreCase(CredentialProofType.ECDSA.getTypeName()) || type.equalsIgnoreCase(CredentialProofType.SM2.getTypeName())) {
String signature = proof.get(ParamKeyConstant.CREDENTIAL_SIGNATURE);
if (StringUtils.isEmpty(signature) || !DataToolUtils.isValidBase64String(signature)) {
return ErrorCode.CREDENTIAL_SIGNATURE_BROKEN;
Expand All @@ -468,7 +469,7 @@ private static ErrorCode isCredentialProofValid(Map<String, String> proof) {
* @return Context value in String.
*/
public static String getDefaultCredentialProofType() {
return CredentialConstant.CredentialProofType.ECDSA.getTypeName();
return DataToolUtils.cryptoType == CryptoType.ECDSA_TYPE? CredentialProofType.ECDSA.getTypeName():CredentialProofType.SM2.getTypeName();
}

private static boolean isCredentialProofTypeValid(String type) {
Expand Down
65 changes: 0 additions & 65 deletions src/main/resources/fisco.properties

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/java/com/webank/weid/util/TestSignatureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testSignatureUtils()
throws Exception {

String privateKey =
"58317564669857453586637110679746175832914889677346286855728850144028639639411";
"58317564669857453586637110679736175832914889667346286865928840144018638639411";
//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));
Expand All @@ -44,7 +44,7 @@ public void testSignatureUtils()
//logger.info("privateKey:{}", keyPair.getHexPrivateKey());

String str = "hello world...........................yes";
String encodedTransaction = "+QO0hAi2YVSFF0h25/+FF0h25/+Cr7KUBpkSD2WtUaFvOjCsTBmdGldzoWuAuQOEY171pQAAAAAAAAAAAAAAACjm35JDYfxrsw1HaGOliu0ub1toAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0xNjk1MzcxNzQ0NTA0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA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RiOGQ4YWUsV2VJZGVudGl0eSxodHRwczovL2dpdGh1Yi5jb20vV2VCYW5rQmxvY2tjaGFpbi9XZUlkZW50aXR5AAAAAAAAAQGA";
byte[] decodeTransaction = DataToolUtils.base64Decode(encodedTransaction.getBytes());
String decodeTransactionStr = new String(decodeTransaction);
//address = DataToolUtils.addressFromPublic(new BigInteger(decodeTransaction));
Expand Down
20 changes: 0 additions & 20 deletions src/test/resources/ca.crt

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/resources/gm/gmca.crt

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/resources/gm/gmensdk.crt

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/resources/gm/gmensdk.key

This file was deleted.

Loading

0 comments on commit d000452

Please sign in to comment.