8. addSignature

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialPojoService.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. CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
  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. CreateCredentialPojoArgs createCredentialPojoArgs = new CreateCredentialPojoArgs();
  9. createCredentialPojoArgs.setClaim(claim);
  10. createCredentialPojoArgs.setCptId(1017);
  11. createCredentialPojoArgs.setExpirationDate(1551448312461L);
  12. createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  13.  
  14. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  15. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  16.  
  17. createCredentialPojoArgs.setWeIdPrivateKey(weIdPrivateKey);
  18.  
  19. ResponseData<CredentialWrapper> response = credentialPojoService.createCredentialPojo(createCredentialArgs);
  20. List<CredentialPojo> credList = new ArrayList<>();
  21. credList.add(response.getResult().getCredentialPojo());
  22. Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
  23. createCredentialPojoArgs.getExpirationDate() + 24 * 60 * 60);
  24. createCredentialPojoArgs.setExpirationDate(expirationDate);
  25. CredentialPojo tempCredential =
  26. credentialPojoService.createCredentialPojo(createCredentialPojoArgs).getResult().getCredentialPojo();
  27. credentialList.add(tempCredential);
  28. ResponseData<CredentialPojo> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
  29. System.out.println(multiSignedResp);
  1. 返回结果如:
  2. result:(com.webank.weid.protocol.base.CredentialPojo)
  3. credentialPojo:(com.webank.weid.protocol.base.CredentialPojo) {
  4. {
  5. "claim": {
  6. "credentialList": [
  7. {
  8. "claim": {
  9. "age": 1,
  10. "gender": "F",
  11. "id": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
  12. "name": "1"
  13. },
  14. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  15. "cptId": 2000087,
  16. "expirationDate": 1567491752,
  17. "id": "6ea6e209-10e9-4a93-b6be-12af1a32655b",
  18. "issuanceDate": 1567405352,
  19. "issuer": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
  20. "proof": {
  21. "created": 1567405352,
  22. "creator": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33#keys-0",
  23. "salt": {
  24. "age": "yOwN7",
  25. "gender": "jjB85",
  26. "id": "BmRYI",
  27. "name": "BjYqF"
  28. },
  29. "signatureValue": "G+SNG3rBZNDvRNgRtJugPtX1FmE8XJIkV4CGPK\/nt\/breIPMJ5wYxImTp2QAxBUe5HMwCe9PPGhhMJJAazM5u9k=",
  30. "type": "Secp256k1"
  31. },
  32. "type": [
  33. "VerifiableCredential"
  34. ]
  35. },
  36. {
  37. "claim": {
  38. "age": 1,
  39. "gender": "F",
  40. "id": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
  41. "name": "1"
  42. },
  43. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  44. "cptId": 2000087,
  45. "expirationDate": 1567491842,
  46. "id": "a3544a9c-6cb6-4688-9622-bb935fb0d93f",
  47. "issuanceDate": 1567405355,
  48. "issuer": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
  49. "proof": {
  50. "created": 1567405355,
  51. "creator": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53#keys-0",
  52. "salt": {
  53. "age": "5nImi",
  54. "gender": "Me224",
  55. "id": "5pYs2",
  56. "name": "z6VmW"
  57. },
  58. "signatureValue": "HC8OAG\/dRmteGSIGWIDekp8fC1KJI8EEDZBb29HiTLXvVj350l9yTOHeGSBCr2VRY\/DSHT5ONjlvcrO4Mqa3Auo=",
  59. "type": "Secp256k1"
  60. },
  61. "type": [
  62. "VerifiableCredential"
  63. ]
  64. }
  65. ]
  66. },
  67. "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
  68. "cptId": 107,
  69. "expirationDate": 1567491842,
  70. "id": "ad5d5a54-4574-4b3b-b1df-9d0687b6a0ac",
  71. "issuanceDate": 1567405359,
  72. "issuer": "did:weid:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6",
  73. "proof": {
  74. "created": 1567405359,
  75. "creator": "did:weid:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6#keys-0",
  76. "salt": {
  77. "credentialList": "UuJHx"
  78. },
  79. "signatureValue": "HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=",
  80. "type": "Secp256k1"
  81. },
  82. "type": [
  83. "VerifiableCredential"
  84. ]
  85. }
  86. errorCode: 0
  87. errorMessage: success
  88. transactionInfo:null

时序图

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