6. createPresentation
基本信息
- 接口名称:com.webank.weid.rpc.CredentialPojoService.createPresentation
- 接口定义: ResponseData<PresentationE> createPresentation(List<CredentialPojo> credentialList, PresentationPolicyE presentationPolicyE, Challenge challenge, WeIdAuthentication weIdAuthentication)
- 接口描述: 创建Presentation。
接口入参:
java.uitl.List<com.webank.weid.protocol.base.CredentialPojo>
com.webank.weid.protocol.base.CredentialPojo
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | ||
type | List<String> | Y | ||
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | issuer 的 WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
com.webank.weid.protocol.base.PresentationPolicyE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
id | Integer | Y | polcyId | 策略编号 |
orgId | String | Y | 机构编号 | |
version | Integer | Y | 版本 | |
policyPublisherWeId | String | Y | WeIdentity DID | 创建policy机构的WeIdentity DID |
policy | Map<Integer, ClaimPolicy> | Y | 策略配置 | key: CPTID, value: 披露策略对象 |
extra | Map<String, String> | N | 扩展字段 |
com.webank.weid.protocol.base.Challenge
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | N | WeIdentity DID | policy提供给指定的WeIdentity DID |
version | Integer | Y | 版本 | |
nonce | String | Y | 随机字符串 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的WeIdentity DID | WeIdentity DID的格式传入 |
weIdPublicKeyId | String | Y | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
接口返回: com.webank.weid.protocol.response.ResponseData<PresentationE>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | PresentationE | 创建的Presentation | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.PresentationE
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
context | List<String> | 上下文 | |
type | List<String> | Presentation Type | |
credentialList | List<CredentialPojo> | 凭证列表 | |
proof | Map<String, Object> | Presentation的签名信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 用户weId不匹配其私钥 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_CLAIM_DATA_ILLEGAL | 100411 | Claim数据无效 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_CLAIM_POLICY_NOT_EXIST | 100420 | 披露策略为null |
CREDENTIAL_POLICY_FORMAT_DOSE_NOT_MATCH_CLAIM | 100427 | 披露策略与Claim不匹配 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
PRESENTATION_CHALLENGE_INVALID | 100600 | challenge无效 |
PRESENTATION_CHALLENGE_WEID_MISMATCH | 100601 | challenge中的weId不匹配用户的weId |
PRESENTATION_POLICY_INVALID | 100602 | policy无效 |
PRESENTATION_CREDENTIALLIST_MISMATCH_CLAIM_POLICY | 100603 | credentialList不匹配Policy |
PRESENTATION_WEID_PUBLICKEY_ID_INVALID | 100604 | 公钥编号无效 |
PRESENTATION_POLICY_PUBLISHER_WEID_INVALID | 100609 | policy中的publisherWeId无效 |
PRESENTATION_POLICY_PUBLISHER_WEID_NOT_EXIST | 100610 | policy中的publisherWeId不存在 |
UNKNOW_ERROR | 160003 | 未知异常 |
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", "zhang san");
- claim.put("gender", "F");
- claim.put("age", 22);
- createCredentialPojoArgs.setClaim(claim);
- //创建CredentialPojo
- ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
- List<CredentialPojo> credentialList = new ArrayList<CredentialPojo>();
- credentialList.add(response.getResult());
- //创建Challenge
- Challenge challenge = Challenge.create("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", String.valueOf(System.currentTimeMillis()));
- //创建PresentationPolicyE
- String policyJson = "{\"extra\" : {\"extra1\" : \"\",\"extra2\" : \"\"},\"id\" : 123456,\"version\" : 1,\"orgId\" : \"webank\",\"weId\" : \"did:weid:0x0231765e19955fc65133ec8591d73e9136306cd0\",\"policy\" : {\"1017\" : {\"fieldsToBeDisclosed\" : {\"gender\" : 0,\"name\" : 1,\"age\" : 0}}}}";
- PresentationPolicyE presentationPolicyE = PresentationPolicyE.fromJson(policyJson);
- //创建Presentation
- ResponseData<PresentationE> presentationE = credentialPojoService.createPresentation(credentialList, presentationPolicyE, challenge, weIdAuthentication);
- 返回结果如:
- result:(com.webank.weid.protocol.base.PresentationE)
- context:(java.util.ArrayList)
- [0]:https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
- type:(java.util.ArrayList)
- [0]:VerifiablePresentation
- verifiableCredential:(java.util.ArrayList)
- [0]:com.webank.weid.protocol.base.CredentialPojo
- context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
- id: 67598cc5-a922-4e9f-ae0a-90c6285a8236
- cptId: 1017
- issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
- issuanceDate: 1560425696276
- expirationDate: 1560475761684
- claim:(java.util.HashMap)
- gender: 0x8dba4ce05ca123e0c48b877f461e1b8c362fcab9d03330dcb80d7d039081f50b
- name: zhangsan
- age: 0xdeb5a47d7ab03d9fefe2169cc59db146cec6f24005bcf0b2e2a0c95bfe7adde5
- proof:(java.util.HashMap)
- creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
- salt:(java.util.HashMap)
- gender: 0
- name: yjckg
- age: 0
- created: 1560425696276
- type: Secp256k1
- signatureValue: HCgmoX0f7ZYkwpd+pJ2+RCRKNt5lf9nbl8g9YWTSuA32IIoRSjMr7GPZVbe5bcu+hD/pnkAJbbinJo4/YqOOync=
- type:(java.util.ArrayList)
- [0]:VerifiableCredential
- proof:(java.util.HashMap)
- created: 1560425696412
- type: Secp256k1
- verificationMethod: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
- nonce: DJulONVxD2TFidB8vaYH
- signatureValue: G8ivS1e625NT8qSzLEugbqkRW6HDJNA4Lfcl7uCXV+uEffPMVF6Bwnk0pyCOd+4bbw90pMaj+EVxeL79acYPzM4=
- errorCode: 0
- errorMessage: success
- transactionInfo:null
时序图
sequenceDiagramparticipant 调用者participant CredentialPojoService调用者->>CredentialPojoService: 调用verify()CredentialPojoService->>CredentialPojoService: 入参非空、格式及合法性检查opt 入参校验失败CredentialPojoService—>>调用者: 报错,提示参数不合法并退出endloop 遍历credentialPojo列表CredentialPojoService->>CredentialPojoService: 根据credentialPojo中的cptId获取对应的claimPolicyopt claimPolicyCredentialPojoService—>>调用者: continueendCredentialPojoService->>CredentialPojoService: 根据claimPolicy,调用createSelectiveCredential()方法,做选择性披露opt 选择性披露失败CredentialPojoService—>>调用者: 失败退出endendCredentialPojoService->>CredentialPojoService: 设置context等元数据属性CredentialPojoService->>CredentialPojoService: 对presentation整体签名,放入proof结构,同时设置其他proof属性,用于验证CredentialPojoService—>>调用者: 返回成功