Skip to content

Commit

Permalink
Merge pull request #34 from chaoxinhu/feature/evidence-java
Browse files Browse the repository at this point in the history
Evidence Java SDK Part
  • Loading branch information
junqizhang-dev committed Jan 31, 2019
2 parents b63bc13 + 469ef83 commit 7a10fc8
Show file tree
Hide file tree
Showing 33 changed files with 1,886 additions and 266 deletions.
7 changes: 5 additions & 2 deletions build-tools/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ function modify_config()
weid_address=$(cat weIdContract.address)
cpt_address=$(cat cptController.address)
issuer_address=$(cat authorityIssuer.address)
evidence_address=$(cat evidenceController.address)
export WEID_ADDRESS=${weid_address}
export CPT_ADDRESS=${cpt_address}
export ISSUER_ADDRESS=${issuer_address}
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}'
export EVIDENCE_ADDRESS=${evidence_address}
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${app_xml_config_dir}
echo "modify sdk config finished..."
Expand Down Expand Up @@ -124,7 +126,8 @@ function gradle_build_sdk()
export WEID_ADDRESS="0x0"
export CPT_ADDRESS="0x0"
export ISSUER_ADDRESS="0x0"
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}'
export EVIDENCE_ADDRESS="0x0"
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}

cd ${java_source_code_dir}/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ List jackson = [
"com.squareup:javapoet:1.7.0",
"io.reactivex:rxjava:1.2.4",
"com.github.jnr:jnr-unixsocket:0.15",
"com.webank:weidentity-contract-java:1.0.0"
"com.webank:weidentity-contract-java:1.1.0"
]

// In this section you declare the dependencies for your production and test code
Expand Down
7 changes: 5 additions & 2 deletions ci/script/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ function modify_config()
weid_address=$(cat weIdContract.address)
cpt_address=$(cat cptController.address)
issuer_address=$(cat authorityIssuer.address)
evidence_address=$(cat evidenceController.address)
export WEID_ADDRESS=${weid_address}
export CPT_ADDRESS=${cpt_address}
export ISSUER_ADDRESS=${issuer_address}
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}'
export EVIDENCE_ADDRESS=${evidence_address}
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${java_source_code_dir}/src/test/resources/
#cat $app_xml_config
Expand All @@ -31,7 +33,8 @@ function gradle_build_sdk()
export WEID_ADDRESS="0x0"
export CPT_ADDRESS="0x0"
export ISSUER_ADDRESS="0x0"
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}'
export EVIDENCE_ADDRESS="0x0"
MYVARS='${BLOCKCHIAN_NODE_INFO}:${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}

echo "Begin to compile java code......"
Expand Down
10 changes: 5 additions & 5 deletions docs/zh_CN/docs/weidentity-java-sdk-doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3455,7 +3455,7 @@ com.webank.weid.protocol.base.WeIdPrivateKey
**接口入参**\ : String

**接口返回**\ : com.webank.weid.protocol.base.Evidence;
**接口返回**\ : com.webank.weid.protocol.base.EvidenceInfo;

.. list-table::
:header-rows: 1
Expand Down Expand Up @@ -3521,7 +3521,7 @@ com.webank.weid.protocol.base.WeIdPrivateKey
.. code-block:: text
返回结果如:
result: (com.webank.weid.protocol.base.Evidence)
result: (com.webank.weid.protocol.base.EvidenceInfo)
credentialHash: c8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
signers: 0x0106595955ce4713fd169bfa68e599eb99ca2e9f
signature: HO+/ve+/vXfvv70hQO+/vQwMVO+/vSot77+977+9UGEhLO+/vW4277+977+977+9HO+/ve+/vSTvv70777+9f14=
Expand Down Expand Up @@ -3550,14 +3550,14 @@ com.webank.weid.protocol.base.WeIdPrivateKey

----

3. verifyEvidence()
3. verify()
~~~~~~~~~~~~~~~~~~~~~

**基本信息**

