5. getCredentialHash
基本信息
- 接口名称:com.webank.weid.rpc.CredentialService.getCredentialHash
- 接口定义:ResponseData<String> getCredentialHash(CredentialWrapper args)
- 接口描述: 传入Credential信息生成Credential整体的Hash值,一般在生成Evidence时调用。
接口入参: com.webank.weid.protocol.base.CredentialWrapper
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
credential | Credential | Y | 凭证信息 | 具体见下 |
disclosure | Map<String, Object> | Y | 披露属性 | 默认为全披露 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | 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<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 返回结果值 | |
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_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_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
- CredentialService credentialService = new CredentialServiceImpl();
- 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:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
- //创建CredentialWrapper
- ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
- //获取CredentialWrapper的Hash
- ResponseData<String> responseHash = credentialService.getCredentialHash(response.getResult());
- 返回结果如:
- result: 0x06173e4b714d57565ae5ddf23c4e84cb0a9824cb72eab476303d2dd1cc0a4728
- errorCode: 0
- errorMessage: success
- transactionInfo:null
时序图
sequenceDiagramparticipant 调用者participant CredentialService调用者->>CredentialService: 调用GetCredentialHash()CredentialService->>CredentialService: 入参非空、格式及合法性检查opt 入参校验失败CredentialService—>>调用者: 报错,提示参数不合法并退出endCredentialService->>CredentialService: 生成凭证HashCredentialService—>>调用者: 返回凭证Hash