4. verify

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialPojoService.verify
  2. 接口定义: ResponseData<Boolean> verify(WeIdPublicKey issuerPublicKey, CredentialPojo credential)
  3. 接口描述: 使用指定公钥验证credentialWrapper

接口入参:

com.webank.weid.protocol.base.WeIdPublicKey

名称类型非空说明备注
publicKeyStringY公钥

com.webank.weid.protocol.base.CredentialPojo

名称类型非空说明备注
contextStringY
typeList<String>Y
idStringY证书ID
cptIdIntegerYcptId
issuerStringYissuer 的 WeIdentity DID
issuanceDateLongY创建日期
expirationDateLongY到期日期
claimMap<String, Object>YClaim数据
proofMap<String, Object>Y签名数据结构体

接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultBoolean验证结果业务数据
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

名称类型说明备注
blockNumberBigInteger交易块高
transactionHashString交易hash
transactionIndexBigInteger交易索引

此方法返回code

enumcodedesc
SUCCESS0成功
CPT_ID_ILLEGAL100303cptId无效
CREDENTIAL_ISSUER_MISMATCH100403issuerWeId跟Credential中的issuer不匹配
CREDENTIAL_SIGNATURE_BROKEN100405签名验证不通过
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_CLAIM_DATA_ILLEGAL100411Claim数据无效
CREDENTIAL_ID_NOT_EXISTS100412ID为空
CREDENTIAL_CONTEXT_NOT_EXISTS100413context为空
CREDENTIAL_CPT_NOT_EXISTS100416cpt不存在
CREDENTIAL_WEID_DOCUMENT_ILLEGAL100417获取weIdDocument异常
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE100419签名验证异常
CREDENTIAL_PUBLIC_KEY_NOT_EXISTS100421公钥不存在
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL100429验证签名类型异常
CREDENTIAL_SALT_ILLEGAL100430盐值非法
ILLEGAL_INPUT160004参数为空

调用示例

  1. CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
  2. CreateCredentialPojoArgs<Map<String, Object>> createCredentialPojoArgs = new CreateCredentialPojoArgs<Map<String, Object>>();
  3. createCredentialPojoArgs.setCptId(1017);
  4. createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  5. createCredentialPojoArgs.setExpirationDate(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 100);
  6.  
  7. WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
  8. weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  9.  
  10. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  11. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  12. weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
  13.  
  14. weIdAuthentication.setWeIdPublicKeyId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0");
  15. createCredentialPojoArgs.setWeIdAuthentication(weIdAuthentication);
  16.  
  17. Map<String, Object> claim = new HashMap<String, Object>();
  18. claim.put("name", "zhangsan");
  19. claim.put("gender", "F");
  20. claim.put("age", 22);
  21. createCredentialPojoArgs.setClaim(claim);
  22.  
  23. ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
  24.  
  25. WeIdPublicKey weIdPublicKey = new WeIdPublicKey();
  26. weIdPublicKey.setPublicKey("9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875");
  27.  
  28. ResponseData<Boolean> responseVerify = credentialPojoService.verify(weIdPublicKey, response.getResult());
  1. 返回结果如:
  2. result: true
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:null

时序图

sequenceDiagramparticipant 调用者participant CredentialPojoServiceparticipant CptServiceparticipant 区块链节点调用者->>CredentialPojoService: 调用verify()CredentialPojoService->>CredentialPojoService: 入参非空、格式及合法性检查opt 入参校验失败CredentialPojoService—>>调用者: 报错,提示参数不合法并退出endCredentialPojoService->>CptService: 查询CPT存在性及Claim关联语义CptService->>区块链节点: 调用智能合约,查询CPT区块链节点—>>CptService: 返回查询结果CptService—>>CredentialPojoService: 返回查询结果opt 不符合CPT格式要求CredentialPojoService—>>调用者: 报错并退出endCredentialPojoService->>CredentialPojoService: 验证过期、撤销与否opt 任一验证失败CredentialPojoService—>>调用者: 报错并退出endCredentialPojoService->>CredentialPojoService: 通过公钥与签名对比,验证Issuer是否签发此凭证opt 验证签名失败CredentialPojoService—>>调用者: 报错并退出endCredentialPojoService—>>调用者: 返回成功