.. code-block:: text
接口名称:com.webank.weid.rpc.EvidenceService.verifyEvidence
接口名称:com.webank.weid.rpc.EvidenceService.verify
接口定义:ResponseData<Boolean> verifyEvidence(Credential credential, String evidenceAddress)
接口详细描述: 根据传入的凭证和链上凭证对比,验证其是否遭到篡改。
Expand Down Expand Up @@ -3735,7 +3735,7 @@ String:以地址形式存在的String,会进行入参检查
args.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<Credential> credResponse = credentialService.createCredential(args);
ResponseData<String> response = evidenceService.createEvidence(credResponse.getCredential(), weIdPrivateKey);
return evidenceService.verifyEvidence(credResponse.getResult(), response.getResult());
return evidenceService.verify(credResponse.getResult(), response.getResult());
.. code-block:: text
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/webank/weid/config/ContractConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018) WeBank Co., Ltd.
* Copyright© (2018-2019) WeBank Co., Ltd.
*
* This file is part of weidentity-java-sdk.
*
Expand All @@ -25,6 +25,7 @@

/**
* contract address config.
*
* @author tonychen 2018.9.29
*/
@Component("ContractConfig")
Expand All @@ -48,4 +49,10 @@ public class ContractConfig {
*/
@Value("${issuer.contractaddress}")
private String issuerAddress;

/**
* The EvidenceController Contract address.
*/
@Value("${evidence.contractaddress}")
private String evidenceAddress;
}
48 changes: 40 additions & 8 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018) WeBank Co., Ltd.
* Copyright© (2018-2019) WeBank Co., Ltd.
*
* This file is part of weidentity-java-sdk.
*
Expand Down Expand Up @@ -75,9 +75,9 @@ public enum ErrorCode {
CREDENTIAL_ERROR(100400, "error occured during processing credential tasks"),

/**
* The exact error codes in credential tasks.
* The credential does not exist on chain (evidence not found).
*/
CREDENTIAL_NOT_EXISTS(100401, "credential does not exist"),
CREDENTIAL_EVIDENCE_NOT_EXISTS_ON_CHAIN(100401, "credential evidence does not exist on chain"),

/**
* The credential expired.
Expand Down Expand Up @@ -156,7 +156,7 @@ public enum ErrorCode {
* The credential issuer does not have a valid WeIdentity DID document.
*/
CREDENTIAL_WEID_DOCUMENT_ILLEGAL(100417, "weid document illegal"),

/**
* The credential issuer is invalid.
*/
Expand All @@ -167,6 +167,32 @@ public enum ErrorCode {
*/
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE(100419, "credential verify signature exception"),

/**
* The credential evidence contract failure: illegal input.
*/
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT(
500401,
"credential evidence contract failure: illegal input"
),

/**
* The credential evidence base error.
*/
CREDENTIAL_EVIDENCE_BASE_ERROR(
100500,
"generic error when processing credential evidence tasks"
),

/**
* The credential evidence hash mismatch.
*/
CREDENTIAL_EVIDENCE_HASH_MISMATCH(100501, "credential evidence hash mismatch"),

/**
* The credential evidence id mismatch.
*/
CREDENTIAL_EVIDENCE_ID_MISMATCH(100502, "credential evidence id mismatch"),

/**
* Authority issuer main error code.
*/
Expand All @@ -191,8 +217,10 @@ public enum ErrorCode {
/**
* The authority issuer opcode mismatch.
*/
AUTHORITY_ISSUER_OPCODE_MISMATCH(100205,
"opcode in event log does not match the desired opcode"),
AUTHORITY_ISSUER_OPCODE_MISMATCH(
100205,
"opcode in event log does not match the desired opcode"
),

/**
* The authority issuer name illegal.
Expand All @@ -203,13 +231,17 @@ public enum ErrorCode {
* The authority issuer accvalue illegal.
*/
AUTHORITY_ISSUER_ACCVALUE_ILLEAGAL(
100207, "the authority issuer accumulator value is illegal (integer value required)"),
100207,
"the authority issuer accumulator value is illegal (integer value required)"
),

/**
* The Authority Issuer Contract level error: subject already exists.
*/
AUTHORITY_ISSUER_CONTRACT_ERROR_ALREADY_EXIST(
500201, "the authority issuer contract error: the subject already exists"),
500201,
"the authority issuer contract error: the subject already exists"
),

/**
* The Authority Issuer Contract level error: subject already exists.
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/webank/weid/constant/WeIdConstant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018) WeBank Co., Ltd.
* Copyright© (2018-2019) WeBank Co., Ltd.
*
* This file is part of weidentity-java-sdk.
*
Expand Down Expand Up @@ -143,4 +143,25 @@ public final class WeIdConstant {
* 0L.
*/
public static final Long LONG_VALUE_ZERO = 0L;

/**
* -1.
*/
public static final Integer VALUE_NEG_FIRST = -1;

/**
* Hex Prefix.
*/
public static final String HEX_PREFIX = "0x";

/**
* UUID Separator.
*/
public static final String UUID_SEPARATOR = "-";

/**
* UUID Pattern.
*/
public static final String UUID_PATTERN =
"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright© (2018) WeBank Co., Ltd.
* Copyright© (2018-2019) WeBank Co., Ltd.
*
* This file is part of weidentity-java-sdk.
*
Expand Down Expand Up @@ -48,6 +48,7 @@
import com.webank.weid.contract.CommitteeMemberData;
import com.webank.weid.contract.CptController;
import com.webank.weid.contract.CptData;
import com.webank.weid.contract.EvidenceFactory;
import com.webank.weid.contract.RoleController;
import com.webank.weid.contract.WeIdContract;

Expand Down Expand Up @@ -149,6 +150,7 @@ private static void deployContract() {
String weIdContractAddress = deployWeIdContract();
String authorityIssuerDataAddress = deployAuthorityIssuerContracts();
deployCptContracts(authorityIssuerDataAddress, weIdContractAddress);
deployEvidenceContracts();
}

private static String deployWeIdContract() {
Expand Down Expand Up @@ -320,6 +322,30 @@ private static String deployAuthorityIssuerContracts() {
return authorityIssuerDataAddress;
}

private static String deployEvidenceContracts() {
if (null == web3j) {
loadConfig();
}

try {
Future<EvidenceFactory> f =
EvidenceFactory.deploy(
web3j,
credentials,
WeIdConstant.GAS_PRICE,
WeIdConstant.GAS_LIMIT,
WeIdConstant.INILITIAL_VALUE
);
EvidenceFactory evidenceFactory = f
.get(DEFAULT_DEPLOY_CONTRACTS_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
String evidenceFactoryAddress = evidenceFactory.getContractAddress();
writeAddressToFile(evidenceFactoryAddress, "evidenceController.address");
return evidenceFactoryAddress;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("EvidenceFactory deploy exception", e);
}
return StringUtils.EMPTY;
}

private static void writeAddressToFile(
String contractAddress,
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/webank/weid/protocol/base/EvidenceInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright© (2018-2019) WeBank Co., Ltd.
*
* This file is part of weidentity-java-sdk.
*
* weidentity-java-sdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* weidentity-java-sdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with weidentity-java-sdk. If not, see <https://www.gnu.org/licenses/>.
*/

package com.webank.weid.protocol.base;

import java.util.List;

import lombok.Data;

/**
* The base data structure to handle Credential EvidenceInfo info.
*
* @author chaoxinhu 2019.1
*/
@Data
public class EvidenceInfo {

/**
* Required: The full Credential hash.
*/
private String credentialHash;

/**
* Required: The signers of this Credential.
*/
private List<String> signers;

/**
* Required: The signatures of each signers with the same order.
* In JavaBean object, the signatures will be encoded in Base64.
* On the blockchain, the signatures will be stored in its r, s, v.
*/
private List<String> signatures;
}

0 comments on commit 7a10fc8

Please sign in to comment.