1. createEvidence

基本信息

  1. 接口名称:com.webank.weid.rpc.EvidenceService.createEvidence
  2. 接口定义:ResponseData<String> createEvidence(Hashable object, WeIdPrivateKey weIdPrivateKey)
  3. 接口描述: 将传入Object计算Hash值生成存证上链,返回存证地址。传入的私钥将会成为链上存证的签名方。此签名方和凭证的Issuer可以不是同一方。当传入的objectnull时,则会创建一个空的存证并返回其地址,空存证中仅包含签名方,不含Hash值。可以随后调用SetHashValue()方法,为空存证添加Hash值和签名。

接口入参:

Hashable java.lang.Object

名称类型非空说明备注
ObjectHashable objectN实现了Hashable接口的任意Object当前支持Credential,CredentialWrapper,CredentialPojo

com.webank.weid.protocol.base.WeIdPrivateKey

名称类型说明备注
privateKeyString私钥使用十进制数字表示

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultString创建的凭证合约地址业务数据
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

此方法返回code

enumcodedesc
SUCCESS0成功
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS100415私钥为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_EVIDENCE_BASE_ERROR100500Evidence标准错误
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
ILLEGAL_INPUT160004参数为空
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT500401Evidence参数非法

调用示例

  1. CredentialService credentialService = new CredentialServiceImpl();
  2. EvidenceService evidenceService = new EvidenceServiceImpl();
  3.  
  4. HashMap<String, Object> claim = new HashMap<String, Object>(3);
  5. claim.put("name", "zhang san");
  6. claim.put("gender", "F");
  7. claim.put("age", 18);
  8.  
  9. CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
  10. createCredentialArgs.setClaim(claim);
  11. createCredentialArgs.setCptId(1017);
  12. createCredentialArgs.setExpirationDate(1561448312461L);
  13. createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  14.  
  15. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  16. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  17.  
  18. createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
  19.  
  20. // 创建Credential
  21. ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
  22.  
  23. //创建Evidence Address
  24. ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(response.getResult().getCredential(), weIdPrivateKey);
  1. 返回结果如:
  2. result: 0xa3203e054bb7a7f0dec134c7510299869e343e8d
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
  6. blockNumber: 30014
  7. transactionHash: 0x1f9e62fa152eb5fce859dcf81c7c0eddcbcab63c40629d1c745058c227693dae
  8. transactionIndex: 0

时序图

sequenceDiagramparticipant 调用者participant EvidenceServiceparticipant 区块链节点调用者->>EvidenceService: 调用CreateEvidence()EvidenceService->>EvidenceService: 入参非空、格式及合法性检查opt 入参校验失败EvidenceService—>>调用者: 报错,提示参数不合法并退出endEvidenceService->>EvidenceService: 生成凭证HashEvidenceService->>EvidenceService: 基于凭证Hash生成签名值EvidenceService->>区块链节点: 调用智能合约,创建并上传凭证存证区块链节点—>>EvidenceService: 返回创建结果opt 创建失败EvidenceService—>>调用者: 报错并退出endEvidenceService—>>调用者: 返回成功