Skip to content

Commit cf03137

Browse files
authored
Merge pull request #51 from AntChainOpenLabs/feat/embedded-bcdns-supported
[feat][*][*] embedded bcdns supported
2 parents 423ec5f + aa81561 commit cf03137

File tree

75 files changed

+4718
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4718
-112
lines changed

README.md

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ AntChain Bridge为开发者提供了SDK、手册和系统合约模板,来帮
3434

3535
在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)
3636

37+
在v0.3.0之后,拆分出单独的BCDNS Factory模块,用于快速启动不同类型BCDNS的客户端,并剥离依赖。增加关于Embedded BCDNS的实现代码,并提供Spring Boot Starter方便快速启动Embedded BCDNS服务。
38+
3739
以下介绍了基于SDK的一个集成架构:
3840

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

41-
SDK共有五个部分,包括:
43+
SDK共有六个部分,包括:
4244

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

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

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

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

5457

5558
# 构建
5659

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

5962
## 本地安装
6063

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

67-
或者在release[页面](https://github.com/AntChainOpenLab/AntChainBridgePluginSDK/releases)找到适合的版本并下载到本地,解压之后,在根目录下,运行脚本完成SDK的安装:
68-
69-
```
70-
./install_sdk.sh
71-
```
72-
73-
提示信息如下,代表安装完成:
74-
75-
```
76-
___ __ ______ __ _ ____ _ __
77-
/ | ____ / /_ / ____// /_ ____ _ (_)____ / __ ) _____ (_)____/ /____ _ ___
78-
/ /| | / __ \ / __// / / __ \ / __ `// // __ \ / __ |/ ___// // __ // __ `// _ \
79-
/ ___ | / / / // /_ / /___ / / / // /_/ // // / / / / /_/ // / / // /_/ // /_/ // __/
80-
/_/ |_|/_/ /_/ \__/ \____//_/ /_/ \__,_//_//_/ /_/ /_____//_/ /_/ \__,_/ \__, / \___/
81-
/____/
82-
83-
[ INFO ]_[ 2023-12-27 17:40:42.170 ] : successful to install antchain-bridge-commons-0.2.0.jar
84-
[ INFO ]_[ 2023-12-27 17:40:44.170 ] : successful to install antchain-bridge-spi-0.2.0.jar
85-
[ INFO ]_[ 2023-12-27 17:40:45.170 ] : successful to install antchain-bridge-plugin-lib-0.2.0.jar
86-
[ INFO ]_[ 2023-12-27 17:40:47.170 ] : successful to install antchain-bridge-plugin-manager-0.2.0.jar
87-
[ INFO ]_[ 2023-12-27 17:40:48.170 ] : successful to install antchain-bridge-bcdns-0.2.0.jar
88-
[ INFO ]_[ 2023-12-27 17:40:48.170 ] : success
89-
```
90-
9170
这样,SDK的Jar包就被安装在本地了。
9271

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

9574
```xml
9675
<dependency>
@@ -118,27 +97,14 @@ mvn install -Dmaven.test.skip=true
11897
<artifactId>antchain-bridge-bcdns</artifactId>
11998
<version>${antchain-bridge.sdk.version}</version>
12099
</dependency>
100+
<dependency>
101+
<groupId>com.alipay.antchain.bridge</groupId>
102+
<artifactId>antchain-bridge-bcdns-factory</artifactId>
103+
<version>${antchain-bridge.sdk.version}</version>
104+
</dependency>
121105
```
122106

123-
## 通过GitHub Package安装
124-
125-
参考[这里](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。
126-
127-
在您的项目`pom.xml`中,配置上我们的repository:
128107

129-
```xml
130-
<repositories>
131-
<repository>
132-
<id>github</id>
133-
<url>https://maven.pkg.github.com/AntChainOpenLab/*</url>
134-
<snapshots>
135-
<enabled>true</enabled>
136-
</snapshots>
137-
</repository>
138-
</repositories>
139-
```
140-
141-
这样您就可以导入上面的dependency来使用SDK。
142108

143109
# 快速开始
144110

@@ -410,7 +376,7 @@ IV4AUtT9d+Y8gRK/kmNySzlJ32Shw3FNj8Uvy3yjBxjO6vKOWH5Jhu936zMWOgk=
410376

411377
### 星火链网(BIF)BCDNS
412378

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

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

@@ -460,6 +426,10 @@ IV4AUtT9d+Y8gRK/kmNySzlJ32Shw3FNj8Uvy3yjBxjO6vKOWH5Jhu936zMWOgk=
460426

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

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

465435
AntChain Bridge 欢迎您以任何形式参与社区建设。
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2024 Ant Group
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>com.alipay.antchain.bridge</groupId>
24+
<artifactId>antchain-bridge-bcdns-factory</artifactId>
25+
<version>0.3.0</version>
26+
27+
<properties>
28+
<maven.compiler.source>8</maven.compiler.source>
29+
<maven.compiler.target>8</maven.compiler.target>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
32+
<acb.version>0.3.0</acb.version>
33+
<embedded.bcdns.core.version>0.1.0</embedded.bcdns.core.version>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.alipay.antchain.bridge</groupId>
39+
<artifactId>antchain-bridge-bcdns</artifactId>
40+
<version>${acb.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.alipay.antchain.bridge</groupId>
44+
<artifactId>embedded-bcdns-core</artifactId>
45+
<version>${embedded.bcdns.core.version}</version>
46+
</dependency>
47+
</dependencies>
48+
49+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2023 Ant Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alipay.antchain.bridge.bcdns.factory;
18+
19+
import com.alipay.antchain.bridge.bcdns.embedded.client.EmbeddedBCDNSClient;
20+
import com.alipay.antchain.bridge.bcdns.impl.bif.BifBCDNSClient;
21+
import com.alipay.antchain.bridge.bcdns.service.BCDNSTypeEnum;
22+
import com.alipay.antchain.bridge.bcdns.service.IBlockChainDomainNameService;
23+
import com.alipay.antchain.bridge.bcdns.types.exception.AntChainBridgeBCDNSException;
24+
import com.alipay.antchain.bridge.bcdns.types.exception.BCDNSErrorCodeEnum;
25+
26+
public class BlockChainDomainNameServiceFactory {
27+
28+
public static IBlockChainDomainNameService create(BCDNSTypeEnum type, byte[] rawConfig) {
29+
switch (type) {
30+
case BIF:
31+
return BifBCDNSClient.generateFrom(rawConfig);
32+
case EMBEDDED:
33+
return EmbeddedBCDNSClient.generateFrom(rawConfig);
34+
default:
35+
throw new AntChainBridgeBCDNSException(
36+
BCDNSErrorCodeEnum.BCDNS_TYPE_UNKNOWN,
37+
"unknown bcdns type : " + type.getCode()
38+
);
39+
}
40+
}
41+
}

antchain-bridge-bcdns/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.alipay.antchain.bridge</groupId>
88
<artifactId>antchain-bridge-bcdns</artifactId>
9-
<version>0.2.3</version>
9+
<version>0.3.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>

antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/impl/BlockChainDomainNameServiceFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
import com.alipay.antchain.bridge.bcdns.types.exception.AntChainBridgeBCDNSException;
2323
import com.alipay.antchain.bridge.bcdns.types.exception.BCDNSErrorCodeEnum;
2424

25+
/**
26+
* This factory is going to be abandoned in the future.
27+
* Please use new {@code BlockChainDomainNameServiceFactory}
28+
* in module <b>antchain-bridge-bcdns-factory<</b> instead.
29+
*/
30+
@Deprecated
2531
public class BlockChainDomainNameServiceFactory {
2632

2733
public static IBlockChainDomainNameService create(BCDNSTypeEnum type, byte[] rawConfig) {

antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/service/BCDNSTypeEnum.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static BCDNSTypeEnum parseFromValue(String value) {
3939
if (StrUtil.equals(value, BCDNSTypeEnum.BIF.getCode())) {
4040
return BIF;
4141
}
42+
if (StrUtil.equals(value, BCDNSTypeEnum.EMBEDDED.getCode())) {
43+
return EMBEDDED;
44+
}
4245
throw new AntChainBridgeBCDNSException(
4346
BCDNSErrorCodeEnum.BCDNS_TYPE_UNKNOWN,
4447
"Invalid value for bcdns type: " + value
@@ -49,6 +52,8 @@ public static BCDNSTypeEnum valueOf(Byte value) {
4952
switch (value) {
5053
case 0:
5154
return BIF;
55+
case 1:
56+
return EMBEDDED;
5257
default:
5358
return null;
5459
}

antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/service/IBlockChainDomainNameService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IBlockChainDomainNameService {
3030

3131
ApplicationResult queryRelayerCertificateApplicationResult(String applyReceipt);
3232

33-
//
33+
3434
ApplyPTCCertificateResponse applyPTCCertificate(AbstractCrossChainCertificate certSigningRequest);
3535

3636
ApplicationResult queryPTCCertificateApplicationResult(String applyReceipt);

antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/types/base/DomainRouter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.alipay.antchain.bridge.commons.core.base.CrossChainDomain;
2020
import com.alipay.antchain.bridge.commons.utils.codec.tlv.TLVTypeEnum;
21+
import com.alipay.antchain.bridge.commons.utils.codec.tlv.TLVUtils;
2122
import com.alipay.antchain.bridge.commons.utils.codec.tlv.annotation.TLVField;
2223
import lombok.AllArgsConstructor;
2324
import lombok.Getter;
@@ -35,9 +36,22 @@ public class DomainRouter {
3536

3637
private static final short TLV_TYPE_DOMAIN_ROUTER_DEST_RELAYER = 0x0001;
3738

38-
@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_DOMAIN, type = TLVTypeEnum.BYTES)
39+
public static DomainRouter decode(byte[] raw) {
40+
return TLVUtils.decode(raw, DomainRouter.class);
41+
}
42+
43+
public DomainRouter(String destDomain, Relayer destRelayer) {
44+
this.destDomain = new CrossChainDomain(destDomain);
45+
this.destRelayer = destRelayer;
46+
}
47+
48+
@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_DOMAIN, type = TLVTypeEnum.STRING)
3949
private CrossChainDomain destDomain;
4050

4151
@TLVField(tag = TLV_TYPE_DOMAIN_ROUTER_DEST_RELAYER, type = TLVTypeEnum.BYTES, order = 1)
4252
private Relayer destRelayer;
53+
54+
public byte[] encode() {
55+
return TLVUtils.encode(this);
56+
}
4357
}

antchain-bridge-bcdns/src/main/java/com/alipay/antchain/bridge/bcdns/types/exception/BCDNSErrorCodeEnum.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ public enum BCDNSErrorCodeEnum {
5151

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

54-
BCDNS_TYPE_UNKNOWN("800a", "bcdns type unknown");
54+
BCDNS_TYPE_UNKNOWN("800a", "bcdns type unknown"),
55+
56+
BCDNS_QUERY_ROOT_CERT_FAILED("800b", "query root cert failed"),
57+
58+
BCDNS_QUERY_APPLICATION_RESULT_FAILED("800c", "query application result failed"),
59+
60+
BCDNS_APPLY_RELAYER_CERT_FAILED("800d", "apply relayer failed"),
61+
62+
BCDNS_APPLY_PTC_CERT_FAILED("800e", "apply ptc failed"),
63+
64+
BCDNS_APPLY_DOMAIN_CERT_FAILED("800f", "apply domain failed"),
65+
66+
BCDNS_QUERY_RELAYER_CERT_FAILED("8010", "query relayer cert failed"),;
5567

5668
/**
5769
* Error code for errors happened in project {@code antchain-bridge-commons}

antchain-bridge-commons/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.alipay.antchain.bridge</groupId>
88
<artifactId>antchain-bridge-commons</artifactId>
9-
<version>0.2.3</version>
9+
<version>0.3.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>
@@ -69,6 +69,12 @@
6969
<groupId>cn.bitfactory</groupId>
7070
<artifactId>bif-chain-sdk</artifactId>
7171
<version>1.0.2</version>
72+
<exclusions>
73+
<exclusion>
74+
<groupId>org.bouncycastle</groupId>
75+
<artifactId>bcprov-jdk15on</artifactId>
76+
</exclusion>
77+
</exclusions>
7278
</dependency>
7379
</dependencies>
7480

0 commit comments

Comments
 (0)