WeIdentity JAVA SDK文档¶
总体介绍¶
WeIdentity Java SDK提供了一整套对WeIdentity进行管理操作的Java库。目前,SDK支持本地密钥管理、数字身份标识(WeIdentity DID)管理、电子凭证(WeIdentity Credential)管理、授权机构(Authority Issuer)管理、CPT(Claim Protocol Type)管理、存证(Evidence)管理等功能,未来还将支持更丰富的功能和应用。
部署SDK¶
- WeIdentity JAVA SDK 安装部署文档
- 开始使用之前,再次确认启动FISCO-BCOS节点已启动,确保端口可以访问。
整体过程快速上手¶
按照以下流程可以完整地体验本SDK的核心功能:
- 注册DID:通过WeIdService的createWeId()生成一个WeIdentity DID并注册到链上;
- 设置DID属性:分别调用WeIdService的set方法组,为此DID设置公钥、认证方式、服务端点等属性;
- 查询DID属性:调用WeIdService的getWeIdDocumentJson()查阅生成的WeIdentity DID数据;
- 注册授权机构:通过AuthorityIssuerService的registerAuthorityIssuer()把生成的WeIdentity DID注册成一个授权机构;
- 查询授权机构:调用AuthorityIssuerService的queryAuthorityIssuerInfo()查阅生成的授权机构数据;
- 注册CPT:通过CptService的registerCpt(),通过之前生成的WeIdentity DID身份创建一个你喜欢的CPT模板;
- 查询CPT:调用CptService的queryCpt()查阅生成的CPT模板;
- 生成凭证:通过CredentialPojoService的createCredential(),根据CPT模板,生成一份Credential;
- 查询凭证:调用CredentialPojoService的verify(),验证此Credential是否合法;
- 凭证存证上链:调用EvidenceService的createEvidence(),将之前生成的Credential传入,createEvidence会将传入的Credential哈希得到的Hash值存证上链;
- 验证链上凭证存证:调用EvidenceService的verifySigner(),和链上对比,验证Credential是否被篡改。
代码结构说明¶
├─ app:测试小工具
├─ config:FISCO-BCOS的合约配置
├─ constant:系统常量相关
└─ contract:通过WeIdentity-Blockchain模块部署合约
└─ deploy: 合约部署相关
├─ exception: 异常定义
└─ protocol:接口参数相关定义
├─ base: 基础数据类型定义
├─ request: 接口入参定义
└─ response: 接口出参定义
└─ service:SDK提供的接口
├─ rpc:接口定义
├─ console:完全无依赖的接口实现
├─ local:基于数据库的接口实现
└─impl:基于区块链的接口实现
└─ suite:一些配套的工具
├─ cache:自定义缓存
└─persistence:存储接口
└─ util:工具类实现
基本数据结构¶
WeIdDocument¶
属性
com.webank.weid.protocol.base.WeIdDocumentMetadata
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | WeIdentity DID | |
created | Long | 创建时间 | |
updated | Long | 更新时间 | |
authentication | List |
认证方集合,见下 | |
service | List |
服务端点集合,见下 |
com.webank.weid.protocol.base.AuthenticationProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | verification method id |
type | String | 类型 | 默认为:Ed25519VerificationKey2020 |
controller | String | 方法拥有人 | verification method controller |
publicKeyMultibase | String | 验证公钥 | 使用base58编码的公钥 |
com.webank.weid.protocol.base.ServiceProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | |
type | String | 类型 | |
serviceEndpoint | String | 联系/服务方式 | 邮箱、github个人主页等 |
方法
1. toJson¶
基本信息
接口名称:com.webank.weid.protocol.base.WeIdDocument.toJson()
接口定义:String toJson()
接口描述: 将WeIdDocument转换成json格式的字符串。
注意:此方法转换出错会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
2. fromJson¶
基本信息
接口名称:com.webank.weid.protocol.base.WeIdDocument.fromJson(String weIdDocumentJson)
接口定义:WeIdDocument fromJson(String weIdDocumentJson)
接口描述: 将json格式的WeIdDocument转换成WeIdDocument对象。
注意:调用fromJson(String weIdDocumentJson)的入参,必须是通过调用toJson()得到的json格式的WeIdDocument字符串,否则会抛异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
Challenge¶
属性
com.webank.weid.protocol.base.Challenge
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | N | WeIdentity DID | policy提供给指定的WeIdentity DID |
version | Integer | Y | 版本 | |
nonce | String | Y | 随机字符串 |
方法
1. toJson¶
基本信息
接口名称:com.webank.weid.protocol.base.Challenge.toJson()
接口定义:String toJson()
接口描述: 将Challenge转换成json格式的字符串。
注意:此方法转换出错会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
2. fromJson¶
基本信息
接口名称:com.webank.weid.protocol.base.Challenge.fromJson(String challengeJson)
接口定义:Challenge fromJson(String challengeJson)
接口描述: 将json格式的Challenge转换成Challenge对象。
注意:调用fromJson(String challengeJson)的入参,必须是通过调用toJson()得到的json格式的Challenge字符串,否则会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
CredentialPojo¶
属性
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> | 签名数据结构体 |
方法
1. toJson¶
基本信息
接口名称:com.webank.weid.protocol.base.CredentialPojo.toJson()
接口定义:String toJson()
接口描述: 将CredentialPojo转换成json格式的字符串。
注意:此方法转换出错会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
2. fromJson¶
基本信息
接口名称:com.webank.weid.protocol.base.CredentialPojo.fromJson(String credentialPojoJson)
接口定义:CredentialPojo fromJson(String credentialPojoJson)
接口描述: 将json格式的CredentialPojo转换成CredentialPojo对象。
注意:调用fromJson(String credentialPojoJson)的入参,必须是通过调用toJson()得到的json格式的CredentialPojo字符串,否则会抛异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
PresentationPolicyE¶
属性
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 | 扩展字段 |
方法
1. toJson¶
基本信息
接口名称:com.webank.weid.protocol.base.PresentationPolicyE.toJson()
接口定义:String toJson()
接口描述: 将PresentationPolicyE转换成json格式的字符串。
注意:此方法转换出错会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
2. fromJson¶
基本信息
接口名称:com.webank.weid.protocol.base.PresentationPolicyE.fromJson(String presentationPolicyEJson)
接口定义:PresentationPolicyE fromJson(String presentationPolicyEJson)
接口描述: 将json格式的PresentationPolicyE转换成PresentationPolicyE对象。
注意:调用fromJson(String presentationPolicyEJson)的入参,必须是通过调用toJson()得到的json格式的PresentationPolicyE字符串,否则会抛异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
PresentationE¶
属性
com.webank.weid.protocol.base.PresentationE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | List<String> | Y | 上下文 | |
type | List<String> | Y | Presentation Type | |
credentialList | List<CredentialPojo> | Y | 凭证列表 | |
proof | Map<String, Object> | Y | Presentation的签名信息 |
方法
1. toJson¶
基本信息
接口名称:com.webank.weid.protocol.base.PresentationE.toJson()
接口定义:String toJson()
接口描述: 将PresentationE转换成json格式的字符串。
注意:此方法转换出错会抛DATA_TYPE_CASE_ERROR异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
2. fromJson¶
基本信息
接口名称:com.webank.weid.protocol.base.PresentationE.fromJson(String presentationEJson)
接口定义:PresentationE fromJson(String challengeJson)
接口描述: 将json格式的PresentationE转换成PresentationE对象。
注意:调用fromJson(String presentationEJson)的入参,必须是通过调用toJson()得到的json格式的PresentationE字符串,否则会抛异常 。
此方法返回code
enum | code | desc |
---|---|---|
DATA_TYPE_CASE_ERROR | 160008 | 数据转换异常 |
调用示例
3. push¶
基本信息
接口名称: com.webank.weid.protocol.base.PresentationE.push
接口定义: boolean push(CredentialPojo credentialPojo)
接口描述: 将非policy里面的Credential添加到Presentation中
注意:调用 push(CredentialPojo credentialPojo) 添加完所有Credential后需要调用 commit(WeIdAuthentication weIdAuthentication) 进行重新签名,否则验证Presentation时会失败
调用示例
4. commit¶
基本信息
接口名称: com.webank.weid.protocol.base.PresentationE.commit
接口定义: boolean commit(WeIdAuthentication weIdAuthentication)
接口描述: 添加完Credential对Presentation重新签名处理了
调用示例
接口简介¶
WeIdentity Java SDK提供了多种类型的接口实现,包括依赖区块链或数据库的完整接口和没有任何依赖的简化接口,以满足用户的不同需求。 如果需要使用区块链或者数据库存储WeIdDocument和CPT等相关信息,以及需要权限管理和控制功能,可以使用完整接口实现;如果只需要纯功能接口,比如生成WeIdDocument、CPT和验证Credentials等功能,可以使用简化的接口实现。 完整接口实现包括五个主要的接口,它们分别是:WeIdService、AuthorityIssuerService、CptService、PolicyService、CredentialService / CredentialPojoService、EvidenceService。
- WeIdService
WeIdentity DID相关功能的核心接口。
本接口提供WeIdentity DID的创建、获取信息、设置属性等相关操作。
- AuthorityIssuerService
在WeIdentity的整体架构中,存在着可信的“授权机构”这一角色。一般来说,授权机构特指那些广为人知的、具有一定公信力的、并且有相对频繁签发Credential需求的实体。
本接口提供了对这类授权签发Credential的机构的注册、移除、查询信息等操作。
- CptService
任何凭证的签发,都需要将数据转换成已经注册的CPT (Claim Protocol Type)格式规范,也就是所谓的“标准化格式化数据”。相关机构事先需要注册好CPT,在此之后,签发机构会根据CPT提供符合格式的数据,进而进行凭证的签发。
本接口提供了对CPT的注册、更新、查询等操作。
- PolicyService
策略(Policy)包含申明(Claim)策略和表述(Presentation)策略。WeIdentity采用基于哈希连接的方式对Credential做简单的选择性披露,验证方可以构建一种策略(Policy),描述Credential中哪些内容需要披露,哪些内容允许保密,策略的结构体和对应的CPT一致。
本接口提供了对策略Policy的注册、查询等操作。
- CredentialService / CredentialPojoService
凭证签发相关功能的核心接口。
本接口提供凭证的签发和验证操作、Verifiable Presentation的签发和验证操作。
- EvidenceService
凭证存证上链的相关接口。
本接口提供凭证的Hash存证的生成上链、链上查询及校验等操作。
纯功能的简化接口实现抽取了以上完整接口实现的主要接口,归总到两个接口文件:WeIdServiceConsole和CredentialServiceConsole。
- WeIdServiceConsole
提供WeIdDocument生成、CPT生成和保存(文件)、策略(Policy)生成和保存(文件)等操作。
- CredentialServiceConsole
提供Credential生成和验证等操作。
完整接口列表(依赖区块链或数据库)¶
WeIdService¶
1. createWeId¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.createWeId
接口定义:ResponseData<CreateWeIdDataResult> createWeId()
接口描述: 内部创建公私钥,并注册WeIdentity DID, 并返回公钥、私钥以及WeIdentity DID。
接口入参: 无
接口返回: com.webank.weid.protocol.response.ResponseData<CreateWeIdDataResult>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | CreateWeIdDataResult | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.response.CreateWeIdDataResult
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
weId | String | 公钥WeIdentity DID格式字符串 | 格式: did:weid:1000:0x…………………. |
userWeIdPublicKey | WeIdPublicKey | ||
userWeIdPrivateKey | WeIdPrivateKey |
com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
publicKey | String | 数字公钥 | 如下调用示例返回,使用十进制数字表示 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 如下调用示例返回,使用十进制数字表示 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_KEYPAIR_CREATE_FAILED | 100107 | 创建密钥对失败 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥和weid不匹配 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<CreateWeIdDataResult> response = weIdService.createWeId();
输出结果如下:
result:(com.webank.weid.protocol.response.CreateWeIdDataResult)
weId: did:weid:101:0xf4e5f96de0627960c8b91c1cc126f7b5cdeacbd0
userWeIdPublicKey:(com.webank.weid.protocol.base.WeIdPublicKey)
publicKey: 3140516665390655972698269231665028730625296545812754612198268107926656717368563044260511639762256438305037318801307432426840176526241566631412406151716674
userWeIdPrivateKey:(com.webank.weid.protocol.base.WeIdPrivateKey)
privateKey: 70694712486452850283637015242845250545254342779640874305734061338958342229003
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30005
transactionHash: 0x7e4fcacdd296f10936e53d64c7d6470dd4ffa52e22405c86ed8f72389419821f
transactionIndex: 0
时序图
2. createWeId¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.createWeId
接口定义:ResponseData<String> createWeId(CreateWeIdArgs createWeIdArgs)
接口描述: 根据传入的公私钥,注册WeIdentity DID,并返回WeIdentity DID。
接口入参: com.webank.weid.protocol.request.CreateWeIdArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 数字公钥 | |
weIdPrivateKey | WeIdPrivateKey | Y | 后期鉴权使用 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 公钥WeIdentity DID格式字符串 | 如:did:weid:1000:0x…………………. |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_PUBLICKEY_INVALID | 100102 | 公钥无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_ALREADY_EXIST | 100105 | WeIdentity DID已存在 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
WEID_PUBLICKEY_AND_PRIVATEKEY_NOT_MATCHED | 100108 | 公私钥不成对 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
CreateWeIdArgs createWeIdArgs = new CreateWeIdArgs();
createWeIdArgs.setPublicKey(
"2905679808560626772263712571437125497429146398815877180317365034921958007199576809718056336050058032599743534507469742764670961100255274766148096681073592");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("7581560237967740187496354914151086729152742173850631851769274217992481997665");
createWeIdArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<String> response = weIdService.createWeId(createWeIdArgs);
输出结果如下:
result: did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30007
transactionHash: 0x7f9e0fe2bcb0e77bad9aa5c38f8440e71a48dc29406d9ad43e12130afd211c67
transactionIndex: 0
时序图
3. createWeIdByPublicKey¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.createWeIdByPublicKey
接口定义:ResponseData<String> createWeIdByPublicKey(WeIdPublicKey weIdPublicKey,WeIdPrivateKey weIdPrivateKey)
接口描述: 根据传入的公钥和代理的私钥,通过代理发交易链上注册WeIdentity DID,并返回WeIdentity DID。
接口入参: com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 数字公钥,代理会根据这个公钥来创建WeID |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 公钥WeIdentity DID格式字符串 | 如:did:weid:1000:0x…………………. |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_PUBLICKEY_INVALID | 100102 | 公钥无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
WeIdPublicKey weIdPublicKey = new WeIdPublicKey();
weIdPublicKey.setPublicKey(
"2905679808560626772263712571437125497429146398815877180317365034921958007199576809718056336050058032599743534507469742764670961100255274766148096681073592");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
esponseData<String> response = weIdService.createWeIdByPublicKey(weIdPublicKey, weIdPrivateKey);
输出结果如下:
result: did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30007
transactionHash: 0x7f9e0fe2bcb0e77bad9aa5c38f8440e71a48dc29406d9ad43e12130afd211c67
transactionIndex: 0
时序图
4. getWeIdDocumentJson¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdDocumentJson
接口定义:ResponseData<String> getWeIdDocumentJson(String weId)
接口描述: 根据WeIdentity DID查询WeIdentity DID Document信息,并以JSON格式返回。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | weidDocument Json |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<String> response = weIdService.getWeIdDocumentJson("did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a");
返回结果如下:
result: {"@context" : "https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"id" : "did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a",
"authentication" : [ {
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
} ],
"service" : [ {
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
} ]
}
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
(同时也包含getWeIDDocument时序)
5. getWeIDDocument¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdDocument
接口定义:ResponseData<WeIdDocument> getWeIdDocument(String weId)
接口描述: 根据WeIdentity DID查询出WeIdentity DID Document对象。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocument>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | WeIdDocument | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | WeIdentity DID | |
authentication | List |
认证方集合,见下 | |
service | List |
服务端点集合,见下 |
com.webank.weid.protocol.base.AuthenticationProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | verification method id |
type | String | 类型 | 默认为:Ed25519VerificationKey2020 |
controller | String | 方法拥有人 | verification method controller |
publicKeyMultibase | String | 验证公钥 | 使用base58编码的公钥 |
com.webank.weid.protocol.base.ServiceProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | |
type | String | 类型 | |
serviceEndpoint | String | 联系/服务方式 | 邮箱、github个人主页等 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<WeIdDocument> response = weIdService.getWeIdDocument("did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a");
返回结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
authentication:
[0]:
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
service:
[0]:
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
errorCode: 0
errorMessage: success
transactionInfo:null
6. getWeIdDocumentMetadata¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdDocumentMetadata
接口定义:ResponseData<getWeIdDocumentMetadata> getWeIdDocumentMetadata(String weId)
接口描述: 根据WeIdentity DID查询出WeIdentity DID DocumentMetadata对象。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocumentMetadata>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | WeIdDocument | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
created | Long | 创建 | |
updated | Long | 修改 | |
deactivated | boolean | 解散 | |
versionId | int | 版本Id |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<WeIdDocument> response = weIdService.getWeIdDocumentMetadata("did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a");
返回结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
created: 1686560615
updated: 1686560615
deactivated: false
versionId: 1
errorCode: 0
errorMessage: success
transactionInfo:null
7. setService¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.setService
接口定义:ResponseData<Boolean> setService(String weId, ServiceArgs setServiceArgs, WeIdPrivateKey weIdPrivateKey)
接口描述: 根据WeIdentity DID添加Service信息。
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
com.webank.weid.protocol.request.ServiceArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
type | String | Y | 类型 | 如:drivingCardService |
serviceEndpoint | String | Y | 服务端点 | 如:”https://weidentity.webank.com/endpoint/8377464” |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
WEID_SERVICE_TYPE_OVERLIMIT | 100110 | type字段超长 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ServiceArgs setServiceArgs = new SetServiceArgs();
setServiceArgs.setType("drivingCardService");
setServiceArgs.setServiceEndpoint("https://weidentity.webank.com/endpoint/8377464");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
ResponseData<Boolean> response = weIdService.setService("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", setServiceArgs, weIdPrivateKey);
返回结果如下:
result: true
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30012
transactionHash: 0xf4992c4d190a9338f13119125861aaa3fa86622de1ab6862d06c05c6e6d1d9be
transactionIndex: 0
时序图
8. setAuthentication¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.setAuthentication
接口定义:ResponseData<Boolean> setAuthentication(String weId, AuthenticationArgs authenticationArgs, WeIdPrivateKey weIdPrivateKey)
接口描述: 根据WeIdentity DID添加Authentication信息。
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
com.webank.weid.protocol.request.AuthenticationArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
owner | String | N | 所有者 | 默认为当前WeIdentity DID |
publicKey | String | Y | 数字公钥 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
AuthenticationArgs setAuthenticationArgs = new SetAuthenticationArgs();
setAuthenticationArgs.setPublicKey(
"13161444623157635919577071263152435729269604287924587017945158373362984739390835280704888860812486081963832887336483721952914804189509503053687001123007342");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
ResponseData<Boolean> response = weIdService.setAuthentication("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", setAuthenticationArgs, weIdPrivateKey);
返回结果如下:
result: true
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30013
transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
transactionIndex: 0
时序图
9. isWeIdExist¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.isWeIdExist
接口定义:ResponseData<Boolean> isWeIdExist(String weId)
接口描述: 根据WeIdentity DID判断链上是否存在。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID格式字符串 | 如:did:weid:101:0x…. |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<Boolean> response = weIdService.isWeIdExist("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
返回结果如下:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
10. isDeactivated¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.isDeactivated
接口定义:ResponseData<Boolean> isDeactivated(String weId)
接口描述: 检查WeIdentity DID是否在链上停用。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID格式字符串 | 如:did:weid:101:0x…. |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<Boolean> response = weIdService.isDeactivated("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
返回结果如下:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
11. revokeAuthentication¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.revokeAuthentication
接口定义:ResponseData<Boolean> revokeAuthentication(String weId, AuthenticationArgs authenticationArgs, WeIdPrivateKey weIdPrivateKey)
接口描述: 仅删除WeID文档中的身份验证标签-不会影响其公钥。
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID字符串 |
com.webank.weid.protocol.request.AuthenticationArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
owner | String | N | 所有者 | 默认为当前WeIdentity DID |
publicKey | String | Y | 数字公钥 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
AuthenticationArgs authenticationArgs = new AuthenticationArgs();
authenticationArgs.setPublicKey(
"13161444623157635919577071263152435729269604287924587017945158373362984739390835280704888860812486081963832887336483721952914804189509503053687001123007342");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
ResponseData<Boolean> response = weIdService.revokeAuthentication("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", authenticationArgs, weIdPrivateKey);
返回结果如下:
result: true
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30013
transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
transactionIndex: 0
12. getWeIdList¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdList
接口定义:ResponseData<List<String>> getWeIdList(Integer first, Integer last)
接口描述: 根据块高度、索引位置和搜索方向查询数据。
接口入参:
Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
first | Integer |
Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
last | Integer |
接口返回: com.webank.weid.protocol.response.ResponseData<List<String>>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<Boolean> response = weIdService.getWeIdList(1,10);
返回结果如下:
result:
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30013
transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
transactionIndex: 0
13. getWeIdCount¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdCount
接口定义:ResponseData<Integer> getWeIdCount()
接口描述: 获得总weId。
接口入参:
无
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<Boolean> response = weIdService.getWeIdCount();
返回结果如下:
result: 123
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30013
transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
transactionIndex: 0
14. getWeIdListByPubKeyList¶
基本信息
接口名称:com.webank.weid.service.rpc.WeIdService.getWeIdListByPubKeyList
接口定义:ResponseData<WeIdListResult> getWeIdListByPubKeyList(List<WeIdPublicKey> pubKeyList)
接口描述: 通过公钥列表获取WeID列表。
接口入参: com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 数字公钥,代理会根据这个公钥来创建WeID |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdListResult>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否set成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.response.WeIdListResult
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
weIdList | List<String> | ||
errorCodeList | List<String> |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdService weIdService = new WeIdServiceImpl();
List<WeIdPublicKey> pubKeyList = new ArrayList<>();
int num = 5;
for (int i = 0; i < num; i++) {
WeIdPublicKey publicKey = new WeIdPublicKey();
publicKey.setPublicKey("13161444623157635919577071263152435729269604287924587017945158373362984739390835280704888860812486081963832887336483721952914804189509503053687001123007342");
pubKeyList.add(publicKey);
}
ResponseData<WeIdListResult> weIdListRes = weIdService.getWeIdListByPubKeyList(pubKeyList);
返回结果如下:
result:
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30013
transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
transactionIndex: 0
AuthorityIssuerService¶
1. registerAuthorityIssuer¶
基本信息
接口名称:com.webank.weid.service.rpc.AuthorityIssuerService.registerAuthorityIssuer
接口定义:ResponseData<Boolean> registerAuthorityIssuer(RegisterAuthorityIssuerArgs args)
接口描述: 注册成为权威机构。
注意:这是一个需要权限的操作,目前只有合约的部署者(一般为SDK)才能正确执行。
接口入参: com.webank.weid.protocol.request.RegisterAuthorityIssuerArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
authorityIssuer | AuthorityIssuer | Y | AuthorityIssuer信息,见下 | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
com.webank.weid.protocol.base.AuthorityIssuer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 授权机构WeIdentity DID | |
name | String | Y | 授权机构名称 | 机构名称必须小于32个字节,非空,且仅包含ASCII码可打印字符(ASCII值位于32~126) |
created | Long | N | 创建日期 | 注册时不需要传入,SDK内置默认为当前时间 |
accValue | String | Y | 授权方累积判定值 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
AUTHORITY_ISSUER_PRIVATE_KEY_ILLEGAL | 100202 | 私钥格式非法 |
AUTHORITY_ISSUER_OPCODE_MISMATCH | 100205 | 操作码不匹配 |
AUTHORITY_ISSUER_NAME_ILLEGAL | 100206 | 名称格式非法 |
AUTHORITY_ISSUER_ACCVALUE_ILLEAGAL | 100207 | 累计值格式非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
AuthorityIssuer authorityIssuer = new AuthorityIssuer();
authorityIssuer.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
authorityIssuer.setName("webank1");
authorityIssuer.setAccValue("0");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("36162289879206412028682370838615850457668262092955617990245744195910144330785");
RegisterAuthorityIssuerArgs registerAuthorityIssuerArgs = new RegisterAuthorityIssuerArgs();
registerAuthorityIssuerArgs.setAuthorityIssuer(authorityIssuer);
registerAuthorityIssuerArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<Boolean> response = authorityIssuerService.registerAuthorityIssuer(registerAuthorityIssuerArgs);
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29963
transactionHash: 0x97a5cc2f4f7888e788a22e7c9bef1a293614bceec4721810511d07fc5b748f33
transactionIndex: 0
时序图
2. removeAuthorityIssuer¶
基本信息
接口名称:com.webank.weid.service.rpc.AuthorityIssuerService.removeAuthorityIssuer
接口定义:ResponseData<Boolean> removeAuthorityIssuer(RemoveAuthorityIssuerArgs args)
接口描述: 注销权威机构。
注意:这是一个需要权限的操作,目前只有合约的部署者(一般为SDK)才能正确执行。
接口入参: com.webank.weid.protocol.request.RemoveAuthorityIssuerArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | 授权机构WeIdentity DID |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
AUTHORITY_ISSUER_PRIVATE_KEY_ILLEGAL | 100202 | 私钥格式非法 |
AUTHORITY_ISSUER_OPCODE_MISMATCH | 100205 | 操作码不匹配 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("36162289879206412028682370838615850457668262092955617990245744195910144330785");
RemoveAuthorityIssuerArgs removeAuthorityIssuerArgs = new RemoveAuthorityIssuerArgs();
removeAuthorityIssuerArgs.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
removeAuthorityIssuerArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<Boolean> response = authorityIssuerService.removeAuthorityIssuer(removeAuthorityIssuerArgs);
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29951
transactionHash: 0xb9a2ef2a6045e0804b711e0ce39f7187de08e329160d5a5a00a1815e067f15e5
transactionIndex: 0
时序图
3. isAuthorityIssuer¶
基本信息
接口名称:com.webank.weid.service.rpc.AuthorityIssuerService.isAuthorityIssuer
接口定义:ResponseData<Boolean> isAuthorityIssuer(String weId)
接口描述: 根据WeIdentity DID判断是否为权威机构。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | 用于搜索权限发布者 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
AUTHORITY_ISSUER_CONTRACT_ERROR_NOT_EXISTS | 500202 | 实体不存在 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
String weId = "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7";
ResponseData<Boolean> response = authorityIssuerService.isAuthorityIssuer(weId);
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
4. queryAuthorityIssuerInfo¶
基本信息
接口名称:com.webank.weid.service.rpc.AuthorityIssuerService.queryAuthorityIssuerInfo
接口定义:ResponseData<AuthorityIssuer> queryAuthorityIssuerInfo(String weId)
接口描述: 根据WeIdentity DID查询权威机构信息。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | 用于搜索权限发布者 |
接口返回: com.webank.weid.protocol.response.ResponseData<AuthorityIssuer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | AuthorityIssuer | 授权机构信息,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.AuthorityIssuer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 授权机构WeIdentity DID | |
name | String | Y | 授权机构名称 | |
created | Long | Y | 创建日期 | |
accValue | String | Y | 授权方累积判定值 |
注意:因为Solidity 0.4.4的限制,无法正确的返回accValue,因此这里取得的accValue一定为空字符串。未来会进行修改。
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
AUTHORITY_ISSUER_CONTRACT_ERROR_NOT_EXISTS | 500202 | 实体不存在 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
String weId = "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7";
ResponseData<AuthorityIssuer> response = authorityIssuerService.queryAuthorityIssuerInfo(weId);
返回数据如:
result:(com.webank.weid.protocol.base.AuthorityIssuer)
weId: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
name: webank1
created: 1560412556901
accValue:
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
5. getAllAuthorityIssuerList¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.getAllAuthorityIssuerList
接口定义: ResponseData<List<AuthorityIssuer>> getAllAuthorityIssuerList(Integer index, Integer num)
接口描述: 查询指定范围内的issuer列表。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
index | Integer | Y | 检索的开始位置 | |
num | Integer | Y | 检索的数据条数 | 单次最多可以检索50条 |
接口返回: com.webank.weid.protocol.response.ResponseData<List<AuthorityIssuer>>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | List<AuthorityIssuer> | 授权机构信息,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.AuthorityIssuer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 授权机构WeIdentity DID | |
name | String | Y | 授权机构名称 | |
created | Long | Y | 创建日期 | |
accValue | String | Y | 授权方累积判定值 |
注意:因为Solidity 0.4.4的限制,无法正确的返回accValue,因此这里取得的accValue一定为空字符串。未来会进行修改。
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
ResponseData<List<AuthorityIssuer>> response = authorityIssuerService.getAllAuthorityIssuerList(0, 2);
返回数据如:
result: (java.util.ArrayList)
[0]: com.webank.weid.protocol.base.AuthorityIssuer
weId: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
name: webank1
created: 1560412556901
accValue:
[1]: com.webank.weid.protocol.base.AuthorityIssuer
weId: did:weid:101:0x48f56f6b8cd77409447014ceb060243b914cb2a9
name: webank2
created: 1560632118000
accValue:
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
6. registerIssuerType¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.registerIssuerType
接口定义: ResponseData<Boolean> registerIssuerType(WeIdAuthentication callerAuth, String issuerType)
接口描述: 指定并注册不同issuer的类型,如学校、政府机构等。
权限说明:本方法对传入的WeIdAuthentication没有特定权限要求。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
callerAuth | WeIdAuthentication | Y | weId身份信息 | |
issuerType | String | Y | 机构类型 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | WeIdentity DID的格式传入 |
weIdPublicKeyId | String | N | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否注册成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
SPECIFIC_ISSUER_TYPE_ILLEGAL | 100208 | 机构类型非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
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");
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
ResponseData<List<AuthorityIssuer>> response = authorityIssuerService.registerIssuerType(weIdAuthentication, "College");
返回数据如:
result: true
errorCode: 0
errorMessage: success
transactionInfo: (com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29950
transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
transactionIndex: 0
时序图
7. addIssuerIntoIssuerType¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.addIssuerIntoIssuerType
接口定义: ResponseData<Boolean> addIssuerIntoIssuerType(WeIdAuthentication callerAuth, String issuerType, String targetIssuerWeId)
接口描述: 向指定的issuerType中添加成员。
权限说明:方法的调用者至少需要是Authority Issuer才能成功。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
callerAuth | WeIdAuthentication | Y | weId身份信息 | |
issuerType | String | Y | 机构类型 | |
targetIssuerWeId | String | Y | issuer的WeIdentity DID |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | WeIdentity DID的格式传入 |
weIdPublicKeyId | String | N | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否添加成员成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
WEID_INVALID | 100201 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_PRIVATE_KEY_ILLEGAL | 100202 | 私钥格式非法 |
SPECIFIC_ISSUER_TYPE_ILLEGAL | 100208 | 机构类型非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
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");
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
ResponseData<List<AuthorityIssuer>> response = authorityIssuerService.addIssuerIntoIssuerType(weIdAuthentication, "College", "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
返回数据如:
result: true
errorCode: 0
errorMessage: success
transactionInfo: (com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29950
transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
transactionIndex: 0
时序图
8. removeIssuerFromIssuerType¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.removeIssuerFromIssuerType
接口定义: ResponseData<Boolean> removeIssuerFromIssuerType(WeIdAuthentication callerAuth, String issuerType, String targetIssuerWeId)
接口描述: 移除指定issuerType里面的WeId成员。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
callerAuth | WeIdAuthentication | Y | weId身份信息 | |
issuerType | String | Y | 机构类型 | |
targetIssuerWeId | String | Y | issuer的WeIdentity DID |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | WeIdentity DID的格式传入 |
weIdPublicKeyId | String | N | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,见下 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否移除成功 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
WEID_INVALID | 100201 | 无效的WeIdentity DID |
AUTHORITY_ISSUER_PRIVATE_KEY_ILLEGAL | 100202 | 私钥格式非法 |
SPECIFIC_ISSUER_TYPE_ILLEGAL | 100208 | 机构类型非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
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");
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
ResponseData<List<AuthorityIssuer>> response = authorityIssuerService.removeIssuerFromIssuerType(weIdAuthentication, "College", "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
返回数据如:
result: true
errorCode: 0
errorMessage: success
transactionInfo: (com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29950
transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
transactionIndex: 0
时序图
9. isSpecificTypeIssuer¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.isSpecificTypeIssuer
接口定义: ResponseData<Boolean> isSpecificTypeIssuer(String issuerType, String targetIssuerWeId)
接口描述: 判断issuer是否为指定机构里面的成员。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
issuerType | String | Y | 机构类型 | |
targetIssuerWeId | String | Y | issuer的WeIdentity DID |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否为指定类型中的成员 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
SPECIFIC_ISSUER_TYPE_ILLEGAL | 100208 | 机构类型非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
SPECIFIC_ISSUER_CONTRACT_ERROR_ALREADY_NOT_EXIST | 500502 | 授权人不存在 |
调用示例
AuthorityIssuerService authorityIssuerService = new AuthorityIssuerServiceImpl();
String weId = "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7";
ResponseData<Boolean> response = authorityIssuerService.isAuthorityIssuer(weId);
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
10. getAllSpecificTypeIssuerList¶
基本信息
接口名称: com.webank.weid.service.rpc.AuthorityIssuerService.getAllSpecificTypeIssuerList
接口定义: ResponseData<List<String>> getAllSpecificTypeIssuerList(String issuerType, Integer index, Integer num)
接口描述: 获取指定索引范围内的issuer列表。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
issuerType | String | Y | 机构类型 | |
index | Integer | Y | 检索的开始下标位置 | |
num | Integer | Y | 检索数据个数 | 单次最多可以检索50条 |
接口返回: com.webank.weid.protocol.response.ResponseData<List<String>>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | List<String> | issuer列表 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
AUTHORITY_ISSUER_ERROR | 100200 | 授权标准异常 |
SPECIFIC_ISSUER_TYPE_ILLEGAL | 100208 | 机构类型非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
返回数据如:
CptService¶
1. registerCpt¶
基本信息
接口名称:com.webank.weid.service.rpc.CptService.registerCpt
接口定义:ResponseData<CptBaseInfo> registerCpt(CptMapArgs args)
接口描述: 传入WeIdentity DID,JsonSchema(Map类型) 和其对应的私钥,链上注册CPT,返回CPT编号和版本。
接口入参: com.webank.weid.protocol.request.CptMapArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
调用示例
CptService cptService = new CptServiceImpl();
HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
String[] genderEnum = { "F", "M" };
HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
cptJsonSchemaKeys.put("name", propertitesMap1);
cptJsonSchemaKeys.put("gender", propertitesMap2);
cptJsonSchemaKeys.put("age", propertitesMap3);
cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
String[] genderRequired = { "name", "gender" };
cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setCptJsonSchema(cptJsonSchema);
cptMapArgs.setWeIdAuthentication(weIdAuthentication);
ResponseData<CptBaseInfo> response = cptService.registerCpt(cptMapArgs);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1016
cptVersion: 1
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29950
transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
transactionIndex: 0
时序图
(同时也包含重载updateCpt时序)
2. registerCpt¶
基本信息
接口名称: com.webank.weid.service.rpc.CptService.registerCpt
接口定义: ResponseData<CptBaseInfo> registerCpt(CptMapArgs args, Integer cptId)
接口描述: 传入WeIdentity DID,JsonSchema(Map类型), cptId 和其对应的私钥,链上注册指定cptId的CPT,返回CPT编号和版本。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
args | CptMapArgs | Y | Map类型参数注册CPT | |
cptId | Integer | Y | 指定的cptId |
com.webank.weid.protocol.request.CptMapArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
CptService cptService = new CptServiceImpl();
HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
String[] genderEnum = { "F", "M" };
HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
HashMap<String, Object> propertitesMap4 = new HashMap<String, Object>(2);
propertitesMap4.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap4.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is id");
HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
cptJsonSchemaKeys.put("name", propertitesMap1);
cptJsonSchemaKeys.put("gender", propertitesMap2);
cptJsonSchemaKeys.put("age", propertitesMap3);
cptJsonSchemaKeys.put("id", propertitesMap4);
cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
String[] genderRequired = { "id", "name", "gender" };
cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setCptJsonSchema(cptJsonSchema);
cptMapArgs.setWeIdAuthentication(weIdAuthentication);
ResponseData<CptBaseInfo> response = cptService.registerCpt(cptMapArgs, 101);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 101
cptVersion: 1
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29950
transactionHash: 0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13
transactionIndex: 0
3. registerCpt¶
基本信息
接口名称:com.webank.weid.service.rpc.CptService.registerCpt
接口定义:ResponseData<CptBaseInfo> registerCpt(CptStringArgs args)
接口描述: 传入WeIdentity DID,JsonSchema(String类型) 和其对应的私钥,链上注册CPT,返回CPT编号和版本。
接口入参: com.webank.weid.protocol.request.CptStringArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | String | Y | 字符串类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
CptService cptService = new CptServiceImpl();
String jsonSchema = "{\"properties\" : {\"name\": {\"type\": \"string\",\"description\": \"the name of certificate owner\"},\"gender\": {\"enum\": [\"F\", \"M\"],\"type\": \"string\",\"description\": \"the gender of certificate owner\"}, \"age\": {\"type\": \"number\", \"description\": \"the age of certificate owner\"}},\"required\": [\"name\", \"age\"]}";
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptStringArgs cptStringArgs = new CptStringArgs();
cptStringArgs.setCptJsonSchema(jsonSchema);
cptStringArgs.setWeIdAuthentication(weIdAuthentication);
ResponseData<CptBaseInfo> response = cptService.registerCpt(cptStringArgs);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1017
cptVersion: 1
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29964
transactionHash: 0xf3b039557b2d1e575e9949b3a33d34ee5c8749b55940347d18a0f7e929eda799
transactionIndex: 0
4. registerCpt¶
基本信息
接口名称: com.webank.weid.service.rpc.CptService.registerCpt
接口定义: ResponseData<CptBaseInfo> registerCpt(CptStringArgs args, Integer cptId)
接口描述: 传入WeIdentity DID,JsonSchema(String类型) , cptId和其对应的私钥,链上注册指定cptId的CPT,返回CPT编号和版本。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
args | CptStringArgs | Y | String类型参数注册CPT | |
cptId | Integer | Y | 指定的cptId |
com.webank.weid.protocol.request.CptStringArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | String | Y | 字符串类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
CptService cptService = new CptServiceImpl();
String jsonSchema = "{\"properties\" : {\"id\": {\"type\": \"string\",\"description\": \"the id of certificate owner\"}, \"name\": {\"type\": \"string\",\"description\": \"the name of certificate owner\"},\"gender\": {\"enum\": [\"F\", \"M\"],\"type\": \"string\",\"description\": \"the gender of certificate owner\"}, \"age\": {\"type\": \"number\", \"description\": \"the age of certificate owner\"}},\"required\": [\"id\", \"name\", \"age\"]}";
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptStringArgs cptStringArgs = new CptStringArgs();
cptStringArgs.setCptJsonSchema(jsonSchema);
cptStringArgs.setWeIdAuthentication(weIdAuthentication);
ResponseData<CptBaseInfo> response = cptService.registerCpt(cptStringArgs, 103);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 103
cptVersion: 1
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29910
transactionHash: 0xf3b039557b2d1e575e9949b3a33d34e35c8749b55940347d18a0f7e929eda799
transactionIndex: 0
5. queryCpt¶
基本信息
接口名称:com.webank.weid.service.rpc.CptService.queryCpt
接口定义:ResponseData<Cpt> queryCpt(Integer cptId)
接口描述: 根据CPT编号查询CPT信息。
接口入参: java.lang.Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
cptId | Integer | Y | cptId编号 |
接口返回: com.webank.weid.protocol.response.ResponseData<Cpt>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | Cpt | CPT内容,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.Cpt
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptJsonSchema | Map<String, Object> | Map类型的cptJsonSchema信息 | |
cptBaseInfo | CptBaseInfo | CPT基础数据,见下 | |
cptMetaData | CptMetaData | CPT元数据内部类,见下 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
com.webank.weid.protocol.base.Cpt.MetaData
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptPublisher | String | CPT发布者的WeIdentity DID | WeIdentity DID格式数据 |
cptSignature | String | 签名数据 | cptPublisher与cptJsonSchema拼接的签名数据 |
updated | long | 更新时间 | |
created | long | 创建日期 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数非法 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
调用示例
CptService cptService = new CptServiceImpl();
Integer cptId = Integer.valueOf(1017);
ResponseData<Cpt> response = cptService.queryCpt(cptId);
返回数据如下:
result:(com.webank.weid.protocol.base.Cpt)
cptBaseInfo:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1017
cptVersion: 1
cptJsonSchema:(java.util.HashMap)
$schema: http://json-schema.org/draft-04/schema#
type: object
properties:(java.util.LinkedHashMap)
age:(java.util.LinkedHashMap)
description: the age of certificate owner
type: number
gender:(java.util.LinkedHashMap)
description: the gender of certificate owner
enum:(java.util.ArrayList)
[0]:F
[1]:M
type: string
name:(java.util.LinkedHashMap)
description: the name of certificate owner
type: string
required:(java.util.ArrayList)
[0]:name
[1]:age
metaData:(com.webank.weid.protocol.base.Cpt$MetaData)
cptPublisher: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
cptSignature: G/YGY8Ftj9jPRdtr4ym+19M4/K6x9RbmRiV9JkryXeQGFr8eukDCBAcbinnNpF2N3Eo72bvxNqJOKx4ohWIus0Y=
created: 1560415607673
updated: 0
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
6. updateCpt¶
基本信息
接口名称:com.webank.weid.service.rpc.CptService.updateCpt
接口定义:ResponseData<CptBaseInfo> updateCpt(CptMapArgs args, Integer cptId)
接口描述: 传入cptId,JsonSchema(Map类型),WeIdentity DID,WeIdentity DID所属私钥,进行更新CPT信息,更新成功版本自动+1。
接口入参: com.webank.weid.protocol.request.CptMapArgs,Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
args | CptMapArgs | Y | CPT信息 | 具体见下 |
cptId | Integer | Y | 发布的CPT编号 |
com.webank.weid.protocol.request.CptMapArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
CptService cptService = new CptServiceImpl();
HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
String[] genderEnum = { "F", "M" };
HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
cptJsonSchemaKeys.put("name", propertitesMap1);
cptJsonSchemaKeys.put("gender", propertitesMap2);
cptJsonSchemaKeys.put("age", propertitesMap3);
cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
String[] genderRequired = { "name", "gender" };
cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setCptJsonSchema(cptJsonSchema);
cptMapArgs.setWeIdAuthentication(weIdAuthentication);
Integer cptId = Integer.valueOf(1017);
ResponseData<CptBaseInfo> response = cptService.updateCpt(cptMapArgs, cptId);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1017
cptVersion: 2
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29989
transactionHash: 0x4435fa88f9f138f14671d8baa5e5f16c69c5efa3591c4912772b9b1233af398a
transactionIndex: 0
时序图
(同时也包含重载updateCpt时序)
7. updateCpt¶
基本信息
接口名称:com.webank.weid.service.rpc.CptService.updateCpt
接口定义:ResponseData<CptBaseInfo> updateCpt(CptStringArgs args, Integer cptId)
接口描述: 传入cptId,JsonSchema(String类型),WeIdentity DID,WeIdentity DID所属私钥,进行更新CPT信息,更新成功版本自动+1。
接口入参: com.webank.weid.protocol.request.CptStringArgs,Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
args | CptStringArgs | Y | CPT信息 | 具体见下 |
cptId | Integer | Y | 发布的CPT编号 |
com.webank.weid.protocol.request.CptStringArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | String | Y | 字符串类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
CptService cptService = new CptServiceImpl();
String jsonSchema = "{\"properties\" : {\"name\": {\"type\": \"string\",\"description\": \"the name of certificate owner\"},\"gender\": {\"enum\": [\"F\", \"M\"],\"type\": \"string\",\"description\": \"the gender of certificate owner\"}, \"age\": {\"type\": \"number\", \"description\": \"the age of certificate owner\"}},\"required\": [\"name\", \"age\"]}";
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptStringArgs cptStringArgs = new CptStringArgs();
cptStringArgs.setCptJsonSchema(jsonSchema);
cptStringArgs.setWeIdAuthentication(weIdAuthentication);
Integer cptId = Integer.valueOf(1017);
ResponseData<CptBaseInfo> response = cptService.updateCpt(cptStringArgs, cptId);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1017
cptVersion: 3
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 29991
transactionHash: 0x8ed8113dd1772ae74e6f12de3d3716d76a410190c3d564d5d5842b85c7005aee
transactionIndex: 0
CredentialService¶
1. createCredential¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.createCredential
接口定义:ResponseData<CredentialWrapper> createCredential(CreateCredentialArgs args)
接口描述: 创建电子凭证,默认是original类型,还支持轻量级lite1类型和基于零知识证明的zkp类型的credential。
接口入参: com.webank.weid.protocol.request.CreateCredentialArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
cptId | Integer | Y | CPT编号 | |
issuer | String | Y | 发行方WeIdentity DID | WeIdentity DID格式数据 |
expirationDate | Long | Y | 到期日 | |
claim | Map<String, Object> | Y | Map类型的claim数据 | 凭证所需数据 |
weIdPrivateKey | WeIdPrivateKey | Y | 签名所用Issuer WeIdentity DID私钥,见下 | |
type | CredentialType | Y | 默认值是ORIGINAL,还支持ZKP和Lite类型 | 创建的credential的类型 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<CredentialWrapper>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | CredentialWrapper | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.CredentialWrapper
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
credential | Credential | Y | 凭证信息 | 具体见下 |
disclosure | Map<String, Object> | Y | 披露属性 | 默认为全披露 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_JSON_SCHEMA_INVALID | 100301 | JsonSchema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
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_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例 Original类型的credential生成示例:
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1551448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
返回结果如下:
{
"errorCode":0,
"errorMessage":"success",
"result":{
"claim":{
"age":18,
"gender":"F",
"name":"zhangsan"
},
"context":"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"cptId":2000082,
"expirationDate":1588776752,
"id":"0d633260-d31c-4155-b79d-a9eb67df7bab",
"issuanceDate":1588065179,
"issuer":"did:weid:101:0x9bd9897fcdb98428f7b152ce8a06cb16758ccd17",
"proof":{
"created":1588065179,
"creator":"did:weid:101:0x9bd9897fcdb98428f7b152ce8a06cb16758ccd17#keys-0",
"salt":{
"age":"exkEX",
"gender":"ya9jA",
"name":"Q4BDW"
},
"signatureValue":"G51huya0Q4Nz4HGa+dUju3GVrR0ng+atlXeouEKe60ImLMl6aihwZsSGExOgC8KwP3sUjeiggdba3xjVE9SSI/g=",
"type":"Secp256k1"
},
"type":[
"VerifiableCredential",
"original"
]
},
"transactionInfo":null
}
Lite类型的credential生成示例:
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1551448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
//如果不设置type为LITE1,则默认生成ORIGINAL类型
createCredentialArgs.setType(CredentialType.LITE1);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
返回结果如下,lite 类型的credential会比original类型的credential少salt等一些字段,更轻量:
{
"errorCode":0,
"errorMessage":"success",
"result":{
"claim":{
"age":18,
"gender":"F",
"name":"zhangsan"
},
"context":"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"cptId":2000082,
"expirationDate":1588776636,
"id":"c85cbaea-753b-4ae7-830f-20fb718b01b7",
"issuanceDate":1588065063,
"issuer":"did:weid:101:0x9bd9897fcdb98428f7b152ce8a06cb16758ccd17",
"proof":{
"signatureValue":"YopZgmhvi6ob9xPiROLb4p2WJ7j7RTwydGDUbonO9GEZBkpYVfcnlrbJ2H1vuyaVaoR46goJWfDWG3s1woY1/AE=",
"type":"Secp256k1"
},
"type":[
"VerifiableCredential",
"lite1"
]
},
"transactionInfo":null
}
时序图
2. verify¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.verify
接口定义:ResponseData<Boolean> verify(Credential credential);
接口描述: 验证凭证是否正确。
接口入参: com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuer与签名不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_ISSUER_NOT_EXISTS | 100407 | WeIdentity DID不能为空 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | WeIdentity Document为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 验证签名异常 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1561448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
//创建Credential
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
//验证Credential
ResponseData<Boolean> responseVerify = credentialService.verify(response.getResult().getCredential());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
(同时也包含verifyCredentialWithSpecifiedPubKey时序)
3. verifyCredentialWithSpecifiedPubKey¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.verifyCredentialWithSpecifiedPubKey
接口定义: ResponseData<Boolean> verifyCredentialWithSpecifiedPubKey(CredentialWrapper credentialWrapper, WeIdPublicKey weIdPublicKey)
接口描述: 验证凭证是否正确,需传入公钥。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
credentialWrapper | CredentialWrapper | Y | 凭证信息,见下 | |
weIdPublicKey | WeIdPublicKey | Y | 公钥信息,见下 |
com.webank.weid.protocol.base.CredentialWrapper
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
credential | Credential | Y | 凭证信息 | 具体见下 |
disclosure | Map<String, Object> | N | 披露属性 | 默认为全披露 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
publicKey | String | 数字公钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuer与签名不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_ISSUER_NOT_EXISTS | 100407 | WeIdentity DID不能为空 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | WeIdentity Document为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 验证签名异常 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1561448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
// 创建Credential
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
WeIdPublicKey weIdPublicKey = new WeIdPublicKey();
weIdPublicKey.setPublicKey(
"9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875");
//使用公钥验证
ResponseData<Boolean> responseVerify = credentialService
.verifyCredentialWithSpecifiedPubKey(response.getResult(), weIdPublicKey);
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
4. getCredentialHash¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.getCredentialHash
接口定义:ResponseData<String> getCredentialHash(Credential args)
接口描述: 传入Credential信息生成Credential整体的Hash值,一般在生成Evidence时调用。
接口入参: com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1561448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
//创建Credentia
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
//获取Credentia的Hash
ResponseData<String> responseHash = credentialService.getCredentialHash(response.getResult().getCredential());
返回结果如:
result: 0x06173e4b714d57565ae5ddf23c4e84cb0a9824cb72eab476303d2dd1cc0a4728
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
5. getCredentialHash¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.getCredentialHash
接口定义:ResponseData<String> getCredentialHash(CredentialWrapper args)
接口描述: 传入Credential信息生成Credential整体的Hash值,一般在生成Evidence时调用。
接口入参: com.webank.weid.protocol.base.CredentialWrapper
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
credential | Credential | Y | 凭证信息 | 具体见下 |
disclosure | Map<String, Object> | Y | 披露属性 | 默认为全披露 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1561448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
//创建CredentialWrapper
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
//获取CredentialWrapper的Hash
ResponseData<String> responseHash = credentialService.getCredentialHash(response.getResult());
返回结果如:
result: 0x06173e4b714d57565ae5ddf23c4e84cb0a9824cb72eab476303d2dd1cc0a4728
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
6. addSignature¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialService.addSignature
接口定义:ResponseData<Credential> addSignature(List<Credential> credentialList, WeIdPrivateKey weIdPrivateKey)
接口描述:多签,在原凭证列表的基础上,创建包裹成一个新的多签凭证,由传入的私钥所签名。此凭证的CPT为一个固定值。在验证一个多签凭证时,会迭代验证其包裹的所有子凭证。本接口不支持创建选择性披露的多签凭证。
接口入参: java.util.ArrayList
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Credential>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Credential | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | 默认为106 |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_JSON_SCHEMA_INVALID | 100301 | JsonSchema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
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_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1551448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
List<Credential> credList = new ArrayList<>();
credList.add(response.getResult().getCredential());
Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
createCredentialArgs.getExpirationDate() + 24 * 60 * 60);
createCredentialArgs.setExpirationDate(expirationDate);
Credential tempCredential =
credentialService.createCredential(createCredentialArgs).getResult().getCredential();
credentialList.add(tempCredential);
ResponseData<Credential> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
System.out.println(multiSignedResp);
返回结果如:
result:(com.webank.weid.protocol.base.CredentialWrapper)
credential:(com.webank.weid.protocol.base.Credential) {
"claim": {
"credentialList": [
{
"claim": {
"age": 18,
"gender": "F",
"id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
"name": "zhang san"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000084,
"expirationDate": 1567488114,
"id": "a8b1c030-231d-49de-9618-b5ed7f3e6d2e",
"issuanceDate": 1567401714,
"issuer": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"proof": {
"created": "1567401714",
"creator": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"signature": "GwKcDoEseYdJxI7M\/R4RAdGcV5SJoFVvg8Z53BVa76LMV8eqbX3F4rb1dWjhqI286AvPECx6uuuo9cTAKuNHRXM=",
"type": "Secp256k1"
}
},
{
"claim": {
"age": 18,
"gender": "F",
"id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
"name": "zhang san"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000084,
"expirationDate": 1567488201,
"id": "2130908d-fb2a-4675-8bf1-727f354ca8e4",
"issuanceDate": 1567401715,
"issuer": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"proof": {
"created": "1567401715",
"creator": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"signature": "HJXDuvg2l8jRbL5ymmBSAo\/6DMKbCv3P1XoP67S+OVzSbRVDNFXY1CsqpTqT5MAkSY4+UwPLwCfXrLtHsZQ6GOo=",
"type": "Secp256k1"
}
}
]
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 106,
"expirationDate": 1567488201,
"id": "d8642623-703f-447a-8765-dab1dab4df0a",
"issuanceDate": 1567401717,
"issuer": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"proof": {
"created": "1567401717",
"creator": "did:weid:1000:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
"signature": "HKXEwzDEwqte4aAUBLvQjiI3C0cw5V\/iWeKWmBs7HIG0IRzgbXnMj8kYw37y5yJE4KdsWCuehBUGuW7WdihL560=",
"type": "Secp256k1"
}
}
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
EvidenceService¶
1. createEvidence¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.createEvidence
接口定义:ResponseData<String> createEvidence(Hashable object, WeIdPrivateKey weIdPrivateKey)
接口描述: 为一个**未曾上过链**的Object,将传入的Object计算Hash值生成存证上链,返回存证hash值。传入的私钥将会成为链上存证的签名方。此签名方和凭证的Issuer可以不是同一方。此接口返回的Hash值和generateHash()接口返回值一致。同样的传入Object可以由不同的私钥注册存证,它们的链上存证值将会共存。
接口入参:
Hashable java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | Hashable object | N | 实现了Hashable接口的任意Object | 当前支持HashString,Credential,CredentialWrapper,CredentialPojo |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 创建的凭证hash值 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT | 500401 | Evidence参数非法 |
时序图
2. createEvidenceWithLogAndCustomKey / createEvidenceWithLog¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.createEvidence
接口定义:ResponseData<String> createEvidence(Hashable object, WeIdPrivateKey weIdPrivateKey, String log, String customKey)
接口描述: 为一个**未曾上过链**的Object,将传入Object计算Hash值生成存证上链。此方法允许在创建存证时写入额外信息。额外信息为一个log记录,从后往前叠加存储。不同私钥发交易方的额外信息也是共存且相互独立存储的。如果您重复调用此接口,那么新写入的额外值会以列表的形式添加到之前的log列表之后。此方法还允许传入一个用户自定义的custom key,用来查询链上的存证(而不是通过hash)。
接口入参:
Hashable java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | Hashable object | N | 实现了Hashable接口的任意Object | 当前支持Credential,CredentialWrapper,CredentialPojo |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
log | String | Y | 额外信息 | 长度不能超过2M,必须为UTF-8 |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
customKey | String | Y | 用户自定索引关键字 | 长度不能超过2M,必须为UTF-8 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 创建的凭证hash值 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CREDENTIAL_EVIDENCE_CONTRACT_FAILURE_ILLEAGAL_INPUT | 500401 | Evidence参数非法 |
时序图
3. getEvidence¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.getEvidence
接口定义:ResponseData<EvidenceInfo> getEvidence(String hashValue)
接口描述: 根据传入的凭证存证hash值,在链上查找凭证在链上是否存在。如果存在,则返回所有为此hash值创建过存证的创建方,及其创建时间、额外信息。
接口入参: String
接口返回: com.webank.weid.protocol.response.ResponseData<EvidenceInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | EvidenceInfo | 创建的凭证合约地址 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.EvidenceInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
credentialHash | String | 凭证Hash值 | 是一个66个字节的字符串,以0x开头 |
signInfo | Map<String, EvidenceSignInfo> | 存证创建者信息 | 链上允许一个存证存在多个创建者 |
com.webank.weid.protocol.base.EvidenceSignInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
signature | String | 存证的签名 | 以Base64编码的存证签名值 |
timestamp | String | 存证创建时间 | |
logs | List<String> | 额外信息列表 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
时序图
4. getEvidenceByCustomKey¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.getEvidenceByCustomKey
接口定义:ResponseData<EvidenceInfo> getEvidenceByCustomKey(String customKey)
接口描述: 根据传入的自定义索引,在链上查找凭证在链上是否存在。如果存在,则返回所有为此索引值值创建过存证的创建方,及其创建时间、额外信息。
接口入参: String
接口返回: com.webank.weid.protocol.response.ResponseData<EvidenceInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | EvidenceInfo | 创建的凭证合约地址 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.EvidenceInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
credentialHash | String | 凭证Hash值 | 是一个66个字节的字符串,以0x开头 |
signInfo | Map<String, EvidenceSignInfo> | 存证创建者信息 | 链上允许一个存证存在多个创建者 |
com.webank.weid.protocol.base.EvidenceSignInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
signature | String | 存证的签名 | 以Base64编码的存证签名值 |
timestamp | String | 存证创建时间 | |
logs | List<String> | 额外信息列表 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
时序图
5. verifySigner¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.verifySigner
接口定义:ResponseData<Boolean> verify(CredentialPojo credentialPojo, EvidenceInfo evidenceInfo, String weId)
接口描述: 根据传入的凭证和存证信息和WeID,从链上根据WeID的公钥,判断此存证是否合法。
接口入参:
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> | 签名数据结构体 |
com.webank.weid.protocol.base.EvidenceInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
credentialHash | String | 凭证Hash值 | 是一个66个字节的字符串,以0x开头 |
signInfo | Map<String, EvidenceSignInfo> | 存证创建者信息 | 链上允许一个存证存在多个创建者 |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 用户WeID |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否验证成功 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_SIGNATURE_BROKEN | 100431 | 存证签名异常 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
6. verifySigner(传入公钥)¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.verifySigner
接口定义:ResponseData<Boolean> verify(CredentialPojo credentialPojo, EvidenceInfo evidenceInfo, String weId, String publicKey)
接口描述: 根据传入的凭证和存证信息和WeID,及传入的公钥,判断此WeID是否为存证的合法创建者。不需要链上交互。
接口入参:
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> | 签名数据结构体 |
com.webank.weid.protocol.base.EvidenceInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
credentialHash | String | 凭证Hash值 | 是一个66个字节的字符串,以0x开头 |
signInfo | Map<String, EvidenceSignInfo> | 存证创建者信息 | 链上允许一个存证存在多个创建者 |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 用户WeID |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 传入公钥 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 是否验证成功 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_SIGNATURE_BROKEN | 100431 | 存证签名异常 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
WEID_PUBLICKEY_INVALID | 100102 | 公钥格式非法 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
7. generateHash¶
基本信息
接口名称: com.webank.weid.service.rpc.EvidenceService.generateHash
接口定义: ResponseData<HashString> generateHash(T object)
接口描述: 将传入的任意Object计算Hash值,不需网络。可以接受**任意Hashable对象**(如凭证)、**File**(Java里的文件实例)、**String**(字符串)。对于不符合类型的入参,将返回类型不支持错误。返回值为HashString,可以直接传入CreateEvidence接口用于存证创建。
接口入参:
T java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | T object | N | 任意Object | 当前支持Hashable,File, String |
接口返回: com.webank.weid.protocol.response.ResponseData<HashString>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | HashString | 创建的符合Hashable接口的存证值对象 | 存证值,可以直接传入createEvidence用于存证上链 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
ILLEGAL_INPUT | 160004 | 入参非法 |
调用示例
CredentialService credentialService = new CredentialServiceImpl();
EvidenceService evidenceService = new EvidenceServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
createCredentialArgs.setClaim(claim);
createCredentialArgs.setCptId(1017);
createCredentialArgs.setExpirationDate(1561448312461L);
createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
// 创建Credential
ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
// 直接将凭证传入generateHash
String hash = evidenceService.generateHash(response.getResult().getCredential()).getResult().getHash();
// 将凭证传入createEvidence(),将自动对Credential做hash并以Credential的hash上链
ResponseData<String> responseCreateEvidence = evidenceService.createEvidence(response.getResult().getCredential(), weIdPrivateKey);
// 对比hash和responseCreateEvidence.getResult()的哈希值,应为相同
返回结果如:
result: 0xa3203e054bb7a7f0dec134c7510299869e343e8d
errorCode: 0
errorMessage: success
transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
blockNumber: 30014
transactionHash: 0x1f9e62fa152eb5fce859dcf81c7c0eddcbcab63c40629d1c745058c227693dae
transactionIndex: 0
时序图
8. addLogByHash / addLogByCustomKey¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.addLogByHash / addLogByCustomKey
接口定义:ResponseData<Boolean> addLogByHash(String hashValueSupplement(仅在customKey中用到), String hashValue / customKey, String log, WeIdPrivateKey weIdPrivateKey)
接口描述: 为一个**已经在链上存在的存证**添加额外信息记录存入其log中。有两个接口,一个是以hash值为索引,一个可以接受用户自定义索引(customKey);如果自定义索引不存在,则会使用替补hash作为上链索引。
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
hashValueSupplement | String | N |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
hashValue | String | N |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
log | String | Y | 额外信息 | 长度不能超过2M,必须为UTF-8 |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
customKey | String | Y | 用户自定索引关键字 | 长度不能超过2M,必须为UTF-8 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
时序图
9. addSignatureAndLogByHash / addSignatureAndLogByCustomKey¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.addSignatureAndLogByHash / addSignatureAndLogByCustomKey
接口定义:ResponseData<Boolean> addSignatureAndLogByHash(String hashValueSupplement(仅在customKey中用到), String hashValue / customKey, String log, WeIdPrivateKey weIdPrivateKey)
接口描述:为一个**已经在链上存在的存证**添加日志条目。有两个接口,一个是以hash值为索引,一个可以接受用户自定义索引(customKey);如果自定义索引不存在,则会使用替补hash作为上链索引,此日志将是永久记录在区块链上,最后在尝试获取存证。
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
hashValueSupplement | String | N |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
hashValue | String | N |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
log | String | Y | 额外信息 | 长度不能超过2M,必须为UTF-8 |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
customKey | String | Y | 用户自定索引关键字 | 长度不能超过2M,必须为UTF-8 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
10. revoke / unRevoke¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.revoke / unRevoke
接口定义:ResponseData<Boolean> revoke(Hashable object, WeIdAuthentication weIdAuthentication)
接口描述: 撤销存证 / 撤销存证-可以取消。
接口入参:
Hashable java.lang.Object
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
Object | Hashable object | N | 实现了Hashable接口的任意Object | 当前支持Credential,CredentialWrapper,CredentialPojo |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
privateKey | String | 私钥 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
11. isRevoked¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.isRevoked
接口定义:ResponseData<Boolean> isRevoked(EvidenceInfo evidenceInfo, String weId)
接口描述: 检查该存证是否被该WeID撤销。
接口入参:
com.webank.weid.protocol.base.EvidenceInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
credentialHash | String | 凭证Hash值 | 是一个66个字节的字符串,以0x开头 |
signInfo | Map<String, EvidenceSignInfo> | 存证创建者信息 | 链上允许一个存证存在多个创建者 |
com.webank.weid.protocol.base.EvidenceSignInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
signature | String | 存证的签名 | 以Base64编码的存证签名值 |
timestamp | String | 存证创建时间 | |
logs | List<String> | 额外信息列表 |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 用户WeID |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
12. createRawEvidenceWithCustomKey¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.createRawEvidenceWithCustomKey
接口定义:ResponseData<Boolean> createRawEvidenceWithCustomKey(String hashValue,String signature,String log,Long timestamp,String extraKey,String privateKey)
接口描述: 创建可定制所有输入的原始存证。
接口入参:
String
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 用户WeID |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
13. createRawEvidenceWithSpecificSigner¶
基本信息
接口名称:com.webank.weid.service.rpc.EvidenceService.createRawEvidenceWithSpecificSigner
接口定义:ResponseData<Boolean> createRawEvidenceWithSpecificSigner(String hashValue,String signature,String log,Long timestamp,String extraKey,String signer,
String privateKey)
接口描述: 创建原始存证接口,其中所有输入(包括签名者)都可以定制。
接口入参:
String
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | 用户WeID |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 成功与否 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CREDENTIAL_EVIDENCE_BASE_ERROR | 100500 | Evidence标准错误 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CredentialPojoService¶
1. createCredential¶
基本信息
接口名称:com.webank.weid.service.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身份信息 | |
type | CredentialType | N | 凭证类型enum,默认为Original,可选ZKP类型和Lite类型 |
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
时序图
2. prepareZkpCredential¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.prepareZkpCredential
接口定义:<T> ResponseData<CredentialPojo> createCredential(CredentialPojo preCredential, String claimJson, WeIdAuthentication weIdAuthentication)
接口描述: 此接口仅在使用WeDPR的选择性披露时才需要调用,用于生成一些中间数据。用户根据传入的preCredential,claimJson以及weIdAuthentication生成基于系统CPT 111的credential。
接口入参:
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 | 签名数据结构体 |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
claimJson | String | Y | User claim | 用户填入的claim |
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
调用示例
CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
CreateCredentialPojoArgs<Map<String, Object>> createCredentialPojoArgs = new CreateCredentialPojoArgs<Map<String, Object>>();
createCredentialPojoArgs.setCptId(110);
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("id", "d5e68eb5-0417-47b0-b678-5eb86c50bf22");
claim.put("issuer", "did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
claim.put("expirationDate", System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 100);
claim.put("cptId", 2000003);
claim.put(issuanceDate, System.currentTimeMillis());
createCredentialPojoArgs.setClaim(claim);
ResponseData<CredentialPojo> response = credentialPojoService.createCredential(createCredentialPojoArgs);
CredentialPojo credential = response.getResult;
Map<String, Object> userClaim = new HashMap<String, Object>();
userClaim.put("name", "zhangsan");
userClaim.put("age", 18);
userClaim.put("gender", "F");
String claimJson = DataToolUtils.serialize(userClaim);
WeIdAuthentication userAuth = new WeIdAuthentication();
userAuth.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey userPrivateKey = new WeIdPrivateKey();
userPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
userAuth.setWeIdPrivateKey(userPrivateKey);
userAuth.setWeIdPublicKeyId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0");
ResponseData<CredentialPojo> prepareZkpResponse = credentialPojoService.prepareZkpCredential(credential, claimJson, userAuth);
返回结果如:
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)
cptId: 2000003
credentialSignatureRequest: YWjF2cFZnPT0SKAomEiRkNWU2OGViNS0wNDE3LTQ3YjAtYjY3OC01ZWI4NmM1MGJmMj
userNonce: mNXpIM2lJaUh2STNtc3hvTHgxMHQxZz09Egg1ZTU2MjBmMhpICixsS2NSNWx
proof:(java.util.HashMap)
creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
salt:(java.util.HashMap)
cptId: ibu7f
credentialSignatureRequest: el1w8
userNonce: ajqkr
created: 1560420878712
type: Secp256k1
signatureValue: G7UPiw08P5E9dEcSJEo9zpKu/nsUrpn00xDE+mwDXn9gJEohIlRUX5XTGQB4G1w3yThp6R/2RqjUYkuQTaUXbIU=
type:(java.util.ArrayList)
[0]:VerifiableCredential
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
3. createSelectiveCredential¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.createSelectiveCredential
接口定义: ResponseData<CredentialPojo> createSelectiveCredential(CredentialPojo credentialPojo, ClaimPolicy claimPolicy)
接口描述: 通过原始凭证和披露策略,创建选择性披露的Credential。
注解
注意:对于已经创建好的选择性披露凭证,不允许再次进行选择性披露。
接口入参:
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.ClaimPolicy
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
fieldsToBeDisclosed | String | Y | 披露配置 | 根据claim匹配的结构,为一个Json字符串,和Claim字段格式匹配。详见调用示例 |
接口返回: 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 | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
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_DISCLOSUREVALUE_ILLEGAL | 100423 | policy披露信息非法 |
CREDENTIAL_POLICY_FORMAT_DOSE_NOT_MATCH_CLAIM | 100427 | 披露策略与Claim不匹配 |
CREDENTIAL_DISCLOSURE_DATA_TYPE_ILLEGAL | 100428 | 披露数据格式错误 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数非法 |
CREDENTIAL_NOT_SUPPORT_SELECTIVE_DISCLOSURE | 100440 | lite credential不支持选择性披露 |
调用示例
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);
// 选择性披露
ClaimPolicy claimPolicy = new ClaimPolicy();
claimPolicy.setFieldsToBeDisclosed("{\"name\":1,\"gender\":0,\"age\":1}");
ResponseData<CredentialPojo> selectiveResponse =
credentialPojoService.createSelectiveCredential(response.getResult(), claimPolicy);
返回结果如:
result:(com.webank.weid.protocol.base.CredentialPojo)
context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
id: c4f8ca00-7c1b-4ba0-993f-008106075d9c
cptId: 1017
issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
issuanceDate: 1560420975268
expirationDate: 1560471040676
claim:(java.util.HashMap)
gender: 0x0756ccf78a0ebd5bd186b054376f1e9d86139bf04f660e9171a74673e5a21c75
name: zhangsan
age: 22
proof:(java.util.HashMap)
creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
salt:(java.util.HashMap)
gender: 0
name: rr3g0
age: 9ysgr
created: 1560420975268
type: Secp256k1
signatureValue: GxVcZJFEnC7w+ZKOZAjmKy5JfFxoEFqffmCMvbUnVYmzEVKIUtDCiDmokZ2X3jIV/uFvUHQ4DWXksrD6Opr1vLo=
type:(java.util.ArrayList)
[0]:VerifiableCredential
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
4. verify¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.verify
接口定义: ResponseData<Boolean> verify(String issuerWeId, CredentialPojo credential)
接口描述: 验证credential。
接口入参:
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
issuerWeId | String | Y | WeIdentity DID |
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.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
调用示例
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);
ResponseData<Boolean> responseVerify = credentialPojoService.verify("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", response.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
5. verify¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.verify
接口定义: ResponseData<Boolean> verify(WeIdPublicKey issuerPublicKey, CredentialPojo credential)
接口描述: 使用指定公钥验证credential。
接口入参:
com.webank.weid.protocol.base.WeIdPublicKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 公钥 |
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.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuerWeId跟Credential中的issuer不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名验证不通过 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
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_TYPE_IS_NULL | 100414 | type为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | 获取weIdDocument异常 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 签名验证异常 |
CREDENTIAL_PUBLIC_KEY_NOT_EXISTS | 100421 | 公钥不存在 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
CREDENTIAL_SALT_ILLEGAL | 100430 | 盐值非法 |
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);
WeIdPublicKey weIdPublicKey = new WeIdPublicKey();
weIdPublicKey.setPublicKey("9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875");
ResponseData<Boolean> responseVerify = credentialPojoService.verify(weIdPublicKey, response.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
6. verify¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.verify
接口定义: ResponseData<Boolean> verify(String presenterWeId, PresentationPolicyE presentationPolicyE, Challenge challenge, PresentationE presentationE)
接口描述: 验证Presentation。
接口入参:
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
presenterWeId | String | Y | WeIdentity DID | 用户的WeIdentity DID |
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.PresentationE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | List<String> | Y | 上下文 | |
type | List<String> | Y | Presentation Type | |
credentialList | List<CredentialPojo> | Y | 凭证列表 | |
proof | Map<String, Object> | Y | Presentation的签名信息 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
调用示例
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:1000:0x0231765e19955fc65133ec8591d73e9136306cd0\",\"policy\" : {\"1017\" : {\"fieldsToBeDisclosed\" : {\"gender\" : 0,\"name\" : 1,\"age\" : 0}}}}";
PresentationPolicyE presentationPolicyE = PresentationPolicyE.fromJson(policyJson);
//创建Presentation
ResponseData<PresentationE> presentationERes = credentialPojoService.createPresentation(credentialList, presentationPolicyE, challenge, weIdAuthentication);
//验证Presentation
ResponseData<Boolean> verifyRes = credentialPojoService.verify("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", presentationPolicyE, challenge, presentationERes.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
7. verifyPresentationFromPdf¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.verifyPresentationFromPdf
接口定义: ResponseData<Boolean> verifyPresentationFromPdf(String pdfTemplatePath, byte[] serializePdf, String presenterWeId, PresentationPolicyE presentationPolicyE, Challenge challenge, PresentationE presentationE)
接口描述: 验证由PDF Transportation传输的Presentation。
接口入参:
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
pdfTemplatePath | String | Y | PDF模板路径 | 用于PDF序列化的PDF模板路径 |
java.lang.byte
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
serializePdf | byte[] | Y | 包含PDF数据的byte数组 | 序列化生成包含PDF数据的byte数组 |
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
presenterWeId | String | Y | WeIdentity DID | 用户的WeIdentity DID |
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.PresentationE
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | List<String> | Y | 上下文 | |
type | List<String> | Y | Presentation Type | |
credentialList | List<CredentialPojo> | Y | 凭证列表 | |
proof | Map<String, Object> | Y | Presentation的签名信息 |
接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
调用示例
//序列化presentation,生成包含PDF信息的byte数组
ResponseData<byte[]> retSerialize = TransportationFactory.newPdfTransportation()
.serializeWithTemplate(
presentationE1,
new ProtocolProperty(EncodeType.ORIGINAL),
"src/test/resources/test-template.pdf");
//反序列化包含PDF信息的byte数组为Presentation
ResponseData<PresentationE> retDeserialize = TransportationFactory.newPdfTransportation()
.deserialize(
retSerialize.getResult(),
PresentationE.class,
weIdAuthentication);
//验证presentation
ResponseData<Boolean> response = credentialPojoService.verifyPresentationFromPdf(
"src/test/resources/test-template.pdf",
retSerialize.getResult(),
credentialPojoNew1.getIssuer(),
presentationPolicyE1,
challenge1,
retDeserialize.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
8. createPresentation¶
基本信息
接口名称:com.webank.weid.service.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:1000: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
时序图
9. getCredentialPojoHash¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.getCredentialPojoHash
接口定义:ResponseData<String> getCredentialHash(CredentialPojo args)
接口描述: 传入CredentialPojo信息生成CredentialPojo整体的Hash值,一般在生成Evidence时调用。
接口入参: 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.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 返回结果值 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
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);
ResponseData<String> resp = credentialPojoService.getCredentialPojoHash(response.getResult());
返回结果如:
result: 0x06173e4b714d57565ae5ddf23c4e84cb0a9824cb72eab476303d2dd1cc0a4728
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
10. addSignature¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.addSignature
接口定义:ResponseData<Credential> addSignature(List<Credential> credentialList, WeIdPrivateKey weIdPrivateKey)
接口描述:多签,在原凭证列表的基础上,创建包裹成一个新的多签凭证,由传入的私钥所签名。此凭证的CPT为一个固定值。在验证一个多签凭证时,会迭代验证其包裹的所有子凭证。本接口不支持创建选择性披露的多签凭证。
接口入参: java.util.ArrayList
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Credential>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Credential | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | 默认为106 |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_JSON_SCHEMA_INVALID | 100301 | JsonSchema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
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_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialPojoArgs createCredentialPojoArgs = new CreateCredentialPojoArgs();
createCredentialPojoArgs.setClaim(claim);
createCredentialPojoArgs.setCptId(1017);
createCredentialPojoArgs.setExpirationDate(1551448312461L);
createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialPojoArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialWrapper> response = credentialPojoService.createCredentialPojo(createCredentialArgs);
List<CredentialPojo> credList = new ArrayList<>();
credList.add(response.getResult().getCredentialPojo());
Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
createCredentialPojoArgs.getExpirationDate() + 24 * 60 * 60);
createCredentialPojoArgs.setExpirationDate(expirationDate);
CredentialPojo tempCredential =
credentialPojoService.createCredentialPojo(createCredentialPojoArgs).getResult().getCredentialPojo();
credentialList.add(tempCredential);
ResponseData<CredentialPojo> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
System.out.println(multiSignedResp);
返回结果如:
result:(com.webank.weid.protocol.base.CredentialPojo)
credentialPojo:(com.webank.weid.protocol.base.CredentialPojo) {
{
"claim": {
"credentialList": [
{
"claim": {
"age": 1,
"gender": "F",
"id": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
"name": "1"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000087,
"expirationDate": 1567491752,
"id": "6ea6e209-10e9-4a93-b6be-12af1a32655b",
"issuanceDate": 1567405352,
"issuer": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
"proof": {
"created": 1567405352,
"creator": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33#keys-0",
"salt": {
"age": "yOwN7",
"gender": "jjB85",
"id": "BmRYI",
"name": "BjYqF"
},
"signatureValue": "G+SNG3rBZNDvRNgRtJugPtX1FmE8XJIkV4CGPK\/nt\/breIPMJ5wYxImTp2QAxBUe5HMwCe9PPGhhMJJAazM5u9k=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
},
{
"claim": {
"age": 1,
"gender": "F",
"id": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
"name": "1"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000087,
"expirationDate": 1567491842,
"id": "a3544a9c-6cb6-4688-9622-bb935fb0d93f",
"issuanceDate": 1567405355,
"issuer": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
"proof": {
"created": 1567405355,
"creator": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53#keys-0",
"salt": {
"age": "5nImi",
"gender": "Me224",
"id": "5pYs2",
"name": "z6VmW"
},
"signatureValue": "HC8OAG\/dRmteGSIGWIDekp8fC1KJI8EEDZBb29HiTLXvVj350l9yTOHeGSBCr2VRY\/DSHT5ONjlvcrO4Mqa3Auo=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
}
]
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 107,
"expirationDate": 1567491842,
"id": "ad5d5a54-4574-4b3b-b1df-9d0687b6a0ac",
"issuanceDate": 1567405359,
"issuer": "did:weid:1000:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6",
"proof": {
"created": 1567405359,
"creator": "did:weid:1000:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6#keys-0",
"salt": {
"credentialList": ""
},
"signatureValue": "HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
}
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
11. createTrustedTimestamp¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.createTrustedTimestamp
接口定义:ResponseData<CredentialPojo> createTrustedTimestamp(List<CredentialPojo> credentialList, WeIdAuthentication weIdAuthentication)
接口描述: 使用第三方可信时间戳服务,创建一个可信时间戳凭证。
注解
注意:本服务需要您先行配置好时间戳服务的相关参数,请参见时间戳服务配置步骤。当前,可信时间戳服务支持使用WeSign(微鉴证)集成。
注解
注意:创建可信时间戳凭证的输入参数是一个凭证list。当前,因为一些技术限制,还不支持对**已经选择性披露的凭证**进行可信时间戳的创建。也就是说,如果您传入的凭证list里面有任何一个凭证是选择性披露的,那么创建将会失败。
注解
注意:对于已经创建好的可信时间戳凭证,您可以通过调用createSelectiveCredential对其进行选择性披露。
接口入参: java.util.ArrayList
com.webank.weid.protocol.base.CredentialPojo
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | 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<CredentialPojo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Credential | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.base.CredentialPojo
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | 默认为106 |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_JSON_SCHEMA_INVALID | 100301 | JsonSchema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
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_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
TIMESTAMP_SERVICE_BASE_ERROR | 100433 | 时间戳服务一般错误,请参照log检查具体错误 |
CREDENTIAL_SYSTEM_CPT_CLAIM_VERIFY_ERROR | 100434 | 凭证签名验证通过,但是内部系统CPT内容验证失败 |
TIMESTAMP_SERVICE_UNCONFIGURED | 100435 | 时间戳服务未配置 |
TIMESTAMP_SERVICE_WESIGN_ERROR | 100436 | 时间戳服务微鉴证侧出错,请参照log检查具体错误 |
TIMESTAMP_VERIFICATION_FAILED | 100437 | 时间戳验证不通过(可能是hash值/时间/时间戳签名任一错误) |
TIMESTAMP_CREATION_FAILED_FOR_SELECTIVELY_DISCLOSED | 100438 | 时间戳服务不支持对已经选择性披露的凭证进行创建时间戳 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
HashMap<String, Object> claim = new HashMap<String, Object>(3);
claim.put("name", "zhang san");
claim.put("gender", "F");
claim.put("age", 18);
CreateCredentialPojoArgs createCredentialPojoArgs = new CreateCredentialPojoArgs();
createCredentialPojoArgs.setClaim(claim);
createCredentialPojoArgs.setCptId(1017);
createCredentialPojoArgs.setExpirationDate(1551448312461L);
createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
createCredentialPojoArgs.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialWrapper> response = credentialPojoService.createCredentialPojo(createCredentialArgs);
List<CredentialPojo> credList = new ArrayList<>();
credList.add(response.getResult().getCredentialPojo());
Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
createCredentialPojoArgs.getExpirationDate() + 24 * 60 * 60);
createCredentialPojoArgs.setExpirationDate(expirationDate);
CredentialPojo tempCredential =
credentialPojoService.createCredentialPojo(createCredentialPojoArgs).getResult().getCredentialPojo();
credentialList.add(tempCredential);
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
ResponseData<CredentialPojo> trustedCred = credentialService.createTrustedTimestamp(credList, weIdAuthentication);
System.out.println(trustedCred);
返回结果如:
result:(com.webank.weid.protocol.base.CredentialPojo)
credentialPojo:(com.webank.weid.protocol.base.CredentialPojo) {
{
"claim": {
"credentialList": [
{
"claim": {
"age": 1,
"gender": "F",
"id": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
"name": "1"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000087,
"expirationDate": 1567491752,
"id": "6ea6e209-10e9-4a93-b6be-12af1a32655b",
"issuanceDate": 1567405352,
"issuer": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
"proof": {
"created": 1567405352,
"creator": "did:weid:1000:1:0xa4c2666560499868baf1906941f806b6d1c26e33#keys-0",
"salt": {
"age": "yOwN7",
"gender": "jjB85",
"id": "BmRYI",
"name": "BjYqF"
},
"signatureValue": "G+SNG3rBZNDvRNgRtJugPtX1FmE8XJIkV4CGPK\/nt\/breIPMJ5wYxImTp2QAxBUe5HMwCe9PPGhhMJJAazM5u9k=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
},
{
"claim": {
"age": 1,
"gender": "F",
"id": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
"name": "1"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 2000087,
"expirationDate": 1567491842,
"id": "a3544a9c-6cb6-4688-9622-bb935fb0d93f",
"issuanceDate": 1567405355,
"issuer": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
"proof": {
"created": 1567405355,
"creator": "did:weid:1000:1:0x309320a01f215a380c6950e80a89181ad8a8cd53#keys-0",
"salt": {
"age": "5nImi",
"gender": "Me224",
"id": "5pYs2",
"name": "z6VmW"
},
"signatureValue": "HC8OAG\/dRmteGSIGWIDekp8fC1KJI8EEDZBb29HiTLXvVj350l9yTOHeGSBCr2VRY\/DSHT5ONjlvcrO4Mqa3Auo=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
}
]
"timestampAuthority": "wesign",
"authoritySignature": "MhmbHC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=a235==",
"timestamp": 151233113000,
"claimHash": "0xe3f48648beee61d17de609d32af36ac0bf4d68a9352890b04d53841c4949bd13"
},
"context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
"cptId": 108,
"expirationDate": 1567491842,
"id": "ad5d5a54-4574-4b3b-b1df-9d0687b6a0ac",
"issuanceDate": 1567405359,
"issuer": "did:weid:1000:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6",
"proof": {
"created": 1567405359,
"creator": "did:weid:1000:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6#keys-0",
"salt": {
"credentialList": ""
},
"signatureValue": "HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=",
"type": "Secp256k1"
},
"type": [
"VerifiableCredential"
]
}
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
12. createDataAuthToken¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.createDataAuthToken
接口定义:ResponseData<CredentialPojo> createCredential(Cpt101 authInfo, WeIdAuthentication weIdAuthentication)
接口描述: 根据传入的授权要求信息,生成符合CPT101格式规范的数据授权凭证。该凭证需要被verify之后和Endpoint Service结合使用。
..note:
注意:使用这个接口的前提是首先需要将CPT 101注册到链上。如果您是新搭了一条WeIdentity 1.6.0+的链,那么搭链过程中这一步已经自动完成了。否则(如您是升级SDK),您需要使用部署WeIdentity合约的私钥(ecdsa_key)去将CPT 101注册到链上。下文的代码范例中我们给出了详细的流程
接口入参:
com.webank.weid.protocol.cpt.Cpt101
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
fromWeId | String | Y | 发起授权的WeIdentity DID(必须同时是Issuer) | 必须在链上存在,且需要传入私钥作为Issuer |
toWeId | String | Y | 接受授权的WeIdentity DID | 必须在链上存在且和fromWeId不同 |
serviceUrl | String | Y | 所授权内容在Endpoint Service上注册的service URL | 必须是一个包含主机名,端口号,以及端点地址的标准URL |
resourceId | String | Y | UUID | 用于标识资源的符合UUID格式字符串 |
duration | Long | Y | 授权有效时间 | 同时决定了凭证的expirationDate |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | WeIdentity DID | 必须和fromWeId一致 |
weIdPublicKeyId | String | N | 公钥Id | |
weIdPrivateKey | WeIdPrivateKey | Y | 交易私钥,必须和fromWeId在链上所公开的某个公钥一致 |
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.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无效 |
AUTHORIZATION_FROM_TO_MUST_BE_DIFFERENT | 100450 | fromWeId和toWeId必须不同 |
AUTHORIZATION_CANNOT_AUTHORIZE_OTHER_WEID_RESOURCE | 100451 | fromWeId必须和Issuer相同 |
ILLEGAL_INPUT | 160004 | 参数非法 |
调用示例
// Enforce a Register/Update system CPT first
WeIdAuthentication sdkAuthen = new WeIdAuthentication();
ECKeyPair keyPair = DataToolUtils.createKeyPairFromPrivate(privateKey);
String keyWeId = WeIdUtils
.convertAddressToWeId(new Address(Keys.getAddress(keyPair)).toString());
sdkAuthen.setWeId(keyWeId);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey(privateKey);
sdkAuthen.setWeIdPrivateKey(weIdPrivateKey);
if (!weIdService.isWeIdExist(keyWeId).getResult()) {
CreateWeIdArgs wargs = new CreateWeIdArgs();
wargs.setWeIdPrivateKey(weIdPrivateKey);
wargs.setPublicKey(keyPair.getPublicKey().toString(10));
weIdService.createWeId(wargs);
}
String cptJsonSchema = DataToolUtils
.generateDefaultCptJsonSchema(Class.forName("com.webank.weid.protocol.cpt.Cpt101"));
CptStringArgs args = new CptStringArgs();
args.setCptJsonSchema(cptJsonSchema);
args.setWeIdAuthentication(sdkAuthen);
if (cptService.queryCpt(CredentialConstant.AUTHORIZATION_CPT).getResult() == null) {
cptService.registerCpt(args, CredentialConstant.AUTHORIZATION_CPT);
} else {
cptService.updateCpt(args, CredentialConstant.AUTHORIZATION_CPT);
}
// Init params
Cpt101 authInfo = new Cpt101();
authInfo.setFromWeId(createWeIdResultWithSetAttr.getWeId());
String toWeId = this.createWeIdWithSetAttr().getWeId();
authInfo.setToWeId(toWeId);
authInfo.setDuration(360000L);
authInfo.setResourceId(UUID.randomUUID().toString());
authInfo.setServiceUrl("http://127.0.0.1:6011/fetch-data");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId(createWeIdResultWithSetAttr.getWeId());
weIdAuthentication.setWeIdPrivateKey(createWeIdResultWithSetAttr.getUserWeIdPrivateKey());
weIdAuthentication.setWeIdPublicKeyId(createWeIdResultWithSetAttr.getWeId() + "#keys-0");
// Create and check
ResponseData<CredentialPojo> authTokenCredResp = credentialPojoService
.createDataAuthToken(authInfo, weIdAuthentication);
System.out.println(DataToolUtils.deserialize(authTokenCredResp.getResult()));
返回结果如:
result:(com.webank.weid.protocol.base.CredentialPojo)
{
"claim": {
"duration": 360000,
"fromWeId": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168",
"resourceId": "4b077c17-9612-42ee-9e36-3a3d46b27e81",
"serviceUrl": "http://127.0.0.1:6010/fetch-data",
"toWeId": "did:weid:101:0x68bedb2cbe55b4c8e3473faa63f121c278f6dba9"
},
"context": "https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"cptId": 101,
"expirationDate": 1581347039,
"id": "48b75424-9411-4d22-b925-4e730b445a31",
"issuanceDate": 1580987039,
"issuer": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168",
"proof": {
"created": 1580987039,
"creator": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168#keys-0",
"salt": {
"duration": "fmk5A",
"fromWeId": "DEvFy",
"resourceId": "ugVeN",
"serviceUrl": "nVdeE",
"toWeId": "93Z1E"
},
"signatureValue": "HCZwyTzGst87cjCDaUEzPrO8QRlsPvCYXvRTUVBUTDKRSoGDgu4h4HLrMZ+emDacRnmQ/yke38u1jBnilNnCh6c=",
"type": "Secp256k1"
},
"type": ["VerifiableCredential", "hashTree"]
}
errorCode: 0
errorMessage: success
transactionInfo:null
时序图
13. verify¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.verify
接口定义: ResponseData<Boolean> verify(String issuerWeId, String weIdPublicKeyId, CredentialPojo credential)
接口描述: 通过传入的Issuer的WeID,并指定其链上公钥ID,验证credential。若验证失败,则会遍历所有公钥;如果能够找到一个适配的,那么就返回验证成功但公钥ID不匹配。
接口入参:
java.lang.String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
issuerWeId | String | Y | WeIdentity DID | |
weIdPublicKeyId | String | Y | 公钥ID |
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.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | 交易信息 |
此方法返回code
调用示例
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);
ResponseData<Boolean> responseVerify = credentialPojoService.verify("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7", "0", response.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
Persistence¶
1. add¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.add
接口定义: public ResponseData<Integer> add(String domain, String id, String data);
接口描述: 将数据存储到配置的存储库中
注解
注意:数据存储在相应的domain中,目前系统内置domain为7个,如需修改或新增domain,可在weidentity.properties进行自定义配置。
domain | 描述 |
---|---|
defaultInfo | 系统内置默认的domain |
encryptKey | 密钥存储的domain,比如transportation中加密的密钥存储 |
templateSecret | 零知识量证明流程需要 |
masterKey | 零知识量证明流程需要 |
credentialSignature | 零知识量证明流程需要 |
weIdAuth | weidauth存放鉴权时使用 |
resourceInfo | transportation下载模式存储原资源数据用的 |
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回结果 | 添加数据成功为1,不成功为0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
调用示例
String domain = "domain.defaultInfo";
String id = "123";
String data = "data123456";
// 调用persistence.add接口
ResponseData<Integer> result = persistence.add(domain, id, data);
2. batchAdd¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.batchAdd
接口定义: public ResponseData<Integer> batchAdd(String domain, Map<String, String> keyValueList);
接口描述: 数据批量存储到配置的存储库中
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回批量添加的数据数量 | 添加数据成功加1,不成功加0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
PERSISTENCE_BATCH_ADD_DATA_MISMATCH | 100904 | 存储库批量存储参数不匹配 |
调用示例
String domain = "domain.defaultInfo";
String id1 = "12345";
String data1 = "data12345";
String id2 = "54321";
String data2 = "data54321";
//以id-value形式将数据批量存储到HashMap
HashMap<String, String> map = new HashMap<>();
map.put(id1, data1);
map.put(id2, data2);
//调用persistence.batchAdd接口实现批量存储
ResponseData<Integer> res = persistence.batchAdd("domain.defaultInfo", map);
3. get¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.get
接口定义: public ResponseData<String> get(String domain, String id);
接口描述: 从相关存储库读取数据
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
PERSISTENCE_DATA_EXPIRE | 160015 | 存储库数据失效 |
调用示例
String domain = "domain.defaultInfo";
String id = "12345";
String data = "data123456";
// 存储数据
ResponseData<Integer> result = persistence.add(domain, id, data);
//通过id读取数据
ResponseData<String> res = persistence.get(domain, id);
4. delete¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.delete
接口定义: public ResponseData<Integer> delete(String domain, String id);
接口描述: 从相关存储库中删除数据
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回结果 | 删除成功返回1,删除失败返回0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
调用示例
String domain = "domain.defaultInfo";
String id = "123";
String data = "data123";
// 存储数据
ResponseData<Integer> result = persistence.add(domain, id, data);
//通过id删除相应数据
ResponseData<String> res = persistence.delete(domain, id);
5. update¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.update
接口定义: public ResponseData<Integer> update(String domain, String id, String data);
接口描述: 更新存储库中对应的数据
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回结果 | 更新数据成功为1,不成功为0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
调用示例
String domain = "domain.defaultInfo";
String id = "123456";
String data = "data123456";
String data1 = "data12345654321"
//存储数据
ResponseData<Integer> result = persistence.add(domain, id, data);
//更新数据
ResponseData<Integer> result1 = persistence.update(domain, id, data1);
6. addOrUpdate¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.addOrUpdate
接口定义: public ResponseData<Integer> addOrUpdate(String domain, String id, String data);
接口描述: 更新或新增数据
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回结果 | 更新或新增数据成功为1,不成功为0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
PERSISTENCE_DATA_EXPIRE | 160015 | 存储库数据失效 |
调用示例
String domain = "domain.defaultInfo";
String id = "1111";
String data = "data1111";
//存储或更新数据,根存储库中是否有对应id来判断调用add或者update接口
ResponseData<Integer> result = persistence.addOrUpdate(domain, id, data);
7. addTransaction¶
基本信息
接口名称: com.webank.weid.suite.persistence.Persistence.addTransaction
接口定义: public ResponseData<Integer> addTransaction(TransactionArgs transactionArgs);
接口描述: 新增交易数据
接口入参:
接口返回: com.webank.weid.protocol.response.ResponseData<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Integer | 返回结果 | 新增离线数据成功为1,不成功为0 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
PRESISTENCE_DATA_KEY_INVALID | 100901 | persistence的id不能为空 |
PRESISTENCE_DOMAIN_ILLEGAL | 100902 | domain非法 |
PRESISTENCE_DOMAIN_INVALID | 100903 | domain无效 |
PERSISTENCE_EXECUTE_FAILED | 160011 | mysql存储失败 |
PERSISTENCE_GET_CONNECTION_ERROR | 160013 | 存储库连接池连接失败 |
纯功能接口列表(无存储依赖)¶
WeIdServiceConsole¶
1. createWeIdDocument¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.createWeIdDocument
接口定义:ResponseData<WeIdDocument> createWeIdDocument(String publicKey)
接口描述: 外部传入公钥,根据该公钥生成初始的WeIdDocument。
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 公钥十进制字符串 |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocument>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | WeIdDocument | 见下 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | WeIdentity DID | |
authentication | List |
认证方集合,见下 | |
service | List |
服务端点集合,见下 |
com.webank.weid.protocol.base.AuthenticationProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | verification method id |
type | String | 类型 | 默认为:Ed25519VerificationKey2020 |
controller | String | 方法拥有人 | verification method controller |
publicKeyMultibase | String | 验证公钥 | 使用base58编码的公钥 |
com.webank.weid.protocol.base.ServiceProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | |
type | String | 类型 | |
serviceEndpoint | String | 联系/服务方式 | 邮箱、github个人主页等 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_KEYPAIR_CREATE_FAILED | 100107 | 创建密钥对失败 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥和weid不匹配 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
ResponseData<String> response = weIdServiceConsole.createWeIdDocument("13079093397463814932731720163442777403208788175453836227824139092404945067394266611910031425181012754616377192193136435818972874637291518463471522281921222");
输出结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
authentication:
[0]:
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
service:
[0]:
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
errorCode: 0
errorMessage: success
transactionInfo:null
2. createWeIdDocumentJson¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.createWeIdDocumentJson
接口定义:ResponseData<String> createWeIdDocumentJson(String publicKey)
接口描述: 外部传入公钥,根据该公钥生成初始的WeIdDocument的Json序列化结果
接口入参: String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
publicKey | String | Y | 公钥十进制字符串 |
接口返回: com.webank.weid.protocol.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | weidDocument Json | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
ResponseData<String> response = weIdServiceConsole.createWeIdDocumentJson("13079093397463814932731720163442777403208788175453836227824139092404945067394266611910031425181012754616377192193136435818972874637291518463471522281921222");
返回结果如下:
result: {"@context" : "https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"id" : "did:weid:101:0xd9aeaa982fc21ea9addaf09e4f0c6a23a08d306a",
"authentication" : [ {
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
} ],
"service" : [ {
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
} ]
}
errorCode: 0
errorMessage: success
transactionInfo:null
3. getWeIdDocumentMetadata¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.createWeIdDocumentMetadata
接口定义:ResponseData<WeIdDocumentMetadata> createWeIdDocumentMetadata()
接口描述: 创建WeIdentity DID DocumentMetadata对象。
接口入参: 无
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocumentMetadata>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
created | Long | 创建 | |
updated | Long | 修改 | |
deactivated | boolean | 解散 | |
versionId | int | 版本Id |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_DOES_NOT_EXIST | 100104 | WeIdentity DID不存在 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
ResponseData<WeIdDocumentMetadata> response = weIdServiceConsole.createWeIdDocumentMetadata();
返回结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
created: 1686560615
updated: 1686560615
deactivated: false
versionId: 1
errorCode: 0
errorMessage: success
transactionInfo:null
4. setService¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.setService
接口定义:ResponseData<WeIdDocument> setService(WeIdDocument weIdDocument, ServiceArgs setServiceArgs)
接口描述: 在给定的WeIdDocument中添加Service信息。
接口入参:
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdDocument | WeIdDocument | Y | WeIdentity Document |
com.webank.weid.protocol.request.ServiceArgs
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | |
type | String | 类型 | |
serviceEndpoint | String | 联系/服务方式 | 邮箱、github个人主页等 |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocument>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | WeIdDocument | ||
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
WEID_SERVICE_TYPE_OVERLIMIT | 100110 | type字段超长 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
WeIdDocument weIdDocument= weIdServiceConsole.createWeIdDocument("13079093397463814932731720163442777403208788175453836227824139092404945067394266611910031425181012754616377192193136435818972874637291518463471522281921222");
ServiceArgs setServiceArgs = new SetServiceArgs();
setServiceArgs.setType("drivingCardService");
setServiceArgs.setServiceEndpoint("https://weidentity.webank.com/endpoint/8377464");
ResponseData<WeIdDocument> response = weIdServiceConsole.setService(weIdDocument, serviceArgs);
返回结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
authentication:(java.util.ArrayList)
[0]:com.webank.weid.protocol.base.AuthenticationProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
service:(java.util.ArrayList)
[0]:com.webank.weid.protocol.base.ServiceProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
[1]:com.webank.weid.protocol.base.ServiceProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#2d37911b
type: drivingCardService
serviceEndpoint: https://weidentity.webank.com/endpoint/xxxxx
errorCode: 0
errorMessage: success
transactionInfo:null
5. setAuthentication¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.setAuthentication
接口定义:ResponseData<WeIdDocument> setAuthentication(WeIdDocument weIdDocument, AuthenticationArgs authenticationArgs)
接口描述: 在给定的WeIdDocument中添加Authentication信息。
接口入参:
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdDocument | WeIdDocument | Y | WeIdentity Document |
com.webank.weid.protocol.request.AuthenticationArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
owner | String | N | 所有者 | 默认为当前WeIdentity DID |
publicKey | String | Y | 数字公钥 |
接口返回: com.webank.weid.protocol.response.ResponseData<WeIdDocument>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | WeIdDocument | ||
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | 无效的WeIdentity DID |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥格式非法 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥不与WeIdentity DID所对应 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 其他错误 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
WeIdDocument weIdDocument= weIdServiceConsole.createWeIdDocument("13079093397463814932731720163442777403208788175453836227824139092404945067394266611910031425181012754616377192193136435818972874637291518463471522281921222");
AuthenticationArgs setAuthenticationArgs = new SetAuthenticationArgs();
setAuthenticationArgs.setPublicKey(
"13161444623157635919577071263152435729269604287924587017945158373362984739390835280704888860812486081963832887336483721952914804189509503053687001123007342");
ResponseData<Boolean> response = weIdServiceConsole.setAuthentication(weIdDocument, setAuthenticationArgs);
返回结果如下:
result:(com.webank.weid.protocol.base.WeIdDocument)
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
authentication:(java.util.ArrayList)
[0]:com.webank.weid.protocol.base.AuthenticationProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-116cc51b
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: zNT4AwSzTb3qwQXaDeE1tg8e8QYhWLMuguH6yR6XmZBnVtJVbidxCZ6dSd17YNi9z7oJgKdWnDzphND1ePa11oQZC7u5WcpDvPLJFWcAHwuYd4A2EeKfnwR1hdpY2PdK28StuVuV2H6jk7CgxitBNu9yRHBrXWanJ7R4FtoTsXf3YJvZUoDnNyRfoy1M19x6dcppge7zUZ2G4dSNcx1cpF6zM
[1]:com.webank.weid.protocol.base.AuthenticationProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#keys-1521a0db
type: Ed25519VerificationKey2020
controller: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
publicKeyMultibase: z5rrf3uPPK5AxXoWX7R2rpPkFHwj3ZoHnaPuHXj7CDt3cC5qRR5ihZSQGgBdTW5QZbthqndkkWXRVqHd3m5dPGJYaR8YEn7K32eL2mUMYLRxjSx7JfxAPYhB1gb6WvtnS24y6JRNahisBLXvXAcjM3PfKM32mMAipJZRXdaQr1SGUU4M9mYjDj2xNA96nz23yaZ8qpkxM9xJ7cUSR9w6Lo48
service:(java.util.ArrayList)
[0]:com.webank.weid.protocol.base.ServiceProperty
id: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a#04b8d8ae
type: WeIdentity
serviceEndpoint: https://github.com/WeBankBlockchain/WeIdentity
errorCode: 0
errorMessage: success
transactionInfo:null
6. registerCpt¶
基本信息
接口名称: com.webank.weid.service.console.weIdServiceConsole.registerCpt
接口定义: ResponseData<CptBaseInfo> registerCpt(CptMapArgs args, Integer cptId)
接口描述: 传入WeIdentity DID,JsonSchema(Map类型), cptId 和其对应的私钥,注册指定cptId的CPT,将cpt保存在本地文件,名字为:Cpt[cptId],返回CPT编号和版本。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
args | CptMapArgs | Y | Map类型参数注册CPT | |
cptId | Integer | Y | 指定的cptId |
com.webank.weid.protocol.request.CptMapArgs
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<CptBaseInfo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | CptBaseInfo | CPT基础数据,见下 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
WEID_INVALID | 100101 | WeIdentity DID无效 |
WEID_PRIVATEKEY_INVALID | 100103 | 私钥无效 |
WEID_PRIVATEKEY_DOES_NOT_MATCH | 100106 | 私钥与WeIdentity DID不匹配 |
WEID_AUTHORITY_INVALID | 100109 | 授权信息无效 |
CPT_JSON_SCHEMA_INVALID | 100301 | schema无效 |
CPT_EVENT_LOG_NULL | 100304 | 交易日志异常 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
CPT_ID_AUTHORITY_ISSUER_EXCEED_MAX | 500302 | 为权威机构生成的cptId超过上限 |
CPT_PUBLISHER_NOT_EXIST | 500303 | CPT发布者的WeIdentity DID不存在 |
CPT_ALREADY_EXIST | 500304 | CPT已经存在 |
CPT_NO_PERMISSION | 500305 | CPT无权限 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
HashMap<String, Object> cptJsonSchema = new HashMap<String, Object>(3);
cptJsonSchema.put(JsonSchemaConstant.TITLE_KEY, "cpt template");
cptJsonSchema.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is a cpt template");
HashMap<String, Object> propertitesMap1 = new HashMap<String, Object>(2);
propertitesMap1.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap1.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is name");
String[] genderEnum = { "F", "M" };
HashMap<String, Object> propertitesMap2 = new HashMap<String, Object>(2);
propertitesMap2.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap2.put(JsonSchemaConstant.DATA_TYPE_ENUM, genderEnum);
HashMap<String, Object> propertitesMap3 = new HashMap<String, Object>(2);
propertitesMap3.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_NUMBER);
propertitesMap3.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is age");
HashMap<String, Object> propertitesMap4 = new HashMap<String, Object>(2);
propertitesMap4.put(JsonSchemaConstant.TYPE_KEY, JsonSchemaConstant.DATA_TYPE_STRING);
propertitesMap4.put(JsonSchemaConstant.DESCRIPTION_KEY, "this is id");
HashMap<String, Object> cptJsonSchemaKeys = new HashMap<String, Object>(3);
cptJsonSchemaKeys.put("name", propertitesMap1);
cptJsonSchemaKeys.put("gender", propertitesMap2);
cptJsonSchemaKeys.put("age", propertitesMap3);
cptJsonSchemaKeys.put("id", propertitesMap4);
cptJsonSchema.put(JsonSchemaConstant.PROPERTIES_KEY, cptJsonSchemaKeys);
String[] genderRequired = { "id", "name", "gender" };
cptJsonSchema.put(JsonSchemaConstant.REQUIRED_KEY, genderRequired);
WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
WeIdAuthentication weIdAuthentication = new WeIdAuthentication();
weIdAuthentication.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
auth.setAuthenticationMethodId(DataToolUtils.publicKeyStrFromPrivate(new BigInteger("60866441986950167911324536025850958917764441489874006048340539971987791929772")) + "#keys-0");
weIdAuthentication.setWeIdPrivateKey(weIdPrivateKey);
CptMapArgs cptMapArgs = new CptMapArgs();
cptMapArgs.setCptJsonSchema(cptJsonSchema);
cptMapArgs.setWeIdAuthentication(weIdAuthentication);
ResponseData<CptBaseInfo> response = weIdServiceConsole.registerCpt(cptMapArgs, 101);
返回数据如下:
result:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 101
cptVersion: 1
errorCode: 0
errorMessage: success
transactionInfo: null
7. queryCpt¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.queryCpt
接口定义:ResponseData<Cpt> queryCpt(Integer cptId)
接口描述: 根据CPT编号查询CPT信息。
接口入参: java.lang.Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
cptId | Integer | Y | cptId编号 |
接口返回: com.webank.weid.protocol.response.ResponseData<Cpt>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | Cpt | CPT内容,见下 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
com.webank.weid.protocol.base.Cpt
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptJsonSchema | Map<String, Object> | Map类型的cptJsonSchema信息 | |
cptBaseInfo | CptBaseInfo | CPT基础数据,见下 | |
cptMetaData | CptMetaData | CPT元数据内部类,见下 |
com.webank.weid.protocol.base.CptBaseInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptId | Integer | cpId编号 | |
cptVersion | Integer | 版本号 |
com.webank.weid.protocol.base.Cpt.MetaData
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
cptPublisher | String | CPT发布者的WeIdentity DID | WeIdentity DID格式数据 |
cptSignature | String | 签名数据 | cptPublisher与cptJsonSchema拼接的签名数据 |
updated | long | 更新时间 | |
created | long | 创建日期 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
TRANSACTION_TIMEOUT | 160001 | 超时 |
TRANSACTION_EXECUTE_ERROR | 160002 | 交易错误 |
UNKNOW_ERROR | 160003 | 未知异常 |
ILLEGAL_INPUT | 160004 | 参数非法 |
CPT_NOT_EXISTS | 500301 | CPT不存在 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
Integer cptId = Integer.valueOf(1017);
ResponseData<Cpt> response = weIdServiceConsole.queryCpt(cptId);
返回数据如下:
result:(com.webank.weid.protocol.base.Cpt)
cptBaseInfo:(com.webank.weid.protocol.base.CptBaseInfo)
cptId: 1017
cptVersion: 1
cptJsonSchema:(java.util.HashMap)
$schema: http://json-schema.org/draft-04/schema#
type: object
properties:(java.util.LinkedHashMap)
age:(java.util.LinkedHashMap)
description: the age of certificate owner
type: number
gender:(java.util.LinkedHashMap)
description: the gender of certificate owner
enum:(java.util.ArrayList)
[0]:F
[1]:M
type: string
name:(java.util.LinkedHashMap)
description: the name of certificate owner
type: string
required:(java.util.ArrayList)
[0]:name
[1]:age
metaData:(com.webank.weid.protocol.base.Cpt$MetaData)
cptPublisher: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
cptSignature: G/YGY8Ftj9jPRdtr4ym+19M4/K6x9RbmRiV9JkryXeQGFr8eukDCBAcbinnNpF2N3Eo72bvxNqJOKx4ohWIus0Y=
created: 1560415607673
updated: 0
errorCode: 0
errorMessage: success
transactionInfo:null
8. registerPolicy¶
基本信息
接口名称: com.webank.weid.service.console.weIdServiceConsole.registerPolicy
接口定义: ResponseData<Integer> registerPolicy(String policyJson, WeIdAuthentication auth)
接口描述: 传入claimPolicy的Json序列化字符串,注册随机生成claimPolicyId的claimPolicy,将claimPolicy保存在本地文件,名字为:Policy[policyId],返回claimPolicy编号。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
policyJson | String | Y | claimPolicy的Json序列化字符串 |
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | Integer | claimPolicy的Id | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
WeIdAuthentication auth = new WeIdAuthentication();
auth.setWeId(WeIdUtils.getWeIdFromPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772"));
auth.setAuthenticationMethodId(DataToolUtils.publicKeyStrFromPrivate(new BigInteger("60866441986950167911324536025850958917764441489874006048340539971987791929772")) + "#keys-0");
auth.setWeIdPrivateKey(new WeIdPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772"));
ClaimPolicy claimPolicy = new ClaimPolicy();
claimPolicy.setFieldsToBeDisclosed("{\"name\":0,\"gender\":0,\"age\":0,\"id\":0}");
ResponseData<Integer> registerResp = weIdServiceConsole.registerPolicy(claimPolicy.getFieldsToBeDisclosed(), auth);
返回数据如下:
result: 101
errorCode: 0
errorMessage: success
transactionInfo: null
9. getClaimPolicy¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.getClaimPolicy
接口定义:ResponseData<ClaimPolicy> getClaimPolicy(Integer policyId)
接口描述: 根据policyId查询ClaimPolicy信息。
接口入参: java.lang.Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
policyId | Integer | Y | policy编号 |
接口返回: com.webank.weid.protocol.response.ResponseData<ClaimPolicy>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | ClaimPolicy | ClaimPolicy内容,见下 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
com.webank.weid.protocol.base.ClaimPolicy
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
fieldsToBeDisclosed | String | policy的Json序列化字符串 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
Integer policyId = Integer.valueOf(1017);
ResponseData<ClaimPolicy> response = weIdServiceConsole.getClaimPolicy(policyId);
返回数据如下:
result:(com.webank.weid.protocol.base.ClaimPolicy)
fieldsToBeDisclosed: "{\"name\":0,\"gender\":0,\"age\":0,\"id\":0}"
errorCode: 0
errorMessage: success
transactionInfo:null
10. registerPresentationPolicy¶
基本信息
接口名称: com.webank.weid.service.console.weIdServiceConsole.registerPresentationPolicy
接口定义: ResponseData<Integer> registerPresentationPolicy(List<Integer> claimPolicyIdList, WeIdAuthentication auth)
接口描述: 传入一组claimPolicyId,注册随机生成presentationId的presentationPolicy,将presentationPolicy保存在本地文件,名字为:Presentation[presentationId],返回presentationPolicy编号。
接口入参:
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
claimPolicyIdList | List<Integer> | Y | 一组claimPolicyId |
List<Integer>
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weIdAuthentication | WeIdAuthentication | Y | 认证信息,包含WeIdentity DID和私钥 | 用于WeIdentity DID的身份认证 |
cptJsonSchema | Map<String, Object> | Y | Map类型的JsonSchema信息 | 基本使用见调用示例 |
com.webank.weid.protocol.base.WeIdAuthentication
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
weId | String | Y | CPT发布者的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<Integer>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | Integer | presentationPolicy的Id | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
WeIdAuthentication auth = new WeIdAuthentication();
auth.setWeId(WeIdUtils.getWeIdFromPrivateKey(privateKey));
auth.setAuthenticationMethodId(DataToolUtils.publicKeyStrFromPrivate(new BigInteger(privateKey)) + "#keys-0");
auth.setWeIdPrivateKey(new WeIdPrivateKey(privateKey));
ClaimPolicy claimPolicy = new ClaimPolicy();
claimPolicy.setFieldsToBeDisclosed("{\"name\":0,\"gender\":0,\"age\":0,\"id\":0}");
List<Integer> claimPolicyIdList = new ArrayList<>();
ResponseData<Integer> registerResp = weIdServiceConsole.registerPolicy(claimPolicy.getFieldsToBeDisclosed(), auth);
Assert.assertTrue(registerResp.getResult() > 0);
claimPolicyIdList.add(registerResp.getResult());
registerResp = weIdServiceConsole.registerPolicy(claimPolicy.getFieldsToBeDisclosed(), auth);
Assert.assertTrue(registerResp.getResult() > 0);
claimPolicyIdList.add(registerResp.getResult());
registerResp = weIdServiceConsole.registerPolicy(claimPolicy.getFieldsToBeDisclosed(), auth);
Assert.assertTrue(registerResp.getResult() > 0);
claimPolicyIdList.add(registerResp.getResult());
ClaimPolicy claimPolicyFromChain = weIdServiceConsole.getClaimPolicy(registerResp.getResult()).getResult();
Assert.assertFalse(StringUtils.isEmpty(claimPolicyFromChain.getFieldsToBeDisclosed()));
System.out.println(claimPolicyFromChain.getFieldsToBeDisclosed());
ResponseData<Integer> presentationResp = weIdServiceConsole.registerPresentationPolicy(claimPolicyIdList, auth);
返回数据如下:
result: 101
errorCode: 0
errorMessage: success
transactionInfo: null
11. getPresentationPolicy¶
基本信息
接口名称:com.webank.weid.service.console.weIdServiceConsole.getPresentationPolicy
接口定义:ResponseData<PresentationPolicyE> getPresentationPolicy(Integer presentationPolicyId)
接口描述: 根据presentationPolicyId查询PresentationPolicy信息。
接口入参: java.lang.Integer
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
presentationPolicyId | Integer | Y | PresentationPolicy编号 |
接口返回: com.webank.weid.protocol.response.ResponseData<PresentationPolicyE>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | 此接口返回的code |
errorMessage | String | 返回结果描述 | |
result | PresentationPolicyE | PresentationPolicyE内容,见下 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
com.webank.weid.protocol.base.PresentationPolicyE
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | Integer | presentationPolicy的编号 | |
orgId | Integer | 创建该presentationPolicy的组织 | |
policy | Map<Integer, ClaimPolicy> | 不同claimPolicyId对应的ClaimPolicy | |
extra | Map<String, String> | 额外的特定信息 | |
policyType | String | 所包含的policy类型 | 有original和ZKP类型,默认original |
调用示例
WeIdServiceConsole weIdServiceConsole = new WeIdServiceConsole();
Integer presentationPolicyId = Integer.valueOf(1017);
ResponseData<PresentationPolicyE> response = weIdServiceConsole.getPresentationPolicy(presentationPolicyId);
返回数据如下:
result:(com.webank.weid.protocol.base.PresentationPolicyE)
id: 62
orgId:null
policyPublisherWeId: did:weid:0:0x82cf6d7c796126673238eae72d4d81f73596b04a
policy:(java.util.LinkedHashMap)
81:(com.webank.weid.protocol.base.ClaimPolicy)
fieldsToBeDisclosed: {"age":0,"gender":0,"id":0,"name":0}
65:(com.webank.weid.protocol.base.ClaimPolicy)
fieldsToBeDisclosed: {"age":0,"gender":0,"id":0,"name":0}
10:(com.webank.weid.protocol.base.ClaimPolicy)
fieldsToBeDisclosed: {"age":0,"gender":0,"id":0,"name":0}
extra:null
policyType: original
errorCode: 0
errorMessage: success
transactionInfo:null
CredentialServiceConsole¶
12. createCredential¶
基本信息
接口名称:com.webank.weid.service.console.CredentialServiceConsole.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身份信息 | |
type | CredentialType | N | 凭证类型enum,默认为Original,可选ZKP类型和Lite类型 |
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 | null | 纯功能接口没有交易信息 |
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 | 参数非法 |
调用示例
CredentialServiceConsole credentialServiceConsole = new CredentialServiceConsole();
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.setAuthenticationMethodId("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 = credentialServiceConsole.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
13. createSelectiveCredential¶
基本信息
接口名称:com.webank.weid.service.console.CredentialServiceConsole.createSelectiveCredential
接口定义: ResponseData<CredentialPojo> createSelectiveCredential(CredentialPojo credentialPojo, ClaimPolicy claimPolicy)
接口描述: 通过原始凭证和披露策略,创建基于hash连接选择性披露的Credential。
注解
注意:对于已经创建好的选择性披露凭证,不允许再次进行选择性披露。
接口入参:
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.ClaimPolicy
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
fieldsToBeDisclosed | String | Y | 披露配置 | 根据claim匹配的结构,为一个Json字符串,和Claim字段格式匹配。详见调用示例 |
接口返回: com.webank.weid.protocol.response.ResponseData<CredentialPojo>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | CredentialPojo | 凭证对象 | 业务数据 |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
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_DISCLOSUREVALUE_ILLEGAL | 100423 | policy披露信息非法 |
CREDENTIAL_POLICY_FORMAT_DOSE_NOT_MATCH_CLAIM | 100427 | 披露策略与Claim不匹配 |
CREDENTIAL_DISCLOSURE_DATA_TYPE_ILLEGAL | 100428 | 披露数据格式错误 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数非法 |
CREDENTIAL_NOT_SUPPORT_SELECTIVE_DISCLOSURE | 100440 | lite credential不支持选择性披露 |
调用示例
CredentialServiceConsole credentialServiceConsole = new CredentialServiceConsole();
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.setAuthenticationMethodId("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 =
credentialServiceConsole.createCredential(createCredentialPojoArgs);
// 选择性披露
ClaimPolicy claimPolicy = new ClaimPolicy();
claimPolicy.setFieldsToBeDisclosed("{\"name\":1,\"gender\":0,\"age\":1}");
ResponseData<CredentialPojo> selectiveResponse =
credentialServiceConsole.createSelectiveCredential(response.getResult(), claimPolicy);
返回结果如:
result:(com.webank.weid.protocol.base.CredentialPojo)
context: https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1
id: c4f8ca00-7c1b-4ba0-993f-008106075d9c
cptId: 1017
issuer: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7
issuanceDate: 1560420975268
expirationDate: 1560471040676
claim:(java.util.HashMap)
gender: 0x0756ccf78a0ebd5bd186b054376f1e9d86139bf04f660e9171a74673e5a21c75
name: zhangsan
age: 22
proof:(java.util.HashMap)
creator: did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7#key0
salt:(java.util.HashMap)
gender: 0
name: rr3g0
age: 9ysgr
created: 1560420975268
type: Secp256k1
signatureValue: GxVcZJFEnC7w+ZKOZAjmKy5JfFxoEFqffmCMvbUnVYmzEVKIUtDCiDmokZ2X3jIV/uFvUHQ4DWXksrD6Opr1vLo=
type:(java.util.ArrayList)
[0]:VerifiableCredential
errorCode: 0
errorMessage: success
transactionInfo:null
14. verify¶
基本信息
接口名称:com.webank.weid.service.console.CredentialServiceConsole.verify
接口定义: ResponseData<Boolean> verify(String issuerPublicKey, CredentialPojo credential)
接口描述: 使用提供的签发者公钥验证Credential,前提是该Credential对应的CPT文件保存在本地,如果没有请先使用registerCpt将CPT保存至本地文件
接口入参:
String
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
issuerPublicKey | String | Y | 公钥 |
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.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuerWeId跟Credential中的issuer不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名验证不通过 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
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_TYPE_IS_NULL | 100414 | type为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | 获取weIdDocument异常 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 签名验证异常 |
CREDENTIAL_PUBLIC_KEY_NOT_EXISTS | 100421 | 公钥不存在 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
CREDENTIAL_SALT_ILLEGAL | 100430 | 盐值非法 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialServiceConsole credentialServiceConsole = new CredentialServiceConsole();
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.setAuthenticationMethodId("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 = credentialServiceConsole.createCredential(createCredentialPojoArgs);
String issuerPublicKey = "9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875";
ResponseData<Boolean> responseVerify = credentialServiceConsole.verify(issuerPublicKey, response.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
15. verify¶
基本信息
接口名称:com.webank.weid.service.console.CredentialServiceConsole.verify
接口定义: ResponseData<Boolean> verify(WeIdDocument weIdDocument, CredentialPojo credential)
接口描述: 使用提供的签发者的WeIdDocument来验证Credential,前提是该Credential对应的CPT文件保存在本地,如果没有请先使用registerCpt将CPT保存至本地文件。
接口入参:
com.webank.weid.protocol.base.WeIdDocument
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | WeIdentity DID | |
authentication | List |
认证方集合,见下 | |
service | List |
服务端点集合,见下 |
com.webank.weid.protocol.base.AuthenticationProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | verification method id |
type | String | 类型 | 默认为:Ed25519VerificationKey2020 |
controller | String | 方法拥有人 | verification method controller |
publicKeyMultibase | String | 验证公钥 | 使用base58编码的公钥 |
com.webank.weid.protocol.base.ServiceProperty
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
id | String | 方法编号 | |
type | String | 类型 | |
serviceEndpoint | String | 联系/服务方式 | 邮箱、github个人主页等 |
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.response.ResponseData<Boolean>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Boolean | 验证结果 | 业务数据 |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ISSUER_MISMATCH | 100403 | issuerWeId跟Credential中的issuer不匹配 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名验证不通过 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
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_TYPE_IS_NULL | 100414 | type为空 |
CREDENTIAL_CPT_NOT_EXISTS | 100416 | cpt不存在 |
CREDENTIAL_WEID_DOCUMENT_ILLEGAL | 100417 | 获取weIdDocument异常 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_EXCEPTION_VERIFYSIGNATURE | 100419 | 签名验证异常 |
CREDENTIAL_PUBLIC_KEY_NOT_EXISTS | 100421 | 公钥不存在 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
CREDENTIAL_SALT_ILLEGAL | 100430 | 盐值非法 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialServiceConsole credentialServiceConsole = new CredentialServiceConsole();
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.setAuthenticationMethodId("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 = credentialServiceConsole.createCredential(createCredentialPojoArgs);
WeIdDocument weIdDocument = weIdServiceConsole.createWeIdDocument("9202079291855274840499629257327649367489192973501473466426182121217769706994308329953406897395674428921435762028726727399019951049448689033610431403383875").getResult();
ResponseData<Boolean> responseVerify = credentialServiceConsole.verify(weIdDocument, response.getResult());
返回结果如:
result: true
errorCode: 0
errorMessage: success
transactionInfo:null
16. getCredentialPojoHash¶
基本信息
接口名称:com.webank.weid.service.rpc.CredentialPojoService.getCredentialPojoHash
接口定义:ResponseData<String> getCredentialHash(CredentialPojo args)
接口描述: 传入CredentialPojo信息生成CredentialPojo整体的Hash值,一般在生成Evidence时调用。
接口入参: 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.response.ResponseData<String>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | String | 返回结果值 | |
transactionInfo | TransactionInfo | null | 纯功能接口没有交易信息 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_EXPIRED | 100402 | 过期 |
CREDENTIAL_SIGNATURE_BROKEN | 100405 | 签名破坏 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期格式非法 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_ID_NOT_EXISTS | 100412 | ID为空 |
CREDENTIAL_CONTEXT_NOT_EXISTS | 100413 | context为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
CREDENTIAL_SIGNATURE_TYPE_ILLEGAL | 100429 | 验证签名类型异常 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
CredentialServiceConsole credentialServiceConsole = new CredentialServiceConsole();
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.setAuthenticationMethodId("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 = credentialServiceConsole.createCredential(createCredentialPojoArgs);
ResponseData<String> resp = credentialServiceConsole.getCredentialPojoHash(response.getResult());
返回结果如:
result: 0x06173e4b714d57565ae5ddf23c4e84cb0a9824cb72eab476303d2dd1cc0a4728
errorCode: 0
errorMessage: success
transactionInfo:null
异常场景对接口的影响¶
- mysql或redis连接异常受影响接口:Persistence相关和serialize密文。
- 节点连接异常受影响接口:createWeId,createEvidence,registerAuthorityIssuer,RegisterIssuerType,RegisterCpt,VerifyCredentialWithSpecifiedPubKey,GetWeIdDocument,verifyLiteCredential。
- 节点连接正常,但不满足3f+1受影响接口:createWeId,createEvidence,registerAuthorityIssuer,RegisterIssuerType,RegisterCpt。