5. verify

基本信息

  1. 接口名称:com.webank.weid.rpc.EvidenceService.verify
  2. 接口定义:ResponseData<Boolean> verify(Hashable object, String evidenceAddress)
  3. 接口描述: 根据传入的Object计算存证Hash值和链上值对比,验证其是否遭到篡改。当存证包含多个签名时,将会依次验证每个签名,必须确实由签名者列表中的某个WeID所签发才算验证成功。

接口入参:

java.lang.Object

名称类型非空说明备注
ObjectHashable objectY实现了Hashable接口的任意Object当前支持Credential,CredentialWrapper,CredentialPojo

java.lang.String

名称类型非空说明备注
evidenceAddressStringY存证地址

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultBoolean是否set成功
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

此方法返回code

enumcodedesc
SUCCESS0成功
CPT_ID_ILLEGAL100303cptId无效
CREDENTIAL_EXPIRED100402过期
CREDENTIAL_ISSUER_MISMATCH100403issuer与签名不匹配
CREDENTIAL_SIGNATURE_BROKEN100405签名破坏
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_EXPIRE_DATE_ILLEGAL100409到期日期格式非法
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_ID_NOT_EXISTS100412ID为空
CREDENTIAL_CONTEXT_NOT_EXISTS100413context为空
CREDENTIAL_WEID_DOCUMENT_ILLEGAL100417WeIdentity Document为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE100419验证签名异常
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL100429验证签名类型异常
CREDENTIAL_EVIDENCE_SIGNATURE_BROKEN100431存证签名异常
CREDENTIAL_EVIDENCE_BASE_ERROR100500Evidence标准错误
CREDENTIAL_EVIDENCE_HASH_MISMATCH100501Evidence Hash不匹配
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
ILLEGAL_INPUT160004参数为空

调用示例

  1. CredentialService credentialService = new CredentialServiceImpl();
  2. EvidenceService evidenceService = new EvidenceServiceImpl();
  3.  
  4. HashMap<String, Object> claim = new HashMap<String, Object>(3);
  5. claim.put("name", "zhang san");
  6. claim.put("gender", "F");
  7. claim.put("age", 18);
  8.  
  9. CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
  10. createCredentialArgs.setClaim(claim);
  11. createCredentialArgs.setCptId(1017);
  12. createCredentialArgs.setExpirationDate(1561448312461L);
  13. createCredentialArgs.setIssuer("did:weid:0x30404b47c6c5811d49e28ea2306c804d16618017");
  14.  
  15. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  16. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  17.  
  18. createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
  19.  
  20. //创建Credential
  21. ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
  22.  
  23. Credential credential = response.getResult().getCredential();
  24.  
  25. //创建Evidence Address
  26. ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(credential, weIdPrivateKey);
  27.  
  28. String evidenceAddress = responseCreateEvidence.getResult();
  29.  
  30. //验证Credential by evidenceAddress
  31. ResponseData<Boolean> responseVerify = evidenceService.verify(credential, evidenceAddress);
  1. 返回结果如:
  2. result: true
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:null

时序图

sequenceDiagramparticipant 调用者participant EvidenceServiceparticipant WeIdServiceparticipant 区块链节点调用者->>EvidenceService: 调用VerifyEvidence()EvidenceService->>EvidenceService: 入参非空、格式及合法性检查opt 入参校验失败EvidenceService—>>调用者: 报错,提示参数不合法并退出endEvidenceService->>EvidenceService: 调用GetEvidence()查询凭证内容EvidenceService->>区块链节点: 调用智能合约,查询凭证存证内容区块链节点—>>EvidenceService: 返回查询结果opt 查询出错EvidenceService—>>调用者: 返回验证失败,报错并退出endEvidenceService->>EvidenceService: 生成凭证Hash,与链上凭证Hash对比是否一致opt Hash不一致EvidenceService—>>调用者: 返回验证失败,报错并退出endEvidenceService->>WeIdService: 根据存证中签名方信息,调用GetWeIdDocument()查询WeID公钥WeIdService->>区块链节点: 调用智能合约,查询WeID公钥区块链节点—>>WeIdService: 返回查询结果EvidenceService->>EvidenceService: 验证存证中签名是否为与凭证Hash一致opt 验签失败EvidenceService—>>调用者: 返回验证失败,报错并退出endEvidenceService—>>调用者: 返回验证成功