2. verify

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialService.verify
  2. 接口定义:ResponseData<Boolean> verify(Credential credential);
  3. 接口描述: 验证凭证是否正确。

接口入参: com.webank.weid.protocol.base.Credential

名称类型非空说明备注
contextStringY版本默认为v1
idStringY证书ID
cptIdIntegerYcptId
issuerStringYWeIdentity 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_ERROR100400Credential标准错误
CREDENTIAL_EXPIRED100402过期
CREDENTIAL_ISSUER_MISMATCH100403issuer与签名不匹配
CREDENTIAL_SIGNATURE_BROKEN100405签名破坏
CREDENTIAL_ISSUER_NOT_EXISTS100407WeIdentity DID不能为空
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_EXPIRE_DATE_ILLEGAL100409到期日期格式非法
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_ID_NOT_EXISTS100412ID为空
CREDENTIAL_CONTEXT_NOT_EXISTS100413context为空
CREDENTIAL_CPT_NOT_EXISTS100416cpt不存在
CREDENTIAL_WEID_DOCUMENT_ILLEGAL100417WeIdentity Document为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE100419验证签名异常
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL100429验证签名类型异常
ILLEGAL_INPUT160004参数为空

调用示例

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

时序图

(同时也包含verifyCredentialWithSpecifiedPubKey时序)

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