5. verify
基本信息
- 接口名称:com.webank.weid.rpc.CredentialPojoService.verify
- 接口定义: ResponseData<Boolean> verify(String presenterWeId, PresentationPolicyE presentationPolicyE, Challenge challenge, PresentationE presentationE)
- 接口描述: 验证Presentation。
接口入参:
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
presenterWeId | String | Y | WeIdentity DID | 用户的WeIdentity DID |
com.webank.weid.protocol.base.PresentationPolicyE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
id | Integer | Y | polcyId | 策略编号 |
orgId | String | Y | 机构编号 | |
version | Integer | Y | 版本 | |
policyPublisherWeId | String | Y | WeIdentity DID | 创建policy机构的WeIdentity DID |
policy | Map<Integer, ClaimPolicy> | Y | 策略配置 | key: CPTID, value: 披露策略对象 |
extra | Map<String, String> | N | 扩展字段 |
com.webank.weid.protocol.base.Challenge
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | N | WeIdentity DID | policy提供给指定的WeIdentity DID |
version | Integer | Y | 版本 | |
nonce | String | Y | 随机字符串 |
com.webank.weid.protocol.base.PresentationE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | List<String> | Y | 上下文 | |
type | List<String> | Y | Presentation Type | |
credentialList | List<CredentialPojo> | Y | 凭证列表 | |
proof | Map<String, Object> | Y | Presentation的签名信息 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
调用示例
- CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
- CreateCredentialPojoArgs<Map<String, Object>> createCredentialPojoArgs = new CreateCredentialPojoArgs<Map<String, Object>>();
- createCredentialPojoArgs.setCptId(1017);
- createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- createCredentialPojoArgs.setExpirationDate(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 100);
- WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
- weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
- weIdAuthentication.setWeIdPublicKeyId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0");
- createCredentialPojoArgs.setWeIdAuthentication(weIdAuthentication);
- Map<String, Object> claim = new HashMap<String, Object>();
- claim.put("name", "zhang san");
- claim.put("gender", "F");
- claim.put("age", 22);
- createCredentialPojoArgs.setClaim(claim);
- //创建CredentialPojo
- ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
- List<CredentialPojo> credentialList = new ArrayList<CredentialPojo>();
- credentialList.add(response.getResult());
- //创建Challenge
- Challenge challenge = Challenge.create("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", String.valueOf(System.currentTimeMillis()));
- //创建PresentationPolicyE
- String policyJson = "{\"extra\" : {\"extra1\" : \"\",\"extra2\" : \"\"},\"id\" : 123456,\"version\" : 1,\"orgId\" : \"webank\",\"weId\" : \"did:weid:0x0231765e19955fc65133ec8591d73e9136306cd0\",\"policy\" : {\"1017\" : {\"fieldsToBeDisclosed\" : {\"gender\" : 0,\"name\" : 1,\"age\" : 0}}}}";
- PresentationPolicyE presentationPolicyE = PresentationPolicyE.fromJson(policyJson);
- //创建Presentation
- ResponseData<PresentationE> presentationERes = credentialPojoService.createPresentation(credentialList, presentationPolicyE, challenge, weIdAuthentication);
- //验证Presentation
- ResponseData<Boolean> verifyRes = credentialPojoService.verify("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", presentationPolicyE, challenge, presentationERes.getResult());
- 返回结果如:
- result: true
- errorCode: 0
- errorMessage: success
- 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—>>调用者: 返回成功