6. createPresentation

基本信息

  1. 接口名称:com.webank.weid.rpc.CredentialPojoService.createPresentation
  2. 接口定义: ResponseData<PresentationE> createPresentation(List<CredentialPojo> credentialList, PresentationPolicyE presentationPolicyE, Challenge challenge, WeIdAuthentication weIdAuthentication)
  3. 接口描述: 创建Presentation

接口入参:

java.uitl.List<com.webank.weid.protocol.base.CredentialPojo>

com.webank.weid.protocol.base.CredentialPojo

名称类型非空说明备注
contextStringY
typeList<String>Y
idStringY证书ID
cptIdIntegerYcptId
issuerStringYissuer 的 WeIdentity DID
issuanceDateLongY创建日期
expirationDateLongY到期日期
claimMap<String, Object>YClaim数据
proofMap<String, Object>Y签名数据结构体

com.webank.weid.protocol.base.PresentationPolicyE

名称类型非空说明备注
idIntegerYpolcyId策略编号
orgIdStringY机构编号
versionIntegerY版本
policyPublisherWeIdStringYWeIdentity DID创建policy机构的WeIdentity DID
policyMap<Integer, ClaimPolicy>Y策略配置key: CPTID, value: 披露策略对象
extraMap<String, String>N扩展字段

com.webank.weid.protocol.base.Challenge

名称类型非空说明备注
weIdStringNWeIdentity DIDpolicy提供给指定的WeIdentity DID
versionIntegerY版本
nonceStringY随机字符串

com.webank.weid.protocol.base.WeIdAuthentication

名称类型非空说明备注
weIdStringYCPT发布者的WeIdentity DIDWeIdentity DID的格式传入
weIdPublicKeyIdStringY公钥Id
weIdPrivateKeyWeIdPrivateKeyY 交易私钥,见下

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

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultPresentationE创建的Presentation业务数据
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

com.webank.weid.protocol.base.PresentationE

名称类型说明备注
contextList<String>上下文
typeList<String>Presentation Type
credentialListList<CredentialPojo>凭证列表
proofMap<String, Object>Presentation的签名信息

此方法返回code

enumcodedesc
SUCCESS0成功
WEID_PRIVATEKEY_DOES_NOT_MATCH100106用户weId不匹配其私钥
CPT_ID_ILLEGAL100303cptId无效
CREDENTIAL_ERROR100400Credential标准错误
CREDENTIAL_SIGNATURE_BROKEN100405签名破坏
CREDENTIAL_CREATE_DATE_ILLEGAL100408创建日期格式非法
CREDENTIAL_EXPIRE_DATE_ILLEGAL100409到期日期格式非法
CREDENTIAL_CLAIM_NOT_EXISTS100410Claim数据不能为空
CREDENTIAL_CLAIM_DATA_ILLEGAL100411Claim数据无效
CREDENTIAL_ID_NOT_EXISTS100412ID为空
CREDENTIAL_CONTEXT_NOT_EXISTS100413context为空
CREDENTIAL_ISSUER_INVALID100418WeIdentity DID无效
CREDENTIAL_CLAIM_POLICY_NOT_EXIST100420披露策略为null
CREDENTIAL_POLICY_FORMAT_DOSE_NOT_MATCH_CLAIM100427披露策略与Claim不匹配
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL100429验证签名类型异常
PRESENTATION_CHALLENGE_INVALID100600challenge无效
PRESENTATION_CHALLENGE_WEID_MISMATCH100601challenge中的weId不匹配用户的weId
PRESENTATION_POLICY_INVALID100602policy无效
PRESENTATION_CREDENTIALLIST_MISMATCH_CLAIM_POLICY100603credentialList不匹配Policy
PRESENTATION_WEID_PUBLICKEY_ID_INVALID100604公钥编号无效
PRESENTATION_POLICY_PUBLISHER_WEID_INVALID100609policy中的publisherWeId无效
PRESENTATION_POLICY_PUBLISHER_WEID_NOT_EXIST100610policy中的publisherWeId不存在
UNKNOW_ERROR160003未知异常
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", "zhang san");
  19. claim.put("gender", "F");
  20. claim.put("age", 22);
  21. createCredentialPojoArgs.setClaim(claim);
  22.  
  23. //创建CredentialPojo
  24. ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
  25.  
  26. List<CredentialPojo> credentialList = new ArrayList<CredentialPojo>();
  27. credentialList.add(response.getResult());
  28.  
  29. //创建Challenge
  30. Challenge challenge = Challenge.create("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", String.valueOf(System.currentTimeMillis()));
  31.  
  32. //创建PresentationPolicyE
  33. String policyJson = "{\"extra\" : {\"extra1\" : \"\",\"extra2\" : \"\"},\"id\" : 123456,\"version\" : 1,\"orgId\" : \"webank\",\"weId\" : \"did:weid:0x0231765e19955fc65133ec8591d73e9136306cd0\",\"policy\" : {\"1017\" : {\"fieldsToBeDisclosed\" : {\"gender\" : 0,\"name\" : 1,\"age\" : 0}}}}";
  34. PresentationPolicyE presentationPolicyE = PresentationPolicyE.fromJson(policyJson);
  35.  
  36. //创建Presentation
  37. ResponseData<PresentationE> presentationE = credentialPojoService.createPresentation(credentialList, presentationPolicyE, challenge, weIdAuthentication);
  1. 返回结果如:
  2. result:(com.webank.weid.protocol.base.PresentationE)
  3. context:(java.util.ArrayList)
  4. [0]:https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
  5. type:(java.util.ArrayList)
  6. [0]:VerifiablePresentation
  7. verifiableCredential:(java.util.ArrayList)
  8. [0]:com.webank.weid.protocol.base.CredentialPojo
  9. context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
  10. id: 67598cc5-a922-4e9f-ae0a-90c6285a8236
  11. cptId: 1017
  12. issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
  13. issuanceDate: 1560425696276
  14. expirationDate: 1560475761684
  15. claim:(java.util.HashMap)
  16. gender: 0x8dba4ce05ca123e0c48b877f461e1b8c362fcab9d03330dcb80d7d039081f50b
  17. name: zhangsan
  18. age: 0xdeb5a47d7ab03d9fefe2169cc59db146cec6f24005bcf0b2e2a0c95bfe7adde5
  19. proof:(java.util.HashMap)
  20. creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
  21. salt:(java.util.HashMap)
  22. gender: 0
  23. name: yjckg
  24. age: 0
  25. created: 1560425696276
  26. type: Secp256k1
  27. signatureValue: HCgmoX0f7ZYkwpd+pJ2+RCRKNt5lf9nbl8g9YWTSuA32IIoRSjMr7GPZVbe5bcu+hD/pnkAJbbinJo4/YqOOync=
  28. type:(java.util.ArrayList)
  29. [0]:VerifiableCredential
  30. proof:(java.util.HashMap)
  31. created: 1560425696412
  32. type: Secp256k1
  33. verificationMethod: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
  34. nonce: DJulONVxD2TFidB8vaYH
  35. signatureValue: G8ivS1e625NT8qSzLEugbqkRW6HDJNA4Lfcl7uCXV+uEffPMVF6Bwnk0pyCOd+4bbw90pMaj+EVxeL79acYPzM4=
  36. errorCode: 0
  37. errorMessage: success
  38. 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—>>调用者: 返回成功