4. addSignature

基本信息

  1. 接口名称:com.webank.weid.rpc.EvidenceService.addSignature
  2. 接口定义:ResponseData<String> addSignature(Hashable object, String evidenceAddress, WeIdPrivateKey weIdPrivateKey)
  3. 接口描述: 对传入的Object及链上地址,加一个签名存入链上的存证。要求:传入的签名方必须隶属于在创建存证时传入多个签名方的WeID之一。

接口入参:

Hashable java.lang.Object

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

java.lang.String

名称类型非空说明备注
evidenceAddressStringY存证地址

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. createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
  18.  
  19. // 创建Credential
  20. ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
  21.  
  22. List<String> signer = new ArrayList<>();
  23. signer.add("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  24. signer.add("did:weid:101:0x48f6f6f663ef77409144014ceb063713b65611f8");
  25.  
  26. //创建Evidence Address
  27. ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(response.getResult().getCredential(), signer, weIdPrivateKey);
  28.  
  29. String eviAddr = responseCreateEvidence.getResult();
  30. weIdPrivateKey.setPrivateKey("3171324536025850958917764441489874006048340539971987768716844")
  31. ResponseData<Boolean> resp = evidenceService.addSignature(response.getResult().getCredential, eviAddr, weIdPrivateKey);
  1. 返回结果如:
  2. result: true
  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: 调用addSignature()EvidenceService->>EvidenceService: 入参非空、格式及合法性检查opt 入参校验失败EvidenceService—>>调用者: 报错,提示参数不合法并退出endEvidenceService->>EvidenceService: 根据凭证Hash计算签名值EvidenceService->>区块链节点: 调用智能合约,上传签名值区块链节点—>>EvidenceService: 返回创建结果opt 创建失败EvidenceService—>>调用者: 报错并退出endEvidenceService—>>调用者: 返回成功