4. verify
基本信息
- 接口名称:com.webank.weid.rpc.CredentialPojoService.verify
- 接口定义: ResponseData<Boolean> verify(WeIdPublicKey issuerPublicKey, CredentialPojo credential)
- 接口描述: 使用指定公钥验证credentialWrapper。
接口入参:
com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 公钥 |
com.webank.weid.protocol.base.CredentialPojo
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | ||
type | List<String> | Y | ||
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | issuer 的 WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
接口返回: 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
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuerWeId跟Credential中的issuer不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名验证不通过 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_CLAIM_DATA_ILLEGAL | 100411 | Claim数据无效 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | 获取weIdDocument异常 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 签名验证异常 |
CREDENTIAL_PUBLIC_KEY_NOT_EXISTS | 100421 | 公钥不存在 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
CREDENTIAL_SALT_ILLEGAL | 100430 | 盐值非法 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
- 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", "zhangsan");
- claim.put("gender", "F");
- claim.put("age", 22);
- createCredentialPojoArgs.setClaim(claim);
- ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
- WeIdPublicKey weIdPublicKey = new WeIdPublicKey();
- weIdPublicKey.setPublicKey("9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875");
- ResponseData<Boolean> responseVerify = credentialPojoService.verify(weIdPublicKey, response.getResult());
- 返回结果如:
- result: true
- errorCode: 0
- errorMessage: success
- 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—>>调用者: 返回成功