4. addSignature
基本信息
- 接口名称:com.webank.weid.rpc.EvidenceService.addSignature
- 接口定义:ResponseData<String> addSignature(Hashable object, String evidenceAddress, WeIdPrivateKey weIdPrivateKey)
- 接口描述: 对传入的Object及链上地址,加一个签名存入链上的存证。要求:传入的签名方必须隶属于在创建存证时传入多个签名方的WeID之一。
接口入参:
Hashable java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | Hashable object | Y | 实现了Hashable接口的任意Object | 当前支持Credential,CredentialWrapper,CredentialPojo |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
evidenceAddress | String | Y | 存证地址 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: 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 | 成功 |
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT | 500401 | Evidence参数非法 |
调用示例
- 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:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
- // 创建Credential
- ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
- List<String> signer = new ArrayList<>();
- signer.add("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- signer.add("did:weid:101:0x48f6f6f663ef77409144014ceb063713b65611f8");
- //创建Evidence Address
- ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(response.getResult().getCredential(), signer, weIdPrivateKey);
- String eviAddr = responseCreateEvidence.getResult();
- weIdPrivateKey.setPrivateKey("3171324536025850958917764441489874006048340539971987768716844")
- ResponseData<Boolean> resp = evidenceService.addSignature(response.getResult().getCredential, eviAddr, weIdPrivateKey);
- 返回结果如:
- result: true
- errorCode: 0
- errorMessage: success
- transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
- blockNumber: 30014
- transactionHash: 0x1f9e62fa152eb5fce859dcf81c7c0eddcbcab63c40629d1c745058c227693dae
- transactionIndex: 0
时序图
sequenceDiagramparticipant 调用者participant EvidenceServiceparticipant 区块链节点调用者->>EvidenceService: 调用addSignature()EvidenceService->>EvidenceService: 入参非空、格式及合法性检查opt 入参校验失败EvidenceService—>>调用者: 报错,提示参数不合法并退出endEvidenceService->>EvidenceService: 根据凭证Hash计算签名值EvidenceService->>区块链节点: 调用智能合约,上传签名值区块链节点—>>EvidenceService: 返回创建结果opt 创建失败EvidenceService—>>调用者: 报错并退出endEvidenceService—>>调用者: 返回成功