2. registerCpt

基本信息

  1. 接口名称: com.webank.weid.rpc.CptService.registerCpt
  2. 接口定义: ResponseData<CptBaseInfo> registerCpt(CptMapArgs args, Integer cptId)
  3. 接口描述: 传入WeIdentity DIDJsonSchema(Map类型), cptId 和其对应的私钥,链上注册指定cptIdCPT,返回CPT编号和版本。

接口入参:

名称类型非空说明备注
argsCptMapArgsYMap类型参数注册CPT
cptIdIntegerY指定的cptId

com.webank.weid.protocol.request.CptMapArgs

名称类型非空说明备注
weIdAuthenticationWeIdAuthenticationY认证信息,包含WeIdentity DID和私钥用于WeIdentity DID的身份认证
cptJsonSchemaMap<String, Object>YMap类型的JsonSchema信息基本使用见调用示例

com.webank.weid.protocol.base.WeIdAuthentication

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

com.webank.weid.protocol.base.WeIdPrivateKey

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

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

名称类型说明备注
errorCodeInteger返回结果码此接口返回的code
errorMessageString返回结果描述
resultCptBaseInfo CPT基础数据,见下
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

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

com.webank.weid.protocol.base.CptBaseInfo

名称类型说明备注
cptIdIntegercpId编号
cptVersionInteger版本号

此方法返回code

enumcodedesc
SUCCESS0成功
WEID_INVALID100101WeIdentity DID无效
WEID_PRIVATEKEY_INVALID100103私钥无效
WEID_PRIVATEKEY_DOES_NOT_MATCH100106私钥与WeIdentity DID不匹配
WEID_AUTHORITY_INVALID100109授权信息无效
CPT_JSON_SCHEMA_INVALID100301schema无效
CPT_EVENT_LOG_NULL100304交易日志异常
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
UNKNOW_ERROR160003未知异常
ILLEGAL_INPUT160004参数为空
CPT_NOT_EXISTS500301CPT不存在
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX500302为权威机构生成的cptId超过上限
CPT_PUBLISHER_NOT_EXIST500303CPT发布者的WeIdentity DID不存在
CPT_ALREADY_EXIST500304CPT已经存在
CPT_NO_PERMISSION500305CPT无权限

调用示例

  1. CptService cptService = new CptServiceImpl();
  2.  
  3. HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
  4. cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
  5. cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
  6.  
  7. HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
  8. propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
  9. propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
  10.  
  11. String[] genderEnum = { "F", "M" };
  12. HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
  13. propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
  14. propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
  15.  
  16. HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
  17. propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
  18. propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
  19.  
  20. HashMap<String, Object> propertitesMap4 = new HashMap<String, Object>(2);
  21. propertitesMap4.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
  22. propertitesMap4.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is id");
  23.  
  24. HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
  25. cptJsonSchemaKeys.put("name", propertitesMap1);
  26. cptJsonSchemaKeys.put("gender", propertitesMap2);
  27. cptJsonSchemaKeys.put("age", propertitesMap3);
  28. cptJsonSchemaKeys.put("id", propertitesMap4);
  29. cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
  30.  
  31. String[] genderRequired = { "id", "name", "gender" };
  32. cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
  33.  
  34. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  35. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  36.  
  37. WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
  38. weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  39. weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
  40.  
  41. CptMapArgs cptMapArgs = new CptMapArgs();
  42. cptMapArgs.setCptJsonSchema(cptJsonSchema);
  43. cptMapArgs.setWeIdAuthentication(weIdAuthentication);
  44.  
  45. ResponseData<CptBaseInfo> response = cptService.registerCpt(cptMapArgs, 101);
  1. 返回数据如下:
  2. result:(com.webank.weid.protocol.base.CptBaseInfo)
  3. cptId: 101
  4. cptVersion: 1
  5. errorCode: 0
  6. errorMessage: success
  7. transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
  8. blockNumber: 29950
  9. transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
  10. transactionIndex: 0