5. verify
基本信息
- 接口名称:com.webank.weid.rpc.EvidenceService.verify
- 接口定义:ResponseData<Boolean> verify(Hashable object, String evidenceAddress)
- 接口描述: 根据传入的Object计算存证Hash值和链上值对比,验证其是否遭到篡改。当存证包含多个签名时,将会依次验证每个签名,必须确实由签名者列表中的某个WeID所签发才算验证成功。
接口入参:
java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | Hashable object | Y | 实现了Hashable接口的任意Object | 当前支持Credential,CredentialWrapper,CredentialPojo |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
evidenceAddress | String | Y | 存证地址 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
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_EXPIRED | 100402 | 过期 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuer与签名不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | WeIdentity Document为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 验证签名异常 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
CREDENTIAL_EVIDENCE_SIGNATURE_BROKEN | 100431 | 存证签名异常 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
CREDENTIAL_EVIDENCE_HASH_MISMATCH | 100501 | Evidence Hash不匹配 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
- CredentialService credentialService = new CredentialServiceImpl();
- EvidenceService evidenceService = new EvidenceServiceImpl();
- HashMap<String, Object> claim = new HashMap<String, Object>(3);
- claim.put("name", "zhang san");
- claim.put("gender", "F");
- claim.put("age", 18);
- CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
- createCredentialArgs.setClaim(claim);
- createCredentialArgs.setCptId(1017);
- createCredentialArgs.setExpirationDate(1561448312461L);
- createCredentialArgs.setIssuer("did:weid:0x30404b47c6c5811d49e28ea2306c804d16618017");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
- //创建Credential
- ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
- Credential credential = response.getResult().getCredential();
- //创建Evidence Address
- ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(credential, weIdPrivateKey);
- String evidenceAddress = responseCreateEvidence.getResult();
- //验证Credential by evidenceAddress
- ResponseData<Boolean> responseVerify = evidenceService.verify(credential, evidenceAddress);
- 返回结果如:
- result: true
- errorCode: 0
- errorMessage: success
- 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—>>调用者: 返回验证成功