Skip to content

Commit

Permalink
Merge pull request #37 from chenhaozx/feature/selective-disclosure
Browse files Browse the repository at this point in the history
The first version of selective disclosure
  • Loading branch information
junqizhang-dev committed Jan 30, 2019
2 parents 26f976e + 2221b16 commit b63bc13
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 501 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright© (2018) 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.constant;

/**
* credential field disclosure status.
* @author tonychen
*/
public enum CredentialFieldDisclosureValue {

/**
* the field is disclosed.
*/
DISCLOSED(1),

/**
* the field is not disclosed.
*/
NOT_DISCLOSED(0);

/**
* disclosure status.
*/
private Integer status;

CredentialFieldDisclosureValue(Integer status) {
this.status = status;
}

/**
* get field disclosure status.
* @return disclosure status of the field.
*/
public Integer getStatus() {
return status;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public enum ErrorCode {
* The credential credential verify signature is exception.
*/
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE(100419, "credential verify signature exception"),

/**
* Authority issuer main error code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@
* along with weidentity-java-sdk. If not, see <https://www.gnu.org/licenses/>.
*/

package com.webank.weid.protocol.request;
package com.webank.weid.protocol.base;

import java.util.Map;

import lombok.Data;

import com.webank.weid.protocol.base.Credential;
import com.webank.weid.protocol.base.WeIdPublicKey;

/**
* The Arguments for the following SDK API: verifyCredential().
* Credential response.
*
* @author chaoxinhu 2018.10
* @author tonychen 2019年1月24日
*/
@Data
public class VerifyCredentialArgs {
public class CredentialWrapper {

/**
* Required: The Credential content.
* Required: The Credential.
*/
private Credential credential;

/**
* Optional: The public key passed in.
* Required: key is the credential field, and value "1" for disclosure to the third party, "0"
* for no disclosure.
*/
private WeIdPublicKey weIdPublicKey;
private Map<String, Object> disclosure;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.webank.weid.protocol.base.WeIdAuthentication;

/**
* The Arguments for the SDK API register CPT.
* The cptJsonSchema is Map.
* The Arguments for the SDK API register CPT. The cptJsonSchema is Map.
*
* @author lingfenghe
*/
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import com.webank.weid.protocol.base.WeIdAuthentication;

/**
* This is a subclass, The Arguments for the SDK API register CPT.
* The cptJsonSchema is String.
* This is a subclass, The Arguments for the SDK API register CPT. The cptJsonSchema is String.
*
* @author darwindu
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.webank.weid.protocol.base.WeIdPrivateKey;


/**
* The Arguments for the following SDK API: createCredential().
*
Expand Down
43 changes: 36 additions & 7 deletions src/main/java/com/webank/weid/rpc/CredentialService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package com.webank.weid.rpc;

import com.webank.weid.protocol.base.Credential;
import com.webank.weid.protocol.base.CredentialWrapper;
import com.webank.weid.protocol.base.WeIdPublicKey;
import com.webank.weid.protocol.request.CreateCredentialArgs;
import com.webank.weid.protocol.request.VerifyCredentialArgs;
import com.webank.weid.protocol.response.ResponseData;

/**
Expand All @@ -32,28 +33,56 @@
public interface CredentialService {

/**
* Generate a credential.
* Generate a credential for full claim content.
*
* @param args the args
* @return credential
*/
ResponseData<Credential> createCredential(CreateCredentialArgs args);
ResponseData<CredentialWrapper> createCredential(CreateCredentialArgs args);

/**
* Generate a credential with selected data.
*
* @param credential the credential.
* @param disclosure the setting of disclosure, such as: {@code{"name":1,"gender":0,"age":1}},
* which means you WILL disclose "name" and "age" to others, and "gender" WILL NOT disclose
* to others.
* @return CredentialWrapper
*/
ResponseData<CredentialWrapper> createSelectiveCredential(
Credential credential,
String disclosure
);

/**
* Verify the validity of a credential. Public key will be fetched from chain.
*
* @param args the args
* @param credential the credential
* @return the verification result. True if yes, false otherwise with exact verify error codes
* in ResponseData
*/
ResponseData<Boolean> verifyCredential(Credential args);
ResponseData<Boolean> verify(Credential credential);

/**
* Verify the validity of a credential. Public key will be fetched from chain.
*
* @param credentialWrapper the credentialWrapper
* @return the verification result. True if yes, false otherwise with exact verify error codes
* in ResponseData
*/
ResponseData<Boolean> verify(CredentialWrapper credentialWrapper);

/**
* Verify the validity of a credential. Public key must be provided.
*
* @param args the args
* @param credentialWrapper the credential wrapper.
* @param weIdPublicKey the specific public key which used to verify signature of the
* credential.
* @return the verification result. True if yes, false otherwise with exact verify error codes
* in ResponseData
*/
ResponseData<Boolean> verifyCredentialWithSpecifiedPubKey(VerifyCredentialArgs args);
ResponseData<Boolean> verifyCredentialWithSpecifiedPubKey(
CredentialWrapper credentialWrapper,
WeIdPublicKey weIdPublicKey
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public ResponseData<AuthorityIssuer> queryAuthorityIssuerInfo(String weId) {

private ResponseData<Boolean> checkRegisterAuthorityIssuerArgs(
RegisterAuthorityIssuerArgs args) {

if (args == null) {
return new ResponseData<>(false, ErrorCode.ILLEGAL_INPUT);
}
Expand Down Expand Up @@ -340,7 +340,7 @@ private ResponseData<Boolean> checkRegisterAuthorityIssuerArgs(
}

private ResponseData<Boolean> checkRemoveAuthorityIssuerArgs(RemoveAuthorityIssuerArgs args) {

if (args == null) {
return new ResponseData<>(false, ErrorCode.ILLEGAL_INPUT);
}
Expand All @@ -357,7 +357,7 @@ private ResponseData<Boolean> checkRemoveAuthorityIssuerArgs(RemoveAuthorityIssu
}

private ResponseData<Boolean> checkAuthorityIssuerArgsValidity(AuthorityIssuer args) {

if (args == null) {
return new ResponseData<>(false, ErrorCode.ILLEGAL_INPUT);
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/webank/weid/service/impl/CptServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private static void reloadContract(String privateKey) {

/**
* This is used to register a new CPT to the blockchain.
*
* @param args the args
* @return the response data
*/
Expand All @@ -118,7 +119,7 @@ public ResponseData<CptBaseInfo> registerCpt(CptStringArgs args) {
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setWeIdAuthentication(args.getWeIdAuthentication());
cptMapArgs.setCptJsonSchema(
(Map<String, Object>)JsonUtil.jsonStrToObj(
(Map<String, Object>) JsonUtil.jsonStrToObj(
new HashMap<String, Object>(),
args.getCptJsonSchema())
);
Expand Down Expand Up @@ -234,7 +235,7 @@ public ResponseData<Cpt> queryCpt(Integer cptId) {
}

Map<String, Object> jsonSchemaMap =
(Map<String, Object>)JsonUtil.jsonStrToObj(
(Map<String, Object>) JsonUtil.jsonStrToObj(
new HashMap<String, Object>(),
jsonSchema.toString().trim());
cpt.setCptJsonSchema(jsonSchemaMap);
Expand All @@ -248,7 +249,7 @@ public ResponseData<Cpt> queryCpt(Integer cptId) {
new String(
SignatureUtils.base64Encode(
SignatureUtils.simpleSignatureSerialization(signatureData)),
WeIdConstant.UTF_8);
WeIdConstant.UTF_8);
cpt.setCptSignature(cptSignature);

ResponseData<Cpt> responseData = new ResponseData<Cpt>();
Expand All @@ -268,6 +269,7 @@ public ResponseData<Cpt> queryCpt(Integer cptId) {

/**
* This is used to update a CPT data which has been register.
*
* @param args the args
* @return the response data
*/
Expand All @@ -282,7 +284,7 @@ public ResponseData<CptBaseInfo> updateCpt(CptStringArgs args, Integer cptId) {
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setWeIdAuthentication(args.getWeIdAuthentication());
cptMapArgs.setCptJsonSchema(
(Map<String, Object>)JsonUtil.jsonStrToObj(
(Map<String, Object>) JsonUtil.jsonStrToObj(
new HashMap<String, Object>(),
args.getCptJsonSchema())
);
Expand Down Expand Up @@ -533,6 +535,7 @@ private boolean validatePrivateKeyWeIdMatches(WeIdPrivateKey cptPublisherPrivate

/**
* create new cpt json schema.
*
* @param cptJsonSchema Map
* @return String
*/
Expand Down

0 comments on commit b63bc13

Please sign in to comment.