weIdentity 官方给出的demo是用gradle编译的,我自己的demo还是用自己熟悉的maven进行吧,而且个人感觉weIdentity 给出的demo过于复杂了。我想要的是短,快,准的效果,所以只有自己先过一遍他的demo,然后总结出本文了。
整体上,WeIdentity Java SDK包括五个主要的接口,它们分别是:WeIdService、AuthorityIssuerService、CptService、CredentialService / CredentialPojoService、EvidenceService、AmopService。
1. WeIdService
WeIdentity DID相关功能的核心接口。
本接口提供WeIdentity DID的创建、获取信息、设置属性等相关操作。
package com.hello.weidentity.weIdservice;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.rpc.WeIdService;
import com.webank.weid.service.impl.WeIdServiceImpl;
public class DemoWeIdService {
public void createWeId(){
WeIdService weIdService = new WeIdServiceImpl();
ResponseData<CreateWeIdDataResult> resultResponseData = weIdService.createWeId();
System.out.println("PrivateKey:" + resultResponseData.getResult().getUserWeIdPrivateKey().getPrivateKey());
System.out.println("PublicKey:" + resultResponseData.getResult().getUserWeIdPublicKey().getPublicKey());
System.out.println("we get weId:" + resultResponseData.getResult().getWeId());
}
}
package com.hello.weidentity;
import com.hello.weidentity.weIdservice.DemoWeIdService;
public class App {
public static void main(String[] args) {
DemoWeIdService demoWeIdService = new DemoWeIdService();
demoWeIdService.createWeId();
}
}

这里,我们来看看CreateWeIdDataResult类:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.webank.weid.protocol.response;
import com.webank.weid.protocol.base.WeIdPrivateKey;
import com.webank.weid.protocol.base.WeIdPublicKey;
public class CreateWeIdDataResult {
//公钥WeIdentity DID格式字符串, 格式: did:weid:0x………………….
private String weId;
//WeIdPublicKey 公钥
private WeIdPublicKey userWeIdPublicKey;
//WeIdPrivateKey 私钥
private WeIdPrivateKey userWeIdPrivateKey;
public CreateWeIdDataResult() {
}
public String getWeId() {
return this.weId;
}
public WeIdPublicKey getUserWeIdPublicKey() {
return this.userWeIdPublicKey;
}
public WeIdPrivateKey getUserWeIdPrivateKey() {
return this.userWeIdPrivateKey;
}
public void setWeId(String weId) {
this.weId = weId;
}
public void setUserWeIdPublicKey(WeIdPublicKey userWeIdPublicKey) {
this.userWeIdPublicKey = userWeIdPublicKey;
}
public void setUserWeIdPrivateKey(WeIdPrivateKey userWeIdPrivateKey) {
this.userWeIdPrivateKey = userWeIdPrivateKey;
}
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (!(o instanceof CreateWeIdDataResult)) {
return false;
} else {
CreateWeIdDataResult other = (CreateWeIdDataResult)o;
if (!other.canEqual(this)) {
return false;
} else {
label47: {
Object this$weId = this.getWeId();
Object other$weId = other.getWeId();
if (this$weId == null) {
if (other$weId == null) {
break label47;
}
} else if (this$weId.equals(other$weId)) {
break label47;
}
return false;
}
Object this$userWeIdPublicKey = this.getUserWeIdPublicKey();
Object other$userWeIdPublicKey = other.getUserWeIdPublicKey();
if (this$userWeIdPublicKey == null) {
if (other$userWeIdPublicKey != null) {
return false;
}
} else if (!this$userWeIdPublicKey.equals(other$userWeIdPublicKey)) {
return false;
}
Object this$userWeIdPrivateKey = this.getUserWeIdPrivateKey();
Object other$userWeIdPrivateKey = other.getUserWeIdPrivateKey();
if (this$userWeIdPrivateKey == null) {
if (other$userWeIdPrivateKey != null) {
return false;
}
} else if (!this$userWeIdPrivateKey.equals(other$userWeIdPrivateKey)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(Object other) {
return other instanceof CreateWeIdDataResult;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $weId = this.getWeId();
int result = result * 59 + ($weId == null ? 43 : $weId.hashCode());
Object $userWeIdPublicKey = this.getUserWeIdPublicKey();
result = result * 59 + ($userWeIdPublicKey == null ? 43 : $userWeIdPublicKey.hashCode());
Object $userWeIdPrivateKey = this.getUserWeIdPrivateKey();
result = result * 59 + ($userWeIdPrivateKey == null ? 43 : $userWeIdPrivateKey.hashCode());
return result;
}
public String toString() {
return "CreateWeIdDataResult(weId=" + this.getWeId() + ", userWeIdPublicKey=" + this.getUserWeIdPublicKey() + ", userWeIdPrivateKey=" + this.getUserWeIdPrivateKey() + ")";
}
}

2. AuthorityIssuerService
在WeIdentity的整体架构中,存在着可信的“授权机构”这一角色。一般来说,授权机构特指那些广为人知的、具有一定公信力的、并且有相对频繁签发Credential需求的实体。
本接口提供了对这类授权签发Credential的机构的注册、移除、查询信息等操作。
3. CptService
任何凭证的签发,都需要将数据转换成已经注册的CPT (Claim Protocol Type)格式规范,也就是所谓的“标准化格式化数据”。相关机构事先需要注册好CPT,在此之后,签发机构会根据CPT提供符合格式的数据,进而进行凭证的签发。
本接口提供了对CPT的注册、更新、查询等操作。
4. CredentialService / CredentialPojoService
凭证签发相关功能的核心接口。
本接口提供凭证的签发和验证操作、Verifiable Presentation的签发和验证操作。
5. EvidenceService
凭证存证上链的相关接口。
本接口提供凭证的Hash存证的生成上链、链上查询及校验等操作。
6. AmopService
AMOP通讯相关接口。
本接口提供AMOP的请求和注册。
后续文章,将会对以上6个服务进行详细介绍。
网友评论