1. createCredential
基本信息
- 接口名称:com.webank.weid.rpc.CredentialPojoService.createCredential
- 接口定义:<T> ResponseData<CredentialPojo> createCredential(CreateCredentialPojoArgs<T> args)
- 接口描述: 根据传入的claim对象生成Credential。
接口入参:
com.webank.weid.protocol.request.CreateCredentialPojoArgs<T>
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
cptId | Integer | Y | CPT ID | |
issuer | String | Y | WeIdentity DID | |
expirationDate | Long | Y | 到期时间 | |
claim | T | Y | 创建凭证需要的claim数据,参数类型为泛型,为POJO对象(不同的CPT对应不同的POJO类)。 | 需要通过build-tool工具根据CPT ID生成对应的jar包, |
weIdAuthentication | WeIdAuthentication | Y | weId身份信息 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | WeIdentity DID的格式传入 |
weIdPublicKeyId | String | N | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<CredentialPojo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | CredentialPojo | 凭证对象 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CredentialPojo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
context | String | ||
type | List<String> | ||
id | String | 证书ID | |
cptId | Integer | cptId | |
issuer | String | issuer 的 WeIdentity DID | |
issuanceDate | Long | 创建日期 | |
expirationDate | Long | 到期日期 | |
claim | Map<String, Object> | Claim数据 | |
proof | Map<String, Object> | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥和weid不匹配 |
CREDENTIAL_ERROR | 100400 | credential处理未知异常 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期无效 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_CLAIM_DATA_ILLEGAL | 100411 | Claim非法 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
ILLEGAL_INPUT | 160004 | 参数非法 |
调用示例
- CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
- CreateCredentialPojoArgs<Map<String, Object>> createCredentialPojoArgs = new CreateCredentialPojoArgs<Map<String, Object>>();
- createCredentialPojoArgs.setCptId(1017);
- createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- createCredentialPojoArgs.setExpirationDate(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 100);
- WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
- weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
- weIdAuthentication.setWeIdPublicKeyId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0");
- createCredentialPojoArgs.setWeIdAuthentication(weIdAuthentication);
- Map<String, Object> claim = new HashMap<String, Object>();
- claim.put("name", "zhangsan");
- claim.put("gender", "F");
- claim.put("age", 22);
- createCredentialPojoArgs.setClaim(claim);
- ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
- 返回结果如:
- result:(com.webank.weid.protocol.base.CredentialPojo)
- context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
- id: 04a3e89d-825a-49fe-b8f5-8ccb9f487a52
- cptId: 1017
- issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
- issuanceDate: 1560420878712
- expirationDate: 1560470944120
- claim:(java.util.HashMap)
- gender: F
- name: zhangsan
- age: 22
- proof:(java.util.HashMap)
- creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
- salt:(java.util.HashMap)
- gender: ibu7f
- name: el1w8
- age: ajqkr
- created: 1560420878712
- type: Secp256k1
- signatureValue: G7UPiw08P5E9dEcSJEo9zpKu/nsUrpn00xDE+mwDXn9gJEohIlRUX5XTGQB4G1w3yThp6R/2RqjUYkuQTaUXbIU=
- type:(java.util.ArrayList)
- [0]:VerifiableCredential
- errorCode: 0
- errorMessage: success
- transactionInfo:null
时序图
sequenceDiagramparticipant 调用者participant CredentialPojoService调用者->>CredentialPojoService: 调用CreateCredential()CredentialPojoService->>CredentialPojoService: 入参非空、格式及合法性检查opt 入参校验失败CredentialPojoService—>>调用者: 报错,提示参数不合法并退出endCredentialPojoService->>CredentialPojoService: 为claim中的每个字段生成盐值CredentialPojoService->>CredentialPojoService: 生成签发日期、生成数字签名CredentialPojoService—>>调用者: 返回凭证