6. addSignature

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialService.addSignature
  2. 接口定义:ResponseData<Credential> addSignature(List<Credential> credentialList, WeIdPrivateKey weIdPrivateKey)
  3. 接口描述:多签,在原凭证列表的基础上,创建包裹成一个新的多签凭证,由传入的私钥所签名。此凭证的CPT为一个固定值。在验证一个多签凭证时,会迭代验证其包裹的所有子凭证。本接口不支持创建选择性披露的多签凭证。

接口入参: java.util.ArrayList

com.webank.weid.protocol.base.Credential

名称类型非空说明备注
contextStringY版本默认为v1
idStringY证书ID
cptIdIntegerYcptId
issuerStringYWeIdentity DID
issuanceDateLongY创建日期
expirationDateLongY到期日期
claimMap<String, Object>YClaim数据
proofMap<String, Object>Y签名数据结构体

com.webank.weid.protocol.base.WeIdPrivateKey

名称类型非空说明备注
privateKeyStringY私钥值使用十进制数字表示

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultCredential 见下
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

com.webank.weid.protocol.base.Credential

名称类型非空说明备注
contextStringY版本默认为v1
idStringY证书ID
cptIdIntegerYcptId默认为106
issuerStringYWeIdentity DID
issuanceDateLongY创建日期
expirationDateLongY到期日期
claimMap<String, Object>YClaim数据
proofMap<String, Object>Y签名数据结构体

此方法返回code

enumcodedesc
SUCCESS0成功
CPT_JSON_SCHEMA_INVALID100301JsonSchema无效
CPT_ID_ILLEGAL100303cptId无效
CREDENTIAL_ERROR100400Credential标准错误
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_EXPIRE_DATE_ILLEGAL100409到期日期无效
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_CLAIM_DATA_ILLEGAL100411Claim数据无效
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS100415私钥为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
ILLEGAL_INPUT160004参数为空

调用示例

  1. CredentialService credentialService = new CredentialServiceImpl();
  2.  
  3. HashMap<String, Object> claim = new HashMap<String, Object>(3);
  4. claim.put("name", "zhang san");
  5. claim.put("gender", "F");
  6. claim.put("age", 18);
  7.  
  8. CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
  9. createCredentialArgs.setClaim(claim);
  10. createCredentialArgs.setCptId(1017);
  11. createCredentialArgs.setExpirationDate(1551448312461L);
  12. createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  13.  
  14. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  15. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  16.  
  17. createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
  18.  
  19. ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
  20. List<Credential> credList = new ArrayList<>();
  21. credList.add(response.getResult().getCredential());
  22. Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
  23. createCredentialArgs.getExpirationDate() + 24 * 60 * 60);
  24. createCredentialArgs.setExpirationDate(expirationDate);
  25. Credential tempCredential =
  26. credentialService.createCredential(createCredentialArgs).getResult().getCredential();
  27. credentialList.add(tempCredential);
  28. ResponseData<Credential> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
  29. System.out.println(multiSignedResp);
  1. 返回结果如:
  2. result:(com.webank.weid.protocol.base.CredentialWrapper)
  3. credential:(com.webank.weid.protocol.base.Credential) {
  4. "claim": {
  5. "credentialList": [
  6. {
  7. "claim": {
  8. "age": 18,
  9. "gender": "F",
  10. "id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
  11. "name": "zhang san"
  12. },
  13. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  14. "cptId": 2000084,
  15. "expirationDate": 1567488114,
  16. "id": "a8b1c030-231d-49de-9618-b5ed7f3e6d2e",
  17. "issuanceDate": 1567401714,
  18. "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  19. "proof": {
  20. "created": "1567401714",
  21. "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  22. "signature": "GwKcDoEseYdJxI7M\/R4RAdGcV5SJoFVvg8Z53BVa76LMV8eqbX3F4rb1dWjhqI286AvPECx6uuuo9cTAKuNHRXM=",
  23. "type": "Secp256k1"
  24. }
  25. },
  26. {
  27. "claim": {
  28. "age": 18,
  29. "gender": "F",
  30. "id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
  31. "name": "zhang san"
  32. },
  33. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  34. "cptId": 2000084,
  35. "expirationDate": 1567488201,
  36. "id": "2130908d-fb2a-4675-8bf1-727f354ca8e4",
  37. "issuanceDate": 1567401715,
  38. "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  39. "proof": {
  40. "created": "1567401715",
  41. "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  42. "signature": "HJXDuvg2l8jRbL5ymmBSAo\/6DMKbCv3P1XoP67S+OVzSbRVDNFXY1CsqpTqT5MAkSY4+UwPLwCfXrLtHsZQ6GOo=",
  43. "type": "Secp256k1"
  44. }
  45. }
  46. ]
  47. },
  48. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  49. "cptId": 106,
  50. "expirationDate": 1567488201,
  51. "id": "d8642623-703f-447a-8765-dab1dab4df0a",
  52. "issuanceDate": 1567401717,
  53. "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  54. "proof": {
  55. "created": "1567401717",
  56. "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
  57. "signature": "HKXEwzDEwqte4aAUBLvQjiI3C0cw5V\/iWeKWmBs7HIG0IRzgbXnMj8kYw37y5yJE4KdsWCuehBUGuW7WdihL560=",
  58. "type": "Secp256k1"
  59. }
  60. }
  61. errorCode: 0
  62. errorMessage: success
  63. transactionInfo:null

时序图

sequenceDiagramparticipant 调用者participant CredentialService调用者->>CredentialService: 调用addSignature()CredentialService->>CredentialService: 入参非空、格式及合法性检查opt 入参校验失败CredentialService—>>调用者: 报错,提示参数不合法并退出endCredentialService->>CredentialService: 生成签发日期、以原凭证列表为Claim生成数字签名CredentialService—>>调用者: 返回凭证