1. createCredential

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialPojoService.createCredential
  2. 接口定义:<T> ResponseData<CredentialPojo> createCredential(CreateCredentialPojoArgs<T> args)
  3. 接口描述: 根据传入的claim对象生成Credential

接口入参:

com.webank.weid.protocol.request.CreateCredentialPojoArgs<T>

名称类型非空说明备注
cptIdIntegerYCPT ID
issuerStringYWeIdentity DID
expirationDateLongY到期时间
claimTY创建凭证需要的claim数据,参数类型为泛型,为POJO对象(不同的CPT对应不同的POJO类)。需要通过build-tool工具根据CPT ID生成对应的jar包,
weIdAuthenticationWeIdAuthenticationYweId身份信息

com.webank.weid.protocol.base.WeIdAuthentication

名称类型非空说明备注
weIdStringYWeIdentity DIDWeIdentity DID的格式传入
weIdPublicKeyIdStringN公钥Id
weIdPrivateKeyWeIdPrivateKeyY 交易私钥,见下

com.webank.weid.protocol.base.WeIdPrivateKey

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

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultCredentialPojo凭证对象业务数据
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

com.webank.weid.protocol.base.CredentialPojo

名称类型说明备注
contextString
typeList<String>
idString证书ID
cptIdIntegercptId
issuerStringissuer 的 WeIdentity DID
issuanceDateLong创建日期
expirationDateLong到期日期
claimMap<String, Object>Claim数据
proofMap<String, Object>签名数据结构体

此方法返回code

enumcodedesc
SUCCESS0成功
CPT_ID_ILLEGAL100303cptId无效
WEID_PRIVATEKEY_DOES_NOT_MATCH100106私钥和weid不匹配
CREDENTIAL_ERROR100400credential处理未知异常
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_EXPIRE_DATE_ILLEGAL100409到期日期无效
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_CLAIM_DATA_ILLEGAL100411Claim非法
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
ILLEGAL_INPUT160004参数非法

调用示例

  1. CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
  2. CreateCredentialPojoArgs<Map<String, Object>> createCredentialPojoArgs = new CreateCredentialPojoArgs<Map<String, Object>>();
  3. createCredentialPojoArgs.setCptId(1017);
  4. createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  5. createCredentialPojoArgs.setExpirationDate(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 100);
  6.  
  7. WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
  8. weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  9.  
  10. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  11. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  12. weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
  13.  
  14. weIdAuthentication.setWeIdPublicKeyId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0");
  15. createCredentialPojoArgs.setWeIdAuthentication(weIdAuthentication);
  16.  
  17. Map<String, Object> claim = new HashMap<String, Object>();
  18. claim.put("name", "zhangsan");
  19. claim.put("gender", "F");
  20. claim.put("age", 22);
  21. createCredentialPojoArgs.setClaim(claim);
  22.  
  23. ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
  1. 返回结果如:
  2. result:(com.webank.weid.protocol.base.CredentialPojo)
  3. context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
  4. id: 04a3e89d-825a-49fe-b8f5-8ccb9f487a52
  5. cptId: 1017
  6. issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
  7. issuanceDate: 1560420878712
  8. expirationDate: 1560470944120
  9. claim:(java.util.HashMap)
  10. gender: F
  11. name: zhangsan
  12. age: 22
  13. proof:(java.util.HashMap)
  14. creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
  15. salt:(java.util.HashMap)
  16. gender: ibu7f
  17. name: el1w8
  18. age: ajqkr
  19. created: 1560420878712
  20. type: Secp256k1
  21. signatureValue: G7UPiw08P5E9dEcSJEo9zpKu/nsUrpn00xDE+mwDXn9gJEohIlRUX5XTGQB4G1w3yThp6R/2RqjUYkuQTaUXbIU=
  22. type:(java.util.ArrayList)
  23. [0]:VerifiableCredential
  24. errorCode: 0
  25. errorMessage: success
  26. transactionInfo:null

时序图

sequenceDiagramparticipant 调用者participant CredentialPojoService调用者->>CredentialPojoService: 调用CreateCredential()CredentialPojoService->>CredentialPojoService: 入参非空、格式及合法性检查opt 入参校验失败CredentialPojoService—>>调用者: 报错,提示参数不合法并退出endCredentialPojoService->>CredentialPojoService: 为claim中的每个字段生成盐值CredentialPojoService->>CredentialPojoService: 生成签发日期、生成数字签名CredentialPojoService—>>调用者: 返回凭证