Skip to content

Commit

Permalink
Merge pull request #51 from AntChainOpenLabs/feat/embedded-bcdns-supp…
Browse files Browse the repository at this point in the history
…orted

[feat][*][*] embedded bcdns supported
  • Loading branch information
zouxyan authored Aug 12, 2024
2 parents 423ec5f + aa81561 commit cf03137
Show file tree
Hide file tree
Showing 75 changed files with 4,718 additions and 112 deletions.
62 changes: 16 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ AntChain Bridge为开发者提供了SDK、手册和系统合约模板,来帮

在SDK中抽象了BCDNS服务的接口[IBlockChainDomainNameService](antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/service/IBlockChainDomainNameService.java),描述了BCDNS应该提供的功能,目前仅支持官方实现的BCDNS,支持的类型可[](antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/service/BCDNSTypeEnum.java)

在v0.3.0之后,拆分出单独的BCDNS Factory模块,用于快速启动不同类型BCDNS的客户端,并剥离依赖。增加关于Embedded BCDNS的实现代码,并提供Spring Boot Starter方便快速启动Embedded BCDNS服务。

以下介绍了基于SDK的一个集成架构:

![](https://antchainbridge.oss-cn-shanghai.aliyuncs.com/antchainbridge/document/picture/deploy_arch_231228.png)

SDK共有五个部分,包括:
SDK共有六个部分,包括:

- **antchain-bridge-commons**:包含很多工具方法和数据结构,帮助BBC实现快速开发;

Expand All @@ -50,11 +52,12 @@ SDK共有五个部分,包括:

- **antchain-bridge-bcdns**:主要包含了接口`IBlockChainDomainNameService`,描述了一个BCDNS客户端应该有的功能,目前仅支持星火链网(BIF)的BCDNS客户端实现,详细使用可以参考[wiki]()中“如何实现跨链”的内容;

- **antchain-bridge-bcdns-factory**:包含一个工厂类,支持依据类型创建BCDNS客户端,目前支持星火链网(BIF)的BCDNS客户端和Embedded BCDNS的实现,详细使用可以参考[wiki](https://github.com/AntChainOpenLab/AntChainBridgePluginSDK/wiki)中“如何实现跨链”的内容;


# 构建

**在开始之前,请您确保安装了maven和JDK,这里推荐使用[openjdk-1.8](https://adoptium.net/zh-CN/temurin/releases/?version=8)版本*
**在开始之前,请您确保安装了maven和JDK,这里推荐使用[jdk-1.8](https://adoptium.net/zh-CN/temurin/releases/?version=8)版本*

## 本地安装

Expand All @@ -64,33 +67,9 @@ SDK共有五个部分,包括:
mvn install -Dmaven.test.skip=true
```

或者在release[页面](https://github.com/AntChainOpenLab/AntChainBridgePluginSDK/releases)找到适合的版本并下载到本地,解压之后,在根目录下,运行脚本完成SDK的安装:

```
./install_sdk.sh
```

提示信息如下,代表安装完成:

```
___ __ ______ __ _ ____ _ __
/ | ____ / /_ / ____// /_ ____ _ (_)____ / __ ) _____ (_)____/ /____ _ ___
/ /| | / __ \ / __// / / __ \ / __ `// // __ \ / __ |/ ___// // __ // __ `// _ \
/ ___ | / / / // /_ / /___ / / / // /_/ // // / / / / /_/ // / / // /_/ // /_/ // __/
/_/ |_|/_/ /_/ \__/ \____//_/ /_/ \__,_//_//_/ /_/ /_____//_/ /_/ \__,_/ \__, / \___/
/____/
[ INFO ]_[ 2023-12-27 17:40:42.170 ] : successful to install antchain-bridge-commons-0.2.0.jar
[ INFO ]_[ 2023-12-27 17:40:44.170 ] : successful to install antchain-bridge-spi-0.2.0.jar
[ INFO ]_[ 2023-12-27 17:40:45.170 ] : successful to install antchain-bridge-plugin-lib-0.2.0.jar
[ INFO ]_[ 2023-12-27 17:40:47.170 ] : successful to install antchain-bridge-plugin-manager-0.2.0.jar
[ INFO ]_[ 2023-12-27 17:40:48.170 ] : successful to install antchain-bridge-bcdns-0.2.0.jar
[ INFO ]_[ 2023-12-27 17:40:48.170 ] : success
```

这样,SDK的Jar包就被安装在本地了。

然后,可以通过在maven的pom.xml配置依赖就可以了,比如下面一段配置,`${antchain-bridge.sdk.version}`为当前仓库的版本号,可以在项目目录的[po m.xml](pom.xml)看到。
然后,可以通过在maven的pom.xml配置依赖就可以了,比如下面一段配置,`${antchain-bridge.sdk.version}`为当前仓库的版本号,可以在项目目录的[pom.xml](pom.xml)看到。

```xml
<dependency>
Expand Down Expand Up @@ -118,27 +97,14 @@ mvn install -Dmaven.test.skip=true
<artifactId>antchain-bridge-bcdns</artifactId>
<version>${antchain-bridge.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns-factory</artifactId>
<version>${antchain-bridge.sdk.version}</version>
</dependency>
```

## 通过GitHub Package安装

参考[这里](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-to-github-packages)配置您的maven,在`setting.xml`中配置上您的GitHub账号和Token。

在您的项目`pom.xml`中,配置上我们的repository:

```xml
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/AntChainOpenLab/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
```

这样您就可以导入上面的dependency来使用SDK。

# 快速开始

Expand Down Expand Up @@ -410,7 +376,7 @@ IV4AUtT9d+Y8gRK/kmNySzlJ32Shw3FNj8Uvy3yjBxjO6vKOWH5Jhu936zMWOgk=

### 星火链网(BIF)BCDNS

目前SDK仅支持星火链网的BCDNS服务客户端,这里介绍其配置项和如何实例化该客户端。
目前SDK支持星火链网的BCDNS服务客户端,这里介绍其配置项和如何实例化该客户端。

首先介绍配置,代码可[](antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/impl/bif/conf/BifBCNDSConfig.java),主要分为两部分,一部分`certificationServiceConfig`是用于和颁证服务通信、鉴权,另一部分`chainConfig`用于和星火链网交互。

Expand Down Expand Up @@ -460,6 +426,10 @@ IV4AUtT9d+Y8gRK/kmNySzlJ32Shw3FNj8Uvy3yjBxjO6vKOWH5Jhu936zMWOgk=

准备完配置之后,可以根据[这里](antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/impl/BlockChainDomainNameServiceFactory.java)创建一个BCDNS实例。

### Embedded BCDNS

Embedded BCDNS是内嵌在服务内部的BCDNS,提供中心化的权威服务,会使用一把私钥为跨链网络提供认证、准入等功能,按照服务端要求可以通过简单配置接入BCDNS,具体内容可以参考[这里](bcdns-services/embedded-bcdns/README.md)

# 社区治理

AntChain Bridge 欢迎您以任何形式参与社区建设。
Expand Down
49 changes: 49 additions & 0 deletions antchain-bridge-bcdns-factory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024 Ant Group
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns-factory</artifactId>
<version>0.3.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<acb.version>0.3.0</acb.version>
<embedded.bcdns.core.version>0.1.0</embedded.bcdns.core.version>
</properties>

<dependencies>
<dependency>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns</artifactId>
<version>${acb.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>embedded-bcdns-core</artifactId>
<version>${embedded.bcdns.core.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2023 Ant Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alipay.antchain.bridge.bcdns.factory;

import com.alipay.antchain.bridge.bcdns.embedded.client.EmbeddedBCDNSClient;
import com.alipay.antchain.bridge.bcdns.impl.bif.BifBCDNSClient;
import com.alipay.antchain.bridge.bcdns.service.BCDNSTypeEnum;
import com.alipay.antchain.bridge.bcdns.service.IBlockChainDomainNameService;
import com.alipay.antchain.bridge.bcdns.types.exception.AntChainBridgeBCDNSException;
import com.alipay.antchain.bridge.bcdns.types.exception.BCDNSErrorCodeEnum;

public class BlockChainDomainNameServiceFactory {

public static IBlockChainDomainNameService create(BCDNSTypeEnum type, byte[] rawConfig) {
switch (type) {
case BIF:
return BifBCDNSClient.generateFrom(rawConfig);
case EMBEDDED:
return EmbeddedBCDNSClient.generateFrom(rawConfig);
default:
throw new AntChainBridgeBCDNSException(
BCDNSErrorCodeEnum.BCDNS_TYPE_UNKNOWN,
"unknown bcdns type : " + type.getCode()
);
}
}
}
2 changes: 1 addition & 1 deletion antchain-bridge-bcdns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-bcdns</artifactId>
<version>0.2.3</version>
<version>0.3.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
import com.alipay.antchain.bridge.bcdns.types.exception.AntChainBridgeBCDNSException;
import com.alipay.antchain.bridge.bcdns.types.exception.BCDNSErrorCodeEnum;

/**
* This factory is going to be abandoned in the future.
* Please use new {@code BlockChainDomainNameServiceFactory}
* in module <b>antchain-bridge-bcdns-factory<</b> instead.
*/
@Deprecated
public class BlockChainDomainNameServiceFactory {

public static IBlockChainDomainNameService create(BCDNSTypeEnum type, byte[] rawConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static BCDNSTypeEnum parseFromValue(String value) {
if (StrUtil.equals(value, BCDNSTypeEnum.BIF.getCode())) {
return BIF;
}
if (StrUtil.equals(value, BCDNSTypeEnum.EMBEDDED.getCode())) {
return EMBEDDED;
}
throw new AntChainBridgeBCDNSException(
BCDNSErrorCodeEnum.BCDNS_TYPE_UNKNOWN,
"Invalid value for bcdns type: " + value
Expand All @@ -49,6 +52,8 @@ public static BCDNSTypeEnum valueOf(Byte value) {
switch (value) {
case 0:
return BIF;
case 1:
return EMBEDDED;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IBlockChainDomainNameService {

ApplicationResult queryRelayerCertificateApplicationResult(String applyReceipt);

//

ApplyPTCCertificateResponse applyPTCCertificate(AbstractCrossChainCertificate certSigningRequest);

ApplicationResult queryPTCCertificateApplicationResult(String applyReceipt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alipay.antchain.bridge.commons.core.base.CrossChainDomain;
import com.alipay.antchain.bridge.commons.utils.codec.tlv.TLVTypeEnum;
import com.alipay.antchain.bridge.commons.utils.codec.tlv.TLVUtils;
import com.alipay.antchain.bridge.commons.utils.codec.tlv.annotation.TLVField;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -35,9 +36,22 @@ public class DomainRouter {

private static final short TLV_TYPE_DOMAIN_ROUTER_DEST_RELAYER = 0x0001;

@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_DOMAIN, type = TLVTypeEnum.BYTES)
public static DomainRouter decode(byte[] raw) {
return TLVUtils.decode(raw, DomainRouter.class);
}

public DomainRouter(String destDomain, Relayer destRelayer) {
this.destDomain = new CrossChainDomain(destDomain);
this.destRelayer = destRelayer;
}

@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_DOMAIN, type = TLVTypeEnum.STRING)
private CrossChainDomain destDomain;

@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_RELAYER, type = TLVTypeEnum.BYTES, order = 1)
private Relayer destRelayer;

public byte[] encode() {
return TLVUtils.encode(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ public enum BCDNSErrorCodeEnum {

BCDNS_QUERY_TPBTA_FAILED("8009", "query tpbta failed"),

BCDNS_TYPE_UNKNOWN("800a", "bcdns type unknown");
BCDNS_TYPE_UNKNOWN("800a", "bcdns type unknown"),

BCDNS_QUERY_ROOT_CERT_FAILED("800b", "query root cert failed"),

BCDNS_QUERY_APPLICATION_RESULT_FAILED("800c", "query application result failed"),

BCDNS_APPLY_RELAYER_CERT_FAILED("800d", "apply relayer failed"),

BCDNS_APPLY_PTC_CERT_FAILED("800e", "apply ptc failed"),

BCDNS_APPLY_DOMAIN_CERT_FAILED("800f", "apply domain failed"),

BCDNS_QUERY_RELAYER_CERT_FAILED("8010", "query relayer cert failed"),;

/**
* Error code for errors happened in project {@code antchain-bridge-commons}
Expand Down
8 changes: 7 additions & 1 deletion antchain-bridge-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-commons</artifactId>
<version>0.2.3</version>
<version>0.3.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -69,6 +69,12 @@
<groupId>cn.bitfactory</groupId>
<artifactId>bif-chain-sdk</artifactId>
<version>1.0.2</version>
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package com.alipay.antchain.bridge.commons.bcdns;

import java.security.PublicKey;
import java.security.Security;

import com.alipay.antchain.bridge.commons.bcdns.utils.ObjectIdentityUtil;
import com.alipay.antchain.bridge.commons.core.base.ObjectIdentity;
import com.alipay.antchain.bridge.commons.utils.codec.tlv.TLVTypeEnum;
Expand All @@ -30,6 +27,9 @@
import lombok.Setter;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.PublicKey;
import java.security.Security;

@Getter
@Setter
@AllArgsConstructor
Expand All @@ -41,30 +41,30 @@ public class RelayerCredentialSubject extends AbstractCredentialSubjectWithSingl

public static final String CURRENT_VERSION = "1.0";

public static final short TLV_TYPE_PTC_CREDENTIAL_SUBJECT_VERSION = 0x0000;
public static final short TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_VERSION = 0x0000;

public static final short TLV_TYPE_PTC_CREDENTIAL_SUBJECT_NAME = 0x0001;
public static final short TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_NAME = 0x0001;

public static final short TLV_TYPE_PTC_CREDENTIAL_SUBJECT_TYPE = 0x0002;
public static final short TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_TYPE = 0x0002;

public static final short TLV_TYPE_PTC_CREDENTIAL_SUBJECT_APPLICANT = 0x0003;
public static final short TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_APPLICANT = 0x0003;

public static final short TLV_TYPE_PTC_CREDENTIAL_SUBJECT_SUBJECT_INFO = 0x0004;
public static final short TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_SUBJECT_INFO = 0x0004;

public static RelayerCredentialSubject decode(byte[] rawData) {
return TLVUtils.decode(rawData, RelayerCredentialSubject.class);
}

@TLVField(tag = TLV_TYPE_PTC_CREDENTIAL_SUBJECT_VERSION, type = TLVTypeEnum.STRING)
@TLVField(tag = TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_VERSION, type = TLVTypeEnum.STRING)
private String version;

@TLVField(tag = TLV_TYPE_PTC_CREDENTIAL_SUBJECT_NAME, type = TLVTypeEnum.STRING, order = 1)
@TLVField(tag = TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_NAME, type = TLVTypeEnum.STRING, order = 1)
private String name;

@TLVField(tag = TLV_TYPE_PTC_CREDENTIAL_SUBJECT_APPLICANT, type = TLVTypeEnum.BYTES, order = 2)
@TLVField(tag = TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_APPLICANT, type = TLVTypeEnum.BYTES, order = 2)
private ObjectIdentity applicant;

@TLVField(tag = TLV_TYPE_PTC_CREDENTIAL_SUBJECT_SUBJECT_INFO, type = TLVTypeEnum.BYTES, order = 3)
@TLVField(tag = TLV_TYPE_RELAYER_CREDENTIAL_SUBJECT_SUBJECT_INFO, type = TLVTypeEnum.BYTES, order = 3)
private byte[] subjectInfo;

@Override
Expand Down
Loading

0 comments on commit cf03137

Please sign in to comment.