5. verify

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialPojoService.verify
  2. 接口定义: ResponseData<Boolean> verify(String presenterWeId, PresentationPolicyE presentationPolicyE, Challenge challenge, PresentationE presentationE)
  3. 接口描述: 验证Presentation

接口入参:

java.lang.String

名称类型非空说明备注
presenterWeIdStringYWeIdentity DID用户的WeIdentity DID

com.webank.weid.protocol.base.PresentationPolicyE

名称类型非空说明备注
idIntegerYpolcyId策略编号
orgIdStringY机构编号
versionIntegerY版本
policyPublisherWeIdStringYWeIdentity DID创建policy机构的WeIdentity DID
policyMap<Integer, ClaimPolicy>Y策略配置key: CPTID, value: 披露策略对象
extraMap<String, String>N扩展字段

com.webank.weid.protocol.base.Challenge

名称类型非空说明备注
weIdStringNWeIdentity DIDpolicy提供给指定的WeIdentity DID
versionIntegerY版本
nonceStringY随机字符串

com.webank.weid.protocol.base.PresentationE

名称类型非空说明备注
contextList<String>Y上下文
typeList<String>YPresentation Type
credentialListList<CredentialPojo>Y凭证列表
proofMap<String, Object>YPresentation的签名信息

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

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

com.webank.weid.protocol.response.TransactionInfo

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

此方法返回code

调用示例

  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", "zhang san");
  19. claim.put("gender", "F");
  20. claim.put("age", 22);
  21. createCredentialPojoArgs.setClaim(claim);
  22.  
  23. //创建CredentialPojo
  24. ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
  25.  
  26. List<CredentialPojo> credentialList = new ArrayList<CredentialPojo>();
  27. credentialList.add(response.getResult());
  28.  
  29. //创建Challenge
  30. Challenge challenge = Challenge.create("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", String.valueOf(System.currentTimeMillis()));
  31.  
  32. //创建PresentationPolicyE
  33. String policyJson = "{\"extra\" : {\"extra1\" : \"\",\"extra2\" : \"\"},\"id\" : 123456,\"version\" : 1,\"orgId\" : \"webank\",\"weId\" : \"did:weid:0x0231765e19955fc65133ec8591d73e9136306cd0\",\"policy\" : {\"1017\" : {\"fieldsToBeDisclosed\" : {\"gender\" : 0,\"name\" : 1,\"age\" : 0}}}}";
  34. PresentationPolicyE presentationPolicyE = PresentationPolicyE.fromJson(policyJson);
  35.  
  36. //创建Presentation
  37. ResponseData<PresentationE> presentationERes = credentialPojoService.createPresentation(credentialList, presentationPolicyE, challenge, weIdAuthentication);
  38.  
  39. //验证Presentation
  40. ResponseData<Boolean> verifyRes = credentialPojoService.verify("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", presentationPolicyE, challenge, presentationERes.getResult());
  1. 返回结果如:
  2. result: true
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:null

时序图

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